Manufacture.php 34 KB

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