WorkOrder.php 91 KB

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