WorkOrder.php 80 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use Monolog\Handler\IFTTTHandler;
  5. use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
  6. use think\Db;
  7. use think\Request;
  8. use PhpOffice\PhpSpreadsheet\IOFactory;
  9. /**
  10. * 工单资料管理
  11. */
  12. class WorkOrder extends Api
  13. {
  14. protected $noNeedLogin = ['*'];
  15. protected $noNeedRight = ['*'];
  16. /**
  17. * 工单资料菜单列表
  18. *
  19. * @ApiMethod (GET)
  20. * @return false|string
  21. * @throws \think\Exception
  22. */
  23. public function DataList()
  24. {
  25. if ($this->request->isGet() === false){
  26. $this->error('请求错误');
  27. }
  28. $data = \db('erp_客户供应商')
  29. ->column('rtrim(编号) as 编号');
  30. $this->success('成功',$data);
  31. }
  32. /**
  33. * 工单基本资料列表
  34. * @ApiMethod (GET)
  35. * @param string $limit 查询长度
  36. * @param string $Gd_khdh 客户代号
  37. * @param string $startTime 接单日期开始时间
  38. * @param string $endTime 接单日期结束时间
  39. * @return \think\response\Json
  40. * @throws \think\exception\DbException
  41. */
  42. public function WorkOrderList()
  43. {
  44. if ($this->request->isGet() === false){
  45. $this->error('请求错误');
  46. }
  47. $search = input('search');
  48. $page = input('page');
  49. $limit = input('limit');
  50. $param = $this->request->param();
  51. $where = [];
  52. if (!empty($search)){
  53. $where['订单编号|生产款号|客户编号|款式|审核|Sys_id'] = ['like','%'.$search.'%'];
  54. }
  55. $total = \db('工单_基本资料')->where($where)->distinct(true)->count();
  56. $list = \db('工单_基本资料')
  57. ->where($where)
  58. ->order('Gd_statu desc,Sys_rq desc')
  59. ->limit(($page-1)*$limit,$limit)
  60. ->select();
  61. foreach ($list as $key=>$value){
  62. $number = \db('工单_工艺资料')->where('订单编号',$value['订单编号'])->count();
  63. if ($number === 0){
  64. $list[$key]['status'] = '*';
  65. }else{
  66. $list[$key]['status'] = '';
  67. }
  68. }
  69. $this->success('成功',['data'=>$list,'total'=>$total]);
  70. }
  71. /**
  72. * 工单详情
  73. * @ApiMethod (GET)
  74. * @param void
  75. * @return void
  76. * @throws \think\db\exception\DataNotFoundException
  77. * @throws \think\db\exception\ModelNotFoundException
  78. * @throws \think\exception\DbException
  79. */
  80. public function workOrderListDetail()
  81. {
  82. if ($this->request->isGet() === false){
  83. $this->error('请求错误');
  84. }
  85. $Gd_gdbh = input('订单编号');
  86. $param = $this->request->param();
  87. if (empty($Gd_gdbh)){
  88. $this->error('参数错误');
  89. }
  90. $data = [];
  91. //颜色资料
  92. $printList = \db('工单_印件资料')
  93. ->where('订单编号',$Gd_gdbh)
  94. ->select();
  95. $data['printList'] = $printList;
  96. //工序资料
  97. $processList = \db('工单_工艺资料')
  98. ->where('订单编号',$Gd_gdbh)
  99. ->order('子订单编号,工序编号')
  100. ->select();
  101. $data['processList'] = $processList;
  102. //工单相关附件
  103. $bomList = \db('工单_相关附件')
  104. ->where('关联编号',$Gd_gdbh)
  105. ->where('附件备注','订单资料')
  106. ->select();
  107. $data['attachments'] = $bomList;
  108. //技术附件资料
  109. $jsRes = db('工单_相关附件')
  110. ->where('关联编号',$Gd_gdbh)
  111. ->where('附件备注','技术附件')
  112. ->select();
  113. $data['jsData'] = $jsRes;
  114. $this->success('成功',$data);
  115. }
  116. /**
  117. * 编辑页面展示
  118. * @ApiMethod (GET)
  119. * @param string $workOrder 工单编号
  120. * @return void
  121. * @throws \think\db\exception\DataNotFoundException
  122. * @throws \think\db\exception\ModelNotFoundException
  123. * @throws \think\exception\DbException
  124. */
  125. public function DataCorrection()
  126. {
  127. if ($this->request->isGet() === false){
  128. $this->error('请求错误');
  129. }
  130. $workOrder = input('Gd_gdbh');
  131. if (empty($workOrder)){
  132. $this->error('参数错误');
  133. }
  134. $field = 'rtrim(Gd_lx) as 重点工单,rtrim(Gd_gdbh) as 工单编号,rtrim(Gd_生产分类) as 生产类型,rtrim(Gd_khdh) as 客户代号,rtrim(Gd_客户名称) as 客户名称,
  135. rtrim(Gd_cpdh) as 印件代号,rtrim(Gd_cpmc) as 印件名称,rtrim(成品代号) as 产品代号,rtrim(成品名称) as 产品名称,rtrim(接单日期) as 开单日期,rtrim(订单数量) as 订单数量,rtrim(交货日期) as 交货日期,
  136. rtrim(投料率) as 投料率,rtrim(实际投料) as 万小张,rtrim(计量单位) as 单位,rtrim(投料大箱) as 投料大箱,rtrim(排产时库存) as 库存大箱,rtrim(警语版面) as 警语版面,
  137. rtrim(销售订单号) as 销售订单号,rtrim(产品版本号) as 版本号,rtrim(客户ERP编码) as 客户ERP编码,rtrim(码源数量) as 码源数量,rtrim(进程备注) as 进程备注,rtrim(Gd_desc) as 备注,rtrim(Uniqid) as Uniqid,rtrim(计划投料) as 平张投料';
  138. $list = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field($field)->find();
  139. if (empty($list)){
  140. $this->error('未找到该工单信息');
  141. }
  142. $printData = \db('工单_印件资料')
  143. ->where('Yj_Gdbh',$workOrder)
  144. ->field('rtrim(yj_yjmc) as 印件名称,rtrim(yj_Yjdh) as 印件代号,rtrim(Uniqid) as id')
  145. ->cache(true,84600)
  146. ->find();
  147. if (empty($printData)){
  148. $list['印件名称'] = '';
  149. $list['印件代号'] = '';
  150. $list['印件ID'] = '';
  151. }else{
  152. $list['印件名称'] = $printData['印件名称'];
  153. $list['印件代号'] = $printData['印件代号'];
  154. $list['印件ID'] = $printData['id'];
  155. }
  156. $this->success('成功',$list);
  157. }
  158. /**
  159. * 工单资料修改
  160. * @ApiMethod (POST)
  161. * @param void
  162. * @return void
  163. * @throws \think\Exception
  164. * @throws \think\exception\PDOException
  165. */
  166. public function WorkOrderEdit()
  167. {
  168. if (Request::instance()->isPost() === false){
  169. $this->error('请求错误');
  170. }
  171. $param = Request::instance()->post();
  172. if (empty($param) || isset($param['Uniqid']) === false){
  173. $this->error('参数错误');
  174. }
  175. $row = [
  176. 'Gd_lx' => isset($param['lx'])?$param['lx']:'',
  177. '开单日期' => isset($param['kdrq'])?$param['kdrq']:'',
  178. 'Gd_gdbh' => isset($param['gdbh'])?$param['gdbh']:'',
  179. 'Gd_生产分类' => isset($param['scfl'])?$param['scfl']:'',
  180. 'Gd_客户代号' => isset($param['khdh'])?$param['khdh']:'',
  181. 'Gd_客户名称' => isset($param['khmc'])?$param['khmc']:'',
  182. '成品代号' => isset($param['cpdh'])?$param['cpdh']:'',
  183. '成品名称' => isset($param['cpmc'])?$param['cpmc']:'',
  184. '订单数量' => isset($param['ddsl'])?$param['ddsl']:'',
  185. '交货日期' => isset($param['jhrq'])?$param['jhrq']:'',
  186. '投料率' => isset($param['tll'])?$param['tll']:'',
  187. '计划投料' => isset($param['jhtl'])?$param['jhtl']:'',
  188. '实际投料' => isset($param['sjtl'])?$param['sjtl']:'',
  189. '计量单位' => isset($param['jldw'])?$param['jldw']:'',
  190. '投料大箱' => isset($param['tldx'])?$param['tldx']:'',
  191. '销售订单号' => isset($param['xsddh'])?$param['xsddh']:'',
  192. '警语版面' => isset($param['jymb'])?$param['jymb']:'',
  193. '产品版本号' => isset($param['bbh'])?$param['bbh']:'',
  194. '客户ERP编码' => isset($param['erp'])?$param['erp']:'',
  195. '码源数量' => isset($param['ymsl'])?$param['ymsl']:'',
  196. '进程备注' => isset($param['jcbz'])?$param['jcbz']:'',
  197. 'Gd_desc' => isset($param['desc'])?$param['desc']:'',
  198. '排产时库存' => isset($param['kc'])?$param['kc']:'',
  199. '平均合格率' => isset($param['avg'])?$param['avg']:'',
  200. ];
  201. //获取印件资料
  202. $printCode = \db('工单_印件资料')
  203. ->where('Uniqid',$param['printID'])
  204. ->value('yj_Yjno');
  205. if (!empty($printCode)){
  206. if ((int)$param['jhtl'] >0){
  207. //修改工单工艺计划产量
  208. $result = $this->PlannedProcessYield($param['gdbh'],$printCode,0,$param['jhtl']);
  209. if ($result === false){
  210. $this->success('分配工序计划产量失败');
  211. }
  212. }
  213. //修改印件信息
  214. $printSql = \db('工单_印件资料')
  215. ->where('Uniqid',$param['printID'])
  216. ->fetchSql(true)
  217. ->update(['Yj_Gdbh'=>$param['gdbh'],'yj_yjmc'=>$param['yjmc'],'yj_Yjdh'=>$param['yjdh'],'yj_平张投料'=>$param['jhtl']]);
  218. $printRes = Db::query($printSql);
  219. }
  220. //修改工单信息
  221. $sql = \db('工单_基本资料')->where('Uniqid',$param['Uniqid'])->fetchSql(true)->update($row);
  222. $res = Db::query($sql);
  223. //修改订单数量该工单下的订单数量
  224. //1. 查询该id下的工单编号, 防止其手动修改工单编号导致条件错误
  225. $gdbh = \db('工单_基本资料')->where('Uniqid',$param['Uniqid'])->value('Gd_gdbh');
  226. //2. 根据查出的工单编号修改订单数量
  227. $sql = \db('工单_基本资料')->where('Gd_gdbh',$param['gdbh'])->fetchSql(true)->update(['订单数量'=>$row['订单数量']]);
  228. $res1 = Db::query($sql);
  229. if ($res !== false && $res1 !== false){
  230. $this->success('成功');
  231. }else{
  232. $this->error('失败');
  233. }
  234. }
  235. /**
  236. * U8投料试算
  237. * @ApiMethod (GET)
  238. * @param string $processCode 产品编号
  239. * @return void
  240. * @throws \think\db\exception\DataNotFoundException
  241. * @throws \think\db\exception\ModelNotFoundException
  242. * @throws \think\exception\DbException
  243. */
  244. public function U8Trial()
  245. {
  246. if ($this->request->isGet() === false)
  247. {
  248. $this->error('请求错误');
  249. }
  250. $productCode = input('productCode');
  251. if (empty($productCode)){
  252. $this->error('参数错误');
  253. }
  254. $field = 'rtrim(Gy0_cpdh) as 产品代号,rtrim(Gy0_yjno) as 印件号,rtrim(Gy0_gxh) as 工序号,rtrim(gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
  255. rtrim(Gy0_Ms) as 墨色数,rtrim(Gy0_shdh) as 损耗代号,rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ls) as 加工联数';
  256. $list = \db('产品_工艺资料')->where('Gy0_cpdh',$productCode)->field($field)->select();
  257. if (empty($list)){
  258. $this->success('未找到该产品工序');
  259. }
  260. foreach ($list as $key=>$value){
  261. $data = \db('dic_lzsh')->where('sys_bh',$value['损耗代号'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->cache(true)->find();
  262. $list[$key]['调机损耗'] = isset($data['rate0'])?$data['rate0']:'';
  263. $list[$key]['运行损耗率'] = isset($data['rate1'])?$data['rate1']:'';
  264. if ($value['add_gxmc'] !== ''){
  265. $list[$key]['工序名称'] = $value['gxmc'].'【'.$value['add_gxmc'].'】';
  266. }else{
  267. $list[$key]['工序名称'] = $value['gxmc'];
  268. }
  269. unset($list[$key]['gxmc'],$list[$key]['add_gxmc']);
  270. }
  271. $this->success('成功',$list);
  272. }
  273. /**
  274. * 引用产品资料->获取产品资料
  275. * @ApiMethod (GET)
  276. * @param string $workOrder 工单编号
  277. * @return void
  278. * @throws \think\db\exception\DataNotFoundException
  279. * @throws \think\db\exception\ModelNotFoundException
  280. * @throws \think\exception\DbException
  281. */
  282. public function ProductInformation()
  283. {
  284. if ($this->request->isGet() === false)
  285. {
  286. $this->error('请求错误');
  287. }
  288. $workOrder = input('workOrder');
  289. if (empty($workOrder)){
  290. $this->error('参数错误');
  291. }
  292. $field = 'rtrim(Gd_gdbh) as 工单编号,rtrim(Gd_客户名称) as 客户名称,rtrim(成品代号) as 产品代号,rtrim(成品名称) as 产品名称';
  293. $Detail = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field($field)->find();
  294. if (empty($Detail)){
  295. $this->success('未找到工单信息');
  296. }
  297. $Detail['客户代号'] = substr($Detail['产品代号'],0,4);
  298. $this->success('成功',$Detail);
  299. }
  300. /**
  301. * 引用产品资料->复制产品工艺资料
  302. * @ApiMethod (POST)
  303. * @param string $oldWorkOrder 被复制工单编号
  304. * @param string $newWorkOrder 复制工单编号
  305. * @return void
  306. * @throws \think\Exception
  307. * @throws \think\db\exception\DataNotFoundException
  308. * @throws \think\db\exception\ModelNotFoundException
  309. * @throws \think\exception\DbException
  310. * @throws \think\exception\PDOException
  311. */
  312. public function ProductInformationEdit()
  313. {
  314. if (Request::instance()->isPost() === false)
  315. {
  316. $this->error('请求错误');
  317. }
  318. $oldWorkOrder = input('oldWorkOrder');
  319. $newWorkOrder = input('newWorkOrder');
  320. if (empty($oldWorkOrder) || empty($newWorkOrder))
  321. {
  322. $this->error('参数错误');
  323. }
  324. $lastId = \db('工单_工艺资料')->order('UniqId desc')->value('UniqId');
  325. if ($lastId<10000000){
  326. $lastId = 10000000;
  327. }else{
  328. $lastId = $lastId + 1;
  329. }
  330. //获取原工单工艺资料
  331. $oldProcessData = \db('工单_工艺资料')->where('Gy0_gdbh',$newWorkOrder)->select();
  332. $ProsessUniqId = \db('工单_工艺资料')->field('UniqId')->order('UniqId desc')->find();
  333. foreach ($oldProcessData as $k=>$v){
  334. $oldProcessData[$k]['Gy0_gdbh'] = $oldWorkOrder;
  335. $oldProcessData[$k]['Sys_id'] = '';
  336. $oldProcessData[$k]['Gy0_sj1'] = '1900-01-01 00:00:00';
  337. $oldProcessData[$k]['Gy0_sj2'] = '1900-01-01 00:00:00';
  338. $oldProcessData[$k]['UniqId'] = $lastId + $k;
  339. $oldProcessData[$k]['PD_WG'] = '1900-01-01 00:00:00';
  340. }
  341. if (\db('工单_工艺资料')->where('Gy0_gdbh',$oldWorkOrder)->find()){
  342. \db('工单_工艺资料')->where('Gy0_gdbh',$oldWorkOrder)->delete();
  343. }
  344. //获取原工单印件资料
  345. $lastUniqId = \db('工单_印件资料')->order('UniqId desc')->value('UniqId');
  346. if ($lastUniqId<1000000){
  347. $lastUniqId = 1000000;
  348. }else{
  349. $lastUniqId = $lastUniqId + 1;
  350. }
  351. $oldPrintData = \db('工单_印件资料')->where('Yj_Gdbh',$newWorkOrder)->select();
  352. $PrintUniqId = \db('工单_印件资料')->field('Uniqid')->order('Uniqid desc')->find();
  353. foreach ($oldPrintData as $k=>$v){
  354. $oldPrintData[$k]['Yj_Gdbh'] = $oldWorkOrder;
  355. $oldPrintData[$k]['Sys_id'] = '';
  356. $oldPrintData[$k]['Uniqid'] = $lastUniqId +$k +1;
  357. }
  358. if (\db('工单_印件资料')->where('Yj_Gdbh',$oldWorkOrder)->find()){
  359. \db('工单_印件资料')->where('Yj_Gdbh',$oldWorkOrder)->delete();
  360. }
  361. //复制印件、工艺资料
  362. $ProcessSQL = \db('工单_工艺资料')->fetchSql(true)->insertAll($oldProcessData);
  363. $ProcessRes = Db::query($ProcessSQL);
  364. $PrintSQL = \db('工单_印件资料')->fetchSql(true)->insertAll($oldPrintData);
  365. $PrintRes = Db::query($PrintSQL);
  366. if ($ProcessRes !== false && $PrintRes !== false){
  367. $this->success('成功');
  368. }else{
  369. $this->error('失败');
  370. }
  371. }
  372. /**
  373. * 工艺流程调成->获取当前工单工艺资料
  374. * @ApiMethod (GET)
  375. * @param string $workorder 当前工单编号
  376. * @return void
  377. * @throws \think\db\exception\DataNotFoundException
  378. * @throws \think\db\exception\ModelNotFoundException
  379. * @throws \think\exception\DbException
  380. */
  381. public function ProcessFlow()
  382. {
  383. if ($this->request->isGet() === false){
  384. $this->error('请求错误');
  385. }
  386. $workOrder = input('workOrder');
  387. if (empty($workOrder)){
  388. $this->error('参数错误');
  389. }
  390. $list = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field('rtrim(成品代号) as 成品编号,rtrim(成品名称) as 成品名称')->find();
  391. if (empty($list)){
  392. $this->success('未找到工单信息');
  393. }
  394. $filed = 'rtrim(Gy0_方案) as 方案,rtrim(Gy0_yjno) as 印件号,rtrim(Gy0_gxh) as 工序号,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
  395. rtrim(工价系数) as 工价系数,rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ks) as ks,rtrim(Gy0_ls) as ls,rtrim(工序备注) as 备注,rtrim(Gy0_SITE) as 车间,
  396. rtrim(Gy0_sbbh) as 设备编号,rtrim(Gy0_sbmc) as 设备名称,rtrim(Sys_id) as 建档用户,rtrim(Sys_rq) as 建档时间,rtrim(Mod_rq) as 更新时间,rtrim(UniqId) as UniqId';
  397. $process = \db('工单_工艺资料')->where('Gy0_gdbh',$workOrder)->cache(true,84600)->field($filed)->select();
  398. if (empty($process)){
  399. $this->error('未找到该工单工艺资料');
  400. }
  401. foreach ($process as $key=>$value){
  402. if (isset($value['add_gxmc'])){
  403. $process[$key]['工序名称'] = $value['gxmc'] . '【'.$value['add_gxmc'].'】';
  404. }else{
  405. $process[$key]['工序名称'] = $value['gxmc'];
  406. }
  407. $process[$key]['工价系数'] = (float)$value['工价系数'];
  408. $process[$key]['损耗系数'] = (float)$value['损耗系数'];
  409. $process[$key]['开数*联数'] = $value['ks'].'*'.$value['ls'];
  410. }
  411. $list['process'] = $process;
  412. $this->success('成功',$list);
  413. }
  414. /**
  415. * 参照工单列表获取
  416. * @ApiMethod (GET)
  417. * @param string $workOrder 工单编号
  418. * @param string $productCode 产品代号
  419. * @return void
  420. */
  421. public function ReferenceWorkOrder()
  422. {
  423. if ($this->request->isGet() === false){
  424. $this->error('请求错误');
  425. }
  426. $productCode = input('productCode');
  427. $workOrder = input('workOrder');
  428. if (empty($productCode) || empty($workOrder)){
  429. $this->error('参数错误');
  430. }
  431. $list = \db('工单_基本资料')->where('成品代号',$productCode)->distinct(true)->where('Gd_gdbh','<>',$workOrder)->column('Gd_gdbh');
  432. if (empty($list)){
  433. $this->success('未获取该产品其他工单信息');
  434. }
  435. $this->success('成功',$list);
  436. }
  437. /**
  438. * 工艺资料复制
  439. * @ApiMethod (POST)
  440. * @param string $oldWorkOrder 被复制工单编号
  441. * @param string $newWorkOrder 复制工单编号
  442. * @return void
  443. * @throws \think\Exception
  444. * @throws \think\db\exception\DataNotFoundException
  445. * @throws \think\db\exception\ModelNotFoundException
  446. * @throws \think\exception\DbException
  447. * @throws \think\exception\PDOException
  448. *
  449. */
  450. public function ProcessCopy()
  451. {
  452. if (Request::instance()->isPost() === false){
  453. $this->error('请求错误');
  454. }
  455. $param = Request::instance()->post();
  456. if (empty($param)){
  457. $this->error('参数错误');
  458. }
  459. $UniqId = [];
  460. $lastId = \db('工单_工艺资料')->field('rtrim(UniqId) as id')->order('UniqId desc')->find();
  461. if ($lastId['id']>10000000){
  462. $lastUniqId = $lastId['id'];
  463. }else{
  464. $lastUniqId = 10000000;
  465. }
  466. foreach ($param as $key=>$value){
  467. $UniqId[$key] = $value['UniqId'];
  468. }
  469. $processList = \db('工单_工艺资料')->where('UniqId','in',$UniqId)->select();
  470. if (empty($processList)){
  471. $this->success('未找到工艺资料');
  472. }
  473. $data = [];
  474. foreach ($param as $key=>$value){
  475. foreach ($processList as $k=>$v){
  476. if ($value['UniqId'] = $v['UniqId']){
  477. $data[$key] = $v;
  478. $data[$key]['Gy0_gxh'] = $value['gxh'];
  479. $data[$key]['Gy0_gdbh'] = $value['workOrder'];
  480. $data[$key]['UniqId'] = $lastUniqId + $key + 1;
  481. }
  482. }
  483. }
  484. $res = \db('工单_工艺资料')->where(['Gy0_gdbh'=>$param[0]['workOrder']])->delete();
  485. if ($res !== false){
  486. $result = \db('工单_工艺资料')->insertAll($data);
  487. if ($result !== false){
  488. $this->success('成功');
  489. }else{
  490. $this->error('失败');
  491. }
  492. }else{
  493. $this->error('失败');
  494. }
  495. }
  496. /**
  497. * U8工单列表
  498. * @ApiMethod (GET)
  499. * @param void
  500. * @return void
  501. * @throws \think\db\exception\DataNotFoundException
  502. * @throws \think\db\exception\ModelNotFoundException
  503. * @throws \think\exception\DbException
  504. */
  505. public function U8workOrder()
  506. {
  507. if ($this->request->isGet() === false){
  508. $this->error('请求错误');
  509. }
  510. $param = $this->request->param();
  511. if (empty($param)){
  512. $this->error('参数错误');
  513. }
  514. $filed = 'rtrim(Gd_gdbh) as 工单编号,rtrim(行号) as 行号,rtrim(Gd_客户代号) as 客户代号,rtrim(Gd_客户名称) as 客户名称,
  515. rtrim(成品代号) as 成品代号,rtrim(成品名称) as 成品名称,rtrim(Mod_rq) as 获取日期,rtrim(Uniqid) as 序号';
  516. $list = \db('工单_基本资料')->where('Gd_gdbh',$param['workOrder'])->field($filed)->select();
  517. if (empty($list)){
  518. $this->success('未找到工单');
  519. }
  520. $this->success('成功',$list);
  521. }
  522. /**
  523. * U8工单资料删除
  524. * @param string $workOrder 工单编号
  525. * @return void
  526. * @throws \think\Exception
  527. * @throws \think\exception\PDOException
  528. */
  529. public function U8DataCorrection()
  530. {
  531. if($this->request->isGet() === false){
  532. $this->error('请求错误');
  533. }
  534. $workOrder = input('Uniqid');
  535. if (empty($workOrder)){
  536. $this->error('参数错误');
  537. }
  538. $data = [];
  539. if (strpos($workOrder,',')){
  540. $data = explode(',',$workOrder);
  541. }else{
  542. $data[0] = $workOrder;
  543. }
  544. $res = \db('工单_基本资料')->where('Uniqid','in',$data)->delete();
  545. if ($res !== false){
  546. $this->success('成功');
  547. }else{
  548. $this->error('失败');
  549. }
  550. }
  551. /**
  552. * 产品废检系数调整->质检工艺数据获取
  553. * @ApiMethod (GET)
  554. * @param string $workOrder 工单编号
  555. * @return void
  556. * @throws \think\db\exception\DataNotFoundException
  557. * @throws \think\db\exception\ModelNotFoundException
  558. * @throws \think\exception\DbException
  559. */
  560. public function TestCoefficient()
  561. {
  562. if ($this->request->isGet() === false){
  563. $this->error('请求错误');
  564. }
  565. $workOrder = input('workOrder');
  566. if (empty($workOrder)){
  567. $this->error('参数错误');
  568. }
  569. $where = [
  570. 'Gy0_gdbh' => $workOrder,
  571. 'Gy0_gxmc' => ['like','%检%']
  572. ];
  573. $filed = 'rtrim(Gy0_gdbh) as gdbh,rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(人工检_正品板) as 人工正品板,
  574. rtrim(人工检_次品板) as 人工次品板,rtrim(人工检_废检) as 人工废检,rtrim(机检_正品板) as 机检正品板,rtrim(机检_次品板) as 机检次品板,
  575. rtrim(机检_废检) as 机检废检,rtrim(Gy0_sbbh) as 设备编号,rtrim(Uniqid) as Uniqid';
  576. $list = \db('工单_工艺资料')->where($where)->field($filed)->select();
  577. if (empty($list)){
  578. $this->success('未找到该工单工艺');
  579. }
  580. $name = \db('工单_基本资料')
  581. ->where('Gd_gdbh',$workOrder)
  582. ->field('rtrim(Gd_cpdh) as 产品代号,rtrim(Gd_khmc) as 客户名称,rtrim(Gd_cpmc) as 产品名称')
  583. ->find();
  584. if (empty($name)){
  585. $this->success('未找到该工单');
  586. }
  587. foreach ($list as $key=>$value){
  588. if ($value['yjno']<10){
  589. $value['yjno'] = '0'.$value['yjno'];
  590. }
  591. if ($value['gxh']<10){
  592. $value['gxh'] = '0'.$value['gxh'];
  593. }
  594. $list[$key]['印件工序及工艺'] = $value['gdbh'].'-'.$value['yjno'].'-'.$value['gxh'].'-'.$value['gxmc'];
  595. unset($list[$key]['gdbh'],$list[$key]['yjno'],$list[$key]['gxmc']);
  596. $list[$key]['产品编号'] = $name['产品代号'];
  597. $list[$key]['产品名称'] = $name['产品名称'];
  598. $list[$key]['客户名称'] = $name['客户名称'];
  599. }
  600. $this->success('成功',$list);
  601. }
  602. /**
  603. * 产品质检系数调整->系数修改
  604. * @ApiMethod (GET)
  605. * @param string $workorder 工单编号
  606. * @param string $processCode 工序号
  607. * @param float $code1 人工正品板
  608. * @param float $code2 人工次品板
  609. * @param float $code3 人工废检
  610. * @param float $code4 机检正品板
  611. * @param float $code5 机检次品板
  612. * @param float $code6 机检废检
  613. * @return void
  614. * @throws \think\Exception
  615. * @throws \think\exception\PDOException
  616. */
  617. public function TestCoefficientEdit()
  618. {
  619. if (Request::instance()->isPost() === false){
  620. $this->error('请求错误');
  621. }
  622. $workOrder = input('workOrder');
  623. $processCode = input('processCode');
  624. $row = [
  625. '人工检_正品板' => input('code1'),
  626. '人工检_次品板' => input('code2'),
  627. '人工检_废检' => input('code3'),
  628. '机检_正品板' => input('code4'),
  629. '机检_次品板' => input('code5'),
  630. '机检_废检' => input('code6'),
  631. ];
  632. if (empty($workOrder) || empty($processCode)){
  633. $this->error('参数错误');
  634. }
  635. $where = [
  636. 'Gy0_gdbh' => $workOrder,
  637. 'Gy0_gxh' => $processCode
  638. ];
  639. $sql = \db('工单_工艺资料')->where($where)->fetchSql(true)->update($row);
  640. $res = Db::query($sql);
  641. if ($res !== false){
  642. $this->success('成功');
  643. }else{
  644. $this->error('失败');
  645. }
  646. }
  647. /**
  648. * 修正工单核算参数->数据获取
  649. * @ApiMethod (GET)
  650. * @param string $workOrder 工单编号
  651. * @return void
  652. * @throws \think\db\exception\DataNotFoundException
  653. * @throws \think\db\exception\ModelNotFoundException
  654. * @throws \think\exception\DbException
  655. */
  656. public function AccountingParameter()
  657. {
  658. if ($this->request->isGet() === false){
  659. $this->error('请求错误');
  660. }
  661. $workOrder = input('workOrder');
  662. if (empty($workOrder)){
  663. $this->error('参数错误');
  664. }
  665. $field = 'rtrim(Gy0_方案) as 方案,rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
  666. rtrim(Gy0_sbbh) as 参照设备,rtrim(工价系数) as 难度系数,rtrim(Gy0_shdh) as 损耗代号,rtrim(Gy0_Rate0) as 基础损耗,rtrim(Gy0_Rate1) as 损耗率,
  667. rtrim(印刷方式) as 印刷方式,rtrim(版距) as 版距,rtrim(Gy0_ms) as 计损色数,rtrim(损耗系数) as 损耗系数,rtrim(UniqId) as UniqId';
  668. $list = \db('工单_工艺资料')->where('Gy0_gdbh',$workOrder)->field($field)->select();
  669. if (empty($list)){
  670. $this->success('未找到该工单工艺资料');
  671. }
  672. foreach ($list as $key=>$value){
  673. if ($value['yjno']<10){
  674. $value['yjno'] = '0'.$value['yjno'];
  675. }
  676. if ($value['gxh']<10){
  677. $value['gxh'] = '0'.$value['gxh'];
  678. }
  679. $list[$key]['印件号及工序名称'] = $value['yjno'].'-'.$value['gxh'].$value['gxmc'].'('.$value['add_gxmc'].')';
  680. unset($list[$key]['yjno'],$list[$key]['gxmc'],$list[$key]['add_gxmc']);
  681. }
  682. $this->success('成功',$list);
  683. }
  684. /**
  685. * 修正工单核算参数->参数修改
  686. * @ApiMethod (POST)
  687. * @param void
  688. * @return void
  689. * @throws \think\Exception
  690. * @throws \think\db\exception\DataNotFoundException
  691. * @throws \think\db\exception\ModelNotFoundException
  692. * @throws \think\exception\DbException
  693. * @throws \think\exception\PDOException
  694. */
  695. public function AccountingParameterEdit()
  696. {
  697. if (Request::instance()->isPost() === false){
  698. $this->error('请求错误');
  699. }
  700. $param = Request::instance()->post();
  701. if (empty($param) || isset($param[0]['Uniqid']) === false){
  702. $this->error('参数错误');
  703. }
  704. $i = 0;
  705. foreach ($param as $key=>$value){
  706. $data['rate0'] = 0;
  707. $data['rate1'] = 0;
  708. $rate = \db('dic_lzsh')->where('sys_bh',$value['loss'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
  709. if (!empty($rate)){
  710. $data['rate0'] = $rate['rate0'];
  711. $data['rate1'] = $rate['rate1'];
  712. }
  713. $row = [
  714. '工价系数' => $value['difficulty']?:'',
  715. 'Gy0_shdh' => $value['loss']?:'',
  716. '印刷方式' => $value['printMode']?:'',
  717. '版距' => $value['plate']?:'',
  718. 'Gy0_ms' => $value['chromatic']?:'',
  719. '损耗系数' => $value['wastage']?:'',
  720. 'Gy0_Rate0' => $data['rate0'],
  721. 'Gy0_Rate1' => $data['rate1']
  722. ];
  723. $sql = \db('工单_工艺资料')->where('Uniqid',$value['Uniqid'])->fetchSql(true)->update($row);
  724. $res = Db::query($sql);
  725. if ($res !== false){
  726. $i++;
  727. }
  728. }
  729. if ($i !== 0){
  730. $this->success('成功');
  731. }else{
  732. $this->error('失败');
  733. }
  734. }
  735. /**
  736. * 印件资料修改
  737. * @ApiMethod (POST)
  738. * @param void
  739. * @return void
  740. * @throws \think\Exception
  741. * @throws \think\exception\PDOException
  742. */
  743. public function PrintedEdit()
  744. {
  745. if (Request::instance()->isPost() === false){
  746. $this->error('请求错误');
  747. }
  748. $param = Request::instance()->post();
  749. if (empty($param) || isset($param['Uniqid']) === false){
  750. $this->error('参数错误');
  751. }
  752. $param['Yj_Gdbh'] = \db('工单_印件资料')->where('Uniqid',$param['Uniqid'])->value('Yj_Gdbh');
  753. $data = [
  754. 'Yj_Gdbh' =>$param['Yj_Gdbh'],
  755. 'yj_Yjno' =>$param['yjno'],
  756. 'yj_Yjdh' =>$param['yjdh'],
  757. 'yj_yjmc' =>$param['yjmc'],
  758. 'yj_zzdh' =>$param['zzdh'],
  759. 'yj_zzdh1' =>$param['zzdh1'],
  760. 'yj_zzdh2' =>$param['zzdh2'],
  761. 'yj_zzdh3' =>$param['zzdh3'],
  762. 'yj_zzdh4' =>$param['zzdh4'],
  763. 'yj_zzmc' =>$param['zzmc'],
  764. 'yj_zzmc1' =>$param['zzmc1'],
  765. 'yj_zzmc2' =>$param['zzmc2'],
  766. 'yj_zzmc3' =>$param['zzmc3'],
  767. 'yj_zzmc4' =>$param['zzmc4'],
  768. 'yj_tlgg' =>$param['tlgg'],
  769. 'yj_klgg' =>$param['klgg'],
  770. 'Yj_核算规格' =>$param['hsgg'],
  771. 'yj_成品数量' =>$param['cpsl'],
  772. 'yj_平张投料' =>$param['pztl'],
  773. 'yj_ks' =>$param['ks'],
  774. 'yj_ls' =>$param['ls'],
  775. 'yj_desc' =>$param['desc'],
  776. ];
  777. $UniqId = $param['Uniqid'];
  778. $sql = \db('工单_印件资料')->where('Uniqid',$UniqId)->fetchSql(true)->update($data);
  779. $res = Db::query($sql);
  780. $process = \db('工单_工艺资料')
  781. ->where('Gy0_gdbh',$data['Yj_Gdbh'])
  782. ->where('Gy0_yjno',$data['yj_Yjno'])
  783. ->select();
  784. if ((int)$data['yj_平张投料'] > 0 && !empty($process)){
  785. //重新分配工序计划产量
  786. $result = $this->PlannedProcessYield($data['Yj_Gdbh'],$data['yj_Yjno'],0,$data['yj_平张投料']);
  787. if ($result === false){
  788. $this->success('修改工序产量失败');
  789. }
  790. }
  791. if ($res !== false){
  792. $this->success('成功');
  793. }else{
  794. $this->error('失败');
  795. }
  796. }
  797. /**
  798. * 工艺资料修改
  799. * @ApiMethod (POST)
  800. * @param void
  801. * @return void
  802. * @throws \think\Exception
  803. * @throws \think\db\exception\DataNotFoundException
  804. * @throws \think\db\exception\ModelNotFoundException
  805. * @throws \think\exception\DbException
  806. * @throws \think\exception\PDOException
  807. */
  808. public function ProcessDetailEdit()
  809. {
  810. if (Request::instance()->isPost() === false){
  811. $this->error('请求错误');
  812. }
  813. $param = Request::instance()->post();
  814. if (empty($param) || isset($param['UniqId']) === false){
  815. $this->error('参数错误');
  816. }
  817. if (empty($param['Gy0_shdh'])){
  818. $rate['rate0'] = 0;
  819. $rate['rate1'] = 0;
  820. }else{
  821. $rate = \db('dic_lzsh')->where('sys_bh',$param['Gy0_shdh'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
  822. }
  823. $param['Gy0_Rate0']= isset($rate['rate0'])?$rate['rate0']:0;
  824. $param['Gy0_Rate1'] = isset($rate['rate1'])?$rate['rate1']:0;
  825. $param['Mod_rq'] = date('Y-m-d H:i:s',time());
  826. $UniqId = $param['UniqId'];
  827. unset($param['UniqId']);
  828. //修改工艺资料
  829. $sql = \db('工单_工艺资料')->where('UniqId',$UniqId)->fetchSql(true)->update($param);
  830. $res = Db::query($sql);
  831. //获取工艺资料数据
  832. $list = \db('工单_工艺资料')->where('UniqId',$UniqId)->field('Gy0_yjno,Gy0_gxh,rtrim(Gy0_计划接货数) as 计划接货数')->find();
  833. //修改工单状态
  834. $status = \db('工单_基本资料')->where('Gd_gdbh',$param['Gy0_gdbh'])->field('rtrim(gd_statu) as status')->find();
  835. if ($status['status'] !== '2-生产中'){
  836. $statusSql = \db('工单_基本资料')->where('Gd_gdbh',$param['Gy0_gdbh'])->fetchSql(true)->update(['gd_statu'=>'2-生产中']);
  837. Db::query($statusSql);
  838. }
  839. //重新分配工序计划产量
  840. if ((int)$list['计划接货数'] > 0){
  841. $result = $this->PlannedProcessYield($param['Gy0_gdbh'],$list['Gy0_yjno'],$list['Gy0_gxh'],$list['计划接货数']);
  842. }
  843. if ($res !== false){
  844. $this->success('成功');
  845. }else{
  846. $this->error('失败');
  847. }
  848. }
  849. /**
  850. * 工艺资料编辑->机台列表获取
  851. * @return void
  852. * @throws \think\db\exception\DataNotFoundException
  853. * @throws \think\db\exception\ModelNotFoundException
  854. * @throws \think\exception\DbException
  855. */
  856. public function MachineList()
  857. {
  858. if ($this->request->isGet() === false){
  859. $this->error('请求错误');
  860. }
  861. $param = $this->request->param();
  862. if (empty($param)){
  863. $this->error('参数错误');
  864. }
  865. $list = \db('设备_基本资料')
  866. ->where('存放地点',$param['address'])
  867. ->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')
  868. ->select();
  869. if (empty($list)){
  870. $this->success('未找到该车间机台');
  871. }
  872. $data = [];
  873. foreach ($list as $key=>$value){
  874. $data[$key] = $value['设备编号'].'-->'.$value['设备名称'];
  875. }
  876. $this->success('成功',$data);
  877. }
  878. /**
  879. * 打印作业通知单->工单印件和工序获取
  880. * @ApiMethod (GET)
  881. * @return void
  882. * @throws \think\db\exception\DataNotFoundException
  883. * @throws \think\db\exception\ModelNotFoundException
  884. * @throws \think\exception\DbException
  885. */
  886. public function PrintCodeList()
  887. {
  888. if ($this->request->isGet() === false){
  889. $this->error('请求错误');
  890. }
  891. $param = $this->request->param();
  892. if (empty($param)){
  893. $this->error('参数错误');
  894. }
  895. $list = \db('工单_印件资料')
  896. ->field([
  897. 'rtrim(yj_Yjno)' => '印件号',
  898. 'rtrim(yj_yjmc)' => '印件名称'
  899. ])
  900. ->where('Yj_Gdbh',$param['workOrder'])
  901. ->select();
  902. $this->success('成功',$list);
  903. }
  904. /**
  905. * 打印作业通知单->工艺编号获取
  906. * @ApiMethod (GET)
  907. * @return void
  908. * @throws \think\db\exception\DataNotFoundException
  909. * @throws \think\db\exception\ModelNotFoundException
  910. * @throws \think\exception\DbException
  911. */
  912. public function ProcessCodeList()
  913. {
  914. if ($this->request->isGet() === false){
  915. $this->error('请求错误');
  916. }
  917. $param = $this->request->param();
  918. if (empty($param)){
  919. $this->error('参数错误');
  920. }
  921. $list = \db('工单_工艺资料')
  922. ->field('rtrim(Gy0_gxh) as 工序号')
  923. ->where([
  924. 'Gy0_gdbh' => $param['workOrder'],
  925. 'Gy0_yjno' => $param['yjno']
  926. ])
  927. ->select();
  928. $this->success('成功',$list);
  929. }
  930. /**
  931. * 打印作业通知单
  932. * @ApiMethod (POST)
  933. * @param void
  934. * @return void
  935. * @throws \think\db\exception\DataNotFoundException
  936. * @throws \think\db\exception\ModelNotFoundException
  937. * @throws \think\exception\DbException
  938. */
  939. public function PrintJobOrder()
  940. {
  941. if ($this->request->isGet() === false) {
  942. $this->error('请求错误');
  943. }
  944. $param = $this->request->param();
  945. if (empty($param)){
  946. $this->error('参数错误');
  947. }
  948. $data = $this->workOrderDetailGet($param['workOrder'],$param['yjno']);
  949. if (empty($data)){
  950. $this->success('未找到工单信息');
  951. }
  952. $materiel = $this->MaterielDetailGet($param['workOrder']);
  953. $printDetail = $this->PrintDetailGet($param['workOrder'],$param['yjno'],$param['gxh']);
  954. if (empty($printDetail)){
  955. $this->success('未找到工艺信息');
  956. }
  957. $number = 0;
  958. foreach ($printDetail as $key=>$value){
  959. $value['允损比例'] = (float)substr($value['允损比例'],0,-1);
  960. $number = $number+$value['允损比例'];
  961. }
  962. $data['制单'] = $param['PrepareDocument'];
  963. $data['审核'] = $param['examine'];
  964. $data['目标合格率'] = 100-$number.'%';
  965. $data['materiel'] = $materiel;
  966. $data['printDetail'] = $printDetail;
  967. $this->success('成功',$data);
  968. }
  969. /**
  970. * 打印作业通知单->工单及印件资料获取
  971. * @param $workOrder
  972. * @return mixed
  973. */
  974. public function workOrderDetailGet($workOrder,$yjno)
  975. {
  976. $sql = "SELECT
  977. RTRIM( a.Gd_lx) AS 工单类型,
  978. RTRIM( a.Gd_gdbh ) AS 生产批次号,
  979. RTRIM( a.销售订单号 ) AS 销售订单号,
  980. RTRIM( a.Gd_客户代号 ) AS 客户代号,
  981. RTRIM( a.Gd_客户名称 ) AS 客户名称,
  982. RTRIM( a.成品代号 ) AS 产品代码,
  983. RTRIM( a.成品名称 ) AS 产品名称,
  984. RTRIM( a.产品版本号 ) AS 版本号,
  985. RTRIM( a.警语版面 ) AS 警语版面,
  986. RTRIM( a.码源数量 ) AS 码源数量,
  987. RTRIM( a.客户ERP编码 ) AS 客户ERP编码,
  988. RTRIM( a.接单日期 ) AS 开单日期,
  989. RTRIM( a.交货日期 ) AS 交货日期,
  990. RTRIM( a.Gd_desc ) AS 工单说明,
  991. RTRIM( a.投料率 ) AS 投料率,
  992. RTRIM( a.订单数量 ) AS 订单数量,
  993. RTRIM( a.平均合格率 ) AS 平均合格率,
  994. RTRIM( a.投料大箱 ) AS 订货数量,
  995. RTRIM( a.排产时库存 ) AS 排产时库存,
  996. RTRIM( b.yj_Yjno ) AS 印件,
  997. RTRIM( b.yj_Yjdh ) AS 印件代号,
  998. RTRIM( b.yj_yjmc ) AS 印件名称,
  999. RTRIM( b.yj_平张投料 ) AS 平张投料量,
  1000. RTRIM( b.yj_zzmc ) AS 纸张名称,
  1001. RTRIM( b.yj_tlgg ) AS 投料规格,
  1002. RTRIM( b.yj_ks ) AS 开数,
  1003. RTRIM( b.yj_ls ) AS 联数,
  1004. RTRIM( b.yj_desc ) AS 印件备注
  1005. FROM
  1006. `工单_基本资料` AS a
  1007. JOIN `工单_印件资料` AS b ON b.Yj_Gdbh = a.Gd_gdbh
  1008. WHERE
  1009. a.Gd_gdbh = '{$workOrder}' AND a.行号 = 1 AND b.yj_Yjno = '{$yjno}'";
  1010. $list = Db::query($sql);
  1011. if (empty($list)){
  1012. $this->success('未找到订单数据');
  1013. }
  1014. $list[0]['开单日期'] = date('Y-m-d',strtotime($list[0]['开单日期']));
  1015. $list[0]['交货日期'] = date('Y-m-d',strtotime($list[0]['交货日期']));
  1016. if (strpos($list[0]['产品名称'],'条') !== false){
  1017. $list[0]['订货数量'] = (int)$list[0]['订单数量']*40;
  1018. $list[0]['投料数量'] = intval($list[0]['平张投料量']*$list[0]['联数']/250);
  1019. }else{
  1020. $list[0]['订货数量'] = (int)$list[0]['订单数量']*4;
  1021. $list[0]['投料数量'] = intval($list[0]['平张投料量']*$list[0]['联数']/2500);
  1022. }
  1023. $list[0]['联数'] = (int)$list[0]['联数'];
  1024. $list[0]['印件代号及名称'] = $list[0]['印件代号'].' '.$list[0]['印件名称'];
  1025. // $list[0]['投料数量'] = $list[0]['订货数量'];
  1026. unset($list[0]['印件代号'],$list[0]['印件名称']);
  1027. return($list[0]);
  1028. }
  1029. /**打印作业流程单->物料资料获取
  1030. * @param $workOrder
  1031. * @return bool|\PDOStatement|string|\think\Collection
  1032. * @throws \think\db\exception\DataNotFoundException
  1033. * @throws \think\db\exception\ModelNotFoundException
  1034. * @throws \think\exception\DbException
  1035. */
  1036. public function MaterielDetailGet($workOrder)
  1037. {
  1038. $where = [
  1039. 'BOM_工单编号' => $workOrder,
  1040. ];
  1041. $filed = 'rtrim(BOM_物料编码) as 物料编码,rtrim(BOM_物料名称) as 物料名称,rtrim(BOM_投料单位) as 投料单位,rtrim(BOM_计划用量) as 计划用量';
  1042. $list = \db('工单_bom资料')->where($where)->field($filed)->select();
  1043. if (!empty($list)){
  1044. foreach ($list as $key=>$value){
  1045. $list[$key]['物料代码及名称'] = $value['物料编码'].' '.$value['物料名称'];
  1046. $list[$key]['计划用量'] = (float)$value['计划用量'];
  1047. unset($list[$key]['物料编码'],$list[$key]['物料名称']);
  1048. }
  1049. }
  1050. return $list;
  1051. }
  1052. /**
  1053. * 打印作业流程单->工艺资料获取
  1054. * @param $workOrder
  1055. * @return bool|\PDOStatement|string|\think\Collection
  1056. * @throws \think\db\exception\DataNotFoundException
  1057. * @throws \think\db\exception\ModelNotFoundException
  1058. * @throws \think\exception\DbException
  1059. */
  1060. public function PrintDetailGet($workOrder,$yjno,$gxh)
  1061. {
  1062. $where = [
  1063. 'Gy0_gdbh' => $workOrder,
  1064. 'Gy0_yjno' => $yjno,
  1065. 'Gy0_gxh' => ['<=',$gxh]
  1066. ];
  1067. $filed = 'rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
  1068. rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ls) as ls,rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_计划损耗) as 计划损耗,
  1069. rtrim(Gy0_辅助工时) as 装版工时,rtrim(Gy0_小时产能) as 小时定额,rtrim(Gy0_生产工时) as 生产工时,rtrim(工序备注) as 工序备注';
  1070. $list = \db('工单_工艺资料')
  1071. ->where($where)
  1072. ->field($filed)
  1073. ->select();
  1074. if (empty($list)){
  1075. $this->success('工单工艺为空');
  1076. }
  1077. foreach ($list as $key=>$value){
  1078. if ($value['yjno']<10){
  1079. $value['yjno'] = '0'.$value['yjno'];
  1080. }
  1081. if ($value['gxh']<10){
  1082. $value['gxh'] = '0'.$value['gxh'];
  1083. }
  1084. if ($value['add_gxmc'] !== null){
  1085. $list[$key]['印件及工序名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
  1086. }else{
  1087. $list[$key]['印件及工序名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'];
  1088. }
  1089. $list[$key]['转序数'] = (int)($value['计划接货数']/$value['ls']);
  1090. $list[$key]['报废定额'] = (int)($value['计划损耗']/$value['ls']);
  1091. if ((int)$value['计划接货数'] === 0){
  1092. $list[$key]['允损比例'] = 0;
  1093. }else{
  1094. $list[$key]['允损比例'] = round(($value['计划损耗']/$value['计划接货数'])*100,2).'%';
  1095. }
  1096. unset($list[$key]['yjno'],$list[$key]['gxh'],$list[$key]['gxmc'],$list[$key]['add_gxmc'],$list[$key]['计划接货数'],$list[$key]['计划损耗']);
  1097. }
  1098. return $list;
  1099. }
  1100. /**
  1101. * 获取小时产能
  1102. * @ApiMethod (GET)
  1103. * @param void
  1104. * @return void
  1105. * @throws \think\db\exception\DataNotFoundException
  1106. * @throws \think\db\exception\ModelNotFoundException
  1107. * @throws \think\exception\DbException
  1108. */
  1109. public function capacityList()
  1110. {
  1111. if ($this->request->isGet() === false){
  1112. $this->error('请求错误');
  1113. }
  1114. $param = $this->request->param();
  1115. if (empty($param)){
  1116. $this->error('参数错误');
  1117. }
  1118. $machine = explode(' ',$param['machine'])[0];
  1119. $number = \db('设备_基本资料')->where('设备编号',$machine)->field('rtrim(排单小时定额) as 小时产能')->find();
  1120. if (empty($number)){
  1121. $this->error('未找到小时产能');
  1122. }
  1123. $this->success('成功',$number['小时产能']);
  1124. }
  1125. /**
  1126. * 新增工单->添加工单
  1127. * @ApiMethod (POST)
  1128. * @param
  1129. * @return void
  1130. * @throws \think\Exception
  1131. * @throws \think\db\exception\BindParamException
  1132. * @throws \think\db\exception\DataNotFoundException
  1133. * @throws \think\db\exception\ModelNotFoundException
  1134. * @throws \think\exception\DbException
  1135. * @throws \think\exception\PDOException
  1136. */
  1137. public function WorkOrderAdd()
  1138. {
  1139. if (Request::instance()->isPost() === false){
  1140. $this->error('请求错误');
  1141. }
  1142. $param = Request::instance()->post();
  1143. if (empty($param)){
  1144. $this->error('参数错误');
  1145. }
  1146. $param['Sys_rq'] = date('Y-m-d',time());
  1147. $param['gd_statu'] = '1-计划中';
  1148. $sql= \db('工单_基本资料')->fetchSql(true)->insert($param);
  1149. $res = \db()->query($sql);
  1150. if ($res !== false){
  1151. $this->success('成功');
  1152. }else{
  1153. $this->error('失败');
  1154. }
  1155. }
  1156. /**
  1157. * 新增工单->客户代号列表获取
  1158. * @return void
  1159. * @throws \think\db\exception\BindParamException
  1160. * @throws \think\exception\PDOException
  1161. */
  1162. public function ClientList()
  1163. {
  1164. if ($this->request->isGet() === false){
  1165. $this->error('请求错误');
  1166. }
  1167. $param = $this->request->param();
  1168. if (isset($param['search'])){
  1169. $where = $param['search'].'%';
  1170. $sql = "SELECT DISTINCT
  1171. (客户编号),rtrim(客户名称 ) as 客户名称
  1172. FROM
  1173. `产品_基本资料`
  1174. WHERE
  1175. 客户编号 LIKE "."'".$where."'"."
  1176. OR
  1177. 客户名称 LIKE "."'".$where."'"."
  1178. GROUP BY
  1179. 客户编号
  1180. order by
  1181. 客户编号";
  1182. }else{
  1183. $sql = "SELECT DISTINCT
  1184. (客户编号),rtrim(客户名称 ) as 客户名称
  1185. FROM
  1186. `产品_基本资料`
  1187. GROUP BY
  1188. 客户编号
  1189. order by
  1190. 客户编号";
  1191. }
  1192. $list = \db()->query($sql);
  1193. if (empty($list)){
  1194. $this->success('未找到客户列表');
  1195. }
  1196. foreach ($list as $key=>$value){
  1197. if (empty($value['客户编号'])){
  1198. unset($list[$key]);
  1199. }else{
  1200. $list[$key]['客户编号'] = rtrim($value['客户编号']);
  1201. $list[$key]['name'] = rtrim($value['客户编号']).'【'.$value['客户名称'].'】';
  1202. if ($value['客户编号'] == '1098'){
  1203. $list[$key]['客户名称'] = '打样专用';
  1204. }
  1205. }
  1206. }
  1207. $list = array_values($list);
  1208. $this->success('成功',$list);
  1209. }
  1210. /**
  1211. * 新增工单->产品代号获取
  1212. * @ApiMethod (GET)
  1213. * @param void
  1214. * @return void
  1215. * @throws \think\db\exception\DataNotFoundException
  1216. * @throws \think\db\exception\ModelNotFoundException
  1217. * @throws \think\exception\DbException
  1218. */
  1219. public function ProductCodeList()
  1220. {
  1221. if ($this->request->isGet() === false){
  1222. $this->error('请求错误');
  1223. }
  1224. $param = $this->request->param();
  1225. if (isset($param['cilent']) === false){
  1226. $this->error('参数错误');
  1227. }
  1228. $where = ['产品编号'=>['like',$param['cilent'].'%']];
  1229. $list = \db('产品_基本资料')
  1230. ->where($where)
  1231. ->field('rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称')
  1232. ->select();
  1233. if (empty($list)){
  1234. $this->success('未获取到产品数据');
  1235. }
  1236. foreach ($list as $key=>$value){
  1237. $list[$key]['name'] = $value['产品编号'].'【'.$value['产品名称'].'】';
  1238. }
  1239. $this->success('成功',$list);
  1240. }
  1241. /**
  1242. * 新增印件资料->印件资料添加
  1243. * @return void
  1244. * @throws \think\db\exception\BindParamException
  1245. * @throws \think\exception\PDOException
  1246. */
  1247. public function PrintDetailAdd()
  1248. {
  1249. if (Request::instance()->isPost() === false){
  1250. $this->error('请求错误');
  1251. }
  1252. $param = Request::instance()->post();
  1253. if (empty($param)){
  1254. $this->error('参数错误');
  1255. }
  1256. $param['Sys_rq'] = date('Y-m-d H:i:s',time());
  1257. $process = [
  1258. ['1','仓库出库'],['2','裁切'],['3','车缝'],['4','后道收样'],['5','大烫'],['6','总检'],['7','包装']
  1259. ];
  1260. $processDetail = [];
  1261. foreach ($process as $key=>$value){
  1262. $total = null;
  1263. if ($key !== 0){
  1264. $total = $param['total'];
  1265. }
  1266. $processDetail[$key] = [
  1267. '订单编号' => $param['订单编号'],
  1268. '子订单编号' => $param['子订单编号'],
  1269. '款号' => $param['款号'],
  1270. '颜色' => $param['颜色'],
  1271. '工序编号' => $value[0],
  1272. '工序名称' => $value[1],
  1273. '计划产量' => $total,
  1274. 'Sys_id' => $param['Sys_id'],
  1275. 'Sys_rq' => $param['Sys_rq']
  1276. ];
  1277. }
  1278. //开启事务
  1279. db()->startTrans();
  1280. try{
  1281. $priSql = \db('工单_印件资料')->fetchSql(true)->insert($param);
  1282. $priRes = \db()->query($priSql);
  1283. $proSql = \db('工单_工艺资料')->fetchSql(true)->insertAll($processDetail);
  1284. $proRes = \db()->query($proSql);
  1285. // 提交事务
  1286. db()->commit();
  1287. } catch (\Exception $e) {
  1288. // 回滚事务
  1289. db()->rollback();
  1290. $this->error($e->getMessage());
  1291. }
  1292. if ($priRes !== false && $proRes !== false){
  1293. $this->success('成功');
  1294. }else{
  1295. $this->error('失败');
  1296. }
  1297. }
  1298. /**
  1299. * 新增工艺资料->工艺资料添加
  1300. * @return void
  1301. * @throws \think\db\exception\BindParamException
  1302. * @throws \think\exception\PDOException
  1303. */
  1304. public function ProcessDetailAdd()
  1305. {
  1306. if (Request::instance()->isPost() === false){
  1307. $this->error('请求错误');
  1308. }
  1309. $param = Request::instance()->post();
  1310. if (empty($param)){
  1311. $this->error('参数错误');
  1312. }
  1313. $lastId = \db('工单_工艺资料')->order('UniqId desc')->value('UniqId');
  1314. if (empty($lastId)){
  1315. $lastId = 0;
  1316. }else{
  1317. $lastId = $lastId + 1;
  1318. }
  1319. if (empty($param['Gy0_shdh'])){
  1320. $param['Gy0_Rate0'] = 0;
  1321. $param['Gy0_Rate1'] = 0;
  1322. }else{
  1323. $detail = \db('dic_lzsh')->field('sys_rate0,sys_rate1')->where('sys_bh',$param['Gy0_shdh'])->find();
  1324. $param['Gy0_Rate0'] = $detail['sys_rate0'];
  1325. $param['Gy0_Rate1'] = $detail['sys_rate1'];
  1326. }
  1327. $param['Sys_rq'] = date('Y-m-d H:i:s',time());
  1328. $param['Mod_rq'] = '1900-01-01 00:00:00';
  1329. $param['Gy0_sj1'] = '1900-01-01 00:00:00';
  1330. $param['Gy0_sj2'] = '1900-01-01 00:00:00';
  1331. $param['PD_WG'] = '1900-01-01 00:00:00';
  1332. $param['UniqId'] = $lastId;
  1333. $sql = \db('工单_工艺资料')
  1334. ->fetchSql(true)
  1335. ->insert($param);
  1336. $res = \db()->query($sql);
  1337. //获取平张投料
  1338. $number = \db('工单_印件资料')
  1339. ->where('Yj_Gdbh',$param['Gy0_gdbh'])
  1340. ->where('yj_Yjno',$param['Gy0_yjno'])
  1341. ->value('rtrim(yj_平张投料)');
  1342. //分配工艺计划产量
  1343. if ((int)$number >0){
  1344. $this->PlannedProcessYield($param['Gy0_gdbh'],$param['Gy0_yjno'],$param['Gy0_gxh'],$number);
  1345. }
  1346. if ($res !== false){
  1347. $this->success('成功');
  1348. }else{
  1349. $this->error('失败');
  1350. }
  1351. }
  1352. /**
  1353. * 新增工艺资料->印件编号获取
  1354. * @return void
  1355. * @throws \think\db\exception\DataNotFoundException
  1356. * @throws \think\db\exception\ModelNotFoundException
  1357. * @throws \think\exception\DbException
  1358. */
  1359. public function PrintDetailList()
  1360. {
  1361. if ($this->request->isGet() === false){
  1362. $this->error('请求错误');
  1363. }
  1364. $param = $this->request->param();
  1365. if (empty($param)){
  1366. $this->error('参数错误');
  1367. }
  1368. $printList = \db('工单_印件资料')
  1369. ->where('Yj_Gdbh',$param['workOrder'])
  1370. ->order('yj_Yjno')
  1371. ->select();
  1372. if (empty($printList)){
  1373. $this->success('未找到该工单印件资料');
  1374. }
  1375. $list = [];
  1376. foreach ($printList as $key=>$value){
  1377. $list[$key]['name'] = rtrim($value['yj_Yjno']).'-->'.rtrim($value['yj_yjmc']);
  1378. $list[$key]['no'] = rtrim($value['yj_Yjno']);
  1379. }
  1380. $this->success('成功',$list);
  1381. }
  1382. /**
  1383. * 工单资料管理->印件资料删除
  1384. * @return void
  1385. * @throws \think\Exception
  1386. * @throws \think\exception\PDOException
  1387. */
  1388. public function PrintDetailDel()
  1389. {
  1390. if ($this->request->isGet() === false){
  1391. $this->error('请求错误');
  1392. }
  1393. $param = $this->request->param();
  1394. if (isset($param['UniqId']) === false){
  1395. $this->error('参数错误');
  1396. }
  1397. $printId = explode(',',$param['UniqId']);
  1398. $i = 0;
  1399. foreach ($printId as $value){
  1400. $res = \db('工单_印件资料')
  1401. ->where('Uniqid',$value)
  1402. ->delete();
  1403. if ($res === false){
  1404. $i++;
  1405. }
  1406. }
  1407. if ($i === 0){
  1408. $this->success('删除成功');
  1409. }else{
  1410. $this->error('删除失败');
  1411. }
  1412. }
  1413. /**
  1414. * 工单资料管理->工艺资料删除
  1415. * @return void
  1416. * @throws \think\Exception
  1417. * @throws \think\exception\PDOException
  1418. */
  1419. public function ProcessDetailDel()
  1420. {
  1421. if ($this->request->isGet() === false){
  1422. $this->error('请求错误');
  1423. }
  1424. $param = $this->request->param();
  1425. if (isset($param['UniqId']) === false){
  1426. $this->error('参数错误');
  1427. }
  1428. $printId = explode(',',$param['UniqId']);
  1429. $i = 0;
  1430. //获取工单编号、印件号
  1431. $codeList = \db('工单_工艺资料')
  1432. ->where('UniqId',$printId[0])
  1433. ->field('rtrim(Gy0_gdbh) as 工单编号,rtrim(Gy0_yjno) as 印件号')
  1434. ->find();
  1435. //获取平张投料数量
  1436. $number = \db('工单_印件资料')
  1437. ->where([
  1438. 'Yj_Gdbh' => $codeList['工单编号'],
  1439. 'yj_Yjno' => $codeList['印件号']
  1440. ])
  1441. ->value('rtrim(yj_平张投料)');
  1442. //循环删除工艺资料
  1443. foreach ($printId as $value){
  1444. $res = \db('工单_工艺资料')
  1445. ->where('UniqId',$value)
  1446. ->delete();
  1447. if ($res === false){
  1448. $i++;
  1449. }
  1450. }
  1451. //重新分配工艺计划产量
  1452. if ((int)$number>0){
  1453. $this->PlannedProcessYield($codeList['工单编号'],$codeList['印件号'],0,$number);
  1454. }
  1455. if ($i === 0){
  1456. $this->success('删除成功');
  1457. }else{
  1458. $this->error('删除失败');
  1459. }
  1460. }
  1461. /**
  1462. * 工艺资料添加->工序损耗代码
  1463. * @return void
  1464. * @throws \think\db\exception\DataNotFoundException
  1465. * @throws \think\db\exception\ModelNotFoundException
  1466. * @throws \think\exception\DbException
  1467. */
  1468. public function WastageList()
  1469. {
  1470. if ($this->request->isGet() === false){
  1471. $this->error('请求错误');
  1472. }
  1473. $param = $this->request->param();
  1474. if (empty($param['process'])){
  1475. $this->error('参数错误');
  1476. }
  1477. $order = \db('dic_lzsh')
  1478. ->where('sys_mc','like',$param['process'].'%')
  1479. ->value('rtrim(sys_bh) as 编号');
  1480. $this->success('成功',$order);
  1481. }
  1482. /**
  1483. * 获取产品附件列表
  1484. */
  1485. public function getAnnexTable(){
  1486. if(!$this->request->isGet()){
  1487. $this->error('请求方式错误');
  1488. }
  1489. $req = $this->request->param();
  1490. if (isset($req['cpdh']) && !empty($req['cpdh'])){
  1491. $where['关联产品'] = ['LIKE','%'.$req['cpdh'].'%'];
  1492. }else{
  1493. $this->error('参数错误');
  1494. }
  1495. $rows = db('产品_技术附件')
  1496. ->where($where)
  1497. ->select();
  1498. foreach ($rows as $key=>&$value){
  1499. if(mb_detect_encoding($value['附件内容'])!='ASCII'){
  1500. $value['附件内容'] = '';
  1501. }
  1502. }
  1503. $this->success('成功',$rows);
  1504. }
  1505. /**
  1506. * 产品附件新增
  1507. */
  1508. public function annexAdd(){
  1509. if(!$this->request->isPost()){
  1510. $this->error('请求方式错误');
  1511. }
  1512. $req = $this->request->param();
  1513. $arr = [
  1514. 'sys_id',
  1515. '序号',
  1516. '附件备注',
  1517. '附件内容',
  1518. '附件类型',
  1519. '适用工序',
  1520. '关联产品'
  1521. ];
  1522. $data = [];
  1523. foreach ($arr as $key => $value){
  1524. if (!isset($req[$value])){
  1525. $this->error('参数错误',$value,$key+1);
  1526. }
  1527. $data[$value] = $req[$value];
  1528. }
  1529. $data['sys_rq'] = date('Y-m-d H:i:s');
  1530. //开启事务
  1531. db()->startTrans();
  1532. try{
  1533. $sql = db('产品_技术附件')->fetchSql(true)->insert($data);
  1534. $bool = db()->query($sql);
  1535. // 提交事务
  1536. db()->commit();
  1537. } catch (\Exception $e) {
  1538. // 回滚事务
  1539. db()->rollback();
  1540. $this->error($e->getMessage());
  1541. }
  1542. if($bool===false) $this->error('失败');
  1543. $this->success('成功');
  1544. }
  1545. /**
  1546. * 产品附件修改
  1547. * @ApiMethod (GET)
  1548. * @param string 'UniqId'
  1549. */
  1550. public function annexDel()
  1551. {
  1552. if(!$this->request->isGet()){
  1553. $this->error('请求方式错误');
  1554. }
  1555. $req = $this->request->param();
  1556. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  1557. $this->error('参数错误','UniqId',100);
  1558. }
  1559. //开启事务
  1560. db()->startTrans();
  1561. try{
  1562. $bool = db('产品_技术附件')->where('UniqId',$req['UniqId'])->delete();
  1563. // 提交事务
  1564. db()->commit();
  1565. } catch (\Exception $e) {
  1566. // 回滚事务
  1567. db()->rollback();
  1568. $this->error($e->getMessage());
  1569. }
  1570. if($bool===false) $this->error('失败');
  1571. $this->success('成功');
  1572. }
  1573. /**
  1574. * 获取产品附件列表
  1575. */
  1576. public function getGdAnnexTable(){
  1577. if(!$this->request->isGet()){
  1578. $this->error('请求方式错误');
  1579. }
  1580. $req = $this->request->param();
  1581. if (isset($req['gdbh']) && !empty($req['gdbh'])){
  1582. $where['关联编号'] = ['LIKE','%'.$req['gdbh'].'%'];
  1583. }else{
  1584. $this->error('参数错误');
  1585. }
  1586. $rows = db('工单_相关附件')
  1587. ->where($where)
  1588. ->select();
  1589. foreach ($rows as $key=>&$value){
  1590. if(mb_detect_encoding($value['附件内容'])!='ASCII'){
  1591. $value['附件内容'] = '';
  1592. }
  1593. }
  1594. $this->success('成功',$rows);
  1595. }
  1596. /**
  1597. * 产品附件新增
  1598. */
  1599. public function gdAnnexAdd(){
  1600. if(!$this->request->isPost()){
  1601. $this->error('请求方式错误');
  1602. }
  1603. $req = $this->request->param();
  1604. $arr = [
  1605. 'sys_id',
  1606. '附件备注',
  1607. '附件内容',
  1608. '附件类型',
  1609. '关联编号'
  1610. ];
  1611. $data = [];
  1612. foreach ($arr as $key => $value){
  1613. if (!isset($req[$value])){
  1614. $this->error('参数错误',$value,$key+1);
  1615. }
  1616. $data[$value] = $req[$value];
  1617. }
  1618. $data['sys_rq'] = date('Y-m-d H:i:s');
  1619. //开启事务
  1620. db()->startTrans();
  1621. try{
  1622. $sql = db('工单_相关附件')->fetchSql(true)->insert($data);
  1623. $bool = db()->query($sql);
  1624. // 提交事务
  1625. db()->commit();
  1626. } catch (\Exception $e) {
  1627. // 回滚事务
  1628. db()->rollback();
  1629. $this->error($e->getMessage());
  1630. }
  1631. if($bool===false) $this->error('失败');
  1632. $this->success('成功');
  1633. }
  1634. /**
  1635. * 产品附件修改
  1636. * @ApiMethod (GET)
  1637. * @param string 'UniqId'
  1638. */
  1639. public function gdAnnexDel()
  1640. {
  1641. if(!$this->request->isGet()){
  1642. $this->error('请求方式错误');
  1643. }
  1644. $req = $this->request->param();
  1645. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  1646. $this->error('参数错误','UniqId',100);
  1647. }
  1648. //开启事务
  1649. db()->startTrans();
  1650. try{
  1651. $bool = db('工单_相关附件')->where('UniqId',$req['UniqId'])->delete();
  1652. // 提交事务
  1653. db()->commit();
  1654. } catch (\Exception $e) {
  1655. // 回滚事务
  1656. db()->rollback();
  1657. $this->error($e->getMessage());
  1658. }
  1659. if($bool===false) $this->error('失败');
  1660. $this->success('成功');
  1661. }
  1662. /**
  1663. * 引用工单资料数据查询
  1664. * @return void
  1665. * @throws \think\db\exception\DataNotFoundException
  1666. * @throws \think\db\exception\ModelNotFoundException
  1667. * @throws \think\exception\DbException
  1668. */
  1669. public function WorkOrderDetailCope()
  1670. {
  1671. if ($this->request->isGet() === false){
  1672. $this->error('请求错误');
  1673. }
  1674. $param = $this->request->param();
  1675. if (empty($param['search'])){
  1676. $this->error('参数错误');
  1677. }
  1678. $list = \Db('工单_基本资料')
  1679. ->alias('a')
  1680. ->field([
  1681. 'rtrim(a.Gd_gdbh)' => '工单编号',
  1682. 'rtrim(b.客户编号)' => '客户编号',
  1683. 'rtrim(b.客户名称)' => '客户名称',
  1684. 'rtrim(b.产品编号)' => '产品编号',
  1685. 'rtrim(b.产品名称)' => '产品名称'
  1686. ])
  1687. ->join('产品_基本资料 b', 'a.成品代号 = b.产品编号')
  1688. ->join('产品_工艺资料 c', 'a.成品代号 = c.Gy0_cpdh')
  1689. ->join('产品_印件资料 d', 'a.成品代号 = d.yj_cpdh')
  1690. ->where(function($query) use ($param) {
  1691. $query->where('a.Gd_gdbh', 'like', '%'.$param['search'].'%')
  1692. ->whereOr('a.成品名称', 'like', '%'.$param['search'].'%');
  1693. })
  1694. ->where(function($query) {
  1695. $query->where('c.Gy0_cpdh', '<>', '')
  1696. ->where('d.yj_cpdh', '<>', '')
  1697. ->where('b.状态', 'not like', '%停用%')
  1698. ->where('b.产品名称', 'not like', '%停用%');
  1699. })
  1700. ->group('a.Gd_gdbh')
  1701. ->order('a.Uniqid desc')
  1702. ->select();
  1703. if (empty($list)){
  1704. $this->success('未找到工单资料');
  1705. }else{
  1706. $this->success('成功',$list);
  1707. }
  1708. }
  1709. /**
  1710. * 引用产品印件、工艺资料
  1711. * @return void
  1712. * @throws \think\db\exception\BindParamException
  1713. * @throws \think\db\exception\DataNotFoundException
  1714. * @throws \think\db\exception\ModelNotFoundException
  1715. * @throws \think\exception\DbException
  1716. * @throws \think\exception\PDOException
  1717. */
  1718. public function WorkOrderDetailListCope()
  1719. {
  1720. if (Request::instance()->isPost() === false){
  1721. $this->error('请求错误');
  1722. }
  1723. $param = Request::instance()->post();
  1724. if (empty($param['workorder']) || empty($param['productCode']) || empty($param['option'])){
  1725. $this->error('参数错误');
  1726. }
  1727. if (isset($param['sort'])){
  1728. $priWhere['yj_yjno'] = ['>=',10];
  1729. $proWhere['Gy0_yjno'] = ['>=',10];
  1730. }else{
  1731. $priWhere['yj_yjno'] = ['<',10];
  1732. $proWhere['Gy0_yjno'] = ['<',10];
  1733. }
  1734. $list = \db('工单_基本资料')
  1735. ->where('Gd_gdbh',$param['workorder'])
  1736. // ->where('成品代号',$param['productCode'])
  1737. ->field('行号,Gd_cpdh')
  1738. ->select();
  1739. //引用印件资料
  1740. $PrintList = \db('产品_印件资料')
  1741. ->where('yj_cpdh',$param['productCode'])
  1742. ->where($priWhere)
  1743. ->select();
  1744. if (empty($PrintList)){
  1745. $this->error('未找到印件资料');
  1746. }
  1747. $PrintLastId = \db('工单_印件资料')->order('Uniqid desc')->value('rtrim(Uniqid)');
  1748. $number = \db('工单_基本资料')
  1749. ->where('Gd_gdbh',$param['workorder'])
  1750. ->where('成品代号',$param['productCode'])
  1751. ->value('rtrim(计划投料)');
  1752. $arr = [];
  1753. foreach ($PrintList as $key => $value){
  1754. foreach ($list as $k=>$v){
  1755. if ($value['yj_yjdh'] === $v['Gd_cpdh']){
  1756. $PrintList[$key]['Yj_Gdbh'] = $param['workorder'];
  1757. $PrintList[$key]['yj_Yjno'] = $value['yj_yjno'];
  1758. $PrintList[$key]['yj_Yjdh'] = $value['yj_yjdh'];
  1759. $PrintList[$key]['yj_ks'] = $value['yj_ks'];
  1760. $PrintList[$key]['yj_ls'] = $value['yj_ls'];
  1761. $PrintList[$key]['yj_平张投料'] = $number;
  1762. $PrintList[$key]['Sys_id'] = $value['sys_id'];
  1763. $PrintList[$key]['Uniqid'] = $PrintLastId + $key + 1;
  1764. $PrintList[$key]['Sys_rq'] = date('Y-m-d H:i:s',time());
  1765. $PrintList[$key]['Mod_rq'] = date('Y-m-d H:i:s',time());
  1766. array_push($arr,[$value['yj_yjno'],$v['行号']]);
  1767. }
  1768. $sql = \db('工单_基本资料')
  1769. ->where('Gd_gdbh',$param['workorder'])
  1770. ->where('Gd_cpdh',$value['yj_yjdh'])
  1771. ->fetchSql(true)
  1772. ->update(['行号'=>$value['yj_yjno']]);
  1773. \db()->query($sql);
  1774. }
  1775. unset($PrintList[$key]['mod_rq'],$PrintList[$key]['sys_rq'],$PrintList[$key]['sys_id'],$PrintList[$key]['KgToPages'],$PrintList[$key]['yj_tll'],$PrintList[$key]['yj_yjdh'],$PrintList[$key]['yj_yjno'],$PrintList[$key]['UniqId']);
  1776. }
  1777. //引用工艺资料
  1778. $processWhere = [
  1779. 'Gy0_方案' => $param['option'],
  1780. 'Gy0_cpdh' => $param['productCode']
  1781. ];
  1782. $ProcessList = \db('产品_工艺资料')
  1783. ->where($processWhere)
  1784. ->where($proWhere)
  1785. ->order('Gy0_yjno,Gy0_gxh')
  1786. ->select();
  1787. if (empty($ProcessList)){
  1788. $this->error('未找到产品工艺资料');
  1789. }
  1790. $ProcesslastId = \db('工单_工艺资料')->order('UniqId desc')->value('rtrim(UniqId)');
  1791. foreach ($ProcessList as $key=>$value){
  1792. if (empty(trim($value['Gy0_shdh']))){
  1793. $rate['rate0'] = 0;
  1794. $rate['rate1'] = 0;
  1795. }else{
  1796. $rate = \db('dic_lzsh')->where('sys_bh',$value['Gy0_shdh'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
  1797. if (empty($rate)){
  1798. $this->error('该产品印件号'.$value['Gy0_yjno'].'工序号为'.$value['gy0_gxmc'].'的损耗代号错误,请调整之后再引用');
  1799. }
  1800. }
  1801. //设置默认机台
  1802. $machineList = \db('设备_基本资料')
  1803. ->where('生产工序','like','%'.$value['gy0_gxmc'].'%')
  1804. ->order('设备编号')
  1805. ->value('设备编号');
  1806. $ProcessList[$key]['Gy0_sbbh'] = '';
  1807. if (!empty($machineList)){
  1808. $ProcessList[$key]['Gy0_sbbh'] = $machineList;
  1809. }
  1810. $ProcessList[$key]['Gy0_yjno'] = $value['Gy0_yjno'];
  1811. $ProcessList[$key]['Gy0_gdbh'] = $param['workorder'];
  1812. $ProcessList[$key]['Gy0_gxmc'] = $value['gy0_gxmc'];
  1813. $ProcessList[$key]['Gy0_SITE'] = $value['Gy0_site'];
  1814. $ProcessList[$key]['Gy0_shdh'] = $value['Gy0_shdh'];
  1815. $ProcessList[$key]['Gy0_Rate0'] = $rate['rate0'];
  1816. $ProcessList[$key]['Gy0_Rate1'] = $rate['rate1'];
  1817. $ProcessList[$key]['Gy0_ks'] = $value['Gy0_Ks'];
  1818. $ProcessList[$key]['Gy0_ms'] = $value['Gy0_Ms'];
  1819. $ProcessList[$key]['Gy0_oil'] = $value['Gy0_Oil'];
  1820. $ProcessList[$key]['Gy0_计划接货数'] = 0;
  1821. $ProcessList[$key]['Gy0_计划损耗'] = 0;
  1822. $ProcessList[$key]['无形损承担比例'] = 0;
  1823. $ProcessList[$key]['超节损承担比例'] = 1;
  1824. $ProcessList[$key]['超节损核算单价'] = 0;
  1825. $ProcessList[$key]['Gy0_sj1'] = '1900-01-01 00:00:00';
  1826. $ProcessList[$key]['Gy0_sj2'] = '1900-01-01 00:00:00';
  1827. $ProcessList[$key]['UniqId'] = $ProcesslastId + $key + 1;
  1828. $ProcessList[$key]['PD_WG'] = '1900-01-01 00:00:00';
  1829. $ProcessList[$key]['Sys_rq'] = date('Y-m-d H:i:s', time());
  1830. unset($ProcessList[$key]['Gy0_Oil'],$ProcessList[$key]['Gy0_Ms'],$ProcessList[$key]['Gy0_Ks'],$ProcessList[$key]['UniqID'],$ProcessList[$key]['Gy0_cpdh'],$ProcessList[$key]['gy0_gxmc'],$ProcessList[$key]['Gy0_site']);
  1831. }
  1832. //插入数据
  1833. \db()->startTrans();
  1834. try {
  1835. \db('工单_工艺资料')->where('Gy0_gdbh',$param['workorder'])->delete();
  1836. $processSql = \db('工单_工艺资料')->fetchSql(true)->insertAll($ProcessList);
  1837. \db()->query($processSql);
  1838. \db('工单_印件资料')->where('Yj_Gdbh',$param['workorder'])->delete();
  1839. $printSql = \db('工单_印件资料')->fetchSql(true)->insertAll($PrintList);
  1840. \db()->query($printSql);
  1841. \db()->commit();
  1842. }catch (\Exception $e){
  1843. \db()->rollback();
  1844. }
  1845. //计算工序计划生产数量
  1846. if ($number !== null){
  1847. $list = \db('工单_印件资料')->where('Yj_Gdbh',$param['workorder'])->field('yj_Yjno,yj_平张投料')->select();
  1848. foreach ($list as $value){
  1849. if ((int)$value['yj_平张投料'] >0){
  1850. $this->PlannedProcessYield($param['workorder'],$value['yj_Yjno'],0,$value['yj_平张投料']);
  1851. }
  1852. }
  1853. }
  1854. $this->success('成功');
  1855. }
  1856. /**
  1857. * 引用产品印件、工艺资料->信息获取
  1858. * @return void
  1859. * @throws \think\db\exception\DataNotFoundException
  1860. * @throws \think\db\exception\ModelNotFoundException
  1861. * @throws \think\exception\DbException
  1862. */
  1863. public function ProductCopeDetail()
  1864. {
  1865. if ($this->request->isGet() === false){
  1866. $this->error('请求错误');
  1867. }
  1868. $param = $this->request->param();
  1869. if (empty($param['workorder'])){
  1870. $this->error('参数错误');
  1871. }
  1872. $list = \db('工单_基本资料')
  1873. ->alias('a')
  1874. ->field([
  1875. 'rtrim(a.Gd_gdbh)' => '工单编号',
  1876. 'rtrim(b.客户编号)' => '客户编号',
  1877. 'rtrim(b.客户名称)' => '客户名称',
  1878. 'rtrim(b.产品编号)' => '产品编号',
  1879. 'rtrim(b.产品名称)' => '产品名称'
  1880. ])
  1881. ->join('产品_基本资料 b','a.成品代号 = b.产品编号')
  1882. ->where('a.Gd_gdbh',$param['workorder'])
  1883. ->find();
  1884. if (empty($list)){
  1885. $this->error('未找到工单信息');
  1886. }
  1887. $option = \db('产品_工艺资料')
  1888. ->field('rtrim(Gy0_方案) as 方案')
  1889. ->where('Gy0_cpdh',$list['产品编号'])
  1890. ->group('Gy0_方案')
  1891. ->select();
  1892. $list['方案'] = $option;
  1893. $this->success('成功',$list);
  1894. }
  1895. /**
  1896. * 工艺资料计划产量重新分配
  1897. * @param string $workOrder 工单
  1898. * @param int $yjno 印件号
  1899. * @param int $gxh 工序号
  1900. * @param int $feed 平张投料
  1901. * @return bool
  1902. * @throws \think\Exception
  1903. * @throws \think\db\exception\BindParamException
  1904. * @throws \think\db\exception\DataNotFoundException
  1905. * @throws \think\db\exception\ModelNotFoundException
  1906. * @throws \think\exception\DbException
  1907. * @throws \think\exception\PDOException
  1908. */
  1909. public function PlannedProcessYield($workOrder,$yjno,$gxh,$feed)
  1910. {
  1911. if ($gxh === 0){
  1912. $where = [
  1913. 'Gy0_gdbh'=>$workOrder,
  1914. 'Gy0_yjno'=>$yjno,
  1915. ];
  1916. }else{
  1917. $where = [
  1918. 'Gy0_gdbh'=>$workOrder,
  1919. 'Gy0_yjno'=>$yjno,
  1920. 'Gy0_gxh'=>['>=',$gxh]
  1921. ];
  1922. }
  1923. //获取工艺资料
  1924. $processList = \db('工单_工艺资料')
  1925. ->where($where)
  1926. ->field('Gy0_Rate0 as 损耗定额,Gy0_Rate1 as 损耗率,rtrim(损耗系数) as 损耗系数,Gy0_ms,Gy0_ls,UniqId')
  1927. ->order('Gy0_gxh')
  1928. ->select();
  1929. if (empty($processList)){
  1930. $this->success('未找到该工单工序资料');
  1931. }
  1932. //计算损耗定额和计划产量
  1933. $production = [];
  1934. $i = 0;
  1935. foreach ($processList as $key=>$value){
  1936. if ($key === 0){
  1937. array_push($production,$feed);
  1938. }
  1939. $wastage = 0;
  1940. if ($value['损耗率'] !== 0 && !empty($value['损耗率'])){
  1941. $wastage = ($production[$key]*$value['损耗率']+$value['损耗定额'])*$value['损耗系数'];
  1942. }
  1943. if ($value['Gy0_ms'] >0 && !empty($value['Gy0_ms'])){
  1944. $wastage = round($wastage * $value['Gy0_ms']);
  1945. }
  1946. if ((int)$value['Gy0_ls'] === 1 && $key>=1){
  1947. $number = $production[$key]*$processList[$key-1]['Gy0_ls'];
  1948. }else{
  1949. $number = $production[$key];
  1950. }
  1951. if ($key>=1 && (int)$processList[$key-1]['Gy0_ls'] === 1 && (int)$value['Gy0_ls'] > 1){
  1952. $number = $number/(int)$value['Gy0_ls'];
  1953. }
  1954. array_push($production,ceil($number-$wastage));
  1955. $processSql = \db('工单_工艺资料')
  1956. ->where('UniqId',$value['UniqId'])
  1957. ->fetchSql(true)
  1958. ->update(['Gy0_计划接货数'=>$production[$key],'Gy0_计划损耗'=>$wastage]);
  1959. $res = \db()->query($processSql);
  1960. if ($res === false){
  1961. $i++;
  1962. }
  1963. }
  1964. if ($i===0){
  1965. return true;
  1966. }else{
  1967. return false;
  1968. }
  1969. }
  1970. /**
  1971. * 工单资料删除
  1972. * @return void
  1973. * @throws \think\exception\PDOException
  1974. */
  1975. public function WorkOrderDel()
  1976. {
  1977. if ($this->request->isGet() === false){
  1978. $this->error('请求错误');
  1979. }
  1980. $param = $this->request->param();
  1981. if (isset($param['UniqId']) === false){
  1982. $this->error('参数错误');
  1983. }
  1984. $WorkOrderId = explode(',',$param['UniqId']);
  1985. $i = 0;
  1986. foreach ($WorkOrderId as $key=>$value){
  1987. //获取工单编号
  1988. $workorder = \db('工单_基本资料')
  1989. ->where('Uniqid',$value)
  1990. ->value('rtrim(Gd_gdbh)');
  1991. //删除工单资料、工艺资料、印件资料
  1992. \db()->startTrans();
  1993. try {
  1994. \db('工单_基本资料')->where('Gd_gdbh',$workorder)->delete();
  1995. if (!empty(\db('工单_工艺资料')->where('Gy0_gdbh',$workorder)->find())){
  1996. \db('工单_工艺资料')->where('Gy0_gdbh',$workorder)->delete();
  1997. }
  1998. if (!empty(\db('工单_印件资料')->where('Yj_Gdbh',$workorder)->find())){
  1999. \db('工单_印件资料')->where('Yj_Gdbh',$workorder)->delete();
  2000. }
  2001. if (!empty(\db('工单_bom资料')->where('BOM_工单编号',$workorder)->find())){
  2002. \db('工单_bom资料')->where('BOM_工单编号',$workorder)->delete();
  2003. }
  2004. \db()->commit();
  2005. }catch (\Exception $e){
  2006. \db()->rollback();
  2007. $i++;
  2008. }
  2009. }
  2010. if ($i === 0){
  2011. $this->success('删除成功');
  2012. }else{
  2013. $this->error('删除失败');
  2014. }
  2015. }
  2016. /**
  2017. * 修正核算参数-》工单产品信息获取
  2018. * @return void
  2019. * @throws \think\db\exception\DataNotFoundException
  2020. * @throws \think\db\exception\ModelNotFoundException
  2021. * @throws \think\exception\DbException
  2022. */
  2023. public function ProductNameData()
  2024. {
  2025. if ($this->request->isGet() === false){
  2026. $this->error('请求错误');
  2027. }
  2028. $workOrder = input('workOrder');
  2029. if (empty($workOrder)){
  2030. $this->error('参数错误');
  2031. }
  2032. $orderList = \db('工单_基本资料')
  2033. ->field('rtrim(Gd_cpdh) as 印件代号,rtrim(Gd_cpmc) as 印件名称,rtrim(成品代号) as 产品代号,rtrim(成品名称) as 产品名称')
  2034. ->where('Gd_gdbh',$workOrder)
  2035. ->find();
  2036. $this->success('成功',$orderList);
  2037. }
  2038. /**
  2039. * 获取联数
  2040. * @return void
  2041. * @throws \think\db\exception\DataNotFoundException
  2042. * @throws \think\db\exception\ModelNotFoundException
  2043. * @throws \think\exception\DbException
  2044. */
  2045. public function getCouplet()
  2046. {
  2047. if ($this->request->isGet() === false){
  2048. $this->error('请求错误');
  2049. }
  2050. $param = $this->request->param();
  2051. if (empty($param['gdbh']) || empty($param['yjno'])){
  2052. $this->error('参数错误');
  2053. }
  2054. $list = \db('工单_印件资料')
  2055. ->where('Yj_gdbh',$param['gdbh'])
  2056. ->where('yj_Yjno',$param['yjno'])
  2057. ->field('rtrim(yj_ks) as 开数,rtrim(yj_ls) as 联数')
  2058. ->find();
  2059. $process = \db('工单_工艺资料')
  2060. ->where('Gy0_gdbh',$param['gdbh'])
  2061. ->where('Gy0_yjno',$param['yjno'])
  2062. ->order('Gy0_gxh desc')
  2063. ->value('Gy0_gxh');
  2064. $list['工序号'] = $process + 1;
  2065. $this->success('成功',$list);
  2066. }
  2067. }