Manufacture.php 25 KB

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