meetingModel.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. )$msg = '该会议室的时间段已被申请过了,主题“'.$rs['title'].'”';
  65. return $msg;
  66. }
  67. if ($type == 1) {
  68. if(
  69. ($sdt<=$startdt && $edt>$startdt)
  70. || ($sdt<$enddt && $edt>=$enddt)
  71. || ($sdt>$startdt && $edt<$enddt)
  72. || ($sdt==$startdt && $edt==$enddt)
  73. )$msg = '该会议室的时间段已被申请过了,主题“'.$rs['title'].'”';
  74. return $msg;
  75. }
  76. }
  77. return $msg;
  78. }
  79. // ---------------所有类型会议数据--------------------
  80. // 获取今日有效会议
  81. public function getMeetingEffective($uid) {
  82. $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";
  83. return $this->db->getall($sql);
  84. }
  85. // ---------------flow相关--------------------
  86. // 第一个议题状态开始
  87. public function firstMeetingTopicStart($meeting_id) {
  88. $topic = m('meeting_topics')->getall("mid={$meeting_id}", "id", 'sort');
  89. if (isset($topic[0]['id'])) {
  90. m('meeting_topics')->update(['topic_state'=>'2'], 'id='.$topic[0]['id']);
  91. }
  92. if (isset($topic[1]['id'])) {
  93. m('meeting_topics')->update(['topic_state'=>'1'], 'id='.$topic[1]['id']);
  94. }
  95. }
  96. // 会议室状态样式
  97. public function getstatezt($zt)
  98. {
  99. if (isset($this->hyarrb[$zt])) {
  100. $html = '<font color="'.$this->hyarrb[$zt].'">'.$this->hyarra[$zt].'</font>';
  101. return $html;
  102. } else {
  103. return null;
  104. }
  105. }
  106. // 会议状态
  107. public function meetingState($stime, $etime, $type=1) {
  108. // type == 1 获取状态码, type==2获取状态名
  109. $code = [0, 1, 2];
  110. $info = m('meeting')->hyarra;
  111. if ($stime > date("Y-m-d H:i:s")) {
  112. // 开始时间比当前时间大——未开始
  113. return $type == 1 ? $code[0] : $info[0];
  114. } else if ($etime < date("Y-m-d H:i:s")) {
  115. // 当前时间 比 结束时间比——已结束
  116. return $type == 1 ? $code[2] : $info[2];
  117. } else {
  118. // 在时间段内——会议中
  119. return $type == 1 ? $code[1] : $info[1];
  120. }
  121. }
  122. // 根据会议时间-更换会议状态
  123. public function meetingStateChange($mid, $stime, $etime) {
  124. $state = $this->meetingState($stime, $etime, 1);
  125. $this->update(["meet_state"=>$state], "id=".$mid);
  126. }
  127. }