WorkOrder.php 89 KB

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