Manufacture.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  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('工单_基本资料')->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('工单_工艺资料')->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('工单_工艺资料')->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('工单_印件资料')->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. $where = '';
  156. if (isset($param['search'])){
  157. $where = "
  158. a.Gd_lx LIKE '%{$param['search']}%'
  159. OR a.Gd_gdbh LIKE '%{$param['search']}%'
  160. OR a.`Gd_客户代号` LIKE '%{$param['search']}%'
  161. OR a.`Gd_客户名称` LIKE '%{$param['search']}%'
  162. OR a.Gd_khdh LIKE '%{$param['search']}%'
  163. OR a.Gd_khmc LIKE '%{$param['search']}%'
  164. OR a.Gd_cpdh LIKE '%{$param['search']}%'
  165. OR a.Gd_cpmc LIKE '%{$param['search']}%'
  166. OR a.`成品代号` LIKE '%{$param['search']}%'
  167. OR a.`成品名称` LIKE '%{$param['search']}%'
  168. OR a.`产品版本号` LIKE '%{$param['search']}%'
  169. ";
  170. }
  171. if ($param['status'] === '排程中'){
  172. $sql = "SELECT
  173. rtrim( a.Gd_gdbh ) AS 工单编号,
  174. rtrim( a.Gd_cpdh ) AS 产品代号,
  175. rtrim( a.Gd_cpmc ) AS 产品名称,
  176. rtrim( a.接单日期 ) AS 接单日期,
  177. rtrim( a.交货日期 ) AS 交货日期,
  178. rtrim( a.订单数量 ) AS 订单数量,
  179. rtrim( a.计量单位 ) AS 计量单位,
  180. rtrim( a.销售订单号 ) AS 销售订单号,
  181. rtrim( a.Gd_客户代号 ) AS 客户编号,
  182. rtrim( a.Gd_客户名称 ) AS 客户名称,
  183. rtrim( a.客户料号 ) AS 客户料号,
  184. rtrim( a.Uniqid ) AS GDUID
  185. FROM
  186. `工单_基本资料` AS a
  187. INNER JOIN `工单_工艺资料` AS b ON a.Gd_gdbh = b.Gy0_gdbh
  188. JOIN `产品_基本资料` AS c ON a.Gd_cpdh = c.产品编号
  189. WHERE
  190. a.gd_statu = '2-生产中'
  191. AND a.行号 = '1'
  192. AND b.PD_WG = '1900-01-01 00:00:00'
  193. AND b.Gy0_sj1 = '1900-01-01 00:00:00'
  194. AND c.状态 = ''
  195. AND (".
  196. $where
  197. .")
  198. GROUP BY
  199. a.Gd_gdbh";
  200. }else{
  201. $sql = "SELECT
  202. rtrim(a.Gd_gdbh) AS 工单编号,
  203. rtrim(a.Gd_cpdh) AS 产品代号,
  204. rtrim(a.Gd_cpmc) AS 产品名称,
  205. rtrim(a.接单日期) AS 接单日期,
  206. rtrim(a.交货日期) AS 交货日期,
  207. rtrim(a.订单数量) AS 订单数量,
  208. rtrim(a.计量单位) AS 计量单位,
  209. rtrim(a.销售订单号) AS 销售订单号,
  210. rtrim(a.Gd_客户代号) AS 客户编号,
  211. rtrim(a.Gd_客户名称) AS 客户名称,
  212. rtrim(a.客户料号) AS 客户料号,
  213. rtrim(a.Uniqid) AS GDUID
  214. FROM
  215. `工单_基本资料` AS a
  216. INNER JOIN `工单_工艺资料` AS b ON a.Gd_gdbh = b.Gy0_gdbh
  217. JOIN `产品_基本资料` AS c ON a.Gd_cpdh = c.产品编号
  218. WHERE
  219. a.gd_statu = '2-生产中'
  220. AND a.行号 = '1'
  221. AND b.PD_WG = '1900-01-01 00:00:00'
  222. AND b.Gy0_sj1 != '1900-01-01 00:00:00'
  223. AND c.状态 = ''
  224. AND (".
  225. $where
  226. .")
  227. GROUP BY
  228. a.Gd_gdbh";
  229. }
  230. $list = Db::query($sql);
  231. if (empty($list)){
  232. $this->error('未找到工单信息');
  233. }
  234. $this->success('成功',$list);
  235. }
  236. /**
  237. * 排程中/制程中工单->工序列表
  238. * @ApiMethod (GET)
  239. * @param string $Gd_gdbh 工单编号
  240. * @return \think\response\Json
  241. * @throws \think\db\exception\DataNotFoundException
  242. * @throws \think\db\exception\ModelNotFoundException
  243. * @throws \think\exception\DbException
  244. */
  245. public function ScheduleProcess()
  246. {
  247. if ($this->request->isGet() === false){
  248. $this->error('请求错误');
  249. }
  250. $Gd_gdbh = input('Gd_gdbh');
  251. if (empty($Gd_gdbh)){
  252. $this->error('参数错误');
  253. }
  254. $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 小时产能,
  255. rtrim(a.工价系数) as 产能系数,rtrim(a.Gy0_生产工时) as 生产工时,rtrim(a.Gy0_辅助工时) as 辅助工时,rtrim(a.Gy0_最早开工时间) as 最早开工时间,
  256. rtrim(a.Gy0_sj1) as 计划开工时间,rtrim(a.Gy0_sj2) as 计划完工时间,rtrim(a.Gy0_班次安排) as 班次安排,rtrim(a.工序备注) as 排单备注,
  257. rtrim(a.PD_WG) as 工序完工,rtrim(a.UniqId) as UniqId,COALESCE(b.cl, 0) AS 产量, c.设备名称,rtrim(d.计划投料) as 工序产量
  258. FROM `工单_工艺资料` AS a
  259. JOIN `设备_基本资料` AS c ON a.Gy0_sbbh = c.设备编号
  260. JOIN `工单_基本资料` As d ON a.Gy0_gdbh = d.Gd_Gdbh
  261. LEFT JOIN (
  262. SELECT sczl_gdbh, sczl_gxh, SUM(sczl_cl) AS cl
  263. FROM `设备_产量计酬`
  264. GROUP BY sczl_gdbh, sczl_gxh
  265. ) AS b ON a.Gy0_gdbh = b.sczl_gdbh AND (a.Gy0_gxh = b.sczl_gxh OR b.sczl_gxh IS NULL)
  266. WHERE a.Gy0_gdbh = '{$Gd_gdbh}' AND a.Gy0_sbbh != ''
  267. GROUP BY a.Gy0_gxh";
  268. $list = Db::query($sql);
  269. if (empty($list)){
  270. $this->error('未找到工序');
  271. }
  272. foreach ($list as $key=>$value){
  273. if ((int)$value['Gy0_yjno'] <10){
  274. $value['Gy0_yjno'] = '0'.rtrim($value['Gy0_yjno']);
  275. }
  276. if ((int)$value['Gy0_gxh'] <10){
  277. $value['Gy0_gxh'] = '0'.rtrim($value['Gy0_gxh']);
  278. }
  279. if (rtrim($value['Add_gxmc']) == ''){
  280. $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']);
  281. }else{
  282. $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']).'【'.rtrim($value['Add_gxmc']).'】';
  283. }
  284. unset($list[$key]['Gy0_gxmc'],$list[$key]['Add_gxmc']);
  285. $list[$key]['机组'] = $value['设备编号'];
  286. $list[$key]['剩余产量'] = (int)$list[$key]['工序产量']-(int)$list[$key]['产量'];
  287. }
  288. $this->success('成功',$list);
  289. }
  290. /**
  291. * 排单页面左侧车间和机台菜单
  292. * @ApiMethod (GET)
  293. * @return \think\response\Json
  294. * @throws \think\db\exception\DataNotFoundException
  295. * @throws \think\db\exception\ModelNotFoundException
  296. * @throws \think\exception\DbException
  297. */
  298. public function workbench()
  299. {
  300. if ($this->request->isGet() === false){
  301. $this->error('请求错误');
  302. }
  303. $data = [];
  304. $department = \db('设备_基本资料')->distinct(true)->cache(true)->column('使用部门');
  305. if (empty($department)){
  306. $this->error('为获取到机台数据');
  307. }
  308. foreach ($department as $value){
  309. if (rtrim($value) !== '研发中心'){
  310. $benchClass = \db('设备_基本资料')->where('使用部门',$value)->distinct(true)->cache(true)->column('设备编组');
  311. foreach ($benchClass as $v){
  312. if (rtrim($v) !== ''){
  313. $machine = \db('设备_基本资料')->where('使用部门',$value)->where('设备编组',$v)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->cache(true)->select();
  314. foreach ($machine as $kk=>$vv){
  315. $data[rtrim($value)][rtrim($v)][$kk] = $vv['设备编号'].'-->'.$vv['设备名称'];
  316. }
  317. }
  318. }
  319. }
  320. }
  321. $this->success('成功',$data);
  322. }
  323. /**
  324. * 工单状态设置
  325. * @ApiMethod (GET)
  326. * @param string $workOrder 工单编号
  327. * @param string $status 工单状态
  328. * @return void
  329. * @throws \think\Exception
  330. * @throws \think\exception\PDOException
  331. */
  332. public function StatusEdit()
  333. {
  334. if (Request::instance()->isPost() === false){
  335. $this->error('请求错误');
  336. }
  337. $workOrder = input('workOrder');
  338. $status = input('status');
  339. if (empty($workOrder) || empty($status)){
  340. $this->error('参数错误');
  341. }
  342. $sql = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->fetchSql(true)->update(['gd_statu'=>$status]);
  343. $res = Db::query($sql);
  344. if ($res !== false){
  345. $this->success('成功');
  346. }else{
  347. $this->error('失败');
  348. }
  349. }
  350. /**
  351. * 更改工序状态
  352. * @ApiMethod (GET)
  353. * @param void
  354. * @return void
  355. * @throws \think\Exception
  356. * @throws \think\exception\PDOException
  357. */
  358. public function complete()
  359. {
  360. if ($this->request->isGet() === false){
  361. $this->error('请求错误');
  362. }
  363. $data = $this->request->param();
  364. if (empty($data)){
  365. $this->error('参数错误');
  366. }
  367. $where = [
  368. 'Gy0_gdbh' => $data['workOrder'],
  369. 'Gy0_gxh' => $data['processCode']
  370. ];
  371. $sql = \db('工单_工艺资料')->where($where)->fetchSql(true)->update(['PD_WG'=>date('Y-m-d H:i:s',time())]);
  372. $res = Db::query($sql);
  373. if ($res !== false){
  374. $this->success('成功');
  375. }else{
  376. $this->error('失败');
  377. }
  378. }
  379. /**
  380. * 加入排产
  381. * @ApiMethod (POST)
  382. * @param void $data
  383. * @return void
  384. * @throws \think\Exception
  385. * @throws \think\db\exception\DataNotFoundException
  386. * @throws \think\db\exception\ModelNotFoundException
  387. * @throws \think\exception\DbException
  388. * @throws \think\exception\PDOException
  389. */
  390. public function ProductionSchedulingAdd()
  391. {
  392. if (Request::instance()->isPost() === false){
  393. $this->error('请求错误');
  394. }
  395. $data = Request::instance()->post();
  396. if (empty($data)){
  397. $this->error('参数错误');
  398. }
  399. $where = [
  400. 'Gy0_gdbh' => $data['workOrder'],
  401. 'Gy0_sbbh' => $data['machine'],
  402. 'Gy0_yjno' => $data['printCode'],
  403. 'Gy0_gxh' => $data['processCode']
  404. ];
  405. $lastTime = \db('工单_工艺资料')
  406. ->where(['Gy0_sbbh'=>$where['Gy0_sbbh'],'Gy0_sj2'=>['<>','1900-01-01 00:00:00'],'Gy0_sj2'=>['<','2099-01-01 00:00:00']])
  407. ->field('rtrim(Gy0_sj2) as sj2')
  408. ->order('Gy0_sj2 desc')
  409. ->find();
  410. $row = \db('工单_工艺资料')
  411. ->where($where)
  412. ->field('rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_小时产能) as 小时产能,rtrim(Gy0_辅助工时) as 辅助工时')
  413. ->find();
  414. if (empty($row)){
  415. $this->error('未找到该工单工艺资料');
  416. }
  417. $endTime = date('Y-m-d H:i:s',strtotime($lastTime['sj2']) + ((int)round($row['计划接货数']/$row['小时产能'])+(int)$row['辅助工时'])*3600);
  418. $sql = \db('工单_工艺资料')
  419. ->where($where)
  420. ->fetchSql(true)
  421. ->update(['Gy0_sj1'=>$lastTime['sj2'],'Gy0_sj2'=>$endTime,'Mod_rq'=>date('Y-m-d H:i:s',time())]);
  422. $res = Db::query($sql);
  423. if ($res !== false){
  424. $this->success('成功');
  425. }else{
  426. $this->error('失败');
  427. }
  428. }
  429. /**
  430. * 暂停排产
  431. * @ApiMethod (POST)
  432. * @param void $data
  433. * @return void
  434. * @throws \think\Exception
  435. * @throws \think\db\exception\DataNotFoundException
  436. * @throws \think\db\exception\ModelNotFoundException
  437. * @throws \think\exception\DbException
  438. * @throws \think\exception\PDOException
  439. */
  440. public function ProductionSchedulingPause()
  441. {
  442. if (Request::instance()->isPost() === false){
  443. $this->error('请求错误');
  444. }
  445. $data = Request::instance()->post();
  446. if (empty($data)){
  447. $this->error('参数错误');
  448. }
  449. $where = [
  450. 'Gy0_gdbh' => $data['workOrder'],
  451. 'Gy0_sbbh' => $data['machine'],
  452. 'Gy0_yjno' => $data['printCode'],
  453. 'Gy0_gxh' => $data['processCode']
  454. ];
  455. $machine = $where['Gy0_sbbh'];
  456. $endTime = \db('工单_工艺资料')->where($where)->field('rtrim(Gy0_sj2) as sj2')->find()['sj2'];
  457. if (empty($endTime)){
  458. $this->error('未找到该工序');
  459. }
  460. if ($endTime <= '1900-01-01 00:00:00' || $endTime >= '2099-01-01 00:00:00'){
  461. $this->error('该工单不是制程中工单');
  462. }
  463. $sql = \db('工单_工艺资料')
  464. ->where($where)
  465. ->fetchSql(true)
  466. ->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')]);
  467. $row = \db('工单_工艺资料')
  468. ->where($where)
  469. ->field('rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_小时产能) as 小时产能,rtrim(Gy0_辅助工时) as 辅助工时')
  470. ->find();
  471. if (empty($row)){
  472. $this->error('未找到该工序');
  473. }
  474. $number = -(int)round($row['计划接货数']/$row['小时产能'])+(int)$row['辅助工时'];
  475. $res = Db::query($sql);
  476. $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'";
  477. $rechres = Db::query($rechSql);
  478. if ($res !== false && $rechres !== false){
  479. $this->success('成功');
  480. }else{
  481. $this->error('失败');
  482. }
  483. }
  484. /**
  485. * 工序状态更正
  486. * @ApiMethod (GET)
  487. * @param void $param
  488. * @return void
  489. * @throws \think\db\exception\DataNotFoundException
  490. * @throws \think\db\exception\ModelNotFoundException
  491. * @throws \think\exception\DbException
  492. */
  493. public function ProcessStatusCorrection()
  494. {
  495. if ($this->request->isGet() === false){
  496. $this->error('请求错误');
  497. }
  498. $param = $this->request->param();
  499. if (empty($param)){
  500. $this->error('参数错误');
  501. }
  502. $where = [
  503. 'Gy0_gdbh' => $param['workOrder'],
  504. 'Gy0_sbbh' => ['<>','']
  505. ];
  506. $workOrder = $where['Gy0_gdbh'];
  507. $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';
  508. $list = \db('工单_工艺资料')->where($where)->field($field)->order('Gy0_gxh')->select();
  509. if (empty($list)){
  510. $this->error('未找到该工单工艺资料');
  511. }
  512. $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";
  513. $yield = Db::query($yieldSql);
  514. foreach ($list as $key=>$value){
  515. if ($value['yjno']<10){
  516. $value['yjno'] = '0'.$value['yjno'];
  517. }
  518. if ($value['gxh']<10){
  519. $value['gxh'] = '0'.$value['gxh'];
  520. }
  521. $list[$key]['印件及工序'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'];
  522. foreach ($yield as $k=>$v){
  523. if ($v['gxh'] === $list[$key]['gxh']){
  524. $list[$key]['计划产量/已完成'] = (int)($value['计划接货数']/$value['ls']).'/'.$v['cl'];
  525. $list[$key]['完成率'] = number_format($v['cl']/($value['计划接货数']/$value['ls']),4)*100 . '%';
  526. }else{
  527. $list[$key]['计划产量/已完成'] = ($value['计划接货数']/$value['ls']).'/0';
  528. $list[$key]['完成率'] = '';
  529. }
  530. }
  531. if ($value['完工时间'] == '1900-01-01 00:00:00') {
  532. $list[$key]['完工时间'] = '';
  533. }
  534. unset($list[$key]['yjno'],$list[$key]['gxh'],$list[$key]['gxmc'],$list[$key]['计划接货数'],$list[$key]['ls']);
  535. }
  536. $this->success('成功',$list);
  537. }
  538. /**
  539. * 工序状态更正->工序状态编辑
  540. * @ApiMethod (POST)
  541. * @param void
  542. * @return void
  543. * @throws \think\Exception
  544. * @throws \think\exception\PDOException
  545. */
  546. public function ProcessStatusCorrectionEdit()
  547. {
  548. if (Request::instance()->isPost() === false){
  549. $this->error('请求错误');
  550. }
  551. $param = Request::instance()->post();
  552. if (empty($param)){
  553. $this->error('参数错误');
  554. }
  555. $i = 0;
  556. foreach ($param as $key=>$value){
  557. if ($value['PD_WG'] === null || $value['PD_WG'] === ''){
  558. $endTime = '1900-01-01 00:00:00';
  559. }else{
  560. $endTime = $value['PD_WG'];
  561. }
  562. $sql = \db('工单_工艺资料')
  563. ->where('UniqId',$value['UniqId'])
  564. ->fetchSql(true)
  565. ->update(['PD_WG'=>$endTime]);
  566. $res = Db::query($sql);
  567. if ($res !== false){
  568. $i++;
  569. }
  570. }
  571. if ($i !== 0){
  572. $this->success('成功');
  573. }else{
  574. $this->error('失败');
  575. }
  576. }
  577. /**
  578. * 班次选择
  579. * @ApiMethod (GET)
  580. * @return void
  581. * @throws \think\db\exception\DataNotFoundException
  582. * @throws \think\db\exception\ModelNotFoundException
  583. * @throws \think\exception\DbException
  584. */
  585. public function ScheduleSelection()
  586. {
  587. if ($this->request->isGet() === false){
  588. $this->error('请求错误');
  589. }
  590. $list = \db('工单_排程班次')->field('rtrim(bcdh) as 班次代号,rtrim(desc_) as desc_,rtrim(stdtime) as stdtime')->select();
  591. if (empty($list)){
  592. $this->error('未找到班次数据');
  593. }
  594. foreach ($list as $key=>$value){
  595. $list[$key]['detail'] = $value['班次代号'].'||'.$value['desc_'].'||'.$value['stdtime'];
  596. unset($list[$key]['desc_'],$list[$key]['stdtime']);
  597. }
  598. $this->success('成功',$list);
  599. }
  600. /**
  601. * 车间设备制程展示
  602. * @ApiMethod (GET)
  603. * @param void $param
  604. * @return void
  605. * @throws \think\db\exception\DataNotFoundException
  606. * @throws \think\db\exception\ModelNotFoundException
  607. * @throws \think\exception\DbException
  608. */
  609. public function EquipmentScheduling()
  610. {
  611. if ($this->request->isGet() === false){
  612. $this->error('参数错误');
  613. }
  614. $param = $this->request->param();
  615. if (empty($param)){
  616. $this->error('参数错误');
  617. }
  618. $where = [
  619. 'Gy0_sbbh' => $param['machine'],
  620. 'Gy0_sj1' => ['between',['1900-01-01 00:00:01','2098-12-31 23:59:59']],
  621. 'PD_WG' => '1900-01-01 00:00:00'
  622. ];
  623. $machine = $where['Gy0_sbbh'];
  624. if (isset($param['class'])){
  625. $where['Gy0_班次安排'] = $param['class'];
  626. }
  627. $filed = 'rtrim(Gy0_gdbh) as 工单编号,rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_小时产能) as 小时产能,
  628. rtrim(Gy0_生产工时) as 生产工时,rtrim(Gy0_辅助工时) as 辅助工时,rtrim(Gy0_班次安排) as 班次安排,rtrim(工序备注) as 排单备注,
  629. rtrim(Gy0_最早开工时间) as 最早开工时间,rtrim(Gy0_sj1) as 计划开工时间,rtrim(Gy0_sj2) as 计划完工时间,rtrim(Gy0_yjno) as yjno,
  630. rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Gy0_ls) as ls,rtrim(UniqId) as UniqId';
  631. $list = \db('工单_工艺资料')->where($where)->field($filed)->cache(true)->select();
  632. if (empty($list)){
  633. $this->error('未找到该机台制程中产品');
  634. }
  635. $Sql = "SELECT SUM(c.sczl_cl) as 已完成,rtrim(c.sczl_gdbh) as gdbh
  636. FROM `工单_工艺资料` AS a JOIN `设备_产量计酬` AS c ON a.Gy0_gdbh = c.sczl_gdbh
  637. AND a.Gy0_gxh = c.sczl_gxh WHERE a.Gy0_sbbh = '{$machine}' AND a.Gy0_sj1 > '1900-01-01 00:00:00'
  638. 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";
  639. $res = Db::query($Sql);
  640. foreach ($list as $key=>$value){
  641. $list[$key]['计划接货数'] = (int)round($value['计划接货数']/$value['ls']);
  642. if ($value['yjno']<10){
  643. $value['yjno'] = '0'.$value['yjno'];
  644. }
  645. if ($value['gxh']<10){
  646. $value['gxh'] = '0'.$value['gxh'];
  647. }
  648. $list[$key]['印件/工序'] = $value['yjno'].'-'.$value['gxh'].'-'.$value['gxmc'];
  649. unset($list[$key]['yjno'],$list[$key]['gxh'],$list[$key]['gxmc'],$list[$key]['ls']);
  650. $list[$key]['已完成'] = 0;
  651. foreach ($res as $k=>$v){
  652. if ($value['工单编号'] === $v['gdbh']){
  653. $list[$key]['已完成'] = $v['已完成'];
  654. }
  655. }
  656. }
  657. $this->success('成功',$list);
  658. }
  659. /**
  660. * 车间设备排程编辑
  661. * @ApiMethod (POST)
  662. * @param void $param
  663. * @return void
  664. * @throws \think\Exception
  665. * @throws \think\exception\PDOException
  666. */
  667. public function EquipmentSchedulingEdit()
  668. {
  669. if (Request::instance()->isPost() === false){
  670. $this->error('请求错误');
  671. }
  672. $param = Request::instance()->post();
  673. if (empty($param)){
  674. $this->error('参数错误');
  675. }
  676. $i = 0;
  677. foreach ($param as $key=>$value){
  678. $data = [
  679. 'Gy0_小时产能' => $value['capacity'],
  680. 'Gy0_生产工时' => $value['ProductionHours'],
  681. 'Gy0_辅助工时' => $value['AuxiliaryHours'],
  682. 'Gy0_班次安排' => $value['shift'],
  683. '工序备注' => $value['remark'],
  684. 'Gy0_最早开工时间' => $value['start'] === ''?'1900-01-01 00:00:00':date('Y-m-d H:i:s',strtotime($value['start'])),
  685. 'Gy0_sj1' => date('Y-m-d H:i:s',strtotime($value['projectTime'])),
  686. 'Gy0_sj2' => date('Y-m-d HY-m-d',strtotime(($value['projectTime'])+(ceil($value['ProductionHours'])+ceil($value['AuxiliaryHours']))*3600)),
  687. ];
  688. $sql = \db('工单_工艺资料')
  689. ->where('UniqId',$value['UniqId'])
  690. ->fetchSql(true)
  691. ->update($data);
  692. $res = Db::query($sql);
  693. if ($res !== false){
  694. $i++;
  695. }
  696. }
  697. if ($i !== 0){
  698. $this->success('成功');
  699. }else{
  700. $this->error('失败');
  701. }
  702. }
  703. /**
  704. * 机台工单展示
  705. * @ApiMethod ()
  706. * @return void
  707. * @throws \think\db\exception\BindParamException
  708. * @throws \think\exception\PDOException
  709. */
  710. public function MachineWorkOrderList()
  711. {
  712. if ($this->request->isGet() === false){
  713. $this->error('请求失败');
  714. }
  715. $param = $this->request->param();
  716. if (empty($param)){
  717. $this->error('参数错误');
  718. }
  719. if ($param['status'] === '制程'){
  720. $where = "a.gd_statu = '2-生产中'
  721. AND a.`行号` = '1'
  722. AND b.Gy0_sbbh LIKE '%{$param['machine']}%'
  723. AND b.PD_WG = '1900-01-01 00:00:00'
  724. AND b.Gy0_sj1 != '1900-01-01 00:00:00' ";
  725. }else{
  726. $where = "a.gd_statu = '2-生产中'
  727. AND a.`行号` = '1'
  728. AND b.Gy0_sbbh LIKE '%{$param['machine']}%'
  729. AND b.PD_WG = '1900-01-01 00:00:00'
  730. AND b.Gy0_sj1 = '1900-01-01 00:00:00' ";
  731. }
  732. $sql = "SELECT
  733. RTRIM( a.Gd_gdbh ) AS 工单编号,
  734. RTRIM( a.`销售订单号` ) AS 销售订单号,
  735. RTRIM( c.yj_yjmc ) AS 印件名称,
  736. RTRIM( b.Gy0_yjno ) AS yjno,
  737. RTRIM( b.Gy0_gxh ) AS gxh,
  738. RTRIM( b.Gy0_gxmc ) AS gxmc,
  739. RTRIM( b.Add_gxmc ) AS Add_gxmc,
  740. RTRIM( b.`Gy0_计划接货数` ) AS 计划接货数,
  741. RTRIM( b.`Gy0_小时产能` ) AS 小时产能,
  742. RTRIM( b.`工价系数` ) AS 产能系数,
  743. RTRIM( b.`Gy0_生产工时` ) AS 生产工时,
  744. RTRIM( b.Gy0_ls ) AS ls,
  745. RTRIM( b.`Gy0_辅助工时` ) AS 辅助工时,
  746. RTRIM( b.`Gy0_最早开工时间` ) AS 最早开工时间,
  747. RTRIM( b.Gy0_sj1 ) AS 计划开工时间,
  748. RTRIM( b.Gy0_sj2 ) AS 计划完工时间,
  749. RTRIM( b.`Gy0_班次安排` ) AS 班次安排,
  750. RTRIM( b.`工序备注` ) AS 排单备注,
  751. RTRIM( a.Gd_cpmc ) AS 产品名称,
  752. RTRIM( a.`成品名称` ) AS 成品名称,
  753. RTRIM( a.`订单数量` ) AS 订单数量,
  754. RTRIM( a.`计量单位` ) AS 计量单位,
  755. RTRIM( a.`交货日期` ) AS 交货日期,
  756. RTRIM( a.Gd_cpdh ) AS 产品代号,
  757. RTRIM( a.`成品代号` ) AS 成品代号,
  758. RTRIM( b.Gy0_sbbh ) AS 设备编号,
  759. RTRIM( b.Gy0_SITE ) AS 车间名称,
  760. RTRIM( b.UniqId ) AS GYUID,
  761. SUM( d.sczl_cl ) AS 已完成产量
  762. FROM
  763. `工单_基本资料` AS a
  764. JOIN `工单_工艺资料` AS b ON a.Gd_gdbh = b.Gy0_gdbh
  765. JOIN `工单_印件资料` AS c ON c.Yj_Gdbh = a.Gd_gdbh
  766. LEFT JOIN `设备_产量计酬` AS d ON a.Gd_gdbh = d.sczl_gdbh
  767. AND b.Gy0_sbbh = d.sczl_jtbh
  768. WHERE
  769. ".$where."
  770. GROUP BY
  771. A.Gd_gdbh";
  772. $list = \db()->query($sql);
  773. if (empty($list)){
  774. $this->success('',[]);
  775. }
  776. foreach ($list as $key=>$value){
  777. if ((int)$value['yjno'] <10){
  778. $value['yjno'] = '0'.rtrim($value['yjno']);
  779. }
  780. if ((int)$value['gxh'] <10){
  781. $value['gxh'] = '0'.rtrim($value['gxh']);
  782. }
  783. if (rtrim($value['Add_gxmc']) == ''){
  784. $list[$key]['印件工序及名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.rtrim($value['gxmc']);
  785. }else{
  786. $list[$key]['印件工序及名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.rtrim($value['gxmc']).'【'.rtrim($value['Add_gxmc']).'】';
  787. }
  788. unset($list[$key]['gxmc'],$list[$key]['Add_gxmc']);
  789. if ($value['产品名称'] == ''){
  790. $list[$key]['产品名称'] = $value['成品名称'];
  791. }
  792. if ($value['产品代号'] == ''){
  793. $list[$key]['产品代号'] = $value['成品代号'];
  794. }
  795. unset($list[$key]['成品代号'],$list[$key]['成品名称']);
  796. }
  797. $this->success('成功',$list);
  798. }
  799. }