meetingModel.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  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_chage_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_chage_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) {
  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 = $sm['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. m("log")->addlog("会议室审批", "发送短信给".$meeting['attendees']);
  205. $userIds = []; // 用户id
  206. $users = []; // 用户信息
  207. $deptIds = []; // 部门id
  208. $depts = []; // 部门信息
  209. $nullMobileArr = ["user"=>[], "dept"=>[]]; // 没有手机号的用户、部门
  210. // 分解参会人员、部门id
  211. foreach (explode(',', $meeting['attendees_id']) as $val) {
  212. // u=用户 or d=部门
  213. if (substr($val, 0,1) == 'u') {
  214. $userIds[] = substr($val, 1);
  215. } else if (substr($val, 0,1) == 'd') {
  216. $deptIds[] = substr($val, 1);
  217. }
  218. }
  219. // 用户:获取用户电话
  220. if (count($userIds) > 0) {
  221. // 获取所有用户信息
  222. $uInfo = m("admin")->getall("id in (".implode(',', $userIds).")");
  223. for ($i = 0; $i < count($userIds); $i++) {
  224. $mobile = $uInfo[$i]['mobile'];
  225. $name = $uInfo[$i]['name'];
  226. if (empty($mobile)) {
  227. $nullMobileArr['user'][] = $name;
  228. continue;
  229. }
  230. $users['phoneNum'][] = $mobile;
  231. $users['para'][] = [
  232. "name" => $name,
  233. "meetdate" => $meetTime,
  234. "meetname" => $meetName,
  235. "meetroom" => $meetRoom
  236. ];
  237. }
  238. if (count($users['phoneNum']) > 0) {
  239. m('send_sms')->sendBatchSms($users['phoneNum'], $users['para'], 1);
  240. }
  241. }
  242. // 部门
  243. if (count($deptIds) > 0) {
  244. // $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).") ";
  245. // $deptSql = "SELECT * FROM [Q]admin WHERE FIND_IN_SET(id, (SELECT headid FROM [Q]dept WHERE id in (".implode(',', $deptIds)."))";
  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. "deptname" => $deptName,
  258. "meetdate" => $meetTime,
  259. "meetname" => $meetName,
  260. "meetroom" => $meetRoom
  261. ];
  262. }
  263. if (isset($depts['phoneNum']) && count($depts['phoneNum']) > 0) {
  264. m('send_sms')->sendBatchSms($depts['phoneNum'], $depts['para'], 3);
  265. }
  266. }
  267. $nullMobileInfo = '';
  268. if (count($nullMobileArr['user']) > 0) {
  269. $nullMobileInfo .= "以下用户未设手机号:".implode(',', $nullMobileArr['user'])."。";
  270. }
  271. if (count($nullMobileArr['dept']) > 0) {
  272. $nullMobileInfo .= "以下部门未设手机号:".implode(',', $nullMobileArr['dept'])."。";
  273. }
  274. if (!empty($nullMobileInfo)) {
  275. m("log")->addlog("会议短信", $nullMobileInfo);
  276. };
  277. }
  278. // 提醒审批
  279. public function meetingAuditSms($meetId, $setp) {
  280. if (empty($meetId)) {
  281. m("log")->addlog("短信发送", "会议Id为空");
  282. return;
  283. }
  284. // 获取当前会议信息
  285. $meeting = m("meeting")->getone("id={$this->id}");
  286. $meetTime = $meeting['start_time']; // 时间
  287. $meetTime = date('m月d日H点i分', strtotime($meetTime));
  288. $meetName = $this->strLength35($meeting['title']); // 主题
  289. $smsInfo = [];
  290. if ($setp == 0) {
  291. m("log")->addlog("会议室审批", "提醒部门领导审批【".$meetName."】");
  292. $checkid = $this->nowcourse['checkid'];
  293. } else {
  294. $checkid = $this->nextcourse['checkid'];
  295. m("log")->addlog("会议室审批", "提醒管理员审批【".$meetName."】");
  296. }
  297. if (!empty($checkid)) {
  298. $cAdmins = m("admin")->getall("id in ({$checkid})");
  299. if (!empty($cAdmins) && is_array($cAdmins)) {
  300. for ($i = 0; $i < count($cAdmins); $i++) {
  301. $user = $cAdmins[$i];
  302. $mobile = $user['mobile']; // 领导手机号
  303. $meetUName = $this->rs['attn']; // 申请人姓名
  304. if (!empty($mobile)) {
  305. $smsInfo['phoneNum'][] = $mobile;
  306. $smsInfo['para'][] = [
  307. "usernam" => $meetUName,
  308. "username" => $meetUName,
  309. "meetingname" => $meetName,
  310. "begindate" => $meetTime,
  311. ];
  312. }
  313. }
  314. if (count($smsInfo['phoneNum']) > 0) {
  315. m('send_sms')->sendBatchSms($smsInfo['phoneNum'], $smsInfo['para'], 2);
  316. }
  317. }
  318. }
  319. }
  320. // 提醒申请人
  321. public function meetingApplicantSms($meetId) {
  322. if (empty($meetId)) {
  323. m("log")->addlog("短信发送", "会议Id为空");
  324. return;
  325. }
  326. if (empty($this->rs)) {
  327. m("log")->addlog("短信发送", "表单数据为空");
  328. return;
  329. }
  330. // 获取当前会议信息
  331. $meeting = m("meeting")->getone("id={$this->id}");
  332. $uname = $this->rs['optname'];
  333. $mdate = date('m月d日H点i分', strtotime($this->rs['start_time']));
  334. $mname = $this->strLength35($this->rs['title']);
  335. $mobile = $this->rs['mobile'];
  336. $smsInfo['phoneNum'][] = $mobile;
  337. $smsInfo['para'][] = [
  338. "username" => $uname,
  339. "date" => $mdate,
  340. "meetname" => $mname
  341. ];
  342. if (count($smsInfo['phoneNum']) > 0) {
  343. m('send_sms')->sendBatchSms($smsInfo['phoneNum'], $smsInfo['para'], 4);
  344. }
  345. }
  346. public function meetingMaXuSms($meetId) {
  347. if (empty($meetId)) {
  348. m("log")->addlog("短信发送", "会议Id为空");
  349. return;
  350. }
  351. if (empty($this->rs)) {
  352. m("log")->addlog("短信发送", "表单数据为空");
  353. return;
  354. }
  355. $uname = "马旭";
  356. $mdate = date('m月d日H点i分', strtotime($this->rs['start_time']));
  357. $mname = $this->strLength35($this->rs['title']);
  358. $mobile = "18695503090";
  359. $smsInfo['phoneNum'][] = $mobile;
  360. $smsInfo['para'][] = [
  361. "username" => $uname,
  362. "date" => $mdate,
  363. "meetname" => $mname
  364. ];
  365. if (count($smsInfo['phoneNum']) > 0) {
  366. m('send_sms')->sendBatchSms($smsInfo['phoneNum'], $smsInfo['para'], 4);
  367. }
  368. }
  369. // 固定会议,每日改变会议日期
  370. public function fixedMeetings($mid='') {
  371. $meets = $this->getall('fixed=1');
  372. for ($i = 0; $i < count($meets); $i++) {
  373. $meet = $meets[$i];
  374. $date = date('Y-m-d', strtotime('+1 day'));
  375. $id = $meet['id'];
  376. $st = $meet['start_time'];
  377. $et = $meet['end_time'];
  378. $st = $date.' '.substr($st, 11);
  379. $et = $date.' '.substr($et, 11);
  380. m('meeting')->update([
  381. 'start_time'=>$st,
  382. 'end_time'=>$et,
  383. 'meet_state' => 0,
  384. 'is_hand' => 0
  385. ], "id={$id}");
  386. }
  387. }
  388. function strLength35($str) {
  389. if (strlen($str) > 35) {
  390. $str = substr($str, 0, 35);
  391. $str = substr_replace($str, '…', 34, 1);
  392. }
  393. return $str;
  394. }
  395. }