WorkOrder.php 97 KB

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