WorkOrder.php 66 KB

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