meetingModel.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  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 = ["不需要", "远程视频会议", "电子大屏"];
  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. //提交时调用
  86. protected function flowsubmit($na, $sm){
  87. $this->updateAttendees($this->id); // 更新部门名
  88. $this->meetingAuditSms($this->id, 0); // 提醒领导审核
  89. $this->meetingApplicantSms($this->id); // 提醒申请人
  90. $this->meetingMaXuSms($this->id); // 单独给马旭发
  91. }
  92. // $ors当前单据操作信息,$crs提交过来的信息
  93. public function flowoptmenu($ors, $crs)
  94. {
  95. if ($ors['num'] == 'enableMeeting') {
  96. // 开始会议
  97. $data = [
  98. 'meet_state'=>1,
  99. 'is_hand'=>1
  100. ];
  101. m('meeting')->update($data, "id={$this->id}");
  102. } else if ($ors['num'] == 'noup_end_meet') {
  103. // 手动结束会议
  104. $data = [
  105. 'meet_state'=>2,
  106. 'is_hand'=>1
  107. ];
  108. m('meeting')->update($data, "id={$this->id}");
  109. } else if ($ors['num'] == "noup_change_room") {
  110. $data = $this->rs;
  111. $roomName = $this->meeting_room[$data['room_id']]['room_name'];
  112. $isApply = m('meeting')->isapplymsg($this->rs['start_time'], $this->rs['end_time'], $roomName, $this->id, 1);
  113. if (empty($isApply)) {
  114. $this->update([
  115. "meeting_room"=>$roomName,
  116. ], "id={$this->id}");
  117. // 更换会议室 - 发送会议短信
  118. $this->meetingSuccSms($this->id);
  119. } else {
  120. return $isApply;
  121. }
  122. } else if ($ors['num']=='updateAttendees') {
  123. // 更新部门信息
  124. $this->updateAttendees($this->id);
  125. }
  126. }
  127. //操作菜单操作之前
  128. protected function flowoptmenubefore($ors, $arr)
  129. {
  130. if($ors['num']=='noup_change_room') {
  131. $room_id = $this->rock->post('fields_room_id');
  132. $room = m("meeting_room")->getone("id={$room_id}", 'room_name');
  133. $roomName = $room['room_name'];
  134. $isApply = m('meeting')->isapplymsg($this->rs['start_time'], $this->rs['end_time'], $roomName, $this->id, 1);
  135. if (!empty($isApply)) {
  136. return $isApply;
  137. }
  138. }
  139. }
  140. //删除单据时调用
  141. public function flowdeletebill($sm) {
  142. // m('meet_sys')->deleteMeetingRoom($this->rs);
  143. }
  144. //审核之前调用$zt 状态, $sm说明
  145. protected function flowcheckbefore($zt, $sm, $ufied) {
  146. if ($this->nowcourse['step'] == 1) {
  147. $this->meetingAuditSms($this->id, 1);
  148. // return [
  149. // "msg"=>'发送短信'
  150. // ];
  151. } else if ($this->nowcourse['step'] == 2) {
  152. $meet_room = $ufied['meeting_room'];
  153. $isApply = m('meeting')->isapplymsg($this->rs['start_time'], $this->rs['end_time'], $meet_room, $this->id, 1);
  154. if (!empty($isApply)) {
  155. return [
  156. "msg"=>$isApply
  157. ];
  158. }
  159. }
  160. }
  161. //审核完成后调用
  162. protected function flowcheckafter($zt, $sm){
  163. }
  164. //流程全部完成后调用
  165. protected function flowcheckfinsh($sm){
  166. // 审批完成给负责人发短信
  167. $this->meetingSuccSms($this->id);
  168. }
  169. //单据判断条件从写$lx类型,$uid用户Id
  170. protected function flowbillwhere($lx, $uid){
  171. return [
  172. 'order'=>'start_time desc'
  173. ];
  174. }
  175. // 自定义方法
  176. // 状态样式
  177. public function getstatezt($zt)
  178. {
  179. if (isset($this->hyarrb[$zt])) {
  180. $html = '<font color="'.$this->hyarrb[$zt].'">'.$this->hyarra[$zt].'</font>';
  181. return $html;
  182. } else {
  183. return null;
  184. }
  185. }
  186. // 审核样式
  187. public function getApproval($names) {
  188. if (empty($names)) {
  189. $html = '<font style="background-color:#00c959; padding: 2px 8px; border-radius: 4px; color: #fff">已审核</font>';
  190. return $html;
  191. } else {
  192. $html = '<font style="background-color:#ff4974; padding: 2px 8px; border-radius: 4px; color: #fff">待审核</font><br /><font style="color: #ff4974">审核人:'.$names.'</font>';
  193. return $html;
  194. }
  195. }
  196. // 审批完成通知参会
  197. public function meetingSuccSms($meetId) {
  198. if (empty($meetId)) {
  199. m("log")->addlog("短信发送", "会议Id为空");
  200. return;
  201. }
  202. // 获取当前会议信息
  203. $meeting = m("meeting")->getone("id={$this->id}");
  204. $meetTime = $meeting['start_time']; // 时间
  205. $meetTime = date('m月d日H点i分', strtotime($meetTime));
  206. $meetName = $this->strLength35($meeting['title']); // 主题
  207. $meetRoom = $meeting['meeting_room']; // 地点
  208. $orgDeptname = $meeting['apply_dept']; // 申请部门(组织部门)
  209. m("log")->addlog("会议室审批", "发送短信给".$meeting['attendees']);
  210. $userIds = []; // 用户id
  211. $users = []; // 用户信息
  212. $deptIds = []; // 部门id
  213. $depts = []; // 部门信息
  214. $nullMobileArr = ["user"=>[], "dept"=>[]]; // 没有手机号的用户、部门
  215. // 分解参会人员、部门id
  216. foreach (explode(',', $meeting['attendees_id']) as $val) {
  217. // u=用户 or d=部门
  218. if (substr($val, 0,1) == 'u') {
  219. $userIds[] = substr($val, 1);
  220. } else if (substr($val, 0,1) == 'd') {
  221. $deptIds[] = substr($val, 1);
  222. }
  223. }
  224. // 通知用户:获取用户电话
  225. if (count($userIds) > 0) {
  226. // 获取所有用户信息
  227. $uInfo = m("admin")->getall("id in (".implode(',', $userIds).")");
  228. for ($i = 0; $i < count($userIds); $i++) {
  229. $mobile = $uInfo[$i]['mobile'];
  230. $name = $uInfo[$i]['name'];
  231. if (empty($mobile)) {
  232. $nullMobileArr['user'][] = $name;
  233. continue;
  234. }
  235. $users['phoneNum'][] = $mobile;
  236. $users['para'][] = [
  237. // "notify_name" => mb_substr($name, 0, 1, 'UTF-8'),
  238. "org_deptname" => $orgDeptname,
  239. "meetdate" => $meetTime,
  240. "meetname" => $meetName,
  241. "meetroom" => $meetRoom
  242. ];
  243. }
  244. if (count($users['phoneNum']) > 0) {
  245. // m('send_sms')->sendBatchSms($users['phoneNum'], $users['para'], 5);
  246. m('send_sms')->sendBatchSms($users['phoneNum'], $users['para'], 7);
  247. }
  248. }
  249. // 通知部门
  250. if (count($deptIds) > 0) {
  251. $deptSql = "SELECT distinct a.mobile, b.name FROM zqoa_admin a JOIN zqoa_dept b ON FIND_IN_SET(a.id, b.headid) > 0 WHERE b.id IN (".implode(',', $deptIds).")";
  252. $dInfo = $this->db->getall($deptSql);
  253. for ($i = 0; $i < count($dInfo); $i++) {
  254. $mobile = $dInfo[$i]['mobile'];
  255. $deptName = $dInfo[$i]['name']; // 部门名
  256. if (empty($mobile)) {
  257. $nullMobileArr['dept'][] = $name;
  258. continue;
  259. }
  260. $depts['phoneNum'][] = $mobile;
  261. $depts['para'][] = [
  262. "notify_deptname" => $deptName,
  263. "org_deptname" => $orgDeptname,
  264. // "deptname" => $deptName,
  265. "meetdate" => $meetTime,
  266. "meetname" => $meetName,
  267. "meetroom" => $meetRoom
  268. ];
  269. }
  270. if (isset($depts['phoneNum']) && count($depts['phoneNum']) > 0) {
  271. m('send_sms')->sendBatchSms($depts['phoneNum'], $depts['para'], 6);
  272. }
  273. }
  274. $nullMobileInfo = '';
  275. if (count($nullMobileArr['user']) > 0) {
  276. $nullMobileInfo .= "以下用户未设手机号:".implode(',', $nullMobileArr['user'])."。";
  277. }
  278. if (count($nullMobileArr['dept']) > 0) {
  279. $nullMobileInfo .= "以下部门未设手机号:".implode(',', $nullMobileArr['dept'])."。";
  280. }
  281. if (!empty($nullMobileInfo)) {
  282. m("log")->addlog("会议短信", $nullMobileInfo);
  283. };
  284. }
  285. // 提醒审批
  286. public function meetingAuditSms($meetId, $setp) {
  287. if (empty($meetId)) {
  288. m("log")->addlog("短信发送", "会议Id为空");
  289. return;
  290. }
  291. // 获取当前会议信息
  292. $meeting = m("meeting")->getone("id={$this->id}");
  293. $meetTime = $meeting['start_time']; // 时间
  294. $meetTime = date('m月d日H点i分', strtotime($meetTime));
  295. $meetName = $this->strLength35($meeting['title']); // 主题
  296. $smsInfo = [];
  297. if ($setp == 0) {
  298. m("log")->addlog("会议室审批", "提醒部门领导审批【".$meetName."】");
  299. $checkid = $this->nowcourse['checkid'];
  300. } else {
  301. $checkid = $this->nextcourse['checkid'];
  302. m("log")->addlog("会议室审批", "提醒管理员审批【".$meetName."】");
  303. }
  304. if (!empty($checkid)) {
  305. $cAdmins = m("admin")->getall("id in ({$checkid})");
  306. if (!empty($cAdmins) && is_array($cAdmins)) {
  307. for ($i = 0; $i < count($cAdmins); $i++) {
  308. $user = $cAdmins[$i];
  309. $mobile = $user['mobile']; // 领导手机号
  310. $meetUName = $this->rs['attn']; // 申请人姓名
  311. if (!empty($mobile)) {
  312. $smsInfo['phoneNum'][] = $mobile;
  313. $smsInfo['para'][] = [
  314. "usernam" => $meetUName,
  315. "username" => $meetUName,
  316. "meetingname" => $meetName,
  317. "begindate" => $meetTime,
  318. ];
  319. }
  320. }
  321. if (count($smsInfo['phoneNum']) > 0) {
  322. m('send_sms')->sendBatchSms($smsInfo['phoneNum'], $smsInfo['para'], 2);
  323. }
  324. }
  325. }
  326. }
  327. // 提醒申请人
  328. public function meetingApplicantSms($meetId) {
  329. if (empty($meetId)) {
  330. m("log")->addlog("短信发送", "会议Id为空");
  331. return;
  332. }
  333. if (empty($this->rs)) {
  334. m("log")->addlog("短信发送", "表单数据为空");
  335. return;
  336. }
  337. // 获取当前会议信息
  338. $meeting = m("meeting")->getone("id={$this->id}");
  339. $uname = $this->rs['optname'];
  340. $mdate = date('m月d日H点i分', strtotime($this->rs['start_time']));
  341. $mname = $this->strLength35($this->rs['title']);
  342. $mobile = $this->rs['mobile'];
  343. $smsInfo['phoneNum'][] = $mobile;
  344. $smsInfo['para'][] = [
  345. "username" => $uname,
  346. "date" => $mdate,
  347. "meetname" => $mname
  348. ];
  349. if (count($smsInfo['phoneNum']) > 0) {
  350. m('send_sms')->sendBatchSms($smsInfo['phoneNum'], $smsInfo['para'], 4);
  351. }
  352. }
  353. public function meetingMaXuSms($meetId) {
  354. if (empty($meetId)) {
  355. m("log")->addlog("短信发送", "会议Id为空");
  356. return;
  357. }
  358. if (empty($this->rs)) {
  359. m("log")->addlog("短信发送", "表单数据为空");
  360. return;
  361. }
  362. $uname = "马旭";
  363. $mdate = date('m月d日H点i分', strtotime($this->rs['start_time']));
  364. $mname = $this->strLength35($this->rs['title']);
  365. $mobile = "18695503090";
  366. $smsInfo['phoneNum'][] = $mobile;
  367. $smsInfo['para'][] = [
  368. "username" => $uname,
  369. "date" => $mdate,
  370. "meetname" => $mname
  371. ];
  372. if (count($smsInfo['phoneNum']) > 0) {
  373. m('send_sms')->sendBatchSms($smsInfo['phoneNum'], $smsInfo['para'], 4);
  374. }
  375. }
  376. // 固定会议,每日改变会议日期
  377. public function fixedMeetings($mid='') {
  378. $meets = $this->getall('fixed=1');
  379. for ($i = 0; $i < count($meets); $i++) {
  380. $meet = $meets[$i];
  381. $date = date('Y-m-d', strtotime('+1 day'));
  382. $id = $meet['id'];
  383. $st = $meet['start_time'];
  384. $et = $meet['end_time'];
  385. $st = $date.' '.substr($st, 11);
  386. $et = $date.' '.substr($et, 11);
  387. m('meeting')->update([
  388. 'start_time'=>$st,
  389. 'end_time'=>$et,
  390. 'meet_state' => 0,
  391. 'is_hand' => 0
  392. ], "id={$id}");
  393. }
  394. }
  395. function strLength35($str) {
  396. if (strlen($str) > 35) {
  397. // 截取前35个字符
  398. $str = mb_substr($str, 0, 35, 'UTF-8');
  399. // 如果截取后的字符串长度达到35,则添加省略号
  400. if (mb_strlen($str, 'UTF-8') == 35) {
  401. $str = mb_substr($str, 0, 34, 'UTF-8') . '…';
  402. }
  403. }
  404. return $str;
  405. }
  406. function updateAttendees($meetingId) {
  407. $meetingInfo = m('meeting')->getone("id = $meetingId");
  408. $attendees_id = $meetingInfo['attendees_id'];
  409. $attendees_arr = explode(',', $attendees_id);
  410. $dept_arr = [];
  411. $user_arr = [];
  412. for ($i = 0; $i < count($attendees_arr); $i++) {
  413. $att = $attendees_arr[$i];
  414. $start_str = substr($att, 0, 1);
  415. if ($start_str == 'd') {
  416. $dept_arr[] = substr($att, 1);
  417. } else if ($start_str == 'u') {
  418. $user_arr[] = substr($att, 1);
  419. };
  420. }
  421. $dept_str = implode(',', $dept_arr);
  422. $user_str = implode(',', $user_arr);
  423. $dept_names = m('dept')->getall("id in ($dept_str)", "name", 'sort');
  424. $user_names = m('admin')->getall("id in ($user_str)", 'name', 'sort');
  425. $dept_names = array_column($dept_names, 'name');
  426. $user_names = array_column($user_names, 'name');
  427. $data['attendees'] = '';
  428. if ($dept_names != null) {
  429. $name = implode(',', $dept_names);
  430. $data['attendees'] .= $name;
  431. }
  432. if ($user_names != null) {
  433. if ($dept_names != null) $data['attendees'] .= ',';
  434. $name = implode(',', $user_names);
  435. $data['attendees'] .= $name;
  436. }
  437. // // 英文双引号替换为中文双引号
  438. $meetingTitle = html_entity_decode($meetingInfo['title'], ENT_QUOTES, 'UTF-8');
  439. $meetingTitle = preg_replace('/"([^"]*)"/', '“${1}”', $meetingTitle);
  440. $data['title'] = str_replace('"', '“', $meetingTitle);
  441. m('meeting')->update($data, "id = $meetingId");
  442. }
  443. }