GluingReport.php 35 KB

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