WorkOrder.php 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681
  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. $sql = "SELECT DISTINCT
  47. (客户编号),rtrim(客户名称 ) as 客户名称
  48. FROM
  49. `产品_基本资料`
  50. GROUP BY
  51. 客户编号
  52. order by
  53. 客户编号";
  54. $list = \db()->query($sql);
  55. if (empty($list)){
  56. $this->success('',[]);
  57. }
  58. foreach ($list as $key=>$value){
  59. $value['客户编号'] = rtrim($value['客户编号']);
  60. if ($value['客户编号'] == '1098'){
  61. $value['客户名称'] = '打样专用';
  62. }
  63. //这条sql查出来的数据可能不对,试一下以下sql
  64. //SELECT COUNT(*) FROM `工单_基本资料` WHERE (SUBSTRING( `成品代号`, 1, 4 ) = '1001' OR (`Gd_客户名称`='浙江中烟' AND `Gd_客户代号` = '1001')) AND gd_statu = '2-生产中' AND `行号` = '1'
  65. $productIng = \db('工单_基本资料')->where('行号','1')->where('成品代号','LIKE',rtrim($value['客户编号']).'%')->where('gd_statu','2-生产中')->count();
  66. $proGress = \db('工单_基本资料')->where('行号','1')->where('成品代号','LIKE',rtrim($value['客户编号']).'%')->where('gd_statu','3-计划中')->count();
  67. $string = '';
  68. if ($productIng != 0){
  69. $string = $string."生产中:".$productIng;
  70. }
  71. if ($proGress != 0){
  72. $string = $string."计划中:".$proGress;
  73. }
  74. if ($string !== ''){
  75. // $data[$key] = $value['prefix'].'【'.$string.'】'.($value['客户名称']!==''?$value['客户名称']:$value['khmc']);
  76. $data[$key] = $value['客户编号'].'【'.$string.'】'.$value['客户名称'];
  77. }else{
  78. // $data[$key] = $value['prefix'].($value['客户名称']!==''?$value['客户名称']:$value['khmc']);
  79. $data[$key] = $value['客户编号'].$value['客户名称'];
  80. }
  81. }
  82. $this->success('成功',$data);
  83. }
  84. /**
  85. * 工单基本资料列表
  86. * @ApiMethod (GET)
  87. * @param string $limit 查询长度
  88. * @param string $Gd_khdh 客户代号
  89. * @param string $startTime 接单日期开始时间
  90. * @param string $endTime 接单日期结束时间
  91. * @return \think\response\Json
  92. * @throws \think\exception\DbException
  93. */
  94. public function WorkList()
  95. {
  96. if ($this->request->isGet() === false){
  97. $this->error('请求错误');
  98. }
  99. $search = input('search');
  100. $clientNumber = input('Gd_khdh');
  101. $startTime = input('start');
  102. $endTime = input('end');
  103. $page = input('page');
  104. $limit = input('limit');
  105. $where = [];
  106. if (!empty($clientNumber)){
  107. $where['成品代号'] = ['like',$clientNumber.'%'];
  108. }
  109. if (!empty($workOrder)){
  110. $where['Gd_gdbh'] = $workOrder;
  111. }
  112. if (!empty($productCode)){
  113. $where['Gd_cpdh'] = $productCode;
  114. }
  115. if (!empty($search)){
  116. $where['Gd_lx|Gd_gdbh|Gd_客户代号|Gd_客户名称|Gd_khdh|Gd_khmc|Gd_cpdh|Gd_cpmc|成品代号|成品名称|产品版本号'] = ['like','%'.$search.'%'];
  117. }
  118. if (!empty($startTime) && !empty($endTime)){
  119. $where['接单日期'] = ['between',[$startTime,$endTime]];
  120. }
  121. $total = \db('工单_基本资料')->where($where)->count();
  122. $list = \db('工单_基本资料')
  123. ->where($where)
  124. ->order('Gd_statu desc')
  125. ->limit(($page-1)*$limit,$limit)
  126. ->select();
  127. //工单基本资料数据整理
  128. $data = [];
  129. foreach ($list as $key=>$value){
  130. $data[$key] = [
  131. '工单编号' => rtrim($value['Gd_gdbh']),
  132. '生产分类' => rtrim($value['Gd_生产分类']),
  133. '销售订单号' => rtrim($value['销售订单号']),
  134. '产品代号' => rtrim($value['Gd_cpdh']),
  135. '产品名称' => rtrim($value['Gd_cpmc']),
  136. '订单数量' => rtrim($value['订单数量']),
  137. '单位' => rtrim($value['计量单位']),
  138. '折合大箱' => rtrim((int)$value['投料大箱']),
  139. '投料率' => rtrim($value['投料率']),
  140. '平均合格率' => '',
  141. '开单日期' => date('Y-m-d',strtotime(rtrim($value['接单日期']))),
  142. '交货日期' => date('Y-m-d',strtotime(rtrim($value['交货日期']))),
  143. '工单类型' => rtrim($value['Gd_lx']),
  144. '工单状态' => rtrim($value['gd_statu']),
  145. '当前生产工序' => '',
  146. '产量提交时间' => '',
  147. '建档用户' => rtrim($value['Sys_id']),
  148. '建档时间' => rtrim($value['Sys_rq']),
  149. '更新时间' => rtrim($value['Mod_rq']),
  150. 'Uniqid' => rtrim($value['Uniqid'])
  151. ];
  152. $number = \db('工单_工艺资料')->where('Gy0_gdbh',$data[$key]['工单编号'])->count();
  153. if ($number === 0){
  154. $data[$key]['status'] = '*';
  155. }else{
  156. $data[$key]['status'] = '';
  157. }
  158. }
  159. $this->success('成功',['data'=>$data,'total'=>$total]);
  160. }
  161. /**
  162. * 工单详情
  163. * @ApiMethod (GET)
  164. * @param void
  165. * @return void
  166. * @throws \think\db\exception\DataNotFoundException
  167. * @throws \think\db\exception\ModelNotFoundException
  168. * @throws \think\exception\DbException
  169. */
  170. public function workOrderListDetail()
  171. {
  172. if ($this->request->isGet() === false){
  173. $this->error('请求错误');
  174. }
  175. $Gd_gdbh = input('Gd_gdbh');
  176. if (empty($Gd_gdbh)){
  177. $this->error('参数错误');
  178. }
  179. $data = [];
  180. //印件资料
  181. $printList = \db('工单_印件资料')
  182. ->where('Yj_Gdbh',$Gd_gdbh)
  183. ->select();
  184. if (!empty($printList)){
  185. foreach ($printList as $key=>$value){
  186. $data['printList'][$key] = [
  187. '印件号' => rtrim($value['yj_Yjno']),
  188. '印件代号' => rtrim($value['yj_Yjdh']),
  189. '印件名称' => rtrim($value['yj_yjmc']),
  190. '纸张代号' => rtrim($value['yj_zzdh']),
  191. '纸张名称' => rtrim($value['yj_zzmc']),
  192. '投料规格' => rtrim($value['yj_tlgg']),
  193. '平张投料' => rtrim($value['yj_平张投料']),
  194. '开料规格' => rtrim($value['yj_klgg']),
  195. '开数*联数' => rtrim($value['yj_ks']).'*'.rtrim($value['yj_ls']),
  196. '建档用户' => rtrim($value['Sys_id']),
  197. '建档时间' => rtrim($value['Sys_rq']),
  198. '更新时间' => rtrim($value['Mod_rq']),
  199. 'zzdh1' => rtrim($value['yj_zzdh1']),
  200. 'zzdh2' => rtrim($value['yj_zzdh2']),
  201. 'zzdh3' => rtrim($value['yj_zzdh3']),
  202. 'zzdh4' => rtrim($value['yj_zzdh4']),
  203. 'zzmc1' => rtrim($value['yj_zzmc1']),
  204. 'zzmc2' => rtrim($value['yj_zzmc2']),
  205. 'zzmc3' => rtrim($value['yj_zzmc3']),
  206. 'zzmc4' => rtrim($value['yj_zzmc4']),
  207. '订单数量' => rtrim($value['yj_成品数量']),
  208. '万小张' => rtrim($value['yj_实际投料']),
  209. '开数' => rtrim($value['yj_ks']),
  210. '联数' => rtrim($value['yj_ls']),
  211. '核算规格' => rtrim($value['Yj_核算规格']),
  212. '备注' => rtrim($value['yj_desc']),
  213. 'Uniqid' => rtrim($value['Uniqid'])
  214. ];
  215. }
  216. }else{
  217. $data['printList'] = [];
  218. }
  219. //工艺资料
  220. $processList = \db('工单_工艺资料')
  221. ->where('Gy0_gdbh',$Gd_gdbh)
  222. ->order('Gy0_yjno,Gy0_gxh')
  223. ->select();
  224. if (!empty($processList)){
  225. foreach ($processList as $key=>$value){
  226. if ($value['Gy0_yjno']<10){
  227. $value['Gy0_yjno'] = '0'.$value['Gy0_yjno'];
  228. }
  229. if ($value['Gy0_gxh']<10){
  230. $value['Gy0_gxh'] = '0'.$value['Gy0_gxh'];
  231. }
  232. if ((int)$value['Gy0_ms'] === 0){
  233. $scrap = ceil(($value['Gy0_Rate0']+((int)($value['Gy0_计划接货数']/$value['Gy0_ls']))*$value['Gy0_Rate1'])*$value['损耗系数']);
  234. }else{
  235. $scrap = ceil(($value['Gy0_Rate0']+((int)($value['Gy0_计划接货数']/$value['Gy0_ls']))*$value['Gy0_Rate1'])*$value['损耗系数']*$value['Gy0_ms']);
  236. }
  237. $number = round(($scrap/((int)($value['Gy0_计划接货数']/$value['Gy0_ls'])))*100,2).'%';
  238. if ($value['PD_WG'] !== '1900-01-01 00:00:00'){
  239. $status = '已完工';
  240. }else{
  241. $status = '未完工';
  242. }
  243. $data['processList'][$key] = [
  244. '重点工序' => rtrim($value['重点工序']),
  245. '印件-工序' => rtrim($value['Gy0_yjno']).'-'.rtrim($value['Gy0_gxh']),
  246. '备选工序' => rtrim($value['备选工序']),
  247. '工序名称' => rtrim($value['Gy0_gxmc']).'【'.rtrim($value['Add_gxmc']).'】',
  248. '计划产量' => (int)($value['Gy0_计划接货数']/$value['Gy0_ls']),
  249. '基础损耗' => rtrim($value['Gy0_Rate0']),
  250. '损耗率' => rtrim($value['Gy0_Rate1']),
  251. '报废定额' => $scrap,
  252. '允损比例' => $number,
  253. '难度系数' => isset($value['工价系数'])?rtrim($value['工价系数']):'',
  254. '损耗系数' => isset($value['损耗系数'])?rtrim($value['损耗系数']):'',
  255. '人工检_次品板' => (int)$value['人工检_次品板']=0?'':$value['人工检_次品板'],
  256. '人工检_废检' => (int)$value['人工检_废检']=0?'':$value['人工检_废检'],
  257. '机检_正品板' => (int)$value['机检_正品板']=0?'':$value['机检_正品板'],
  258. '机检_次品板' => (int)$value['机检_次品板']=0?'':$value['机检_次品板'],
  259. '机检_废检' => (int)$value['机检_废检']=0?'':$value['机检_废检'],
  260. '开数*联数' => rtrim($value['Gy0_ks']).'*'.rtrim($value['Gy0_ls']),
  261. '备注' => isset($value['工序备注'])?rtrim($value['工序备注']):'',
  262. '印刷方式' => isset($value['印刷方式'])?rtrim($value['印刷方式']):'',
  263. '版距' => isset($value['版距'])?rtrim($value['版距']):'',
  264. '建档用户' => rtrim($value['Sys_id']),
  265. '建档日期' => isset($value['Sys_rq'])?rtrim($value['Sys_rq']):'',
  266. '更新时间' => isset($value['Mod_rq'])?rtrim($value['Mod_rq']):'',
  267. '车间名称' => rtrim($value['Gy0_SITE']),
  268. '质量要求' => rtrim($value['质量要求']),
  269. '质量隐患' => rtrim($value['质量隐患']),
  270. '开数' => rtrim($value['Gy0_ks']),
  271. '联数' => rtrim($value['Gy0_ls']),
  272. 'UniqId' => rtrim($value['UniqId']),
  273. 'shdh' => rtrim($value['Gy0_shdh']),
  274. '辅助工时' => rtrim($value['Gy0_辅助工时']),
  275. '小时产能' => rtrim($value['Gy0_小时产能']),
  276. 'status' => $status
  277. ];
  278. }
  279. }else{
  280. $data['processList'] = [];
  281. }
  282. //BOM资料
  283. $field = 'rtrim(BOM_方案) as 方案,rtrim(BOM_物料编码) as 物料编号,rtrim(BOM_物料名称) as 物料名称,BOM_投料单位,
  284. BOM_投入数,BOM_产出数,BOM_产出单位,rtrim(BOM_计划用量) as 计划用量,rtrim(Sys_ID) as 建档用户,rtrim(Sys_rq) as 建档时间,rtrim(Mod_rq) as 更新时间';
  285. $bomList = \db('工单_bom资料')
  286. ->where('BOM_工单编号',$Gd_gdbh)
  287. ->field($field)
  288. ->select();
  289. if (!empty($bomList)){
  290. foreach ($bomList as $key=>$value){
  291. $bomList[$key]['消耗定量'] = rtrim($value['BOM_投入数']).rtrim($value['BOM_投料单位']).'/'.rtrim($value['BOM_产出数']).rtrim($value['BOM_产出单位']);
  292. unset($bomList[$key]['BOM_投料单位'],$bomList[$key]['BOM_投入数'],$bomList[$key]['BOM_产出数'],$bomList[$key]['BOM_产出单位']);
  293. $bomList[$key]['计划用量'] = rtrim((float)$value['计划用量']);
  294. }
  295. $data['BOM'] = $bomList;
  296. }else{
  297. $data['BOM'] = [];
  298. }
  299. $this->success('成功',$data);
  300. }
  301. /**
  302. * 编辑页面展示
  303. * @ApiMethod (GET)
  304. * @param string $workOrder 工单编号
  305. * @return void
  306. * @throws \think\db\exception\DataNotFoundException
  307. * @throws \think\db\exception\ModelNotFoundException
  308. * @throws \think\exception\DbException
  309. */
  310. public function DataCorrection()
  311. {
  312. if ($this->request->isGet() === false){
  313. $this->error('请求错误');
  314. }
  315. $workOrder = input('Gd_gdbh');
  316. if (empty($workOrder)){
  317. $this->error('参数错误');
  318. }
  319. $field = 'rtrim(Gd_lx) as 重点工单,rtrim(Gd_gdbh) as 工单编号,rtrim(Gd_生产分类) as 生产类型,rtrim(Gd_khdh) as 客户代号,rtrim(Gd_客户名称) as 客户名称,
  320. rtrim(Gd_cpdh) as 产品代号,rtrim(Gd_cpmc) as 产品名称,rtrim(接单日期) as 开单日期,rtrim(订单数量) as 订单数量,rtrim(交货日期) as 交货日期,
  321. rtrim(投料率) as 投料率,rtrim(实际投料) as 万小张,rtrim(计量单位) as 单位,rtrim(投料大箱) as 投料大箱,rtrim(排产时库存) as 库存大箱,rtrim(警语版面) as 警语版面,
  322. rtrim(销售订单号) as 销售订单号,rtrim(产品版本号) as 版本号,rtrim(客户ERP编码) as 客户ERP编码,rtrim(码源数量) as 码源数量,rtrim(进程备注) as 进程备注,rtrim(Gd_desc) as 备注,rtrim(Uniqid) as Uniqid';
  323. $list = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field($field)->find();
  324. if (empty($list)){
  325. $this->error('未找到该工单信息');
  326. }
  327. $printData = \db('工单_印件资料')
  328. ->where('Yj_Gdbh',$workOrder)
  329. ->field('rtrim(yj_yjmc) as 印件名称,rtrim(yj_Yjdh) as 印件代号,rtrim(yj_平张投料) as 平张投料,rtrim(Uniqid) as id')
  330. ->cache(true,84600)
  331. ->find();
  332. if (empty($printData)){
  333. $list['印件名称'] = '';
  334. $list['印件代号'] = '';
  335. $list['平张投料'] = '';
  336. $list['印件ID'] = '';
  337. }else{
  338. $list['印件名称'] = $printData['印件名称'];
  339. $list['印件代号'] = $printData['印件代号'];
  340. $list['平张投料'] = $printData['平张投料'];
  341. $list['印件ID'] = $printData['id'];
  342. }
  343. $this->success('成功',$list);
  344. }
  345. /**
  346. * 工单资料修改
  347. * @ApiMethod (POST)
  348. * @param void
  349. * @return void
  350. * @throws \think\Exception
  351. * @throws \think\exception\PDOException
  352. */
  353. public function WorkOrderEdit()
  354. {
  355. if (Request::instance()->isPost() === false){
  356. $this->error('请求错误');
  357. }
  358. $param = Request::instance()->post();
  359. if (empty($param) || isset($param['Uniqid']) === false){
  360. $this->error('参数错误');
  361. }
  362. $row = [
  363. 'Gd_lx' => isset($param['lx'])?$param['lx']:'',
  364. '开单日期' => isset($param['kdrq'])?$param['kdrq']:'',
  365. 'Gd_gdbh' => isset($param['gdbh'])?$param['gdbh']:'',
  366. 'Gd_生产分类' => isset($param['scfl'])?$param['scfl']:'',
  367. 'Gd_客户代号' => isset($param['khdh'])?$param['khdh']:'',
  368. 'Gd_客户名称' => isset($param['khmc'])?$param['khmc']:'',
  369. '成品代号' => isset($param['cpdh'])?$param['cpdh']:'',
  370. '成品名称' => isset($param['cpmc'])?$param['cpmc']:'',
  371. '订单数量' => isset($param['ddsl'])?$param['ddsl']:'',
  372. '交货日期' => isset($param['jhrq'])?$param['jhrq']:'',
  373. '投料率' => isset($param['tll'])?$param['tll']:'',
  374. '计划投料' => isset($param['jhtl'])?$param['jhtl']:'',
  375. '实际投料' => isset($param['sjtl'])?$param['sjtl']:'',
  376. '计量单位' => isset($param['jldw'])?$param['jldw']:'',
  377. '投料大箱' => isset($param['tldx'])?$param['tldx']:'',
  378. '销售订单号' => isset($param['xsddh'])?$param['xsddh']:'',
  379. '警语版面' => isset($param['jymb'])?$param['jymb']:'',
  380. '产品版本号' => isset($param['bbh'])?$param['bbh']:'',
  381. '客户ERP编码' => isset($param['erp'])?$param['erp']:'',
  382. '码源数量' => isset($param['ymsl'])?$param['ymsl']:'',
  383. '进程备注' => isset($param['jcbz'])?$param['jcbz']:'',
  384. 'Gd_desc' => isset($param['desc'])?$param['desc']:'',
  385. '排产时库存' => isset($param['kc'])?$param['kc']:'',
  386. '平均合格率' => isset($param['avg'])?$param['avg']:'',
  387. ];
  388. $sql = \db('工单_基本资料')->where('Uniqid',$param['Uniqid'])->fetchSql(true)->update($row);
  389. $res = Db::query($sql);
  390. $printSql = \db('工单_印件资料')
  391. ->where('Uniqid',$param['printID'])
  392. ->fetchSql(true)
  393. ->update(['yj_yjmc'=>$param['yjmc'],'yj_Yjdh'=>$param['yjdh'],'yj_平张投料'=>$param['jhtl']]);
  394. $printRes = Db::query($printSql);
  395. if ($res !== false && $printRes !== false){
  396. $this->success('成功');
  397. }else{
  398. $this->error('失败');
  399. }
  400. }
  401. /**
  402. * U8投料试算
  403. * @ApiMethod (GET)
  404. * @param string $processCode 产品编号
  405. * @return void
  406. * @throws \think\db\exception\DataNotFoundException
  407. * @throws \think\db\exception\ModelNotFoundException
  408. * @throws \think\exception\DbException
  409. */
  410. public function U8Trial()
  411. {
  412. if ($this->request->isGet() === false)
  413. {
  414. $this->error('请求错误');
  415. }
  416. $productCode = input('productCode');
  417. if (empty($productCode)){
  418. $this->error('参数错误');
  419. }
  420. $field = 'rtrim(Gy0_cpdh) as 产品代号,rtrim(Gy0_yjno) as 印件号,rtrim(Gy0_gxh) as 工序号,rtrim(gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
  421. rtrim(Gy0_Ms) as 墨色数,rtrim(Gy0_shdh) as 损耗代号,rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ls) as 加工联数';
  422. $list = \db('产品_工艺资料')->where('Gy0_cpdh',$productCode)->field($field)->select();
  423. if (empty($list)){
  424. $this->success('未找到该产品工序');
  425. }
  426. foreach ($list as $key=>$value){
  427. $data = \db('dic_lzsh')->where('sys_bh',$value['损耗代号'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->cache(true)->find();
  428. $list[$key]['调机损耗'] = isset($data['rate0'])?$data['rate0']:'';
  429. $list[$key]['运行损耗率'] = isset($data['rate1'])?$data['rate1']:'';
  430. if ($value['add_gxmc'] !== ''){
  431. $list[$key]['工序名称'] = $value['gxmc'].'【'.$value['add_gxmc'].'】';
  432. }else{
  433. $list[$key]['工序名称'] = $value['gxmc'];
  434. }
  435. unset($list[$key]['gxmc'],$list[$key]['add_gxmc']);
  436. }
  437. $this->success('成功',$list);
  438. }
  439. /**
  440. * 引用产品资料->获取产品资料
  441. * @ApiMethod (GET)
  442. * @param string $workOrder 工单编号
  443. * @return void
  444. * @throws \think\db\exception\DataNotFoundException
  445. * @throws \think\db\exception\ModelNotFoundException
  446. * @throws \think\exception\DbException
  447. */
  448. public function ProductInformation()
  449. {
  450. if ($this->request->isGet() === false)
  451. {
  452. $this->error('请求错误');
  453. }
  454. $workOrder = input('workOrder');
  455. if (empty($workOrder)){
  456. $this->error('参数错误');
  457. }
  458. $field = 'rtrim(Gd_gdbh) as 工单编号,rtrim(Gd_客户名称) as 客户名称,rtrim(成品代号) as 产品代号,rtrim(成品名称) as 产品名称';
  459. $Detail = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field($field)->find();
  460. if (empty($Detail)){
  461. $this->success('未找到工单信息');
  462. }
  463. $Detail['客户代号'] = substr($Detail['产品代号'],0,4);
  464. $this->success('成功',$Detail);
  465. }
  466. /**
  467. * 引用产品资料->复制产品工艺资料
  468. * @ApiMethod (POST)
  469. * @param string $oldWorkOrder 被复制工单编号
  470. * @param string $newWorkOrder 复制工单编号
  471. * @return void
  472. * @throws \think\Exception
  473. * @throws \think\db\exception\DataNotFoundException
  474. * @throws \think\db\exception\ModelNotFoundException
  475. * @throws \think\exception\DbException
  476. * @throws \think\exception\PDOException
  477. */
  478. public function ProductInformationEdit()
  479. {
  480. if (Request::instance()->isPost() === false)
  481. {
  482. $this->error('请求错误');
  483. }
  484. $oldWorkOrder = input('oldWorkOrder');
  485. $newWorkOrder = input('newWorkOrder');
  486. if (empty($oldWorkOrder) || empty($newWorkOrder))
  487. {
  488. $this->error('参数错误');
  489. }
  490. $lastId = \db('工单_工艺资料')->order('UniqId desc')->value('UniqId');
  491. if ($lastId<10000000){
  492. $lastId = 10000000;
  493. }else{
  494. $lastId = $lastId + 1;
  495. }
  496. //获取原工单工艺资料
  497. $oldProcessData = \db('工单_工艺资料')->where('Gy0_gdbh',$newWorkOrder)->select();
  498. $ProsessUniqId = \db('工单_工艺资料')->field('UniqId')->order('UniqId desc')->find();
  499. foreach ($oldProcessData as $k=>$v){
  500. $oldProcessData[$k]['Gy0_gdbh'] = $oldWorkOrder;
  501. $oldProcessData[$k]['Sys_id'] = '';
  502. $oldProcessData[$k]['UniqId'] = $lastId + $k;
  503. $oldProcessData[$k]['PD_WG'] = '1900-01-01 00:00:00';
  504. }
  505. if (\db('工单_工艺资料')->where('Gy0_gdbh',$oldWorkOrder)->find()){
  506. \db('工单_工艺资料')->where('Gy0_gdbh',$oldWorkOrder)->delete();
  507. }
  508. //获取原工单印件资料
  509. $lastUniqId = \db('工单_印件资料')->order('UniqId desc')->value('UniqId');
  510. if ($lastUniqId<1000000){
  511. $lastUniqId = 1000000;
  512. }else{
  513. $lastUniqId = $lastUniqId + 1;
  514. }
  515. $oldPrintData = \db('工单_印件资料')->where('Yj_Gdbh',$newWorkOrder)->select();
  516. $PrintUniqId = \db('工单_印件资料')->field('Uniqid')->order('Uniqid desc')->find();
  517. foreach ($oldPrintData as $k=>$v){
  518. $oldPrintData[$k]['Yj_Gdbh'] = $oldWorkOrder;
  519. $oldPrintData[$k]['Sys_id'] = '';
  520. $oldPrintData[$k]['Uniqid'] = $lastUniqId +$k +1;
  521. }
  522. if (\db('工单_印件资料')->where('Yj_Gdbh',$oldWorkOrder)->find()){
  523. \db('工单_印件资料')->where('Yj_Gdbh',$oldWorkOrder)->delete();
  524. }
  525. //复制印件、工艺资料
  526. $ProcessSQL = \db('工单_工艺资料')->fetchSql(true)->insertAll($oldProcessData);
  527. $ProcessRes = Db::query($ProcessSQL);
  528. $PrintSQL = \db('工单_印件资料')->fetchSql(true)->insertAll($oldPrintData);
  529. $PrintRes = Db::query($PrintSQL);
  530. if ($ProcessRes !== false && $PrintRes !== false){
  531. $this->success('成功');
  532. }else{
  533. $this->error('失败');
  534. }
  535. }
  536. /**
  537. * 工艺流程调成->获取当前工单工艺资料
  538. * @ApiMethod (GET)
  539. * @param string $workorder 当前工单编号
  540. * @return void
  541. * @throws \think\db\exception\DataNotFoundException
  542. * @throws \think\db\exception\ModelNotFoundException
  543. * @throws \think\exception\DbException
  544. */
  545. public function ProcessFlow()
  546. {
  547. if ($this->request->isGet() === false){
  548. $this->error('请求错误');
  549. }
  550. $workOrder = input('workOrder');
  551. if (empty($workOrder)){
  552. $this->error('参数错误');
  553. }
  554. $list = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field('rtrim(成品代号) as 成品编号,rtrim(成品名称) as 成品名称')->find();
  555. if (empty($list)){
  556. $this->success('未找到工单信息');
  557. }
  558. $filed = 'rtrim(Gy0_方案) as 方案,rtrim(Gy0_yjno) as 印件号,rtrim(Gy0_gxh) as 工序号,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
  559. rtrim(工价系数) as 工价系数,rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ks) as ks,rtrim(Gy0_ls) as ls,rtrim(工序备注) as 备注,rtrim(Gy0_SITE) as 车间,
  560. rtrim(Gy0_sbbh) as 设备编号,rtrim(Gy0_sbmc) as 设备名称,rtrim(Sys_id) as 建档用户,rtrim(Sys_rq) as 建档时间,rtrim(Mod_rq) as 更新时间,rtrim(UniqId) as UniqId';
  561. $process = \db('工单_工艺资料')->where('Gy0_gdbh',$workOrder)->cache(true,84600)->field($filed)->select();
  562. if (empty($process)){
  563. $this->error('未找到该工单工艺资料');
  564. }
  565. foreach ($process as $key=>$value){
  566. if (isset($value['add_gxmc'])){
  567. $process[$key]['工序名称'] = $value['gxmc'] . '【'.$value['add_gxmc'].'】';
  568. }else{
  569. $process[$key]['工序名称'] = $value['gxmc'];
  570. }
  571. $process[$key]['工价系数'] = (float)$value['工价系数'];
  572. $process[$key]['损耗系数'] = (float)$value['损耗系数'];
  573. $process[$key]['开数*联数'] = $value['ks'].'*'.$value['ls'];
  574. }
  575. $list['process'] = $process;
  576. $this->success('成功',$list);
  577. }
  578. /**
  579. * 参照工单列表获取
  580. * @ApiMethod (GET)
  581. * @param string $workOrder 工单编号
  582. * @param string $productCode 产品代号
  583. * @return void
  584. */
  585. public function ReferenceWorkOrder()
  586. {
  587. if ($this->request->isGet() === false){
  588. $this->error('请求错误');
  589. }
  590. $productCode = input('productCode');
  591. $workOrder = input('workOrder');
  592. if (empty($productCode) || empty($workOrder)){
  593. $this->error('参数错误');
  594. }
  595. $list = \db('工单_基本资料')->where('成品代号',$productCode)->distinct(true)->where('Gd_gdbh','<>',$workOrder)->column('Gd_gdbh');
  596. if (empty($list)){
  597. $this->success('未获取该产品其他工单信息');
  598. }
  599. $this->success('成功',$list);
  600. }
  601. /**
  602. * 工艺资料复制
  603. * @ApiMethod (POST)
  604. * @param string $oldWorkOrder 被复制工单编号
  605. * @param string $newWorkOrder 复制工单编号
  606. * @return void
  607. * @throws \think\Exception
  608. * @throws \think\db\exception\DataNotFoundException
  609. * @throws \think\db\exception\ModelNotFoundException
  610. * @throws \think\exception\DbException
  611. * @throws \think\exception\PDOException
  612. *
  613. */
  614. public function ProcessCopy()
  615. {
  616. if (Request::instance()->isPost() === false){
  617. $this->error('请求错误');
  618. }
  619. $param = Request::instance()->post();
  620. if (empty($param)){
  621. $this->error('参数错误');
  622. }
  623. $UniqId = [];
  624. $lastId = \db('工单_工艺资料')->field('rtrim(UniqId) as id')->order('UniqId desc')->find();
  625. if ($lastId['id']>10000000){
  626. $lastUniqId = $lastId['id'];
  627. }else{
  628. $lastUniqId = 10000000;
  629. }
  630. foreach ($param as $key=>$value){
  631. $UniqId[$key] = $value['UniqId'];
  632. }
  633. $processList = \db('工单_工艺资料')->where('UniqId','in',$UniqId)->select();
  634. if (empty($processList)){
  635. $this->success('未找到工艺资料');
  636. }
  637. $data = [];
  638. foreach ($param as $key=>$value){
  639. foreach ($processList as $k=>$v){
  640. if ($value['UniqId'] = $v['UniqId']){
  641. $data[$key] = $v;
  642. $data[$key]['Gy0_gxh'] = $value['gxh'];
  643. $data[$key]['Gy0_gdbh'] = $value['workOrder'];
  644. $data[$key]['UniqId'] = $lastUniqId + $key + 1;
  645. }
  646. }
  647. }
  648. $res = \db('工单_工艺资料')->where(['Gy0_gdbh'=>$param[0]['workOrder']])->delete();
  649. if ($res !== false){
  650. $result = \db('工单_工艺资料')->insertAll($data);
  651. if ($result !== false){
  652. $this->success('成功');
  653. }else{
  654. $this->error('失败');
  655. }
  656. }else{
  657. $this->error('失败');
  658. }
  659. }
  660. /**
  661. * U8工单列表
  662. * @ApiMethod (GET)
  663. * @param void
  664. * @return void
  665. * @throws \think\db\exception\DataNotFoundException
  666. * @throws \think\db\exception\ModelNotFoundException
  667. * @throws \think\exception\DbException
  668. */
  669. public function U8workOrder()
  670. {
  671. if ($this->request->isGet() === false){
  672. $this->error('请求错误');
  673. }
  674. $param = $this->request->param();
  675. if (empty($param)){
  676. $this->error('参数错误');
  677. }
  678. $filed = 'rtrim(Gd_gdbh) as 工单编号,rtrim(行号) as 行号,rtrim(Gd_客户代号) as 客户代号,rtrim(Gd_客户名称) as 客户名称,
  679. rtrim(成品代号) as 成品代号,rtrim(成品名称) as 成品名称,rtrim(Mod_rq) as 获取日期,rtrim(Uniqid) as 序号';
  680. $list = \db('工单_基本资料')->where('Gd_gdbh',$param['workOrder'])->field($filed)->select();
  681. if (empty($list)){
  682. $this->success('未找到工单');
  683. }
  684. $this->success('成功',$list);
  685. }
  686. /**
  687. * U8工单资料删除
  688. * @param string $workOrder 工单编号
  689. * @return void
  690. * @throws \think\Exception
  691. * @throws \think\exception\PDOException
  692. */
  693. public function U8DataCorrection()
  694. {
  695. if($this->request->isGet() === false){
  696. $this->error('请求错误');
  697. }
  698. $workOrder = input('Uniqid');
  699. if (empty($workOrder)){
  700. $this->error('参数错误');
  701. }
  702. $data = [];
  703. if (strpos($workOrder,',')){
  704. $data = explode(',',$workOrder);
  705. }else{
  706. $data[0] = $workOrder;
  707. }
  708. $res = \db('工单_基本资料')->where('Uniqid','in',$data)->delete();
  709. if ($res !== false){
  710. $this->success('成功');
  711. }else{
  712. $this->error('失败');
  713. }
  714. }
  715. /**
  716. * 产品废检系数调整->质检工艺数据获取
  717. * @ApiMethod (GET)
  718. * @param string $workOrder 工单编号
  719. * @return void
  720. * @throws \think\db\exception\DataNotFoundException
  721. * @throws \think\db\exception\ModelNotFoundException
  722. * @throws \think\exception\DbException
  723. */
  724. public function TestCoefficient()
  725. {
  726. if ($this->request->isGet() === false){
  727. $this->error('请求错误');
  728. }
  729. $workOrder = input('workOrder');
  730. if (empty($workOrder)){
  731. $this->error('参数错误');
  732. }
  733. $where = [
  734. 'Gy0_gdbh' => $workOrder,
  735. 'Gy0_gxmc' => ['like','%检%']
  736. ];
  737. $filed = 'rtrim(Gy0_gdbh) as gdbh,rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(人工检_正品板) as 人工正品板,
  738. rtrim(人工检_次品板) as 人工次品板,rtrim(人工检_废检) as 人工废检,rtrim(机检_正品板) as 机检正品板,rtrim(机检_次品板) as 机检次品板,
  739. rtrim(机检_废检) as 机检废检,rtrim(Gy0_sbbh) as 设备编号,rtrim(Uniqid) as Uniqid';
  740. $list = \db('工单_工艺资料')->where($where)->field($filed)->select();
  741. if (empty($list)){
  742. $this->success('未找到该工单工艺');
  743. }
  744. $name = \db('工单_基本资料')
  745. ->where('Gd_gdbh',$workOrder)
  746. ->field('rtrim(Gd_cpdh) as 产品代号,rtrim(Gd_khmc) as 客户名称,rtrim(Gd_cpmc) as 产品名称')
  747. ->find();
  748. if (empty($name)){
  749. $this->success('未找到该工单');
  750. }
  751. foreach ($list as $key=>$value){
  752. if ($value['yjno']<10){
  753. $value['yjno'] = '0'.$value['yjno'];
  754. }
  755. if ($value['gxh']<10){
  756. $value['gxh'] = '0'.$value['gxh'];
  757. }
  758. $list[$key]['印件工序及工艺'] = $value['gdbh'].'-'.$value['yjno'].'-'.$value['gxh'].'-'.$value['gxmc'];
  759. unset($list[$key]['gdbh'],$list[$key]['yjno'],$list[$key]['gxmc']);
  760. $list[$key]['产品编号'] = $name['产品代号'];
  761. $list[$key]['产品名称'] = $name['产品名称'];
  762. $list[$key]['客户名称'] = $name['客户名称'];
  763. }
  764. $this->success('成功',$list);
  765. }
  766. /**
  767. * 产品质检系数调整->系数修改
  768. * @ApiMethod (GET)
  769. * @param string $workorder 工单编号
  770. * @param string $processCode 工序号
  771. * @param float $code1 人工正品板
  772. * @param float $code2 人工次品板
  773. * @param float $code3 人工废检
  774. * @param float $code4 机检正品板
  775. * @param float $code5 机检次品板
  776. * @param float $code6 机检废检
  777. * @return void
  778. * @throws \think\Exception
  779. * @throws \think\exception\PDOException
  780. */
  781. public function TestCoefficientEdit()
  782. {
  783. if (Request::instance()->isPost() === false){
  784. $this->error('请求错误');
  785. }
  786. $workOrder = input('workOrder');
  787. $processCode = input('processCode');
  788. $row = [
  789. '人工检_正品板' => input('code1'),
  790. '人工检_次品板' => input('code2'),
  791. '人工检_废检' => input('code3'),
  792. '机检_正品板' => input('code4'),
  793. '机检_次品板' => input('code5'),
  794. '机检_废检' => input('code6'),
  795. ];
  796. if (empty($workOrder) || empty($processCode)){
  797. $this->error('参数错误');
  798. }
  799. $where = [
  800. 'Gy0_gdbh' => $workOrder,
  801. 'Gy0_gxh' => $processCode
  802. ];
  803. $sql = \db('工单_工艺资料')->where($where)->fetchSql(true)->update($row);
  804. $res = Db::query($sql);
  805. if ($res !== false){
  806. $this->success('成功');
  807. }else{
  808. $this->error('失败');
  809. }
  810. }
  811. /**
  812. * 修正工单核算参数->数据获取
  813. * @ApiMethod (GET)
  814. * @param string $workOrder 工单编号
  815. * @return void
  816. * @throws \think\db\exception\DataNotFoundException
  817. * @throws \think\db\exception\ModelNotFoundException
  818. * @throws \think\exception\DbException
  819. */
  820. public function AccountingParameter()
  821. {
  822. if ($this->request->isGet() === false){
  823. $this->error('请求错误');
  824. }
  825. $workOrder = input('workOrder');
  826. if (empty($workOrder)){
  827. $this->error('参数错误');
  828. }
  829. $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,
  830. rtrim(Gy0_sbbh) as 参照设备,rtrim(工价系数) as 难度系数,rtrim(Gy0_shdh) as 损耗代号,rtrim(Gy0_Rate0) as 基础损耗,rtrim(Gy0_Rate1) as 损耗率,
  831. rtrim(印刷方式) as 印刷方式,rtrim(版距) as 版距,rtrim(Gy0_ms) as 计损色数,rtrim(损耗系数) as 损耗系数,rtrim(UniqId) as UniqId';
  832. $list = \db('工单_工艺资料')->where('Gy0_gdbh',$workOrder)->field($field)->select();
  833. if (empty($list)){
  834. $this->success('未找到该工单工艺资料');
  835. }
  836. foreach ($list as $key=>$value){
  837. if ($value['yjno']<10){
  838. $value['yjno'] = '0'.$value['yjno'];
  839. }
  840. if ($value['gxh']<10){
  841. $value['gxh'] = '0'.$value['gxh'];
  842. }
  843. $list[$key]['印件号及工序名称'] = $value['yjno'].'-'.$value['gxh'].$value['gxmc'].'('.$value['add_gxmc'].')';
  844. unset($list[$key]['yjno'],$list[$key]['gxmc'],$list[$key]['add_gxmc']);
  845. }
  846. $this->success('成功',$list);
  847. }
  848. /**
  849. * 修正工单核算参数->参数修改
  850. * @ApiMethod (POST)
  851. * @param void
  852. * @return void
  853. * @throws \think\Exception
  854. * @throws \think\db\exception\DataNotFoundException
  855. * @throws \think\db\exception\ModelNotFoundException
  856. * @throws \think\exception\DbException
  857. * @throws \think\exception\PDOException
  858. */
  859. public function AccountingParameterEdit()
  860. {
  861. if (Request::instance()->isPost() === false){
  862. $this->error('请求错误');
  863. }
  864. $param = Request::instance()->post();
  865. if (empty($param) || isset($param[0]['Uniqid']) === false){
  866. $this->error('参数错误');
  867. }
  868. $i = 0;
  869. foreach ($param as $key=>$value){
  870. if (!empty($value['loss'])){
  871. $data = \db('dic_lzsh')->where('sys_bh',$value['loss'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
  872. }
  873. $row = [
  874. '工价系数' => $value['difficulty']?:'',
  875. 'Gy0_shdh' => $value['loss']?:'',
  876. '印刷方式' => $value['printMode']?:'',
  877. '版距' => $value['plate']?:'',
  878. 'Gy0_ms' => $value['chromatic']?:'',
  879. '损耗系数' => $value['wastage']?:'',
  880. 'Gy0_Rate0' => $data['rate0'],
  881. 'Gy0_Rate1' => $data['rate1']
  882. ];
  883. $sql = \db('工单_工艺资料')->where('Uniqid',$value['Uniqid'])->fetchSql(true)->update($row);
  884. $res = Db::query($sql);
  885. if ($res !== false){
  886. $i++;
  887. }
  888. }
  889. if ($i !== 0){
  890. $this->success('成功');
  891. }else{
  892. $this->error('失败');
  893. }
  894. }
  895. /**
  896. * 印件资料修改
  897. * @ApiMethod (POST)
  898. * @param void
  899. * @return void
  900. * @throws \think\Exception
  901. * @throws \think\exception\PDOException
  902. */
  903. public function PrintedEdit()
  904. {
  905. if (Request::instance()->isPost() === false){
  906. $this->error('请求错误');
  907. }
  908. $param = Request::instance()->post();
  909. if (empty($param) || isset($param['Uniqid']) === false){
  910. $this->error('参数错误');
  911. }
  912. $data = [
  913. 'yj_Yjno' => isset($param['yjno'])?$param['yjno']:'',
  914. 'yj_Yjdh' => isset($param['yjdh'])?$param['yjdh']:'',
  915. 'yj_yjmc' => isset($param['yjmc'])?$param['yjmc']:'',
  916. 'yj_zzdh' => isset($param['zzdh'])?$param['zzdh']:'',
  917. 'yj_zzdh1' => isset($param['zzdh1'])?$param['zzdh1']:'',
  918. 'yj_zzdh2' => isset($param['zzdh2'])?$param['zzdh2']:'',
  919. 'yj_zzdh3' => isset($param['zzdh3'])?$param['zzdh3']:'',
  920. 'yj_zzdh4' => isset($param['zzdh4'])?$param['zzdh4']:'',
  921. 'yj_zzmc' => isset($param['zzmc'])?$param['zzmc']:'',
  922. 'yj_zzmc1' => isset($param['zzmc1'])?$param['zzmc1']:'',
  923. 'yj_zzmc2' => isset($param['zzmc2'])?$param['zzmc2']:'',
  924. 'yj_zzmc3' => isset($param['zzmc3'])?$param['zzmc3']:'',
  925. 'yj_zzmc4' => isset($param['zzmc4'])?$param['zzmc4']:'',
  926. 'yj_成品数量' => isset($param['cpsl'])?$param['cpsl']:'',
  927. 'yj_实际投料' => isset($param['sjtl'])?$param['sjtl']:'',
  928. 'yj_平张投料' => isset($param['pztl'])?$param['pztl']:'',
  929. 'yj_tlgg' => isset($param['tlgg'])?$param['tlgg']:'',
  930. 'yj_klgg' => isset($param['klgg'])?$param['klgg']:'',
  931. 'Yj_核算规格' => isset($param['hsgg'])?$param['hsgg']:'',
  932. 'yj_ks' => isset($param['ks'])?$param['ks']:'',
  933. 'yj_ls' => isset($param['ls'])?$param['ls']:'',
  934. 'yj_desc' => isset($param['desc'])?$param['desc']:'',
  935. ];
  936. $sql = \db('工单_印件资料')->where('Uniqid',$param['Uniqid'])->fetchSql(true)->update($data);
  937. $res = Db::query($sql);
  938. if ($res !== false){
  939. $this->success('成功');
  940. }else{
  941. $this->error('失败');
  942. }
  943. }
  944. /**
  945. * 工艺资料修改
  946. * @ApiMethod (POST)
  947. * @param void
  948. * @return void
  949. * @throws \think\Exception
  950. * @throws \think\db\exception\DataNotFoundException
  951. * @throws \think\db\exception\ModelNotFoundException
  952. * @throws \think\exception\DbException
  953. * @throws \think\exception\PDOException
  954. */
  955. public function ProcessDetailEdit()
  956. {
  957. if (Request::instance()->isPost() === false){
  958. $this->error('请求错误');
  959. }
  960. $param = Request::instance()->post();
  961. if (empty($param) || isset($param['UniqId']) === false){
  962. $this->error('参数错误');
  963. }
  964. $rate = \db('dic_lzsh')->where('sys_bh',$param['shdh'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
  965. $data = [
  966. '重点工序' => isset($param['zdgx'])?$param['zdgx']:'',
  967. '备选工序' => isset($param['bxgx'])?$param['bxgx']:'',
  968. 'Gy0_sbbh' => isset($param['sbbh'])?$param['sbbh']:'',
  969. 'Gy0_Rate0' => isset($rate['rate0'])?$rate['rate0']:'',
  970. 'Gy0_Rate1' => isset($rate['rate1'])?$rate['rate1']:'',
  971. 'Gy0_shdh' => isset($param['shdh'])?$param['shdh']:'',
  972. '损耗系数' => isset($param['shxs'])?$param['shxs']:'',
  973. '工价系数' => isset($param['ndxs'])?$param['ndxs']:'',
  974. 'Gy0_小时产能' => $param['xscn'],
  975. 'Mod_rq' => date('Y-m-d H:i:s',time()),
  976. ];
  977. $sql = \db('工单_工艺资料')->where('UniqId',$param['UniqId'])->fetchSql(true)->update($data);
  978. $res = Db::query($sql);
  979. $status = \db('工单_基本资料')->where('Gd_gdbh',$param['workOrder'])->field('rtrim(gd_statu) as status')->find();
  980. if ($status['status'] !== '2-生产中'){
  981. $statusSql = \db('工单_基本资料')->where('Gd_gdbh',$param['workOrder'])->fetchSql(true)->update(['gd_statu'=>'2-生产中']);
  982. Db::query($statusSql);
  983. }
  984. if ($res !== false){
  985. $this->success('成功');
  986. }else{
  987. $this->error('失败');
  988. }
  989. }
  990. /**
  991. * 工艺资料编辑->机台列表获取
  992. * @return void
  993. * @throws \think\db\exception\DataNotFoundException
  994. * @throws \think\db\exception\ModelNotFoundException
  995. * @throws \think\exception\DbException
  996. */
  997. public function MachineList()
  998. {
  999. if ($this->request->isGet() === false){
  1000. $this->error('请求错误');
  1001. }
  1002. $param = $this->request->param();
  1003. if (empty($param)){
  1004. $this->error('参数错误');
  1005. }
  1006. $list = \db('设备_基本资料')
  1007. ->where('存放地点',$param['address'])
  1008. ->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')
  1009. ->select();
  1010. if (empty($list)){
  1011. $this->success('未找到该车间机台');
  1012. }
  1013. $data = [];
  1014. foreach ($list as $key=>$value){
  1015. $data[$key] = $value['设备编号'].'-->'.$value['设备名称'];
  1016. }
  1017. $this->success('成功',$data);
  1018. }
  1019. /**
  1020. * 打印作业通知单->工单印件和工序获取
  1021. * @ApiMethod (GET)
  1022. * @return void
  1023. * @throws \think\db\exception\DataNotFoundException
  1024. * @throws \think\db\exception\ModelNotFoundException
  1025. * @throws \think\exception\DbException
  1026. */
  1027. public function PrintCodeList()
  1028. {
  1029. if ($this->request->isGet() === false){
  1030. $this->error('请求错误');
  1031. }
  1032. $param = $this->request->param();
  1033. if (empty($param)){
  1034. $this->error('参数错误');
  1035. }
  1036. $list = \db('工单_印件资料')
  1037. ->field([
  1038. 'rtrim(yj_Yjno)' => '印件号',
  1039. 'rtrim(yj_yjmc)' => '印件名称'
  1040. ])
  1041. ->where('Yj_Gdbh',$param['workOrder'])
  1042. ->select();
  1043. $this->success('成功',$list);
  1044. }
  1045. /**
  1046. * 打印作业通知单->工艺编号获取
  1047. * @ApiMethod (GET)
  1048. * @return void
  1049. * @throws \think\db\exception\DataNotFoundException
  1050. * @throws \think\db\exception\ModelNotFoundException
  1051. * @throws \think\exception\DbException
  1052. */
  1053. public function ProcessCodeList()
  1054. {
  1055. if ($this->request->isGet() === false){
  1056. $this->error('请求错误');
  1057. }
  1058. $param = $this->request->param();
  1059. if (empty($param)){
  1060. $this->error('参数错误');
  1061. }
  1062. $list = \db('工单_工艺资料')
  1063. ->field('rtrim(Gy0_gxh) as 工序号')
  1064. ->where([
  1065. 'Gy0_gdbh' => $param['workOrder'],
  1066. 'Gy0_yjno' => $param['yjno']
  1067. ])
  1068. ->select();
  1069. $this->success('成功',$list);
  1070. }
  1071. /**
  1072. * 打印作业通知单
  1073. * @ApiMethod (POST)
  1074. * @param void
  1075. * @return void
  1076. * @throws \think\db\exception\DataNotFoundException
  1077. * @throws \think\db\exception\ModelNotFoundException
  1078. * @throws \think\exception\DbException
  1079. */
  1080. public function PrintJobOrder()
  1081. {
  1082. if ($this->request->isGet() === false) {
  1083. $this->error('请求错误');
  1084. }
  1085. $param = $this->request->param();
  1086. if (empty($param)){
  1087. $this->error('参数错误');
  1088. }
  1089. $data = $this->workOrderDetailGet($param['workOrder'],$param['yjno']);
  1090. if (empty($data)){
  1091. $this->success('未找到工单信息');
  1092. }
  1093. $materiel = $this->MaterielDetailGet($param['workOrder']);
  1094. if (empty($materiel)){
  1095. $this->success('未找到物料信息');
  1096. }
  1097. $printDetail = $this->PrintDetailGet($param['workOrder'],$param['yjno'],$param['gxh']);
  1098. if (empty($printDetail)){
  1099. $this->success('未找到工艺信息');
  1100. }
  1101. $number = 0;
  1102. foreach ($printDetail as $key=>$value){
  1103. $value['允损比例'] = (float)substr($value['允损比例'],0,-1);
  1104. $number = $number+$value['允损比例'];
  1105. }
  1106. $data['制单'] = $param['PrepareDocument'];
  1107. $data['审核'] = $param['examine'];
  1108. $data['目标合格率'] = 100-$number.'%';
  1109. $data['materiel'] = $materiel;
  1110. $data['printDetail'] = $printDetail;
  1111. $this->success('成功',$data);
  1112. }
  1113. /**
  1114. * 打印作业通知单->工单及印件资料获取
  1115. * @param $workOrder
  1116. * @return mixed
  1117. */
  1118. public function workOrderDetailGet($workOrder,$yjno)
  1119. {
  1120. $sql = "SELECT
  1121. RTRIM( a.Gd_lx) AS 工单类型,
  1122. RTRIM( a.Gd_gdbh ) AS 生产批次号,
  1123. RTRIM( a.销售订单号 ) AS 销售订单号,
  1124. RTRIM( a.Gd_客户代号 ) AS 客户代号,
  1125. RTRIM( a.Gd_客户名称 ) AS 客户名称,
  1126. RTRIM( a.成品代号 ) AS 产品代码,
  1127. RTRIM( a.成品名称 ) AS 产品名称,
  1128. RTRIM( a.产品版本号 ) AS 版本号,
  1129. RTRIM( a.警语版面 ) AS 警语版面,
  1130. RTRIM( a.码源数量 ) AS 码源数量,
  1131. RTRIM( a.客户ERP编码 ) AS 客户ERP编码,
  1132. RTRIM( a.接单日期 ) AS 开单日期,
  1133. RTRIM( a.交货日期 ) AS 交货日期,
  1134. RTRIM( a.Gd_desc ) AS 工单说明,
  1135. RTRIM( a.投料率 ) AS 投料率,
  1136. RTRIM( a.平均合格率 ) AS 平均合格率,
  1137. RTRIM( a.投料大箱 ) AS 订货数量,
  1138. RTRIM( a.排产时库存 ) AS 排产时库存,
  1139. RTRIM( b.yj_Yjno ) AS 印件,
  1140. RTRIM( b.yj_Yjdh ) AS 印件代号,
  1141. RTRIM( b.yj_yjmc ) AS 印件名称,
  1142. RTRIM( b.yj_平张投料 ) AS 平张投料量,
  1143. RTRIM( b.yj_zzmc ) AS 纸张名称,
  1144. RTRIM( b.yj_tlgg ) AS 投料规格,
  1145. RTRIM( b.yj_ks ) AS 开数,
  1146. RTRIM( b.yj_ls ) AS 联数,
  1147. RTRIM( b.yj_desc ) AS 印件备注
  1148. FROM
  1149. `工单_基本资料` AS a
  1150. JOIN `工单_印件资料` AS b ON b.Yj_Gdbh = a.Gd_gdbh
  1151. WHERE
  1152. a.Gd_gdbh = '{$workOrder}' AND a.行号 = 1 AND b.yj_Yjno = '{$yjno}'";
  1153. $list = Db::query($sql);
  1154. if (empty($list)){
  1155. $this->success('未找到订单数据');
  1156. }
  1157. $list[0]['开单日期'] = date('Y-m-d',strtotime($list[0]['开单日期']));
  1158. $list[0]['交货日期'] = date('Y-m-d',strtotime($list[0]['交货日期']));
  1159. $list[0]['订货数量'] = (int)$list[0]['订货数量'];
  1160. $list[0]['联数'] = (int)$list[0]['联数'];
  1161. $list[0]['印件代号及名称'] = $list[0]['印件代号'].' '.$list[0]['印件名称'];
  1162. $list[0]['投料数量'] = $list[0]['订货数量'];
  1163. unset($list[0]['印件代号'],$list[0]['印件名称']);
  1164. return($list[0]);
  1165. }
  1166. /**打印作业流程单->物料资料获取
  1167. * @param $workOrder
  1168. * @return bool|\PDOStatement|string|\think\Collection
  1169. * @throws \think\db\exception\DataNotFoundException
  1170. * @throws \think\db\exception\ModelNotFoundException
  1171. * @throws \think\exception\DbException
  1172. */
  1173. public function MaterielDetailGet($workOrder)
  1174. {
  1175. $where = [
  1176. 'BOM_工单编号' => $workOrder,
  1177. ];
  1178. $filed = 'rtrim(BOM_物料编码) as 物料编码,rtrim(BOM_物料名称) as 物料名称,rtrim(BOM_投料单位) as 投料单位,rtrim(BOM_计划用量) as 计划用量';
  1179. $list = \db('工单_bom资料')->where($where)->field($filed)->select();
  1180. if (empty($list)){
  1181. $this->success('未找到物料资料信息');
  1182. }
  1183. foreach ($list as $key=>$value){
  1184. $list[$key]['物料代码及名称'] = $value['物料编码'].' '.$value['物料名称'];
  1185. $list[$key]['计划用量'] = (float)$value['计划用量'];
  1186. unset($list[$key]['物料编码'],$list[$key]['物料名称']);
  1187. }
  1188. return $list;
  1189. }
  1190. /**
  1191. * 打印作业流程单->工艺资料获取
  1192. * @param $workOrder
  1193. * @return bool|\PDOStatement|string|\think\Collection
  1194. * @throws \think\db\exception\DataNotFoundException
  1195. * @throws \think\db\exception\ModelNotFoundException
  1196. * @throws \think\exception\DbException
  1197. */
  1198. public function PrintDetailGet($workOrder,$yjno,$gxh)
  1199. {
  1200. $where = [
  1201. 'Gy0_gdbh' => $workOrder,
  1202. 'Gy0_yjno' => $yjno,
  1203. 'Gy0_gxh' => ['<=',$gxh]
  1204. ];
  1205. $filed = 'rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
  1206. rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ls) as ls,rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_计划损耗) as 计划损耗,
  1207. rtrim(Gy0_辅助工时) as 装版工时,rtrim(Gy0_小时产能) as 小时定额,rtrim(Gy0_生产工时) as 生产工时,rtrim(工序备注) as 工序备注';
  1208. $list = \db('工单_工艺资料')
  1209. ->where($where)
  1210. ->field($filed)
  1211. ->select();
  1212. if (empty($list)){
  1213. $this->success('工单工艺为空');
  1214. }
  1215. foreach ($list as $key=>$value){
  1216. if ($value['yjno']<10){
  1217. $value['yjno'] = '0'.$value['yjno'];
  1218. }
  1219. if ($value['gxh']<10){
  1220. $value['gxh'] = '0'.$value['gxh'];
  1221. }
  1222. if ($value['add_gxmc'] !== null){
  1223. $list[$key]['印件及工序名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
  1224. }else{
  1225. $list[$key]['印件及工序名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'];
  1226. }
  1227. $list[$key]['转序数'] = (int)($value['计划接货数']/$value['ls']);
  1228. $list[$key]['报废定额'] = (int)($value['计划损耗']/$value['ls']);
  1229. $list[$key]['允损比例'] = round(($value['计划损耗']/$value['计划接货数'])*100,2).'%';
  1230. unset($list[$key]['yjno'],$list[$key]['gxh'],$list[$key]['gxmc'],$list[$key]['add_gxmc'],$list[$key]['计划接货数'],$list[$key]['计划损耗']);
  1231. }
  1232. return $list;
  1233. }
  1234. /**
  1235. * 获取小时产能
  1236. * @ApiMethod (GET)
  1237. * @param void
  1238. * @return void
  1239. * @throws \think\db\exception\DataNotFoundException
  1240. * @throws \think\db\exception\ModelNotFoundException
  1241. * @throws \think\exception\DbException
  1242. */
  1243. public function capacityList()
  1244. {
  1245. if ($this->request->isGet() === false){
  1246. $this->error('请求错误');
  1247. }
  1248. $param = $this->request->param();
  1249. if (empty($param)){
  1250. $this->error('参数错误');
  1251. }
  1252. $machine = explode(' ',$param['machine'])[0];
  1253. $number = \db('设备_基本资料')->where('设备编号',$machine)->field('rtrim(排单小时定额) as 小时产能')->find();
  1254. if (empty($number)){
  1255. $this->error('未找到小时产能');
  1256. }
  1257. $this->success('成功',$number['小时产能']);
  1258. }
  1259. /**
  1260. * 新增工单->添加工单
  1261. * @ApiMethod (POST)
  1262. * @param
  1263. * @return void
  1264. * @throws \think\Exception
  1265. * @throws \think\db\exception\BindParamException
  1266. * @throws \think\db\exception\DataNotFoundException
  1267. * @throws \think\db\exception\ModelNotFoundException
  1268. * @throws \think\exception\DbException
  1269. * @throws \think\exception\PDOException
  1270. */
  1271. public function WorkOrderAdd()
  1272. {
  1273. if (Request::instance()->isPost() === false){
  1274. $this->error('请求错误');
  1275. }
  1276. $param = Request::instance()->post();
  1277. if (empty($param)){
  1278. $this->error('参数错误');
  1279. }
  1280. $num = \db('工单_基本资料')->where('Gd_gdbh',$param['gdbh'])->count();
  1281. $productDetail = \db('产品_基本资料')->where('产品编号',$param['cpdh'])->find();
  1282. $lastId = \db('工单_基本资料')->order('Uniqid desc')->value('Uniqid');
  1283. if ($lastId<1000000000){
  1284. $lastId = 1000000000;
  1285. }
  1286. $data = [
  1287. 'Gd_lx' =>$param['zdgd'],
  1288. 'Gd_生产分类' =>$param['sclx'],
  1289. '成本处理类别' =>'',
  1290. 'Gd_gdbh' =>$param['gdbh'],
  1291. '行号' =>$num+1 ,
  1292. 'Gd_客户代号' =>$param['khdh'],
  1293. 'Gd_客户名称' =>$param['khmc'],
  1294. 'Gd_khdh' =>$param['khdh'],
  1295. 'Gd_khmc' =>$param['khmc'],
  1296. '客户料号' =>rtrim($productDetail['客户料号']),
  1297. '客户ERP编码' =>$param['erp'],
  1298. 'Gd_cpdh' =>$param['cpdh'],
  1299. 'Gd_cpmc' =>$param['cpmc'],
  1300. '成品代号' =>$param['cpdh'],
  1301. '成品名称' =>$param['cpmc'],
  1302. '产品版本号' =>$param['bbh'],
  1303. '销售订单号' =>$param['xsddh'],
  1304. '警语版面' =>$param['jybm'],
  1305. '码源数量' =>$param['mysl'],
  1306. '排产时库存' =>$param['kcdx'],
  1307. '投料大箱' =>$param['tldx'],
  1308. '投料率' =>$param['tll'],
  1309. '平均合格率' =>$param['hgl'],
  1310. '进程备注' =>$param['jcbz'],
  1311. 'Gd_desc' =>$param['remark'],
  1312. '开单日期' =>date('Y-m-d H:i:s',time()),
  1313. '接单日期' =>$param['start'],
  1314. '交货日期' =>$param['end'],
  1315. '订单数量' =>$param['number'],
  1316. '计量单位' =>$param['tldw'],
  1317. '计划投料' =>$param['pztl'],
  1318. '实际投料' =>$param['wxz'],
  1319. '产品单价' =>0,
  1320. '入仓日期' =>'1900-01-01 00:00:00',
  1321. '工单入仓数量' =>0,
  1322. '工单制程废品' => 0,
  1323. '工单质检废品' => 0,
  1324. '工单无形损' => 0,
  1325. '工单计划损耗' => 0,
  1326. '工单完工日期' => $param['end'],
  1327. '投料确认' => '',
  1328. 'gd_statu' => '3-计划中',
  1329. '直接人工' => 0,
  1330. '分摊人工' => 0,
  1331. '直接材料' => 0,
  1332. '考核直接材料' => 0,
  1333. '分摊材料' => 0,
  1334. '考核分摊材料' => 0,
  1335. '直接折旧' => 0,
  1336. '水电气费' => 0,
  1337. '分摊空调' => 0,
  1338. '分摊锅炉' => 0,
  1339. '分摊废气处理' => 0,
  1340. '分摊空压机' => 0,
  1341. '分摊鼓风机' => 0,
  1342. '分摊其他' => 0,
  1343. '待摊人工' => 0,
  1344. '待摊折旧' => 0,
  1345. '待摊场地租金' => 0,
  1346. '待摊其他费用' => 0,
  1347. '加工费' => 0,
  1348. '加工费单价' => 0,
  1349. '成本考核_胶印' => 0,
  1350. '成本考核_凹印' => 0,
  1351. '成本考核_丝印' => 0,
  1352. '成本考核_模切' => 0,
  1353. '成本考核_检验' => 0,
  1354. '印版费' => 0,
  1355. 'V23制造成本' => 0,
  1356. 'Prt_rq' => date('Y-m-d H:i:s',time()),
  1357. 'Sys_id' => '',
  1358. 'Sys_rq' => date('Y-m-d H:i:s',time()),
  1359. 'Mod_rq' => date('Y-m-d H:i:s',time()),
  1360. 'U8UID' => '',
  1361. 'Uniqid' => $lastId+1,
  1362. '工序加工费' => 0,
  1363. ];
  1364. $sql= \db('工单_基本资料')->fetchSql(true)->insert($data);
  1365. $res = \db()->query($sql);
  1366. if ($res !== false){
  1367. $this->success('成功');
  1368. }else{
  1369. $this->error('失败');
  1370. }
  1371. }
  1372. /**
  1373. * 新增工单->客户代号列表获取
  1374. * @return void
  1375. * @throws \think\db\exception\BindParamException
  1376. * @throws \think\exception\PDOException
  1377. */
  1378. public function ClientList()
  1379. {
  1380. if ($this->request->isGet() === false){
  1381. $this->error('请求错误');
  1382. }
  1383. $param = $this->request->param();
  1384. if (isset($param['search'])){
  1385. $where = $param['search'].'%';
  1386. $sql = "SELECT DISTINCT
  1387. (客户编号),rtrim(客户名称 ) as 客户名称
  1388. FROM
  1389. `产品_基本资料`
  1390. WHERE
  1391. 客户编号 LIKE "."'".$where."'"."
  1392. OR
  1393. 客户名称 LIKE "."'".$where."'"."
  1394. GROUP BY
  1395. 客户编号
  1396. order by
  1397. 客户编号";
  1398. }else{
  1399. $sql = "SELECT DISTINCT
  1400. (客户编号),rtrim(客户名称 ) as 客户名称
  1401. FROM
  1402. `产品_基本资料`
  1403. GROUP BY
  1404. 客户编号
  1405. order by
  1406. 客户编号";
  1407. }
  1408. $list = \db()->query($sql);
  1409. if (empty($list)){
  1410. $this->success('未找到客户列表');
  1411. }
  1412. foreach ($list as $key=>$value){
  1413. $list[$key]['客户编号'] = rtrim($value['客户编号']);
  1414. $list[$key]['name'] = rtrim($value['客户编号']).'【'.$value['客户名称'].'】';
  1415. if ($value['客户编号'] == '1098'){
  1416. $list[$key]['客户名称'] = '打样专用';
  1417. }
  1418. }
  1419. $this->success('成功',$list);
  1420. }
  1421. /**
  1422. * 新增工单->产品代号获取
  1423. * @ApiMethod (GET)
  1424. * @param void
  1425. * @return void
  1426. * @throws \think\db\exception\DataNotFoundException
  1427. * @throws \think\db\exception\ModelNotFoundException
  1428. * @throws \think\exception\DbException
  1429. */
  1430. public function ProductCodeList()
  1431. {
  1432. if ($this->request->isGet() === false){
  1433. $this->error('请求错误');
  1434. }
  1435. $param = $this->request->param();
  1436. if (isset($param['cilent']) === false){
  1437. $this->error('参数错误');
  1438. }
  1439. $where = ['产品编号'=>['like',$param['cilent'].'%']];
  1440. $list = \db('产品_基本资料')
  1441. ->where($where)
  1442. ->field('rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称')
  1443. ->select();
  1444. if (empty($list)){
  1445. $this->success('未获取到产品数据');
  1446. }
  1447. foreach ($list as $key=>$value){
  1448. $list[$key]['name'] = $value['产品编号'].'【'.$value['产品名称'].'】';
  1449. }
  1450. $this->success('成功',$list);
  1451. }
  1452. /**
  1453. * 新增印件资料->印件资料添加
  1454. * @return void
  1455. * @throws \think\db\exception\BindParamException
  1456. * @throws \think\exception\PDOException
  1457. */
  1458. public function PrintDetailAdd()
  1459. {
  1460. if (Request::instance()->isPost() === false){
  1461. $this->error('请求错误');
  1462. }
  1463. $param = Request::instance()->post();
  1464. if (empty($param)){
  1465. $this->error('参数错误');
  1466. }
  1467. $lastId = \db('工单_印件资料')->order('Uniqid desc')->value('Uniqid');
  1468. if ($lastId<1000000){
  1469. $lastId = 1000000;
  1470. }else{
  1471. $lastId = $lastId + 1;
  1472. }
  1473. $param['Uniqid'] = $lastId;
  1474. $param['Sys_rq'] = date('Y-m-d H:i:s',time());
  1475. $param['Mod_rq'] = date('Y-m-d H:i:s',time());
  1476. $sql = \db('工单_印件资料')->fetchSql(true)->insert($param);
  1477. $res = \db()->query($sql);
  1478. if ($res !== false){
  1479. $this->success('成功');
  1480. }else{
  1481. $this->error('失败');
  1482. }
  1483. }
  1484. //新增工艺资料->工艺资料添加
  1485. public function ProcessDetailAdd()
  1486. {
  1487. if (Request::instance()->isPost() === false){
  1488. $this->error('请求错误');
  1489. }
  1490. $param = Request::instance()->post();
  1491. if (empty($param)){
  1492. $this->error('参数错误');
  1493. }
  1494. $lastId = \db('工单_工艺资料')->order('UniqId desc')->value('UniqId');
  1495. if ($lastId<100000000){
  1496. $lastId = 100000000;
  1497. }else{
  1498. $lastId = $lastId + 1;
  1499. }
  1500. }
  1501. /**
  1502. * 新增工艺资料->印件编号获取
  1503. * @return void
  1504. * @throws \think\db\exception\DataNotFoundException
  1505. * @throws \think\db\exception\ModelNotFoundException
  1506. * @throws \think\exception\DbException
  1507. */
  1508. public function PrintDetailList()
  1509. {
  1510. if ($this->request->isGet() === false){
  1511. $this->error('请求错误');
  1512. }
  1513. $param = $this->request->param();
  1514. if (empty($param)){
  1515. $this->error('参数错误');
  1516. }
  1517. $printList = \db('工单_印件资料')
  1518. ->where('Yj_Gdbh',$param['workOrder'])
  1519. ->order('yj_Yjno')
  1520. ->select();
  1521. if (empty($printList)){
  1522. $this->success('未找到该工单印件资料');
  1523. }
  1524. $list = [];
  1525. foreach ($printList as $key=>$value){
  1526. $list[$key]['name'] = rtrim($value['yj_Yjno']).'-->'.rtrim($value['yj_yjmc']);
  1527. $list[$key]['no'] = rtrim($value['yj_Yjno']);
  1528. }
  1529. $this->success('成功',$list);
  1530. }
  1531. /**
  1532. * 工单资料管理->印件资料删除
  1533. * @return void
  1534. * @throws \think\Exception
  1535. * @throws \think\exception\PDOException
  1536. */
  1537. public function PrintDetailDel()
  1538. {
  1539. if ($this->request->isGet() === false){
  1540. $this->error('请求错误');
  1541. }
  1542. $param = $this->request->param();
  1543. if (isset($param['UniqId']) === false){
  1544. $this->error('参数错误');
  1545. }
  1546. $printId = explode(',',$param['UniqId']);
  1547. $i = 0;
  1548. foreach ($printId as $value){
  1549. $res = \db('工单_印件资料')
  1550. ->where('Uniqid',$value)
  1551. ->delete();
  1552. if ($res === false){
  1553. $i++;
  1554. }
  1555. }
  1556. if ($i === 0){
  1557. $this->success('删除成功');
  1558. }else{
  1559. $this->error('删除失败');
  1560. }
  1561. }
  1562. /**
  1563. * 工单资料管理->工艺资料删除
  1564. * @return void
  1565. * @throws \think\Exception
  1566. * @throws \think\exception\PDOException
  1567. */
  1568. public function ProcessDetailDel()
  1569. {
  1570. if ($this->request->isGet() === false){
  1571. $this->error('请求错误');
  1572. }
  1573. $param = $this->request->param();
  1574. if (isset($param['UniqId']) === false){
  1575. $this->error('参数错误');
  1576. }
  1577. $printId = explode(',',$param['UniqId']);
  1578. $i = 0;
  1579. foreach ($printId as $value){
  1580. $res = \db('工单_工艺资料')
  1581. ->where('UniqId',$value)
  1582. ->delete();
  1583. if ($res === false){
  1584. $i++;
  1585. }
  1586. }
  1587. if ($i === 0){
  1588. $this->success('删除成功');
  1589. }else{
  1590. $this->error('删除失败');
  1591. }
  1592. }
  1593. /**
  1594. * 工艺资料添加->工序损耗代码
  1595. * @return void
  1596. * @throws \think\db\exception\DataNotFoundException
  1597. * @throws \think\db\exception\ModelNotFoundException
  1598. * @throws \think\exception\DbException
  1599. */
  1600. public function WastageList()
  1601. {
  1602. if ($this->request->isGet() === false){
  1603. $this->error('请求错误');
  1604. }
  1605. $param = $this->request->param();
  1606. if (isset($param['search']) === false){
  1607. $this->error('参数错误');
  1608. }
  1609. $order = \db('dic_lzsh')
  1610. ->where('sys_mc','like',substr($param['search'],0,6).'%')
  1611. ->value('rtrim(sys_bh) as 编号');
  1612. $list = \db('dic_lzsh')
  1613. ->where('sys_bh','like',$order.'%')
  1614. ->where('sys_bh','<>',$order)
  1615. ->field('rtrim(sys_bh) as 编号,rtrim(sys_mc) as 名称,rtrim(UniqId) as UniqId')
  1616. ->select();
  1617. $this->success('成功',$list);
  1618. }
  1619. }