meetingModel.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. class meetingClassModel extends Model
  3. {
  4. public $hyarra, $ytarra, $hyarrb;
  5. public function initModel()
  6. {
  7. $this->hyarra = array('等待中', '会议中', '结束', '取消');
  8. $this->ytarra = array('等待', '待进行', '进行中', '已结束');
  9. $this->hyarrb = array('green', 'blue', '#ff6600', '#888888');
  10. }
  11. // ---------------验证--------------------
  12. /**
  13. * 判断会议室是否重复申请了
  14. */
  15. public function isapplymsg($startdt, $enddt, $roomName, $id=0, $meetType=1)
  16. {
  17. $msg = '';
  18. if ($meetType == 1) {
  19. $sql = /** @lang text */
  20. 'SELECT * FROM (
  21. SELECT 1 as type, id, meeting_room, start_time, end_time, title, null as tzone
  22. FROM [Q]meeting
  23. WHERE id <> '.$id.'
  24. AND meet_state in (0, 1)
  25. AND start_time regexp date_format("'.$startdt.'", "%Y-%m-%d")
  26. UNION All
  27. select 2 as type, id, meeting_room, start_time, end_time, title, tzone
  28. FROM [Q]meeting_key
  29. WHERE meet_state in (0, 1)
  30. AND start_time regexp date_format("'.$startdt.'", "%Y-%m-%d")
  31. ) t order by type desc, start_time asc
  32. ';
  33. } else {
  34. $sql = /** @lang text */
  35. 'SELECT * FROM (
  36. SELECT 1 as type, id, meeting_room, start_time, end_time, title, null as tzone
  37. FROM [Q]meeting
  38. WHERE meet_state in (0, 1)
  39. AND start_time regexp date_format("'.$startdt.'", "%Y-%m-%d")
  40. UNION All
  41. SELECT 2 as type, id, meeting_room, start_time, end_time, title, tzone
  42. FROM [Q]meeting_key
  43. WHERE id <> '.$id.'
  44. AND start_time regexp date_format("'.$startdt.'", "%Y-%m-%d")
  45. AND meet_state in (0, 1)
  46. ) t order by type desc, start_time asc
  47. ';
  48. }
  49. $rows = $this->db->getall($sql);
  50. foreach($rows as $k=>$rs){
  51. if($rs['meeting_room'] != $roomName)continue;
  52. $sdt = $rs['start_time'];
  53. $edt = $rs['end_time'];
  54. $type = $rs['type'];
  55. if ($type == 2) {
  56. $tp = m("meeting_key")->tp[$rs['tzone']];
  57. $sdt = substr($startdt, 0, 10).' '.$tp['start_time'];
  58. $edt = substr($startdt, 0, 10).' '.$tp['end_time'];
  59. if(
  60. ($sdt<=$startdt && $edt>$startdt)
  61. || ($sdt<$enddt && $edt>=$enddt)
  62. || ($sdt>$startdt && $edt<$enddt)
  63. || ($sdt==$startdt && $edt==$enddt)
  64. ) {
  65. $msg = '该会议室的时间段已被申请过了,主题“'.$rs['title'].'”';
  66. return $msg;
  67. }
  68. }
  69. if ($type == 1) {
  70. if(
  71. ($sdt<=$startdt && $edt>$startdt)
  72. || ($sdt<$enddt && $edt>=$enddt)
  73. || ($sdt>$startdt && $edt<$enddt)
  74. || ($sdt==$startdt && $edt==$enddt)
  75. ) {
  76. $msg = '该会议室的时间段已被申请过了,主题“'.$rs['title'].'”';
  77. return $msg;
  78. }
  79. }
  80. }
  81. return $msg;
  82. }
  83. // ---------------所有类型会议数据--------------------
  84. // 获取今日有效会议
  85. public function getMeetingEffective($uid) {
  86. $sql = "select * from [Q]meeting where uid={$uid} and meet_state in (0, 1) and start_time>='".date("Y-m-d")."' order by start_time asc";
  87. return $this->db->getall($sql);
  88. }
  89. // ---------------flow相关--------------------
  90. // 第一个议题状态开始
  91. public function firstMeetingTopicStart($meeting_id) {
  92. $topic = m('meeting_topics')->getall("mid={$meeting_id}", "id", 'sort');
  93. if (isset($topic[0]['id'])) {
  94. m('meeting_topics')->update(['topic_state'=>'2'], 'id='.$topic[0]['id']);
  95. }
  96. if (isset($topic[1]['id'])) {
  97. m('meeting_topics')->update(['topic_state'=>'1'], 'id='.$topic[1]['id']);
  98. }
  99. }
  100. // 会议室状态样式
  101. public function getstatezt($zt)
  102. {
  103. if (isset($this->hyarrb[$zt])) {
  104. $html = '<font color="'.$this->hyarrb[$zt].'">'.$this->hyarra[$zt].'</font>';
  105. return $html;
  106. } else {
  107. return null;
  108. }
  109. }
  110. // 会议状态
  111. public function meetingState($stime, $etime, $type=1) {
  112. // type == 1 获取状态码, type==2获取状态名
  113. $code = [0, 1, 2];
  114. $info = m('meeting')->hyarra;
  115. if ($stime > date("Y-m-d H:i:s")) {
  116. // 开始时间比当前时间大——未开始
  117. return $type == 1 ? $code[0] : $info[0];
  118. } else if ($etime < date("Y-m-d H:i:s")) {
  119. // 当前时间 比 结束时间比——已结束
  120. return $type == 1 ? $code[2] : $info[2];
  121. } else {
  122. // 在时间段内——会议中
  123. return $type == 1 ? $code[1] : $info[1];
  124. }
  125. }
  126. // 根据会议时间-更换会议状态
  127. public function meetingStateChange($mid, $stime, $etime) {
  128. $state = $this->meetingState($stime, $etime, 1);
  129. $this->update(["meet_state"=>$state], "id=".$mid);
  130. }
  131. }