123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- <?php
- namespace app\admin\controller;
- use app\hander\HelpHander;
- use think\Db;
- class Supervise extends Auth
- {
- public function index(){
- if(request()->isAjax()){
- //分页参数
- $length = input('rows',10,'intval'); //每页条数
- $page = input('page',1,'intval'); //第几页
- $start = ($page - 1) * $length; //分页开始位置
- //排序
- $sortRow = input('sidx','id','trim'); //排序列
- $sort = input('sort','desc','trim'); //排序方式
- $order = $sortRow.' '.$sort;
- $map[] = ['del','=',0];
- $map= empty($map) ? true: $map;
- //数据查询
- $lists = Db::name('supervise')->where($map)->limit($start,$length)->order('id desc')->select();
- //数据返回
- $totalCount = Db::name('supervise')->where($map)->count();
- $totalPage = ceil($totalCount/$length);
- $result['page'] = $page;
- $result['total'] = $totalPage;
- $result['records'] = $totalCount;
- $result['rows'] = $lists;
- return json($result);
- }else{
- return $this->fetch();
- }
- }
- /**
- * 新增/编辑
- */
- public function add($id=0){
- if(request()->isPost()){
- $res = model('Supervise')->updates();
- if($res){
- $this->success('操作成功',url('index'));
- }else{
- $this->error(model('Supervise')->getError());
- }
- }else{
- $meta_title = '添加品质督察标准';
- if($id){
- $meta_title = '编辑品质督察标准';
- $info = db('supervise')->where('id',$id)->find();
- $this->assign('info',$info);
- }
- $this->assign('meta_title',$meta_title);
- if($id > 0){
- return $this->fetch('edit');
- }else{
- return $this->fetch();
- }
- }
- }
- /**
- * 删除记录
- * @param int $id
- */
- public function del($id=0){
- if(!$id){
- $this->error('参数错误');
- }
- $info = Db::name('supervise_record')->where('supervise_id',$id)->where('del',0)->find();
- if($info){
- $this->error('该类下面有记录不能删除');
- }
- $res = Db::name('supervise')->where('id',$id)->setField('del',1);
- if($res){
- $this->success('删除成功');
- }else{
- $this->error('删除失败');
- }
- }
- /**
- * 改变字段值
- * @param int $fv
- * @param string $fn
- * @param int $fv
- */
- public function changeField($id=0,$fn='',$fv=0){
- if(!$fn||!$id){
- $this->error('参数错误');
- }
- $res = db('supervise')->where('id',$id)->setField($fn,$fv);
- if($res){
- $this->success('操作成功');
- }else{
- $this->error('操作失败');
- }
- }
- public function record($id=0){
- if(request()->isAjax()){
- //分页参数
- $length = input('rows',20,'intval'); //每页条数
- $page = input('page',1,'intval'); //第几页
- $start = ($page - 1) * $length; //分页开始位置
- //排序
- $sortRow = input('sidx','id','trim'); //排序列
- $sort = input('sord','desc','trim'); //排序方式
- $order = $sortRow.' '.$sort;
- $st = input('start','','trim');
- if($st){
- $map[] = ['create_time','>=',date('Y-m-d 00:00:00',strtotime($st))];
- }
- $et = input('end','','trim');
- if($et){
- $map[] = ['create_time','<=',date('Y-m-d 23:59:59',strtotime($et))];
- }
- $map[] = ['supervise_id','=',$id];
- $map[] = ['del','=',0];
- $map= empty($map) ? true: $map;
- //数据查询
- $lists = Db::name('supervise_record')->where($map)->limit($start,$length)->order('score desc')->select();
- foreach ($lists as $k=>$v){
- $lists[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
- $lists[$k]['org_name'] = Db::name('org')->where('id',$v['org_id'])->value('name');
- }
- //数据返回
- $totalCount = Db::name('supervise_record')->where($map)->count();
- $totalPage = ceil($totalCount/$length);
- $result['page'] = $page;
- $result['total'] = $totalPage;
- $result['records'] = $totalCount;
- $result['rows'] = $lists;
- return json($result);
- }else{
- $this->assign('start',date('Y-m-d',strtotime('-1 months')));
- $this->assign('end',date('Y-m-d'));
- $this->assign('id',$id);
- return $this->fetch();
- }
- }
- /**
- * 删除记录
- * @param int $id
- */
- public function recordDel($id=0){
- if(!$id){
- $this->error('参数错误');
- }
- $data = [
- 'del'=>1,
- 'del_user'=>$this->userId,
- 'del_time'=>date('Y-m-d H:i:s'),
- ];
- $res = Db::name('supervise_record')->where('id',$id)->update($data);
- if($res){
- $this->success('删除成功');
- }else{
- $this->error('删除失败');
- }
- }
- public function recordDetail($id){
- $info = Db::name('supervise_record')->where('id',$id)->find();
- if(!$info){
- HelpHander::success('参数错误');
- }
- $info['supervise_title'] = Db::name('supervise')->where('id',$info['supervise_id'])->value('title');
- $info['user_name'] = Db::name('user')->where('id',$info['user_id'])->value('real_name');
- $info['content'] = json_decode($info['content'] ,true);
- foreach ($info['content'] as $k=>$v){
- $nums = $nums2= 0;
- foreach ($v['sub'] as $kk=>$vv){
- $nums2 = 0;
- foreach ($vv['sub'] as $kkk=>$vvv){
- if($vvv){
- $nums2 +=1;
- }
- }
- $nums +=$nums2;
- $info['content'][$k]['sub'][$kk]['nums'] = $nums2 >0 ? $nums2 :0;
- }
- $info['content'][$k]['nums'] = $nums;
- }
- $arr = [];
- $total = 0;
- foreach ($info['content'] as $k=>$v){
- foreach ($v['sub'] as $kk=>$vv){
- foreach ($vv['sub'] as $kkk=>$vvv){
- $arr[] = [
- 'num1' => $v['nums'],
- 'num2' => $vv['nums'],
- 'title1' => $kk==0&&$kkk==0?$v['title'].'('.$v['score'].'分)':'',
- 'title2' => $kkk==0?$vv['title'].'('.$vv['score'].'分)':'',
- 'standard' => $vv['standard'],
- 'title3' => $vvv['title'],
- 'score' => $vvv['score'],
- 'scored' => $vv['scored'],
- 'score_dec' => $vv['score']-$vv['scored'],
- 'reason' => isset($vv['reason'])&&!empty($vv['reason'])?$vv['reason']:'',
- 'img' => isset($vv['img'])&&!empty($vv['img'])? explode(',',$vv['img']):[],
- ];
- }
- }
- }
- $this->assign('info',$info);
- $this->assign('arr',$arr);
- return $this->fetch();
- }
- }
|