MeetingApply.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <?php
  2. namespace app\common\model;
  3. use app\common\util\AppMsg;
  4. use think\Db;
  5. class MeetingApply extends Base
  6. {
  7. public function agree(){
  8. $data = request()->post();
  9. $data['apply_time'] = date('Y-m-d H:i:s');
  10. $data['status'] = 1;
  11. $id = $data['id'];
  12. // $userIds = $data['user_id'];
  13. unset($data['id']);
  14. // unset($data['user_id']);
  15. // if(!$data['apply_remark']){
  16. // $this->error = '审批意见不能为空';
  17. // return false;
  18. // }
  19. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  20. $apply = Db::name('meeting_apply')->where('id',$id)->find();
  21. if($apply['user_id']){
  22. send_jpush([$apply['user_id']],AppMsg::PUSH_CUSTOM,'您预约的会议室审批已通过');
  23. }
  24. $room = Db::name('meeting_room')->where('id',$apply['meeting_room_id'])->find();
  25. if($room['waiter'] > 0 && $room['is_notice_waiter'] == 1){
  26. $time = $apply['start_time'].'-'.$apply['end_time'];
  27. $msg = '请在'.$time.'进行会议服务';
  28. send_jpush([$room['waiter']],AppMsg::PUSH_CUSTOM,$msg);
  29. }
  30. // $ids = isset($userIds) && !empty($userIds)?explode(',',$userIds):[];
  31. // if(count($ids)>0){
  32. // foreach ($ids as $k=>$v){
  33. // $mData = [
  34. // 'user_id'=>$v,
  35. // 'meetapply_id'=>$id,
  36. // ];
  37. // $add = Db::name('meet_service')->insert($mData);
  38. // if(!$add){
  39. // $this->error = '操作失败';
  40. // return false;
  41. // }
  42. // }
  43. // }
  44. if(!$ret){
  45. $this->error = '操作失败';
  46. return false;
  47. }
  48. return true;
  49. }
  50. public function refuse(){
  51. $data = request()->post();
  52. $data['apply_time'] = date('Y-m-d H:i:s');
  53. $data['status'] = 2;
  54. $id = $data['id'];
  55. unset($data['id']);
  56. if(!$data['apply_remark']){
  57. $this->error = '审批意见不能为空';
  58. return false;
  59. }
  60. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  61. if(!$ret){
  62. $this->error = '操作失败';
  63. return false;
  64. }
  65. $userId = Db::name('meeting_apply')->where('id',$id)->value('user_id');
  66. if($userId){
  67. send_jpush([$userId],AppMsg::PUSH_CUSTOM,'您预约的会议室审批未通过');
  68. }
  69. return true;
  70. }
  71. //app接口
  72. public function lists($page,$size,$userId,$orgId){
  73. $ret = db('meeting_apply')
  74. ->alias('ma')
  75. ->field('ma.id,ma.start_time,ma.end_time,ma.status,u.real_name,mr.title,mr.waiter')
  76. ->leftJoin('meeting_room mr','mr.id=ma.meeting_room_id')
  77. ->leftJoin('user u','u.id=ma.user_id')
  78. ->where([
  79. 'ma.status'=>0,
  80. 'ma.del'=>0,
  81. 'ma.org_id'=>$orgId,
  82. 'ma.approver'=>$userId,
  83. ])
  84. ->order('ma.id desc')
  85. ->page($page,$size)
  86. ->select();
  87. return $ret?$ret:[];
  88. }
  89. public function blist($page,$size,$title,$userId,$orgId){
  90. if($title){
  91. $map[] = ['u.real_name|ma.theme','like','%'.$title.'%'];
  92. }
  93. $map[] = ['ma.del','=',0];
  94. $map[] = ['ma.org_id','=',$orgId];
  95. $map[] = ['ma.approver','=',$userId];
  96. $ret = db('meeting_apply')
  97. ->alias('ma')
  98. ->field('ma.id,ma.start_time,ma.end_time,ma.status,u.real_name,mr.title,mr.waiter')
  99. ->join('meeting_room mr','mr.id=ma.meeting_room_id')
  100. ->join('user u','u.id=ma.user_id')
  101. ->where($map)
  102. ->order('ma.id desc')
  103. ->page($page,$size)
  104. ->select();
  105. return $ret?$ret:[];
  106. }
  107. public function searchs($page,$size,$title,$userId,$orgId){
  108. $ret = db('meeting_apply')
  109. ->alias('ma')
  110. ->field('ma.id,ma.start_time,ma.end_time,ma.status,u.real_name,mr.title,mr.waiter')
  111. ->join('meeting_room mr','mr.id=ma.meeting_room_id')
  112. ->join('user u','u.id=ma.user_id')
  113. ->where([
  114. 'ma.del'=>0,
  115. 'ma.org_id'=>$orgId,
  116. 'ma.approver'=>$userId,
  117. ])
  118. ->whereIn('ma.status',[1,2,3])
  119. ->where(function ($query) use($title){
  120. $query->where('u.real_name','like','%.'.$title.'%')
  121. ->whereOr('ma.theme','like','%'.$title.'%');
  122. })
  123. ->order('ma.id desc')
  124. ->page($page,$size)
  125. ->select();
  126. return $ret?$ret:[];
  127. }
  128. public function details($id){
  129. $info = db('meeting_apply')->where('id',$id)->where('del',0)->find();
  130. if($info){
  131. //发起人
  132. $info['user_name'] = db('user')->where('id',$info['user_id'])->value('real_name');
  133. //会议室名称
  134. $info['meeting_room_title'] = db('meeting_room')->where('id',$info['meeting_room_id'])->value('title');
  135. //参会人员
  136. $userIds = $info['user_ids'] ? explode(',',$info['user_ids']):[];
  137. $info['meeting_user'] = db('user')->field('real_name,head_image')->whereIn('id',$userIds)->select();
  138. //设备
  139. $info['device'] = db('meeting_device')->field('title')->whereIn('id',$info['meeting_devices'])->select();
  140. //审批人
  141. $applyUser = db('user')->where('id',$info['approver'])->find();
  142. $info['approver_user'] = $applyUser?$applyUser['real_name']:'';
  143. $info['approver_head_img'] = $applyUser?$applyUser['head_image']:'';
  144. //会议室服务人员
  145. $info['waiter'] = db('meeting_room')->where('id',$info['meeting_room_id'])->value('waiter');
  146. //使用部门
  147. $info['dep_name'] = Db::name('dep')->where('id',$info['dep_id'])->value('title');
  148. }
  149. return $info?$info:[];
  150. }
  151. public function confirms($id,$content,$serviceId){
  152. $info = db('meeting_apply')->where('del',0)->where('id',$id)->find();
  153. if(!$info){
  154. $this->error = '记录不存在';
  155. return false;
  156. }
  157. if($info['status'] != 0){
  158. $this->error = '已处理,无法审核';
  159. return false;
  160. }
  161. $data=[
  162. 'status'=>1,
  163. 'apply_remark'=>$content,
  164. 'apply_time'=>date('Y-m-d H:i:s')
  165. ];
  166. $save = db('meeting_apply')->where('id',$id)->update($data);
  167. if($save > 0){
  168. // send_push_meeting(11,[$info['USER_ID']],['id' => $info['ID']]);
  169. if(!empty($serviceId)){
  170. $sid = explode(',',$serviceId);
  171. foreach ($sid as $v){
  172. db('meet_service')->insert(['meetapply_id'=>$id,'user_id'=>$v]);
  173. }
  174. // send_push_meeting(15,$sid,['id' => $info['ID']]);
  175. }
  176. }else{
  177. $this->error = '操作失败';
  178. return false;
  179. }
  180. return $save;
  181. }
  182. public function rejects($id,$content){
  183. $info = db('meeting_apply')->where('del',0)->where('id',$id)->find();
  184. if(!$info){
  185. $this->error = '记录不存在';
  186. return false;
  187. }
  188. if($info['status'] != 0){
  189. $this->error = '已处理,无法审核';
  190. return false;
  191. }
  192. $data=[
  193. 'status'=>2,
  194. 'apply_remark'=>$content,
  195. 'apply_time'=>date('Y-m-d H:i:s')
  196. ];
  197. $save = db('meeting_apply')->where('id',$id)->update($data);
  198. if($save){
  199. // send_push_meeting(12,[$info['USER_ID']],['id' => $info['ID']]);
  200. }else{
  201. $this->error = '操作失败';
  202. return false;
  203. }
  204. return $save;
  205. }
  206. public function myReserves($page,$size,$userId,$orgId){
  207. $ret = db('meeting_apply')
  208. ->alias('ma')
  209. ->field('ma.id,ma.start_time,ma.end_time,ma.status,mr.title,mr.address')
  210. ->join('meeting_room mr','mr.id=ma.meeting_room_id')
  211. ->where([
  212. 'ma.del'=>0,
  213. 'ma.org_id'=>$orgId,
  214. 'ma.USER_ID'=>$userId,
  215. ])
  216. ->order('ma.id desc')
  217. ->page($page,$size)
  218. ->select();
  219. foreach ($ret as $k=>$v){
  220. $newstarttime=date('Y-m-d H:i',strtotime($v['start_time']));
  221. $newendtime=date('H:i',strtotime($v['end_time']));
  222. $ret[$k]['meeting_time']=$newstarttime.'~'.$newendtime;
  223. }
  224. return $ret?$ret:[];
  225. }
  226. public function cancelReserves($id){
  227. $data=[
  228. 'cancel_time'=>date('Y-m-d H:i:s'),
  229. 'status'=>3
  230. ];
  231. $ret = db('meeting_apply')->where('id',$id)->update($data);
  232. return $ret;
  233. }
  234. public function reserveDetails($id){
  235. $info = db('meeting_apply')
  236. ->field('id,meeting_room_id,start_time,end_time,status,nums,user_ids,meeting_devices,banner,theme,approver,dep_id')
  237. ->where('id',$id)
  238. ->where('del',0)
  239. ->find();
  240. if($info){
  241. //会议室名称/人数/地址/设备
  242. $meeting_room = db('meeting_room')->where('id',$info['meeting_room_id'])->find();
  243. $info['meeting_room_title']=$meeting_room?$meeting_room['title']:'';
  244. $info['meeting_room_content']=$meeting_room?$meeting_room['content']:'';
  245. $info['meeting_room_limit']=$meeting_room?$meeting_room['limit']:'';
  246. $info['meeting_room_address']=$meeting_room?$meeting_room['address']:'';
  247. //会议室设备
  248. $meeting_room_device = db('meeting_device')->field('title')->whereIn('id',$meeting_room['meeting_device_ids'])->select();
  249. if($meeting_room_device){
  250. foreach ($meeting_room_device as $k=>$v){
  251. $roomdevice[$k]=$v['title'];
  252. }
  253. $info['meeting_room_device']=$roomdevice?implode('/',$roomdevice):'';
  254. }else{
  255. $info['meeting_room_device']='';
  256. }
  257. //参会人员
  258. $info['meeting_user'] = db('user')->field('real_name,head_image')->whereIn('id',$info['user_ids'])->select();
  259. //审批单设备
  260. $device= db('meeting_device')->field('title')->whereIn('id',$info['meeting_devices'])->select();
  261. if($device){
  262. foreach ($device as $k=>$v){
  263. $applydevice[$k]=$v['title'];
  264. }
  265. $info['meeting_apply_device']=$applydevice?implode('、',$applydevice):'';
  266. }else{
  267. $info['meeting_apply_device']='';
  268. }
  269. //会议室名称
  270. $info['meeting_room_title'] = db('meeting_room')->where('id',$info['meeting_room_id'])->value('title');
  271. //审批人
  272. $applyUser = db('user')->field('real_name,head_image')->where('id',$info['approver'])->find();
  273. $info['approver_user'] = $applyUser?$applyUser['real_name']:'';
  274. $info['approver_head_img'] = $applyUser?$applyUser['head_image']:'';
  275. $info['dep_name'] = Db::name('dep')->where('id',$info['dep_id'])->value('title');
  276. unset($info['user_ids'],$info['approver'],$info['meeting_devices'],$info['meeting_room_id']);
  277. }
  278. return $info?$info:[];
  279. }
  280. }