GluChronographSheet.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  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, wgjs_je1,
  197. wgjs_bh2, wgjs_js2, rtrim(wgjs_yy2) as wgjs_yy2, wgjs_je2,
  198. wgjs_bh3, wgjs_js3, rtrim(wgjs_yy3) as wgjs_yy3, wgjs_je3,
  199. wgjs_bh4, wgjs_js4, rtrim(wgjs_yy4) as wgjs_yy4, wgjs_je4,
  200. wgjs_bh5, wgjs_js5, rtrim(wgjs_yy5) as wgjs_yy5, wgjs_je5,
  201. wgjs_bh6, wgjs_js6, rtrim(wgjs_yy6) as wgjs_yy6, wgjs_je6,
  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. 'wgjs_je1', 'wgjs_je2', 'wgjs_je3', 'wgjs_je4', 'wgjs_je5', 'wgjs_je6'
  238. ];
  239. $data = [];
  240. foreach ($arr as $key => $value){
  241. if (!isset($req[$value])){
  242. continue;
  243. }
  244. $data[$value] = $req[$value];
  245. }
  246. if (count($data)==0){
  247. $this->error('参数错误','',111);
  248. }
  249. $data['wgjs_rq'] = $req['wgjs_rq'].' 00:00:00';
  250. $data['mod_rq'] = date('Y-m-d H:i:s');
  251. //开启事务
  252. db()->startTrans();
  253. try{
  254. $sql = db('糊盒报工机时')->where('UniqId',$req['UniqId'])->fetchSql(true)->update($data);
  255. $bool = db()->query($sql);
  256. // 提交事务
  257. db()->commit();
  258. } catch (\Exception $e) {
  259. // 回滚事务
  260. db()->rollback();
  261. $this->error($e->getMessage());
  262. }
  263. if($bool===false) $this->error('失败');
  264. $this->success('成功');
  265. }
  266. /**
  267. * 新增
  268. * @ApiMethod POST
  269. */
  270. public function add()
  271. {
  272. if(!$this->request->isPost()){
  273. $this->error('请求方式错误');
  274. }
  275. $req = $this->request->param();
  276. if (!isset($req['wgjs_rq']) || !isset($req['wgjs_bh1']) || !isset($req['sys_id']) ){
  277. $this->error('参数错误');
  278. }
  279. if (empty($req['wgjs_rq']) || empty($req['wgjs_bh1']) || empty($req['sys_id'])){
  280. $this->error('参数不能为空');
  281. }
  282. $req['wgjs_rq'] = $req['wgjs_rq'].' 00:00:00';
  283. $req['sys_rq'] = date('Y-m-d H:i:s');
  284. //开启事务
  285. db()->startTrans();
  286. try{
  287. $sql = db()->table('糊盒报工机时')->fetchSql(true)->insert($req);
  288. $res= db()->query($sql);
  289. // 提交事务
  290. db()->commit();
  291. } catch (\Exception $e) {
  292. // 回滚事务
  293. db()->rollback();
  294. $this->error($e->getMessage());
  295. }
  296. if($res===false) $this->error('失败');
  297. $this->success('成功');
  298. }
  299. /**
  300. * 删除
  301. * @ApiMethod (GET)
  302. * @param string $wgjs_rq 日期
  303. * @param string $wgjs_bh1 员工编号
  304. */
  305. public function del(){
  306. //get请求
  307. if(!$this->request->isGet()){
  308. $this->error('请求方式错误');
  309. }
  310. $req = $this->request->param();
  311. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  312. $this->error('参数错误','UniqId',100);
  313. }
  314. //开启事务
  315. db()->startTrans();
  316. try{
  317. $bool = db('糊盒报工机时')->where('UniqId',$req['UniqId'])->delete();
  318. // 提交事务
  319. db()->commit();
  320. } catch (\Exception $e) {
  321. // 回滚事务
  322. db()->rollback();
  323. $this->error($e->getMessage());
  324. }
  325. if($bool===false) $this->error('失败');
  326. $this->success('成功');
  327. }
  328. /**
  329. * 糊盒班组计时报工
  330. * @return void
  331. * @throws \think\db\exception\DataNotFoundException
  332. * @throws \think\db\exception\ModelNotFoundException
  333. * @throws \think\exception\DbException
  334. * @throws \think\exception\PDOException
  335. */
  336. public function GluingReportClock()
  337. {
  338. if (!$this->request->isPost()) {
  339. $this->error('请求错误');
  340. }
  341. $param = $this->request->post();
  342. $validate = new \think\Validate([
  343. 'sczl_rq' => 'require',
  344. 'type' => 'require',
  345. ], [
  346. 'sczl_rq.require' => '请选择上报日期',
  347. 'type.require' => '请选择计时类型',
  348. ]);
  349. if (!$validate->check($param)) {
  350. $this->error($validate->getError());
  351. }
  352. $employeeFields = $this->parseGluingReportClockEmployeeFields($param);
  353. $data = array_merge([
  354. 'sczl_rq' => $param['sczl_rq'],
  355. 'type' => $param['type'],
  356. 'duration' => $param['duration'],
  357. 'price' => $param['price'],
  358. 'remark' => $param['remark'],
  359. 'sys_id' => $param['sys_id'],
  360. 'sys_rq' => date('Y-m-d H:i:s'),
  361. ], $employeeFields);
  362. if (\db('糊盒班组计时')->insert($data) === false) {
  363. $this->error('报工失败');
  364. }
  365. $this->success('报工成功');
  366. }
  367. /**
  368. * 糊盒班组计时报工删除
  369. * @return void
  370. * @throws \think\db\exception\DataNotFoundException
  371. * @throws \think\db\exception\ModelNotFoundException
  372. * @throws \think\exception\DbException
  373. * @throws \think\exception\PDOException
  374. */
  375. public function deleteGluingReportClock()
  376. {
  377. if (!$this->request->isPost()) {
  378. $this->error('请求错误');
  379. }
  380. $params = $this->request->param();
  381. if (!isset($params['id']) || empty($params['id'])){
  382. $this->error('参数错误');
  383. }
  384. $ids = explode(',', $params['id']);
  385. $res = \db('糊盒班组计时')->where('id', 'in', $ids)->delete();
  386. if ($res === false) {
  387. $this->error('删除失败');
  388. }
  389. $this->success('删除成功');
  390. }
  391. /**
  392. * 糊盒班组计时报工修改
  393. * @return void
  394. * @throws \think\db\exception\DataNotFoundException
  395. * @throws \think\db\exception\ModelNotFoundException
  396. * @throws \think\exception\DbException
  397. * @throws \think\exception\PDOException
  398. */
  399. public function updateGluingReportClock()
  400. {
  401. if (!$this->request->isPost()) {
  402. $this->error('请求错误');
  403. }
  404. $param = $this->request->post();
  405. if (!isset($param['id']) || empty($param['id'])) {
  406. $this->error('参数错误');
  407. }
  408. $validate = new \think\Validate([
  409. 'sczl_rq' => 'require',
  410. 'type' => 'require',
  411. ], [
  412. 'sczl_rq.require' => '请选择上报日期',
  413. 'type.require' => '请选择计时类型',
  414. ]);
  415. if (!$validate->check($param)) {
  416. $this->error($validate->getError());
  417. }
  418. $id = intval($param['id']);
  419. $employeeFields = $this->parseGluingReportClockEmployeeFields($param);
  420. $data = array_merge([
  421. 'sczl_rq' => $param['sczl_rq'],
  422. 'type' => $param['type'],
  423. 'duration' => $param['duration'],
  424. 'price' => $param['price'],
  425. 'remark' => $param['remark'],
  426. 'mod_rq' => date('Y-m-d H:i:s'),
  427. ], $employeeFields);
  428. $result = \db('糊盒班组计时')->where('id', $id)->update($data);
  429. if ($result === false) {
  430. $this->error('修改失败');
  431. }
  432. $this->success('修改成功');
  433. }
  434. /**
  435. * 糊盒班组计时报工列表
  436. * @return void
  437. * @throws \think\db\exception\DataNotFoundException
  438. * @throws \think\db\exception\ModelNotFoundException
  439. * @throws \think\exception\DbException
  440. * @throws \think\exception\PDOException
  441. */
  442. public function getGluingReportClockList()
  443. {
  444. if (!$this->request->isPost()) {
  445. $this->error('请求错误');
  446. }
  447. $params = $this->request->param();
  448. if (empty($params['sczl_rq'])) {
  449. $this->error('参数错误');
  450. }
  451. $bhFields = [];
  452. for ($i = 1; $i <= 30; $i++) {
  453. $bhFields[] = 'bh' . $i;
  454. }
  455. $list = \db('糊盒班组计时')
  456. ->field(array_merge([
  457. 'id as 编号',
  458. 'sczl_rq as 上报日期',
  459. 'type as 计时类型',
  460. 'duration as 工时',
  461. 'price as 单价',
  462. 'remark as 备注',
  463. 'sys_id as 创建人员',
  464. 'sys_rq as 上报时间',
  465. ], $bhFields))
  466. ->where('sczl_rq', $params['sczl_rq'])
  467. ->order('id desc')
  468. ->select();
  469. if (empty($list)) {
  470. $this->error('未找到报工数据');
  471. }
  472. $employeeIds = [];
  473. foreach ($list as $row) {
  474. for ($i = 1; $i <= 30; $i++) {
  475. $bh = isset($row['bh' . $i]) ? trim($row['bh' . $i]) : '';
  476. if ($bh !== '' && $bh !== '000000') {
  477. $employeeIds[$bh] = true;
  478. }
  479. }
  480. }
  481. $employeeNames = [];
  482. if (!empty($employeeIds)) {
  483. $employees = \db('人事_基本资料')
  484. ->whereIn('员工编号', array_keys($employeeIds))
  485. ->field('员工编号, rtrim(员工姓名) as 姓名')
  486. ->select();
  487. foreach ($employees as $employee) {
  488. $employeeNames[$employee['员工编号']] = $employee['姓名'];
  489. }
  490. }
  491. foreach ($list as $key => $row) {
  492. for ($i = 1; $i <= 30; $i++) {
  493. $bh = isset($row['bh' . $i]) ? trim($row['bh' . $i]) : '';
  494. $list[$key]['员工姓名' . $i] = ($bh !== '' && $bh !== '000000')
  495. ? ($employeeNames[$bh] ?? '')
  496. : '';
  497. }
  498. }
  499. $this->success('获取成功', $list);
  500. }
  501. /**
  502. * 糊盒班组计时报工左侧日期菜单
  503. * @return void
  504. * @throws \think\db\exception\DataNotFoundException
  505. * @throws \think\db\exception\ModelNotFoundException
  506. * @throws \think\exception\DbException
  507. * @throws \think\exception\PDOException
  508. */
  509. public function getGluingReportClockDateMenu()
  510. {
  511. if (!$this->request->isGet()) {
  512. $this->error('请求错误');
  513. }
  514. $list = \db('糊盒班组计时')
  515. ->field('DISTINCT(sczl_rq) as sczl_rq')
  516. ->order('sczl_rq desc')
  517. ->select();
  518. $data = [];
  519. foreach ($list as $value) {
  520. $timestamp = strtotime($value['sczl_rq']);
  521. $month = date('Y-m', $timestamp);
  522. $date = date('Y-m-d', $timestamp);
  523. if (!isset($data[$month])) {
  524. $data[$month] = [];
  525. }
  526. $data[$month][] = $date;
  527. }
  528. $this->success('获取成功', $data);
  529. }
  530. /**
  531. * 解析糊盒班组计时报工员工编号
  532. * @param array $param
  533. * @return array
  534. */
  535. private function parseGluingReportClockEmployeeFields($param)
  536. {
  537. $employeeFields = [];
  538. for ($i = 1; $i <= 30; $i++) {
  539. $employeeFields['bh' . $i] = '';
  540. }
  541. $hasEmployee = false;
  542. for ($i = 1; $i <= 30; $i++) {
  543. $bh = isset($param['bh' . $i]) ? trim($param['bh' . $i]) : '';
  544. if ($bh !== '') {
  545. if (!preg_match('/^[a-zA-Z0-9]+$/', $bh)) {
  546. $this->error('员工' . $i . '编号只能由英文字母和数字组成');
  547. }
  548. $employeeFields['bh' . $i] = $bh;
  549. $hasEmployee = true;
  550. continue;
  551. }
  552. for ($j = $i + 1; $j <= 30; $j++) {
  553. $laterBh = isset($param['bh' . $j]) ? trim($param['bh' . $j]) : '';
  554. if ($laterBh !== '') {
  555. $this->error('员工编号不能间隔填报,请先填写员工' . $i . '编号');
  556. }
  557. }
  558. break;
  559. }
  560. if (!$hasEmployee) {
  561. $this->error('请至少填写一个员工编号');
  562. }
  563. return $employeeFields;
  564. }
  565. /**
  566. * 糊盒报工数据详情
  567. * @return void
  568. * @throws \think\db\exception\DataNotFoundException
  569. * @throws \think\db\exception\ModelNotFoundException
  570. * @throws \think\exception\DbException
  571. * @throws \think\exception\PDOException
  572. */
  573. public function getGluingReportClockDataDetail()
  574. {
  575. if (!$this->request->isGet()) {
  576. $this->error('请求错误');
  577. }
  578. $params = $this->request->param();
  579. if (!isset($params['id']) || empty($params['id'])) {
  580. $this->error('参数错误');
  581. }
  582. $detail = \db('糊盒班组计时')
  583. ->where('id', $params['id'])
  584. ->find();
  585. if (empty($detail)) {
  586. $this->error('未找到报工数据');
  587. }
  588. $employeeIds = [];
  589. for ($i = 1; $i <= 30; $i++) {
  590. $bh = isset($detail['bh' . $i]) ? trim($detail['bh' . $i]) : '';
  591. if ($bh !== '' && $bh !== '000000') {
  592. $employeeIds[$bh] = true;
  593. }
  594. }
  595. $employeeNames = [];
  596. if (!empty($employeeIds)) {
  597. $employees = \db('人事_基本资料')
  598. ->whereIn('员工编号', array_keys($employeeIds))
  599. ->field('员工编号, rtrim(员工姓名) as 姓名')
  600. ->select();
  601. foreach ($employees as $employee) {
  602. $employeeNames[$employee['员工编号']] = $employee['姓名'];
  603. }
  604. }
  605. $detail['class'] = [];
  606. for ($i = 1; $i <= 30; $i++) {
  607. $bh = isset($detail['bh' . $i]) ? trim($detail['bh' . $i]) : '';
  608. if ($bh !== '' && $bh !== '000000') {
  609. $detail['class'][] = [
  610. '编号' => $bh,
  611. '姓名' => $employeeNames[$bh] ?? '',
  612. ];
  613. }
  614. }
  615. $this->success('获取成功', $detail);
  616. }
  617. }