meetingModel.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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'];
  96. $rs['state_info'] = $this->getApproval($rs['nowcheckname'] ?? '');
  97. return $rs;
  98. }
  99. // $ors当前单据操作信息,$crs提交过来的信息
  100. public function flowoptmenu($ors, $crs)
  101. {
  102. // 切换会议议题
  103. if ($ors['num'] == 'changeTopic') {
  104. $topics = $this->db->getall("select * from `[Q]meeting_topics` where mid = {$this->id} order by sort");
  105. for ($i = 0; $i < count($topics); $i++) {
  106. if(isset($topics[$i]['topic_state']) && $topics[$i]['topic_state'] == 2) {
  107. $id = $topics[$i]['id'];
  108. $data = ['topic_state'=>$topics[$i]['topic_state']+1];
  109. m('meeting_topics')->update($data, "id={$id}");
  110. if (isset($topics[$i+1]['topic_state'])) {
  111. $id = $topics[$i+1]['id'];
  112. $data = ['topic_state'=>2];
  113. m('meeting_topics')->update($data, "id={$id}");
  114. }
  115. if (isset($topics[$i+2]['topic_state'])) {
  116. $id = $topics[$i+2]['id'];
  117. $data = ['topic_state'=>1];
  118. m('meeting_topics')->update($data, "id={$id}");
  119. }
  120. break;
  121. }
  122. }
  123. if (isset($topics[count($topics) - 1]) && $topics[count($topics) - 1]['topic_state'] == 2) {
  124. m('meeting')->update(['is_hand'=>1,'meet_state'=>2], "id={$this->id}");
  125. }
  126. } else if ($ors['num'] == 'enableMeeting') {
  127. $time = time();
  128. $stime = strtotime($this->rs['start_time']);
  129. $etime = strtotime($this->rs['end_time']);
  130. if ($stime < $time){
  131. $data = [
  132. 'meet_state'=>1,
  133. 'is_hand'=>1
  134. ];
  135. } else if ($stime >= $time) {
  136. $data = [
  137. 'meet_state'=>0,
  138. 'is_hand'=>1
  139. ];
  140. }
  141. m('meeting')->update($data, "id={$this->id}");
  142. $topic = m('meeting_topics')->getone("mid={$this->id}", "id", 'sort desc');
  143. if (isset($topic['id'])) {
  144. m('meeting_topics')->update(['topic_state'=>'2'], 'id='.$topic['id']);
  145. }
  146. } else if ($ors['num'] == 'disenableMeeting') {
  147. // $data = [
  148. // 'meet_state'=>2,
  149. // 'is_hand'=>1
  150. // ];
  151. //
  152. // m('meeting_key')->update($data, "id={$this->id}");
  153. } else if ($ors['num'] == "noup") {
  154. // 动作名
  155. if ($ors['actname'] == "change_room") {
  156. $data = $this->rs;
  157. $roomName = $this->meeting_room[$data['room_id']]['room_name'];
  158. if (!empty($roomName)) {
  159. $this->update([
  160. "meeting_room"=>$roomName,
  161. ], "id={$this->id}");
  162. // 更换会议室 - 发送会议短信
  163. $this->meetingSms($this->id);
  164. }
  165. }
  166. }
  167. }
  168. //删除单据时调用
  169. public function flowdeletebill($sm) {
  170. // m('meet_sys')->deleteMeetingRoom($this->rs);
  171. }
  172. //审核完成后调用
  173. protected function flowcheckafter($zt, $sm){
  174. // 发送会议短信
  175. // $this->meetingSms($this->id);
  176. }
  177. //流程全部完成后调用
  178. protected function flowcheckfinsh($sm){
  179. // 审批完成给负责人发短信
  180. $this->meetingSms($this->id);
  181. }
  182. public function getstatezt($zt)
  183. {
  184. if (isset($this->hyarrb[$zt])) {
  185. $html = '<font color="'.$this->hyarrb[$zt].'">'.$this->hyarra[$zt].'</font>';
  186. return $html;
  187. } else {
  188. return null;
  189. }
  190. }
  191. public function getApproval($names) {
  192. if (empty($names)) {
  193. $html = '<font style="background-color:#00c959; padding: 2px 8px; border-radius: 4px; color: #fff">已审核</font>';
  194. return $html;
  195. } else {
  196. $html = '<font style="background-color:#ff4974; padding: 2px 8px; border-radius: 4px; color: #fff">待审核</font><br /><font style="color: #ff4974">审核人:'.$names.'</font>';
  197. return $html;
  198. }
  199. }
  200. public function meetingSms($meetId) {
  201. if (empty($meetId)) {
  202. m("log")->addlog("短信发送", "会议Id为空");
  203. return;
  204. }
  205. // 获取当前会议信息
  206. $meeting = m("meeting")->getone("id={$this->id}");
  207. $meetTime = $meeting['start_time']; // 时间
  208. $meetName = $meeting['title']; // 主题
  209. $meetRoom = $meeting['meeting_room']; // 地点
  210. m("log")->addlog("会议室审批", "发送短信给".$meeting['attendees']);
  211. $userIds = []; // 用户id
  212. $users = []; // 用户信息
  213. $deptIds = []; // 部门id
  214. $depts = []; // 部门信息
  215. $nullMobileArr = ["user"=>[], "dept"=>[]]; // 没有手机号的用户、部门
  216. // 分解参会人员、部门id
  217. foreach (explode(',', $meeting['attendees_id']) as $val) {
  218. // u=用户 or d=部门
  219. if (substr($val, 0,1) == 'u') {
  220. $userIds[] = substr($val, 1);
  221. } else if (substr($val, 0,1) == 'd') {
  222. $deptIds[] = substr($val, 1);
  223. }
  224. }
  225. // 获取用户电话
  226. if (count($userIds) > 0) {
  227. // 获取所有用户信息
  228. $uInfo = m("admin")->getall("id in (".implode(',', $userIds).")");
  229. for ($i = 0; $i < count($userIds); $i++) {
  230. $mobile = $uInfo[$i]['mobile'];
  231. $name = $uInfo[$i]['name'];
  232. if (empty($mobile)) {
  233. $nullMobileArr['user'][] = $name;
  234. continue;
  235. }
  236. $users['phoneNum'][] = $mobile;
  237. $users['para'][] = [
  238. "name" => $name,
  239. "meetdate" => $meetTime,
  240. "meetname" => $meetName,
  241. "meetroom" => $meetRoom
  242. ];
  243. }
  244. if (count($users['phoneNum']) > 0) {
  245. m('send_sms')->sendBatchSms($users['phoneNum'], $users['para'], 1);
  246. }
  247. }
  248. if (count($deptIds) > 0) {
  249. $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).") ";
  250. $dInfo = $this->db->getall($deptSql);
  251. for ($i = 0; $i < count($dInfo); $i++) {
  252. $mobile = $dInfo[$i]['mobile'];
  253. $name = $dInfo[$i]['name'];
  254. if (empty($mobile)) {
  255. $nullMobileArr['dept'][] = $name;
  256. continue;
  257. }
  258. $depts['phoneNum'][] = $mobile;
  259. $depts['para'][] = [
  260. "name" => $name,
  261. "meetdate" => $meetTime,
  262. "meetname" => $meetName,
  263. "meetroom" => $meetRoom
  264. ];
  265. }
  266. if (count($depts['phoneNum']) > 0) {
  267. m('send_sms')->sendBatchSms($depts['phoneNum'], $depts['para'], 1);
  268. }
  269. }
  270. $nullMobileInfo = '';
  271. if (count($nullMobileArr['user']) > 0) {
  272. $nullMobileInfo .= "以下用户未设手机号:".implode(',', $nullMobileArr['user'])."。";
  273. }
  274. if (count($nullMobileArr['dept']) > 0) {
  275. $nullMobileInfo .= "以下部门未设手机号:".implode(',', $nullMobileArr['dept'])."。";
  276. }
  277. if (!empty($nullMobileInfo)) {
  278. m("log")->addlog("会议短信", $nullMobileInfo);
  279. };
  280. }
  281. }