Manufacture.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  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. */
  11. class Manufacture extends Api
  12. {
  13. protected $noNeedLogin = ['*'];
  14. protected $noNeedRight = ['*'];
  15. /**
  16. * 计划中工单
  17. * @ApiMethod (GET)
  18. * @return \think\response\Json
  19. * @throws \think\db\exception\DataNotFoundException
  20. * @throws \think\db\exception\ModelNotFoundException
  21. * @throws \think\exception\DbException
  22. */
  23. public function Project()
  24. {
  25. if ($this->request->isGet() === false){
  26. $this->error('请求错误');
  27. }
  28. $param = $this->request->param();
  29. if (empty($param)){
  30. $this->error('参数错误');
  31. }
  32. if ($param['status'] === '计划中'){
  33. $status = '3-计划中';
  34. }else{
  35. $status = '1-已完工';
  36. }
  37. $where = [
  38. 'gd_statu' => $status,
  39. '行号' => '1',
  40. ];
  41. if (isset($param['search'])){
  42. $where['Gd_lx|Gd_gdbh|Gd_客户代号|Gd_客户名称|Gd_khdh|Gd_khmc|Gd_cpdh|Gd_cpmc|成品代号|成品名称|产品版本号'] = ['like','%'.$param['search'].'%'];
  43. }
  44. $field = 'rtrim(Gd_生产分类) as 生产分类,rtrim(Gd_gdbh) as 工单编号,rtrim(Gd_cpdh) as 产品代号,rtrim(Gd_cpmc) as 产品名称,rtrim(成品名称) as 成品名称,
  45. rtrim(接单日期) as 接单日期,rtrim(交货日期) as 交货日期,rtrim(订单数量) as 订单数量,rtrim(计量单位) as 计量单位,rtrim(Gd_khmc) as 客户名称,
  46. rtrim(Gd_客户代号) as 客户编号,rtrim(Gd_desc) as 备注,rtrim(客户料号) as 客户料号,rtrim(Sys_id) as 创建用户,rtrim(Sys_rq) as 创建时间,
  47. rtrim(Mod_rq) as 修改时间,rtrim(Uniqid) as UNIQID,rtrim(投料率) as 投料率,rtrim(销售订单号) as 销售订单号';
  48. $list = Db::table('工单_基本资料')->where($where)->field($field)->limit(500)->order('Uniqid desc')->select();
  49. if (empty($list)){
  50. $this->error('失败');
  51. }
  52. foreach ($list as $key=>$value){
  53. $list[$key]['订单数量'] = rtrim((float)$value['订单数量']);
  54. $list[$key]['产品名称'] = $value['产品名称'] != '' ? $value['产品名称']:$value['成品名称'];
  55. $number = Db::table('工单_工艺资料')->where('Gy0_gdbh',$value['工单编号'])->count();
  56. if ($number === 0){
  57. $list[$key]['status'] = 0;
  58. }else{
  59. $list[$key]['status'] = 1;
  60. }
  61. unset($list[$key]['成品名称']);
  62. }
  63. $this->success('成功',$list);
  64. }
  65. /**
  66. * 计划中工单->工艺资料
  67. * @ApiMethod (GET)
  68. * @param string $Gd_gdbh 工单编号
  69. * @return \think\response\Json
  70. * @throws \think\db\exception\DataNotFoundException
  71. * @throws \think\db\exception\ModelNotFoundException
  72. * @throws \think\exception\DbException
  73. */
  74. public function projectCraft()
  75. {
  76. if ($this->request->isGet() === false){
  77. $this->error('请求错误');
  78. }
  79. $Gd_gdbh = input('Gd_gdbh');
  80. if (empty($Gd_gdbh)){
  81. $this->error('参数错误');
  82. }
  83. $where = [
  84. 'Gy0_gdbh' => $Gd_gdbh
  85. ];
  86. $filed = 'rtrim(Gy0_gdbh) as 工单编号,rtrim(重点工序) as 重点工序,Gy0_yjno,Gy0_gxh,Gy0_gxmc,Add_gxmc,rtrim(工序备注) as 工序备注,
  87. rtrim(Gy0_sbbh) as 机组,rtrim(Gy0_小时产能) as 小时产能,rtrim(Gy0_生产工时) as 生产工时,rtrim(Gy0_辅助工时) as 辅助工时,
  88. rtrim(印刷方式) as 印刷方式,rtrim(版距) as 版距,rtrim(Sys_id) as 创建用户,rtrim(Sys_rq) as 创建时间,rtrim(Mod_rq) as 修改时间,rtrim(UniqId) as UNIQID';
  89. $list = Db::table('工单_工艺资料')->where($where)->field($filed)->select();
  90. if (empty($list)){
  91. $this->success('',[]);
  92. }
  93. foreach ($list as $key=>$value){
  94. if ((int)$value['Gy0_yjno'] <10){
  95. $value['Gy0_yjno'] = '0'.rtrim($value['Gy0_yjno']);
  96. }
  97. if ((int)$value['Gy0_gxh'] <10){
  98. $value['Gy0_gxh'] = '0'.rtrim($value['Gy0_gxh']);
  99. }
  100. if (rtrim($value['Add_gxmc']) == ''){
  101. $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']);
  102. }else{
  103. $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']).'【'.rtrim($value['Add_gxmc']).'】';
  104. }
  105. unset($list[$key]['Gy0_gxmc'],$list[$key]['Add_gxmc']);
  106. }
  107. $this->success('成功',$list);
  108. }
  109. /**
  110. * 计划中工单->印件资料
  111. * @ApiMethod (GET)
  112. * @param string $Gd_gdbh 工单编号
  113. * @return \think\response\Json
  114. * @throws \think\db\exception\DataNotFoundException
  115. * @throws \think\db\exception\ModelNotFoundException
  116. * @throws \think\exception\DbException
  117. */
  118. public function projectPrint()
  119. {
  120. if ($this->request->isGet() === false){
  121. $this->error('请求错误');
  122. }
  123. $Gd_gdbh = input('Gd_gdbh');
  124. if (empty($Gd_gdbh)){
  125. $this->error('参数错误');
  126. }
  127. $where = [
  128. 'Yj_Gdbh' => $Gd_gdbh,
  129. ];
  130. $field = 'rtrim(Yj_Gdbh) as 工单编号,rtrim(yj_Yjno) as 印件号,rtrim(yj_Yjdh) as 印件代号,rtrim(yj_yjmc) as 印件名称,
  131. rtrim(yj_zzmc) as 纸张名称,rtrim(yj_tlgg) as 投料规格,rtrim(yj_成品数量) as 成品数量,rtrim(yj_实际投料) as 实际投料,
  132. rtrim(yj_Dw) as 投料单位,rtrim(yj_平张投料) as 平张投料,rtrim(yj_ls) as 联数,rtrim(yj_ks) as 开数,rtrim(Sys_id) as 创建用户,
  133. rtrim(Sys_rq) as 创建时间,rtrim(Mod_rq) as 修改时间,rtrim(Uniqid) as UNIQID';
  134. $list = Db::table('工单_印件资料')->where($where)->field($field)->select();
  135. if (empty($list)){
  136. $this->error('失败');
  137. }
  138. foreach ($list as $key=>$value){
  139. $list[$key]['成品数量'] = rtrim((float)$value['成品数量']);
  140. $list[$key]['实际投料'] = rtrim((float)$value['实际投料']);
  141. }
  142. $this->success('成功',$list);
  143. }
  144. /**
  145. * 排程中/制程中工单
  146. */
  147. public function Schedule(){
  148. if ($this->request->isGet() === false){
  149. $this->error('请求错误');
  150. }
  151. $param = $this->request->param();
  152. if (empty($param)){
  153. $this->error('参数错误');
  154. }
  155. // if (isset($param)){
  156. // "Gd_lx|Gd_gdbh|Gd_客户代号|Gd_客户名称|Gd_khdh|Gd_khmc|Gd_cpdh|Gd_cpmc|成品代号|成品名称|产品版本号" LIKE
  157. // }
  158. if ($param['status'] === '排程中'){
  159. $sql = "SELECT
  160. rtrim(a.Gd_gdbh) AS 工单编号,
  161. rtrim(a.Gd_cpdh) AS 产品代号,
  162. rtrim(a.Gd_cpmc) AS 产品名称,
  163. rtrim(a.接单日期) AS 接单日期,
  164. rtrim(a.交货日期) AS 交货日期,
  165. rtrim(a.订单数量) AS 订单数量,
  166. rtrim(a.计量单位) AS 计量单位,
  167. rtrim(a.销售订单号) AS 销售订单号,
  168. rtrim(a.Gd_客户代号) AS 客户编号,
  169. rtrim(a.Gd_客户名称) AS 客户名称,
  170. rtrim(a.客户料号) AS 客户料号,
  171. rtrim(a.Uniqid) AS GDUID
  172. FROM
  173. `工单_基本资料` AS a
  174. INNER JOIN `工单_工艺资料` AS b ON a.Gd_gdbh = b.Gy0_gdbh
  175. JOIN `产品_基本资料` AS c ON a.Gd_cpdh = c.产品编号
  176. WHERE
  177. a.gd_statu = '2-生产中'
  178. AND a.行号 = '1'
  179. AND b.PD_WG = '1900-01-01 00:00:00'
  180. AND b.Gy0_sj1 = '1900-01-01 00:00:00'
  181. AND c.状态 = ''
  182. GROUP BY a.Gd_gdbh ";
  183. }else{
  184. $sql = "SELECT
  185. rtrim(a.Gd_gdbh) AS 工单编号,
  186. rtrim(a.Gd_cpdh) AS 产品代号,
  187. rtrim(a.Gd_cpmc) AS 产品名称,
  188. rtrim(a.接单日期) AS 接单日期,
  189. rtrim(a.交货日期) AS 交货日期,
  190. rtrim(a.订单数量) AS 订单数量,
  191. rtrim(a.计量单位) AS 计量单位,
  192. rtrim(a.销售订单号) AS 销售订单号,
  193. rtrim(a.Gd_客户代号) AS 客户编号,
  194. rtrim(a.Gd_客户名称) AS 客户名称,
  195. rtrim(a.客户料号) AS 客户料号,
  196. rtrim(a.Uniqid) AS GDUID
  197. FROM
  198. `工单_基本资料` AS a
  199. INNER JOIN `工单_工艺资料` AS b ON a.Gd_gdbh = b.Gy0_gdbh
  200. JOIN `产品_基本资料` AS c ON a.Gd_cpdh = c.产品编号
  201. WHERE
  202. a.gd_statu = '2-生产中'
  203. AND a.行号 = '1'
  204. AND b.PD_WG = '1900-01-01 00:00:00'
  205. AND b.Gy0_sj1 != '1900-01-01 00:00:00'
  206. AND c.状态 = ''
  207. GROUP BY a.Gd_gdbh ";
  208. }
  209. $list = Db::query($sql);
  210. if (empty($list)){
  211. $this->error('未找到工单信息');
  212. }
  213. $this->success('成功',$list);
  214. }
  215. /**
  216. * 排程中/制程中工单->工序列表
  217. * @ApiMethod (GET)
  218. * @param string $Gd_gdbh 工单编号
  219. * @return \think\response\Json
  220. * @throws \think\db\exception\DataNotFoundException
  221. * @throws \think\db\exception\ModelNotFoundException
  222. * @throws \think\exception\DbException
  223. */
  224. public function ScheduleProcess()
  225. {
  226. if ($this->request->isGet() === false){
  227. $this->error('请求错误');
  228. }
  229. $Gd_gdbh = input('Gd_gdbh');
  230. if (empty($Gd_gdbh)){
  231. $this->error('参数错误');
  232. }
  233. $sql = "SELECT rtrim(a.Gy0_gdbh) as 工单编号,a.Gy0_yjno,a.Gy0_gxh,a.Gy0_gxmc,a.Add_gxmc,rtrim(a.Gy0_sbbh) as 设备编号,rtrim(a.Gy0_小时产能) as 小时产能,
  234. rtrim(a.工价系数) as 产能系数,rtrim(a.Gy0_生产工时) as 生产工时,rtrim(a.Gy0_辅助工时) as 辅助工时,rtrim(a.Gy0_最早开工时间) as 最早开工时间,
  235. rtrim(a.Gy0_sj1) as 计划开工时间,rtrim(a.Gy0_sj2) as 计划完工时间,rtrim(a.Gy0_班次安排) as 班次安排,rtrim(a.工序备注) as 排单备注,
  236. rtrim(a.PD_WG) as 工序完工,rtrim(a.UniqId) as UniqId,COALESCE(b.cl, 0) AS 产量, c.设备名称,rtrim(d.计划投料) as 工序产量
  237. FROM `工单_工艺资料` AS a
  238. JOIN `设备_基本资料` AS c ON a.Gy0_sbbh = c.设备编号
  239. JOIN `工单_基本资料` As d ON a.Gy0_gdbh = d.Gd_Gdbh
  240. LEFT JOIN (
  241. SELECT sczl_gdbh, sczl_gxh, SUM(sczl_cl) AS cl
  242. FROM `设备_产量计酬`
  243. GROUP BY sczl_gdbh, sczl_gxh
  244. ) AS b ON a.Gy0_gdbh = b.sczl_gdbh AND (a.Gy0_gxh = b.sczl_gxh OR b.sczl_gxh IS NULL)
  245. WHERE a.Gy0_gdbh = '{$Gd_gdbh}' AND a.Gy0_sbbh != ''
  246. GROUP BY a.Gy0_gxh";
  247. $list = Db::query($sql);
  248. if (empty($list)){
  249. $this->error('未找到工序');
  250. }
  251. foreach ($list as $key=>$value){
  252. if ((int)$value['Gy0_yjno'] <10){
  253. $value['Gy0_yjno'] = '0'.rtrim($value['Gy0_yjno']);
  254. }
  255. if ((int)$value['Gy0_gxh'] <10){
  256. $value['Gy0_gxh'] = '0'.rtrim($value['Gy0_gxh']);
  257. }
  258. if (rtrim($value['Add_gxmc']) == ''){
  259. $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']);
  260. }else{
  261. $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']).'【'.rtrim($value['Add_gxmc']).'】';
  262. }
  263. unset($list[$key]['Gy0_gxmc'],$list[$key]['Add_gxmc']);
  264. $list[$key]['机组'] = $value['设备编号'];
  265. $list[$key]['剩余产量'] = (int)$list[$key]['工序产量']-(int)$list[$key]['产量'];
  266. }
  267. $this->success('成功',$list);
  268. }
  269. /**
  270. * 排单页面左侧车间和机台菜单
  271. * @ApiMethod (GET)
  272. * @return \think\response\Json
  273. * @throws \think\db\exception\DataNotFoundException
  274. * @throws \think\db\exception\ModelNotFoundException
  275. * @throws \think\exception\DbException
  276. */
  277. public function workbench()
  278. {
  279. if ($this->request->isGet() === false){
  280. $this->error('请求错误');
  281. }
  282. $data = [];
  283. $department = Db::table('设备_基本资料')->distinct(true)->cache(true)->column('使用部门');
  284. if (empty($department)){
  285. $this->error('为获取到机台数据');
  286. }
  287. foreach ($department as $value){
  288. if (rtrim($value) !== '研发中心'){
  289. $benchClass = Db::table('设备_基本资料')->where('使用部门',$value)->distinct(true)->cache(true)->column('设备编组');
  290. foreach ($benchClass as $v){
  291. if (rtrim($v) !== ''){
  292. $machine = Db::table('设备_基本资料')->where('使用部门',$value)->where('设备编组',$v)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->cache(true)->select();
  293. foreach ($machine as $kk=>$vv){
  294. $data[rtrim($value)][rtrim($v)][$kk] = $vv['设备编号'].'-->'.$vv['设备名称'];
  295. }
  296. }
  297. }
  298. }
  299. }
  300. $this->success('成功',$data);
  301. }
  302. /**
  303. * 工单状态设置
  304. * @ApiMethod (GET)
  305. * @param string $workOrder 工单编号
  306. * @param string $status 工单状态
  307. * @return void
  308. * @throws \think\Exception
  309. * @throws \think\exception\PDOException
  310. */
  311. public function StatusEdit()
  312. {
  313. if (Request::instance()->isPost() === false){
  314. $this->error('请求错误');
  315. }
  316. $workOrder = input('workOrder');
  317. $status = input('status');
  318. if (empty($workOrder) || empty($status)){
  319. $this->error('参数错误');
  320. }
  321. $sql = Db::table('工单_基本资料')->where('Gd_gdbh',$workOrder)->fetchSql(true)->update(['gd_statu'=>$status]);
  322. $res = Db::query($sql);
  323. if ($res !== false){
  324. $this->success('成功');
  325. }else{
  326. $this->error('失败');
  327. }
  328. }
  329. /**
  330. * 更改工序状态
  331. * @ApiMethod (GET)
  332. * @param void
  333. * @return void
  334. * @throws \think\Exception
  335. * @throws \think\exception\PDOException
  336. */
  337. public function complete()
  338. {
  339. if ($this->request->isGet() === false){
  340. $this->error('请求错误');
  341. }
  342. $data = $this->request->param();
  343. if (empty($data)){
  344. $this->error('参数错误');
  345. }
  346. $where = [
  347. 'Gy0_gdbh' => $data['workOrder'],
  348. 'Gy0_gxh' => $data['processCode']
  349. ];
  350. $sql = Db::table('工单_工艺资料')->where($where)->fetchSql(true)->update(['PD_WG'=>date('Y-m-d H:i:s',time())]);
  351. $res = Db::query($sql);
  352. if ($res !== false){
  353. $this->success('成功');
  354. }else{
  355. $this->error('失败');
  356. }
  357. }
  358. /**
  359. * 加入排产
  360. * @ApiMethod (POST)
  361. * @param void $data
  362. * @return void
  363. * @throws \think\Exception
  364. * @throws \think\db\exception\DataNotFoundException
  365. * @throws \think\db\exception\ModelNotFoundException
  366. * @throws \think\exception\DbException
  367. * @throws \think\exception\PDOException
  368. */
  369. public function ProductionSchedulingAdd()
  370. {
  371. if (Request::instance()->isPost() === false){
  372. $this->error('请求错误');
  373. }
  374. $data = Request::instance()->post();
  375. if (empty($data)){
  376. $this->error('参数错误');
  377. }
  378. $where = [
  379. 'Gy0_gdbh' => $data['workOrder'],
  380. 'Gy0_sbbh' => $data['machine'],
  381. 'Gy0_yjno' => $data['printCode'],
  382. 'Gy0_gxh' => $data['processCode']
  383. ];
  384. $lastTime = Db::table('工单_工艺资料')
  385. ->where(['Gy0_sbbh'=>$where['Gy0_sbbh'],'Gy0_sj2'=>['<>','1900-01-01 00:00:00'],'Gy0_sj2'=>['<','2099-01-01 00:00:00']])
  386. ->field('rtrim(Gy0_sj2) as sj2')
  387. ->order('Gy0_sj2 desc')
  388. ->find();
  389. $row = Db::table('工单_工艺资料')
  390. ->where($where)
  391. ->field('rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_小时产能) as 小时产能,rtrim(Gy0_辅助工时) as 辅助工时')
  392. ->find();
  393. if (empty($row)){
  394. $this->error('未找到该工单工艺资料');
  395. }
  396. $endTime = date('Y-m-d H:i:s',strtotime($lastTime['sj2']) + ((int)round($row['计划接货数']/$row['小时产能'])+(int)$row['辅助工时'])*3600);
  397. $sql = Db::table('工单_工艺资料')
  398. ->where($where)
  399. ->fetchSql(true)
  400. ->update(['Gy0_sj1'=>$lastTime['sj2'],'Gy0_sj2'=>$endTime,'Mod_rq'=>date('Y-m-d H:i:s',time())]);
  401. $res = Db::query($sql);
  402. if ($res !== false){
  403. $this->success('成功');
  404. }else{
  405. $this->error('失败');
  406. }
  407. }
  408. /**
  409. * 暂停排产
  410. * @ApiMethod (POST)
  411. * @param void $data
  412. * @return void
  413. * @throws \think\Exception
  414. * @throws \think\db\exception\DataNotFoundException
  415. * @throws \think\db\exception\ModelNotFoundException
  416. * @throws \think\exception\DbException
  417. * @throws \think\exception\PDOException
  418. */
  419. public function ProductionSchedulingPause()
  420. {
  421. if (Request::instance()->isPost() === false){
  422. $this->error('请求错误');
  423. }
  424. $data = Request::instance()->post();
  425. if (empty($data)){
  426. $this->error('参数错误');
  427. }
  428. $where = [
  429. 'Gy0_gdbh' => $data['workOrder'],
  430. 'Gy0_sbbh' => $data['machine'],
  431. 'Gy0_yjno' => $data['printCode'],
  432. 'Gy0_gxh' => $data['processCode']
  433. ];
  434. $machine = $where['Gy0_sbbh'];
  435. $endTime = Db::table('工单_工艺资料')->where($where)->field('rtrim(Gy0_sj2) as sj2')->find()['sj2'];
  436. if (empty($endTime)){
  437. $this->error('未找到该工序');
  438. }
  439. if ($endTime <= '1900-01-01 00:00:00' || $endTime >= '2099-01-01 00:00:00'){
  440. $this->error('该工单不是制程中工单');
  441. }
  442. $sql = Db::table('工单_工艺资料')
  443. ->where($where)
  444. ->fetchSql(true)
  445. ->update(['Gy0_sj1'=>'1900-01-01 00:00:00','Gy0_sj2'=>'1900-01-01 00:00:00','Mod_rq'=>date('Y-m-d H:i:s')]);
  446. $row = Db::table('工单_工艺资料')
  447. ->where($where)
  448. ->field('rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_小时产能) as 小时产能,rtrim(Gy0_辅助工时) as 辅助工时')
  449. ->find();
  450. if (empty($row)){
  451. $this->error('未找到该工序');
  452. }
  453. $number = -(int)round($row['计划接货数']/$row['小时产能'])+(int)$row['辅助工时'];
  454. $res = Db::query($sql);
  455. $rechSql = "UPDATE `工单_工艺资料` SET Gy0_sj1 = DATE_ADD(Gy0_sj1, INTERVAL {$number} HOUR),Gy0_sj2 = DATE_ADD(Gy0_sj2, INTERVAL {$number} HOUR) WHERE Gy0_sbbh = '{$machine}' AND Gy0_sj1 >= '{$endTime}' AND Gy0_sj1 < '2099-01-01 00:00:00'";
  456. $rechres = Db::query($rechSql);
  457. if ($res !== false && $rechres !== false){
  458. $this->success('成功');
  459. }else{
  460. $this->error('失败');
  461. }
  462. }
  463. /**
  464. * 工序状态更正
  465. * @ApiMethod (GET)
  466. * @param void $param
  467. * @return void
  468. * @throws \think\db\exception\DataNotFoundException
  469. * @throws \think\db\exception\ModelNotFoundException
  470. * @throws \think\exception\DbException
  471. */
  472. public function ProcessStatusCorrection()
  473. {
  474. if ($this->request->isGet() === false){
  475. $this->error('请求错误');
  476. }
  477. $param = $this->request->param();
  478. if (empty($param)){
  479. $this->error('参数错误');
  480. }
  481. $where = [
  482. 'Gy0_gdbh' => $param['workOrder'],
  483. 'Gy0_sbbh' => ['<>','']
  484. ];
  485. $workOrder = $where['Gy0_gdbh'];
  486. $field = 'rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Gy0_sbbh) as 设备代号,rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_ls) as ls,rtrim(PD_WG) as 完工时间,rtrim(UniqId) as UniqId';
  487. $list = Db::table('工单_工艺资料')->where($where)->field($field)->order('Gy0_gxh')->select();
  488. if (empty($list)){
  489. $this->error('未找到该工单工艺资料');
  490. }
  491. $yieldSql = "SELECT a.Gy0_gxh as gxh,SUM(b.sczl_cl) as cl FROM `工单_工艺资料` AS a JOIN `设备_产量计酬` as b ON a.Gy0_gxh = b.sczl_gxh WHERE a.Gy0_gdbh = '{$workOrder}' AND b.sczl_gdbh = '{$workOrder}' GROUP BY a.Gy0_gxh";
  492. $yield = Db::query($yieldSql);
  493. foreach ($list as $key=>$value){
  494. if ($value['yjno']<10){
  495. $value['yjno'] = '0'.$value['yjno'];
  496. }
  497. if ($value['gxh']<10){
  498. $value['gxh'] = '0'.$value['gxh'];
  499. }
  500. $list[$key]['印件及工序'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'];
  501. foreach ($yield as $k=>$v){
  502. if ($v['gxh'] === $list[$key]['gxh']){
  503. $list[$key]['计划产量/已完成'] = (int)($value['计划接货数']/$value['ls']).'/'.$v['cl'];
  504. $list[$key]['完成率'] = number_format($v['cl']/($value['计划接货数']/$value['ls']),4)*100 . '%';
  505. }else{
  506. $list[$key]['计划产量/已完成'] = ($value['计划接货数']/$value['ls']).'/0';
  507. $list[$key]['完成率'] = '';
  508. }
  509. }
  510. if ($value['完工时间'] == '1900-01-01 00:00:00') {
  511. $list[$key]['完工时间'] = '';
  512. }
  513. unset($list[$key]['yjno'],$list[$key]['gxh'],$list[$key]['gxmc'],$list[$key]['计划接货数'],$list[$key]['ls']);
  514. }
  515. $this->success('成功',$list);
  516. }
  517. /**
  518. * 工序状态更正->工序状态编辑
  519. * @ApiMethod (POST)
  520. * @param void
  521. * @return void
  522. * @throws \think\Exception
  523. * @throws \think\exception\PDOException
  524. */
  525. public function ProcessStatusCorrectionEdit()
  526. {
  527. if (Request::instance()->isPost() === false){
  528. $this->error('请求错误');
  529. }
  530. $param = Request::instance()->post();
  531. if (empty($param)){
  532. $this->error('参数错误');
  533. }
  534. $i = 0;
  535. foreach ($param as $key=>$value){
  536. if ($value['PD_WG'] === null || $value['PD_WG'] === ''){
  537. $endTime = '1900-01-01 00:00:00';
  538. }else{
  539. $endTime = $value['PD_WG'];
  540. }
  541. $sql = Db::table('工单_工艺资料')
  542. ->where('UniqId',$value['UniqId'])
  543. ->fetchSql(true)
  544. ->update(['PD_WG'=>$endTime]);
  545. $res = Db::query($sql);
  546. if ($res !== false){
  547. $i++;
  548. }
  549. }
  550. if ($i !== 0){
  551. $this->success('成功');
  552. }else{
  553. $this->error('失败');
  554. }
  555. }
  556. /**
  557. * 班次选择
  558. * @ApiMethod (GET)
  559. * @return void
  560. * @throws \think\db\exception\DataNotFoundException
  561. * @throws \think\db\exception\ModelNotFoundException
  562. * @throws \think\exception\DbException
  563. */
  564. public function ScheduleSelection()
  565. {
  566. if ($this->request->isGet() === false){
  567. $this->error('请求错误');
  568. }
  569. $list = Db::table('工单_排程班次')->field('rtrim(bcdh) as 班次代号,rtrim(desc_) as desc_,rtrim(stdtime) as stdtime')->select();
  570. if (empty($list)){
  571. $this->error('未找到班次数据');
  572. }
  573. foreach ($list as $key=>$value){
  574. $list[$key]['detail'] = $value['班次代号'].'||'.$value['desc_'].'||'.$value['stdtime'];
  575. unset($list[$key]['desc_'],$list[$key]['stdtime']);
  576. }
  577. $this->success('成功',$list);
  578. }
  579. /**
  580. * 车间设备制程展示
  581. * @ApiMethod (GET)
  582. * @param void $param
  583. * @return void
  584. * @throws \think\db\exception\DataNotFoundException
  585. * @throws \think\db\exception\ModelNotFoundException
  586. * @throws \think\exception\DbException
  587. */
  588. public function EquipmentScheduling()
  589. {
  590. if ($this->request->isGet() === false){
  591. $this->error('参数错误');
  592. }
  593. $param = $this->request->param();
  594. if (empty($param)){
  595. $this->error('参数错误');
  596. }
  597. $where = [
  598. 'Gy0_sbbh' => $param['machine'],
  599. 'Gy0_sj1' => ['between',['1900-01-01 00:00:01','2098-12-31 23:59:59']],
  600. 'PD_WG' => '1900-01-01 00:00:00'
  601. ];
  602. $machine = $where['Gy0_sbbh'];
  603. if (isset($param['class'])){
  604. $where['Gy0_班次安排'] = $param['class'];
  605. }
  606. $filed = 'rtrim(Gy0_gdbh) as 工单编号,rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_小时产能) as 小时产能,
  607. rtrim(Gy0_生产工时) as 生产工时,rtrim(Gy0_辅助工时) as 辅助工时,rtrim(Gy0_班次安排) as 班次安排,rtrim(工序备注) as 排单备注,
  608. rtrim(Gy0_最早开工时间) as 最早开工时间,rtrim(Gy0_sj1) as 计划开工时间,rtrim(Gy0_sj2) as 计划完工时间,rtrim(Gy0_yjno) as yjno,
  609. rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Gy0_ls) as ls,rtrim(UniqId) as UniqId';
  610. $list = Db::table('工单_工艺资料')->where($where)->field($filed)->cache(true)->select();
  611. if (empty($list)){
  612. $this->error('未找到该机台制程中产品');
  613. }
  614. $Sql = "SELECT SUM(c.sczl_cl) as 已完成,rtrim(c.sczl_gdbh) as gdbh
  615. FROM `工单_工艺资料` AS a JOIN `设备_产量计酬` AS c ON a.Gy0_gdbh = c.sczl_gdbh
  616. AND a.Gy0_gxh = c.sczl_gxh WHERE a.Gy0_sbbh = '{$machine}' AND a.Gy0_sj1 > '1900-01-01 00:00:00'
  617. AND a.Gy0_sj1 < '2099-01-01 00:00:00' AND a.PD_WG = '1900-01-01 00:00:00' GROUP BY a.Gy0_gdbh";
  618. $res = Db::query($Sql);
  619. foreach ($list as $key=>$value){
  620. $list[$key]['计划接货数'] = (int)round($value['计划接货数']/$value['ls']);
  621. if ($value['yjno']<10){
  622. $value['yjno'] = '0'.$value['yjno'];
  623. }
  624. if ($value['gxh']<10){
  625. $value['gxh'] = '0'.$value['gxh'];
  626. }
  627. $list[$key]['印件/工序'] = $value['yjno'].'-'.$value['gxh'].'-'.$value['gxmc'];
  628. unset($list[$key]['yjno'],$list[$key]['gxh'],$list[$key]['gxmc'],$list[$key]['ls']);
  629. $list[$key]['已完成'] = 0;
  630. foreach ($res as $k=>$v){
  631. if ($value['工单编号'] === $v['gdbh']){
  632. $list[$key]['已完成'] = $v['已完成'];
  633. }
  634. }
  635. }
  636. $this->success('成功',$list);
  637. }
  638. /**
  639. * 车间设备排程编辑
  640. * @ApiMethod (POST)
  641. * @param void $param
  642. * @return void
  643. * @throws \think\Exception
  644. * @throws \think\exception\PDOException
  645. */
  646. public function EquipmentSchedulingEdit()
  647. {
  648. if (Request::instance()->isPost() === false){
  649. $this->error('请求错误');
  650. }
  651. $param = Request::instance()->post();
  652. if (empty($param)){
  653. $this->error('参数错误');
  654. }
  655. $i = 0;
  656. foreach ($param as $key=>$value){
  657. $data = [
  658. 'Gy0_小时产能' => $value['capacity'],
  659. 'Gy0_生产工时' => $value['ProductionHours'],
  660. 'Gy0_辅助工时' => $value['AuxiliaryHours'],
  661. 'Gy0_班次安排' => $value['shift'],
  662. '工序备注' => $value['remark'],
  663. 'Gy0_最早开工时间' => $value['start'] === ''?'1900-01-01 00:00:00':date('Y-m-d H:i:s',strtotime($value['start'])),
  664. 'Gy0_sj1' => date('Y-m-d H:i:s',strtotime($value['projectTime'])),
  665. 'Gy0_sj2' => date('Y-m-d HY-m-d',strtotime(($value['projectTime'])+(ceil($value['ProductionHours'])+ceil($value['AuxiliaryHours']))*3600)),
  666. ];
  667. halt($data);
  668. $sql = Db::table('工单_工艺资料')
  669. ->where('UniqId',$value['UniqId'])
  670. ->fetchSql(true)
  671. ->update($data);
  672. $res = Db::query($sql);
  673. if ($res !== false){
  674. $i++;
  675. }
  676. }
  677. if ($i !== 0){
  678. $this->success('成功');
  679. }else{
  680. $this->error('失败');
  681. }
  682. }
  683. }