Manufacture.php 25 KB

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