123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Db;
- use think\helper\Time;
- use think\Model;
- use think\response\Json;
- class MeetingRoom extends Model
- {
- public function add(){
- $data = [
- 'id' => input('id/d',0),
- 'title' => input('title','','trim'),
- 'remark' => input('remark','','trim'),
- 'org_id' => input('orgId/d',0),
- 'enable' => input('enable/d',1),
- ];
- $logdata = json_encode($data);
- $result = validate('MeetingRoom')->check($data,[],'');
- if(true !== $result){
- HelpHander::error(validate('MeetingRoom')->getError());
- }
- $id = $data['id'];
- unset($data['id']);
- if($id > 0){
- $data['update_time'] = date('Y-m-d H:i:s');
- $ret = $this->allowField(true)->save($data,['id'=>$id]);
- }else{
- $data['create_time'] = date('Y-m-d H:i:s');
- $ret = $this->allowField(true)->save($data);
- }
- if(!$ret){
- HelpHander::error('操作失败');
- }
- if($id > 0){
- $content = '修改会议室';
- }else{
- $content = '添加会议室';
- }
- model('ActionLog')->add(9,$content,0,$logdata);
- return true;
- }
- public function info($id){
- $info = $this->where('id',$id)->find();
- if(!$info){
- HelpHander::error('数据不存在');
- }
- return $info->toArray();
- }
- public function lists($page,$size,$title,$orgId){
- $map[] = ['del','=',0];
- $map[] = ['org_id','=',$orgId];
- if($title != ''){
- $map[] = ['title','like','%'.$title.'%'];
- }
- $lists = $this
- ->where($map)
- ->page($page,$size)
- ->order('id desc')
- ->select();
- $total = $this->where($map)->count();
- $data = [
- 'total' => $total,
- 'list' => $lists?$lists->toArray():[]
- ];
- return $data;
- }
- public function all($orgId){
- $map[] = ['del','=',0];
- $map[] = ['org_id','=',$orgId];
- $lists = $this
- ->where($map)
- ->field('id,title')
- ->order('id desc')
- ->select();
- return $lists?$lists->toArray():[];
- }
- public function del($id){
- $ret = $this->where('id',$id)->setField('del',1);
- if(!$ret){
- HelpHander::error('删除失败');
- }
- $logdata = json_encode(['id' => $id]);
- model('ActionLog')->add(9,'删除会议室',0,$logdata);
- return true;
- }
- public function createSn($formJson){
- $formJson = json_decode($formJson,true);
- foreach ($formJson as $k=>$v){
- if($v['componentName'] == 'ddmeetingroomfield'){
- foreach ($v['components'] as $key=>$val){
- switch ($val['idx']){
- case '0':
- $sn = isset($val['values'])?$val['values']:'';
- if(!$sn){
- list($start,$end) = Time::month();
- $startDate = date('Y-m-d H:i:s',$start);
- $endDate = date('Y-m-d H:i:s',$end);
- $sn = Db::name('meeting_room_book')
- ->where('sn','like',date('Ym').'%')
- ->where('create_time','>=',$startDate)
- ->where('create_time','<=',$endDate)
- ->order('id desc')
- ->value('sn');
- if(is_numeric($sn)){
- $sn = $sn?$sn+1:date('Ym').'0001';
- }else{
- $sn = date('Ym').'0001';
- }
- if(mb_strlen($sn) == 12){
- $sn = date('Ym').'0001';
- }
- }
- $formJson[$k]['components'][$key]['values'] = "{$sn}";
- break;
- }
- }
- break;
- }
- }
- return json_encode($formJson,JSON_UNESCAPED_UNICODE);
- }
- public function advancedStartMeetingRoom($id,$orgId,$userId,$formJson,$extra){
- $formJson = json_decode($formJson,true);
- $data = [
- 'org_id' => $orgId,
- 'user_id' => $userId,
- 'apply_id' => $id,
- 'dep_id' => $extra['depId'],
- 'create_time' => date('Y-m-d H:i:s'),
- 'status' => 0,
- ];
- foreach ($formJson as $k=>$v){
- if($v['componentName'] == 'ddmeetingroomfield'){
- foreach ($v['components'] as $key=>$val){
- $val['values2'] = isset($val['values2'])?$val['values2']:[];
- $val['values'] = isset($val['values'])?$val['values']:'';
- switch ($val['idx']){
- case '0':
- $data['sn'] = isset($val['values'])?$val['values']:'';
- break;
- case '1':
- $d = json_decode($val['values'],true);
- $data['meeting_room_id'] = $d['id'];
- break;
- case '2':
- $data['start_time'] = date('Y-m-d H:i:s',strtotime($val['values2'][0]));
- $data['end_time'] = date('Y-m-d H:i:s',strtotime($val['values2'][1]));
- break;
- case '3':
- $data['nums'] = $val['values'];
- break;
- case '4':
- $data['leader'] = $val['values'];
- break;
- case '5':
- $data['participants'] = $val['values'];
- break;
- case '6':
- $data['service'] = implode(',',$val['values2']);
- break;
- case '7':
- $data['banner'] = $val['values'];
- break;
- case '8':
- $data['remark'] = $val['values'];
- break;
- case '9':
- $data['projection'] = $val['values'];
- break;
- }
- }
- break;
- }
- }
- $ret = Db::name('meeting_room_book')->insert($data);
- return $ret?true:false;
- }
- public function advancedEndMeetingRoom($id,$orgId,$userId,$formJson){
- $data = [
- 'update_time' => date('Y-m-d H:i:s'),
- 'status' => 1
- ];
- $ret = Db::name('meeting_room_book')->where('apply_id',$id)->update($data);
- return $ret?true:false;
- }
- public function advancedDisagreeMeetingRoom($id){
- $data = [
- 'update_time' => date('Y-m-d H:i:s'),
- 'status' => 2
- ];
- $ret = Db::name('meeting_room_book')->where('apply_id',$id)->update($data);
- return $ret?true:false;
- }
- public function books($page,$size,$meetingRoomId,$orgId){
- $map[] = ['status','=',1];
- $map[] = ['org_id','=',$orgId];
- if($meetingRoomId > 0){
- $map[] = ['meeting_room_id','=',$meetingRoomId];
- }
- $lists = Db::name('meeting_room_book')
- ->where($map)
- ->page($page,$size)
- ->order('id desc')
- ->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- $lists[$k]['userPhone'] = Db::name('user')->where('id',$v['user_id'])->value('phone');
- $lists[$k]['userName'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name');
- $lists[$k]['meetingRoom'] = Db::name('meeting_room')->where('id',$v['meeting_room_id'])->value('title');
- $lists[$k]['depName'] = Db::name('dep')->where('id',$v['dep_id'])->value('name');
- }
- $total = Db::name('meeting_room_book')->where($map)->count();
- $data = [
- 'total' => $total,
- 'list' => $lists?$lists:[]
- ];
- return $data;
- }
- public function curbooks($meetingRoomId,$orgId){
- $map[] = ['status','=',1];
- $map[] = ['enable','=',1];
- $map[] = ['org_id','=',$orgId];
- if($meetingRoomId > 0){
- $map[] = ['meeting_room_id','=',$meetingRoomId];
- }
- $curDate = date('Y-m-d H:i:s');
- // $map[] = ['start_time','<=',$curDate];
- $map[] = ['end_time','>=',$curDate];
- $lists = Db::name('meeting_room_book')
- ->where($map)
- ->field('id,start_time,end_time')
- ->order('start_time desc')
- ->select();
- return $lists = $lists?$lists:[];
- }
- public function cancel($id){
- $info = Db::name('meeting_room_book')->where('id',$id)->find();
- if(!$info||$info['status']!=1){
- HelpHander::error('记录不存在');
- }
- if($info['enable'] == 0){
- HelpHander::error('已取消');
- }
- $ret = Db::name('meeting_room_book')->where('id',$id)->setField('enable',0);
- if(!$ret){
- HelpHander::error('取消失败');
- }
- return true;
- }
- }
|