WorkOrder.php 37 KB

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