meetingModel.php 13 KB

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