WorkOrder.php 50 KB

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