GluingReport.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  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. if (empty($list)){
  174. $this->error('未找到数据');
  175. }else{
  176. $this->success('成功',$list);
  177. }
  178. }
  179. /**
  180. * 获取设备角色数据
  181. * @return void
  182. * @throws \think\db\exception\DataNotFoundException
  183. * @throws \think\db\exception\ModelNotFoundException
  184. * @throws \think\exception\DbException
  185. */
  186. public function getGluingcole()
  187. {
  188. if ($this->request->isGet() === false){
  189. $this->error('请求错误');
  190. }
  191. $param = $this->request->param();
  192. if (empty($param)){
  193. $this->error('参数错误');
  194. }
  195. $list = db('设备_糊盒班组角色')
  196. ->where('jtbh',$param['machine'])
  197. ->where('status',1)
  198. ->find();
  199. if (empty($list)){
  200. $this->error('未找到角色资料');
  201. }else{
  202. $this->success('成功',$list);
  203. }
  204. }
  205. /**
  206. * 新增糊盒机台班组资料
  207. * @return void
  208. */
  209. public function AddGluingClass()
  210. {
  211. if ($this->request->isPost() === false){
  212. $this->error('请求错误');
  213. }
  214. $param = Request::instance()->post();
  215. if (empty($param)){
  216. $this->error('参数错误');
  217. }
  218. $param['sys_rq'] = date('Y-m-d H:i:s',time());
  219. $res = db('设备_糊盒班组资料')->insert($param);
  220. if ($res === false){
  221. $this->error('新增失败');
  222. }else{
  223. $this->success('新增失败');
  224. }
  225. }
  226. /**
  227. * 修改设备糊盒班组资料
  228. * @return void
  229. * @throws \think\Exception
  230. * @throws \think\exception\PDOException
  231. */
  232. public function UpdateGluingClass()
  233. {
  234. if ($this->request->isPost() === false){
  235. $this->error('请求错误');
  236. }
  237. $param = Request::instance()->post();
  238. if (empty($param['id'])){
  239. $this->error('参数错误');
  240. }
  241. $id = intval($param['id']);
  242. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  243. unset($param['id']);
  244. $res = db('设备_糊盒班组资料')
  245. ->where('id',$id)
  246. ->update($param);
  247. if ($res === false){
  248. $this->error('修改成功');
  249. }else{
  250. $this->success('修改失败');
  251. }
  252. }
  253. /**
  254. * 糊盒机台报工
  255. * @return void
  256. * @throws \think\db\exception\BindParamException
  257. * @throws \think\exception\PDOException
  258. */
  259. public function AddGluingReportData()
  260. {
  261. if ($this->request->isPost() === false){
  262. $this->error('请求错误');
  263. }
  264. $param = Request::instance()->post();
  265. if (empty($param)){
  266. $this->error('参数错误');
  267. }
  268. $param['sys_rq'] = date('Y-m-d H:i:s',time());
  269. $Sql = db('设备_糊盒报工资料')->fetchSql(true)->insert($param);
  270. $res = db()->query($Sql);
  271. if ($res === false){
  272. $this->error('报工失败');
  273. }else{
  274. $this->success('报工成功');
  275. }
  276. }
  277. /**
  278. * 糊盒机台报工数据菜单
  279. * @return void
  280. * @throws \think\db\exception\DataNotFoundException
  281. * @throws \think\db\exception\ModelNotFoundException
  282. * @throws \think\exception\DbException
  283. */
  284. public function getTab()
  285. {
  286. if ($this->request->isGet() === false){
  287. $this->error('请求错误');
  288. }
  289. $data = [];
  290. $date = date('Y-m-d 00:00:00',time()-3888000);
  291. $sist = ['印后糊盒车间','精品自动化车间','数字化车间'];
  292. $department = \db('设备_基本资料')
  293. ->distinct(true)
  294. ->where('使用部门','in',$sist)
  295. ->where('设备编组','<>','')
  296. ->where('sys_sbID','<>','')
  297. ->order('设备编组')
  298. ->column('rtrim(使用部门) as 使用部门');
  299. if (empty($department)){
  300. $this->success('为获取到机台数据');
  301. }
  302. $list = \db('设备_糊盒报工资料')
  303. ->field([
  304. 'DISTINCT(sczl_rq)' => '时间',
  305. 'rtrim(sczl_jtbh)' => '机台编号'
  306. ])
  307. ->where('sczl_rq','>',$date)
  308. ->order('sczl_rq desc')
  309. ->select();
  310. if (empty($list)){
  311. $this->success('未找到机台生产记录');
  312. }
  313. foreach ($department as $value){
  314. $machine = \db('设备_基本资料')->where('使用部门',$value)->where('sys_sbID','<>','')->where('使用部门',$value)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->order('设备编号')->select();
  315. foreach ($machine as $k=>$v){
  316. $data[rtrim($value)][$v['设备编号'].'-->'.$v['设备名称']] = [];
  317. foreach ($list as $kk=>$vv){
  318. if ($v['设备编号'] === $vv['机台编号']){
  319. array_push($data[rtrim($value)][$v['设备编号'].'-->'.$v['设备名称']],date('Y-m-d',strtotime($vv['时间'])));
  320. }
  321. }
  322. }
  323. }
  324. $this->success('成功',$data);
  325. }
  326. // public function gitGluingReportList()
  327. // {
  328. // if ($this->request->isGet() === false){
  329. // $this->error('请求错误');
  330. // }
  331. // $param = $this->request->param();
  332. // if (empty($param)){
  333. // $this->error('参数错误');
  334. // }
  335. // $where = [
  336. // 'a.sczl_jtbh' => $param['machine'],
  337. // 'a.sys_rq' => $param['date'],
  338. // ];
  339. // $list = \db('设备_糊盒报工资料')
  340. // ->alias('a')
  341. // ->join('工单_基本资料 b','a.sczl_gdbh = b.Gd_gdbh')
  342. // ->join('设备_糊盒班组资料 c','a. = c.Gd_gdbh')
  343. // }
  344. public function GetProduction()
  345. {
  346. if (Request::instance()->isGet() == false) {
  347. $this->error('非法请求');
  348. }
  349. $params = Request::instance()->param();
  350. if (!isset($params['machine']) || empty($params['machine'])) {
  351. $this->error('参数错误');
  352. }
  353. $machine = $params['machine'];
  354. $machineCode = \db('dic_lzde')->where('适用机型',$machine)->value('sys_bh');
  355. $data = \db('设备_产量采集')->where('设备编号',$machine)->order('UniqId desc')->find();
  356. $list = [];
  357. $row = [];
  358. if (!empty($data['工单编号'])){
  359. $endTime = \db('工单_工艺资料')
  360. ->where('Gy0_gdbh',$data['工单编号'])
  361. ->where('Gy0_yjno',$data['印件号'])
  362. ->where('Gy0_gxh',$data['工序号'])
  363. ->find();
  364. $list['工单编号'] = $data['工单编号'];
  365. if (!empty($endTime)){
  366. $list['印件号'] = $data['印件号'];
  367. $name = \db('工单_基本资料')->where('Gd_Gdbh',$data['工单编号'])->value('成品名称');
  368. $code = \db('工单_基本资料')->where('Gd_Gdbh',$data['工单编号'])->value('成品代号');
  369. $list['产品名称'] = rtrim($name);
  370. $list['产品代号'] = rtrim($code);
  371. $list['工序名称'] = $data['工序名称'];
  372. }
  373. $list['状态'] = rtrim($data['当前状态']);
  374. $list['开工时间'] = $data['开工时间'];
  375. }else{
  376. $list['工单编号'] = '';
  377. $list['印件号'] = 0;
  378. $list['产品名称'] = '';
  379. $list['工序名称'] = '';
  380. $list['产品代号'] = '';
  381. $list['状态'] = '';
  382. $list['开工时间'] = '';
  383. }
  384. $list['班组编号'] = rtrim($data['班组编号']);
  385. $list['班组Id'] = rtrim($data['班组ID']);
  386. $class = \db('设备_班组资料')->where('UniqId',$data['班组ID'])->field("rtrim(sczl_bh1) as bh1,rtrim(sczl_bh2) as bh2,rtrim(sczl_bh3) as bh3,rtrim(sczl_bh4) as bh4,
  387. rtrim(sczl_bh5) as bh5,rtrim(sczl_bh6) as bh6,rtrim(sczl_bh7) as bh7,rtrim(sczl_bh8) as bh8,rtrim(sczl_bh9) as bh9,
  388. rtrim(sczl_bh10) as bh10")->find();
  389. if (!empty($class)){
  390. for ($i=1;$i<11;$i++) {
  391. if ($class['bh' . $i] != '' && $class['bh' . $i] != '000000') {
  392. $name = \db('人事_基本资料')->where('员工编号', $class['bh' . $i])->field('rtrim(员工姓名) as 姓名')->find();
  393. $row[$i] = [
  394. '编号' => $class['bh' . $i],
  395. '姓名' => $name['姓名']
  396. ];
  397. }
  398. }
  399. $row = array_values($row);
  400. }
  401. $list['班组成员'] = $row;
  402. $list['定额代号'] = $machineCode;
  403. $this->success('成功',$list);
  404. }
  405. public function setMachineTeam()
  406. {
  407. if (Request::instance()->isPost() == false) {
  408. $this->error('非法请求');
  409. }
  410. $params = Request::instance()->post();
  411. if (!isset($params['machine']) || empty($params['machine'] )) {
  412. $this->error('参数不能为空');
  413. }
  414. if (empty($params['team_id']) || empty($params['sczl_bzdh'])){
  415. $this->error('请先选择班组成员');
  416. }
  417. $machine = $params['machine'] . '#';
  418. $data = [];
  419. $lastData = \db('设备_产量采集')
  420. ->order('UniqId desc')
  421. ->find();
  422. $id = $lastData['UniqId']+1;
  423. $data['当前状态'] = $params['status'];
  424. $data['时间'] = date('Y-m-d H:i:s');
  425. $data['设备编号'] = $machine;
  426. $data['工单编号'] = empty($params['order']) ? '':$params['order'];
  427. $data['印件号'] = empty($params['yjno']) ? '':$params['yjno'];
  428. $data['工序号'] = empty($params['gy_name']) ? '' : (int)substr($params['gy_name'], 0, 2);
  429. $data['工序名称'] = empty($params['gy_name']) ? '' : $params['gy_name'];
  430. $data['当班产量'] = $params['production_now'];
  431. $data['累计产量'] = $params['production_all'];
  432. $data['班组编号'] = $params['sczl_bzdh'];
  433. $data['班组ID'] = $params['team_id'];
  434. // 获取当前时间
  435. $current_time = time();
  436. // 设置时间范围
  437. $start_time1 = strtotime(date('Y-m-d') . ' 08:30:00');
  438. $end_time1 = strtotime(date('Y-m-d') . ' 20:30:00');
  439. $end_time2 = strtotime(date('Y-m-d') . ' 24:00:00');
  440. $start_time3 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 08:30:00');
  441. $start_time4 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 00:00:00');
  442. // 判断当前时间属于哪个时间范围
  443. if ($current_time >= $start_time1 && $current_time <= $end_time1) {
  444. $data['开工时间'] = date('Y-m-d') . ' 08:30:00';
  445. } elseif ($current_time > $end_time1 && $current_time <= $end_time2) {
  446. $data['开工时间'] = date('Y-m-d') . ' 20:30:00';
  447. } elseif ($current_time > $end_time1 && $current_time <= $start_time3) {
  448. $data['开工时间'] = date('Y-m-d', strtotime('+1 day')) . ' 08:30:00';
  449. }elseif ($current_time > $start_time4 && $current_time <= $start_time3){
  450. $data['开工时间'] = date('Y-m-d') . ' 20:30:00';
  451. }
  452. if (!empty($params['order']) && !empty($params['yjno'])){
  453. $option['Gy0_gdbh'] = $params['order'];
  454. $option['Gy0_yjno'] = $params['yjno'];
  455. $option['Gy0_gxh'] = $data['工序号'];
  456. $data['任务ID'] = \db('工单_工艺资料')->where($option)->value('UniqId');
  457. }else{
  458. $data['任务ID'] = '';
  459. }
  460. $data['UniqId'] = $id;
  461. $sql = \db('设备_产量采集')->fetchSql(true)->insert($data);
  462. $res = Db::query($sql);
  463. if ($res === false) {
  464. $this->error('设置失败');
  465. } else {
  466. $this->success('设置成功');
  467. }
  468. }
  469. }