WorkOrder.php 50 KB

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