success('请求成功'); } /** * 获取计件工计时单侧边栏 * @ApiMethod (GET) */ public function getTab() { //get请求 if(!$this->request->isGet()){ $this->error('请求方式错误'); } $rows = db()->table('db_wgjs') ->field('LEFT(wgjs_rq, 7) as date') ->group('date') ->order('UniqId desc') ->limit(15) ->select(); foreach($rows as $key=>$value){ $rows[$key]['date'] = str_replace('-', '', $rows[$key]['date']); } $this->success('成功',$rows); } /** * 获取计件工计时单列表 * @ApiMethod (GET) * @param string $date 时间 * @param string $Sczl_bh1 员工编号 */ public function getList() { //get请求 if(!$this->request->isGet()){ $this->error('请求方式错误'); } $req = $this->request->param(); $page = 1; $limit = 15; if (isset($req['page']) && !empty($req['page'])) $page = $req['page']; if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit']; $where = []; if (isset($req['date']) && !empty($req['date'])){ $where['wgjs_rq'] = ['LIKE',$req['date'].'%']; }else{ $this->error('参数错误'); } $rows = db()->table('db_wgjs') ->field('LEFT(wgjs_rq, 10) as wgjs_rq, UniqId, wgjs_bh1, CAST(wgjs_js1 AS SIGNED) as wgjs_js1, rtrim(wgjs_yy1) as wgjs_yy1, wgjs_bh2, CAST(wgjs_js2 AS SIGNED) as wgjs_js2, rtrim(wgjs_yy2) as wgjs_yy2, wgjs_bh3, CAST(wgjs_js3 AS SIGNED) as wgjs_js3, rtrim(wgjs_yy3) as wgjs_yy3, wgjs_bh4, CAST(wgjs_js4 AS SIGNED) as wgjs_js4, rtrim(wgjs_yy4) as wgjs_yy4, wgjs_bh5, CAST(wgjs_js5 AS SIGNED) as wgjs_js5, rtrim(wgjs_yy5) as wgjs_yy5, wgjs_bh6, CAST(wgjs_js6 AS SIGNED) as wgjs_js6, rtrim(wgjs_yy6) as wgjs_yy6') ->where($where) ->order('wgjs_rq desc, UniqId asc') ->page($page,$limit) ->select(); $total = db()->table('db_wgjs')->where($where)->count(); $rs = db()->table('人事_基本资料')->column('员工编号, 员工姓名, 所在部门'); foreach ($rows as $key=>$value){ $rows[$key]['wgjs_js1'] = $value['wgjs_js1'] == 0 ? '' : $value['wgjs_js1']; //存在该员工编号 if (array_key_exists($value['wgjs_bh1'],$rs)){ $rows[$key]['department'] = trim($rs[$value['wgjs_bh1']]['所在部门']); $rows[$key]['name1'] = trim($rs[$value['wgjs_bh1']]['员工姓名']); for ($i=2;$i<=6;$i++){ $rows[$key]['wgjs_js'.$i] = $value['wgjs_js'.$i] == '0.0' ? '' : $value['wgjs_js'.$i]; if ($value['wgjs_bh'.$i]){ if ($value['wgjs_bh'.$i]==$value['wgjs_bh1']){ $rows[$key]['name'.$i] = $rows[$key]['name1']; }else{ $rows[$key]['name'.$i] = trim($rs[$value['wgjs_bh'.$i]]['员工姓名']); } }else{ $rows[$key]['name'.$i] = ''; } } }else{ $rows[$key]['department'] = ''; $rows[$key]['name1'] = ''; for ($i=2;$i<=6;$i++){ $rows[$key]['wgjs_js'.$i] = $value['wgjs_js'.$i] == '0.0' ? '' : $value['wgjs_js'.$i]; $rows[$key]['name'.$i] = ''; } } } $data = [ 'total' => $total, 'rows' => $rows, ]; $this->success('成功',$data); } /** * 获取计件工计时单信息 * @ApiMethod (GET) * @param string $UniqId UniqId */ public function getInfo() { //get请求 if(!$this->request->isGet()){ $this->error('请求方式错误'); } $req = $this->request->param(); if (isset($req['UniqId']) && !empty($req['UniqId'])){ $UniqId = $req['UniqId']; }else{ $this->error('参数错误'); } $rows = db()->table('db_wgjs')->alias('d') ->field('d.*, ') ->join('工单_基本资料 g', 'd.') ->where('d.UniqId',$UniqId) ->select(); $this->success('成功',$rows); } /** * 定位 * @ApiMethod GET */ public function search(){ if (Request::instance()->isGet() == false){ $this->error('非法请求'); } $req = Request::instance()->param(); if (!isset($req['search']) || !isset($req['date'])){ $this->error('参数错误'); } $page = 1; $limit = 10; if (isset($req['page']) && !empty($req['page'])) $page = $req['page']; if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit']; $year=substr($req['date'],0,4); $month=substr($req['date'],-2); $start_time = $year . '-' . $month . '-01 00:00:00'; $end_time = date('Y-m-t', strtotime("$year-$month-01")) . ' 23:59:59'; $yg = db()->table('人事_基本资料')->where('员工姓名',$req['search'])->value('员工编号'); if($yg){ $req['search']=$yg; } $where = [ 'db_wgjs.wgjs_rq'=>['between',"$start_time,$end_time"], 'db_wgjs.wgjs_bh1|db_wgjs.wgjs_bh2|db_wgjs.wgjs_bh3|db_wgjs.wgjs_bh4|db_wgjs.wgjs_bh5|db_wgjs.wgjs_bh6'=>['like', '%'.$req['search'].'%'] ]; $rows = db()->table('db_wgjs') ->field('LEFT(db_wgjs.wgjs_rq, 10) as wgjs_rq, db_wgjs.wgjs_bh1,trim(rs1.所在部门) as 所在部门, CAST(db_wgjs.wgjs_js1 AS SIGNED) as wgjs_js1, rtrim(db_wgjs.wgjs_yy1) as wgjs_yy1, db_wgjs.wgjs_bh2, CAST(db_wgjs.wgjs_js2 AS SIGNED) as wgjs_js2, rtrim(db_wgjs.wgjs_yy2) as wgjs_yy2, db_wgjs.wgjs_bh3, CAST(db_wgjs.wgjs_js3 AS SIGNED) as wgjs_js3, rtrim(db_wgjs.wgjs_yy3) as wgjs_yy3, db_wgjs.wgjs_bh4, CAST(db_wgjs.wgjs_js4 AS SIGNED) as wgjs_js4, rtrim(db_wgjs.wgjs_yy4) as wgjs_yy4, db_wgjs.wgjs_bh5, CAST(db_wgjs.wgjs_js5 AS SIGNED) as wgjs_js5, rtrim(db_wgjs.wgjs_yy5) as wgjs_yy5, db_wgjs.wgjs_bh6, CAST(db_wgjs.wgjs_js6 AS SIGNED) as wgjs_js6, rtrim(db_wgjs.wgjs_yy6) as wgjs_yy6, rtrim(rs1.员工姓名) as name1,rtrim(rs2.员工姓名) as name2,rtrim(rs3.员工姓名) as name3, rtrim(rs4.员工姓名) as name4,rtrim(rs5.员工姓名) as name5,rtrim(rs6.员工姓名) as name6, db_wgjs.UniqId') ->join('人事_基本资料 rs1','rs1.员工编号=db_wgjs.wgjs_bh1','LEFT') ->join('人事_基本资料 rs2','rs2.员工编号=db_wgjs.wgjs_bh2','LEFT') ->join('人事_基本资料 rs3','rs3.员工编号=db_wgjs.wgjs_bh3','LEFT') ->join('人事_基本资料 rs4','rs4.员工编号=db_wgjs.wgjs_bh4','LEFT') ->join('人事_基本资料 rs5','rs5.员工编号=db_wgjs.wgjs_bh5','LEFT') ->join('人事_基本资料 rs6','rs6.员工编号=db_wgjs.wgjs_bh6','LEFT') ->where($where) ->order('wgjs_rq desc, UniqId asc') ->page($page,$limit) ->select(); $total = db()->table('db_wgjs')->where($where)->count(); $data = ['total'=> $total,'rows'=> $rows]; if($rows){ $this->success('成功',$data); }else{ $this->error('失败'); } } /** * 详情 * @ApiMethod (GET) * @param string $wgjs_rq 日期 * @param string $wgjs_bh1 员工编号 */ public function detail(){ //get请求 if(!$this->request->isGet()){ $this->error('请求方式错误'); } $req = $this->request->param(); if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){ $this->error('参数错误','UniqId',100); } $rows = db('db_wgjs') ->field('LEFT(wgjs_rq, 10) as wgjs_rq, db_wgjs.UniqId, wgjs_bh1, CAST(wgjs_js1 AS SIGNED) as wgjs_js1, rtrim(wgjs_yy1) as wgjs_yy1, wgjs_bh2, CAST(wgjs_js2 AS SIGNED) as wgjs_js2, rtrim(wgjs_yy2) as wgjs_yy2, wgjs_bh3, CAST(wgjs_js3 AS SIGNED) as wgjs_js3, rtrim(wgjs_yy3) as wgjs_yy3, wgjs_bh4, CAST(wgjs_js4 AS SIGNED) as wgjs_js4, rtrim(wgjs_yy4) as wgjs_yy4, wgjs_bh5, CAST(wgjs_js5 AS SIGNED) as wgjs_js5, rtrim(wgjs_yy5) as wgjs_yy5, wgjs_bh6, CAST(wgjs_js6 AS SIGNED) as wgjs_js6, rtrim(wgjs_yy6) as wgjs_yy6, rtrim(rs1.员工姓名) as name1,rtrim(rs2.员工姓名) as name2,rtrim(rs3.员工姓名) as name3,rtrim(rs4.员工姓名) as name4,rtrim(rs5.员工姓名) as name5,rtrim(rs6.员工姓名) as name6,wgjs_冲定额1,wgjs_冲定额2,wgjs_冲定额3,wgjs_冲定额4,wgjs_冲定额5,wgjs_冲定额6') ->join('人事_基本资料 rs1','rs1.员工编号=db_wgjs.wgjs_bh1','LEFT') ->join('人事_基本资料 rs2','rs2.员工编号=db_wgjs.wgjs_bh2','LEFT') ->join('人事_基本资料 rs3','rs3.员工编号=db_wgjs.wgjs_bh3','LEFT') ->join('人事_基本资料 rs4','rs4.员工编号=db_wgjs.wgjs_bh4','LEFT') ->join('人事_基本资料 rs5','rs5.员工编号=db_wgjs.wgjs_bh5','LEFT') ->join('人事_基本资料 rs6','rs6.员工编号=db_wgjs.wgjs_bh6','LEFT') ->where('db_wgjs.UniqId', $req['UniqId']) ->find(); if($rows!==false){ $this->success('成功',$rows); }else{ $this->error('失败'); } } /** * 修改 * @ApiMethod POST */ public function edit() { if(!$this->request->isPost()){ $this->error('请求方式错误'); } $req = $this->request->param(); if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){ $this->error('参数错误','UniqId',100); } $arr = [ 'wgjs_rq', 'wgjs_bh1', 'wgjs_bh2', 'wgjs_bh3', 'wgjs_bh4', 'wgjs_bh5', 'wgjs_bh6', 'wgjs_js1', 'wgjs_js2', 'wgjs_js3', 'wgjs_js4', 'wgjs_js5', 'wgjs_js6', 'wgjs_yy1', 'wgjs_yy2', 'wgjs_yy3', 'wgjs_yy4', 'wgjs_yy5', 'wgjs_yy6', 'wgjs_冲定额1', 'wgjs_冲定额2', 'wgjs_冲定额3', 'wgjs_冲定额4', 'wgjs_冲定额5', 'wgjs_冲定额6' ]; $data = []; foreach ($arr as $key => $value){ if (!isset($req[$value])){ continue; } $data[$value] = $req[$value]; } if (count($data)==0){ $this->error('参数错误','',111); } $data['wgjs_rq'] = $req['wgjs_rq'].' 00:00:00'; $data['mod_rq'] = date('Y-m-d H:i:s'); //开启事务 db()->startTrans(); try{ $sql = db('db_wgjs')->where('UniqId',$req['UniqId'])->fetchSql(true)->update($data); $bool = db()->query($sql); // 提交事务 db()->commit(); } catch (\Exception $e) { // 回滚事务 db()->rollback(); $this->error($e->getMessage()); } if($bool===false) $this->error('失败'); $this->success('成功'); } /** * 新增 * @ApiMethod POST */ public function add() { if(!$this->request->isPost()){ $this->error('请求方式错误'); } $req = $this->request->param(); if (!isset($req['wgjs_rq']) || !isset($req['wgjs_bh1']) || !isset($req['sys_id']) ){ $this->error('参数错误'); } if (empty($req['wgjs_rq']) || empty($req['wgjs_bh1']) || empty($req['sys_id'])){ $this->error('参数不能为空'); } $UniqId = db()->table('db_wgjs')->order('UniqId desc')->value('UniqId'); if ($UniqId < 1000000){ $UniqId = 1000000; }else{ $UniqId = $UniqId + 1; } $req['wgjs_rq'] = $req['wgjs_rq'].' 00:00:00'; $req['sys_rq'] = date('Y-m-d H:i:s'); $req['UniqId'] = $UniqId; $req['sys_id'] = $req['sys_id']; //开启事务 db()->startTrans(); try{ $sql = db()->table('db_wgjs')->fetchSql(true)->insert($req); $res= db()->query($sql); // 提交事务 db()->commit(); } catch (\Exception $e) { // 回滚事务 db()->rollback(); $this->error($e->getMessage()); } if($res===false) $this->error('失败'); $this->success('成功'); } /** * 删除 * @ApiMethod (GET) * @param string $wgjs_rq 日期 * @param string $wgjs_bh1 员工编号 */ public function del(){ //get请求 if(!$this->request->isGet()){ $this->error('请求方式错误'); } $req = $this->request->param(); if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){ $this->error('参数错误','UniqId',100); } //开启事务 db()->startTrans(); try{ $bool = db('db_wgjs')->where('UniqId',$req['UniqId'])->delete(); // 提交事务 db()->commit(); } catch (\Exception $e) { // 回滚事务 db()->rollback(); $this->error($e->getMessage()); } if($bool===false) $this->error('失败'); $this->success('成功'); } }