WorkOrder.php 90 KB

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