meetingModel.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  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. // m("log")->addlog("会议室审批", "创建");
  26. $phoneNum = [
  27. "15309501557",
  28. "17701056405"
  29. ];
  30. $signName = "E通新枣泉";
  31. $param = [
  32. [
  33. "name"=>"秦锐1",
  34. "meetdate"=>"2024-04-08",
  35. "meetroom"=>"306会议室"
  36. ],
  37. [
  38. "name"=>"秦锐2",
  39. "meetdate"=>"2024-04-08",
  40. "meetroom"=>"306会议室"
  41. ]
  42. ];
  43. }
  44. //录入页上的标题
  45. public function inputtitle() {
  46. return "会议室审批单";
  47. }
  48. //子表数据替换处理$lx=0编辑时,1展示时
  49. protected function flowsubdata($rows, $lx=0){
  50. for ($i = 0; $i < count($rows); $i++) {
  51. if (isset($rows[$i]['topic_state']) && !empty($rows[$i]['topic_state'])) {
  52. $index = $rows[$i]['topic_state'] ?? 1;
  53. $rows[$i]['topic_state'] = $this->ytarra[$index];
  54. } else {
  55. $id = isset($rows[$i]['id']);
  56. m('meeting_topics')->update(['topic_state'=>1], "id={$id}");
  57. }
  58. }
  59. return $rows;
  60. }
  61. // 初始化单据可替换其他属性,$lx,0默认,1详情展示,2列表显示,3打印页,4外部详情页
  62. public function flowrsreplace($rs, $lx=0)
  63. {
  64. // m('log')->addlog('会议单据', json_encode($rs, true));
  65. $this->id = $rs['id'];
  66. $zt = $rs['meet_state'];
  67. $is_hand = $rs['is_hand'] ?? 0;
  68. $room_id = $rs['room_id'];
  69. $nzt = $zt;
  70. $time = time();
  71. $stime = strtotime($rs['start_time']);
  72. $etime = strtotime($rs['end_time']);
  73. if($is_hand != 1){
  74. if($etime < $time){
  75. $nzt = 2;
  76. } else if ($stime > $time){
  77. $nzt = 0;
  78. } else {
  79. $nzt = 1;
  80. $topic = m('meeting_topics')->getone("mid={$this->id}",'id, topic_state', 'sort');
  81. if (isset($topic['id']) && $topic['topic_state']<2) {
  82. m('meeting')->firstMeetingTopicStart($this->id);
  83. }
  84. }
  85. }
  86. if ($stime <= $time && $nzt != 2) {
  87. $nzt = 1;
  88. }
  89. // 更新数据状态
  90. if($zt != $nzt){
  91. $this->update('meet_state='.$nzt.'', $rs['id']);
  92. $zt = $nzt;
  93. }
  94. // 将id转换为文字
  95. $rs['meet_state'] = $this->getstatezt($zt);
  96. if (!empty($room_id)) $rs['room_id'] = $this->meeting_room[$room_id]['room_name']."({$this->meeting_room[$room_id]['desc']})"; // 会议室Id替换会议室名
  97. $rs['state_info'] = $this->getApproval($rs['nowcheckname'] ?? '');
  98. $meet_dev = ["不需要", "视频会议", "LED屏"];
  99. $rs['meet_dev'] = $rs['meet_dev'] == 0 ? $meet_dev[$rs['meet_dev']] : "<font color=red>".$meet_dev[$rs['meet_dev']]."</font>";
  100. return $rs;
  101. }
  102. // $ors当前单据操作信息,$crs提交过来的信息
  103. public function flowoptmenu($ors, $crs)
  104. {
  105. // 切换会议议题
  106. if ($ors['num'] == 'changeTopic') {
  107. $topics = $this->db->getall("select * from `[Q]meeting_topics` where mid = {$this->id} order by sort");
  108. for ($i = 0; $i < count($topics); $i++) {
  109. if(isset($topics[$i]['topic_state']) && $topics[$i]['topic_state'] == 2) {
  110. $id = $topics[$i]['id'];
  111. $data = ['topic_state'=>$topics[$i]['topic_state']+1];
  112. m('meeting_topics')->update($data, "id={$id}");
  113. if (isset($topics[$i+1]['topic_state'])) {
  114. $id = $topics[$i+1]['id'];
  115. $data = ['topic_state'=>2];
  116. m('meeting_topics')->update($data, "id={$id}");
  117. }
  118. if (isset($topics[$i+2]['topic_state'])) {
  119. $id = $topics[$i+2]['id'];
  120. $data = ['topic_state'=>1];
  121. m('meeting_topics')->update($data, "id={$id}");
  122. }
  123. break;
  124. }
  125. }
  126. if (isset($topics[count($topics) - 1]) && $topics[count($topics) - 1]['topic_state'] == 2) {
  127. m('meeting')->update(['is_hand'=>1,'meet_state'=>2], "id={$this->id}");
  128. }
  129. } else if ($ors['num'] == 'enableMeeting') {
  130. $time = time();
  131. $stime = strtotime($this->rs['start_time']);
  132. $etime = strtotime($this->rs['end_time']);
  133. if ($stime < $time){
  134. $data = [
  135. 'meet_state'=>1,
  136. 'is_hand'=>1
  137. ];
  138. } else if ($stime >= $time) {
  139. $data = [
  140. 'meet_state'=>0,
  141. 'is_hand'=>1
  142. ];
  143. }
  144. m('meeting')->update($data, "id={$this->id}");
  145. $topic = m('meeting_topics')->getone("mid={$this->id}", "id", 'sort desc');
  146. if (isset($topic['id'])) {
  147. m('meeting_topics')->update(['topic_state'=>'2'], 'id='.$topic['id']);
  148. }
  149. } else if ($ors['num'] == 'disenableMeeting') {
  150. // $data = [
  151. // 'meet_state'=>2,
  152. // 'is_hand'=>1
  153. // ];
  154. //
  155. // m('meeting_key')->update($data, "id={$this->id}");
  156. } else if ($ors['num'] == "noup_chage_room") {
  157. $data = $this->rs;
  158. $roomName = $this->meeting_room[$data['room_id']]['room_name'];
  159. $isApply = m('meeting')->isapplymsg($this->rs['start_time'], $this->rs['end_time'], $roomName, $this->id, 1);
  160. if (empty($isApply)) {
  161. $this->update([
  162. "meeting_room"=>$roomName,
  163. ], "id={$this->id}");
  164. // 更换会议室 - 发送会议短信
  165. $this->meetingSuccSms($this->id);
  166. } else {
  167. return $isApply;
  168. }
  169. }
  170. }
  171. //操作菜单操作之前
  172. protected function flowoptmenubefore($ors, $arr)
  173. {
  174. if($ors['num']=='noup_chage_room') {
  175. $room_id = $this->rock->post('fields_room_id');
  176. $room = m("meeting_room")->getone("id={$room_id}", 'room_name');
  177. $roomName = $room['room_name'];
  178. $isApply = m('meeting')->isapplymsg($this->rs['start_time'], $this->rs['end_time'], $roomName, $this->id, 1);
  179. if (!empty($isApply)) {
  180. return $isApply;
  181. }
  182. }
  183. }
  184. //删除单据时调用
  185. public function flowdeletebill($sm) {
  186. // m('meet_sys')->deleteMeetingRoom($this->rs);
  187. }
  188. //审核之前调用$zt 状态, $sm说明
  189. protected function flowcheckbefore($zt, $sm) {
  190. if ($this->nowcourse['step'] == 1) {
  191. $this->meetingAuditSms($this->id);
  192. // return [
  193. // "msg"=>'发送短信'
  194. // ];
  195. } else if ($this->nowcourse['step'] == 2) {
  196. if (!empty($isApply)) {
  197. $haha = $this->rs['room_id'];
  198. $meet_room = $sm['room_id'];
  199. $meet_room = $sm['meeting_room'];
  200. $meeting = m('meeting')->getone("room_id={$meet_room} and ");
  201. $isApply = m('meeting')->isapplymsg($this->rs['start_time'], $this->rs['end_time'], $meet_room, $this->id, 1);
  202. return [
  203. "msg"=>$isApply
  204. ];
  205. }
  206. }
  207. }
  208. //审核完成后调用
  209. protected function flowcheckafter($zt, $sm){
  210. }
  211. //流程全部完成后调用
  212. protected function flowcheckfinsh($sm){
  213. // 审批完成给负责人发短信
  214. $this->meetingSuccSms($this->id);
  215. }
  216. // 自定义方法
  217. // 状态样式
  218. public function getstatezt($zt)
  219. {
  220. if (isset($this->hyarrb[$zt])) {
  221. $html = '<font color="'.$this->hyarrb[$zt].'">'.$this->hyarra[$zt].'</font>';
  222. return $html;
  223. } else {
  224. return null;
  225. }
  226. }
  227. // 审核样式
  228. public function getApproval($names) {
  229. if (empty($names)) {
  230. $html = '<font style="background-color:#00c959; padding: 2px 8px; border-radius: 4px; color: #fff">已审核</font>';
  231. return $html;
  232. } else {
  233. $html = '<font style="background-color:#ff4974; padding: 2px 8px; border-radius: 4px; color: #fff">待审核</font><br /><font style="color: #ff4974">审核人:'.$names.'</font>';
  234. return $html;
  235. }
  236. }
  237. // 短信发送
  238. public function meetingSuccSms($meetId) {
  239. if (empty($meetId)) {
  240. m("log")->addlog("短信发送", "会议Id为空");
  241. return;
  242. }
  243. // 获取当前会议信息
  244. $meeting = m("meeting")->getone("id={$this->id}");
  245. $meetTime = $meeting['start_time']; // 时间
  246. $meetName = $meeting['title']; // 主题
  247. $meetRoom = $meeting['meeting_room']; // 地点
  248. m("log")->addlog("会议室审批", "发送短信给".$meeting['attendees']);
  249. $userIds = []; // 用户id
  250. $users = []; // 用户信息
  251. $deptIds = []; // 部门id
  252. $depts = []; // 部门信息
  253. $nullMobileArr = ["user"=>[], "dept"=>[]]; // 没有手机号的用户、部门
  254. // 分解参会人员、部门id
  255. foreach (explode(',', $meeting['attendees_id']) as $val) {
  256. // u=用户 or d=部门
  257. if (substr($val, 0,1) == 'u') {
  258. $userIds[] = substr($val, 1);
  259. } else if (substr($val, 0,1) == 'd') {
  260. $deptIds[] = substr($val, 1);
  261. }
  262. }
  263. // 获取用户电话
  264. if (count($userIds) > 0) {
  265. // 获取所有用户信息
  266. $uInfo = m("admin")->getall("id in (".implode(',', $userIds).")");
  267. for ($i = 0; $i < count($userIds); $i++) {
  268. $mobile = $uInfo[$i]['mobile'];
  269. $name = $uInfo[$i]['name'];
  270. if (empty($mobile)) {
  271. $nullMobileArr['user'][] = $name;
  272. continue;
  273. }
  274. $users['phoneNum'][] = $mobile;
  275. $users['para'][] = [
  276. "name" => $name,
  277. "meetdate" => $meetTime,
  278. "meetname" => $meetName,
  279. "meetroom" => $meetRoom
  280. ];
  281. }
  282. if (count($users['phoneNum']) > 0) {
  283. m('send_sms')->sendBatchSms($users['phoneNum'], $users['para'], 1);
  284. }
  285. }
  286. if (count($deptIds) > 0) {
  287. $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).") ";
  288. $dInfo = $this->db->getall($deptSql);
  289. for ($i = 0; $i < count($dInfo); $i++) {
  290. $mobile = $dInfo[$i]['mobile'];
  291. $name = $dInfo[$i]['name'];
  292. if (empty($mobile)) {
  293. $nullMobileArr['dept'][] = $name;
  294. continue;
  295. }
  296. $depts['phoneNum'][] = $mobile;
  297. $depts['para'][] = [
  298. "name" => $name,
  299. "meetdate" => $meetTime,
  300. "meetname" => $meetName,
  301. "meetroom" => $meetRoom
  302. ];
  303. }
  304. if (isset($depts['phoneNum']) && count($depts['phoneNum']) > 0) {
  305. m('send_sms')->sendBatchSms($depts['phoneNum'], $depts['para'], 1);
  306. }
  307. }
  308. $nullMobileInfo = '';
  309. if (count($nullMobileArr['user']) > 0) {
  310. $nullMobileInfo .= "以下用户未设手机号:".implode(',', $nullMobileArr['user'])."。";
  311. }
  312. if (count($nullMobileArr['dept']) > 0) {
  313. $nullMobileInfo .= "以下部门未设手机号:".implode(',', $nullMobileArr['dept'])."。";
  314. }
  315. if (!empty($nullMobileInfo)) {
  316. m("log")->addlog("会议短信", $nullMobileInfo);
  317. };
  318. }
  319. public function meetingAuditSms($meetId) {
  320. if (empty($meetId)) {
  321. m("log")->addlog("短信发送", "会议Id为空");
  322. return;
  323. }
  324. // 获取当前会议信息
  325. $meeting = m("meeting")->getone("id={$this->id}");
  326. $meetTime = $meeting['start_time']; // 时间
  327. $meetName = $meeting['title']; // 主题
  328. $smsInfo = [];
  329. m("log")->addlog("会议室审批", "发送短信提醒会议室管理员");
  330. $meetingManager = m("flow_cname")->getone("num='meeting_manager'");
  331. if (!empty($meetingManager)) {
  332. $cAdmins = m("admin")->getall("id in ({$meetingManager['checkid']})");
  333. if (!empty($cAdmins) && is_array($cAdmins)) {
  334. for ($i = 0; $i < count($cAdmins); $i++) {
  335. $user = $cAdmins[$i];
  336. $mobile = $user['mobile'];
  337. $meetUName = $user['name'];
  338. if (!empty($mobile)) {
  339. $smsInfo['phoneNum'][] = $mobile;
  340. $smsInfo['para'][] = [
  341. "usernam" => $meetUName,
  342. "meetingname" => $meetTime,
  343. "begindate" => $meetName
  344. ];
  345. }
  346. }
  347. if (count($smsInfo['phoneNum']) > 0) {
  348. m('send_sms')->sendBatchSms($smsInfo['phoneNum'], $smsInfo['para'], 2);
  349. }
  350. }
  351. }
  352. }
  353. }