GluChronographSheet.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use \think\Request;
  5. use \think\Db;
  6. /**
  7. * 糊盒计时单维护
  8. */
  9. class GluChronographSheet extends Api
  10. {
  11. protected $noNeedLogin = ['*'];
  12. protected $noNeedRight = ['*'];
  13. /**
  14. * 获取计件工计时单侧边栏
  15. * @ApiMethod (GET)
  16. */
  17. public function getTab()
  18. {
  19. //get请求
  20. if(!$this->request->isGet()){
  21. $this->error('请求方式错误');
  22. }
  23. $rows = db()->table('糊盒报工机时')
  24. ->field('LEFT(wgjs_rq, 7) as date')
  25. ->group('date')
  26. ->order('UniqId desc')
  27. ->limit(15)
  28. ->select();
  29. foreach($rows as $key=>$value){
  30. $rows[$key]['date'] = str_replace('-', '', $rows[$key]['date']);
  31. }
  32. $this->success('成功',$rows);
  33. }
  34. /**
  35. * 获取计件工计时单列表
  36. * @ApiMethod (GET)
  37. * @param string $date 时间
  38. * @param string $Sczl_bh1 员工编号
  39. */
  40. public function getList()
  41. {
  42. // 验证请求方式
  43. if (!$this->request->isGet()) {
  44. $this->error('请求方式错误');
  45. }
  46. $req = $this->request->param();
  47. // 必需参数校验
  48. if (empty($req['date'])) {
  49. $this->error('参数错误: 缺少日期参数');
  50. }
  51. $where['wgjs_rq'] = ['LIKE', $req['date'] . '%'];
  52. $usePagination = isset($req['page'], $req['limit']) && $req['page'] > 0 && $req['limit'] > 0;
  53. // 构建基础查询
  54. $query = db()->table('糊盒报工机时')
  55. ->field('LEFT(wgjs_rq, 10) as wgjs_rq, UniqId,
  56. wgjs_bh1, wgjs_js1, rtrim(wgjs_yy1) as wgjs_yy1,
  57. wgjs_bh2, wgjs_js2, rtrim(wgjs_yy2) as wgjs_yy2,
  58. wgjs_bh3, wgjs_js3, rtrim(wgjs_yy3) as wgjs_yy3,
  59. wgjs_bh4, wgjs_js4, rtrim(wgjs_yy4) as wgjs_yy4,
  60. wgjs_bh5, wgjs_js5, rtrim(wgjs_yy5) as wgjs_yy5,
  61. wgjs_bh6, wgjs_js6, rtrim(wgjs_yy6) as wgjs_yy6')
  62. ->where($where)
  63. ->order('wgjs_rq desc, UniqId asc');
  64. // 执行分页/全量查询
  65. if ($usePagination) {
  66. $rows = $query->page($req['page'], $req['limit'])->select();
  67. $total = db()->table('db_wgjs')->where($where)->count();
  68. } else {
  69. $rows = $query->select();
  70. $total = count($rows); // 避免额外COUNT查询
  71. }
  72. // 获取员工基础数据
  73. $employees = db()->table('人事_基本资料')->column('员工编号, 员工姓名, 所在部门');
  74. // 数据处理优化
  75. foreach ($rows as &$row) {
  76. // 处理主员工信息
  77. $mainId = $row['wgjs_bh1'];
  78. $hasMain = isset($employees[$mainId]);
  79. $row['wgjs_js1'] = $row['wgjs_js1'] == 0 ? '' : $row['wgjs_js1'];
  80. $row['department'] = $hasMain ? trim($employees[$mainId]['所在部门']) : '';
  81. $row['name1'] = $hasMain ? trim($employees[$mainId]['员工姓名']) : '';
  82. // 处理2-6号员工信息
  83. for ($i = 2; $i <= 6; $i++) {
  84. $fieldId = $row["wgjs_bh$i"];
  85. $row["wgjs_js$i"] = $row["wgjs_js$i"] == '0.0' ? '' : $row["wgjs_js$i"];
  86. $row["name$i"] = ($fieldId && isset($employees[$fieldId]))
  87. ? trim($employees[$fieldId]['员工姓名'])
  88. : ($fieldId === $mainId ? $row['name1'] : '');
  89. }
  90. }
  91. $this->success('成功', [
  92. 'total' => $total,
  93. 'rows' => $rows
  94. ]);
  95. }
  96. /**
  97. * 获取计件工计时单信息
  98. * @ApiMethod (GET)
  99. * @param string $UniqId UniqId
  100. */
  101. public function getInfo()
  102. {
  103. //get请求
  104. if(!$this->request->isGet()){
  105. $this->error('请求方式错误');
  106. }
  107. $req = $this->request->param();
  108. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  109. $UniqId = $req['UniqId'];
  110. }else{
  111. $this->error('参数错误');
  112. }
  113. $rows = db()->table('糊盒报工机时')->alias('d')
  114. ->field('d.*, ')
  115. ->join('工单_基本资料 g', 'd.')
  116. ->where('d.UniqId',$UniqId)
  117. ->select();
  118. $this->success('成功',$rows);
  119. }
  120. /**
  121. * 定位
  122. * @ApiMethod GET
  123. */
  124. public function search(){
  125. if (Request::instance()->isGet() == false){
  126. $this->error('非法请求');
  127. }
  128. $req = Request::instance()->param();
  129. if (!isset($req['search']) || !isset($req['date'])){
  130. $this->error('参数错误');
  131. }
  132. $page = 1;
  133. $limit = 10;
  134. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  135. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  136. $year=substr($req['date'],0,4);
  137. $month=substr($req['date'],-2);
  138. $start_time = $year . '-' . $month . '-01 00:00:00';
  139. $end_time = date('Y-m-t', strtotime("$year-$month-01")) . ' 23:59:59';
  140. $yg = db()->table('人事_基本资料')->where('员工姓名',$req['search'])->value('员工编号');
  141. if($yg){
  142. $req['search']=$yg;
  143. }
  144. $where = [
  145. 'a.wgjs_rq'=>['between',"$start_time,$end_time"],
  146. 'a.wgjs_bh1|a.wgjs_bh2|a.wgjs_bh3|a.wgjs_bh4|a.wgjs_bh5|a.wgjs_bh6'=>['like', '%'.$req['search'].'%']
  147. ];
  148. $rows = db()->table('糊盒报工机时')
  149. ->alias('a')
  150. ->field('LEFT(a.wgjs_rq, 10) as wgjs_rq,
  151. a.wgjs_bh1,trim(rs1.所在部门) as 所在部门, a.wgjs_js1, rtrim(a.wgjs_yy1) as wgjs_yy1,
  152. a.wgjs_bh2, a.wgjs_js2, rtrim(a.wgjs_yy2) as wgjs_yy2,
  153. a.wgjs_bh3, a.wgjs_js3, rtrim(a.wgjs_yy3) as wgjs_yy3,
  154. a.wgjs_bh4, a.wgjs_js4, rtrim(a.wgjs_yy4) as wgjs_yy4,
  155. a.wgjs_bh5, a.wgjs_js5, rtrim(a.wgjs_yy5) as wgjs_yy5,
  156. a.wgjs_bh6, a.wgjs_js6, rtrim(a.wgjs_yy6) as wgjs_yy6,
  157. rtrim(rs1.员工姓名) as name1,rtrim(rs2.员工姓名) as name2,rtrim(rs3.员工姓名) as name3,
  158. rtrim(rs4.员工姓名) as name4,rtrim(rs5.员工姓名) as name5,rtrim(rs6.员工姓名) as name6,
  159. a.UniqId')
  160. ->join('人事_基本资料 rs1','rs1.员工编号=a.wgjs_bh1','LEFT')
  161. ->join('人事_基本资料 rs2','rs2.员工编号=a.wgjs_bh2','LEFT')
  162. ->join('人事_基本资料 rs3','rs3.员工编号=a.wgjs_bh3','LEFT')
  163. ->join('人事_基本资料 rs4','rs4.员工编号=a.wgjs_bh4','LEFT')
  164. ->join('人事_基本资料 rs5','rs5.员工编号=a.wgjs_bh5','LEFT')
  165. ->join('人事_基本资料 rs6','rs6.员工编号=a.wgjs_bh6','LEFT')
  166. ->where($where)
  167. ->order('wgjs_rq desc, UniqId asc')
  168. ->page($page,$limit)
  169. ->select();
  170. $total = db()->table('糊盒报工机时')->where($where)->count();
  171. $data = ['total'=> $total,'rows'=> $rows];
  172. if($rows){
  173. $this->success('成功',$data);
  174. }else{
  175. $this->error('失败');
  176. }
  177. }
  178. /**
  179. * 详情
  180. * @ApiMethod (GET)
  181. * @param string $wgjs_rq 日期
  182. * @param string $wgjs_bh1 员工编号
  183. */
  184. public function detail(){
  185. //get请求
  186. if(!$this->request->isGet()){
  187. $this->error('请求方式错误');
  188. }
  189. $req = $this->request->param();
  190. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  191. $this->error('参数错误','UniqId',100);
  192. }
  193. $rows = db('糊盒报工机时')
  194. ->alias('a')
  195. ->field('LEFT(a.wgjs_rq, 10) as wgjs_rq, a.UniqId,
  196. wgjs_bh1, wgjs_js1, rtrim(wgjs_yy1) as wgjs_yy1,
  197. wgjs_bh2, wgjs_js2, rtrim(wgjs_yy2) as wgjs_yy2,
  198. wgjs_bh3, wgjs_js3, rtrim(wgjs_yy3) as wgjs_yy3,
  199. wgjs_bh4, wgjs_js4, rtrim(wgjs_yy4) as wgjs_yy4,
  200. wgjs_bh5, wgjs_js5, rtrim(wgjs_yy5) as wgjs_yy5,
  201. wgjs_bh6, wgjs_js6, rtrim(wgjs_yy6) as wgjs_yy6,
  202. rtrim(rs1.员工姓名) as name1,rtrim(rs2.员工姓名) as name2,rtrim(rs3.员工姓名)
  203. as name3,rtrim(rs4.员工姓名) as name4,rtrim(rs5.员工姓名) as name5,rtrim(rs6.员工姓名)
  204. as name6')
  205. ->join('人事_基本资料 rs1','rs1.员工编号=a.wgjs_bh1','LEFT')
  206. ->join('人事_基本资料 rs2','rs2.员工编号=a.wgjs_bh2','LEFT')
  207. ->join('人事_基本资料 rs3','rs3.员工编号=a.wgjs_bh3','LEFT')
  208. ->join('人事_基本资料 rs4','rs4.员工编号=a.wgjs_bh4','LEFT')
  209. ->join('人事_基本资料 rs5','rs5.员工编号=a.wgjs_bh5','LEFT')
  210. ->join('人事_基本资料 rs6','rs6.员工编号=a.wgjs_bh6','LEFT')
  211. ->where('a.UniqId', $req['UniqId'])
  212. ->find();
  213. if($rows!==false){
  214. $this->success('成功',$rows);
  215. }else{
  216. $this->error('失败');
  217. }
  218. }
  219. /**
  220. * 修改
  221. * @ApiMethod POST
  222. */
  223. public function edit()
  224. {
  225. if(!$this->request->isPost()){
  226. $this->error('请求方式错误');
  227. }
  228. $req = Request::instance()->post();
  229. if (!isset($req['UniqId']) || empty($req['UniqId'])) {
  230. $this->error('参数错误','UniqId',100);
  231. }
  232. $arr = [
  233. 'wgjs_rq',
  234. 'wgjs_bh1', 'wgjs_bh2', 'wgjs_bh3', 'wgjs_bh4', 'wgjs_bh5', 'wgjs_bh6',
  235. 'wgjs_js1', 'wgjs_js2', 'wgjs_js3', 'wgjs_js4', 'wgjs_js5', 'wgjs_js6',
  236. 'wgjs_yy1', 'wgjs_yy2', 'wgjs_yy3', 'wgjs_yy4', 'wgjs_yy5', 'wgjs_yy6'
  237. ];
  238. $data = [];
  239. foreach ($arr as $key => $value){
  240. if (!isset($req[$value])){
  241. continue;
  242. }
  243. $data[$value] = $req[$value];
  244. }
  245. if (count($data)==0){
  246. $this->error('参数错误','',111);
  247. }
  248. $data['wgjs_rq'] = $req['wgjs_rq'].' 00:00:00';
  249. $data['mod_rq'] = date('Y-m-d H:i:s');
  250. //开启事务
  251. db()->startTrans();
  252. try{
  253. $sql = db('糊盒报工机时')->where('UniqId',$req['UniqId'])->fetchSql(true)->update($data);
  254. $bool = db()->query($sql);
  255. // 提交事务
  256. db()->commit();
  257. } catch (\Exception $e) {
  258. // 回滚事务
  259. db()->rollback();
  260. $this->error($e->getMessage());
  261. }
  262. if($bool===false) $this->error('失败');
  263. $this->success('成功');
  264. }
  265. /**
  266. * 新增
  267. * @ApiMethod POST
  268. */
  269. public function add()
  270. {
  271. if(!$this->request->isPost()){
  272. $this->error('请求方式错误');
  273. }
  274. $req = $this->request->param();
  275. if (!isset($req['wgjs_rq']) || !isset($req['wgjs_bh1']) || !isset($req['sys_id']) ){
  276. $this->error('参数错误');
  277. }
  278. if (empty($req['wgjs_rq']) || empty($req['wgjs_bh1']) || empty($req['sys_id'])){
  279. $this->error('参数不能为空');
  280. }
  281. $req['wgjs_rq'] = $req['wgjs_rq'].' 00:00:00';
  282. $req['sys_rq'] = date('Y-m-d H:i:s');
  283. //开启事务
  284. db()->startTrans();
  285. try{
  286. $sql = db()->table('糊盒报工机时')->fetchSql(true)->insert($req);
  287. $res= db()->query($sql);
  288. // 提交事务
  289. db()->commit();
  290. } catch (\Exception $e) {
  291. // 回滚事务
  292. db()->rollback();
  293. $this->error($e->getMessage());
  294. }
  295. if($res===false) $this->error('失败');
  296. $this->success('成功');
  297. }
  298. /**
  299. * 删除
  300. * @ApiMethod (GET)
  301. * @param string $wgjs_rq 日期
  302. * @param string $wgjs_bh1 员工编号
  303. */
  304. public function del(){
  305. //get请求
  306. if(!$this->request->isGet()){
  307. $this->error('请求方式错误');
  308. }
  309. $req = $this->request->param();
  310. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  311. $this->error('参数错误','UniqId',100);
  312. }
  313. //开启事务
  314. db()->startTrans();
  315. try{
  316. $bool = db('糊盒报工机时')->where('UniqId',$req['UniqId'])->delete();
  317. // 提交事务
  318. db()->commit();
  319. } catch (\Exception $e) {
  320. // 回滚事务
  321. db()->rollback();
  322. $this->error($e->getMessage());
  323. }
  324. if($bool===false) $this->error('失败');
  325. $this->success('成功');
  326. }
  327. /**
  328. * 糊盒班组计时报工
  329. * @return void
  330. * @throws \think\db\exception\DataNotFoundException
  331. * @throws \think\db\exception\ModelNotFoundException
  332. * @throws \think\exception\DbException
  333. * @throws \think\exception\PDOException
  334. */
  335. public function GluingReportClock()
  336. {
  337. if (!$this->request->isPost()) {
  338. $this->error('请求错误');
  339. }
  340. $param = $this->request->post();
  341. $validate = new \think\Validate([
  342. 'sczl_rq' => 'require',
  343. 'type' => 'require',
  344. ], [
  345. 'sczl_rq.require' => '请选择上报日期',
  346. 'type.require' => '请选择计时类型',
  347. ]);
  348. if (!$validate->check($param)) {
  349. $this->error($validate->getError());
  350. }
  351. $employeeFields = $this->parseGluingReportClockEmployeeFields($param);
  352. $data = array_merge([
  353. 'sczl_rq' => $param['sczl_rq'],
  354. 'type' => $param['type'],
  355. 'duration' => $param['duration'],
  356. 'price' => $param['price'],
  357. 'remark' => $param['remark'],
  358. 'sys_id' => $param['sys_id'],
  359. 'sys_rq' => date('Y-m-d H:i:s'),
  360. ], $employeeFields);
  361. if (\db('糊盒班组计时')->insert($data) === false) {
  362. $this->error('报工失败');
  363. }
  364. $this->success('报工成功');
  365. }
  366. /**
  367. * 糊盒班组计时报工删除
  368. * @return void
  369. * @throws \think\db\exception\DataNotFoundException
  370. * @throws \think\db\exception\ModelNotFoundException
  371. * @throws \think\exception\DbException
  372. * @throws \think\exception\PDOException
  373. */
  374. public function deleteGluingReportClock()
  375. {
  376. if (!$this->request->isPost()) {
  377. $this->error('请求错误');
  378. }
  379. $params = $this->request->param();
  380. if (!isset($params['id']) || empty($params['id'])){
  381. $this->error('参数错误');
  382. }
  383. $ids = explode(',', $params['id']);
  384. $res = \db('糊盒班组计时')->where('id', 'in', $ids)->delete();
  385. if ($res === false) {
  386. $this->error('删除失败');
  387. }
  388. $this->success('删除成功');
  389. }
  390. /**
  391. * 糊盒班组计时报工修改
  392. * @return void
  393. * @throws \think\db\exception\DataNotFoundException
  394. * @throws \think\db\exception\ModelNotFoundException
  395. * @throws \think\exception\DbException
  396. * @throws \think\exception\PDOException
  397. */
  398. public function updateGluingReportClock()
  399. {
  400. if (!$this->request->isPost()) {
  401. $this->error('请求错误');
  402. }
  403. $param = $this->request->post();
  404. if (!isset($param['id']) || empty($param['id'])) {
  405. $this->error('参数错误');
  406. }
  407. $validate = new \think\Validate([
  408. 'sczl_rq' => 'require',
  409. 'type' => 'require',
  410. ], [
  411. 'sczl_rq.require' => '请选择上报日期',
  412. 'type.require' => '请选择计时类型',
  413. ]);
  414. if (!$validate->check($param)) {
  415. $this->error($validate->getError());
  416. }
  417. $id = intval($param['id']);
  418. $employeeFields = $this->parseGluingReportClockEmployeeFields($param);
  419. $data = array_merge([
  420. 'sczl_rq' => $param['sczl_rq'],
  421. 'type' => $param['type'],
  422. 'duration' => $param['duration'],
  423. 'price' => $param['price'],
  424. 'remark' => $param['remark'],
  425. 'mod_rq' => date('Y-m-d H:i:s'),
  426. ], $employeeFields);
  427. $result = \db('糊盒班组计时')->where('id', $id)->update($data);
  428. if ($result === false) {
  429. $this->error('修改失败');
  430. }
  431. $this->success('修改成功');
  432. }
  433. /**
  434. * 糊盒班组计时报工列表
  435. * @return void
  436. * @throws \think\db\exception\DataNotFoundException
  437. * @throws \think\db\exception\ModelNotFoundException
  438. * @throws \think\exception\DbException
  439. * @throws \think\exception\PDOException
  440. */
  441. public function getGluingReportClockList()
  442. {
  443. if (!$this->request->isPost()) {
  444. $this->error('请求错误');
  445. }
  446. $params = $this->request->param();
  447. if (empty($params['sczl_rq'])) {
  448. $this->error('参数错误');
  449. }
  450. $bhFields = [];
  451. for ($i = 1; $i <= 30; $i++) {
  452. $bhFields[] = 'bh' . $i;
  453. }
  454. $list = \db('糊盒班组计时')
  455. ->field(array_merge([
  456. 'id as 编号',
  457. 'sczl_rq as 上报日期',
  458. 'type as 计时类型',
  459. 'duration as 工时',
  460. 'price as 单价',
  461. 'remark as 备注',
  462. 'sys_id as 创建人员',
  463. 'sys_rq as 上报时间',
  464. ], $bhFields))
  465. ->where('sczl_rq', $params['sczl_rq'])
  466. ->order('id desc')
  467. ->select();
  468. if (empty($list)) {
  469. $this->error('未找到报工数据');
  470. }
  471. $employeeIds = [];
  472. foreach ($list as $row) {
  473. for ($i = 1; $i <= 30; $i++) {
  474. $bh = isset($row['bh' . $i]) ? trim($row['bh' . $i]) : '';
  475. if ($bh !== '' && $bh !== '000000') {
  476. $employeeIds[$bh] = true;
  477. }
  478. }
  479. }
  480. $employeeNames = [];
  481. if (!empty($employeeIds)) {
  482. $employees = \db('人事_基本资料')
  483. ->whereIn('员工编号', array_keys($employeeIds))
  484. ->field('员工编号, rtrim(员工姓名) as 姓名')
  485. ->select();
  486. foreach ($employees as $employee) {
  487. $employeeNames[$employee['员工编号']] = $employee['姓名'];
  488. }
  489. }
  490. foreach ($list as $key => $row) {
  491. for ($i = 1; $i <= 30; $i++) {
  492. $bh = isset($row['bh' . $i]) ? trim($row['bh' . $i]) : '';
  493. $list[$key]['员工姓名' . $i] = ($bh !== '' && $bh !== '000000')
  494. ? ($employeeNames[$bh] ?? '')
  495. : '';
  496. }
  497. }
  498. $this->success('获取成功', $list);
  499. }
  500. /**
  501. * 糊盒班组计时报工左侧日期菜单
  502. * @return void
  503. * @throws \think\db\exception\DataNotFoundException
  504. * @throws \think\db\exception\ModelNotFoundException
  505. * @throws \think\exception\DbException
  506. * @throws \think\exception\PDOException
  507. */
  508. public function getGluingReportClockDateMenu()
  509. {
  510. if (!$this->request->isGet()) {
  511. $this->error('请求错误');
  512. }
  513. $list = \db('糊盒班组计时')
  514. ->field('DISTINCT(sczl_rq) as sczl_rq')
  515. ->order('sczl_rq desc')
  516. ->select();
  517. $data = [];
  518. foreach ($list as $value) {
  519. $timestamp = strtotime($value['sczl_rq']);
  520. $month = date('Y-m', $timestamp);
  521. $date = date('Y-m-d', $timestamp);
  522. if (!isset($data[$month])) {
  523. $data[$month] = [];
  524. }
  525. $data[$month][] = $date;
  526. }
  527. $this->success('获取成功', $data);
  528. }
  529. /**
  530. * 解析糊盒班组计时报工员工编号
  531. * @param array $param
  532. * @return array
  533. */
  534. private function parseGluingReportClockEmployeeFields($param)
  535. {
  536. $employeeFields = [];
  537. for ($i = 1; $i <= 30; $i++) {
  538. $employeeFields['bh' . $i] = '';
  539. }
  540. $hasEmployee = false;
  541. for ($i = 1; $i <= 30; $i++) {
  542. $bh = isset($param['bh' . $i]) ? trim($param['bh' . $i]) : '';
  543. if ($bh !== '') {
  544. if (!preg_match('/^[a-zA-Z0-9]+$/', $bh)) {
  545. $this->error('员工' . $i . '编号只能由英文字母和数字组成');
  546. }
  547. $employeeFields['bh' . $i] = $bh;
  548. $hasEmployee = true;
  549. continue;
  550. }
  551. for ($j = $i + 1; $j <= 30; $j++) {
  552. $laterBh = isset($param['bh' . $j]) ? trim($param['bh' . $j]) : '';
  553. if ($laterBh !== '') {
  554. $this->error('员工编号不能间隔填报,请先填写员工' . $i . '编号');
  555. }
  556. }
  557. break;
  558. }
  559. if (!$hasEmployee) {
  560. $this->error('请至少填写一个员工编号');
  561. }
  562. return $employeeFields;
  563. }
  564. /**
  565. * 糊盒报工数据详情
  566. * @return void
  567. * @throws \think\db\exception\DataNotFoundException
  568. * @throws \think\db\exception\ModelNotFoundException
  569. * @throws \think\exception\DbException
  570. * @throws \think\exception\PDOException
  571. */
  572. public function getGluingReportClockDataDetail()
  573. {
  574. if (!$this->request->isGet()) {
  575. $this->error('请求错误');
  576. }
  577. $params = $this->request->param();
  578. if (!isset($params['id']) || empty($params['id'])) {
  579. $this->error('参数错误');
  580. }
  581. $detail = \db('糊盒班组计时')
  582. ->where('id', $params['id'])
  583. ->find();
  584. if (empty($detail)) {
  585. $this->error('未找到报工数据');
  586. }
  587. $employeeIds = [];
  588. for ($i = 1; $i <= 30; $i++) {
  589. $bh = isset($detail['bh' . $i]) ? trim($detail['bh' . $i]) : '';
  590. if ($bh !== '' && $bh !== '000000') {
  591. $employeeIds[$bh] = true;
  592. }
  593. }
  594. $employeeNames = [];
  595. if (!empty($employeeIds)) {
  596. $employees = \db('人事_基本资料')
  597. ->whereIn('员工编号', array_keys($employeeIds))
  598. ->field('员工编号, rtrim(员工姓名) as 姓名')
  599. ->select();
  600. foreach ($employees as $employee) {
  601. $employeeNames[$employee['员工编号']] = $employee['姓名'];
  602. }
  603. }
  604. $detail['class'] = [];
  605. for ($i = 1; $i <= 30; $i++) {
  606. $bh = isset($detail['bh' . $i]) ? trim($detail['bh' . $i]) : '';
  607. if ($bh !== '' && $bh !== '000000') {
  608. $detail['class'][] = [
  609. '编号' => $bh,
  610. '姓名' => $employeeNames[$bh] ?? '',
  611. ];
  612. }
  613. }
  614. $this->success('获取成功', $detail);
  615. }
  616. }