WorkOrder.php 50 KB

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