Manufacture.php 29 KB

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