WorkOrder.php 90 KB

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