WorkOrder.php 33 KB

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