WorkOrder.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888
  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. // $page = input('page');
  74. $clientNumber = input('Gd_khdh');
  75. $startTime = input('start');
  76. $endTime = input('end');
  77. $where = [
  78. '成品代号' => ['like',$clientNumber.'%']
  79. ];
  80. // if (isset($search)){
  81. // $where['']
  82. // }
  83. if (isset($startTime) && isset($endTime)){
  84. $where['接单日期'] = ['between',[$startTime,$endTime]];
  85. }
  86. // $config = [
  87. // 'page_param' => $page,
  88. // 'per_page' => $limit
  89. // ];
  90. $list = Db::table('工单_基本资料')
  91. ->where($where)
  92. ->order('接单日期 desc')
  93. ->paginate($limit);
  94. //工单基本资料数据整理
  95. $data = [];
  96. foreach ($list->items() as $key=>$value){
  97. $data[$key] = [
  98. '工单编号' => rtrim($value['Gd_gdbh']),
  99. '生产分类' => rtrim($value['Gd_生产分类']),
  100. '销售订单号' => rtrim($value['销售订单号']),
  101. '产品代号' => rtrim($value['Gd_cpdh']),
  102. '产品名称' => rtrim($value['Gd_cpmc']),
  103. '订单数量' => rtrim($value['订单数量']),
  104. '单位' => rtrim($value['计量单位']),
  105. '折合大箱' => rtrim((int)$value['投料大箱']),
  106. '投料率' => rtrim($value['投料率']),
  107. '平均合格率' => '',
  108. '开单日期' => date('Y-m-d',strtotime(rtrim($value['接单日期']))),
  109. '交货日期' => date('Y-m-d',strtotime(rtrim($value['交货日期']))),
  110. '工单类型' => rtrim($value['Gd_lx']),
  111. '工单状态' => rtrim($value['gd_statu']),
  112. '当前生产工序' => '',
  113. '产量提交时间' => '',
  114. '建档用户' => rtrim($value['Sys_id']),
  115. '建档时间' => rtrim($value['Sys_rq']),
  116. '更新时间' => rtrim($value['Mod_rq']),
  117. ];
  118. }
  119. $this->success('成功',$data);
  120. }
  121. /**
  122. * 印件资料
  123. * @ApiMethod (GET)
  124. * @param string $Gd_gdbh 工单编号
  125. * @return \think\response\Json
  126. * @throws \think\db\exception\DataNotFoundException
  127. * @throws \think\db\exception\ModelNotFoundException
  128. * @throws \think\exception\DbException
  129. */
  130. public function Printed()
  131. {
  132. if ($this->request->isGet() === false){
  133. $this->error('请求错误');
  134. }
  135. $Gd_gdbh = input('Gd_gdbh');
  136. if (empty($Gd_gdbh)){
  137. $this->error('参数错误');
  138. }
  139. $list = Db::table('工单_印件资料')->where('Yj_Gdbh',$Gd_gdbh)->select();
  140. $data = [];
  141. if ($list){
  142. foreach ($list as $key=>$value){
  143. $data[$key] = [
  144. '印件号' => rtrim($value['yj_Yjno']),
  145. '印件代号' => rtrim($value['yj_Yjdh']),
  146. '印件名称' => rtrim($value['yj_yjmc']),
  147. '纸张代号' => rtrim($value['yj_zzdh']),
  148. '纸张名称' => rtrim($value['yj_zzmc']),
  149. '投料规格' => rtrim($value['yj_tlgg']),
  150. '平张投料' => rtrim($value['yj_平张投料']),
  151. '开料规格' => rtrim($value['yj_klgg']),
  152. '开数*联数' => rtrim($value['yj_ks']).'*'.rtrim($value['yj_ls']),
  153. '建档用户' => rtrim($value['Sys_id']),
  154. '建档时间' => rtrim($value['Sys_rq']),
  155. '更新时间' => rtrim($value['Mod_rq']),
  156. 'zzdh1' => rtrim($value['yj_zzdh1']),
  157. 'zzdh2' => rtrim($value['yj_zzdh2']),
  158. 'zzdh3' => rtrim($value['yj_zzdh3']),
  159. 'zzdh4' => rtrim($value['yj_zzdh4']),
  160. 'zzmc1' => rtrim($value['yj_zzmc1']),
  161. 'zzmc2' => rtrim($value['yj_zzmc2']),
  162. 'zzmc3' => rtrim($value['yj_zzmc3']),
  163. 'zzmc4' => rtrim($value['yj_zzmc4']),
  164. '订单数量' => rtrim($value['yj_成品数量']),
  165. '万小张' => rtrim($value['yj_实际投料']),
  166. '开数' => rtrim($value['yj_ks']),
  167. '联数' => rtrim($value['yj_ls']),
  168. '核算规格' => rtrim($value['Yj_核算规格']),
  169. '备注' => rtrim($value['yj_desc']),
  170. 'Uniqid' => rtrim($value['Uniqid'])
  171. ];
  172. }
  173. }
  174. $this->success('成功',$data);
  175. }
  176. /**
  177. * 工艺资料
  178. * @ApiMethod (GET)
  179. * @param string $Gd_gdbh 工单编号
  180. * @return \think\response\Json
  181. * @throws \think\db\exception\DataNotFoundException
  182. * @throws \think\db\exception\ModelNotFoundException
  183. * @throws \think\exception\DbException
  184. */
  185. public function Craft()
  186. {
  187. if ($this->request->isGet() === false){
  188. $this->error('请求错误');
  189. }
  190. $Gd_gdbh = input('Gd_gdbh');
  191. if (empty($Gd_gdbh)){
  192. $this->error('参数错误');
  193. }
  194. $list = Db::table('工单_工艺资料')
  195. ->where('Gy0_gdbh',$Gd_gdbh)
  196. ->select();
  197. $Gd_cpdh = Db::table('工单_基本资料')->where('Gd_gdbh',$Gd_gdbh)->field('Gd_cpdh')->find();
  198. $data = [];
  199. if ($list){
  200. foreach ($list as $key=>$value){
  201. if ($value['Gy0_yjno']<10){
  202. $value['Gy0_yjno'] = '0'.$value['Gy0_yjno'];
  203. }
  204. if ($value['Gy0_gxh']<10){
  205. $value['Gy0_gxh'] = '0'.$value['Gy0_gxh'];
  206. }
  207. $where = [
  208. 'Gy0_cpdh' => $Gd_cpdh['Gd_cpdh'],
  209. 'Gy0_yjno' => $value['Gy0_yjno'],
  210. 'Gy0_gxh' => $value['Gy0_gxh'],
  211. ];
  212. $product = Db::table('产品_工艺资料')->where($where)->field('工价系数,损耗系数')->find();
  213. $data[$key] = [
  214. '重点工序' => rtrim($value['重点工序']),
  215. '印件-工序' => rtrim($value['Gy0_yjno']).'-'.rtrim($value['Gy0_gxh']),
  216. '备选工序' => '',
  217. '工序名称' => rtrim($value['Gy0_gxmc']).'【'.rtrim($value['Add_gxmc']).'】',
  218. '计划产量' => rtrim($value['Gy0_计划接货数']),
  219. '基础损耗' => rtrim($value['Gy0_Rate0']),
  220. '损耗率' => rtrim($value['Gy0_Rate1']),
  221. '报废定额' => '',
  222. '允损比例' => '',
  223. '难度系数' => isset($product['工价系数'])?rtrim($product['工价系数']):'',
  224. '损耗系数' => isset($product['损耗系数'])?rtrim($product['损耗系数']):'',
  225. '人工检_次品板' => (int)$value['人工检_次品板']=0?'':$value['人工检_次品板'],
  226. '人工检_废检' => (int)$value['人工检_废检']=0?'':$value['人工检_废检'],
  227. '机检_正品板' => (int)$value['机检_正品板']=0?'':$value['机检_正品板'],
  228. '机检_次品板' => (int)$value['机检_次品板']=0?'':$value['机检_次品板'],
  229. '机检_废检' => (int)$value['机检_废检']=0?'':$value['机检_废检'],
  230. '开数*联数' => rtrim($value['Gy0_ks']).'*'.rtrim($value['Gy0_ls']),
  231. '备注' => isset($value['工序备注'])?rtrim($value['工序备注']):'',
  232. '印刷方式' => isset($value['印刷方式'])?rtrim($value['印刷方式']):'',
  233. '版距' => isset($value['版距'])?rtrim($value['版距']):'',
  234. '建档用户' => rtrim($value['Sys_id']),
  235. '建档日期' => isset($value['Sys_rq'])?rtrim($value['Sys_rq']):'',
  236. '更新时间' => isset($value['Mod_rq'])?rtrim($value['Mod_rq']):'',
  237. ];
  238. }
  239. }
  240. $this->success('成功',$data);
  241. }
  242. /**
  243. * BOM资料
  244. * @ApiMethod (GET)
  245. * @param string $Gd_gdbh 工单编号
  246. * @return \think\response\Json
  247. * @throws \think\db\exception\DataNotFoundException
  248. * @throws \think\db\exception\ModelNotFoundException
  249. * @throws \think\exception\DbException
  250. */
  251. public function Bom()
  252. {
  253. if ($this->request->isGet() === false){
  254. $this->error('请求错误');
  255. }
  256. $Gd_gdbh = input('Gd_gdbh');
  257. if (empty($Gd_gdbh)){
  258. $this->error('参数错误');
  259. }
  260. $field = 'rtrim(BOM_方案) as 方案,rtrim(BOM_物料编码) as 物料编号,rtrim(BOM_物料名称) as 物料名称,BOM_投料单位,
  261. BOM_投入数,BOM_产出数,BOM_产出单位,rtrim(BOM_计划用量) as 计划用量,rtrim(Sys_ID) as 建档用户,rtrim(Sys_rq) as 建档时间,rtrim(Mod_rq) as 更新时间';
  262. $list = Db::table('工单_bom资料')
  263. ->where('BOM_工单编号',$Gd_gdbh)
  264. ->field($field)
  265. ->select();
  266. foreach ($list as $key=>$value){
  267. $list[$key]['消耗定量'] = rtrim($value['BOM_投入数']).rtrim($value['BOM_投料单位']).'/'.rtrim($value['BOM_产出数']).rtrim($value['BOM_产出单位']);
  268. unset($list[$key]['BOM_投料单位'],$list[$key]['BOM_投入数'],$list[$key]['BOM_产出数'],$list[$key]['BOM_产出单位']);
  269. $list[$key]['计划用量'] = rtrim((float)$value['计划用量']);
  270. }
  271. $this->success('成功',$list);
  272. }
  273. /**
  274. * 编辑页面展示
  275. * @ApiMethod (GET)
  276. * @param string $workOrder 工单编号
  277. * @return void
  278. * @throws \think\db\exception\DataNotFoundException
  279. * @throws \think\db\exception\ModelNotFoundException
  280. * @throws \think\exception\DbException
  281. */
  282. public function DataCorrection()
  283. {
  284. if ($this->request->isGet() === false){
  285. $this->error('请求错误');
  286. }
  287. $workOrder = input('Gd_gdbh');
  288. if (empty($workOrder)){
  289. $this->error('参数错误');
  290. }
  291. $field = 'rtrim(Gd_lx) as 重点工单,rtrim(Gd_gdbh) as 工单编号,rtrim(Gd_生产分类) as 生产类型,rtrim(Gd_khdh) as 客户代号,rtrim(Gd_客户名称) as 客户名称,
  292. rtrim(Gd_cpdh) as 产品代号,rtrim(Gd_cpmc) as 产品名称,rtrim(开单日期) as 开单日期,rtrim(订单数量) as 订单数量,rtrim(交货日期) as 交货日期,
  293. rtrim(投料率) as 投料率,rtrim(实际投料) as 万小张,rtrim(计量单位) as 单位,rtrim(投料大箱) as 投料大箱,rtrim(排产时库存) as 库存大箱,rtrim(警语版面) as 警语版面,
  294. rtrim(销售订单号) as 销售订单号,rtrim(产品版本号) as 版本号,rtrim(客户ERP编码) as 客户ERP编码,rtrim(码源数量) as 码源数量,rtrim(进程备注) as 进程备注,rtrim(Gd_desc) as 备注';
  295. $list = Db::table('工单_基本资料')->where('Gd_gdbh',$workOrder)->field($field)->find();
  296. if (empty($list)){
  297. $this->error('未找到该工单信息');
  298. }
  299. $printData = Db::table('工单_印件资料')
  300. ->where('Yj_Gdbh',$workOrder)
  301. ->field('rtrim(yj_yjmc) as 印件名称,rtrim(yj_Yjdh) as 印件代号,rtrim(yj_平张投料) as 平张投料')
  302. ->find();
  303. if (empty($printData)){
  304. $this->error('未找到该工单印件资料');
  305. }
  306. $list['印件名称'] = $printData['印件名称'];
  307. $list['印件代号'] = $printData['印件代号'];
  308. $list['平张投料'] = $printData['平张投料'];
  309. $this->success('成功',$list);
  310. }
  311. /**
  312. * 工单资料修改
  313. * @ApiMethod (POST)
  314. * @param array $data 上传数据
  315. * @return void
  316. * @throws \think\Exception
  317. * @throws \think\exception\PDOException
  318. */
  319. public function WorkOrderEdit()
  320. {
  321. if ($this->request->isPost() === false){
  322. $this->error('请求错误');
  323. }
  324. $data = input('data');
  325. if (empty($data)){
  326. $this->error('参数错误');
  327. }
  328. $sql = Db::table('工单_基本资料')->where('Gd_gdbh',$data['Gd_gdbh'])->fetchSql(true)->update($data);
  329. $res = Db::query($sql);
  330. if ($res === 0){
  331. $this->error('修改失败');
  332. }
  333. $this->success('成功');
  334. }
  335. /**
  336. * U8投料试算
  337. * @ApiMethod (GET)
  338. * @param string $processCode 产品编号
  339. * @return void
  340. * @throws \think\db\exception\DataNotFoundException
  341. * @throws \think\db\exception\ModelNotFoundException
  342. * @throws \think\exception\DbException
  343. */
  344. public function U8Trial()
  345. {
  346. if ($this->request->isGet() === false)
  347. {
  348. $this->error('请求错误');
  349. }
  350. $productCode = input('productCode');
  351. if (empty($productCode)){
  352. $this->error('参数错误');
  353. }
  354. $field = 'rtrim(Gy0_cpdh) as 产品代号,rtrim(Gy0_yjno) as 印件号,rtrim(Gy0_gxh) as 工序号,rtrim(gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
  355. rtrim(Gy0_Ms) as 墨色数,rtrim(Gy0_shdh) as 损耗代号,rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ls) as 加工联数';
  356. $list = Db::table('产品_工艺资料')->where('Gy0_cpdh',$productCode)->field($field)->select();
  357. if (empty($list)){
  358. $this->error('未找到该产品工序');
  359. }
  360. foreach ($list as $key=>$value){
  361. $data = Db::table('dic_lzsh')->where('sys_bh',$value['损耗代号'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->cache(true)->find();
  362. $list[$key]['调机损耗'] = isset($data['rate0'])?$data['rate0']:'';
  363. $list[$key]['运行损耗率'] = isset($data['rate1'])?$data['rate1']:'';
  364. if ($value['add_gxmc'] !== ''){
  365. $list[$key]['工序名称'] = $value['gxmc'].'【'.$value['add_gxmc'].'】';
  366. }else{
  367. $list[$key]['工序名称'] = $value['gxmc'];
  368. }
  369. unset($list[$key]['gxmc'],$list[$key]['add_gxmc']);
  370. }
  371. $this->success('成功',$list);
  372. }
  373. /**
  374. * 引用产品资料->获取产品资料
  375. * @ApiMethod (GET)
  376. * @param string $workOrder 工单编号
  377. * @return void
  378. * @throws \think\db\exception\DataNotFoundException
  379. * @throws \think\db\exception\ModelNotFoundException
  380. * @throws \think\exception\DbException
  381. */
  382. public function ProductInformation()
  383. {
  384. if ($this->request->isGet() === false)
  385. {
  386. $this->error('请求错误');
  387. }
  388. $workOrder = input('workOrder');
  389. if (empty($workOrder)){
  390. $this->error('参数错误');
  391. }
  392. $field = 'rtrim(Gd_gdbh) as 工单编号,rtrim(Gd_客户名称) as 客户名称,rtrim(成品代号) as 产品代号,rtrim(成品名称) as 产品名称';
  393. $Detail = Db::table('工单_基本资料')->where('Gd_gdbh',$workOrder)->field($field)->find();
  394. if (empty($Detail)){
  395. $this->error('未找到工单信息');
  396. }
  397. $Detail['客户代号'] = substr($Detail['产品代号'],0,4);
  398. $this->success('成功',$Detail);
  399. }
  400. /**
  401. * 引用产品资料->复制产品工艺资料
  402. * @ApiMethod (POST)
  403. * @param string $oldWorkOrder 被复制工单编号
  404. * @param string $newWorkOrder 复制工单编号
  405. * @return void
  406. * @throws \think\Exception
  407. * @throws \think\db\exception\DataNotFoundException
  408. * @throws \think\db\exception\ModelNotFoundException
  409. * @throws \think\exception\DbException
  410. * @throws \think\exception\PDOException
  411. */
  412. public function ProductInformationEdit()
  413. {
  414. if ($this->request->isPost() === false)
  415. {
  416. $this->error('请求错误');
  417. }
  418. $oldWorkOrder = input('oldWorkOrder');
  419. $newWorkOrder = input('newWorkOrder');
  420. if (empty($oldWorkOrder) || empty($newWorkOrder))
  421. {
  422. $this->error('参数错误');
  423. }
  424. //获取原工单工艺资料
  425. $oldProcessData = Db::table('工单_工艺资料')->where('Gy0_gdbh',$oldWorkOrder)->select();
  426. $ProsessUniqId = Db::table('工单_工艺资料')->field('UniqId')->order('UniqId desc')->find();
  427. foreach ($oldProcessData as $k=>$v){
  428. $oldProcessData[$k]['Gy0_gdbh'] = $newWorkOrder;
  429. $oldProcessData[$k]['Sys_id'] = '';
  430. $oldProcessData[$k]['UniqId'] = $ProsessUniqId['UniqId'] + $k + 1;
  431. }
  432. if (Db::table('工单_工艺资料')->where('Gy0_gdbh',$newWorkOrder)->find()){
  433. Db::table('工单_工艺资料')->where('Gy0_gdbh',$newWorkOrder)->delete();
  434. }
  435. //获取原工单印件资料
  436. $oldPrintData = Db::table('工单_印件资料')->where('Yj_Gdbh',$oldWorkOrder)->select();
  437. $PrintUniqId = Db::table('工单_印件资料')->field('Uniqid')->order('Uniqid desc')->find();
  438. foreach ($oldPrintData as $k=>$v){
  439. $oldPrintData[$k]['Yj_Gdbh'] = $newWorkOrder;
  440. $oldPrintData[$k]['Sys_id'] = '';
  441. $oldPrintData[$k]['Uniqid'] = $PrintUniqId['Uniqid'] +$k +1;
  442. }
  443. if (Db::table('工单_印件资料')->where('Yj_Gdbh',$newWorkOrder)->find()){
  444. Db::table('工单_印件资料')->where('Yj_Gdbh',$newWorkOrder)->delete();
  445. }
  446. //复制印件、工艺资料
  447. $ProcessSQL = Db::table('工单_工艺资料')->fetchSql(true)->insertAll($oldProcessData);
  448. $ProcessRes = Db::query($ProcessSQL);
  449. $PrintSQL = Db::table('工单_印件资料')->fetchSql(true)->insertAll($oldPrintData);
  450. $PrintRes = Db::query($PrintSQL);
  451. if ($ProcessRes !== false && $PrintRes !== false){
  452. $this->success('成功');
  453. }else{
  454. $this->error('失败');
  455. }
  456. }
  457. /**
  458. * 工艺流程调成->获取当前工单工艺资料
  459. * @ApiMethod (GET)
  460. * @param string $workorder 当前工单编号
  461. * @return void
  462. * @throws \think\db\exception\DataNotFoundException
  463. * @throws \think\db\exception\ModelNotFoundException
  464. * @throws \think\exception\DbException
  465. */
  466. public function ProcessFlow()
  467. {
  468. if ($this->request->isGet() === false){
  469. $this->error('请求错误');
  470. }
  471. $workOrder = input('workOrder');
  472. if (empty($workOrder)){
  473. $this->error('参数错误');
  474. }
  475. $list = Db::table('工单_基本资料')->where('Gd_gdbh',$workOrder)->field('rtrim(成品代号) as 成品编号,rtrim(成品名称) as 成品名称')->find();
  476. if (empty($list)){
  477. $this->error('未找到工单信息');
  478. }
  479. $filed = 'rtrim(Gy0_方案) as 方案,rtrim(Gy0_yjno) as 印件号,rtrim(Gy0_gxh) as 工序号,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
  480. rtrim(工价系数) as 工价系数,rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ks) as ks,rtrim(Gy0_ls) as ls,rtrim(工序备注) as 备注,rtrim(Gy0_SITE) as 车间,
  481. rtrim(Gy0_sbbh) as 设备编号,rtrim(Gy0_sbmc) as 设备名称,rtrim(Sys_id) as 建档用户,rtrim(Sys_rq) as 建档时间,rtrim(Mod_rq) as 更新时间';
  482. $process = Db::table('工单_工艺资料')->where('Gy0_gdbh',$workOrder)->field($filed)->select();
  483. if (empty($process)){
  484. $this->error('未找到该工单工艺资料');
  485. }
  486. foreach ($process as $key=>$value){
  487. if (isset($value['add_gxmc'])){
  488. $process[$key]['工序名称'] = $value['gxmc'] . '【'.$value['add_gxmc'].'】';
  489. }else{
  490. $process[$key]['工序名称'] = $value['gxmc'];
  491. }
  492. $process[$key]['工价系数'] = (float)$value['工价系数'];
  493. $process[$key]['损耗系数'] = (float)$value['损耗系数'];
  494. $process[$key]['开数*联数'] = $value['ks'].'*'.$value['ls'];
  495. }
  496. $list['process'] = $process;
  497. $this->success('成功',$list);
  498. }
  499. /**
  500. * 参照工单列表获取
  501. * @ApiMethod (GET)
  502. * @param string $workOrder 工单编号
  503. * @param string $productCode 产品代号
  504. * @return void
  505. */
  506. public function ReferenceWorkOrder()
  507. {
  508. if ($this->request->isGet() === false){
  509. $this->error('请求错误');
  510. }
  511. $productCode = input('productCode');
  512. $workOrder = input('workOrder');
  513. if (empty($productCode) || empty($workOrder)){
  514. $this->error('参数错误');
  515. }
  516. $list = Db::table('工单_基本资料')->where('成品代号',$productCode)->where('Gd_gdbh','<>',$workOrder)->column('Gd_gdbh');
  517. if (empty($list)){
  518. $this->error('未获取该产品其他工单信息');
  519. }
  520. $this->success('成功',$list);
  521. }
  522. /**
  523. * 工艺资料复制
  524. * @ApiMethod (POST)
  525. * @param string $oldWorkOrder 被复制工单编号
  526. * @param string $newWorkOrder 复制工单编号
  527. * @return void
  528. * @throws \think\Exception
  529. * @throws \think\db\exception\DataNotFoundException
  530. * @throws \think\db\exception\ModelNotFoundException
  531. * @throws \think\exception\DbException
  532. * @throws \think\exception\PDOException
  533. *
  534. */
  535. public function ProcessCopy()
  536. {
  537. if ($this->request->isPost() === false){
  538. $this->error('请求错误');
  539. }
  540. $oldWorkOrder = input('oldWorkOrder');
  541. $newWorkOrder = input('newWorkOrder');
  542. if (empty($oldWorkOrder) || empty($newWorkOrder))
  543. {
  544. $this->error('参数错误');
  545. }
  546. //获取原工单工艺资料
  547. $oldProcessData = Db::table('工单_工艺资料')->where('Gy0_gdbh',$oldWorkOrder)->select();
  548. $ProsessUniqId = Db::table('工单_工艺资料')->field('UniqId')->order('UniqId desc')->find();
  549. foreach ($oldProcessData as $k=>$v){
  550. $oldProcessData[$k]['Gy0_gdbh'] = $newWorkOrder;
  551. $oldProcessData[$k]['Sys_id'] = '';
  552. $oldProcessData[$k]['Mod_rq'] = date('Y-m-d H:i:s',time());
  553. $oldProcessData[$k]['UniqId'] = $ProsessUniqId['UniqId'] + $k + 1;
  554. }
  555. if (Db::table('工单_工艺资料')->where('Gy0_gdbh',$newWorkOrder)->find()){
  556. Db::table('工单_工艺资料')->where('Gy0_gdbh',$newWorkOrder)->delete();
  557. }
  558. //插入工艺资料
  559. $ProcessSQL = Db::table('工单_工艺资料')->fetchSql(true)->insertAll($oldProcessData);
  560. $ProcessRes = Db::query($ProcessSQL);
  561. if ($ProcessRes !== false){
  562. $this->success('成功');
  563. }else{
  564. $this->error('失败');
  565. }
  566. }
  567. /**
  568. * U8工单列表
  569. * @ApiMethod (GET)
  570. * @param void
  571. * @return void
  572. * @throws \think\db\exception\DataNotFoundException
  573. * @throws \think\db\exception\ModelNotFoundException
  574. * @throws \think\exception\DbException
  575. */
  576. public function U8workOrder()
  577. {
  578. if ($this->request->isGet() === false){
  579. $this->error('请求错误');
  580. }
  581. $param = $this->request->param();
  582. if (empty($param)){
  583. $this->error('参数错误');
  584. }
  585. $filed = 'rtrim(Gd_gdbh) as 工单编号,rtrim(行号) as 行号,rtrim(Gd_客户代号) as 客户代号,rtrim(Gd_客户名称) as 客户名称,
  586. rtrim(成品代号) as 成品代号,rtrim(成品名称) as 成品名称,rtrim(Mod_rq) as 获取日期,rtrim(Uniqid) as 序号';
  587. $list = Db::table('工单_基本资料')->where('Gd_gdbh',$param['workOrder'])->field($filed)->select();
  588. if (empty($list)){
  589. $this->error('未找到工单');
  590. }
  591. $this->success('成功',$list);
  592. }
  593. /**
  594. * U8工单资料删除
  595. * @param string $workOrder 工单编号
  596. * @return void
  597. * @throws \think\Exception
  598. * @throws \think\exception\PDOException
  599. */
  600. public function U8DataCorrection()
  601. {
  602. if($this->request->isGet() === false){
  603. $this->error('请求错误');
  604. }
  605. $workOrder = input('Uniqid');
  606. if (empty($workOrder)){
  607. $this->error('参数错误');
  608. }
  609. $data = [];
  610. if (strpos($workOrder,',')){
  611. $data = explode(',',$workOrder);
  612. }else{
  613. $data[0] = $workOrder;
  614. }
  615. $res = Db::table('工单_基本资料')->where('Uniqid','in',$data)->delete();
  616. if ($res !== false){
  617. $this->success('成功');
  618. }else{
  619. $this->error('失败');
  620. }
  621. }
  622. /**
  623. * 产品废检系数调整->质检工艺数据获取
  624. * @ApiMethod (GET)
  625. * @param string $workOrder 工单编号
  626. * @return void
  627. * @throws \think\db\exception\DataNotFoundException
  628. * @throws \think\db\exception\ModelNotFoundException
  629. * @throws \think\exception\DbException
  630. */
  631. public function TestCoefficient()
  632. {
  633. if ($this->request->isGet() === false){
  634. $this->error('请求错误');
  635. }
  636. $workOrder = input('workOrder');
  637. if (empty($workOrder)){
  638. $this->error('参数错误');
  639. }
  640. $where = [
  641. 'Gy0_gdbh' => $workOrder,
  642. 'Gy0_gxmc' => ['like','%检%']
  643. ];
  644. $filed = 'rtrim(Gy0_gdbh) as gdbh,rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(人工检_正品板) as 人工正品板,
  645. rtrim(人工检_次品板) as 人工次品板,rtrim(人工检_废检) as 人工废检,rtrim(机检_正品板) as 机检正品板,rtrim(机检_次品板) as 机检次品板,
  646. rtrim(机检_废检) as 机检废检,rtrim(Gy0_sbbh) as 设备编号,rtrim(Uniqid) as Uniqid';
  647. $list = Db::table('工单_工艺资料')->where($where)->field($filed)->select();
  648. if (empty($list)){
  649. $this->error('未找到该工单工艺');
  650. }
  651. $name = Db::table('工单_基本资料')
  652. ->where('Gd_gdbh',$workOrder)
  653. ->field('rtrim(Gd_cpdh) as 产品代号,rtrim(Gd_khmc) as 客户名称,rtrim(Gd_cpmc) as 产品名称')
  654. ->find();
  655. if (empty($name)){
  656. $this->error('未找到该工单');
  657. }
  658. foreach ($list as $key=>$value){
  659. if ($value['yjno']<10){
  660. $value['yjno'] = '0'.$value['yjno'];
  661. }
  662. if ($value['gxh']<10){
  663. $value['gxh'] = '0'.$value['gxh'];
  664. }
  665. $list[$key]['印件工序及工艺'] = $value['gdbh'].'-'.$value['yjno'].'-'.$value['gxh'].'-'.$value['gxmc'];
  666. unset($list[$key]['gdbh'],$list[$key]['yjno'],$list[$key]['gxmc']);
  667. $list[$key]['产品编号'] = $name['产品代号'];
  668. $list[$key]['产品名称'] = $name['产品名称'];
  669. $list[$key]['客户名称'] = $name['客户名称'];
  670. }
  671. $this->success('成功',$list);
  672. }
  673. /**
  674. * 产品质检系数调整->系数修改
  675. * @ApiMethod (GET)
  676. * @param string $workorder 工单编号
  677. * @param string $processCode 工序号
  678. * @param float $code1 人工正品板
  679. * @param float $code2 人工次品板
  680. * @param float $code3 人工废检
  681. * @param float $code4 机检正品板
  682. * @param float $code5 机检次品板
  683. * @param float $code6 机检废检
  684. * @return void
  685. * @throws \think\Exception
  686. * @throws \think\exception\PDOException
  687. */
  688. public function TestCoefficientEdit()
  689. {
  690. if ($this->request->isPost() === false){
  691. $this->error('请求错误');
  692. }
  693. $workOrder = input('workOrder');
  694. $processCode = input('processCode');
  695. $row = [
  696. '人工检_正品板' => input('code1'),
  697. '人工检_次品板' => input('code2'),
  698. '人工检_废检' => input('code3'),
  699. '机检_正品板' => input('code4'),
  700. '机检_次品板' => input('code5'),
  701. '机检_废检' => input('code6'),
  702. ];
  703. if (empty($workOrder) || empty($processCode)){
  704. $this->error('参数错误');
  705. }
  706. $where = [
  707. 'Gy0_gdbh' => $workOrder,
  708. 'Gy0_gxh' => $processCode
  709. ];
  710. $sql = Db::table('工单_工艺资料')->where($where)->fetchSql(true)->update($row);
  711. $res = Db::query($sql);
  712. if ($res !== false){
  713. $this->success('成功');
  714. }else{
  715. $this->error('失败');
  716. }
  717. }
  718. /**
  719. * 修正工单核算参数->数据获取
  720. * @ApiMethod (GET)
  721. * @param string $workOrder 工单编号
  722. * @return void
  723. * @throws \think\db\exception\DataNotFoundException
  724. * @throws \think\db\exception\ModelNotFoundException
  725. * @throws \think\exception\DbException
  726. */
  727. public function AccountingParameter()
  728. {
  729. if ($this->request->isGet() === false){
  730. $this->error('请求错误');
  731. }
  732. $workOrder = input('workOrder');
  733. if (empty($workOrder)){
  734. $this->error('参数错误');
  735. }
  736. $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,
  737. rtrim(Gy0_sbbh) as 参照设备,rtrim(工价系数) as 难度系数,rtrim(Gy0_shdh) as 损耗代号,rtrim(Gy0_Rate0) as 基础损耗,rtrim(Gy0_Rate1) as 损耗率,
  738. rtrim(印刷方式) as 印刷方式,rtrim(版距) as 版距,rtrim(Gy0_ms) as 计损色数,rtrim(损耗系数) as 损耗系数,rtrim(UniqId) as UniqId';
  739. $list = Db::table('工单_工艺资料')->where('Gy0_gdbh',$workOrder)->field($field)->select();
  740. if (empty($list)){
  741. $this->error('未找到该工单工艺资料');
  742. }
  743. foreach ($list as $key=>$value){
  744. if ($value['yjno']<10){
  745. $value['yjno'] = '0'.$value['yjno'];
  746. }
  747. if ($value['gxh']<10){
  748. $value['gxh'] = '0'.$value['gxh'];
  749. }
  750. $list[$key]['印件号及工序名称'] = $value['yjno'].'-'.$value['gxh'].$value['gxmc'].'('.$value['add_gxmc'].')';
  751. unset($list[$key]['yjno'],$list[$key]['gxmc'],$list[$key]['add_gxmc']);
  752. }
  753. $this->success('成功',$list);
  754. }
  755. /**
  756. * 修正工单核算参数->参数修改
  757. * @ApiMethod (POST)
  758. * @param void
  759. * @return void
  760. * @throws \think\Exception
  761. * @throws \think\db\exception\DataNotFoundException
  762. * @throws \think\db\exception\ModelNotFoundException
  763. * @throws \think\exception\DbException
  764. * @throws \think\exception\PDOException
  765. */
  766. public function AccountingParameterEdit()
  767. {
  768. if (Request::instance()->isPost() === false){
  769. $this->error('请求错误');
  770. }
  771. $param = Request::instance()->post();
  772. if (empty($param) || isset($param[0]['Uniqid']) === false){
  773. $this->error('参数错误');
  774. }
  775. $i = 0;
  776. foreach ($param as $key=>$value){
  777. $data = Db::table('dic_lzsh')->where('sys_bh',$value['loss'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
  778. $row = [
  779. '工价系数' => $value['difficulty']?:'',
  780. 'Gy0_shdh' => $value['loss']?:'',
  781. '印刷方式' => $value['printMode']?:'',
  782. '版距' => $value['plate']?:'',
  783. 'Gy0_ms' => $value['chromatic']?:'',
  784. '损耗系数' => $value['wastage']?:'',
  785. 'Gy0_Rate0' => $data['rate0'],
  786. 'Gy0_Rate1' => $data['rate1']
  787. ];
  788. $sql = Db::table('工单_工艺资料')->where('Uniqid',$value['Uniqid'])->fetchSql(true)->update($row);
  789. $res = Db::query($sql);
  790. if ($res !== false){
  791. $i++;
  792. }
  793. }
  794. if ($i !== 0){
  795. $this->success('成功');
  796. }else{
  797. $this->error('失败');
  798. }
  799. }
  800. /**
  801. * 印件资料修改
  802. * @ApiMethod (POST)
  803. * @param void
  804. * @return void
  805. * @throws \think\Exception
  806. * @throws \think\exception\PDOException
  807. */
  808. public function PrintedEdit()
  809. {
  810. if ($this->request->isPost() === false){
  811. $this->error('请求错误');
  812. }
  813. $param = $this->request->param();
  814. if (empty($param) || isset($param['Uniqid']) === false){
  815. $this->error('参数错误');
  816. }
  817. $data = [
  818. 'yj_Yjno' => isset($param['yjno'])?$param['yjno']:'',
  819. 'yj_Yjdh' => isset($param['yjdh'])?$param['yjdh']:'',
  820. 'yj_yjmc' => isset($param['yjmc'])?$param['yjmc']:'',
  821. 'yj_zzdh' => isset($param['zzdh'])?$param['zzdh']:'',
  822. 'yj_zzdh1' => isset($param['zzdh1'])?$param['zzdh1']:'',
  823. 'yj_zzdh2' => isset($param['zzdh2'])?$param['zzdh2']:'',
  824. 'yj_zzdh3' => isset($param['zzdh3'])?$param['zzdh3']:'',
  825. 'yj_zzdh4' => isset($param['zzdh4'])?$param['zzdh4']:'',
  826. 'yj_zzmc' => isset($param['zzmc'])?$param['zzmc']:'',
  827. 'yj_zzmc1' => isset($param['zzmc1'])?$param['zzmc1']:'',
  828. 'yj_zzmc2' => isset($param['zzmc2'])?$param['zzmc2']:'',
  829. 'yj_zzmc3' => isset($param['zzmc3'])?$param['zzmc3']:'',
  830. 'yj_zzmc4' => isset($param['zzmc4'])?$param['zzmc4']:'',
  831. 'yj_成品数量' => isset($param['cpsl'])?$param['cpsl']:'',
  832. 'yj_实际投料' => isset($param['sjtl'])?$param['sjtl']:'',
  833. 'yj_平张投料' => isset($param['pztl'])?$param['pztl']:'',
  834. 'yj_tlgg' => isset($param['tlgg'])?$param['tlgg']:'',
  835. 'yj_klgg' => isset($param['klgg'])?$param['klgg']:'',
  836. 'Yj_核算规格' => isset($param['hsgg'])?$param['hsgg']:'',
  837. 'yj_ks' => isset($param['ks'])?$param['ks']:'',
  838. 'yj_ls' => isset($param['ls'])?$param['ls']:'',
  839. 'yj_desc' => isset($param['desc'])?$param['desc']:'',
  840. ];
  841. $sql = Db::table('工单_印件资料')->where('Uniqid',$param['Uniqid'])->fetchSql(true)->update($data);
  842. $res = Db::query($sql);
  843. if ($res !== false){
  844. $this->success('成功');
  845. }else{
  846. $this->error('失败');
  847. }
  848. }
  849. }