0
0

MeetingApply.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\util\ExcelUtil;
  4. use think\Db;
  5. class MeetingApply extends Auth
  6. {
  7. public function index(){
  8. if(request()->isAjax()){
  9. //分页参数
  10. $length = input('rows',10,'intval'); //每页条数
  11. $page = input('page',1,'intval'); //第几页
  12. $start = ($page - 1) * $length; //分页开始位置
  13. //排序
  14. $sortRow = input('sidx','id','trim'); //排序列
  15. $sort = input('sord','desc','trim'); //排序方式
  16. $order = $sortRow.' '.$sort;
  17. $title = input('title','','trim');
  18. if($title){
  19. $map[] = ['u.real_name','like','%'.$title.'%'];
  20. }
  21. $room_id = input('room_id','','trim');
  22. if($room_id){
  23. $map[] = ['ma.meeting_room_id','=',$room_id];
  24. }
  25. $status = input('status','','trim');
  26. if($status != ''){
  27. $map[] = ['ma.status','=',$status];
  28. }
  29. $map[] = ['ma.del','=',0];
  30. $map[] = ['ma.org_id','=',cur_org_id()];
  31. $map= empty($map) ? true: $map;
  32. //数据查询
  33. $lists = db('meeting_apply')
  34. ->alias('ma')
  35. ->field('ma.*,u.real_name')
  36. ->join('user u','u.id=ma.user_id')
  37. ->limit($start,$length)
  38. ->where($map)
  39. ->order('id desc')
  40. ->select();
  41. foreach ($lists as $k=>$v){
  42. $lists[$k]['roomName'] = Db::name('meeting_room')->where('id',$v['meeting_room_id'])->value('title');
  43. // $lists[$k]['depName'] = Db::name('dep')->where('id',$v['dep_id'])->value('title');
  44. }
  45. //数据返回
  46. $totalCount = db('meeting_apply')
  47. ->alias('ma')
  48. ->field('ma.*,u.real_name')
  49. ->join('user u','u.id=ma.user_id')
  50. ->where($map)->count();
  51. $totalPage = ceil($totalCount/$length);
  52. $result['page'] = $page;
  53. $result['total'] = $totalPage;
  54. $result['records'] = $totalCount;
  55. $result['rows'] = $lists;
  56. return json($result);
  57. }else{
  58. $roomList = db('meeting_room')->where('org_id',cur_org_id())->where('enable',1)->where('del',0)->select();
  59. $this->assign('roomList',$roomList);
  60. return $this->fetch();
  61. }
  62. }
  63. /**
  64. * 删除记录
  65. * @param int $id
  66. */
  67. public function del($id=0){
  68. if(!$id){
  69. $this->error('参数错误');
  70. }
  71. $res = db('meeting_apply')->where('id',$id)->setField('del',1);
  72. if($res){
  73. $this->success('删除成功');
  74. }else{
  75. $this->error('删除失败');
  76. }
  77. }
  78. //同意
  79. public function agree($id=0){
  80. if(request()->isPost()){
  81. $res = model('MeetingApply')->agree();
  82. if($res){
  83. $this->success('操作成功',url('index'));
  84. }else{
  85. $this->error(model('MeetingApply')->getError());
  86. }
  87. }else{
  88. if($id){
  89. $info = db('meeting_apply')->where('id',$id)->find();
  90. $this->assign('info',$info);
  91. }
  92. $userList = model('work_type_mode')->getRolesUserApp(12,cur_org_id(),-1);
  93. foreach ($userList as $k=>$v){
  94. $userList[$k]['title']= $v['real_name'];
  95. }
  96. $this->assign('userList',$userList);
  97. return $this->fetch();
  98. }
  99. }
  100. //拒绝
  101. public function refuse($id=0){
  102. if(request()->isPost()){
  103. $res = model('MeetingApply')->refuse();
  104. if($res){
  105. $this->success('操作成功',url('index'));
  106. }else{
  107. $this->error(model('MeetingApply')->getError());
  108. }
  109. }else{
  110. if($id){
  111. $info = db('meeting_apply')->where('id',$id)->find();
  112. $this->assign('info',$info);
  113. }
  114. return $this->fetch();
  115. }
  116. }
  117. public function details($id=0){
  118. if($id < 1 ){
  119. $this->error('参数错误');
  120. }
  121. $info = db('meeting_apply')->where('id',$id)->find();
  122. if(!$info){
  123. $this->error('记录不存在');
  124. }
  125. $info['meeting_room'] = db('meeting_room')->where('id',$info['meeting_room_id'])->value('title');
  126. //申请人
  127. $info['apply_user'] = db('user')->where('id',$info['user_id'])->value('real_name');
  128. //审批人
  129. $info['approver_user'] = db('user')->where('id',$info['approver'])->value('real_name');
  130. //参会设备
  131. $meeting_devices = db('meeting_device')->whereIn('id',$info['meeting_devices'])->where('del',0)->select();
  132. $deviceName = [];
  133. foreach ($meeting_devices as $k=>$v){
  134. $deviceName[] = $v['title'];
  135. }
  136. $info['meeting_devices'] = $deviceName?implode(',',$deviceName):'';
  137. //参会人员
  138. $cUser= db('user')->whereIn('id',$info['user_ids'])->where('del',0)->select();
  139. $userName = [];
  140. foreach ($cUser as $k=>$v){
  141. $userName[] = $v['real_name'];
  142. }
  143. $info['user_name'] = $userName?implode(',',$userName):'';
  144. $info['dep_name'] = Db::name('dep')->where('id',$info['dep_id'])->value('title');
  145. $this->assign('info',$info);
  146. return $this->fetch();
  147. }
  148. //excel导出
  149. public function export() {
  150. set_time_limit(0);
  151. ini_set("memory_limit","1024M");
  152. $title = input('title','','trim');
  153. if($title){
  154. $map[] = ['u.real_name','like','%'.$title.'%'];
  155. }
  156. $room_id = input('room_id','','trim');
  157. if($room_id){
  158. $map[] = ['ma.meeting_room_id','=',$room_id];
  159. }
  160. $status = input('status','','trim');
  161. if($status != ''){
  162. $map[] = ['ma.status','=',$status];
  163. }
  164. $map[] = ['ma.del','=',0];
  165. $map[] = ['ma.org_id','=',cur_org_id()];
  166. $lists = db('meeting_apply')
  167. ->alias('ma')
  168. ->field('ma.*,u.real_name,mr.title as room_name')
  169. ->join('user u','u.id=ma.user_id')
  170. ->join('meeting_room mr','mr.id=ma.meeting_room_id')
  171. ->where($map)
  172. ->order('id desc')
  173. ->select();
  174. foreach ($lists as $k=>$v){
  175. if($v['status'] == 0){
  176. $lists[$k]['status_text'] = '待审核';
  177. }else if($v['status'] == 1){
  178. $lists[$k]['status_text'] = '已同意';
  179. }else if($v['status'] == 2){
  180. $lists[$k]['status_text'] = '已拒绝';
  181. }else{
  182. $lists[$k]['status_text'] = '已取消';
  183. }
  184. }
  185. $header = [
  186. ['title' => '编号', 'name' => 'id','width'=>'10'],
  187. ['title' => '申请人', 'name' => 'real_name','width'=>'20'],
  188. ['title' => '会议室名称', 'name' => 'room_name','width'=>'20'],
  189. ['title' => '开始时间', 'name' => 'start_time','width'=>'20'],
  190. ['title' => '结束时间', 'name' => 'end_time','width'=>'20'],
  191. ['title' => '状态', 'name' => 'status_text','width'=>'20'],
  192. // ['title' => '使用人部门', 'name' => 'dep_name','width'=>'20'],
  193. ];
  194. $filename = '会议室申请记录';
  195. ExcelUtil::export($filename,$header,$lists);
  196. }
  197. public function calendar(){
  198. $meetingId = input('meetingId',0);
  199. $m_title = '会议室审批列表';
  200. if($meetingId > 0){
  201. $m_title = '会议室列表';
  202. }
  203. $this->assign('m_title',$m_title);
  204. $this->assign('meetingId',$meetingId);
  205. return $this->fetch();
  206. }
  207. public function taskjson(){
  208. $start = input('start');
  209. $end = input('end');
  210. $data = array();
  211. if(!$start||!$end||$start>$end){
  212. header('Content-Type:application/json; charset=utf-8');
  213. exit(json_encode($data));
  214. }
  215. $start = date('Y-m-d H:i:s',strtotime($start));
  216. $end = date('Y-m-d H:i:s',strtotime($end));
  217. $meetingId = input('meetingId',0);
  218. if($meetingId >0){
  219. $map[] = ['meeting_room_id','=',$meetingId];
  220. }
  221. $map[] = ['del','=',0];
  222. $list = Db::name('meeting_apply')
  223. ->whereIn('status',[0,1])
  224. ->where('org_id',cur_org_id())
  225. ->where('start_time','>=',$start)
  226. ->where('end_time','<=',$end)
  227. ->where($map)
  228. ->select();
  229. foreach ($list as $k=>$v){
  230. // $uids = $v['user_ids']?explode(',',$v['user_ids']):[];
  231. // $users = Db::name('user')->whereIn('id',$uids)->column('real_name');
  232. // $users = $users ? implode(',',$users):'';
  233. $roomName= Db::name('meeting_room')->where('id',$v['meeting_room_id'])->value('title');
  234. $arr = array(
  235. 'id' => $v['id'],
  236. 'title' => "$roomName<br>开始时间:{$v['start_time']}<br>结束时间:{$v['end_time']}<br>",
  237. 'status' => $v['status'],
  238. 'start' => $v['start_time'],
  239. 'end' => $v['end_time']
  240. );
  241. if($v['status'] == 0){
  242. $arr['color'] = '#777777';
  243. }else if($v['status'] == 1){
  244. // $arr['color'] = '#478fca';
  245. $arr['color'] = '#69aa46';
  246. }else if($v['status'] == 2){
  247. $arr['color'] = '#69aa46';
  248. }else{
  249. $arr['color'] = '#dd5a43';
  250. }
  251. $data[] = $arr;
  252. }
  253. header('Content-Type:application/json; charset=utf-8');
  254. exit(json_encode($data));
  255. }
  256. }