GluingReport.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use think\Request;
  6. class GluingReport extends Api
  7. {
  8. protected $noNeedLogin = ['*'];
  9. protected $noNeedRight = ['*'];
  10. /**
  11. * 设备角色菜单
  12. * @return void
  13. */
  14. public function getGluingcoleTab()
  15. {
  16. if ($this->request->isGet() === false){
  17. $this->error('请求错误');
  18. }
  19. $sist = ['印后糊盒车间','精品自动化车间','数字化车间'];
  20. $list = db('设备_基本资料')
  21. ->where('使用部门','in',$sist)
  22. ->whereNotNull('sys_sbID')
  23. ->column('CONCAT(设备编号,"->",设备名称)');
  24. if (empty($list)){
  25. $this->error('未找到设备数据');
  26. }else{
  27. $this->success('成功',$list);
  28. }
  29. }
  30. /**
  31. * 设备角色列表
  32. * @return void
  33. * @throws \think\db\exception\DataNotFoundException
  34. * @throws \think\db\exception\ModelNotFoundException
  35. * @throws \think\exception\DbException
  36. */
  37. public function getGluingcoleList()
  38. {
  39. if ($this->request->isGet() === false){
  40. $this->error('请求错误');
  41. }
  42. $param = $this->request->param();
  43. if (empty($param)){
  44. $this->error('参数错误');
  45. }
  46. $list = db('设备_糊盒班组角色')
  47. ->where('jtbh',$param['machine'])
  48. ->select();
  49. if (empty($list)){
  50. $this->error('未找到数据');
  51. }else{
  52. $this->success('成功',$list);
  53. }
  54. }
  55. /**
  56. * 设备角色资料详情
  57. * @return void
  58. * @throws \think\db\exception\DataNotFoundException
  59. * @throws \think\db\exception\ModelNotFoundException
  60. * @throws \think\exception\DbException
  61. */
  62. public function getGluingcoleDetail()
  63. {
  64. if ($this->request->isGet() === false){
  65. $this->error('请求错误');
  66. }
  67. $param = $this->request->param();
  68. if (empty($param)){
  69. $this->error('参数错误');
  70. }
  71. $list = db('设备_糊盒班组角色')
  72. ->where('id',$param['id'])
  73. ->find();
  74. if (empty($list)){
  75. $this->error('未找到数据详情');
  76. }else{
  77. $this->success('成功',$list);
  78. }
  79. }
  80. /**
  81. * 新增机台班组角色
  82. * @return void
  83. */
  84. public function saveGluingcoleDetail(){
  85. if ($this->request->isPost() === false){
  86. $this->error('请求错误');
  87. }
  88. $param = Request::instance()->post();
  89. if (empty($param)){
  90. $this->error('参数错误');
  91. }
  92. $param['sys_rq'] = date('Y-m-d H:i:s',time());
  93. $res = db('设备_糊盒班组角色')->insert($param);
  94. if (empty($res)){
  95. $this->error('新增失败');
  96. }else{
  97. $this->success('新增成功');
  98. }
  99. }
  100. /**
  101. * 修改设备角色资料
  102. * @return void
  103. * @throws \think\Exception
  104. * @throws \think\exception\PDOException
  105. */
  106. public function getGluingcoleDetaiEdit()
  107. {
  108. if ($this->request->isPost() === false){
  109. $this->error('请求错误');
  110. }
  111. $param = Request::instance()->post();
  112. if (empty($param['id'])){
  113. $this->error('参数错误');
  114. }
  115. $id = intval($param['id']);
  116. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  117. unset($param['id']);
  118. $res = db('设备_糊盒班组角色')
  119. ->where('id',$id)
  120. ->update($param);
  121. if ($res === false){
  122. $this->error('修改失败');
  123. }else{
  124. $this->success('修改成功');
  125. }
  126. }
  127. /**
  128. * 设备当前班组角色
  129. * @return void
  130. * @throws \think\Exception
  131. * @throws \think\exception\PDOException
  132. */
  133. public function UpdateGluingcoleStatus()
  134. {
  135. if ($this->request->isGet() === false){
  136. $this->error('请求错误');
  137. }
  138. $param = $this->request->param();
  139. if (empty($param['id']) || empty($param['jtbh'])){
  140. $this->error('参数错误');
  141. }
  142. $updateRes = db('设备_糊盒班组角色')
  143. ->where('jtbh',$param['jtbh'])
  144. ->update(['status' => 0]);
  145. $res = db('设备_糊盒班组角色')
  146. ->where('id',$param['id'])
  147. ->update(['status' => 1]);
  148. if ($updateRes === false || $res === false){
  149. $this->error('更新失败');
  150. }else{
  151. $this->success('更新成功');
  152. }
  153. }
  154. /**
  155. * 设备班组资料列表
  156. * @return void
  157. * @throws \think\db\exception\DataNotFoundException
  158. * @throws \think\db\exception\ModelNotFoundException
  159. * @throws \think\exception\DbException
  160. */
  161. public function getGluingClassLList()
  162. {
  163. if ($this->request->isGet() === false){
  164. $this->error('请求错误');
  165. }
  166. $param = $this->request->param();
  167. if (empty($param)){
  168. $this->error('参数错误');
  169. }
  170. $list = db('设备_糊盒班组资料')
  171. ->where('jtbh',$param['machine'])
  172. ->select();
  173. foreach ($list as $k=>$v){
  174. for ($i = 1; $i <= 15; $i++){
  175. $bh = $v['bh'.$i];
  176. $list[$k]['name'.$i] = '';
  177. if (!empty($bh) && $bh !== ''){
  178. $name = \db('人事_基本资料')
  179. ->where('员工编号',$bh)
  180. ->value('员工姓名');
  181. $list[$k]['name'.$i] = $name;
  182. }
  183. }
  184. }
  185. if (empty($list)){
  186. $this->error('未找到数据');
  187. }else{
  188. $this->success('成功',$list);
  189. }
  190. }
  191. /**
  192. * 获取设备角色数据
  193. * @return void
  194. * @throws \think\db\exception\DataNotFoundException
  195. * @throws \think\db\exception\ModelNotFoundException
  196. * @throws \think\exception\DbException
  197. */
  198. public function getGluingcole()
  199. {
  200. if ($this->request->isGet() === false){
  201. $this->error('请求错误');
  202. }
  203. $param = $this->request->param();
  204. if (empty($param)){
  205. $this->error('参数错误');
  206. }
  207. $list = db('设备_糊盒班组角色')
  208. ->where('jtbh',$param['machine'])
  209. ->where('status',1)
  210. ->find();
  211. if (empty($list)){
  212. $this->error('未找到角色资料');
  213. }else{
  214. $this->success('成功',$list);
  215. }
  216. }
  217. /**
  218. * 新增糊盒机台班组资料
  219. * @return void
  220. */
  221. public function AddGluingClass()
  222. {
  223. if ($this->request->isPost() === false){
  224. $this->error('请求错误');
  225. }
  226. $param = Request::instance()->post();
  227. if (empty($param)){
  228. $this->error('参数错误');
  229. }
  230. $param['sys_rq'] = date('Y-m-d H:i:s',time());
  231. $res = db('设备_糊盒班组资料')->insert($param);
  232. if ($res === false){
  233. $this->error('新增失败');
  234. }else{
  235. $this->success('新增成功');
  236. }
  237. }
  238. /**
  239. * 修改设备糊盒班组资料
  240. * @return void
  241. * @throws \think\Exception
  242. * @throws \think\exception\PDOException
  243. */
  244. public function UpdateGluingClass()
  245. {
  246. if ($this->request->isPost() === false){
  247. $this->error('请求错误');
  248. }
  249. $param = Request::instance()->post();
  250. if (empty($param['id'])){
  251. $this->error('参数错误');
  252. }
  253. $id = intval($param['id']);
  254. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  255. unset($param['id']);
  256. $res = db('设备_糊盒班组资料')
  257. ->where('id',$id)
  258. ->update($param);
  259. if ($res === false){
  260. $this->error('修改失败');
  261. }else{
  262. $this->success('修改成功');
  263. }
  264. }
  265. /**
  266. * 糊盒机台报工
  267. * @return void
  268. * @throws \think\db\exception\BindParamException
  269. * @throws \think\exception\PDOException
  270. */
  271. public function AddGluingReportData()
  272. {
  273. if ($this->request->isPost() === false){
  274. $this->error('请求错误');
  275. }
  276. $param = Request::instance()->post();
  277. if (empty($param)){
  278. $this->error('参数错误');
  279. }
  280. $param['sys_rq'] = date('Y-m-d H:i:s',time());
  281. $Sql = db('设备_糊盒报工资料')->fetchSql(true)->insert($param);
  282. $res = db()->query($Sql);
  283. if ($res === false){
  284. $this->error('报工失败');
  285. }else{
  286. $this->success('报工成功');
  287. }
  288. }
  289. /**
  290. * 糊盒机台报工数据菜单
  291. * @return void
  292. * @throws \think\db\exception\DataNotFoundException
  293. * @throws \think\db\exception\ModelNotFoundException
  294. * @throws \think\exception\DbException
  295. */
  296. public function getTab()
  297. {
  298. if ($this->request->isGet() === false){
  299. $this->error('请求错误');
  300. }
  301. $data = [];
  302. $date = date('Y-m-d 00:00:00',time()-3888000);
  303. $sist = ['印后糊盒车间','精品自动化车间','数字化车间'];
  304. $department = \db('设备_基本资料')
  305. ->distinct(true)
  306. ->where('使用部门','in',$sist)
  307. ->where('设备编组','<>','')
  308. ->where('sys_sbID','<>','')
  309. ->order('设备编组')
  310. ->column('rtrim(使用部门) as 使用部门');
  311. if (empty($department)){
  312. $this->success('为获取到机台数据');
  313. }
  314. $list = \db('设备_糊盒报工资料')
  315. ->field([
  316. 'DISTINCT(sczl_rq)' => '时间',
  317. 'rtrim(sczl_jtbh)' => '机台编号'
  318. ])
  319. ->where('sczl_rq','>',$date)
  320. ->order('sczl_rq desc')
  321. ->select();
  322. if (empty($list)){
  323. $this->success('未找到机台生产记录');
  324. }
  325. foreach ($department as $value){
  326. $machine = \db('设备_基本资料')->where('使用部门',$value)->where('sys_sbID','<>','')->where('使用部门',$value)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->order('设备编号')->select();
  327. foreach ($machine as $k=>$v){
  328. $data[rtrim($value)][$v['设备编号'].'-->'.$v['设备名称']] = [];
  329. foreach ($list as $kk=>$vv){
  330. if ($v['设备编号'] === $vv['机台编号']){
  331. array_push($data[rtrim($value)][$v['设备编号'].'-->'.$v['设备名称']],date('Y-m-d',strtotime($vv['时间'])));
  332. }
  333. }
  334. }
  335. }
  336. $this->success('成功',$data);
  337. }
  338. /**
  339. * 获取当前生产工单
  340. * @return void
  341. * @throws \think\db\exception\DataNotFoundException
  342. * @throws \think\db\exception\ModelNotFoundException
  343. * @throws \think\exception\DbException
  344. */
  345. public function GetProduction()
  346. {
  347. if (Request::instance()->isGet() == false) {
  348. $this->error('非法请求');
  349. }
  350. $params = Request::instance()->param();
  351. if (!isset($params['machine']) || empty($params['machine'])) {
  352. $this->error('参数错误');
  353. }
  354. $machine = $params['machine'];
  355. $machineCode = \db('dic_lzde')->where('适用机型',$machine)->value('sys_bh');
  356. $data = \db('设备_糊盒报工采集')->where('sczl_jtbh',$machine)->order('UID desc')->find();
  357. $list = [];
  358. $list['班组ID'] = $data['班组ID'];
  359. $row = [];
  360. if (!empty($data['sczl_gdbh'])){
  361. $endTime = \db('工单_工艺资料')
  362. ->where('Gy0_gdbh',$data['sczl_gdbh'])
  363. ->where('Gy0_yjno',$data['sczl_yjno'])
  364. ->where('Gy0_gxh',$data['sczl_gxh'])
  365. ->find();
  366. $list['工单编号'] = $data['sczl_gdbh'];
  367. if (!empty($endTime)){
  368. $list['印件号'] = $data['sczl_yjno'];
  369. $name = \db('工单_基本资料')->where('Gd_Gdbh',$data['sczl_gdbh'])->value('成品名称');
  370. $code = \db('工单_基本资料')->where('Gd_Gdbh',$data['sczl_gdbh'])->value('成品代号');
  371. $list['产品名称'] = rtrim($name);
  372. $list['产品代号'] = rtrim($code);
  373. $list['工序名称'] = $data['sczl_gxh'];
  374. }
  375. $list['状态'] = rtrim($data['status']);
  376. $list['开工时间'] = $data['sczl_kgsj'];
  377. }else{
  378. $list['工单编号'] = '';
  379. $list['印件号'] = 0;
  380. $list['产品名称'] = '';
  381. $list['工序名称'] = '';
  382. $list['产品代号'] = '';
  383. $list['状态'] = '';
  384. $list['开工时间'] = '';
  385. }
  386. $list['班组编号'] = rtrim($data['sczl_bzbh']);
  387. $idList = explode(',',$data['班组ID']);
  388. foreach ($idList as $k=>$v){
  389. $class = \db('设备_糊盒班组资料')
  390. ->where('id',$v)
  391. ->field("role,rate,bh1,bh2,bh3,bh4,bh5,bh6,bh7,bh8,bh9,bh10,bh11,bh12,bh13,bh14,bh15")
  392. ->find();
  393. if (!empty($class)){
  394. for ($i=1;$i<16;$i++) {
  395. if ($class['bh' . $i] != '' && $class['bh' . $i] != '000000') {
  396. $name = \db('人事_基本资料')->where('员工编号', $class['bh' . $i])->field('rtrim(员工姓名) as 姓名')->find();
  397. $row[] = [
  398. '编号' => $class['bh' . $i],
  399. '姓名' => $name['姓名'],
  400. '比例' => $class['rate'],
  401. '角色' => $class['role'],
  402. ];
  403. }
  404. }
  405. $row = array_values($row);
  406. }
  407. }
  408. $list['班组成员'] = $row;
  409. $list['定额代号'] = $machineCode;
  410. $this->success('成功',$list);
  411. }
  412. /**
  413. * 设置当前工单和当前班组
  414. * @return void
  415. */
  416. public function setMachineTeam()
  417. {
  418. if (Request::instance()->isPost() == false) {
  419. $this->error('非法请求');
  420. }
  421. $params = Request::instance()->post();
  422. if (!isset($params['machine']) || empty($params['machine'] )) {
  423. $this->error('参数不能为空');
  424. }
  425. if (empty($params['team_id']) || empty($params['sczl_bzdh'])){
  426. $this->error('请先选择班组成员');
  427. }
  428. $machine = $params['machine'] . '#';
  429. $data = [];
  430. $data['status'] = $params['status'];
  431. $data['sczl_sj'] = date('Y-m-d H:i:s');
  432. $data['sczl_jtbh'] = $machine;
  433. $data['sczl_gdbh'] = empty($params['order']) ? '':$params['order'];
  434. $data['sczl_yjno'] = empty($params['yjno']) ? '':$params['yjno'];
  435. $data['sczl_gxh'] = empty($params['gy_name']) ? '' : (int)substr($params['gy_name'], 0, 2);
  436. $data['sczl_gxmc'] = empty($params['gy_name']) ? '' : $params['gy_name'];
  437. $data['sczl_bzbh'] = $params['sczl_bzdh'];
  438. $data['班组ID'] = $params['team_id'];
  439. // 获取当前时间
  440. $current_time = time();
  441. // 设置时间范围
  442. $start_time1 = strtotime(date('Y-m-d') . ' 08:30:00');
  443. $end_time1 = strtotime(date('Y-m-d') . ' 20:30:00');
  444. $end_time2 = strtotime(date('Y-m-d') . ' 24:00:00');
  445. $start_time3 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 08:30:00');
  446. $start_time4 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 00:00:00');
  447. // 判断当前时间属于哪个时间范围
  448. if ($current_time >= $start_time1 && $current_time <= $end_time1) {
  449. $data['sczl_kgsj'] = date('Y-m-d') . ' 08:30:00';
  450. } elseif ($current_time > $end_time1 && $current_time <= $end_time2) {
  451. $data['sczl_kgsj'] = date('Y-m-d') . ' 20:30:00';
  452. } elseif ($current_time > $end_time1 && $current_time <= $start_time3) {
  453. $data['sczl_kgsj'] = date('Y-m-d', strtotime('+1 day')) . ' 08:30:00';
  454. }elseif ($current_time > $start_time4 && $current_time <= $start_time3){
  455. $data['sczl_kgsj'] = date('Y-m-d') . ' 20:30:00';
  456. }
  457. if (!empty($params['order']) && !empty($params['yjno'])){
  458. $option['Gy0_gdbh'] = $params['order'];
  459. $option['Gy0_yjno'] = $params['yjno'];
  460. $option['Gy0_gxh'] = $data['sczl_gxh'];
  461. $data['任务ID'] = \db('工单_工艺资料')->where($option)->value('UniqId');
  462. }else{
  463. $data['任务ID'] = '';
  464. }
  465. $sql = \db('设备_糊盒报工采集')->fetchSql(true)->insert($data);
  466. $res = Db::query($sql);
  467. if ($res === false) {
  468. $this->error('设置失败');
  469. } else {
  470. $this->success('设置成功');
  471. }
  472. }
  473. //糊盒设备运行跟踪数据页面显示
  474. public function getGluingReportDataList()
  475. {
  476. if ($this->request->isGet() === false){
  477. $this->error('请求错误');
  478. }
  479. $params = $this->request->param();
  480. if (empty($params['machine']) || empty($params['day'])){
  481. $this->error('参数错误');
  482. }
  483. $where = [
  484. 'a.sczl_jtbh' => $params['machine'],
  485. 'a.sczl_rq' => ['like',$params['day'].'%']
  486. ];
  487. $field = ['a.sczl_gdbh as 工单编号','a.sczl_yjno as 印件号','a.sczl_gxh as 工序号','a.来料数量','a.sczl_cl as 产量',
  488. 'a.sczl_zcfp as 制程废品','a.startTime as 开始时间','a.endTime as 结束时间','a.sczl_ls as 联数','a.sczl_rq as 日期',
  489. 'a.sczl_dedh as 定额代号','a.工价系数','a.保养工时','a.装版工时','a.异常工时','a.异常类型','a.设备运行工时','a.role',
  490. 'a.sys_id as 创建人员','a.sys_rq as 上报时间','a.mod_rq as 修改时间','a.Uid','a.sczl_jtbh as 机台编号',
  491. 'b.yj_Yjdh as 产品代号','yj_yjmc as 产品名称'];
  492. $list = \db('设备_糊盒报工资料')
  493. ->alias('a')
  494. ->join('工单_印件资料 b','a.sczl_gdbh = b.Yj_Gdbh and a.sczl_yjno = b.yj_Yjno','left')
  495. ->field($field)
  496. ->where($where)
  497. ->group('a.Uid')
  498. ->select();
  499. if (empty($list)){
  500. $this->error('未找到报工数据');
  501. }
  502. foreach ($list as $key=>$value){
  503. $list[$key]['class'] = [];
  504. $idList = explode(',',$value['role']);
  505. foreach ($idList as $item){
  506. $class = \db('设备_糊盒班组资料')
  507. ->where('id',$item)
  508. ->field("role,rate,bh1,bh2,bh3,bh4,bh5,bh6,bh7,bh8,bh9,bh10,bh11,bh12,bh13,bh14,bh15")
  509. ->find();
  510. if (!empty($class)){
  511. for ($i=1;$i<16;$i++) {
  512. if ($class['bh' . $i] != '' && $class['bh' . $i] != '000000') {
  513. $name = \db('人事_基本资料')->where('员工编号', $class['bh' . $i])->field('rtrim(员工姓名) as 姓名')->find();
  514. $list[$key]['class'][] = [
  515. '编号' => $class['bh' . $i],
  516. '姓名' => $name['姓名'],
  517. '比例' => $class['rate'],
  518. '角色' => $class['role'],
  519. ];
  520. }
  521. }
  522. $list[$key]['class'] = array_values($list[$key]['class']);
  523. }
  524. }
  525. unset($list[$key]['role']);
  526. }
  527. $this->success('成功',$list);
  528. }
  529. }