WorkOrder.php 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use Monolog\Handler\IFTTTHandler;
  5. use think\Db;
  6. use think\Request;
  7. /**
  8. * 工单资料管理
  9. */
  10. class WorkOrder extends Api
  11. {
  12. protected $noNeedLogin = ['*'];
  13. protected $noNeedRight = ['*'];
  14. /**
  15. * 工单资料菜单列表
  16. *
  17. * @ApiMethod (GET)
  18. * @return false|string
  19. * @throws \think\Exception
  20. */
  21. public function DataList()
  22. {
  23. if ($this->request->isGet() === false){
  24. $this->error('请求错误');
  25. }
  26. $where = [
  27. '行号' => '1',
  28. ];
  29. $ClientList = Db::table('erp_客户供应商')->where('类型','客户')->cache(true)->column('简称','编号');
  30. //获取总计划中数量和总生产中数量
  31. $productingAll = Db::table('工单_基本资料')->where('gd_statu','2-生产中')->cache(true)->count();
  32. $progressAll = Db::table('工单_基本资料')->where('gd_statu','3-计划中')->cache(true)->count();
  33. $data = [
  34. 'productingAll' => $productingAll,
  35. 'progressAll' => $progressAll
  36. ];
  37. //按客户编号查询生产中,计划中数量
  38. foreach ($ClientList as $key=>$value){
  39. $order = Db::table('工单_基本资料')->where('Gd_客户代号',$key)->cache(true)->count();
  40. if ($order !== 0){
  41. $productIng = Db::table('工单_基本资料')->where('Gd_客户代号',$key)->where($where)->where('gd_statu','2-生产中')->cache(true)->count();
  42. $proGress = Db::table('工单_基本资料')->where('Gd_客户代号',$key)->where($where)->where('gd_statu','3-计划中')->cache(true)->count();
  43. $code = Db::table('工单_基本资料')->where('Gd_客户代号',$key)->field('rtrim(成品代号) as 成品代号')->cache(true)->find();
  44. $Detail = [
  45. 'Gd_khdh' => substr($code['成品代号'],0,4),
  46. 'Gd_khmc' => rtrim($value),
  47. 'producting' => $productIng = 0?'':"生产中:".$productIng,
  48. 'progress' => $proGress=0?'':'计划中:'.$proGress,
  49. ];
  50. $menu = $Detail['Gd_khdh'].'【'.$Detail['producting'].$Detail['progress'].'】'.'【'.$Detail['Gd_khmc'].'】';
  51. array_push($data,$menu);
  52. }
  53. }
  54. $this->success('成功',$data);
  55. }
  56. /**
  57. * 工单基本资料列表
  58. * @ApiMethod (GET)
  59. * @param string $limit 查询长度
  60. * @param string $Gd_khdh 客户代号
  61. * @param string $startTime 接单日期开始时间
  62. * @param string $endTime 接单日期结束时间
  63. * @return \think\response\Json
  64. * @throws \think\exception\DbException
  65. */
  66. public function WorkList()
  67. {
  68. if ($this->request->isGet() === false){
  69. $this->error('请求错误');
  70. }
  71. $search = input('search');
  72. $limit = input('limit');
  73. $clientNumber = input('Gd_khdh');
  74. $startTime = input('start');
  75. $endTime = input('end');
  76. $workOrder = input('workOrder');
  77. $productCode = input('productCode');
  78. $where = [];
  79. if (!empty($clientNumber)){
  80. $where['成品代号'] = ['like',$clientNumber.'%'];
  81. }
  82. if (!empty($workOrder)){
  83. $where['Gd_gdbh'] = $workOrder;
  84. }
  85. if (!empty($productCode)){
  86. $where['Gd_cpdh'] = $productCode;
  87. }
  88. if (!empty($search)){
  89. $where['Gd_lx|Gd_gdbh|Gd_客户代号|Gd_客户名称|Gd_khdh|Gd_khmc|Gd_cpdh|Gd_cpmc|成品代号|成品名称|产品版本号'] = ['like','%'.$search.'%'];
  90. }
  91. if (!empty($startTime) && !empty($endTime)){
  92. $where['接单日期'] = ['between',[$startTime,$endTime]];
  93. }
  94. $list = Db::table('工单_基本资料')
  95. ->where($where)
  96. ->order('接单日期 desc')
  97. ->paginate($limit);
  98. //工单基本资料数据整理
  99. $data = [];
  100. foreach ($list->items() as $key=>$value){
  101. $data[$key] = [
  102. '工单编号' => rtrim($value['Gd_gdbh']),
  103. '生产分类' => rtrim($value['Gd_生产分类']),
  104. '销售订单号' => rtrim($value['销售订单号']),
  105. '产品代号' => rtrim($value['Gd_cpdh']),
  106. '产品名称' => rtrim($value['Gd_cpmc']),
  107. '订单数量' => rtrim($value['订单数量']),
  108. '单位' => rtrim($value['计量单位']),
  109. '折合大箱' => rtrim((int)$value['投料大箱']),
  110. '投料率' => rtrim($value['投料率']),
  111. '平均合格率' => '',
  112. '开单日期' => date('Y-m-d',strtotime(rtrim($value['接单日期']))),
  113. '交货日期' => date('Y-m-d',strtotime(rtrim($value['交货日期']))),
  114. '工单类型' => rtrim($value['Gd_lx']),
  115. '工单状态' => rtrim($value['gd_statu']),
  116. '当前生产工序' => '',
  117. '产量提交时间' => '',
  118. '建档用户' => rtrim($value['Sys_id']),
  119. '建档时间' => rtrim($value['Sys_rq']),
  120. '更新时间' => rtrim($value['Mod_rq']),
  121. 'Uniqid' => rtrim($value['Uniqid'])
  122. ];
  123. $number = Db::table('工单_工艺资料')->where('Gy0_gdbh',$data[$key]['工单编号'])->count();
  124. if ($number === 0){
  125. $data[$key]['status'] = '*';
  126. }else{
  127. $data[$key]['status'] = '';
  128. }
  129. }
  130. $this->success('成功',$data);
  131. }
  132. /**
  133. * 印件资料
  134. * @ApiMethod (GET)
  135. * @param string $Gd_gdbh 工单编号
  136. * @return \think\response\Json
  137. * @throws \think\db\exception\DataNotFoundException
  138. * @throws \think\db\exception\ModelNotFoundException
  139. * @throws \think\exception\DbException
  140. */
  141. public function Printed()
  142. {
  143. if ($this->request->isGet() === false){
  144. $this->error('请求错误');
  145. }
  146. $Gd_gdbh = input('Gd_gdbh');
  147. if (empty($Gd_gdbh)){
  148. $this->error('参数错误');
  149. }
  150. $list = Db::table('工单_印件资料')->where('Yj_Gdbh',$Gd_gdbh)->select();
  151. $data = [];
  152. if ($list){
  153. foreach ($list as $key=>$value){
  154. $data[$key] = [
  155. '印件号' => rtrim($value['yj_Yjno']),
  156. '印件代号' => rtrim($value['yj_Yjdh']),
  157. '印件名称' => rtrim($value['yj_yjmc']),
  158. '纸张代号' => rtrim($value['yj_zzdh']),
  159. '纸张名称' => rtrim($value['yj_zzmc']),
  160. '投料规格' => rtrim($value['yj_tlgg']),
  161. '平张投料' => rtrim($value['yj_平张投料']),
  162. '开料规格' => rtrim($value['yj_klgg']),
  163. '开数*联数' => rtrim($value['yj_ks']).'*'.rtrim($value['yj_ls']),
  164. '建档用户' => rtrim($value['Sys_id']),
  165. '建档时间' => rtrim($value['Sys_rq']),
  166. '更新时间' => rtrim($value['Mod_rq']),
  167. 'zzdh1' => rtrim($value['yj_zzdh1']),
  168. 'zzdh2' => rtrim($value['yj_zzdh2']),
  169. 'zzdh3' => rtrim($value['yj_zzdh3']),
  170. 'zzdh4' => rtrim($value['yj_zzdh4']),
  171. 'zzmc1' => rtrim($value['yj_zzmc1']),
  172. 'zzmc2' => rtrim($value['yj_zzmc2']),
  173. 'zzmc3' => rtrim($value['yj_zzmc3']),
  174. 'zzmc4' => rtrim($value['yj_zzmc4']),
  175. '订单数量' => rtrim($value['yj_成品数量']),
  176. '万小张' => rtrim($value['yj_实际投料']),
  177. '开数' => rtrim($value['yj_ks']),
  178. '联数' => rtrim($value['yj_ls']),
  179. '核算规格' => rtrim($value['Yj_核算规格']),
  180. '备注' => rtrim($value['yj_desc']),
  181. 'Uniqid' => rtrim($value['Uniqid'])
  182. ];
  183. }
  184. }
  185. $this->success('成功',$data);
  186. }
  187. /**
  188. * 工艺资料
  189. * @ApiMethod (GET)
  190. * @param string $Gd_gdbh 工单编号
  191. * @return \think\response\Json
  192. * @throws \think\db\exception\DataNotFoundException
  193. * @throws \think\db\exception\ModelNotFoundException
  194. * @throws \think\exception\DbException
  195. */
  196. public function Craft()
  197. {
  198. if ($this->request->isGet() === false){
  199. $this->error('请求错误');
  200. }
  201. $Gd_gdbh = input('Gd_gdbh');
  202. if (empty($Gd_gdbh)){
  203. $this->error('参数错误');
  204. }
  205. $list = Db::table('工单_工艺资料')
  206. ->where('Gy0_gdbh',$Gd_gdbh)
  207. ->select();
  208. $data = [];
  209. if ($list){
  210. foreach ($list as $key=>$value){
  211. if ($value['Gy0_yjno']<10){
  212. $value['Gy0_yjno'] = '0'.$value['Gy0_yjno'];
  213. }
  214. if ($value['Gy0_gxh']<10){
  215. $value['Gy0_gxh'] = '0'.$value['Gy0_gxh'];
  216. }
  217. if ($value['Gy0_计划损耗'] !== 0){
  218. $number = round(($value['Gy0_计划损耗']/(int)($value['Gy0_计划接货数']/$value['Gy0_ls'])),2).'%';
  219. }else{
  220. $number = 0;
  221. }
  222. $data[$key] = [
  223. '重点工序' => rtrim($value['重点工序']),
  224. '印件-工序' => rtrim($value['Gy0_yjno']).'-'.rtrim($value['Gy0_gxh']),
  225. '备选工序' => rtrim($value['备选工序']),
  226. '工序名称' => rtrim($value['Gy0_gxmc']).'【'.rtrim($value['Add_gxmc']).'】',
  227. '计划产量' => (int)($value['Gy0_计划接货数']/$value['Gy0_ls']),
  228. '基础损耗' => rtrim($value['Gy0_Rate0']),
  229. '损耗率' => rtrim($value['Gy0_Rate1']),
  230. '报废定额' => rtrim($value['Gy0_计划损耗']),
  231. '允损比例' => $number,
  232. '难度系数' => isset($value['工价系数'])?rtrim($value['工价系数']):'',
  233. '损耗系数' => isset($value['损耗系数'])?rtrim($value['损耗系数']):'',
  234. '人工检_次品板' => (int)$value['人工检_次品板']=0?'':$value['人工检_次品板'],
  235. '人工检_废检' => (int)$value['人工检_废检']=0?'':$value['人工检_废检'],
  236. '机检_正品板' => (int)$value['机检_正品板']=0?'':$value['机检_正品板'],
  237. '机检_次品板' => (int)$value['机检_次品板']=0?'':$value['机检_次品板'],
  238. '机检_废检' => (int)$value['机检_废检']=0?'':$value['机检_废检'],
  239. '开数*联数' => rtrim($value['Gy0_ks']).'*'.rtrim($value['Gy0_ls']),
  240. '备注' => isset($value['工序备注'])?rtrim($value['工序备注']):'',
  241. '印刷方式' => isset($value['印刷方式'])?rtrim($value['印刷方式']):'',
  242. '版距' => isset($value['版距'])?rtrim($value['版距']):'',
  243. '建档用户' => rtrim($value['Sys_id']),
  244. '建档日期' => isset($value['Sys_rq'])?rtrim($value['Sys_rq']):'',
  245. '更新时间' => isset($value['Mod_rq'])?rtrim($value['Mod_rq']):'',
  246. '车间名称' => rtrim($value['Gy0_SITE']),
  247. '质量要求' => rtrim($value['质量要求']),
  248. '质量隐患' => rtrim($value['质量隐患']),
  249. '开数' => rtrim($value['Gy0_ks']),
  250. '联数' => rtrim($value['Gy0_ls']),
  251. 'UniqId' => rtrim($value['UniqId']),
  252. 'shdh' => rtrim($value['Gy0_shdh']),
  253. '辅助工时' => rtrim($value['Gy0_辅助工时']),
  254. '小时产能' => rtrim($value['Gy0_小时产能'])
  255. ];
  256. }
  257. }
  258. $this->success('成功',$data);
  259. }
  260. /**
  261. * BOM资料
  262. * @ApiMethod (GET)
  263. * @param string $Gd_gdbh 工单编号
  264. * @return \think\response\Json
  265. * @throws \think\db\exception\DataNotFoundException
  266. * @throws \think\db\exception\ModelNotFoundException
  267. * @throws \think\exception\DbException
  268. */
  269. public function Bom()
  270. {
  271. if ($this->request->isGet() === false){
  272. $this->error('请求错误');
  273. }
  274. $Gd_gdbh = input('Gd_gdbh');
  275. if (empty($Gd_gdbh)){
  276. $this->error('参数错误');
  277. }
  278. $field = 'rtrim(BOM_方案) as 方案,rtrim(BOM_物料编码) as 物料编号,rtrim(BOM_物料名称) as 物料名称,BOM_投料单位,
  279. BOM_投入数,BOM_产出数,BOM_产出单位,rtrim(BOM_计划用量) as 计划用量,rtrim(Sys_ID) as 建档用户,rtrim(Sys_rq) as 建档时间,rtrim(Mod_rq) as 更新时间';
  280. $list = Db::table('工单_bom资料')
  281. ->where('BOM_工单编号',$Gd_gdbh)
  282. ->field($field)
  283. ->select();
  284. foreach ($list as $key=>$value){
  285. $list[$key]['消耗定量'] = rtrim($value['BOM_投入数']).rtrim($value['BOM_投料单位']).'/'.rtrim($value['BOM_产出数']).rtrim($value['BOM_产出单位']);
  286. unset($list[$key]['BOM_投料单位'],$list[$key]['BOM_投入数'],$list[$key]['BOM_产出数'],$list[$key]['BOM_产出单位']);
  287. $list[$key]['计划用量'] = rtrim((float)$value['计划用量']);
  288. }
  289. $this->success('成功',$list);
  290. }
  291. /**
  292. * 编辑页面展示
  293. * @ApiMethod (GET)
  294. * @param string $workOrder 工单编号
  295. * @return void
  296. * @throws \think\db\exception\DataNotFoundException
  297. * @throws \think\db\exception\ModelNotFoundException
  298. * @throws \think\exception\DbException
  299. */
  300. public function DataCorrection()
  301. {
  302. if ($this->request->isGet() === false){
  303. $this->error('请求错误');
  304. }
  305. $workOrder = input('Gd_gdbh');
  306. if (empty($workOrder)){
  307. $this->error('参数错误');
  308. }
  309. $field = 'rtrim(Gd_lx) as 重点工单,rtrim(Gd_gdbh) as 工单编号,rtrim(Gd_生产分类) as 生产类型,rtrim(Gd_khdh) as 客户代号,rtrim(Gd_客户名称) as 客户名称,
  310. rtrim(Gd_cpdh) as 产品代号,rtrim(Gd_cpmc) as 产品名称,rtrim(开单日期) as 开单日期,rtrim(订单数量) as 订单数量,rtrim(交货日期) as 交货日期,
  311. rtrim(投料率) as 投料率,rtrim(实际投料) as 万小张,rtrim(计量单位) as 单位,rtrim(投料大箱) as 投料大箱,rtrim(排产时库存) as 库存大箱,rtrim(警语版面) as 警语版面,
  312. rtrim(销售订单号) as 销售订单号,rtrim(产品版本号) as 版本号,rtrim(客户ERP编码) as 客户ERP编码,rtrim(码源数量) as 码源数量,rtrim(进程备注) as 进程备注,rtrim(Gd_desc) as 备注,rtrim(Uniqid) as Uniqid';
  313. $list = Db::table('工单_基本资料')->where('Gd_gdbh',$workOrder)->field($field)->find();
  314. if (empty($list)){
  315. $this->error('未找到该工单信息');
  316. }
  317. $printData = Db::table('工单_印件资料')
  318. ->where('Yj_Gdbh',$workOrder)
  319. ->field('rtrim(yj_yjmc) as 印件名称,rtrim(yj_Yjdh) as 印件代号,rtrim(yj_平张投料) as 平张投料,rtrim(Uniqid) as id')
  320. ->find();
  321. if (empty($printData)){
  322. $this->error('未找到该工单印件资料');
  323. }
  324. $list['印件名称'] = $printData['印件名称'];
  325. $list['印件代号'] = $printData['印件代号'];
  326. $list['平张投料'] = $printData['平张投料'];
  327. $list['印件ID'] = $printData['id'];
  328. $this->success('成功',$list);
  329. }
  330. /**
  331. * 工单资料修改
  332. * @ApiMethod (POST)
  333. * @param void
  334. * @return void
  335. * @throws \think\Exception
  336. * @throws \think\exception\PDOException
  337. */
  338. public function WorkOrderEdit()
  339. {
  340. if (Request::instance()->isPost() === false){
  341. $this->error('请求错误');
  342. }
  343. $param = Request::instance()->post();
  344. if (empty($param) || isset($param['Uniqid']) === false){
  345. $this->error('参数错误');
  346. }
  347. $row = [
  348. 'Gd_lx' => isset($param['lx'])?$param['lx']:'',
  349. '开单日期' => isset($param['kdrq'])?$param['kdrq']:'',
  350. 'Gd_gdbh' => isset($param['gdbh'])?$param['gdbh']:'',
  351. 'Gd_生产分类' => isset($param['scfl'])?$param['scfl']:'',
  352. 'Gd_客户代号' => isset($param['khdh'])?$param['khdh']:'',
  353. 'Gd_客户名称' => isset($param['khmc'])?$param['khmc']:'',
  354. '成品代号' => isset($param['cpdh'])?$param['cpdh']:'',
  355. '成品名称' => isset($param['cpmc'])?$param['cpmc']:'',
  356. '订单数量' => isset($param['ddsl'])?$param['ddsl']:'',
  357. '交货日期' => isset($param['jhrq'])?$param['jhrq']:'',
  358. '投料率' => isset($param['tll'])?$param['tll']:'',
  359. '计划投料' => isset($param['jhtl'])?$param['jhtl']:'',
  360. '实际投料' => isset($param['sjtl'])?$param['sjtl']:'',
  361. '计量单位' => isset($param['jldw'])?$param['jldw']:'',
  362. '投料大箱' => isset($param['tldx'])?$param['tldx']:'',
  363. '销售订单号' => isset($param['xsddh'])?$param['xsddh']:'',
  364. '警语版面' => isset($param['jymb'])?$param['jymb']:'',
  365. '产品版本号' => isset($param['bbh'])?$param['bbh']:'',
  366. '客户ERP编码' => isset($param['erp'])?$param['erp']:'',
  367. '码源数量' => isset($param['ymsl'])?$param['ymsl']:'',
  368. '进程备注' => isset($param['jcbz'])?$param['jcbz']:'',
  369. 'Gd_desc' => isset($param['desc'])?$param['desc']:'',
  370. '排产时库存' => isset($param['kc'])?$param['kc']:'',
  371. '平均合格率' => isset($param['avg'])?$param['avg']:'',
  372. ];
  373. $sql = Db::table('工单_基本资料')->where('Uniqid',$param['Uniqid'])->fetchSql(true)->update($row);
  374. $res = Db::query($sql);
  375. $printSql = Db::table('工单_印件资料')
  376. ->where('Uniqid',$param['printID'])
  377. ->fetchSql(true)
  378. ->update(['yj_yjmc'=>$param['yjmc'],'yj_Yjdh'=>$param['yjdh'],'yj_平张投料'=>$param['jhtl']]);
  379. $printRes = Db::query($printSql);
  380. if ($res !== false && $printRes !== false){
  381. $this->success('成功');
  382. }else{
  383. $this->error('失败');
  384. }
  385. }
  386. /**
  387. * U8投料试算
  388. * @ApiMethod (GET)
  389. * @param string $processCode 产品编号
  390. * @return void
  391. * @throws \think\db\exception\DataNotFoundException
  392. * @throws \think\db\exception\ModelNotFoundException
  393. * @throws \think\exception\DbException
  394. */
  395. public function U8Trial()
  396. {
  397. if ($this->request->isGet() === false)
  398. {
  399. $this->error('请求错误');
  400. }
  401. $productCode = input('productCode');
  402. if (empty($productCode)){
  403. $this->error('参数错误');
  404. }
  405. $field = 'rtrim(Gy0_cpdh) as 产品代号,rtrim(Gy0_yjno) as 印件号,rtrim(Gy0_gxh) as 工序号,rtrim(gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
  406. rtrim(Gy0_Ms) as 墨色数,rtrim(Gy0_shdh) as 损耗代号,rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ls) as 加工联数';
  407. $list = Db::table('产品_工艺资料')->where('Gy0_cpdh',$productCode)->field($field)->select();
  408. if (empty($list)){
  409. $this->error('未找到该产品工序');
  410. }
  411. foreach ($list as $key=>$value){
  412. $data = Db::table('dic_lzsh')->where('sys_bh',$value['损耗代号'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->cache(true)->find();
  413. $list[$key]['调机损耗'] = isset($data['rate0'])?$data['rate0']:'';
  414. $list[$key]['运行损耗率'] = isset($data['rate1'])?$data['rate1']:'';
  415. if ($value['add_gxmc'] !== ''){
  416. $list[$key]['工序名称'] = $value['gxmc'].'【'.$value['add_gxmc'].'】';
  417. }else{
  418. $list[$key]['工序名称'] = $value['gxmc'];
  419. }
  420. unset($list[$key]['gxmc'],$list[$key]['add_gxmc']);
  421. }
  422. $this->success('成功',$list);
  423. }
  424. /**
  425. * 引用产品资料->获取产品资料
  426. * @ApiMethod (GET)
  427. * @param string $workOrder 工单编号
  428. * @return void
  429. * @throws \think\db\exception\DataNotFoundException
  430. * @throws \think\db\exception\ModelNotFoundException
  431. * @throws \think\exception\DbException
  432. */
  433. public function ProductInformation()
  434. {
  435. if ($this->request->isGet() === false)
  436. {
  437. $this->error('请求错误');
  438. }
  439. $workOrder = input('workOrder');
  440. if (empty($workOrder)){
  441. $this->error('参数错误');
  442. }
  443. $field = 'rtrim(Gd_gdbh) as 工单编号,rtrim(Gd_客户名称) as 客户名称,rtrim(成品代号) as 产品代号,rtrim(成品名称) as 产品名称';
  444. $Detail = Db::table('工单_基本资料')->where('Gd_gdbh',$workOrder)->field($field)->find();
  445. if (empty($Detail)){
  446. $this->error('未找到工单信息');
  447. }
  448. $Detail['客户代号'] = substr($Detail['产品代号'],0,4);
  449. $this->success('成功',$Detail);
  450. }
  451. /**
  452. * 引用产品资料->复制产品工艺资料
  453. * @ApiMethod (POST)
  454. * @param string $oldWorkOrder 被复制工单编号
  455. * @param string $newWorkOrder 复制工单编号
  456. * @return void
  457. * @throws \think\Exception
  458. * @throws \think\db\exception\DataNotFoundException
  459. * @throws \think\db\exception\ModelNotFoundException
  460. * @throws \think\exception\DbException
  461. * @throws \think\exception\PDOException
  462. */
  463. public function ProductInformationEdit()
  464. {
  465. if (Request::instance()->isPost() === false)
  466. {
  467. $this->error('请求错误');
  468. }
  469. $oldWorkOrder = input('oldWorkOrder');
  470. $newWorkOrder = input('newWorkOrder');
  471. if (empty($oldWorkOrder) || empty($newWorkOrder))
  472. {
  473. $this->error('参数错误');
  474. }
  475. //获取原工单工艺资料
  476. $oldProcessData = Db::table('工单_工艺资料')->where('Gy0_gdbh',$oldWorkOrder)->select();
  477. $ProsessUniqId = Db::table('工单_工艺资料')->field('UniqId')->order('UniqId desc')->find();
  478. foreach ($oldProcessData as $k=>$v){
  479. $oldProcessData[$k]['Gy0_gdbh'] = $newWorkOrder;
  480. $oldProcessData[$k]['Sys_id'] = '';
  481. $oldProcessData[$k]['UniqId'] = $ProsessUniqId['UniqId'] + $k + 1;
  482. }
  483. if (Db::table('工单_工艺资料')->where('Gy0_gdbh',$newWorkOrder)->find()){
  484. Db::table('工单_工艺资料')->where('Gy0_gdbh',$newWorkOrder)->delete();
  485. }
  486. //获取原工单印件资料
  487. $oldPrintData = Db::table('工单_印件资料')->where('Yj_Gdbh',$oldWorkOrder)->select();
  488. $PrintUniqId = Db::table('工单_印件资料')->field('Uniqid')->order('Uniqid desc')->find();
  489. foreach ($oldPrintData as $k=>$v){
  490. $oldPrintData[$k]['Yj_Gdbh'] = $newWorkOrder;
  491. $oldPrintData[$k]['Sys_id'] = '';
  492. $oldPrintData[$k]['Uniqid'] = $PrintUniqId['Uniqid'] +$k +1;
  493. }
  494. if (Db::table('工单_印件资料')->where('Yj_Gdbh',$newWorkOrder)->find()){
  495. Db::table('工单_印件资料')->where('Yj_Gdbh',$newWorkOrder)->delete();
  496. }
  497. //复制印件、工艺资料
  498. $ProcessSQL = Db::table('工单_工艺资料')->fetchSql(true)->insertAll($oldProcessData);
  499. $ProcessRes = Db::query($ProcessSQL);
  500. $PrintSQL = Db::table('工单_印件资料')->fetchSql(true)->insertAll($oldPrintData);
  501. $PrintRes = Db::query($PrintSQL);
  502. if ($ProcessRes !== false && $PrintRes !== false){
  503. $this->success('成功');
  504. }else{
  505. $this->error('失败');
  506. }
  507. }
  508. /**
  509. * 工艺流程调成->获取当前工单工艺资料
  510. * @ApiMethod (GET)
  511. * @param string $workorder 当前工单编号
  512. * @return void
  513. * @throws \think\db\exception\DataNotFoundException
  514. * @throws \think\db\exception\ModelNotFoundException
  515. * @throws \think\exception\DbException
  516. */
  517. public function ProcessFlow()
  518. {
  519. if ($this->request->isGet() === false){
  520. $this->error('请求错误');
  521. }
  522. $workOrder = input('workOrder');
  523. if (empty($workOrder)){
  524. $this->error('参数错误');
  525. }
  526. $list = Db::table('工单_基本资料')->where('Gd_gdbh',$workOrder)->field('rtrim(成品代号) as 成品编号,rtrim(成品名称) as 成品名称')->find();
  527. if (empty($list)){
  528. $this->error('未找到工单信息');
  529. }
  530. $filed = 'rtrim(Gy0_方案) as 方案,rtrim(Gy0_yjno) as 印件号,rtrim(Gy0_gxh) as 工序号,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
  531. rtrim(工价系数) as 工价系数,rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ks) as ks,rtrim(Gy0_ls) as ls,rtrim(工序备注) as 备注,rtrim(Gy0_SITE) as 车间,
  532. rtrim(Gy0_sbbh) as 设备编号,rtrim(Gy0_sbmc) as 设备名称,rtrim(Sys_id) as 建档用户,rtrim(Sys_rq) as 建档时间,rtrim(Mod_rq) as 更新时间';
  533. $process = Db::table('工单_工艺资料')->where('Gy0_gdbh',$workOrder)->field($filed)->select();
  534. if (empty($process)){
  535. $this->error('未找到该工单工艺资料');
  536. }
  537. foreach ($process as $key=>$value){
  538. if (isset($value['add_gxmc'])){
  539. $process[$key]['工序名称'] = $value['gxmc'] . '【'.$value['add_gxmc'].'】';
  540. }else{
  541. $process[$key]['工序名称'] = $value['gxmc'];
  542. }
  543. $process[$key]['工价系数'] = (float)$value['工价系数'];
  544. $process[$key]['损耗系数'] = (float)$value['损耗系数'];
  545. $process[$key]['开数*联数'] = $value['ks'].'*'.$value['ls'];
  546. }
  547. $list['process'] = $process;
  548. $this->success('成功',$list);
  549. }
  550. /**
  551. * 参照工单列表获取
  552. * @ApiMethod (GET)
  553. * @param string $workOrder 工单编号
  554. * @param string $productCode 产品代号
  555. * @return void
  556. */
  557. public function ReferenceWorkOrder()
  558. {
  559. if ($this->request->isGet() === false){
  560. $this->error('请求错误');
  561. }
  562. $productCode = input('productCode');
  563. $workOrder = input('workOrder');
  564. if (empty($productCode) || empty($workOrder)){
  565. $this->error('参数错误');
  566. }
  567. $list = Db::table('工单_基本资料')->where('成品代号',$productCode)->where('Gd_gdbh','<>',$workOrder)->column('Gd_gdbh');
  568. if (empty($list)){
  569. $this->error('未获取该产品其他工单信息');
  570. }
  571. $this->success('成功',$list);
  572. }
  573. /**
  574. * 工艺资料复制
  575. * @ApiMethod (POST)
  576. * @param string $oldWorkOrder 被复制工单编号
  577. * @param string $newWorkOrder 复制工单编号
  578. * @return void
  579. * @throws \think\Exception
  580. * @throws \think\db\exception\DataNotFoundException
  581. * @throws \think\db\exception\ModelNotFoundException
  582. * @throws \think\exception\DbException
  583. * @throws \think\exception\PDOException
  584. *
  585. */
  586. public function ProcessCopy()
  587. {
  588. if (Request::instance()->isPost() === false){
  589. $this->error('请求错误');
  590. }
  591. $oldWorkOrder = input('oldWorkOrder');
  592. $newWorkOrder = input('newWorkOrder');
  593. if (empty($oldWorkOrder) || empty($newWorkOrder))
  594. {
  595. $this->error('参数错误');
  596. }
  597. //获取原工单工艺资料
  598. $oldProcessData = Db::table('工单_工艺资料')->where('Gy0_gdbh',$oldWorkOrder)->select();
  599. $ProsessUniqId = Db::table('工单_工艺资料')->field('UniqId')->order('UniqId desc')->find();
  600. foreach ($oldProcessData as $k=>$v){
  601. $oldProcessData[$k]['Gy0_gdbh'] = $newWorkOrder;
  602. $oldProcessData[$k]['Sys_id'] = '';
  603. $oldProcessData[$k]['Mod_rq'] = date('Y-m-d H:i:s',time());
  604. $oldProcessData[$k]['UniqId'] = $ProsessUniqId['UniqId'] + $k + 1;
  605. }
  606. if (Db::table('工单_工艺资料')->where('Gy0_gdbh',$newWorkOrder)->find()){
  607. Db::table('工单_工艺资料')->where('Gy0_gdbh',$newWorkOrder)->delete();
  608. }
  609. //插入工艺资料
  610. $ProcessSQL = Db::table('工单_工艺资料')->fetchSql(true)->insertAll($oldProcessData);
  611. $ProcessRes = Db::query($ProcessSQL);
  612. if ($ProcessRes !== false){
  613. $this->success('成功');
  614. }else{
  615. $this->error('失败');
  616. }
  617. }
  618. /**
  619. * U8工单列表
  620. * @ApiMethod (GET)
  621. * @param void
  622. * @return void
  623. * @throws \think\db\exception\DataNotFoundException
  624. * @throws \think\db\exception\ModelNotFoundException
  625. * @throws \think\exception\DbException
  626. */
  627. public function U8workOrder()
  628. {
  629. if ($this->request->isGet() === false){
  630. $this->error('请求错误');
  631. }
  632. $param = $this->request->param();
  633. if (empty($param)){
  634. $this->error('参数错误');
  635. }
  636. $filed = 'rtrim(Gd_gdbh) as 工单编号,rtrim(行号) as 行号,rtrim(Gd_客户代号) as 客户代号,rtrim(Gd_客户名称) as 客户名称,
  637. rtrim(成品代号) as 成品代号,rtrim(成品名称) as 成品名称,rtrim(Mod_rq) as 获取日期,rtrim(Uniqid) as 序号';
  638. $list = Db::table('工单_基本资料')->where('Gd_gdbh',$param['workOrder'])->field($filed)->select();
  639. if (empty($list)){
  640. $this->error('未找到工单');
  641. }
  642. $this->success('成功',$list);
  643. }
  644. /**
  645. * U8工单资料删除
  646. * @param string $workOrder 工单编号
  647. * @return void
  648. * @throws \think\Exception
  649. * @throws \think\exception\PDOException
  650. */
  651. public function U8DataCorrection()
  652. {
  653. if($this->request->isGet() === false){
  654. $this->error('请求错误');
  655. }
  656. $workOrder = input('Uniqid');
  657. if (empty($workOrder)){
  658. $this->error('参数错误');
  659. }
  660. $data = [];
  661. if (strpos($workOrder,',')){
  662. $data = explode(',',$workOrder);
  663. }else{
  664. $data[0] = $workOrder;
  665. }
  666. $res = Db::table('工单_基本资料')->where('Uniqid','in',$data)->delete();
  667. if ($res !== false){
  668. $this->success('成功');
  669. }else{
  670. $this->error('失败');
  671. }
  672. }
  673. /**
  674. * 产品废检系数调整->质检工艺数据获取
  675. * @ApiMethod (GET)
  676. * @param string $workOrder 工单编号
  677. * @return void
  678. * @throws \think\db\exception\DataNotFoundException
  679. * @throws \think\db\exception\ModelNotFoundException
  680. * @throws \think\exception\DbException
  681. */
  682. public function TestCoefficient()
  683. {
  684. if ($this->request->isGet() === false){
  685. $this->error('请求错误');
  686. }
  687. $workOrder = input('workOrder');
  688. if (empty($workOrder)){
  689. $this->error('参数错误');
  690. }
  691. $where = [
  692. 'Gy0_gdbh' => $workOrder,
  693. 'Gy0_gxmc' => ['like','%检%']
  694. ];
  695. $filed = 'rtrim(Gy0_gdbh) as gdbh,rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(人工检_正品板) as 人工正品板,
  696. rtrim(人工检_次品板) as 人工次品板,rtrim(人工检_废检) as 人工废检,rtrim(机检_正品板) as 机检正品板,rtrim(机检_次品板) as 机检次品板,
  697. rtrim(机检_废检) as 机检废检,rtrim(Gy0_sbbh) as 设备编号,rtrim(Uniqid) as Uniqid';
  698. $list = Db::table('工单_工艺资料')->where($where)->field($filed)->select();
  699. if (empty($list)){
  700. $this->error('未找到该工单工艺');
  701. }
  702. $name = Db::table('工单_基本资料')
  703. ->where('Gd_gdbh',$workOrder)
  704. ->field('rtrim(Gd_cpdh) as 产品代号,rtrim(Gd_khmc) as 客户名称,rtrim(Gd_cpmc) as 产品名称')
  705. ->find();
  706. if (empty($name)){
  707. $this->error('未找到该工单');
  708. }
  709. foreach ($list as $key=>$value){
  710. if ($value['yjno']<10){
  711. $value['yjno'] = '0'.$value['yjno'];
  712. }
  713. if ($value['gxh']<10){
  714. $value['gxh'] = '0'.$value['gxh'];
  715. }
  716. $list[$key]['印件工序及工艺'] = $value['gdbh'].'-'.$value['yjno'].'-'.$value['gxh'].'-'.$value['gxmc'];
  717. unset($list[$key]['gdbh'],$list[$key]['yjno'],$list[$key]['gxmc']);
  718. $list[$key]['产品编号'] = $name['产品代号'];
  719. $list[$key]['产品名称'] = $name['产品名称'];
  720. $list[$key]['客户名称'] = $name['客户名称'];
  721. }
  722. $this->success('成功',$list);
  723. }
  724. /**
  725. * 产品质检系数调整->系数修改
  726. * @ApiMethod (GET)
  727. * @param string $workorder 工单编号
  728. * @param string $processCode 工序号
  729. * @param float $code1 人工正品板
  730. * @param float $code2 人工次品板
  731. * @param float $code3 人工废检
  732. * @param float $code4 机检正品板
  733. * @param float $code5 机检次品板
  734. * @param float $code6 机检废检
  735. * @return void
  736. * @throws \think\Exception
  737. * @throws \think\exception\PDOException
  738. */
  739. public function TestCoefficientEdit()
  740. {
  741. if (Request::instance()->isPost() === false){
  742. $this->error('请求错误');
  743. }
  744. $workOrder = input('workOrder');
  745. $processCode = input('processCode');
  746. $row = [
  747. '人工检_正品板' => input('code1'),
  748. '人工检_次品板' => input('code2'),
  749. '人工检_废检' => input('code3'),
  750. '机检_正品板' => input('code4'),
  751. '机检_次品板' => input('code5'),
  752. '机检_废检' => input('code6'),
  753. ];
  754. if (empty($workOrder) || empty($processCode)){
  755. $this->error('参数错误');
  756. }
  757. $where = [
  758. 'Gy0_gdbh' => $workOrder,
  759. 'Gy0_gxh' => $processCode
  760. ];
  761. $sql = Db::table('工单_工艺资料')->where($where)->fetchSql(true)->update($row);
  762. $res = Db::query($sql);
  763. if ($res !== false){
  764. $this->success('成功');
  765. }else{
  766. $this->error('失败');
  767. }
  768. }
  769. /**
  770. * 修正工单核算参数->数据获取
  771. * @ApiMethod (GET)
  772. * @param string $workOrder 工单编号
  773. * @return void
  774. * @throws \think\db\exception\DataNotFoundException
  775. * @throws \think\db\exception\ModelNotFoundException
  776. * @throws \think\exception\DbException
  777. */
  778. public function AccountingParameter()
  779. {
  780. if ($this->request->isGet() === false){
  781. $this->error('请求错误');
  782. }
  783. $workOrder = input('workOrder');
  784. if (empty($workOrder)){
  785. $this->error('参数错误');
  786. }
  787. $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,
  788. rtrim(Gy0_sbbh) as 参照设备,rtrim(工价系数) as 难度系数,rtrim(Gy0_shdh) as 损耗代号,rtrim(Gy0_Rate0) as 基础损耗,rtrim(Gy0_Rate1) as 损耗率,
  789. rtrim(印刷方式) as 印刷方式,rtrim(版距) as 版距,rtrim(Gy0_ms) as 计损色数,rtrim(损耗系数) as 损耗系数,rtrim(UniqId) as UniqId';
  790. $list = Db::table('工单_工艺资料')->where('Gy0_gdbh',$workOrder)->field($field)->select();
  791. if (empty($list)){
  792. $this->error('未找到该工单工艺资料');
  793. }
  794. foreach ($list as $key=>$value){
  795. if ($value['yjno']<10){
  796. $value['yjno'] = '0'.$value['yjno'];
  797. }
  798. if ($value['gxh']<10){
  799. $value['gxh'] = '0'.$value['gxh'];
  800. }
  801. $list[$key]['印件号及工序名称'] = $value['yjno'].'-'.$value['gxh'].$value['gxmc'].'('.$value['add_gxmc'].')';
  802. unset($list[$key]['yjno'],$list[$key]['gxmc'],$list[$key]['add_gxmc']);
  803. }
  804. $this->success('成功',$list);
  805. }
  806. /**
  807. * 修正工单核算参数->参数修改
  808. * @ApiMethod (POST)
  809. * @param void
  810. * @return void
  811. * @throws \think\Exception
  812. * @throws \think\db\exception\DataNotFoundException
  813. * @throws \think\db\exception\ModelNotFoundException
  814. * @throws \think\exception\DbException
  815. * @throws \think\exception\PDOException
  816. */
  817. public function AccountingParameterEdit()
  818. {
  819. if (Request::instance()->isPost() === false){
  820. $this->error('请求错误');
  821. }
  822. $param = Request::instance()->post();
  823. if (empty($param) || isset($param[0]['Uniqid']) === false){
  824. $this->error('参数错误');
  825. }
  826. $i = 0;
  827. foreach ($param as $key=>$value){
  828. if (!empty($value['loss'])){
  829. $data = Db::table('dic_lzsh')->where('sys_bh',$value['loss'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
  830. }
  831. $row = [
  832. '工价系数' => $value['difficulty']?:'',
  833. 'Gy0_shdh' => $value['loss']?:'',
  834. '印刷方式' => $value['printMode']?:'',
  835. '版距' => $value['plate']?:'',
  836. 'Gy0_ms' => $value['chromatic']?:'',
  837. '损耗系数' => $value['wastage']?:'',
  838. 'Gy0_Rate0' => $data['rate0'],
  839. 'Gy0_Rate1' => $data['rate1']
  840. ];
  841. $sql = Db::table('工单_工艺资料')->where('Uniqid',$value['Uniqid'])->fetchSql(true)->update($row);
  842. $res = Db::query($sql);
  843. if ($res !== false){
  844. $i++;
  845. }
  846. }
  847. if ($i !== 0){
  848. $this->success('成功');
  849. }else{
  850. $this->error('失败');
  851. }
  852. }
  853. /**
  854. * 印件资料修改
  855. * @ApiMethod (POST)
  856. * @param void
  857. * @return void
  858. * @throws \think\Exception
  859. * @throws \think\exception\PDOException
  860. */
  861. public function PrintedEdit()
  862. {
  863. if (Request::instance()->isPost() === false){
  864. $this->error('请求错误');
  865. }
  866. $param = Request::instance()->post();
  867. if (empty($param) || isset($param['Uniqid']) === false){
  868. $this->error('参数错误');
  869. }
  870. // halt($param);
  871. $data = [
  872. 'yj_Yjno' => isset($param['yjno'])?$param['yjno']:'',
  873. 'yj_Yjdh' => isset($param['yjdh'])?$param['yjdh']:'',
  874. 'yj_yjmc' => isset($param['yjmc'])?$param['yjmc']:'',
  875. 'yj_zzdh' => isset($param['zzdh'])?$param['zzdh']:'',
  876. 'yj_zzdh1' => isset($param['zzdh1'])?$param['zzdh1']:'',
  877. 'yj_zzdh2' => isset($param['zzdh2'])?$param['zzdh2']:'',
  878. 'yj_zzdh3' => isset($param['zzdh3'])?$param['zzdh3']:'',
  879. 'yj_zzdh4' => isset($param['zzdh4'])?$param['zzdh4']:'',
  880. 'yj_zzmc' => isset($param['zzmc'])?$param['zzmc']:'',
  881. 'yj_zzmc1' => isset($param['zzmc1'])?$param['zzmc1']:'',
  882. 'yj_zzmc2' => isset($param['zzmc2'])?$param['zzmc2']:'',
  883. 'yj_zzmc3' => isset($param['zzmc3'])?$param['zzmc3']:'',
  884. 'yj_zzmc4' => isset($param['zzmc4'])?$param['zzmc4']:'',
  885. 'yj_成品数量' => isset($param['cpsl'])?$param['cpsl']:'',
  886. 'yj_实际投料' => isset($param['sjtl'])?$param['sjtl']:'',
  887. 'yj_平张投料' => isset($param['pztl'])?$param['pztl']:'',
  888. 'yj_tlgg' => isset($param['tlgg'])?$param['tlgg']:'',
  889. 'yj_klgg' => isset($param['klgg'])?$param['klgg']:'',
  890. 'Yj_核算规格' => isset($param['hsgg'])?$param['hsgg']:'',
  891. 'yj_ks' => isset($param['ks'])?$param['ks']:'',
  892. 'yj_ls' => isset($param['ls'])?$param['ls']:'',
  893. 'yj_desc' => isset($param['desc'])?$param['desc']:'',
  894. ];
  895. halt($data);
  896. $sql = Db::table('工单_印件资料')->where('Uniqid',$param['Uniqid'])->fetchSql(true)->update($data);
  897. $res = Db::query($sql);
  898. if ($res !== false){
  899. $this->success('成功');
  900. }else{
  901. $this->error('失败');
  902. }
  903. }
  904. /**
  905. * 工艺资料修改
  906. * @ApiMethod (POST)
  907. * @param void
  908. * @return void
  909. * @throws \think\Exception
  910. * @throws \think\db\exception\DataNotFoundException
  911. * @throws \think\db\exception\ModelNotFoundException
  912. * @throws \think\exception\DbException
  913. * @throws \think\exception\PDOException
  914. */
  915. public function ProcessDetailEdit()
  916. {
  917. if (Request::instance()->isPost() === false){
  918. $this->error('请求错误');
  919. }
  920. $param = Request::instance()->post();
  921. if (empty($param) || isset($param['UniqId']) === false){
  922. $this->error('参数错误');
  923. }
  924. $rate = Db::table('dic_lzsh')->where('sys_bh',$param['shdh'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
  925. $data = [
  926. '重点工序' => isset($param['zdgx'])?$param['zdgx']:'',
  927. '备选工序' => isset($param['bxgx'])?$param['bxgx']:'',
  928. 'Gy0_sbbh' => isset($param['sbbh'])?$param['sbbh']:'',
  929. 'Gy0_Rate0' => isset($rate['rate0'])?$rate['rate0']:'',
  930. 'Gy0_Rate1' => isset($rate['rate1'])?$rate['rate1']:'',
  931. 'Gy0_shdh' => isset($param['shdh'])?$param['shdh']:'',
  932. '损耗系数' => isset($param['shxs'])?$param['shxs']:'',
  933. '工价系数' => isset($param['ndxs'])?$param['ndxs']:'',
  934. 'Mod_rq' => date('Y-m-d H:i:s',time()),
  935. ];
  936. $sql = Db::table('工单_工艺资料')->where('UniqId',$param['UniqId'])->fetchSql(true)->update($data);
  937. $res = Db::query($sql);
  938. $status = Db::table('工单_基本资料')->where('Gd_gdbh',$param['workOrder'])->field('rtrim(gd_statu) as status')->find();
  939. if ($status['status'] !== '2-生产中'){
  940. $statusSql = Db::table('工单_基本资料')->where('Gd_gdbh',$param['workOrder'])->fetchSql(true)->update(['gd_statu'=>'2-生产中']);
  941. Db::query($statusSql);
  942. }
  943. if ($res !== false){
  944. $this->success('成功');
  945. }else{
  946. $this->error('失败');
  947. }
  948. }
  949. /**
  950. * 工艺资料编辑->机台列表获取
  951. * @return void
  952. * @throws \think\db\exception\DataNotFoundException
  953. * @throws \think\db\exception\ModelNotFoundException
  954. * @throws \think\exception\DbException
  955. */
  956. public function MachineList()
  957. {
  958. if ($this->request->isGet() === false){
  959. $this->error('请求错误');
  960. }
  961. $param = $this->request->param();
  962. if (empty($param)){
  963. $this->error('参数错误');
  964. }
  965. $list = Db::table('设备_基本资料')
  966. ->where('存放地点',$param['address'])
  967. ->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')
  968. ->select();
  969. if (empty($list)){
  970. $this->error('未找到该车间机台');
  971. }
  972. $data = [];
  973. foreach ($list as $key=>$value){
  974. $data[$key] = $value['设备编号'].'-->'.$value['设备名称'];
  975. }
  976. $this->success('成功',$data);
  977. }
  978. /**
  979. * 打印作业通知单
  980. * @ApiMethod (POST)
  981. * @param void
  982. * @return void
  983. * @throws \think\db\exception\DataNotFoundException
  984. * @throws \think\db\exception\ModelNotFoundException
  985. * @throws \think\exception\DbException
  986. */
  987. public function PrintJobOrder()
  988. {
  989. if ($this->request->isGet() === false) {
  990. $this->error('请求错误');
  991. }
  992. $param = $this->request->param();
  993. if (empty($param)){
  994. $this->error('参数错误');
  995. }
  996. $data = $this->workOrderDetailGet($param['workOrder']);
  997. if (empty($data)){
  998. $this->error('未找到工单信息');
  999. }
  1000. $materiel = $this->MaterielDetailGet($param['workOrder']);
  1001. if (empty($materiel)){
  1002. $this->error('未找到物料信息');
  1003. }
  1004. $printDetail = $this->PrintDetailGet($param['workOrder']);
  1005. if (empty($printDetail)){
  1006. $this->error('未找到工艺信息');
  1007. }
  1008. $number = 0;
  1009. foreach ($printDetail as $key=>$value){
  1010. $value['允损比例'] = (float)substr($value['允损比例'],0,-1);
  1011. $number = $number+$value['允损比例'];
  1012. }
  1013. $data['制单'] = $param['PrepareDocument'];
  1014. $data['审核'] = $param['examine'];
  1015. $data['目标合格率'] = 100-$number.'%';
  1016. $data['materiel'] = $materiel;
  1017. $data['printDetail'] = $printDetail;
  1018. $this->success('成功',$data);
  1019. }
  1020. /**
  1021. * 打印作业通知单->工单及印件资料获取
  1022. * @param $workOrder
  1023. * @return mixed
  1024. */
  1025. public function workOrderDetailGet($workOrder)
  1026. {
  1027. $sql = "SELECT
  1028. RTRIM( a.Gd_gdbh ) AS 生产批次号,
  1029. RTRIM( a.销售订单号 ) AS 销售订单号,
  1030. RTRIM( a.Gd_客户代号 ) AS 客户代号,
  1031. RTRIM( a.Gd_客户名称 ) AS 客户名称,
  1032. RTRIM( a.成品代号 ) AS 产品代码,
  1033. RTRIM( a.成品名称 ) AS 产品名称,
  1034. RTRIM( a.产品版本号 ) AS 版本号,
  1035. RTRIM( a.警语版面 ) AS 警语版面,
  1036. RTRIM( a.码源数量 ) AS 码源数量,
  1037. RTRIM( a.客户ERP编码 ) AS 客户ERP编码,
  1038. RTRIM( a.接单日期 ) AS 开单日期,
  1039. RTRIM( a.交货日期 ) AS 交货日期,
  1040. RTRIM( a.Gd_desc ) AS 工单说明,
  1041. RTRIM( a.投料率 ) AS 投料率,
  1042. RTRIM( a.平均合格率 ) AS 平均合格率,
  1043. RTRIM( a.投料大箱 ) AS 订货数量,
  1044. RTRIM( a.排产时库存 ) AS 排产时库存,
  1045. RTRIM( b.yj_Yjno ) AS 印件,
  1046. RTRIM( b.yj_Yjdh ) AS 印件代号,
  1047. RTRIM( b.yj_yjmc ) AS 印件名称,
  1048. RTRIM( b.yj_平张投料 ) AS 平张投料量,
  1049. RTRIM( b.yj_zzmc ) AS 纸张名称,
  1050. RTRIM( b.yj_tlgg ) AS 投料规格,
  1051. RTRIM( b.yj_ks ) AS 开数,
  1052. RTRIM( b.yj_ls ) AS 联数,
  1053. RTRIM( b.yj_desc ) AS 印件备注
  1054. FROM
  1055. `工单_基本资料` AS a
  1056. JOIN `工单_印件资料` AS b ON b.Yj_Gdbh = a.Gd_gdbh
  1057. WHERE
  1058. a.Gd_gdbh = '{$workOrder}' AND a.行号 = 1";
  1059. $list = Db::query($sql);
  1060. if (empty($list)){
  1061. $this->error('未找到订单数据');
  1062. }
  1063. $list[0]['开单日期'] = date('Y-m-d',strtotime($list[0]['开单日期']));
  1064. $list[0]['交货日期'] = date('Y-m-d',strtotime($list[0]['交货日期']));
  1065. $list[0]['订货数量'] = (int)$list[0]['订货数量'];
  1066. $list[0]['联数'] = (int)$list[0]['联数'];
  1067. $list[0]['印件代号及名称'] = $list[0]['印件代号'].' '.$list[0]['印件名称'];
  1068. $list[0]['投料数量'] = $list[0]['订货数量'];
  1069. unset($list[0]['印件代号'],$list[0]['印件名称']);
  1070. return($list[0]);
  1071. }
  1072. /**打印作业流程单->物料资料获取
  1073. * @param $workOrder
  1074. * @return bool|\PDOStatement|string|\think\Collection
  1075. * @throws \think\db\exception\DataNotFoundException
  1076. * @throws \think\db\exception\ModelNotFoundException
  1077. * @throws \think\exception\DbException
  1078. */
  1079. public function MaterielDetailGet($workOrder)
  1080. {
  1081. $where = [
  1082. 'BOM_工单编号' => $workOrder,
  1083. ];
  1084. $filed = 'rtrim(BOM_物料编码) as 物料编码,rtrim(BOM_物料名称) as 物料名称,rtrim(BOM_投料单位) as 投料单位,rtrim(BOM_计划用量) as 计划用量';
  1085. $list = Db::table('工单_bom资料')->where($where)->field($filed)->select();
  1086. if (empty($list)){
  1087. $this->error('未找到物料资料信息');
  1088. }
  1089. foreach ($list as $key=>$value){
  1090. $list[$key]['物料代码及名称'] = $value['物料编码'].' '.$value['物料名称'];
  1091. $list[$key]['计划用量'] = (float)$value['计划用量'];
  1092. unset($list[$key]['物料编码'],$list[$key]['物料名称']);
  1093. }
  1094. return $list;
  1095. }
  1096. /**
  1097. * 打印作业流程单->工艺资料获取
  1098. * @param $workOrder
  1099. * @return bool|\PDOStatement|string|\think\Collection
  1100. * @throws \think\db\exception\DataNotFoundException
  1101. * @throws \think\db\exception\ModelNotFoundException
  1102. * @throws \think\exception\DbException
  1103. */
  1104. public function PrintDetailGet($workOrder)
  1105. {
  1106. $where = [
  1107. 'Gy0_gdbh' => $workOrder,
  1108. ];
  1109. $filed = 'rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
  1110. rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ls) as ls,rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_计划损耗) as 计划损耗,
  1111. rtrim(Gy0_辅助工时) as 装版工时,rtrim(Gy0_小时产能) as 小时定额,rtrim(Gy0_生产工时) as 生产工时,rtrim(工序备注) as 工序备注';
  1112. $list = Db::table('工单_工艺资料')
  1113. ->where($where)
  1114. ->field($filed)
  1115. ->select();
  1116. if (empty($list)){
  1117. $this->error('工单工艺为空');
  1118. }
  1119. foreach ($list as $key=>$value){
  1120. if ($value['yjno']<10){
  1121. $value['yjno'] = '0'.$value['yjno'];
  1122. }
  1123. if ($value['gxh']<10){
  1124. $value['gxh'] = '0'.$value['gxh'];
  1125. }
  1126. if ($value['add_gxmc'] !== null){
  1127. $list[$key]['印件及工序名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
  1128. }else{
  1129. $list[$key]['印件及工序名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'];
  1130. }
  1131. $list[$key]['转序数'] = (int)($value['计划接货数']/$value['ls']);
  1132. $list[$key]['报废定额'] = (int)($value['计划损耗']/$value['ls']);
  1133. $list[$key]['允损比例'] = round(($value['计划损耗']/$value['计划接货数'])*100,2).'%';
  1134. unset($list[$key]['yjno'],$list[$key]['gxh'],$list[$key]['gxmc'],$list[$key]['add_gxmc'],$list[$key]['计划接货数'],$list[$key]['计划损耗']);
  1135. }
  1136. return $list;
  1137. }
  1138. }