GluingReport.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965
  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. //
  287. // // 2. 参数验证
  288. // $param = $this->request->post();
  289. // if (empty($param)) {
  290. // $this->error('参数错误');
  291. // }
  292. //
  293. // // 3. 使用事务确保数据一致性
  294. // Db::startTrans();
  295. // try {
  296. // // 准备数据
  297. // $currentTime = date('Y-m-d H:i:s');
  298. //
  299. // // 构建班组数据
  300. // $classData = [
  301. // 'sys_rq' => $currentTime,
  302. // 'jtbh' => $param['sczl_jtbh'] ?? '',
  303. // 'gdbh' => $param['sczl_gdbh'] ?? '',
  304. // 'gxmc' => $param['sczl_gxmc'] ?? '',
  305. // 'sys_id' => $param['sys_id'] ?? '',
  306. // 'sczl_rq' => $param['sczl_rq'] ?? '',
  307. // ];
  308. //
  309. // // 处理动态字段
  310. // for ($i = 1; $i <= 30; $i++) {
  311. // $classData['bh'.$i] = $param['bh'.$i] ?? '';
  312. // $classData['rate'.$i] = $param['rate'.$i] ?? '';
  313. // unset($param['bh'.$i], $param['rate'.$i]);
  314. // }
  315. //
  316. // // 保存班组数据
  317. // $classId = \db('糊盒报工班组')->insertGetId($classData);
  318. // if (!$classId) {
  319. // throw new \Exception('保存班组数据失败');
  320. // }
  321. //
  322. // // 保存设备数据
  323. // $param['role'] = $classId;
  324. // $param['sys_rq'] = $currentTime;
  325. //
  326. // $sql = \db('设备_糊盒报工资料')->fetchSql(true)->insert($param);
  327. // $result = db()->query($sql);
  328. // if ($result === false) {
  329. // throw new \Exception('保存设备数据失败');
  330. // }
  331. //
  332. // Db::commit();
  333. // $this->success('报工成功');
  334. //
  335. // } catch (\Exception $e) {
  336. // Db::rollback();
  337. // $this->error($e->getMessage() ?: '报工失败');
  338. // }
  339. // }
  340. /**
  341. * 新增糊盒报工数据
  342. * 说明:适配PHP 7.2、中文字段名,支持sczl_jtbh字段含#字符
  343. * @return void
  344. */
  345. public function addGluingReportData()
  346. {
  347. // 1. 请求方式验证(严格限制POST请求)
  348. if (!$this->request->isPost()) {
  349. $this->error('仅支持POST请求');
  350. }
  351. // 2. 获取并验证参数(重点适配含#字符的sczl_jtbh字段)
  352. $param = $this->request->post();
  353. // 核心修复:验证规则调整,明确允许#字符,兼容特殊字符
  354. $validate = new \think\Validate([
  355. 'sczl_jtbh' => 'require|regex:/^[\w#\x{4e00}-\x{9fa5}]+$/u', // 允许字母、数字、下划线、#、中文
  356. 'sczl_gdbh' => 'require',
  357. 'sczl_gxmc' => 'require',
  358. 'sys_id' => 'require',
  359. 'sczl_rq' => 'require|dateFormat:Y-m-d H:i:s',
  360. ], [
  361. 'sczl_jtbh.require' => '机组编号不能为空',
  362. 'sczl_jtbh.regex' => '机组编号仅支持字母、数字、下划线、#号和中文',
  363. 'sczl_gdbh.require' => '工单号不能为空',
  364. 'sczl_gxmc.require' => '工序名称不能为空',
  365. 'sys_id.require' => '系统ID不能为空',
  366. 'sczl_rq.require' => '报工日期不能为空',
  367. 'sczl_rq.dateFormat' => '报工日期格式错误(需为Y-m-d H:i:s)',
  368. ]);
  369. // 验证前处理:仅去除前后空格(不影响#字符)
  370. foreach (['sczl_jtbh', 'sczl_gdbh', 'sczl_gxmc', 'sys_id', 'sczl_rq'] as $field) {
  371. if (isset($param[$field]) && is_string($param[$field])) {
  372. $param[$field] = trim($param[$field]); // 只去空格,保留#等特殊字符
  373. }
  374. }
  375. // 执行验证
  376. if (!$validate->check($param)) {
  377. $this->error($validate->getError());
  378. }
  379. // 3. 事务处理(确保数据一致性)
  380. $currentTime = date('Y-m-d H:i:s');
  381. $tableClass = '糊盒报工班组';
  382. $tableDevice = '设备_糊盒报工资料';
  383. // 4. 构建班组数据(保留#字符,无需额外处理)
  384. $classData = [
  385. 'sys_rq' => $currentTime,
  386. 'jtbh' => $param['sczl_jtbh'], // 直接保留含#的原始值
  387. 'gdbh' => $param['sczl_gdbh'],
  388. 'gxmc' => $param['sczl_gxmc'],
  389. 'sys_id' => $param['sys_id'],
  390. 'sczl_rq' => $param['sczl_rq'],
  391. ];
  392. // 处理动态字段(1-30组bh/rate)
  393. $dynamicFields = [];
  394. for ($i = 1; $i <= 30; $i++) {
  395. $dynamicFields['bh' . $i] = isset($param['bh' . $i]) ? $param['bh' . $i] : '';
  396. $dynamicFields['rate' . $i] = isset($param['rate' . $i]) ? $param['rate' . $i] : '';
  397. }
  398. $classData = array_merge($classData, $dynamicFields);
  399. // 5. 保存班组数据(框架会自动处理特殊字符转义,避免SQL注入)
  400. $classId = Db::name($tableClass)->insertGetId($classData);
  401. if (empty($classId)) {
  402. throw new \Exception("{$tableClass}数据保存失败");
  403. }
  404. // 6. 构建设备数据(适配PHP7.2)
  405. $filteredParam = array_filter($param, function ($key) {
  406. return !preg_match('/^(bh|rate)\d+$/', $key);
  407. }, ARRAY_FILTER_USE_KEY);
  408. $deviceData = array_merge([
  409. 'role' => $classId,
  410. 'sys_rq' => $currentTime,
  411. ], $filteredParam);
  412. // 7. 保存设备数据(含#字符的字段会被自动转义,安全插入)
  413. $sql = Db::name($tableDevice)->fetchSql(true)->insert($deviceData);
  414. $saveResult = db()->query($sql);
  415. if ($saveResult !== false) {
  416. $this->success('报工提交成功');
  417. }else{
  418. $this->error('报工提交失败');
  419. }
  420. }
  421. /**
  422. * 糊盒机台报工数据菜单
  423. * @return void
  424. * @throws \think\db\exception\DataNotFoundException
  425. * @throws \think\db\exception\ModelNotFoundException
  426. * @throws \think\exception\DbException
  427. */
  428. public function getTab()
  429. {
  430. if ($this->request->isGet() === false){
  431. $this->error('请求错误');
  432. }
  433. $data = [];
  434. $date = date('Y-m-d 00:00:00',time()-3888000);
  435. $sist = ['印后糊盒车间','精品自动化车间','数字化车间'];
  436. $department = \db('设备_基本资料')
  437. ->distinct(true)
  438. ->where('使用部门','in',$sist)
  439. ->where('设备编组','<>','')
  440. ->where('sys_sbID','<>','')
  441. ->order('设备编组')
  442. ->column('rtrim(使用部门) as 使用部门');
  443. if (empty($department)){
  444. $this->success('未获取到机台数据');
  445. }
  446. $list = \db('设备_糊盒报工资料')
  447. ->field([
  448. 'DISTINCT(sczl_rq)' => '时间',
  449. 'rtrim(sczl_jtbh)' => '机台编号'
  450. ])
  451. ->where('sczl_rq','>',$date)
  452. ->order('sczl_rq desc')
  453. ->select();
  454. foreach ($department as $value){
  455. $machine = \db('设备_基本资料')->where('使用部门',$value)->where('sys_sbID','<>','')->where('使用部门',$value)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->order('设备编号')->select();
  456. foreach ($machine as $k=>$v){
  457. $data[rtrim($value)][$v['设备编号'].'-->'.$v['设备名称']] = [];
  458. foreach ($list as $kk=>$vv){
  459. if ($v['设备编号'] === $vv['机台编号']){
  460. array_push($data[rtrim($value)][$v['设备编号'].'-->'.$v['设备名称']],date('Y-m-d',strtotime($vv['时间'])));
  461. }
  462. }
  463. }
  464. }
  465. $this->success('成功',$data);
  466. }
  467. /**
  468. * 获取当前生产工单
  469. * @return void
  470. * @throws \think\db\exception\DataNotFoundException
  471. * @throws \think\db\exception\ModelNotFoundException
  472. * @throws \think\exception\DbException
  473. */
  474. public function GetProduction()
  475. {
  476. if (Request::instance()->isGet() == false) {
  477. $this->error('非法请求');
  478. }
  479. $params = Request::instance()->param();
  480. if (!isset($params['machine']) || empty($params['machine'])) {
  481. $this->error('参数错误');
  482. }
  483. $machine = $params['machine'];
  484. $machineCode = \db('dic_lzde')->where('适用机型',$machine)->value('sys_bh');
  485. $data = \db('设备_糊盒报工采集')->where('sczl_jtbh',$machine)->order('UID desc')->find();
  486. if (empty($data)){
  487. $this->success('未找到数据');
  488. }
  489. $list = [];
  490. $list['班组ID'] = $data['班组ID'];
  491. $row = [];
  492. if (!empty($data['sczl_gdbh'])){
  493. $endTime = \db('工单_工艺资料')
  494. ->where('Gy0_gdbh',$data['sczl_gdbh'])
  495. ->where('Gy0_yjno',$data['sczl_yjno'])
  496. ->where('Gy0_gxh',$data['sczl_gxh'])
  497. ->find();
  498. $list['工单编号'] = $data['sczl_gdbh'];
  499. if (!empty($endTime)){
  500. $list['印件号'] = $data['sczl_yjno'];
  501. $name = \db('工单_基本资料')->where('Gd_Gdbh',$data['sczl_gdbh'])->value('成品名称');
  502. $code = \db('工单_基本资料')->where('Gd_Gdbh',$data['sczl_gdbh'])->value('成品代号');
  503. $list['产品名称'] = rtrim($name);
  504. $list['产品代号'] = rtrim($code);
  505. $list['工序名称'] = $data['sczl_gxmc'];
  506. $list['联数'] = $endTime['Gy0_ls'];
  507. }
  508. $list['状态'] = rtrim($data['status']);
  509. $list['开工时间'] = $data['sczl_kgsj'];
  510. }else{
  511. $list['工单编号'] = '';
  512. $list['印件号'] = 0;
  513. $list['产品名称'] = '';
  514. $list['工序名称'] = '';
  515. $list['产品代号'] = '';
  516. $list['状态'] = '';
  517. $list['开工时间'] = '';
  518. $list['联数'] = '';
  519. }
  520. $list['班组编号'] = rtrim($data['sczl_bzbh']);
  521. $idList = explode(',',$data['班组ID']);
  522. foreach ($idList as $k=>$v){
  523. $class = \db('设备_糊盒班组资料')
  524. ->where('id',$v)
  525. ->field("role,rate,bh1,bh2,bh3,bh4,bh5,bh6,bh7,bh8,bh9,bh10,bh11,bh12,bh13,bh14,bh15")
  526. ->find();
  527. if (!empty($class)){
  528. for ($i=1;$i<16;$i++) {
  529. if ($class['bh' . $i] != '' && $class['bh' . $i] != '000000') {
  530. $name = \db('人事_基本资料')->where('员工编号', $class['bh' . $i])->field('rtrim(员工姓名) as 姓名')->find();
  531. $row[] = [
  532. '编号' => $class['bh' . $i],
  533. '姓名' => $name['姓名'],
  534. '比例' => $class['rate'],
  535. '角色' => $class['role'],
  536. ];
  537. }
  538. }
  539. $row = array_values($row);
  540. }
  541. }
  542. $list['班组成员'] = $row;
  543. $list['定额代号'] = $machineCode;
  544. $this->success('成功',$list);
  545. }
  546. /**
  547. * 设置当前工单和当前班组
  548. * @return void
  549. */
  550. public function setMachineTeam()
  551. {
  552. if (Request::instance()->isPost() == false) {
  553. $this->error('非法请求');
  554. }
  555. $params = Request::instance()->post();
  556. if (!isset($params['machine']) || empty($params['machine'] )) {
  557. $this->error('参数不能为空');
  558. }
  559. if (empty($params['team_id']) || empty($params['sczl_bzdh'])){
  560. $this->error('请先选择班组成员');
  561. }
  562. $machine = $params['machine'] . '#';
  563. $data = [];
  564. $data['status'] = $params['status'];
  565. $data['sczl_sj'] = date('Y-m-d H:i:s');
  566. $data['sczl_jtbh'] = $machine;
  567. $data['sczl_gdbh'] = empty($params['order']) ? '':$params['order'];
  568. $data['sczl_yjno'] = empty($params['yjno']) ? '':$params['yjno'];
  569. $data['sczl_gxh'] = empty($params['gy_name']) ? '' : (int)substr($params['gy_name'], 0, 2);
  570. $data['sczl_gxmc'] = empty($params['gy_name']) ? '' : $params['gy_name'];
  571. $data['sczl_bzbh'] = $params['sczl_bzdh'];
  572. $data['班组ID'] = $params['team_id'];
  573. // 获取当前时间
  574. $current_time = time();
  575. // 设置时间范围
  576. $start_time1 = strtotime(date('Y-m-d') . ' 08:30:00');
  577. $end_time1 = strtotime(date('Y-m-d') . ' 20:30:00');
  578. $end_time2 = strtotime(date('Y-m-d') . ' 24:00:00');
  579. $start_time3 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 08:30:00');
  580. $start_time4 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 00:00:00');
  581. // 判断当前时间属于哪个时间范围
  582. if ($current_time >= $start_time1 && $current_time <= $end_time1) {
  583. $data['sczl_kgsj'] = date('Y-m-d') . ' 08:30:00';
  584. } elseif ($current_time > $end_time1 && $current_time <= $end_time2) {
  585. $data['sczl_kgsj'] = date('Y-m-d') . ' 20:30:00';
  586. } elseif ($current_time > $end_time1 && $current_time <= $start_time3) {
  587. $data['sczl_kgsj'] = date('Y-m-d', strtotime('+1 day')) . ' 08:30:00';
  588. }elseif ($current_time > $start_time4 && $current_time <= $start_time3){
  589. $data['sczl_kgsj'] = date('Y-m-d') . ' 20:30:00';
  590. }
  591. if (!empty($params['order']) && !empty($params['yjno'])){
  592. $option['Gy0_gdbh'] = $params['order'];
  593. $option['Gy0_yjno'] = $params['yjno'];
  594. $option['Gy0_gxh'] = $data['sczl_gxh'];
  595. $data['任务ID'] = \db('工单_工艺资料')->where($option)->value('UniqId');
  596. }else{
  597. $data['任务ID'] = '';
  598. }
  599. $sql = \db('设备_糊盒报工采集')->fetchSql(true)->insert($data);
  600. $res = Db::query($sql);
  601. if ($res === false) {
  602. $this->error('设置失败');
  603. } else {
  604. $this->success('设置成功');
  605. }
  606. }
  607. /**
  608. * 糊盒设备运行跟踪数据页面显示
  609. * @return void
  610. * @throws \think\db\exception\DataNotFoundException
  611. * @throws \think\db\exception\ModelNotFoundException
  612. * @throws \think\exception\DbException
  613. */
  614. public function getGluingReportDataList()
  615. {
  616. if ($this->request->isGet() === false){
  617. $this->error('请求错误');
  618. }
  619. $params = $this->request->param();
  620. if (empty($params['machine']) || empty($params['day'])){
  621. $this->error('参数错误');
  622. }
  623. $where = [
  624. 'a.sczl_jtbh' => $params['machine'],
  625. 'a.sczl_rq' => ['like',$params['day'].'%']
  626. ];
  627. $field = ['a.sczl_gdbh as 工单编号','a.sczl_gxmc as 工序名称','a.来料数量','a.sczl_cl as 产量',
  628. 'a.sczl_zcfp as 制程废品','a.startTime as 开始时间','a.endTime as 结束时间','a.sczl_ls as 联数','a.sczl_rq as 日期',
  629. 'a.sczl_dedh as 定额代号','a.工价系数','a.保养工时','a.装版工时','a.异常工时','a.异常类型','a.设备运行工时','a.role',
  630. 'a.sys_id as 创建人员','a.sys_rq as 上报时间','a.mod_rq as 修改时间','a.Uid','a.sczl_jtbh as 机台编号',
  631. 'b.Gd_cpdh as 产品代号','b.Gd_cpmc as 产品名称'];
  632. $list = \db('设备_糊盒报工资料')
  633. ->alias('a')
  634. ->join('工单_基本资料 b','a.sczl_gdbh = b.Gd_gdbh','left')
  635. ->field($field)
  636. ->where($where)
  637. ->group('a.Uid')
  638. ->select();
  639. if (empty($list)){
  640. $this->error('未找到报工数据');
  641. }
  642. foreach ($list as $key=>$value){
  643. $list[$key]['class'] = [];
  644. $idList = explode(',',$value['role']);
  645. foreach ($idList as $item){
  646. $class = \db('')
  647. ->where('id',$item)
  648. ->field("role,rate,bh1,bh2,bh3,bh4,bh5,bh6,bh7,bh8,bh9,bh10,bh11,bh12,bh13,bh14,bh15")
  649. ->find();
  650. if (!empty($class)){
  651. for ($i=1;$i<16;$i++) {
  652. if ($class['bh' . $i] != '' && $class['bh' . $i] != '000000') {
  653. $name = \db('人事_基本资料')->where('员工编号', $class['bh' . $i])->field('rtrim(员工姓名) as 姓名')->find();
  654. $list[$key]['class'][] = [
  655. '编号' => $class['bh' . $i],
  656. '姓名' => $name['姓名'],
  657. '比例' => $class['rate'],
  658. '角色' => $class['role'],
  659. ];
  660. }
  661. }
  662. $list[$key]['class'] = array_values($list[$key]['class']);
  663. }
  664. }
  665. unset($list[$key]['role']);
  666. }
  667. $this->success('成功',$list);
  668. }
  669. /**
  670. * 报工数据详情显示
  671. * @return void
  672. * @throws \think\db\exception\DataNotFoundException
  673. * @throws \think\db\exception\ModelNotFoundException
  674. * @throws \think\exception\DbException
  675. */
  676. public function getGluingReportDataDetail()
  677. {
  678. if ($this->request->isGet() === false){
  679. $this->error('请求错误');
  680. }
  681. $params = $this->request->param();
  682. if(!isset($params['id']) || empty($params['id'])){
  683. $this->error('参数错误');
  684. }
  685. $where = ['Uid'=>$params['id']];
  686. $field = ['a.sczl_gdbh as 工单编号','a.sczl_yjno as 印件号','a.sczl_gxh as 工序号','a.sczl_gxmc as 工序名称','a.来料数量','a.sczl_cl as 产量',
  687. 'a.sczl_zcfp as 制程废品','a.startTime as 开始时间','a.endTime as 结束时间','a.sczl_ls as 联数','a.sczl_rq as 日期',
  688. 'a.sczl_dedh as 定额代号','a.工价系数','a.保养工时','a.装版工时','a.异常工时','a.异常类型','a.设备运行工时','a.role',
  689. 'a.sys_id as 创建人员','a.sys_rq as 上报时间','a.mod_rq as 修改时间','a.Uid','a.sczl_jtbh as 机台编号',
  690. 'b.yj_Yjdh as 产品代号','yj_yjmc as 产品名称'];
  691. $list = \db('设备_糊盒报工资料')
  692. ->alias('a')
  693. ->join('工单_印件资料 b','a.sczl_gdbh = b.Yj_Gdbh and a.sczl_yjno = b.yj_Yjno','left')
  694. ->where($where)
  695. ->field($field)
  696. ->find();
  697. $list['class'] = [];
  698. $idList = explode(',',$list['role']);
  699. foreach ($idList as $item){
  700. $class = \db('设备_糊盒班组资料')
  701. ->where('id',$item)
  702. ->field("role,rate,bh1,bh2,bh3,bh4,bh5,bh6,bh7,bh8,bh9,bh10,bh11,bh12,bh13,bh14,bh15")
  703. ->find();
  704. if (!empty($class)){
  705. for ($i=1;$i<16;$i++) {
  706. if ($class['bh' . $i] != '' && $class['bh' . $i] != '000000') {
  707. $name = \db('人事_基本资料')->where('员工编号', $class['bh' . $i])->field('rtrim(员工姓名) as 姓名')->find();
  708. $list['class'][] = [
  709. '编号' => $class['bh' . $i],
  710. '姓名' => $name['姓名'],
  711. '比例' => $class['rate'],
  712. '角色' => $class['role'],
  713. ];
  714. }
  715. }
  716. $list['class'] = array_values($list['class']);
  717. }
  718. }
  719. $this->success('成功',$list);
  720. }
  721. /**
  722. * 修改糊盒班组报工资料
  723. * @return void
  724. * @throws \think\Exception
  725. * @throws \think\db\exception\BindParamException
  726. * @throws \think\exception\PDOException
  727. */
  728. public function getGluingReportDetailUpdate()
  729. {
  730. if ($this->request->isPost() === false){
  731. $this->error('请求错误');
  732. }
  733. $params = Request::instance()->post();
  734. if(!isset($params['id']) || empty($params['id'])){
  735. $this->error('参数错误');
  736. }
  737. $id = $params['id'];
  738. unset($params['id']);
  739. $params['mod_rq'] = date('Y-m-d H:i:s',time());
  740. $sql = \db('设备_糊盒报工资料')
  741. ->where('Uid',$id)
  742. ->fetchSql(true)
  743. ->update($params);
  744. $res = \db()->query($sql);
  745. if ($res === false) {
  746. $this->error('修改成功');
  747. }else{
  748. $this->success('修改失败');
  749. }
  750. }
  751. /**
  752. * 修改报工数据班组
  753. * @return void
  754. * @throws \think\Exception
  755. * @throws \think\exception\PDOException
  756. */
  757. public function UpdateGluingReportClass()
  758. {
  759. if ($this->request->isPost() === false){
  760. $this->error('请求错误');
  761. }
  762. $params = Request::instance()->post();
  763. if(!isset($params['id']) || empty($params['id'])){
  764. $this->error('参数错误');
  765. }
  766. $id = $params['id'];
  767. $data['role'] = $params['role'];
  768. $res = \db('设备_糊盒报工资料')->where('Uid',$id)->update($data);
  769. if ($res === false) {
  770. $this->error('修改失败');
  771. }else{
  772. $this->success('修改成功');
  773. }
  774. }
  775. /**
  776. * 当班产量
  777. * @return void
  778. * @throws \think\db\exception\DataNotFoundException
  779. * @throws \think\db\exception\ModelNotFoundException
  780. * @throws \think\exception\DbException
  781. */
  782. public function GluingReportList()
  783. {
  784. if ($this->request->isGet() === false){
  785. $this->error('请求错误');
  786. }
  787. $params = $this->request->param();
  788. if (!isset($params['machine']) || empty($params['machine'])){
  789. $this->error('参数错误');
  790. }
  791. $machine = $params['machine'];
  792. $sczlTime = date('Y-m-d H:i:s',time());
  793. if ($sczlTime>date('Y-m-d 00:00:00') && $sczlTime<date('Y-m-d 08:30:00')){
  794. $time = date('Y-m-d 00:00:00',time()-86400);
  795. }else{
  796. $time = date('Y-m-d 00:00:00');
  797. }
  798. $where = [
  799. 'sczl_jtbh' => $machine,
  800. 'sczl_rq' => $time,
  801. ];
  802. $field = 'rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_yjno) as yjno,rtrim(sczl_dedh) as dedh,rtrim(sczl_gxmc) as gxmc,
  803. rtrim(sczl_cl) as 产量,rtrim(sczl_zcfp) as 制程废品,rtrim(装版工时) as 装版工时,rtrim(保养工时) as 保养工时,
  804. rtrim(异常工时) as 异常工时,rtrim(设备运行工时) as 通电工时,startTime,endTime,Uid,rtrim(sczl_ls) as ls,来料数量';
  805. $list = \db('设备_糊盒报工资料')->where($where)->field($field)->order('Uid desc')->select();
  806. if (!empty($list)){
  807. foreach ($list as $k=>$v){
  808. $name = \db('工单_印件资料')->where('Yj_Gdbh',$v['工单编号'])->where('yj_Yjno',$v['yjno'])->field('rtrim(yj_yjmc) as cpmc')->find();
  809. if ($v['yjno']<10){
  810. $list[$k]['yjno'] = '0'.$v['yjno'];
  811. }
  812. $list[$k]['印件及工序'] = $list[$k]['yjno'].'-'.$v['gxmc'];
  813. $list[$k]['生产时间段'] = substr($v['startTime'],5,5).' '.substr($v['startTime'],11,5).'<-->'.substr($v['endTime'],5,5).' '.substr($v['endTime'],11,5);
  814. $list[$k]['产品名称'] = $name['cpmc'];
  815. }
  816. }
  817. $this->success('成功',$list);
  818. }
  819. /**
  820. * 工单查询
  821. * @return void
  822. * @throws \think\db\exception\DataNotFoundException
  823. * @throws \think\db\exception\ModelNotFoundException
  824. * @throws \think\exception\DbException
  825. */
  826. public function getWorkOrderList()
  827. {
  828. if ($this->request->isGet() === false){
  829. $this->error('请求错误');
  830. }
  831. $params = $this->request->param();
  832. if (!isset($params['search']) || empty($params['search'])){
  833. $this->error('参数错误');
  834. }
  835. $search = $params['search'];
  836. $list = \db('工单_基本资料')
  837. ->where('Gd_gdbh|Gd_cpmc','like',$search.'%')
  838. ->field('Gd_gdbh as 工单编号,Gd_cpdh as 产品代号,Gd_cpmc as 产品名称')
  839. ->order('Gd_gdbh desc')
  840. ->select();
  841. if (empty($list)){
  842. $this->error('未找到数据');
  843. }else{
  844. $this->success('成功',$list);
  845. }
  846. }
  847. /**
  848. * 查询机台编号
  849. * @return void
  850. */
  851. public function getMachineList()
  852. {
  853. if ($this->request->isGet() === false){
  854. $this->error('请求错误');
  855. }
  856. $params = $this->request->param();
  857. if (!isset($params['search']) || empty($params['search'])){
  858. $this->error('参数错误');
  859. }
  860. $search = $params['search'];
  861. $list = \db('设备_基本资料')
  862. ->where('使用部门',$search)
  863. ->column('设备名称','设备编号');
  864. if (empty($list)){
  865. $this->error('未找到数据');
  866. }else{
  867. $this->success('成功',$list);
  868. }
  869. }
  870. /**
  871. * 查询工艺名称
  872. * @return void
  873. * @throws \think\db\exception\DataNotFoundException
  874. * @throws \think\db\exception\ModelNotFoundException
  875. * @throws \think\exception\DbException
  876. */
  877. public function gitProcessList()
  878. {
  879. if ($this->request->isGet() === false){
  880. $this->error('请求错误');
  881. }
  882. $params = $this->request->param();
  883. if (!isset($params['search']) || empty($params['search'])){
  884. $this->error('参数错误');
  885. }
  886. $search = $params['search'];
  887. $list = \db('erp_常用字典')
  888. ->where('分类','糊盒工艺')
  889. ->where('名称','like','%'.$search.'%')
  890. ->field('名称')
  891. ->select();
  892. $data = [];
  893. if (empty($list)){
  894. $this->error('未找到工艺数据');
  895. }
  896. foreach ($list as $k=>$v){
  897. $name = explode('_',$v['名称']);
  898. $data[] = $name[2];
  899. }
  900. $this->success('成功',$data);
  901. }
  902. }