| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326 | 
							- <?php
 
- namespace app\admin\controller;
 
- use app\common\util\ExcelUtil;
 
- use think\Db;
 
- class MeetingRoom 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('sord','desc','trim');        //排序方式
 
-             $order = $sortRow.' '.$sort;
 
-             $title = input('title','','trim');
 
-             if($title){
 
-                 $map[] = ['title','like','%'.$title.'%'];
 
-             }
 
-             $enable = input('enable','','trim');
 
-             if($enable != ''){
 
-                 $map[] = ['enable','=',$enable];
 
-             }
 
-             $map[] = ['del','=',0];
 
-             $map[] = ['org_id','=',cur_org_id()];
 
-             $map= empty($map) ? true: $map;
 
-             //数据查询
 
-             $lists = db('meeting_room')->limit($start,$length)->where($map)->order(['sort'=>'desc','id'=>'desc'])->select();
 
-             foreach ($lists as $k=>$v){
 
-                 $lists[$k]['approverName'] = db('user')->where('id',$v['approver'])->value('real_name');
 
-                 $lists[$k]['token'] = think_encrypt($v['id']);
 
-             }
 
-             //数据返回
 
-             $totalCount = db('meeting_room')->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('MeetingRoom')->updates();
 
-             if($res){
 
-                 $this->success('操作成功',url('index'));
 
-             }else{
 
-                 $this->error(model('MeetingRoom')->getError());
 
-             }
 
-         }else{
 
-             $title = '新增';
 
-             if($id){
 
-                 $title = '编辑';
 
-                 $info = db('meeting_room')->where('id',$id)->find();
 
-                 $info['meeting_device_ids'] = !empty($info['meeting_device_ids'])?explode(',',$info['meeting_device_ids']):[];
 
-                 $this->assign('info',$info);
 
-             }
 
-             $c[] = ['del','=',0];
 
-             $c[] = ['enable','=',1];
 
-             $c[] = ['org_id','=',cur_org_id()];
 
-             $device = db('meeting_device')->where($c)->select();
 
-             $approverUser = Db::name('user')
 
-                 ->alias('u')
 
-                 ->field('u.*')
 
-                 ->join('user_org uo','uo.user_id=u.id')
 
-                 ->where([
 
-                     'uo.org_id'=>cur_org_id(),
 
-                     'u.enable'=>1,
 
-                     'u.del'=>0,
 
-                     'u.type'=>0,
 
-                 ])
 
-                 ->select();
 
-             $this->assign('userList',$approverUser);
 
-             $this->assign('deviceList',$device);
 
-             $this->assign('title',$title);
 
-             return $this->fetch();
 
-         }
 
-     }
 
-     /**
 
-      * 删除记录
 
-      * @param int $id
 
-      */
 
