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[] = ['u.real_name','like','%'.$title.'%'];
}
$room_id = input('room_id','','trim');
if($room_id){
$map[] = ['ma.meeting_room_id','=',$room_id];
}
$status = input('status','','trim');
if($status != ''){
$map[] = ['ma.status','=',$status];
}
$map[] = ['ma.del','=',0];
$map[] = ['ma.org_id','=',cur_org_id()];
$map= empty($map) ? true: $map;
//数据查询
$lists = db('meeting_apply')
->alias('ma')
->field('ma.*,u.real_name')
->join('user u','u.id=ma.user_id')
->limit($start,$length)
->where($map)
->order('id desc')
->select();
foreach ($lists as $k=>$v){
$lists[$k]['roomName'] = Db::name('meeting_room')->where('id',$v['meeting_room_id'])->value('title');
// $lists[$k]['depName'] = Db::name('dep')->where('id',$v['dep_id'])->value('title');
}
//数据返回
$totalCount = db('meeting_apply')
->alias('ma')
->field('ma.*,u.real_name')
->join('user u','u.id=ma.user_id')
->where($map)->count();
$totalPage = ceil($totalCount/$length);
$result['page'] = $page;
$result['total'] = $totalPage;
$result['records'] = $totalCount;
$result['rows'] = $lists;
return json($result);
}else{
$roomList = db('meeting_room')->where('org_id',cur_org_id())->where('enable',1)->where('del',0)->select();
$this->assign('roomList',$roomList);
return $this->fetch();
}
}
/**
* 删除记录
* @param int $id
*/
public function del($id=0){
if(!$id){
$this->error('参数错误');
}
$res = db('meeting_apply')->where('id',$id)->setField('del',1);
if($res){
$this->success('删除成功');
}else{
$this->error('删除失败');
}
}
//同意
public function agree($id=0){
if(request()->isPost()){
$res = model('MeetingApply')->agree();
if($res){
$this->success('操作成功',url('index'));
}else{
$this->error(model('MeetingApply')->getError());
}
}else{
if($id){
$info = db('meeting_apply')->where('id',$id)->find();
$this->assign('info',$info);
}
$userList = model('work_type_mode')->getRolesUserApp(12,cur_org_id(),-1);
foreach ($userList as $k=>$v){
$userList[$k]['title']= $v['real_name'];
}
$this->assign('userList',$userList);
return $this->fetch();
}
}
//拒绝
public function refuse($id=0){
if(request()->isPost()){
$res = model('MeetingApply')->refuse();
if($res){
$this->success('操作成功',url('index'));
}else{
$this->error(model('MeetingApply')->getError());
}
}else{
if($id){
$info = db('meeting_apply')->where('id',$id)->find();
$this->assign('info',$info);
}
return $this->fetch();
}
}
public function details($id=0){
if($id < 1 ){
$this->error('参数错误');
}
$info = db('meeting_apply')->where('id',$id)->find();
if(!$info){
$this->error('记录不存在');
}
$info['meeting_room'] = db('meeting_room')->where('id',$info['meeting_room_id'])->value('title');
//申请人
$info['apply_user'] = db('user')->where('id',$info['user_id'])->value('real_name');
//审批人
$info['approver_user'] = db('user')->where('id',$info['approver'])->value('real_name');
//参会设备
$meeting_devices = db('meeting_device')->whereIn('id',$info['meeting_devices'])->where('del',0)->select();
$deviceName = [];
foreach ($meeting_devices as $k=>$v){
$deviceName[] = $v['title'];
}
$info['meeting_devices'] = $deviceName?implode(',',$deviceName):'';
//参会人员
$cUser= db('user')->whereIn('id',$info['user_ids'])->where('del',0)->select();
$userName = [];
foreach ($cUser as $k=>$v){
$userName[] = $v['real_name'];
}
$info['user_name'] = $userName?implode(',',$userName):'';
$info['dep_name'] = Db::name('dep')->where('id',$info['dep_id'])->value('title');
$this->assign('info',$info);
return $this->fetch();
}
//excel导出
public function export() {
set_time_limit(0);
ini_set("memory_limit","1024M");
$title = input('title','','trim');
if($title){
$map[] = ['u.real_name','like','%'.$title.'%'];
}
$room_id = input('room_id','','trim');
if($room_id){
$map[] = ['ma.meeting_room_id','=',$room_id];
}
$status = input('status','','trim');
if($status != ''){
$map[] = ['ma.status','=',$status];
}
$map[] = ['ma.del','=',0];
$map[] = ['ma.org_id','=',cur_org_id()];
$lists = db('meeting_apply')
->alias('ma')
->field('ma.*,u.real_name,mr.title as room_name')
->join('user u','u.id=ma.user_id')
->join('meeting_room mr','mr.id=ma.meeting_room_id')
->where($map)
->order('id desc')
->select();
foreach ($lists as $k=>$v){
if($v['status'] == 0){
$lists[$k]['status_text'] = '待审核';
}else if($v['status'] == 1){
$lists[$k]['status_text'] = '已同意';
}else if($v['status'] == 2){
$lists[$k]['status_text'] = '已拒绝';
}else{
$lists[$k]['status_text'] = '已取消';
}
}
$header = [
['title' => '编号', 'name' => 'id','width'=>'10'],
['title' => '申请人', 'name' => 'real_name','width'=>'20'],
['title' => '会议室名称', 'name' => 'room_name','width'=>'20'],
['title' => '开始时间', 'name' => 'start_time','width'=>'20'],
['title' => '结束时间', 'name' => 'end_time','width'=>'20'],
['title' => '状态', 'name' => 'status_text','width'=>'20'],
// ['title' => '使用人部门', 'name' => 'dep_name','width'=>'20'],
];
$filename = '会议室申请记录';
ExcelUtil::export($filename,$header,$lists);
}
public function calendar(){
$meetingId = input('meetingId',0);
$m_title = '会议室审批列表';
if($meetingId > 0){
$m_title = '会议室列表';
}
$this->assign('m_title',$m_title);
$this->assign('meetingId',$meetingId);
return $this->fetch();
}
public function taskjson(){
$start = input('start');
$end = input('end');
$data = array();
if(!$start||!$end||$start>$end){
header('Content-Type:application/json; charset=utf-8');
exit(json_encode($data));
}
$start = date('Y-m-d H:i:s',strtotime($start));
$end = date('Y-m-d H:i:s',strtotime($end));
$meetingId = input('meetingId',0);
if($meetingId >0){
$map[] = ['meeting_room_id','=',$meetingId];
}
$map[] = ['del','=',0];
$list = Db::name('meeting_apply')
->whereIn('status',[0,1])
->where('org_id',cur_org_id())
->where('start_time','>=',$start)
->where('end_time','<=',$end)
->where($map)
->select();
foreach ($list as $k=>$v){
// $uids = $v['user_ids']?explode(',',$v['user_ids']):[];
// $users = Db::name('user')->whereIn('id',$uids)->column('real_name');
// $users = $users ? implode(',',$users):'';
$roomName= Db::name('meeting_room')->where('id',$v['meeting_room_id'])->value('title');
$arr = array(
'id' => $v['id'],
'title' => "$roomName
开始时间:{$v['start_time']}
结束时间:{$v['end_time']}
",
'status' => $v['status'],
'start' => $v['start_time'],
'end' => $v['end_time']
);
if($v['status'] == 0){
$arr['color'] = '#777777';
}else if($v['status'] == 1){
// $arr['color'] = '#478fca';
$arr['color'] = '#69aa46';
}else if($v['status'] == 2){
$arr['color'] = '#69aa46';
}else{
$arr['color'] = '#dd5a43';
}
$data[] = $arr;
}
header('Content-Type:application/json; charset=utf-8');
exit(json_encode($data));
}
}