Manufacture.php 35 KB

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