-     public function del($id=0){
 
-         if(!$id){
 
-             $this->error('参数错误');
 
-         }
 
-         $res = db('meeting_room')->where('id',$id)->setField('del',1);
 
-         if($res){
 
- //            model('ActionLog')->addlog(is_login(),37,'删除会议室',['id' => $id],cur_org_id());
 
-             $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('meeting_room')->where('id',$id)->setField($fn,$fv);
 
-         if($res){
 
-             $content = '';
 
-             if($fn == 'enable') {
 
-                 $content = '会议室列表:禁用';
 
-                 if ($fv == 1) {
 
-                     $content = '会议室列表:启用';
 
-                 }
 
-             }
 
- //            model('ActionLog')->addlog(is_login(),37,$content,['id' => $id],cur_org_id());
 
-             $this->success('操作成功');
 
-         }else{
 
-             $this->error('操作失败');
 
-         }
 
-     }
 
-     /**
 
-      * 排序
 
-      * @param int $id
 
-      * @param int $sort
 
-      */
 
-     public function changeSort($id=0,$sort=0){
 
-         if($id<0||$sort<0){
 
-             $this->error('参数错误');
 
-         }
 
-         $res = db('meeting_room')->where('id',$id)->update(['sort'=>$sort]);
 
-         if($res){
 
-             $this->success('操作成功');
 
-         }else{
 
-             $this->error('操作失败');
 
-         }
 
-     }
 
-     public function screen(){
 
-         $token = input('token');
 
-         $this->redirect('h5/MeetingScreen/index',['token'=>$token]);
 
-     }
 
-     public function tj(){
 
-         if(request()->isAjax()){
 
-             //分页参数
 
-             $length = input('rows',10,'intval');   //每页条数
 
-             $page = input('page',1,'intval');      //第几页
 
-             $start = ($page - 1) * $length;     //分页开始位置
 
-             //排序
 
-             $sortRow = input('sidx','id','trim');      //排序列
 
-             $sort = input('sord','desc','trim');        //排序方式
 
-             $order = $sortRow.' '.$sort;
 
-             $title = input('title','','trim');
 
-             if($title){
 
-                 $map[] = ['title','like','%'.$title.'%'];
 
-             }
 
-             $map[] = ['del','=',0];
 
-             $map[] = ['org_id','=',cur_org_id()];
 
-             $map= empty($map) ? true: $map;
 
-             $start_time = input('start', '', 'trim');
 
-             $end_time = input('end', '', 'trim');
 
-             //数据查询
 
-             $lists = Db::name('meeting_room')->limit($start,$length)->where($map)->order($order)->select();
 
-             foreach ($lists as $k=>$v){
 
-                 $where[] = ['del','=',0];
 
- //                $where[] = ['meeting_room_id','=',$v['id']];
 
-                 if($start_time){
 
-                     $where[] = ['end_time','>',$start_time.' 00:00:00'];
 
-                 }
 
-                 if($end_time){
 
-                     $where[] = ['start_time','<',$end_time.' 23:59:59'];
 
-                 }
 
-                 $count = Db::name('meeting_apply')->where($where)->where('meeting_room_id',$v['id'])->count();
 
-                 $lists[$k]['count'] = $count;
 
-                 $m1 = $where;
 
-                 $m1[] = ['status','=',0];
 
-                 $count1 = Db::name('meeting_apply')->where($m1)->where('meeting_room_id',$v['id'])->count();
 
-                 $lists[$k]['count1'] = $count1;
 
-                 $m2 = $where;
 
-                 $m2[] = ['status','=',1];
 
-                 $count2 = Db::name('meeting_apply')->where($m2)->where('meeting_room_id',$v['id'])->count();
 
-                 $lists[$k]['count2'] = $count2;
 
-                 $m3 = $where;
 
-                 $m3[] = ['status','=',2];
 
-                 $count3 = Db::name('meeting_apply')->where($m3)->where('meeting_room_id',$v['id'])->count();
 
-                 $lists[$k]['count3'] = $count3;
 
-                 $m4 = $where;
 
-                 $m4[] = ['status','=',3];
 
-                 $count4 = Db::name('meeting_apply')->where($m4)->where('meeting_room_id',$v['id'])->count();
 
-                 $lists[$k]['count4'] = $count4;
 
-                 // 时长
 
-                 $info = Db::name('meeting_apply')->where($m2)->where('meeting_room_id',$v['id'])->field('TIMESTAMPDIFF(SECOND,start_time,end_time) as seconds')->find();
 
-                 $lists[$k]['hour'] = $info?second_to_str($info['seconds']):'0';
 
-             }
 
-             //数据返回
 
-             $totalCount = Db::name('meeting_room')->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 tjexport(){
 
-         set_time_limit(0);
 
-         ini_set("memory_limit","1024M");
 
-         $title = input('title','','trim');
 
-         if($title){
 
-             $map[] = ['title','like','%'.$title.'%'];
 
-         }
 
-         $map[] = ['del','=',0];
 
-         $map[] = ['org_id','=',cur_org_id()];
 
-         $map= empty($map) ? true: $map;
 
-         $start_time = input('start', '', 'trim');
 
-         $end_time = input('end', '', 'trim');
 
-         //数据查询
 
-         $lists = Db::name('meeting_room')->where($map)->order('id desc')->select();
 
-         foreach ($lists as $k=>$v){
 
-             $where[] = ['del','=',0];
 
-             $where[] = ['meeting_room_id','=',$v['id']];
 
-             if($start_time){
 
-                 $where[] = ['end_time','>',$start_time.' 00:00:00'];
 
-             }
 
-             if($end_time){
 
-                 $where[] = ['start_time','<',$end_time.' 23:59:59'];
 
-             }
 
-             $count = Db::name('meeting_apply')->where($where)->count();
 
-             $lists[$k]['count'] = $count;
 
-             $m1 = $where;
 
-             $m1[] = ['status','=',0];
 
-             $count1 = Db::name('meeting_apply')->where($m1)->count();
 
-             $lists[$k]['count1'] = $count1;
 
-             $m2 = $where;
 
-             $m2[] = ['status','=',1];
 
-             $count2 = Db::name('meeting_apply')->where($m2)->count();
 
-             $lists[$k]['count2'] = $count2;
 
-             $m3 = $where;
 
-             $m3[] = ['status','=',2];
 
-             $count3 = Db::name('meeting_apply')->where($m3)->count();
 
-             $lists[$k]['count3'] = $count3;
 
-             $m4 = $where;
 
-             $m4[] = ['status','=',3];
 
-             $count4 = Db::name('meeting_apply')->where($m4)->count();
 
-             $lists[$k]['count4'] = $count4;
 
-             // 时长
 
-             $info = Db::name('meeting_apply')->where($m2)->field('TIMESTAMPDIFF(SECOND,start_time,end_time) as seconds')->find();
 
-             $lists[$k]['hour'] = $info?second_to_str($info['seconds']):'0';
 
-         }
 
-         $header = [
 
-             ['title' => '编号', 'name' => 'id','width'=>'10'],
 
-             ['title' => '会议室名称', 'name' => 'title','width'=>'20'],
 
-             ['title' => '预约总单数', 'name' => 'count','width'=>'20'],
 
-             ['title' => '待审核单数', 'name' => 'count1','width'=>'20'],
 
-             ['title' => '同意单数', 'name' => 'count2','width'=>'20'],
 
-             ['title' => '拒绝单数', 'name' => 'count3','width'=>'20'],
 
-             ['title' => '取消单数', 'name' => 'count4','width'=>'20'],
 
-             ['title' => '有效时长(已同意)', 'name' => 'hour','width'=>'30'],
 
-         ];
 
-         $filename = '会议室统计';
 
-         ExcelUtil::export($filename,$header,$lists);
 
-     }
 
-     //二维码
 
-     public function qrcode($id = 0) {
 
-         $info = Db::name('meeting_room')->where('id', $id)->where('del',0)->find();
 
-         if (!$info) {
 
-             exit('数据不存在');
 
-         }
 
-         $code = get_qrcode_str('meeting', $id);
 
-         $this->assign('code', $code);
 
-         $this->assign('info', $info);
 
-         return $this->fetch();
 
-     }
 
- }
 
 
  |