meetingModel.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. return $rs;
  79. }
  80. // $ors当前单据操作信息,$crs提交过来的信息
  81. public function flowoptmenu($ors, $crs)
  82. {
  83. // 切换会议议题
  84. if ($ors['num'] == 'changeTopic') {
  85. $topics = $this->db->getall("select * from `[Q]meeting_topics` where mid = {$this->id} order by sort");
  86. for ($i = 0; $i < count($topics); $i++) {
  87. if(isset($topics[$i]['topic_state']) && $topics[$i]['topic_state'] == 2) {
  88. $id = $topics[$i]['id'];
  89. $data = ['topic_state'=>$topics[$i]['topic_state']+1];
  90. m('meeting_topics')->update($data, "id={$id}");
  91. if (isset($topics[$i+1]['topic_state'])) {
  92. $id = $topics[$i+1]['id'];
  93. $data = ['topic_state'=>2];
  94. m('meeting_topics')->update($data, "id={$id}");
  95. }
  96. if (isset($topics[$i+2]['topic_state'])) {
  97. $id = $topics[$i+2]['id'];
  98. $data = ['topic_state'=>1];
  99. m('meeting_topics')->update($data, "id={$id}");
  100. }
  101. break;
  102. }
  103. }
  104. if (isset($topics[count($topics) - 1]) && $topics[count($topics) - 1]['topic_state'] == 2) {
  105. m('meeting')->update(['is_hand'=>1,'meet_state'=>2], "id={$this->id}");
  106. }
  107. } else if ($ors['num'] == 'enableMeeting') {
  108. $time = time();
  109. $stime = strtotime($this->rs['start_time']);
  110. $etime = strtotime($this->rs['end_time']);
  111. if ($stime < $time){
  112. $data = [
  113. 'meet_state'=>1,
  114. 'is_hand'=>1
  115. ];
  116. } else if ($stime >= $time) {
  117. $data = [
  118. 'meet_state'=>0,
  119. 'is_hand'=>1
  120. ];
  121. }
  122. m('meeting')->update($data, "id={$this->id}");
  123. $topic = m('meeting_topics')->getone("mid={$this->id}", "id", 'sort desc');
  124. if (isset($topic['id'])) {
  125. m('meeting_topics')->update(['topic_state'=>'2'], 'id='.$topic['id']);
  126. }
  127. } else if ($ors['num'] == 'disenableMeeting') {
  128. // $data = [
  129. // 'meet_state'=>2,
  130. // 'is_hand'=>1
  131. // ];
  132. //
  133. // m('meeting_key')->update($data, "id={$this->id}");
  134. } else if ($ors['num'] == "noup") {
  135. // 动作名
  136. if ($ors['actname'] == "change_room") {
  137. $data = $this->rs;
  138. $roomName = $this->meeting_room[$data['room_id']]['room_name'];
  139. if (!empty($roomName)) {
  140. $this->update([
  141. "meeting_room"=>$roomName,
  142. ], "id={$this->id}");
  143. }
  144. }
  145. }
  146. }
  147. //删除单据时调用
  148. public function flowdeletebill($sm) {
  149. // m('meet_sys')->deleteMeetingRoom($this->rs);
  150. }
  151. //流程全部完成后调用
  152. // public function flowcheckfinsh($sm) {
  153. protected function flowcheckfinsh($sm){
  154. // 审批完成给负责人发短信
  155. $meeting = m("meeting")->getone("id={$this->id}");
  156. if (empty($meeting)) return;
  157. m("log")->addlog("会议室审批", "发送短信给".$meeting['attendees']."部门负责人");
  158. foreach (explode(',', $meeting['attendees_id']) as $val) {
  159. if (substr($val, 0,1) == 'u') {
  160. $users[] = substr($val, 1);
  161. } else if (substr($val, 0,1) == 'd') {
  162. $depts[] = substr($val, 1);
  163. }
  164. }
  165. $users = m("admin")->getall("id in (".implode(',', $users).")");
  166. $mobile = [];
  167. foreach ($users as $val) {
  168. $mobile[] = $val['mobile'];
  169. }
  170. if (!empty($depts)) {
  171. $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).") ";
  172. m("log")->addlog("会议室审批", $deptSql);
  173. $depts = $this->db->getall($deptSql);
  174. $depts_e = [];
  175. // 部门负责人手机号
  176. foreach ($depts as $val) {
  177. if (empty($val['mobile'])) {
  178. $depts_e[] = $val['name'];
  179. } else {
  180. $mobile[] = $val['mobile'];
  181. }
  182. }
  183. }
  184. $infoText = "短信包括:".implode('、', $mobile);
  185. if (!empty($depts_e)) {
  186. $infoText .= ",其中".implode('、', $mobile)."未设负责人,无法通知";
  187. }
  188. m("log")->addlog("会议室审批", $infoText);
  189. }
  190. public function getstatezt($zt)
  191. {
  192. if (isset($this->hyarrb[$zt])) {
  193. $html = '<font color="'.$this->hyarrb[$zt].'">'.$this->hyarra[$zt].'</font>';
  194. return $html;
  195. } else {
  196. return null;
  197. }
  198. }
  199. }