WorkOrder.php 53 KB

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