WorkOrder.php 50 KB

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