meetingModel.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. <?php
  2. class flow_meetingClassModel extends flowModel
  3. {
  4. public $hyarra, $ytarra, $hyarrb, $dbobj, $reatearr, $meeting_room;
  5. public function initModel()
  6. {
  7. $this->hyarra = array('正常','会议中','结束','取消');
  8. $this->ytarra = array('等待','待进行','进行中','已结束');
  9. $this->hyarrb = array('green','blue','#ff6600','#888888');
  10. $this->dbobj = c('date');
  11. // $this->defaultorder = 'start_time desc';
  12. $this->meeting_room = m("meeting_room")->meetingRoomIdList();
  13. $this->reatearr = array(
  14. 'd' => '每天',
  15. 'w1' => '每周一',
  16. 'w2' => '每周二',
  17. 'w3' => '每周三',
  18. 'w4' => '每周四',
  19. 'w5' => '每周五',
  20. 'w6' => '每周六',
  21. 'w7' => '每周日',
  22. 'm' => '每月',
  23. 'y' => '每年',
  24. );
  25. }
  26. //录入页上的标题
  27. public function inputtitle() {
  28. return "会议室审批单";
  29. }
  30. //子表数据替换处理$lx=0编辑时,1展示时
  31. protected function flowsubdata($rows, $lx=0){
  32. for ($i = 0; $i < count($rows); $i++) {
  33. if (isset($rows[$i]['topic_state']) && !empty($rows[$i]['topic_state'])) {
  34. $index = $rows[$i]['topic_state'] ?? 1;
  35. $rows[$i]['topic_state'] = $this->ytarra[$index];
  36. } else {
  37. $id = isset($rows[$i]['id']);
  38. m('meeting_topics')->update(['topic_state'=>1], "id={$id}");
  39. }
  40. }
  41. return $rows;
  42. }
  43. // 初始化单据可替换其他属性,$lx,0默认,1详情展示,2列表显示,3打印页,4外部详情页
  44. public function flowrsreplace($rs, $lx=0)
  45. {
  46. // m('log')->addlog('会议单据', json_encode($rs, true));
  47. $this->id = $rs['id'];
  48. $zt = $rs['meet_state'];
  49. $is_hand = $rs['is_hand'] ?? 0;
  50. $room_id = $rs['room_id'];
  51. $nzt = $zt;
  52. $time = time();
  53. $stime = strtotime($rs['start_time']);
  54. $etime = strtotime($rs['end_time']);
  55. if($is_hand != 1){
  56. if($etime < $time){
  57. $nzt = 2;
  58. } else if ($stime > $time){
  59. $nzt = 0;
  60. } else {
  61. $nzt = 1;
  62. $topic = m('meeting_topics')->getone("mid={$this->id}",'id, topic_state', 'sort');
  63. if (isset($topic['id']) && $topic['topic_state']<2) {
  64. m('meeting')->firstMeetingTopicStart($this->id);
  65. }
  66. }
  67. }
  68. if ($stime <= $time && $nzt != 2) {
  69. $nzt = 1;
  70. }
  71. // 更新数据状态
  72. if($zt != $nzt){
  73. $this->update('meet_state='.$nzt.'', $rs['id']);
  74. $zt = $nzt;
  75. }
  76. // 将id转换为文字
  77. $rs['meet_state'] = $this->getstatezt($zt);
  78. if (!empty($room_id)) $rs['room_id'] = $this->meeting_room[$room_id]['room_name']."({$this->meeting_room[$room_id]['desc']})"; // 会议室Id替换会议室名
  79. $rs['state_info'] = $this->getApproval($rs['nowcheckname'] ?? '');
  80. $meet_dev = ["不需要", "视频会议", "LED屏"];
  81. $rs['meet_dev'] = $rs['meet_dev'] == 0 ? $meet_dev[$rs['meet_dev']] : "<font color=red>".$meet_dev[$rs['meet_dev']]."</font>";
  82. $rs['fixed'] = $rs['fixed'] == 1 ? '是' : '否'; // 是否固定会议
  83. return $rs;
  84. }
  85. // $ors当前单据操作信息,$crs提交过来的信息
  86. public function flowoptmenu($ors, $crs)
  87. {
  88. // 切换会议议题
  89. if ($ors['num'] == 'changeTopic') {
  90. $topics = $this->db->getall("select * from `[Q]meeting_topics` where mid = {$this->id} order by sort");
  91. for ($i = 0; $i < count($topics); $i++) {
  92. if(isset($topics[$i]['topic_state']) && $topics[$i]['topic_state'] == 2) {
  93. $id = $topics[$i]['id'];
  94. $data = ['topic_state'=>$topics[$i]['topic_state']+1];
  95. m('meeting_topics')->update($data, "id={$id}");
  96. if (isset($topics[$i+1]['topic_state'])) {
  97. $id = $topics[$i+1]['id'];
  98. $data = ['topic_state'=>2];
  99. m('meeting_topics')->update($data, "id={$id}");
  100. }
  101. if (isset($topics[$i+2]['topic_state'])) {
  102. $id = $topics[$i+2]['id'];
  103. $data = ['topic_state'=>1];
  104. m('meeting_topics')->update($data, "id={$id}");
  105. }
  106. break;
  107. }
  108. }
  109. if (isset($topics[count($topics) - 1]) && $topics[count($topics) - 1]['topic_state'] == 2) {
  110. m('meeting')->update(['is_hand'=>1,'meet_state'=>2], "id={$this->id}");
  111. }
  112. } else if ($ors['num'] == 'enableMeeting') {
  113. $time = time();
  114. $stime = strtotime($this->rs['start_time']);
  115. $etime = strtotime($this->rs['end_time']);
  116. if ($stime < $time){
  117. $data = [
  118. 'meet_state'=>1,
  119. 'is_hand'=>1
  120. ];
  121. } else if ($stime >= $time) {
  122. $data = [
  123. 'meet_state'=>0,
  124. 'is_hand'=>1
  125. ];
  126. }
  127. m('meeting')->update($data, "id={$this->id}");
  128. $topic = m('meeting_topics')->getone("mid={$this->id}", "id", 'sort desc');
  129. if (isset($topic['id'])) {
  130. m('meeting_topics')->update(['topic_state'=>'2'], 'id='.$topic['id']);
  131. }
  132. } else if ($ors['num'] == 'disenableMeeting') {
  133. // $data = [
  134. // 'meet_state'=>2,
  135. // 'is_hand'=>1
  136. // ];
  137. //
  138. // m('meeting_key')->update($data, "id={$this->id}");
  139. } else if ($ors['num'] == "noup_chage_room") {
  140. $data = $this->rs;
  141. $roomName = $this->meeting_room[$data['room_id']]['room_name'];
  142. $isApply = m('meeting')->isapplymsg($this->rs['start_time'], $this->rs['end_time'], $roomName, $this->id, 1);
  143. if (empty($isApply)) {
  144. $this->update([
  145. "meeting_room"=>$roomName,
  146. ], "id={$this->id}");
  147. // 更换会议室 - 发送会议短信
  148. $this->meetingSuccSms($this->id);
  149. } else {
  150. return $isApply;
  151. }
  152. }
  153. }
  154. //操作菜单操作之前
  155. protected function flowoptmenubefore($ors, $arr)
  156. {
  157. if($ors['num']=='noup_chage_room') {
  158. $room_id = $this->rock->post('fields_room_id');
  159. $room = m("meeting_room")->getone("id={$room_id}", 'room_name');
  160. $roomName = $room['room_name'];
  161. $isApply = m('meeting')->isapplymsg($this->rs['start_time'], $this->rs['end_time'], $roomName, $this->id, 1);
  162. if (!empty($isApply)) {
  163. return $isApply;
  164. }
  165. }
  166. }
  167. //删除单据时调用
  168. public function flowdeletebill($sm) {
  169. // m('meet_sys')->deleteMeetingRoom($this->rs);
  170. }
  171. //审核之前调用$zt 状态, $sm说明
  172. protected function flowcheckbefore($zt, $sm) {
  173. if ($this->nowcourse['step'] == 1) {
  174. $this->meetingAuditSms($this->id);
  175. // return [
  176. // "msg"=>'发送短信'
  177. // ];
  178. } else if ($this->nowcourse['step'] == 2) {
  179. $meet_room = $sm['meeting_room'];
  180. $isApply = m('meeting')->isapplymsg($this->rs['start_time'], $this->rs['end_time'], $meet_room, $this->id, 1);
  181. if (!empty($isApply)) {
  182. return [
  183. "msg"=>$isApply
  184. ];
  185. }
  186. }
  187. }
  188. //审核完成后调用
  189. protected function flowcheckafter($zt, $sm){
  190. }
  191. //流程全部完成后调用
  192. protected function flowcheckfinsh($sm){
  193. // 审批完成给负责人发短信
  194. $this->meetingSuccSms($this->id);
  195. }
  196. // 自定义方法
  197. // 状态样式
  198. public function getstatezt($zt)
  199. {
  200. if (isset($this->hyarrb[$zt])) {
  201. $html = '<font color="'.$this->hyarrb[$zt].'">'.$this->hyarra[$zt].'</font>';
  202. return $html;
  203. } else {
  204. return null;
  205. }
  206. }
  207. // 审核样式
  208. public function getApproval($names) {
  209. if (empty($names)) {
  210. $html = '<font style="background-color:#00c959; padding: 2px 8px; border-radius: 4px; color: #fff">已审核</font>';
  211. return $html;
  212. } else {
  213. $html = '<font style="background-color:#ff4974; padding: 2px 8px; border-radius: 4px; color: #fff">待审核</font><br /><font style="color: #ff4974">审核人:'.$names.'</font>';
  214. return $html;
  215. }
  216. }
  217. // 短信发送
  218. public function meetingSuccSms($meetId) {
  219. if (empty($meetId)) {
  220. m("log")->addlog("短信发送", "会议Id为空");
  221. return;
  222. }
  223. // 获取当前会议信息
  224. $meeting = m("meeting")->getone("id={$this->id}");
  225. $meetTime = $meeting['start_time']; // 时间
  226. $meetName = $meeting['title']; // 主题
  227. $meetRoom = $meeting['meeting_room']; // 地点
  228. m("log")->addlog("会议室审批", "发送短信给".$meeting['attendees']);
  229. $userIds = []; // 用户id
  230. $users = []; // 用户信息
  231. $deptIds = []; // 部门id
  232. $depts = []; // 部门信息
  233. $nullMobileArr = ["user"=>[], "dept"=>[]]; // 没有手机号的用户、部门
  234. // 分解参会人员、部门id
  235. foreach (explode(',', $meeting['attendees_id']) as $val) {
  236. // u=用户 or d=部门
  237. if (substr($val, 0,1) == 'u') {
  238. $userIds[] = substr($val, 1);
  239. } else if (substr($val, 0,1) == 'd') {
  240. $deptIds[] = substr($val, 1);
  241. }
  242. }
  243. // 获取用户电话
  244. if (count($userIds) > 0) {
  245. // 获取所有用户信息
  246. $uInfo = m("admin")->getall("id in (".implode(',', $userIds).")");
  247. for ($i = 0; $i < count($userIds); $i++) {
  248. $mobile = $uInfo[$i]['mobile'];
  249. $name = $uInfo[$i]['name'];
  250. if (empty($mobile)) {
  251. $nullMobileArr['user'][] = $name;
  252. continue;
  253. }
  254. $users['phoneNum'][] = $mobile;
  255. $users['para'][] = [
  256. "name" => $name,
  257. "meetdate" => $meetTime,
  258. "meetname" => $meetName,
  259. "meetroom" => $meetRoom
  260. ];
  261. }
  262. if (count($users['phoneNum']) > 0) {
  263. m('send_sms')->sendBatchSms($users['phoneNum'], $users['para'], 1);
  264. }
  265. }
  266. if (count($deptIds) > 0) {
  267. $deptSql = "select distinct b.mobile, a.name from [Q]dept a left join [Q]admin b on a.headid = b.id where a.id in (".implode(',', $deptIds).") ";
  268. $dInfo = $this->db->getall($deptSql);
  269. for ($i = 0; $i < count($dInfo); $i++) {
  270. $mobile = $dInfo[$i]['mobile'];
  271. $name = $dInfo[$i]['name'];
  272. if (empty($mobile)) {
  273. $nullMobileArr['dept'][] = $name;
  274. continue;
  275. }
  276. $depts['phoneNum'][] = $mobile;
  277. $depts['para'][] = [
  278. "name" => $name,
  279. "meetdate" => $meetTime,
  280. "meetname" => $meetName,
  281. "meetroom" => $meetRoom
  282. ];
  283. }
  284. if (isset($depts['phoneNum']) && count($depts['phoneNum']) > 0) {
  285. m('send_sms')->sendBatchSms($depts['phoneNum'], $depts['para'], 1);
  286. }
  287. }
  288. $nullMobileInfo = '';
  289. if (count($nullMobileArr['user']) > 0) {
  290. $nullMobileInfo .= "以下用户未设手机号:".implode(',', $nullMobileArr['user'])."。";
  291. }
  292. if (count($nullMobileArr['dept']) > 0) {
  293. $nullMobileInfo .= "以下部门未设手机号:".implode(',', $nullMobileArr['dept'])."。";
  294. }
  295. if (!empty($nullMobileInfo)) {
  296. m("log")->addlog("会议短信", $nullMobileInfo);
  297. };
  298. }
  299. public function meetingAuditSms($meetId) {
  300. if (empty($meetId)) {
  301. m("log")->addlog("短信发送", "会议Id为空");
  302. return;
  303. }
  304. // 获取当前会议信息
  305. $meeting = m("meeting")->getone("id={$this->id}");
  306. $meetTime = $meeting['start_time']; // 时间
  307. $meetName = $meeting['title']; // 主题
  308. $smsInfo = [];
  309. m("log")->addlog("会议室审批", "发送短信提醒会议室管理员");
  310. $meetingManager = m("flow_cname")->getone("num='meeting_manager'");
  311. if (!empty($meetingManager)) {
  312. $cAdmins = m("admin")->getall("id in ({$meetingManager['checkid']})");
  313. if (!empty($cAdmins) && is_array($cAdmins)) {
  314. for ($i = 0; $i < count($cAdmins); $i++) {
  315. $user = $cAdmins[$i];
  316. $mobile = $user['mobile'];
  317. $meetUName = $user['name'];
  318. if (!empty($mobile)) {
  319. $smsInfo['phoneNum'][] = $mobile;
  320. $smsInfo['para'][] = [
  321. "usernam" => $meetUName,
  322. "meetingname" => $meetTime,
  323. "begindate" => $meetName
  324. ];
  325. }
  326. }
  327. if (count($smsInfo['phoneNum']) > 0) {
  328. m('send_sms')->sendBatchSms($smsInfo['phoneNum'], $smsInfo['para'], 2);
  329. }
  330. }
  331. }
  332. }
  333. // 固定会议,每日改变会议日期
  334. public function fixedMeetings($mid='') {
  335. $meets = $this->getall('fixed=1');
  336. for ($i = 0; $i < count($meets); $i++) {
  337. $meet = $meets[$i];
  338. $id = $meet['id'];
  339. $st = $meet['start_time'];
  340. $et = $meet['end_time'];
  341. $st = date("Y-m-d").' '.substr($st, 11);
  342. $et = date("Y-m-d").' '.substr($et, 11);
  343. m('meeting')->update([
  344. 'start_time'=>$st,
  345. 'end_time'=>$et,
  346. 'meet_state' => 0
  347. ], "id={$id}");
  348. }
  349. }
  350. }