meetingModel.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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. return $rs;
  83. }
  84. // $ors当前单据操作信息,$crs提交过来的信息
  85. public function flowoptmenu($ors, $crs)
  86. {
  87. // 切换会议议题
  88. if ($ors['num'] == 'changeTopic') {
  89. $topics = $this->db->getall("select * from `[Q]meeting_topics` where mid = {$this->id} order by sort");
  90. for ($i = 0; $i < count($topics); $i++) {
  91. if(isset($topics[$i]['topic_state']) && $topics[$i]['topic_state'] == 2) {
  92. $id = $topics[$i]['id'];
  93. $data = ['topic_state'=>$topics[$i]['topic_state']+1];
  94. m('meeting_topics')->update($data, "id={$id}");
  95. if (isset($topics[$i+1]['topic_state'])) {
  96. $id = $topics[$i+1]['id'];
  97. $data = ['topic_state'=>2];
  98. m('meeting_topics')->update($data, "id={$id}");
  99. }
  100. if (isset($topics[$i+2]['topic_state'])) {
  101. $id = $topics[$i+2]['id'];
  102. $data = ['topic_state'=>1];
  103. m('meeting_topics')->update($data, "id={$id}");
  104. }
  105. break;
  106. }
  107. }
  108. if (isset($topics[count($topics) - 1]) && $topics[count($topics) - 1]['topic_state'] == 2) {
  109. m('meeting')->update(['is_hand'=>1,'meet_state'=>2], "id={$this->id}");
  110. }
  111. } else if ($ors['num'] == 'enableMeeting') {
  112. $time = time();
  113. $stime = strtotime($this->rs['start_time']);
  114. $etime = strtotime($this->rs['end_time']);
  115. if ($stime < $time){
  116. $data = [
  117. 'meet_state'=>1,
  118. 'is_hand'=>1
  119. ];
  120. } else if ($stime >= $time) {
  121. $data = [
  122. 'meet_state'=>0,
  123. 'is_hand'=>1
  124. ];
  125. }
  126. m('meeting')->update($data, "id={$this->id}");
  127. $topic = m('meeting_topics')->getone("mid={$this->id}", "id", 'sort desc');
  128. if (isset($topic['id'])) {
  129. m('meeting_topics')->update(['topic_state'=>'2'], 'id='.$topic['id']);
  130. }
  131. } else if ($ors['num'] == 'disenableMeeting') {
  132. // $data = [
  133. // 'meet_state'=>2,
  134. // 'is_hand'=>1
  135. // ];
  136. //
  137. // m('meeting_key')->update($data, "id={$this->id}");
  138. } else if ($ors['num'] == "noup_chage_room") {
  139. $data = $this->rs;
  140. $roomName = $this->meeting_room[$data['room_id']]['room_name'];
  141. $isApply = m('meeting')->isapplymsg($this->rs['start_time'], $this->rs['end_time'], $roomName, $this->id, 1);
  142. if (empty($isApply)) {
  143. $this->update([
  144. "meeting_room"=>$roomName,
  145. ], "id={$this->id}");
  146. // 更换会议室 - 发送会议短信
  147. $this->meetingSuccSms($this->id);
  148. } else {
  149. return $isApply;
  150. }
  151. }
  152. }
  153. //操作菜单操作之前
  154. protected function flowoptmenubefore($ors, $arr)
  155. {
  156. if($ors['num']=='noup_chage_room') {
  157. $room_id = $this->rock->post('fields_room_id');
  158. $room = m("meeting_room")->getone("id={$room_id}", 'room_name');
  159. $roomName = $room['room_name'];
  160. $isApply = m('meeting')->isapplymsg($this->rs['start_time'], $this->rs['end_time'], $roomName, $this->id, 1);
  161. if (!empty($isApply)) {
  162. return $isApply;
  163. }
  164. }
  165. }
  166. //删除单据时调用
  167. public function flowdeletebill($sm) {
  168. // m('meet_sys')->deleteMeetingRoom($this->rs);
  169. }
  170. //审核之前调用$zt 状态, $sm说明
  171. protected function flowcheckbefore($zt, $sm) {
  172. if ($this->nowcourse['step'] == 1) {
  173. $this->meetingAuditSms($this->id);
  174. // return [
  175. // "msg"=>'发送短信'
  176. // ];
  177. } else if ($this->nowcourse['step'] == 2) {
  178. $meet_room = $sm['meeting_room'];
  179. $isApply = m('meeting')->isapplymsg($this->rs['start_time'], $this->rs['end_time'], $meet_room, $this->id, 1);
  180. if (!empty($isApply)) {
  181. return [
  182. "msg"=>$isApply
  183. ];
  184. }
  185. }
  186. }
  187. //审核完成后调用
  188. protected function flowcheckafter($zt, $sm){
  189. }
  190. //流程全部完成后调用
  191. protected function flowcheckfinsh($sm){
  192. // 审批完成给负责人发短信
  193. $this->meetingSuccSms($this->id);
  194. }
  195. // 自定义方法
  196. // 状态样式
  197. public function getstatezt($zt)
  198. {
  199. if (isset($this->hyarrb[$zt])) {
  200. $html = '<font color="'.$this->hyarrb[$zt].'">'.$this->hyarra[$zt].'</font>';
  201. return $html;
  202. } else {
  203. return null;
  204. }
  205. }
  206. // 审核样式
  207. public function getApproval($names) {
  208. if (empty($names)) {
  209. $html = '<font style="background-color:#00c959; padding: 2px 8px; border-radius: 4px; color: #fff">已审核</font>';
  210. return $html;
  211. } else {
  212. $html = '<font style="background-color:#ff4974; padding: 2px 8px; border-radius: 4px; color: #fff">待审核</font><br /><font style="color: #ff4974">审核人:'.$names.'</font>';
  213. return $html;
  214. }
  215. }
  216. // 短信发送
  217. public function meetingSuccSms($meetId) {
  218. if (empty($meetId)) {
  219. m("log")->addlog("短信发送", "会议Id为空");
  220. return;
  221. }
  222. // 获取当前会议信息
  223. $meeting = m("meeting")->getone("id={$this->id}");
  224. $meetTime = $meeting['start_time']; // 时间
  225. $meetName = $meeting['title']; // 主题
  226. $meetRoom = $meeting['meeting_room']; // 地点
  227. m("log")->addlog("会议室审批", "发送短信给".$meeting['attendees']);
  228. $userIds = []; // 用户id
  229. $users = []; // 用户信息
  230. $deptIds = []; // 部门id
  231. $depts = []; // 部门信息
  232. $nullMobileArr = ["user"=>[], "dept"=>[]]; // 没有手机号的用户、部门
  233. // 分解参会人员、部门id
  234. foreach (explode(',', $meeting['attendees_id']) as $val) {
  235. // u=用户 or d=部门
  236. if (substr($val, 0,1) == 'u') {
  237. $userIds[] = substr($val, 1);
  238. } else if (substr($val, 0,1) == 'd') {
  239. $deptIds[] = substr($val, 1);
  240. }
  241. }
  242. // 获取用户电话
  243. if (count($userIds) > 0) {
  244. // 获取所有用户信息
  245. $uInfo = m("admin")->getall("id in (".implode(',', $userIds).")");
  246. for ($i = 0; $i < count($userIds); $i++) {
  247. $mobile = $uInfo[$i]['mobile'];
  248. $name = $uInfo[$i]['name'];
  249. if (empty($mobile)) {
  250. $nullMobileArr['user'][] = $name;
  251. continue;
  252. }
  253. $users['phoneNum'][] = $mobile;
  254. $users['para'][] = [
  255. "name" => $name,
  256. "meetdate" => $meetTime,
  257. "meetname" => $meetName,
  258. "meetroom" => $meetRoom
  259. ];
  260. }
  261. if (count($users['phoneNum']) > 0) {
  262. m('send_sms')->sendBatchSms($users['phoneNum'], $users['para'], 1);
  263. }
  264. }
  265. if (count($deptIds) > 0) {
  266. $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).") ";
  267. $dInfo = $this->db->getall($deptSql);
  268. for ($i = 0; $i < count($dInfo); $i++) {
  269. $mobile = $dInfo[$i]['mobile'];
  270. $name = $dInfo[$i]['name'];
  271. if (empty($mobile)) {
  272. $nullMobileArr['dept'][] = $name;
  273. continue;
  274. }
  275. $depts['phoneNum'][] = $mobile;
  276. $depts['para'][] = [
  277. "name" => $name,
  278. "meetdate" => $meetTime,
  279. "meetname" => $meetName,
  280. "meetroom" => $meetRoom
  281. ];
  282. }
  283. if (isset($depts['phoneNum']) && count($depts['phoneNum']) > 0) {
  284. m('send_sms')->sendBatchSms($depts['phoneNum'], $depts['para'], 1);
  285. }
  286. }
  287. $nullMobileInfo = '';
  288. if (count($nullMobileArr['user']) > 0) {
  289. $nullMobileInfo .= "以下用户未设手机号:".implode(',', $nullMobileArr['user'])."。";
  290. }
  291. if (count($nullMobileArr['dept']) > 0) {
  292. $nullMobileInfo .= "以下部门未设手机号:".implode(',', $nullMobileArr['dept'])."。";
  293. }
  294. if (!empty($nullMobileInfo)) {
  295. m("log")->addlog("会议短信", $nullMobileInfo);
  296. };
  297. }
  298. public function meetingAuditSms($meetId) {
  299. if (empty($meetId)) {
  300. m("log")->addlog("短信发送", "会议Id为空");
  301. return;
  302. }
  303. // 获取当前会议信息
  304. $meeting = m("meeting")->getone("id={$this->id}");
  305. $meetTime = $meeting['start_time']; // 时间
  306. $meetName = $meeting['title']; // 主题
  307. $smsInfo = [];
  308. m("log")->addlog("会议室审批", "发送短信提醒会议室管理员");
  309. $meetingManager = m("flow_cname")->getone("num='meeting_manager'");
  310. if (!empty($meetingManager)) {
  311. $cAdmins = m("admin")->getall("id in ({$meetingManager['checkid']})");
  312. if (!empty($cAdmins) && is_array($cAdmins)) {
  313. for ($i = 0; $i < count($cAdmins); $i++) {
  314. $user = $cAdmins[$i];
  315. $mobile = $user['mobile'];
  316. $meetUName = $user['name'];
  317. if (!empty($mobile)) {
  318. $smsInfo['phoneNum'][] = $mobile;
  319. $smsInfo['para'][] = [
  320. "usernam" => $meetUName,
  321. "meetingname" => $meetTime,
  322. "begindate" => $meetName
  323. ];
  324. }
  325. }
  326. if (count($smsInfo['phoneNum']) > 0) {
  327. m('send_sms')->sendBatchSms($smsInfo['phoneNum'], $smsInfo['para'], 2);
  328. }
  329. }
  330. }
  331. }
  332. // 固定会议,每日改变会议日期
  333. public function fixedMeetings($mid='') {
  334. $meets = $this->getall('fixed=1');
  335. for ($i = 0; $i < count($meets); $i++) {
  336. $meet = $meets[$i];
  337. $id = $meet['id'];
  338. $st = $meet['start_time'];
  339. $et = $meet['end_time'];
  340. $st = date("Y-m-d").' '.substr($st, 11);
  341. $et = date("Y-m-d").' '.substr($et, 11);
  342. m('meeting')->update([
  343. 'start_time'=>$st,
  344. 'end_time'=>$et,
  345. 'meet_state' => 0
  346. ], "id={$id}");
  347. }
  348. }
  349. }