meetingModel.php 13 KB

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