WorkOrder.php 49 KB

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