meetingModel.php 13 KB

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