WorkOrder.php 51 KB

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