success('请求成功'); } /** * 获取工单抽检记录侧边栏 * @ApiMethod (GET) */ public function getTab() { //get请求 if(!$this->request->isGet()){ $this->error('请求方式错误'); } $rows = db()->table('db_抽检记录') ->field('LEFT(Sys_rq, 10) as date, COUNT(*) as counts') ->group('date') ->order('UniqId desc') ->limit(45) ->select(); $arr = db()->table('db_抽检记录') ->field('LEFT(Sys_rq, 10) as date, rtrim(Sys_id) as Sys_id, COUNT(*) as count') ->where('Sys_rq','>=',$rows[count($rows)-1]['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) */ public function getTabByGdbh() { //get请求 if(!$this->request->isGet()){ $this->error('请求方式错误'); } $date = date('Y-m-d',strtotime("-1 year")); $rows = db()->table('db_抽检记录')->alias('d')->cache(true) ->field('d.Sczl_gdbh, rtrim(y.Gd_cpmc) as Gd_cpmc') ->join('工单_基本资料 y','y.Gd_gdbh = d.Sczl_gdbh','left') // ->where('d.sys_rq','>=',$date) ->group('d.Sczl_gdbh') ->order('d.Sczl_gdbh desc') ->limit(65) ->select(); $arr = db()->table('db_抽检记录')->cache(true) ->field('Sczl_gdbh, rtrim(Sys_id) as Sys_id, COUNT(*) as count') ->where('Sczl_gdbh','>=',$rows[count($rows)-1]['Sczl_gdbh']) ->group('Sczl_gdbh, Sys_id') ->select(); foreach($rows as $key=>$value){ $rows[$key]['sys'] = []; foreach($arr as $k=>$v){ if($value['Sczl_gdbh'] == $v['Sczl_gdbh']){ unset($v['Sczl_gdbh']); array_push($rows[$key]['sys'],$v); unset($arr[$k]); } } } $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'])){ if(strpos($req['date'],'-')){ $where['Sys_rq'] = ['like',$req['date'].'%']; }else{ $where['Sczl_gdbh'] = $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_抽检记录') ->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_抽检记录')->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_抽检记录') ->field('Sczl_bh,rtrim(rs.员工姓名) as name,rtrim(sczl_bzdh) as sczl_bzdh ,LEFT(Sczl_rq, 10) as Sczl_rq, Sczl_gdbh,rtrim(g.Gd_cpmc) as Gd_cpmc, rtrim(Sczl_gxmc) as Sczl_gxmc,sczl_gxh,Sczl_num,Sczl_抽检数, Sczl_A类废,Sczl_B类废,Sczl_C类废,rtrim(Sczl_desc) as Sczl_desc') ->join('人事_基本资料 rs','rs.员工编号=db_抽检记录.Sczl_bh','LEFT') ->join('工单_基本资料 g','g.Gd_gdbh=db_抽检记录.Sczl_gdbh','LEFT') ->where('db_抽检记录.UniqId',$UniqId)->limit(1)->select(); if($rows){ $this->success('成功',$rows); }else{ $this->error('失败'); } } /** * 定位 * @ApiMethod (GET) */ public function search() { //get请求 if(!$this->request->isGet()){ $this->error('请求方式错误'); } $req = $this->request->param(); if (isset($req['search']) && !empty($req['search'])){ $search = $req['search']; }else{ $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']; $gd = db()->table('工单_基本资料')->where('Gd_cpmc',$search)->value('Gd_gdbh'); if($gd){ $search=$gd; } $rows = db()->table('db_抽检记录') ->field('Sczl_bh,sczl_yjno,rtrim(rs.员工姓名) as name,LEFT(Sczl_rq, 10) as Sczl_rq, Sczl_gdbh,rtrim(g.Gd_cpmc) as Gd_cpmc, rtrim(Sczl_gxmc) as Sczl_gxmc,sczl_gxh,Sczl_num,Sczl_抽检数, Sczl_A类废,Sczl_B类废,Sczl_C类废,rtrim(Sczl_desc) as Sczl_desc,rtrim(db_抽检记录.Sys_id) as Sys_id, db_抽检记录.Sys_rq,db_抽检记录.Mod_rq,db_抽检记录.UniqId') ->join('人事_基本资料 rs','rs.员工编号=db_抽检记录.Sczl_bh','LEFT') ->join('工单_基本资料 g','g.Gd_gdbh=db_抽检记录.Sczl_gdbh','LEFT') ->where('db_抽检记录.Sczl_gdbh',$search) ->page($page,$limit)->select(); $total = db()->table('db_抽检记录')->where('db_抽检记录.Sczl_gdbh',$search)->count(); $data = ['total'=> $total,'rows'=> $rows]; if($rows){ $this->success('成功',$data); }else{ $this->error('失败'); } } /** * 修改 * @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('参数错误'); } if (isset($req['Sczl_gxmc']) && !empty($req['Sczl_gxmc'])){ $req['sczl_gxh'] = explode('-',$req['Sczl_gxmc'])[1]; } if (isset($req['Sczl_rq']) && !empty($req['Sczl_rq'])){ $req['Sczl_rq'] = $req['Sczl_rq'].' 00:00:00'; } $req['Mod_rq'] = date('Y-m-d H:i:s'); //开启事务 db()->startTrans(); try{ $sql = db()->table('db_抽检记录')->where('UniqId',$UniqId)->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) && !empty($req)){ }else{ $this->error('参数错误'); } if (isset($req['Sczl_gxmc']) && !empty($req['Sczl_gxmc'])){ $req['sczl_gxh'] = explode('-',$req['Sczl_gxmc'])[1]; } if (isset($req['Sczl_rq']) && !empty($req['Sczl_rq'])){ $req['Sczl_rq'] = $req['Sczl_rq'].' 00:00:00'; } $req['Sys_rq'] = date('Y-m-d H:i:s'); $UniqId = db()->table('db_抽检记录')->order('UniqId desc')->value('UniqId'); if ($UniqId < 1000000){ $UniqId = 1000000; }else{ $UniqId = $UniqId + 1; } $req['UniqId'] = $UniqId; //开启事务 db()->startTrans(); try{ $sql = db()->table('db_抽检记录')->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_抽检记录')->where('UniqId',$UniqId)->delete(); if($rows){ $this->success('成功'); }else{ $this->error('失败'); } } }