success('请求成功'); } /** * 获取工单抽检记录侧边栏 * @ApiMethod (GET) */ public function getTab() { //get请求 if(!$this->request->isGet()){ $this->error('请求方式错误'); } $rows = db()->table('db_抽检记录1') ->field('LEFT(Sys_rq, 10) as date, COUNT(*) as counts') ->group('date') ->order('UniqId desc') ->limit(45) ->select(); $arr = db()->table('db_抽检记录1') ->field('LEFT(Sys_rq, 10) as date, rtrim(Sys_id) as Sys_id, COUNT(Sys_id) as count') ->where('Sys_rq','>=',$rows[44]['date']) ->group('date, Sys_id') ->order('UniqId desc') ->select(); foreach($rows as $key=>$value){ $rows[$key]['sys'] = []; foreach($arr as $k=>$v){ if($value['date'] == $v['date']){ unset($v['date']); array_push($rows[$key]['sys'],$v); unset($arr[$k]); } } $rows[$key]['date'] = str_replace('-', '.', $rows[$key]['date']); } $this->success('成功',$rows); } /** * 获取工单抽检记录列表 * @ApiMethod (GET) * @param string $date 时间 * @param string $sys_id 用户 */ 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['Sys_rq'] = ['LIKE',$req['date'].'%']; }else{ $this->error('参数错误'); } if (isset($req['sys_id']) && !empty($req['sys_id'])) $where['Sys_id'] = ['LIKE','%'.$req['sys_id'].'%']; $rows = db()->table('db_抽检记录1') ->field('LEFT(Sczl_rq, 10) as Sczl_rq, Sczl_bh, Sczl_gdbh, rtrim(Sczl_gxmc) as Sczl_gxmc, sczl_yjno, sczl_gxh, Sczl_num, Sczl_抽检数, sczl_A类废, sczl_B类废, sczl_C类废, rtrim(Sczl_desc) as Sczl_desc, rtrim(Sys_id) as Sys_id, Sys_rq, Mod_rq, UniqId') ->where($where) ->order('UniqId asc') ->page($page,$limit) ->select(); $total = db()->table('db_抽检记录1')->where($where)->count(); $gd = db()->table('工单_基本资料')->column('Gd_gdbh, Gd_cpmc'); $rs = db()->table('人事_基本资料')->column('员工编号, 员工姓名'); foreach ($rows as $key=>$value) { $rows[$key]['sczl_A类废'] = $value['sczl_A类废']==0 ? '' :$value['sczl_A类废']; $rows[$key]['sczl_B类废'] = $value['sczl_B类废']==0 ? '' :$value['sczl_B类废']; $rows[$key]['sczl_C类废'] = $value['sczl_C类废']==0 ? '' :$value['sczl_C类废']; $rows[$key]['Mod_rq'] = $value['Mod_rq']=='1900-01-01 00:00:00' ? '' :$value['Mod_rq']; $rows[$key]['Gd_cpmc'] = array_key_exists($value['Sczl_gdbh'],$gd) ? trim($gd[$value['Sczl_gdbh']]) : ''; $rows[$key]['name'] = array_key_exists($value['Sczl_bh'],$rs) ? trim($rs[$value['Sczl_bh']]) : ''; } $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_抽检记录1') ->field('Sczl_bh,rs.员工姓名 as name,sczl_bzdh,LEFT(Sczl_rq, 10) as Sczl_rq,Sczl_gdbh,g.Gd_cpmc, Sczl_gxmc,sczl_gxh,Sczl_num,Sczl_抽检数,Sczl_A类废,Sczl_B类废,Sczl_C类废,Sczl_desc') ->join('人事_基本资料 rs','rs.员工编号=db_抽检记录1.Sczl_bh','LEFT') ->join('工单_基本资料 g','g.Gd_gdbh=db_抽检记录1.Sczl_gdbh','LEFT') ->where('db_抽检记录1.UniqId',$UniqId)->select(); $this->success('成功',$rows); } /** * 修改 * @ApiMethod POST */ public function edit() { if(!$this->request->isPost()){ $this->error('请求方式错误'); } $req = $this->request->param(); if (isset($req['UniqId']) && !empty($req['UniqId'])){ $UniqId = $req['UniqId']; }else{ $this->error('参数错误'); } $req['wgjs_rq'] = $req['wgjs_rq'].' 00:00:00'; $req['mod_rq'] = date('Y-m-d H:i:s'); //开启事务 db()->startTrans(); try{ $sql = db()->table('db_wgjs1')->where(['wgjs_rq'=>$req['wgjs_rq'],'wgjs_bh1'=>$req['wgjs_bh1']]) ->fetchSql(true)->update($req); $res= db()->query($sql); // 提交事务 db()->commit(); } catch (\Exception $e) { // 回滚事务 db()->rollback(); $this->error($e->getMessage()); } if($res===false) $this->error('失败'); $this->success('成功'); } /** * 新增 * @ApiMethod POST */ public function add() { if(!$this->request->isPost()){ $this->error('请求方式错误'); } $req = $this->request->param(); if (isset($req['UniqId']) && !empty($req['UniqId'])){ $UniqId = $req['UniqId']; }else{ $this->error('参数错误'); } $req['wgjs_rq'] = $req['wgjs_rq'].' 00:00:00'; $req['sys_rq'] = date('Y-m-d H:i:s'); //开启事务 db()->startTrans(); try{ $sql = db()->table('db_wgjs1')->where(['wgjs_rq'=>$req['wgjs_rq'],'wgjs_bh1'=>$req['wgjs_bh1']]) ->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 $UniqId UniqId */ public function del(){ //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_抽检记录1')->where('UniqId',$UniqId)->delete(); if($rows){ $this->success('成功'); }else{ $this->error('失败'); } } }