GluingReport.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  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. $data = [];
  20. $sist = ['印后糊盒车间','精品自动化车间','数字化车间'];
  21. $department = \db('设备_基本资料')
  22. ->distinct(true)
  23. ->where('使用部门','in',$sist)
  24. ->where('设备编组','<>','')
  25. ->where('sys_sbID','<>','')
  26. ->order('设备编组')
  27. ->column('rtrim(使用部门) as 使用部门');
  28. if (empty($department)){
  29. $this->success('为获取到机台数据');
  30. }
  31. foreach ($department as $value){
  32. $machine = \db('设备_基本资料')->where('使用部门',$value)->where('sys_sbID','<>','')->where('使用部门',$value)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->order('设备编号')->select();
  33. foreach ($machine as $k=>$v){
  34. $data[rtrim($value)][] = $v['设备编号'].'-->'.$v['设备名称'];
  35. }
  36. }
  37. $this->success('成功',$data);
  38. }
  39. /**
  40. * 设备角色列表
  41. * @return void
  42. * @throws \think\db\exception\DataNotFoundException
  43. * @throws \think\db\exception\ModelNotFoundException
  44. * @throws \think\exception\DbException
  45. */
  46. public function getGluingcoleList()
  47. {
  48. if ($this->request->isGet() === false){
  49. $this->error('请求错误');
  50. }
  51. $param = $this->request->param();
  52. if (empty($param)){
  53. $this->error('参数错误');
  54. }
  55. $list = db('设备_糊盒班组角色')
  56. ->where('jtbh',$param['machine'])
  57. ->select();
  58. if (empty($list)){
  59. $this->error('未找到数据');
  60. }else{
  61. $this->success('成功',$list);
  62. }
  63. }
  64. /**
  65. * 设备角色资料详情
  66. * @return void
  67. * @throws \think\db\exception\DataNotFoundException
  68. * @throws \think\db\exception\ModelNotFoundException
  69. * @throws \think\exception\DbException
  70. */
  71. public function getGluingcoleDetail()
  72. {
  73. if ($this->request->isGet() === false){
  74. $this->error('请求错误');
  75. }
  76. $param = $this->request->param();
  77. if (empty($param)){
  78. $this->error('参数错误');
  79. }
  80. $list = db('设备_糊盒班组角色')
  81. ->where('id',$param['id'])
  82. ->find();
  83. if (empty($list)){
  84. $this->error('未找到数据详情');
  85. }else{
  86. $this->success('成功',$list);
  87. }
  88. }
  89. /**
  90. * 新增机台班组角色
  91. * @return void
  92. */
  93. public function saveGluingcoleDetail(){
  94. if ($this->request->isPost() === false){
  95. $this->error('请求错误');
  96. }
  97. $param = Request::instance()->post();
  98. if (empty($param)){
  99. $this->error('参数错误');
  100. }
  101. $param['sys_rq'] = date('Y-m-d H:i:s',time());
  102. $res = db('设备_糊盒班组角色')->insert($param);
  103. if (empty($res)){
  104. $this->error('新增失败');
  105. }else{
  106. $this->success('新增成功');
  107. }
  108. }
  109. /**
  110. * 修改设备角色资料
  111. * @return void
  112. * @throws \think\Exception
  113. * @throws \think\exception\PDOException
  114. */
  115. public function getGluingcoleDetaiEdit()
  116. {
  117. if ($this->request->isPost() === false){
  118. $this->error('请求错误');
  119. }
  120. $param = Request::instance()->post();
  121. if (empty($param['id'])){
  122. $this->error('参数错误');
  123. }
  124. $id = intval($param['id']);
  125. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  126. unset($param['id']);
  127. $res = db('设备_糊盒班组角色')
  128. ->where('id',$id)
  129. ->update($param);
  130. if ($res === false){
  131. $this->error('修改失败');
  132. }else{
  133. $this->success('修改成功');
  134. }
  135. }
  136. /**
  137. * 设备当前班组角色
  138. * @return void
  139. * @throws \think\Exception
  140. * @throws \think\exception\PDOException
  141. */
  142. public function UpdateGluingcoleStatus()
  143. {
  144. if ($this->request->isGet() === false){
  145. $this->error('请求错误');
  146. }
  147. $param = $this->request->param();
  148. if (empty($param['id']) || empty($param['jtbh'])){
  149. $this->error('参数错误');
  150. }
  151. $updateRes = db('设备_糊盒班组角色')
  152. ->where('jtbh',$param['jtbh'])
  153. ->update(['status' => 0]);
  154. $res = db('设备_糊盒班组角色')
  155. ->where('id',$param['id'])
  156. ->update(['status' => 1]);
  157. if ($updateRes === false || $res === false){
  158. $this->error('更新失败');
  159. }else{
  160. $this->success('更新成功');
  161. }
  162. }
  163. /**
  164. * 设备班组资料列表
  165. * @return void
  166. * @throws \think\db\exception\DataNotFoundException
  167. * @throws \think\db\exception\ModelNotFoundException
  168. * @throws \think\exception\DbException
  169. */
  170. public function getGluingClassLList()
  171. {
  172. if ($this->request->isGet() === false){
  173. $this->error('请求错误');
  174. }
  175. $param = $this->request->param();
  176. if (empty($param)){
  177. $this->error('参数错误');
  178. }
  179. $list = db('设备_糊盒班组资料')
  180. ->where('jtbh',$param['machine'])
  181. ->select();
  182. foreach ($list as $k=>$v){
  183. for ($i = 1; $i <= 15; $i++){
  184. $bh = $v['bh'.$i];
  185. $list[$k]['name'.$i] = '';
  186. if (!empty($bh) && $bh !== ''){
  187. $name = \db('人事_基本资料')
  188. ->where('员工编号',$bh)
  189. ->value('员工姓名');
  190. $list[$k]['name'.$i] = $name;
  191. }
  192. }
  193. }
  194. if (empty($list)){
  195. $this->error('未找到数据');
  196. }else{
  197. $this->success('成功',$list);
  198. }
  199. }
  200. /**
  201. * 获取设备角色数据
  202. * @return void
  203. * @throws \think\db\exception\DataNotFoundException
  204. * @throws \think\db\exception\ModelNotFoundException
  205. * @throws \think\exception\DbException
  206. */
  207. public function getGluingcole()
  208. {
  209. if ($this->request->isGet() === false){
  210. $this->error('请求错误');
  211. }
  212. $param = $this->request->param();
  213. if (empty($param)){
  214. $this->error('参数错误');
  215. }
  216. $list = db('设备_糊盒班组角色')
  217. ->where('jtbh',$param['machine'])
  218. ->where('status',1)
  219. ->find();
  220. if (empty($list)){
  221. $this->error('未找到角色资料');
  222. }else{
  223. $this->success('成功',$list);
  224. }
  225. }
  226. /**
  227. * 新增糊盒机台班组资料
  228. * @return void
  229. */
  230. public function AddGluingClass()
  231. {
  232. if ($this->request->isPost() === false){
  233. $this->error('请求错误');
  234. }
  235. $param = Request::instance()->post();
  236. if (empty($param)){
  237. $this->error('参数错误');
  238. }
  239. $param['sys_rq'] = date('Y-m-d H:i:s',time());
  240. $res = db('设备_糊盒班组资料')->insert($param);
  241. if ($res === false){
  242. $this->error('新增失败');
  243. }else{
  244. $this->success('新增成功');
  245. }
  246. }
  247. /**
  248. * 修改设备糊盒班组资料
  249. * @return void
  250. * @throws \think\Exception
  251. * @throws \think\exception\PDOException
  252. */
  253. public function UpdateGluingClass()
  254. {
  255. if ($this->request->isPost() === false){
  256. $this->error('请求错误');
  257. }
  258. $param = Request::instance()->post();
  259. if (empty($param['id'])){
  260. $this->error('参数错误');
  261. }
  262. $id = intval($param['id']);
  263. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  264. unset($param['id']);
  265. $res = db('设备_糊盒班组资料')
  266. ->where('id',$id)
  267. ->update($param);
  268. if ($res === false){
  269. $this->error('修改失败');
  270. }else{
  271. $this->success('修改成功');
  272. }
  273. }
  274. /**
  275. * 糊盒机台报工
  276. * @return void
  277. * @throws \think\db\exception\BindParamException
  278. * @throws \think\exception\PDOException
  279. */
  280. public function addGluingReportData()
  281. {
  282. // 1. 请求验证
  283. if (!$this->request->isPost()) {
  284. $this->error('请求错误');
  285. }
  286. // 2. 参数验证
  287. $param = $this->request->post();
  288. if (empty($param)) {
  289. $this->error('参数错误');
  290. }
  291. // 3. 使用事务确保数据一致性
  292. Db::startTrans();
  293. try {
  294. // 准备数据
  295. $currentTime = date('Y-m-d H:i:s');
  296. // 构建班组数据
  297. $classData = [
  298. 'sys_rq' => $currentTime,
  299. 'jtbh' => $param['sczl_jtbh'] ?? '',
  300. 'gdbh' => $param['sczl_gdbh'] ?? '',
  301. 'gxmc' => $param['sczl_gxmc'] ?? '',
  302. 'sys_id' => $param['sys_id'] ?? '',
  303. 'sczl_rq' => $param['sczl_rq'] ?? '',
  304. ];
  305. // 处理动态字段
  306. for ($i = 1; $i <= 30; $i++) {
  307. $classData['bh'.$i] = $param['bh'.$i] ?? '';
  308. $classData['rate'.$i] = $param['rate'.$i] ?? '';
  309. unset($param['bh'.$i], $param['rate'.$i]);
  310. }
  311. // 保存班组数据
  312. $classId = \db('糊盒报工班组')->insertGetId($classData);
  313. if (!$classId) {
  314. throw new \Exception('保存班组数据失败');
  315. }
  316. // 保存设备数据
  317. unset($param['sczl_jtbh'], $param['sczl_gdbh'], $param['sczl_gxmc']);
  318. $param['role'] = $classId;
  319. $param['sys_rq'] = $currentTime;
  320. $sql = \db('设备_糊盒报工资料')->fetchSql(true)->insert($param);
  321. $result = db()->query($sql);
  322. if (!$result) {
  323. throw new \Exception('保存设备数据失败');
  324. }
  325. Db::commit();
  326. $this->success('报工成功');
  327. } catch (\Exception $e) {
  328. Db::rollback();
  329. $this->error($e->getMessage() ?: '报工失败');
  330. }
  331. }
  332. /**
  333. * 糊盒机台报工数据菜单
  334. * @return void
  335. * @throws \think\db\exception\DataNotFoundException
  336. * @throws \think\db\exception\ModelNotFoundException
  337. * @throws \think\exception\DbException
  338. */
  339. public function getTab()
  340. {
  341. if ($this->request->isGet() === false){
  342. $this->error('请求错误');
  343. }
  344. $data = [];
  345. $date = date('Y-m-d 00:00:00',time()-3888000);
  346. $sist = ['印后糊盒车间','精品自动化车间','数字化车间'];
  347. $department = \db('设备_基本资料')
  348. ->distinct(true)
  349. ->where('使用部门','in',$sist)
  350. ->where('设备编组','<>','')
  351. ->where('sys_sbID','<>','')
  352. ->order('设备编组')
  353. ->column('rtrim(使用部门) as 使用部门');
  354. if (empty($department)){
  355. $this->success('未获取到机台数据');
  356. }
  357. $list = \db('设备_糊盒报工资料')
  358. ->field([
  359. 'DISTINCT(sczl_rq)' => '时间',
  360. 'rtrim(sczl_jtbh)' => '机台编号'
  361. ])
  362. ->where('sczl_rq','>',$date)
  363. ->order('sczl_rq desc')
  364. ->select();
  365. foreach ($department as $value){
  366. $machine = \db('设备_基本资料')->where('使用部门',$value)->where('sys_sbID','<>','')->where('使用部门',$value)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->order('设备编号')->select();
  367. foreach ($machine as $k=>$v){
  368. $data[rtrim($value)][$v['设备编号'].'-->'.$v['设备名称']] = [];
  369. foreach ($list as $kk=>$vv){
  370. if ($v['设备编号'] === $vv['机台编号']){
  371. array_push($data[rtrim($value)][$v['设备编号'].'-->'.$v['设备名称']],date('Y-m-d',strtotime($vv['时间'])));
  372. }
  373. }
  374. }
  375. }
  376. $this->success('成功',$data);
  377. }
  378. /**
  379. * 获取当前生产工单
  380. * @return void
  381. * @throws \think\db\exception\DataNotFoundException
  382. * @throws \think\db\exception\ModelNotFoundException
  383. * @throws \think\exception\DbException
  384. */
  385. public function GetProduction()
  386. {
  387. if (Request::instance()->isGet() == false) {
  388. $this->error('非法请求');
  389. }
  390. $params = Request::instance()->param();
  391. if (!isset($params['machine']) || empty($params['machine'])) {
  392. $this->error('参数错误');
  393. }
  394. $machine = $params['machine'];
  395. $machineCode = \db('dic_lzde')->where('适用机型',$machine)->value('sys_bh');
  396. $data = \db('设备_糊盒报工采集')->where('sczl_jtbh',$machine)->order('UID desc')->find();
  397. if (empty($data)){
  398. $this->success('未找到数据');
  399. }
  400. $list = [];
  401. $list['班组ID'] = $data['班组ID'];
  402. $row = [];
  403. if (!empty($data['sczl_gdbh'])){
  404. $endTime = \db('工单_工艺资料')
  405. ->where('Gy0_gdbh',$data['sczl_gdbh'])
  406. ->where('Gy0_yjno',$data['sczl_yjno'])
  407. ->where('Gy0_gxh',$data['sczl_gxh'])
  408. ->find();
  409. $list['工单编号'] = $data['sczl_gdbh'];
  410. if (!empty($endTime)){
  411. $list['印件号'] = $data['sczl_yjno'];
  412. $name = \db('工单_基本资料')->where('Gd_Gdbh',$data['sczl_gdbh'])->value('成品名称');
  413. $code = \db('工单_基本资料')->where('Gd_Gdbh',$data['sczl_gdbh'])->value('成品代号');
  414. $list['产品名称'] = rtrim($name);
  415. $list['产品代号'] = rtrim($code);
  416. $list['工序名称'] = $data['sczl_gxmc'];
  417. $list['联数'] = $endTime['Gy0_ls'];
  418. }
  419. $list['状态'] = rtrim($data['status']);
  420. $list['开工时间'] = $data['sczl_kgsj'];
  421. }else{
  422. $list['工单编号'] = '';
  423. $list['印件号'] = 0;
  424. $list['产品名称'] = '';
  425. $list['工序名称'] = '';
  426. $list['产品代号'] = '';
  427. $list['状态'] = '';
  428. $list['开工时间'] = '';
  429. $list['联数'] = '';
  430. }
  431. $list['班组编号'] = rtrim($data['sczl_bzbh']);
  432. $idList = explode(',',$data['班组ID']);
  433. foreach ($idList as $k=>$v){
  434. $class = \db('设备_糊盒班组资料')
  435. ->where('id',$v)
  436. ->field("role,rate,bh1,bh2,bh3,bh4,bh5,bh6,bh7,bh8,bh9,bh10,bh11,bh12,bh13,bh14,bh15")
  437. ->find();
  438. if (!empty($class)){
  439. for ($i=1;$i<16;$i++) {
  440. if ($class['bh' . $i] != '' && $class['bh' . $i] != '000000') {
  441. $name = \db('人事_基本资料')->where('员工编号', $class['bh' . $i])->field('rtrim(员工姓名) as 姓名')->find();
  442. $row[] = [
  443. '编号' => $class['bh' . $i],
  444. '姓名' => $name['姓名'],
  445. '比例' => $class['rate'],
  446. '角色' => $class['role'],
  447. ];
  448. }
  449. }
  450. $row = array_values($row);
  451. }
  452. }
  453. $list['班组成员'] = $row;
  454. $list['定额代号'] = $machineCode;
  455. $this->success('成功',$list);
  456. }
  457. /**
  458. * 设置当前工单和当前班组
  459. * @return void
  460. */
  461. public function setMachineTeam()
  462. {
  463. if (Request::instance()->isPost() == false) {
  464. $this->error('非法请求');
  465. }
  466. $params = Request::instance()->post();
  467. if (!isset($params['machine']) || empty($params['machine'] )) {
  468. $this->error('参数不能为空');
  469. }
  470. if (empty($params['team_id']) || empty($params['sczl_bzdh'])){
  471. $this->error('请先选择班组成员');
  472. }
  473. $machine = $params['machine'] . '#';
  474. $data = [];
  475. $data['status'] = $params['status'];
  476. $data['sczl_sj'] = date('Y-m-d H:i:s');
  477. $data['sczl_jtbh'] = $machine;
  478. $data['sczl_gdbh'] = empty($params['order']) ? '':$params['order'];
  479. $data['sczl_yjno'] = empty($params['yjno']) ? '':$params['yjno'];
  480. $data['sczl_gxh'] = empty($params['gy_name']) ? '' : (int)substr($params['gy_name'], 0, 2);
  481. $data['sczl_gxmc'] = empty($params['gy_name']) ? '' : $params['gy_name'];
  482. $data['sczl_bzbh'] = $params['sczl_bzdh'];
  483. $data['班组ID'] = $params['team_id'];
  484. // 获取当前时间
  485. $current_time = time();
  486. // 设置时间范围
  487. $start_time1 = strtotime(date('Y-m-d') . ' 08:30:00');
  488. $end_time1 = strtotime(date('Y-m-d') . ' 20:30:00');
  489. $end_time2 = strtotime(date('Y-m-d') . ' 24:00:00');
  490. $start_time3 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 08:30:00');
  491. $start_time4 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 00:00:00');
  492. // 判断当前时间属于哪个时间范围
  493. if ($current_time >= $start_time1 && $current_time <= $end_time1) {
  494. $data['sczl_kgsj'] = date('Y-m-d') . ' 08:30:00';
  495. } elseif ($current_time > $end_time1 && $current_time <= $end_time2) {
  496. $data['sczl_kgsj'] = date('Y-m-d') . ' 20:30:00';
  497. } elseif ($current_time > $end_time1 && $current_time <= $start_time3) {
  498. $data['sczl_kgsj'] = date('Y-m-d', strtotime('+1 day')) . ' 08:30:00';
  499. }elseif ($current_time > $start_time4 && $current_time <= $start_time3){
  500. $data['sczl_kgsj'] = date('Y-m-d') . ' 20:30:00';
  501. }
  502. if (!empty($params['order']) && !empty($params['yjno'])){
  503. $option['Gy0_gdbh'] = $params['order'];
  504. $option['Gy0_yjno'] = $params['yjno'];
  505. $option['Gy0_gxh'] = $data['sczl_gxh'];
  506. $data['任务ID'] = \db('工单_工艺资料')->where($option)->value('UniqId');
  507. }else{
  508. $data['任务ID'] = '';
  509. }
  510. $sql = \db('设备_糊盒报工采集')->fetchSql(true)->insert($data);
  511. $res = Db::query($sql);
  512. if ($res === false) {
  513. $this->error('设置失败');
  514. } else {
  515. $this->success('设置成功');
  516. }
  517. }
  518. /**
  519. * 糊盒设备运行跟踪数据页面显示
  520. * @return void
  521. * @throws \think\db\exception\DataNotFoundException
  522. * @throws \think\db\exception\ModelNotFoundException
  523. * @throws \think\exception\DbException
  524. */
  525. public function getGluingReportDataList()
  526. {
  527. if ($this->request->isGet() === false){
  528. $this->error('请求错误');
  529. }
  530. $params = $this->request->param();
  531. if (empty($params['machine']) || empty($params['day'])){
  532. $this->error('参数错误');
  533. }
  534. $where = [
  535. 'a.sczl_jtbh' => $params['machine'],
  536. 'a.sczl_rq' => ['like',$params['day'].'%']
  537. ];
  538. $field = ['a.sczl_gdbh as 工单编号','a.sczl_yjno as 印件号','a.sczl_gxh as 工序号','a.sczl_gxmc as 工序名称','a.来料数量','a.sczl_cl as 产量',
  539. 'a.sczl_zcfp as 制程废品','a.startTime as 开始时间','a.endTime as 结束时间','a.sczl_ls as 联数','a.sczl_rq as 日期',
  540. 'a.sczl_dedh as 定额代号','a.工价系数','a.保养工时','a.装版工时','a.异常工时','a.异常类型','a.设备运行工时','a.role',
  541. 'a.sys_id as 创建人员','a.sys_rq as 上报时间','a.mod_rq as 修改时间','a.Uid','a.sczl_jtbh as 机台编号',
  542. 'b.yj_Yjdh as 产品代号','yj_yjmc as 产品名称'];
  543. $list = \db('设备_糊盒报工资料')
  544. ->alias('a')
  545. ->join('工单_印件资料 b','a.sczl_gdbh = b.Yj_Gdbh and a.sczl_yjno = b.yj_Yjno','left')
  546. ->field($field)
  547. ->where($where)
  548. ->group('a.Uid')
  549. ->select();
  550. if (empty($list)){
  551. $this->error('未找到报工数据');
  552. }
  553. foreach ($list as $key=>$value){
  554. $list[$key]['class'] = [];
  555. $idList = explode(',',$value['role']);
  556. foreach ($idList as $item){
  557. $class = \db('设备_糊盒班组资料')
  558. ->where('id',$item)
  559. ->field("role,rate,bh1,bh2,bh3,bh4,bh5,bh6,bh7,bh8,bh9,bh10,bh11,bh12,bh13,bh14,bh15")
  560. ->find();
  561. if (!empty($class)){
  562. for ($i=1;$i<16;$i++) {
  563. if ($class['bh' . $i] != '' && $class['bh' . $i] != '000000') {
  564. $name = \db('人事_基本资料')->where('员工编号', $class['bh' . $i])->field('rtrim(员工姓名) as 姓名')->find();
  565. $list[$key]['class'][] = [
  566. '编号' => $class['bh' . $i],
  567. '姓名' => $name['姓名'],
  568. '比例' => $class['rate'],
  569. '角色' => $class['role'],
  570. ];
  571. }
  572. }
  573. $list[$key]['class'] = array_values($list[$key]['class']);
  574. }
  575. }
  576. unset($list[$key]['role']);
  577. }
  578. $this->success('成功',$list);
  579. }
  580. /**
  581. * 报工数据详情显示
  582. * @return void
  583. * @throws \think\db\exception\DataNotFoundException
  584. * @throws \think\db\exception\ModelNotFoundException
  585. * @throws \think\exception\DbException
  586. */
  587. public function getGluingReportDataDetail()
  588. {
  589. if ($this->request->isGet() === false){
  590. $this->error('请求错误');
  591. }
  592. $params = $this->request->param();
  593. if(!isset($params['id']) || empty($params['id'])){
  594. $this->error('参数错误');
  595. }
  596. $where = ['Uid'=>$params['id']];
  597. $field = ['a.sczl_gdbh as 工单编号','a.sczl_yjno as 印件号','a.sczl_gxh as 工序号','a.sczl_gxmc as 工序名称','a.来料数量','a.sczl_cl as 产量',
  598. 'a.sczl_zcfp as 制程废品','a.startTime as 开始时间','a.endTime as 结束时间','a.sczl_ls as 联数','a.sczl_rq as 日期',
  599. 'a.sczl_dedh as 定额代号','a.工价系数','a.保养工时','a.装版工时','a.异常工时','a.异常类型','a.设备运行工时','a.role',
  600. 'a.sys_id as 创建人员','a.sys_rq as 上报时间','a.mod_rq as 修改时间','a.Uid','a.sczl_jtbh as 机台编号',
  601. 'b.yj_Yjdh as 产品代号','yj_yjmc as 产品名称'];
  602. $list = \db('设备_糊盒报工资料')
  603. ->alias('a')
  604. ->join('工单_印件资料 b','a.sczl_gdbh = b.Yj_Gdbh and a.sczl_yjno = b.yj_Yjno','left')
  605. ->where($where)
  606. ->field($field)
  607. ->find();
  608. $list['class'] = [];
  609. $idList = explode(',',$list['role']);
  610. foreach ($idList as $item){
  611. $class = \db('设备_糊盒班组资料')
  612. ->where('id',$item)
  613. ->field("role,rate,bh1,bh2,bh3,bh4,bh5,bh6,bh7,bh8,bh9,bh10,bh11,bh12,bh13,bh14,bh15")
  614. ->find();
  615. if (!empty($class)){
  616. for ($i=1;$i<16;$i++) {
  617. if ($class['bh' . $i] != '' && $class['bh' . $i] != '000000') {
  618. $name = \db('人事_基本资料')->where('员工编号', $class['bh' . $i])->field('rtrim(员工姓名) as 姓名')->find();
  619. $list['class'][] = [
  620. '编号' => $class['bh' . $i],
  621. '姓名' => $name['姓名'],
  622. '比例' => $class['rate'],
  623. '角色' => $class['role'],
  624. ];
  625. }
  626. }
  627. $list['class'] = array_values($list['class']);
  628. }
  629. }
  630. $this->success('成功',$list);
  631. }
  632. /**
  633. * 修改糊盒班组报工资料
  634. * @return void
  635. * @throws \think\Exception
  636. * @throws \think\db\exception\BindParamException
  637. * @throws \think\exception\PDOException
  638. */
  639. public function getGluingReportDetailUpdate()
  640. {
  641. if ($this->request->isPost() === false){
  642. $this->error('请求错误');
  643. }
  644. $params = Request::instance()->post();
  645. if(!isset($params['id']) || empty($params['id'])){
  646. $this->error('参数错误');
  647. }
  648. $id = $params['id'];
  649. unset($params['id']);
  650. $params['mod_rq'] = date('Y-m-d H:i:s',time());
  651. $sql = \db('设备_糊盒报工资料')
  652. ->where('Uid',$id)
  653. ->fetchSql(true)
  654. ->update($params);
  655. $res = \db()->query($sql);
  656. if ($res === false) {
  657. $this->error('修改成功');
  658. }else{
  659. $this->success('修改失败');
  660. }
  661. }
  662. /**
  663. * 修改报工数据班组
  664. * @return void
  665. * @throws \think\Exception
  666. * @throws \think\exception\PDOException
  667. */
  668. public function UpdateGluingReportClass()
  669. {
  670. if ($this->request->isPost() === false){
  671. $this->error('请求错误');
  672. }
  673. $params = Request::instance()->post();
  674. if(!isset($params['id']) || empty($params['id'])){
  675. $this->error('参数错误');
  676. }
  677. $id = $params['id'];
  678. $data['role'] = $params['role'];
  679. $res = \db('设备_糊盒报工资料')->where('Uid',$id)->update($data);
  680. if ($res === false) {
  681. $this->error('修改失败');
  682. }else{
  683. $this->success('修改成功');
  684. }
  685. }
  686. /**
  687. * 当班产量
  688. * @return void
  689. * @throws \think\db\exception\DataNotFoundException
  690. * @throws \think\db\exception\ModelNotFoundException
  691. * @throws \think\exception\DbException
  692. */
  693. public function GluingReportList()
  694. {
  695. if ($this->request->isGet() === false){
  696. $this->error('请求错误');
  697. }
  698. $params = $this->request->param();
  699. if (!isset($params['machine']) || empty($params['machine'])){
  700. $this->error('参数错误');
  701. }
  702. $machine = $params['machine'];
  703. $sczlTime = date('Y-m-d H:i:s',time());
  704. if ($sczlTime>date('Y-m-d 00:00:00') && $sczlTime<date('Y-m-d 08:30:00')){
  705. $time = date('Y-m-d 00:00:00',time()-86400);
  706. }else{
  707. $time = date('Y-m-d 00:00:00');
  708. }
  709. $where = [
  710. 'sczl_jtbh' => $machine,
  711. 'sczl_rq' => $time,
  712. ];
  713. $field = 'rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_yjno) as yjno,rtrim(sczl_dedh) as dedh,rtrim(sczl_gxmc) as gxmc,
  714. rtrim(sczl_cl) as 产量,rtrim(sczl_zcfp) as 制程废品,rtrim(装版工时) as 装版工时,rtrim(保养工时) as 保养工时,
  715. rtrim(异常工时) as 异常工时,rtrim(设备运行工时) as 通电工时,startTime,endTime,Uid,rtrim(sczl_ls) as ls,来料数量';
  716. $list = \db('设备_糊盒报工资料')->where($where)->field($field)->order('Uid desc')->select();
  717. if (!empty($list)){
  718. foreach ($list as $k=>$v){
  719. $name = \db('工单_印件资料')->where('Yj_Gdbh',$v['工单编号'])->where('yj_Yjno',$v['yjno'])->field('rtrim(yj_yjmc) as cpmc')->find();
  720. if ($v['yjno']<10){
  721. $list[$k]['yjno'] = '0'.$v['yjno'];
  722. }
  723. $list[$k]['印件及工序'] = $list[$k]['yjno'].'-'.$v['gxmc'];
  724. $list[$k]['生产时间段'] = substr($v['startTime'],5,5).' '.substr($v['startTime'],11,5).'<-->'.substr($v['endTime'],5,5).' '.substr($v['endTime'],11,5);
  725. $list[$k]['产品名称'] = $name['cpmc'];
  726. }
  727. }
  728. $this->success('成功',$list);
  729. }
  730. /**
  731. * 工单查询
  732. * @return void
  733. * @throws \think\db\exception\DataNotFoundException
  734. * @throws \think\db\exception\ModelNotFoundException
  735. * @throws \think\exception\DbException
  736. */
  737. public function getWorkOrderList()
  738. {
  739. if ($this->request->isGet() === false){
  740. $this->error('请求错误');
  741. }
  742. $params = $this->request->param();
  743. if (!isset($params['search']) || empty($params['search'])){
  744. $this->error('参数错误');
  745. }
  746. $search = $params['search'];
  747. $list = \db('工单_基本资料')
  748. ->where('Gd_gdbh|Gd_cpmc','like',$search.'%')
  749. ->field('Gd_gdbh as 工单编号,Gd_cpdh as 产品代号,Gd_cpmc as 产品名称')
  750. ->order('Gd_gdbh desc')
  751. ->select();
  752. if (empty($list)){
  753. $this->error('未找到数据');
  754. }else{
  755. $this->success('成功',$list);
  756. }
  757. }
  758. /**
  759. * 查询机台编号
  760. * @return void
  761. */
  762. public function getMachineList()
  763. {
  764. if ($this->request->isGet() === false){
  765. $this->error('请求错误');
  766. }
  767. $params = $this->request->param();
  768. if (!isset($params['search']) || empty($params['search'])){
  769. $this->error('参数错误');
  770. }
  771. $search = $params['search'];
  772. $list = \db('设备_基本资料')
  773. ->where('使用部门',$search)
  774. ->column('设备名称','设备编号');
  775. if (empty($list)){
  776. $this->error('未找到数据');
  777. }else{
  778. $this->success('成功',$list);
  779. }
  780. }
  781. /**
  782. * 查询工艺名称
  783. * @return void
  784. * @throws \think\db\exception\DataNotFoundException
  785. * @throws \think\db\exception\ModelNotFoundException
  786. * @throws \think\exception\DbException
  787. */
  788. public function gitProcessList()
  789. {
  790. if ($this->request->isGet() === false){
  791. $this->error('请求错误');
  792. }
  793. $params = $this->request->param();
  794. if (!isset($params['search']) || empty($params['search'])){
  795. $this->error('参数错误');
  796. }
  797. $search = $params['search'];
  798. $list = \db('erp_常用字典')
  799. ->where('分类','糊盒工艺')
  800. ->where('名称','like','%'.$search.'%')
  801. ->field('名称')
  802. ->select();
  803. $data = [];
  804. if (empty($list)){
  805. $this->error('未找到工艺数据');
  806. }
  807. foreach ($list as $k=>$v){
  808. $name = explode('_',$v['名称']);
  809. $data[] = $name[2];
  810. }
  811. $this->success('成功',$data);
  812. }
  813. }