meetingModel.php 16 KB

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