MeetingApply.php 10 KB

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