WorkOrder.php 93 KB

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