GluingReport.php 35 KB

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