WorkOrder.php 50 KB

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