GluingReport.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  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. /**
  327. * 获取当前生产工单
  328. * @return void
  329. * @throws \think\db\exception\DataNotFoundException
  330. * @throws \think\db\exception\ModelNotFoundException
  331. * @throws \think\exception\DbException
  332. */
  333. public function GetProduction()
  334. {
  335. if (Request::instance()->isGet() == false) {
  336. $this->error('非法请求');
  337. }
  338. $params = Request::instance()->param();
  339. if (!isset($params['machine']) || empty($params['machine'])) {
  340. $this->error('参数错误');
  341. }
  342. $machine = $params['machine'];
  343. $machineCode = \db('dic_lzde')->where('适用机型',$machine)->value('sys_bh');
  344. $data = \db('设备_糊盒报工采集')->where('sczl_jtbh',$machine)->order('UID desc')->find();
  345. $list = [];
  346. $row = [];
  347. if (!empty($data['工单编号'])){
  348. $endTime = \db('工单_工艺资料')
  349. ->where('Gy0_gdbh',$data['工单编号'])
  350. ->where('Gy0_yjno',$data['印件号'])
  351. ->where('Gy0_gxh',$data['工序号'])
  352. ->find();
  353. $list['工单编号'] = $data['工单编号'];
  354. if (!empty($endTime)){
  355. $list['印件号'] = $data['印件号'];
  356. $name = \db('工单_基本资料')->where('Gd_Gdbh',$data['工单编号'])->value('成品名称');
  357. $code = \db('工单_基本资料')->where('Gd_Gdbh',$data['工单编号'])->value('成品代号');
  358. $list['产品名称'] = rtrim($name);
  359. $list['产品代号'] = rtrim($code);
  360. $list['工序名称'] = $data['工序名称'];
  361. }
  362. $list['状态'] = rtrim($data['当前状态']);
  363. $list['开工时间'] = $data['开工时间'];
  364. }else{
  365. $list['工单编号'] = '';
  366. $list['印件号'] = 0;
  367. $list['产品名称'] = '';
  368. $list['工序名称'] = '';
  369. $list['产品代号'] = '';
  370. $list['状态'] = '';
  371. $list['开工时间'] = '';
  372. }
  373. $list['班组编号'] = rtrim($data['sczl_bzbh']);
  374. $idList = explode(',',$data['班组ID']);
  375. foreach ($idList as $k=>$v){
  376. $class = \db('设备_糊盒班组资料')
  377. ->where('id',$v)
  378. ->field("role,rate,bh1,bh2,bh3,bh4,bh5,bh6,bh7,bh8,bh9,bh10,bh11,bh12,bh13,bh14,bh15")
  379. ->find();
  380. if (!empty($class)){
  381. for ($i=1;$i<16;$i++) {
  382. if ($class['bh' . $i] != '' && $class['bh' . $i] != '000000') {
  383. $name = \db('人事_基本资料')->where('员工编号', $class['bh' . $i])->field('rtrim(员工姓名) as 姓名')->find();
  384. $row[$i] = [
  385. '编号' => $class['bh' . $i],
  386. '姓名' => $name['姓名'],
  387. '比例' => $class['rate'],
  388. '角色' => $class['role'],
  389. ];
  390. }
  391. }
  392. $row = array_values($row);
  393. }
  394. }
  395. $list['班组成员'] = $row;
  396. $list['定额代号'] = $machineCode;
  397. $this->success('成功',$list);
  398. }
  399. /**
  400. * 设置当前工单和当前班组
  401. * @return void
  402. */
  403. public function setMachineTeam()
  404. {
  405. if (Request::instance()->isPost() == false) {
  406. $this->error('非法请求');
  407. }
  408. $params = Request::instance()->post();
  409. if (!isset($params['machine']) || empty($params['machine'] )) {
  410. $this->error('参数不能为空');
  411. }
  412. if (empty($params['team_id']) || empty($params['sczl_bzdh'])){
  413. $this->error('请先选择班组成员');
  414. }
  415. $machine = $params['machine'] . '#';
  416. $data = [];
  417. $data['status'] = $params['status'];
  418. $data['sczl_sj'] = date('Y-m-d H:i:s');
  419. $data['sczl_jtbh'] = $machine;
  420. $data['sczl_gdbh'] = empty($params['order']) ? '':$params['order'];
  421. $data['sczl_yjno'] = empty($params['yjno']) ? '':$params['yjno'];
  422. $data['sczl_gxh'] = empty($params['gy_name']) ? '' : (int)substr($params['gy_name'], 0, 2);
  423. $data['sczl_gxmc'] = empty($params['gy_name']) ? '' : $params['gy_name'];
  424. $data['sczl_bzbh'] = $params['sczl_bzdh'];
  425. $data['班组ID'] = $params['team_id'];
  426. // 获取当前时间
  427. $current_time = time();
  428. // 设置时间范围
  429. $start_time1 = strtotime(date('Y-m-d') . ' 08:30:00');
  430. $end_time1 = strtotime(date('Y-m-d') . ' 20:30:00');
  431. $end_time2 = strtotime(date('Y-m-d') . ' 24:00:00');
  432. $start_time3 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 08:30:00');
  433. $start_time4 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 00:00:00');
  434. // 判断当前时间属于哪个时间范围
  435. if ($current_time >= $start_time1 && $current_time <= $end_time1) {
  436. $data['sczl_kgsj'] = date('Y-m-d') . ' 08:30:00';
  437. } elseif ($current_time > $end_time1 && $current_time <= $end_time2) {
  438. $data['sczl_kgsj'] = date('Y-m-d') . ' 20:30:00';
  439. } elseif ($current_time > $end_time1 && $current_time <= $start_time3) {
  440. $data['sczl_kgsj'] = date('Y-m-d', strtotime('+1 day')) . ' 08:30:00';
  441. }elseif ($current_time > $start_time4 && $current_time <= $start_time3){
  442. $data['sczl_kgsj'] = date('Y-m-d') . ' 20:30:00';
  443. }
  444. if (!empty($params['order']) && !empty($params['yjno'])){
  445. $option['Gy0_gdbh'] = $params['order'];
  446. $option['Gy0_yjno'] = $params['yjno'];
  447. $option['Gy0_gxh'] = $data['工序号'];
  448. $data['任务ID'] = \db('工单_工艺资料')->where($option)->value('UniqId');
  449. }else{
  450. $data['任务ID'] = '';
  451. }
  452. $sql = \db('设备_糊盒报工采集')->fetchSql(true)->insert($data);
  453. $res = Db::query($sql);
  454. if ($res === false) {
  455. $this->error('设置失败');
  456. } else {
  457. $this->success('设置成功');
  458. }
  459. }
  460. }