meetingModel.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. }
  25. //录入页上的标题
  26. public function inputtitle() {
  27. return "会议室审批单";
  28. }
  29. //子表数据替换处理$lx=0编辑时,1展示时
  30. protected function flowsubdata($rows, $lx=0){
  31. for ($i = 0; $i < count($rows); $i++) {
  32. if (isset($rows[$i]['topic_state']) && !empty($rows[$i]['topic_state'])) {
  33. $index = $rows[$i]['topic_state'] ?? 1;
  34. $rows[$i]['topic_state'] = $this->ytarra[$index];
  35. } else {
  36. $id = isset($rows[$i]['id']);
  37. m('meeting_topics')->update(['topic_state'=>1], "id={$id}");
  38. }
  39. }
  40. return $rows;
  41. }
  42. // 初始化单据可替换其他属性,$lx,0默认,1详情展示,2列表显示,3打印页,4外部详情页
  43. public function flowrsreplace($rs, $lx=0)
  44. {
  45. // m('log')->addlog('会议单据', json_encode($rs, true));
  46. $this->id = $rs['id'];
  47. $zt = $rs['meet_state'];
  48. $is_hand = $rs['is_hand'] ?? 0;
  49. $room_id = $rs['room_id'];
  50. $nzt = $zt;
  51. $time = time();
  52. $stime = strtotime($rs['start_time']);
  53. $etime = strtotime($rs['end_time']);
  54. if($is_hand != 1){
  55. if($etime < $time){
  56. $nzt = 2;
  57. } else if ($stime > $time){
  58. $nzt = 0;
  59. } else {
  60. $nzt = 1;
  61. $topic = m('meeting_topics')->getone("mid={$this->id}",'id, topic_state', 'sort');
  62. if (isset($topic['id']) && $topic['topic_state']<2) {
  63. m('meeting')->firstMeetingTopicStart($this->id);
  64. }
  65. }
  66. }
  67. if ($stime <= $time && $nzt != 2) {
  68. $nzt = 1;
  69. }
  70. // 更新数据状态
  71. if($zt != $nzt){
  72. $this->update('meet_state='.$nzt.'', $rs['id']);
  73. $zt = $nzt;
  74. }
  75. // 将id转换为文字
  76. $rs['meet_state'] = $this->getstatezt($zt);
  77. if (!empty($room_id)) $rs['room_id'] = $this->meeting_room[$room_id]['room_name'];
  78. if (isset($rs['nowcheckname'])) $rs['state_info'] = $this->getApproval($rs['nowcheckname'] ?? '');
  79. return $rs;
  80. }
  81. // $ors当前单据操作信息,$crs提交过来的信息
  82. public function flowoptmenu($ors, $crs)
  83. {
  84. // 切换会议议题
  85. if ($ors['num'] == 'changeTopic') {
  86. $topics = $this->db->getall("select * from `[Q]meeting_topics` where mid = {$this->id} order by sort");
  87. for ($i = 0; $i < count($topics); $i++) {
  88. if(isset($topics[$i]['topic_state']) && $topics[$i]['topic_state'] == 2) {
  89. $id = $topics[$i]['id'];
  90. $data = ['topic_state'=>$topics[$i]['topic_state']+1];
  91. m('meeting_topics')->update($data, "id={$id}");
  92. if (isset($topics[$i+1]['topic_state'])) {
  93. $id = $topics[$i+1]['id'];
  94. $data = ['topic_state'=>2];
  95. m('meeting_topics')->update($data, "id={$id}");
  96. }
  97. if (isset($topics[$i+2]['topic_state'])) {
  98. $id = $topics[$i+2]['id'];
  99. $data = ['topic_state'=>1];
  100. m('meeting_topics')->update($data, "id={$id}");
  101. }
  102. break;
  103. }
  104. }
  105. if (isset($topics[count($topics) - 1]) && $topics[count($topics) - 1]['topic_state'] == 2) {
  106. m('meeting')->update(['is_hand'=>1,'meet_state'=>2], "id={$this->id}");
  107. }
  108. } else if ($ors['num'] == 'enableMeeting') {
  109. $time = time();
  110. $stime = strtotime($this->rs['start_time']);
  111. $etime = strtotime($this->rs['end_time']);
  112. if ($stime < $time){
  113. $data = [
  114. 'meet_state'=>1,
  115. 'is_hand'=>1
  116. ];
  117. } else if ($stime >= $time) {
  118. $data = [
  119. 'meet_state'=>0,
  120. 'is_hand'=>1
  121. ];
  122. }
  123. m('meeting')->update($data, "id={$this->id}");
  124. $topic = m('meeting_topics')->getone("mid={$this->id}", "id", 'sort desc');
  125. if (isset($topic['id'])) {
  126. m('meeting_topics')->update(['topic_state'=>'2'], 'id='.$topic['id']);
  127. }
  128. } else if ($ors['num'] == 'disenableMeeting') {
  129. // $data = [
  130. // 'meet_state'=>2,
  131. // 'is_hand'=>1
  132. // ];
  133. //
  134. // m('meeting_key')->update($data, "id={$this->id}");
  135. } else if ($ors['num'] == "noup") {
  136. // 动作名
  137. if ($ors['actname'] == "change_room") {
  138. $data = $this->rs;
  139. $roomName = $this->meeting_room[$data['room_id']]['room_name'];
  140. if (!empty($roomName)) {
  141. $this->update([
  142. "meeting_room"=>$roomName,
  143. ], "id={$this->id}");
  144. }
  145. }
  146. }
  147. }
  148. //删除单据时调用
  149. public function flowdeletebill($sm) {
  150. // m('meet_sys')->deleteMeetingRoom($this->rs);
  151. }
  152. //流程全部完成后调用
  153. // public function flowcheckfinsh($sm) {
  154. protected function flowcheckfinsh($sm){
  155. // 审批完成给负责人发短信
  156. $meeting = m("meeting")->getone("id={$this->id}");
  157. if (empty($meeting)) return;
  158. m("log")->addlog("会议室审批", "发送短信给".$meeting['attendees']."部门负责人");
  159. foreach (explode(',', $meeting['attendees_id']) as $val) {
  160. if (substr($val, 0,1) == 'u') {
  161. $users[] = substr($val, 1);
  162. } else if (substr($val, 0,1) == 'd') {
  163. $depts[] = substr($val, 1);
  164. }
  165. }
  166. $users = m("admin")->getall("id in (".implode(',', $users).")");
  167. $mobile = [];
  168. foreach ($users as $val) {
  169. $mobile[] = $val['mobile'];
  170. }
  171. if (!empty($depts)) {
  172. $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(',', $depts).") ";
  173. m("log")->addlog("会议室审批", $deptSql);
  174. $depts = $this->db->getall($deptSql);
  175. $depts_e = [];
  176. // 部门负责人手机号
  177. foreach ($depts as $val) {
  178. if (empty($val['mobile'])) {
  179. $depts_e[] = $val['name'];
  180. } else {
  181. $mobile[] = $val['mobile'];
  182. }
  183. }
  184. }
  185. $infoText = "短信包括:".implode('、', $mobile);
  186. if (!empty($depts_e)) {
  187. $infoText .= ",其中".implode('、', $mobile)."未设负责人,无法通知";
  188. }
  189. m("log")->addlog("会议室审批", $infoText);
  190. }
  191. public function getstatezt($zt)
  192. {
  193. if (isset($this->hyarrb[$zt])) {
  194. $html = '<font color="'.$this->hyarrb[$zt].'">'.$this->hyarra[$zt].'</font>';
  195. return $html;
  196. } else {
  197. return null;
  198. }
  199. }
  200. public function getApproval($names) {
  201. if (empty($names)) {
  202. $html = '<font style="background-color:#00c959; padding: 2px 8px; border-radius: 4px; color: #fff">已审核</font>';
  203. return $html;
  204. } else {
  205. $html = '<font style="background-color:#ff4974; padding: 2px 8px; border-radius: 4px; color: #fff">待审核</font><br /><font style="color: #ff4974">审核人:'.$names.'</font>';
  206. return $html;
  207. }
  208. }
  209. }