Manufacture.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  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 (!empty($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. ->where([
  189. 'a.gd_statu' => '2-生产中',
  190. 'a.行号' => '1',
  191. 'b.PD_WG' => '1900-01-01 00:00:00',
  192. ])
  193. ->where($where)
  194. ->whereNotExists(function ($query) {
  195. $query->table('工单_工艺资料')->alias('b2')
  196. ->where('b2.Gy0_gdbh = a.Gd_gdbh')
  197. ->where('b2.Gy0_sj1 <> "1900-01-01 00:00:00"');
  198. })
  199. ->group('a.Gd_gdbh')
  200. ->select();
  201. }else{
  202. $list = db('工单_基本资料')->alias('a')
  203. ->field([
  204. 'rtrim(a.Gd_gdbh)' => '工单编号',
  205. 'rtrim(a.Gd_cpdh)' => '产品代号',
  206. 'rtrim(a.Gd_cpmc)' => '产品名称',
  207. 'rtrim(a.接单日期)' => '接单日期',
  208. 'rtrim(a.交货日期)' => '交货日期',
  209. 'rtrim(a.订单数量)' => '订单数量',
  210. 'rtrim(a.计量单位)' => '计量单位',
  211. 'rtrim(a.销售订单号)' => '销售订单号',
  212. 'rtrim(a.Gd_客户代号)' => '客户编号',
  213. 'rtrim(a.Gd_客户名称)' => '客户名称',
  214. 'rtrim(a.客户料号)' => '客户料号',
  215. 'rtrim(a.Uniqid)' => 'GDUID',
  216. ])
  217. ->join('工单_工艺资料 b', 'a.Gd_gdbh = b.Gy0_gdbh')
  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. ])
  224. ->where($where)
  225. ->group('a.Gd_gdbh')
  226. ->select();
  227. }
  228. if (empty($list)){
  229. $this->success('未找到工单信息');
  230. }
  231. $this->success('成功',$list);
  232. }
  233. /**
  234. * 排程中/制程中工单->工序列表
  235. * @ApiMethod (GET)
  236. * @param string $Gd_gdbh 工单编号
  237. * @return \think\response\Json
  238. * @throws \think\db\exception\DataNotFoundException
  239. * @throws \think\db\exception\ModelNotFoundException
  240. * @throws \think\exception\DbException
  241. */
  242. public function ScheduleProcess()
  243. {
  244. if ($this->request->isGet() === false){
  245. $this->error('请求错误');
  246. }
  247. $Gd_gdbh = input('Gd_gdbh');
  248. if (empty($Gd_gdbh)){
  249. $this->error('参数错误');
  250. }
  251. $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 小时产能,
  252. rtrim(a.工价系数) as 产能系数,rtrim(a.Gy0_生产工时) as 生产工时,rtrim(a.Gy0_辅助工时) as 辅助工时,rtrim(a.Gy0_最早开工时间) as 最早开工时间,
  253. rtrim(a.Gy0_sj1) as 计划开工时间,rtrim(a.Gy0_sj2) as 计划完工时间,rtrim(a.Gy0_班次安排) as 班次安排,rtrim(a.工序备注) as 排单备注,
  254. rtrim(a.PD_WG) as 工序完工,rtrim(a.UniqId) as UniqId,COALESCE(b.cl, 0) AS 产量, c.设备名称,rtrim(d.计划投料) as 工序产量
  255. FROM `工单_工艺资料` AS a
  256. JOIN `设备_基本资料` AS c ON a.Gy0_sbbh = c.设备编号
  257. JOIN `工单_基本资料` As d ON a.Gy0_gdbh = d.Gd_Gdbh
  258. LEFT JOIN (
  259. SELECT sczl_gdbh, sczl_gxh, SUM(sczl_cl) AS cl
  260. FROM `设备_产量计酬`
  261. GROUP BY sczl_gdbh, sczl_gxh
  262. ) AS b ON a.Gy0_gdbh = b.sczl_gdbh AND (a.Gy0_gxh = b.sczl_gxh OR b.sczl_gxh IS NULL)
  263. WHERE a.Gy0_gdbh = '{$Gd_gdbh}' AND a.Gy0_sbbh != ''
  264. GROUP BY a.Gy0_gxh";
  265. $list = Db::query($sql);
  266. if (empty($list)){
  267. $this->success('未找到工序');
  268. }
  269. foreach ($list as $key=>$value){
  270. if ((int)$value['Gy0_yjno'] <10){
  271. $value['Gy0_yjno'] = '0'.rtrim($value['Gy0_yjno']);
  272. }
  273. if ((int)$value['Gy0_gxh'] <10){
  274. $value['Gy0_gxh'] = '0'.rtrim($value['Gy0_gxh']);
  275. }
  276. if (rtrim($value['Add_gxmc']) == ''){
  277. $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']);
  278. }else{
  279. $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']).'【'.rtrim($value['Add_gxmc']).'】';
  280. }
  281. unset($list[$key]['Gy0_gxmc'],$list[$key]['Add_gxmc']);
  282. $list[$key]['机组'] = $value['设备编号'];
  283. $list[$key]['剩余产量'] = (int)$list[$key]['工序产量']-(int)$list[$key]['产量'];
  284. }
  285. $this->success('成功',$list);
  286. }
  287. /**
  288. * 排单页面左侧车间和机台菜单
  289. * @ApiMethod (GET)
  290. * @return \think\response\Json
  291. * @throws \think\db\exception\DataNotFoundException
  292. * @throws \think\db\exception\ModelNotFoundException
  293. * @throws \think\exception\DbException
  294. */
  295. public function workbench()
  296. {
  297. if ($this->request->isGet() === false){
  298. $this->error('请求错误');
  299. }
  300. $data = [];
  301. $department = \db('设备_基本资料')
  302. ->distinct(true)
  303. ->where('使用部门','<>','研发中心')
  304. ->where('设备编组','<>','')
  305. ->order('设备编组')
  306. ->column('使用部门');
  307. if (empty($department)){
  308. $this->success('为获取到机台数据');
  309. }
  310. foreach ($department as $value){
  311. $benchClass = \db('设备_基本资料')->where('使用部门',$value)->distinct(true)->order('设备编组')->column('设备编组');
  312. foreach ($benchClass as $v){
  313. if (rtrim($v) !== ''){
  314. $machine = \db('设备_基本资料')->where('使用部门',$value)->where('设备编组',$v)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->select();
  315. foreach ($machine as $kk=>$vv){
  316. $data[rtrim($value)][rtrim($v)][$kk] = $vv['设备编号'].'-->'.$vv['设备名称'];
  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' => ['like','%'.$data['machine'].'%'],
  402. 'Gy0_yjno' => $data['printCode'],
  403. 'Gy0_gxh' => $data['processCode']
  404. ];
  405. $result = \db('工单_工艺资料')->where($where)->field('rtrim(Gy0_sj1) as sj1')->find();
  406. if ($result['sj1'] != '1900-01-01 00:00:00'){
  407. $this->error('该工单已经是制程中');
  408. }
  409. $lastTime = \db('工单_工艺资料')
  410. ->where(['Gy0_sbbh'=>$where['Gy0_sbbh'],'Gy0_sj2'=>['<>','1900-01-01 00:00:00'],'Gy0_sj2'=>['<','2099-01-01 00:00:00']])
  411. ->field('rtrim(Gy0_sj2) as sj2')
  412. ->order('Gy0_sj2 desc')
  413. ->find();
  414. $date = date('Y-m-d H:i:s',time());
  415. if ($lastTime['sj2'] < $date){
  416. $newTime = $date;
  417. }else{
  418. $newTime = $lastTime['sj2'];
  419. }
  420. $row = \db('工单_工艺资料')
  421. ->where($where)
  422. ->field('rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_小时产能) as 小时产能,rtrim(Gy0_辅助工时) as 辅助工时')
  423. ->find();
  424. if (empty($row)){
  425. $this->success('未找到该工单工艺资料');
  426. }
  427. $endTime = date('Y-m-d H:i:s',strtotime($newTime) + ((int)round($row['计划接货数']/$row['小时产能'])+(int)$row['辅助工时'])*3600);
  428. $sql = \db('工单_工艺资料')
  429. ->where($where)
  430. ->fetchSql(true)
  431. ->update(['Gy0_sj1'=>$newTime,'Gy0_sj2'=>$endTime,'Mod_rq'=>date('Y-m-d H:i:s',time())]);
  432. $res = Db::query($sql);
  433. if ($res !== false){
  434. $this->success('成功');
  435. }else{
  436. $this->error('失败');
  437. }
  438. }
  439. /**
  440. * 暂停排产
  441. * @ApiMethod (POST)
  442. * @param void $data
  443. * @return void
  444. * @throws \think\Exception
  445. * @throws \think\db\exception\DataNotFoundException
  446. * @throws \think\db\exception\ModelNotFoundException
  447. * @throws \think\exception\DbException
  448. * @throws \think\exception\PDOException
  449. */
  450. public function ProductionSchedulingPause()
  451. {
  452. if (Request::instance()->isPost() === false){
  453. $this->error('请求错误');
  454. }
  455. $data = Request::instance()->post();
  456. if (empty($data)){
  457. $this->error('参数错误');
  458. }
  459. $where = [
  460. 'Gy0_gdbh' => $data['workOrder'],
  461. 'Gy0_sbbh' => ['like','%'.$data['machine'].'%'],
  462. 'Gy0_yjno' => $data['printCode'],
  463. 'Gy0_gxh' => $data['processCode']
  464. ];
  465. $machine = $data['machine'];
  466. $endTime = \db('工单_工艺资料')->where($where)->field('rtrim(Gy0_sj2) as sj2,rtrim(PD_WG) as wg')->find();
  467. if (empty($endTime)){
  468. $this->success('未找到该工序');
  469. }
  470. $time = $endTime['sj2'];
  471. if ($endTime['sj2'] == '1900-01-01 00:00:00' || $endTime['wg'] != '1900-01-01 00:00:00'){
  472. $this->error('该工单不是制程中工单');
  473. }
  474. $sql = \db('工单_工艺资料')
  475. ->where($where)
  476. ->fetchSql(true)
  477. ->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')]);
  478. $row = \db('工单_工艺资料')
  479. ->where($where)
  480. ->field('rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_小时产能) as 小时产能,rtrim(Gy0_辅助工时) as 辅助工时')
  481. ->find();
  482. if (empty($row)){
  483. $this->success('未找到该工序');
  484. }
  485. $number = -(int)round($row['计划接货数']/$row['小时产能'])+(int)$row['辅助工时'];
  486. $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'";
  487. $rechres = Db::query($rechSql);
  488. $res = Db::query($sql);
  489. if ($res !== false && $rechres !== false){
  490. $this->success('成功');
  491. }else{
  492. $this->error('失败');
  493. }
  494. }
  495. /**
  496. * 工序状态更正
  497. * @ApiMethod (GET)
  498. * @param void $param
  499. * @return void
  500. * @throws \think\db\exception\DataNotFoundException
  501. * @throws \think\db\exception\ModelNotFoundException
  502. * @throws \think\exception\DbException
  503. */
  504. public function ProcessStatusCorrection()
  505. {
  506. if ($this->request->isGet() === false){
  507. $this->error('请求错误');
  508. }
  509. $param = $this->request->param();
  510. if (empty($param)){
  511. $this->error('参数错误');
  512. }
  513. $where = [
  514. 'Gy0_gdbh' => $param['workOrder'],
  515. 'Gy0_sbbh' => ['<>','']
  516. ];
  517. $workOrder = $where['Gy0_gdbh'];
  518. $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';
  519. $list = \db('工单_工艺资料')->where($where)->field($field)->order('Gy0_gxh')->select();
  520. if (empty($list)){
  521. $this->success('未找到该工单工艺资料');
  522. }
  523. $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";
  524. $yield = Db::query($yieldSql);
  525. foreach ($list as $key=>$value){
  526. if ($value['yjno']<10){
  527. $value['yjno'] = '0'.$value['yjno'];
  528. }
  529. if ($value['gxh']<10){
  530. $value['gxh'] = '0'.$value['gxh'];
  531. }
  532. $list[$key]['印件及工序'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'];
  533. foreach ($yield as $k=>$v){
  534. if ($v['gxh'] === $list[$key]['gxh']){
  535. $list[$key]['计划产量/已完成'] = (int)($value['计划接货数']/$value['ls']).'/'.$v['cl'];
  536. $list[$key]['完成率'] = number_format($v['cl']/($value['计划接货数']/$value['ls']),4)*100 . '%';
  537. }else{
  538. $list[$key]['计划产量/已完成'] = ($value['计划接货数']/$value['ls']).'/0';
  539. $list[$key]['完成率'] = '';
  540. }
  541. }
  542. if ($value['完工时间'] == '1900-01-01 00:00:00') {
  543. $list[$key]['完工时间'] = '';
  544. }
  545. unset($list[$key]['yjno'],$list[$key]['gxh'],$list[$key]['gxmc'],$list[$key]['计划接货数'],$list[$key]['ls']);
  546. }
  547. $this->success('成功',$list);
  548. }
  549. /**
  550. * 工序状态更正->工序状态编辑
  551. * @ApiMethod (POST)
  552. * @param void
  553. * @return void
  554. * @throws \think\Exception
  555. * @throws \think\exception\PDOException
  556. */
  557. public function ProcessStatusCorrectionEdit()
  558. {
  559. if (Request::instance()->isPost() === false){
  560. $this->error('请求错误');
  561. }
  562. $param = Request::instance()->post();
  563. if (empty($param)){
  564. $this->error('参数错误');
  565. }
  566. $i = 0;
  567. foreach ($param as $key=>$value){
  568. if ($value['PD_WG'] === null || $value['PD_WG'] === ''){
  569. $endTime = '1900-01-01 00:00:00';
  570. }else{
  571. $endTime = $value['PD_WG'];
  572. }
  573. $sql = \db('工单_工艺资料')
  574. ->where('UniqId',$value['UniqId'])
  575. ->fetchSql(true)
  576. ->update(['PD_WG'=>$endTime]);
  577. $res = Db::query($sql);
  578. if ($res !== false){
  579. $i++;
  580. }
  581. }
  582. if ($i !== 0){
  583. $this->success('成功');
  584. }else{
  585. $this->error('失败');
  586. }
  587. }
  588. /**
  589. * 班次选择
  590. * @ApiMethod (GET)
  591. * @return void
  592. * @throws \think\db\exception\DataNotFoundException
  593. * @throws \think\db\exception\ModelNotFoundException
  594. * @throws \think\exception\DbException
  595. */
  596. public function ScheduleSelection()
  597. {
  598. if ($this->request->isGet() === false){
  599. $this->error('请求错误');
  600. }
  601. $list = \db('工单_排程班次')->field('rtrim(bcdh) as 班次代号,rtrim(desc_) as desc_,rtrim(stdtime) as stdtime')->select();
  602. if (empty($list)){
  603. $this->success('未找到班次数据');
  604. }
  605. foreach ($list as $key=>$value){
  606. $list[$key]['detail'] = $value['班次代号'].'||'.$value['desc_'].'||'.$value['stdtime'];
  607. unset($list[$key]['desc_'],$list[$key]['stdtime']);
  608. }
  609. $this->success('成功',$list);
  610. }
  611. /**
  612. * 车间设备制程展示
  613. * @ApiMethod (GET)
  614. * @param void $param
  615. * @return void
  616. * @throws \think\db\exception\DataNotFoundException
  617. * @throws \think\db\exception\ModelNotFoundException
  618. * @throws \think\exception\DbException
  619. */
  620. public function EquipmentScheduling()
  621. {
  622. if ($this->request->isGet() === false){
  623. $this->error('参数错误');
  624. }
  625. $param = $this->request->param();
  626. if (empty($param)){
  627. $this->error('参数错误');
  628. }
  629. $machine = $param['machine'];
  630. $list = \db('工单_基本资料')
  631. ->alias('a')
  632. ->field([
  633. 'rtrim(b.Gy0_gdbh)' => '工单编号',
  634. 'rtrim(b.Gy0_计划接货数)' => '计划接货数',
  635. 'rtrim(b.Gy0_小时产能)' => '小时产能',
  636. 'rtrim(b.Gy0_生产工时)' => '生产工时',
  637. 'rtrim(b.Gy0_辅助工时)' => '辅助工时',
  638. 'rtrim(b.Gy0_班次安排)' => '班次安排',
  639. 'rtrim(b.工序备注)' => '排单备注',
  640. 'rtrim(b.Gy0_最早开工时间)' => '最早开工时间',
  641. 'rtrim(b.Gy0_sj1)' => '计划开工时间',
  642. 'rtrim(b.Gy0_sj2)' => '计划完工时间',
  643. 'rtrim(b.Gy0_yjno)' => 'yjno',
  644. 'rtrim(b.Gy0_gxh)' => 'gxh',
  645. 'rtrim(b.Gy0_gxmc)' => 'gxmc',
  646. 'rtrim(b.Gy0_ls)' => 'ls',
  647. 'rtrim(b.UniqId)' => 'UniqId',
  648. 'SUM(c.sczl_cl)' => '已完成'
  649. ])
  650. ->join('工单_工艺资料 b','a.Gd_gdbh = b.Gy0_gdbh')
  651. ->join('设备_产量计酬 c','a.Gd_gdbh = c.sczl_gdbh AND b.Gy0_gxh = c.sczl_gxh','LEFT')
  652. ->where([
  653. 'b.Gy0_sbbh' => $machine,
  654. 'b.Gy0_sj1' => ['>','1900-01-01 00:00:00'],
  655. 'b.PD_WG' => '1900-01-01 00:00:00',
  656. 'a.gd_statu' => '2-生产中'
  657. ])
  658. ->where('b.Gy0_sj1','<','2099-01-01 00:00:00')
  659. ->group('a.Gd_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($value['projectTime'])+(ceil($value['ProductionHours'])+ceil($value['AuxiliaryHours']))*3600),
  702. 'Gy0_sj2' => date('Y-m-d H:i:s',strtotime($value['endTime'])),
  703. ];
  704. $sql = \db('工单_工艺资料')
  705. ->where('UniqId',$value['UniqId'])
  706. ->fetchSql(true)
  707. ->update($data);
  708. $res = Db::query($sql);
  709. if ($res !== false){
  710. $i++;
  711. }
  712. }
  713. if ($i !== 0){
  714. $this->success('成功');
  715. }else{
  716. $this->error('失败');
  717. }
  718. }
  719. /**
  720. * 机台工单展示
  721. * @ApiMethod ()
  722. * @return void
  723. * @throws \think\db\exception\BindParamException
  724. * @throws \think\exception\PDOException
  725. */
  726. public function MachineWorkOrderList()
  727. {
  728. if ($this->request->isGet() === false){
  729. $this->error('请求失败');
  730. }
  731. $param = $this->request->param();
  732. if (empty($param)){
  733. $this->error('参数错误');
  734. }
  735. $where = '';
  736. if (isset($param['search'])){
  737. $where = "
  738. b.Gd_gdbh LIKE '%{$param['search']}%'
  739. OR b.`成品名称` LIKE '%{$param['search']}%'
  740. ";
  741. }
  742. $list = \db('工单_工艺资料')
  743. ->alias('a')
  744. ->field([
  745. 'RTRIM( a.Gy0_yjno )' =>'yjno',
  746. 'RTRIM( a.Gy0_gxh )' => 'gxh',
  747. 'RTRIM( a.Gy0_gxmc )' => 'gxmc',
  748. 'RTRIM( a.Add_gxmc )' => 'Add_gxmc',
  749. 'RTRIM( c.yj_yjmc )' => '印件名称',
  750. 'RTRIM( a.`Gy0_计划接货数` )' => '计划接货数',
  751. 'RTRIM( a.`Gy0_小时产能` )' => '小时产能',
  752. 'RTRIM( a.`工价系数` )' => '产能系数',
  753. 'RTRIM( a.`Gy0_生产工时` )' => '生产工时',
  754. 'RTRIM( a.Gy0_ls )' => 'ls',
  755. 'RTRIM( a.`Gy0_辅助工时` )' => '辅助工时',
  756. 'RTRIM( a.`Gy0_最早开工时间` )' => '最早开工时间',
  757. 'RTRIM( a.Gy0_sj1 )' => '计划开工时间',
  758. 'RTRIM( a.Gy0_sj2 )' => '计划完工时间',
  759. 'RTRIM( a.`Gy0_班次安排` )' => '班次安排',
  760. 'RTRIM( a.`工序备注` )' => '排单备注',
  761. 'RTRIM( b.Gd_cpmc )' => '产品名称',
  762. 'RTRIM( b.`成品名称` )' => '成品名称',
  763. 'RTRIM( b.`订单数量` )' => '订单数量',
  764. 'RTRIM( b.`计量单位` )' => '计量单位',
  765. 'RTRIM( b.`交货日期` )' => '交货日期',
  766. 'RTRIM( b.Gd_cpdh )' => '产品代号',
  767. 'RTRIM( b.`成品代号` )' => '成品代号',
  768. 'RTRIM( a.Gy0_sbbh )' => '设备编号',
  769. 'RTRIM( a.Gy0_SITE )' => '车间名称',
  770. 'RTRIM( a.UniqId )' => 'GYUID',
  771. 'RTRIM( b.Uniqid )' => 'UNIQID',
  772. 'SUM( d.sczl_cl )' => '已完成产量',
  773. 'RTRIM( b.Gd_gdbh )' => '工单编号',
  774. 'RTRIM( b.`销售订单号` )' => '销售订单号',
  775. ])
  776. ->join('工单_印件资料 c','c.Yj_Gdbh = a.Gy0_gdbh AND c.yj_Yjno = a.Gy0_yjno')
  777. ->join('工单_基本资料 b','b.Gd_gdbh = a.Gy0_gdbh AND b.Gd_cpdh = c.yj_Yjdh')
  778. ->join('设备_产量计酬 d','a.Gy0_gdbh = d.sczl_gdbh AND a.Gy0_sbbh = d.sczl_jtbh','LEFT')
  779. ->where([
  780. 'b.gd_statu' => '2-生产中',
  781. 'a.Gy0_sbbh' => ['LIKE','%'.$param['machine'].'%'],
  782. 'a.PD_WG' => '1900-01-01 00:00:00',
  783. ])
  784. ->where($where)
  785. ->group('a.Gy0_gdbh,a.Gy0_yjno,a.Gy0_gxh')
  786. ->order('Gy0_sj1')
  787. ->select();
  788. if (empty($list)){
  789. $this->success('',[]);
  790. }
  791. $data['制程'] = $data['排程'] = [];
  792. foreach ($list as $key=>$value){
  793. $list[$key]['设备编号'] = $param['machine'];
  794. if ((int)$value['yjno'] <10){
  795. $value['yjno'] = '0'.rtrim($value['yjno']);
  796. }
  797. if ((int)$value['gxh'] <10){
  798. $value['gxh'] = '0'.rtrim($value['gxh']);
  799. }
  800. if (rtrim($value['Add_gxmc']) == ''){
  801. $list[$key]['印件工序及名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.rtrim($value['gxmc']);
  802. }else{
  803. $list[$key]['印件工序及名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.rtrim($value['gxmc']).'【'.rtrim($value['Add_gxmc']).'】';
  804. }
  805. unset($list[$key]['Add_gxmc']);
  806. if ($value['产品名称'] == ''){
  807. $list[$key]['产品名称'] = $value['成品名称'];
  808. }
  809. if ($value['产品代号'] == ''){
  810. $list[$key]['产品代号'] = $value['成品代号'];
  811. }
  812. unset($list[$key]['成品代号'],$list[$key]['成品名称']);
  813. if ($list[$key]['计划开工时间'] !== '1900-01-01 00:00:00'){
  814. array_push($data['制程'],$list[$key]);
  815. }else{
  816. array_push($data['排程'],$list[$key]);
  817. }
  818. }
  819. $this->success('成功',$data);
  820. }
  821. /**
  822. * 机组调整
  823. * @return void
  824. * @throws \think\Exception
  825. * @throws \think\db\exception\BindParamException
  826. * @throws \think\exception\PDOException
  827. */
  828. public function MachineTeamEdit()
  829. {
  830. if ($this->request->isGet() === false){
  831. $this->error('请求错误');
  832. }
  833. $param = $this->request->param();
  834. if (empty($param) || isset($param['UniqId']) === false){
  835. $this->error('参数错误');
  836. }
  837. $sql = \db('工单_工艺资料')
  838. ->where('UniqId',$param['UniqId'])
  839. ->fetchSql(true)
  840. ->update(['Gy0_sbbh'=>$param['machine']]);
  841. $res = \db()->query($sql);
  842. if ($res !== false){
  843. $this->success('修改成功');
  844. }else{
  845. $this->error('修改失败');
  846. }
  847. }
  848. }