openmeetAction.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <?php
  2. /**
  3. * 会议相关
  4. * 请求地址如:http://oa.test/api.php?m=openmeet&a=test&openkey=fee5efd3a93ca5c6a85b679cde60faa2
  5. */
  6. class openmeetClassAction extends openapiAction
  7. {
  8. public function testAction() {
  9. $str = $this->postdata;
  10. return json_encode($str);
  11. }
  12. // 绑定设备
  13. public function bindDeviceAction() {
  14. $rawArr = $this->getpostarr();
  15. if (!isset($rawArr['device_id'])) {
  16. return [
  17. "code"=>-1,
  18. "message"=>"参数错误!"
  19. ];
  20. }
  21. $rawData = m('meeting_room')->getone(" mac like '%{$rawArr['device_id']}%'", "id, room_name");
  22. $now = date('Y年m月d日('.$this->getWeek().') H:i:s');
  23. if ($rawData['id'] ?? 0 > 0) {
  24. return [
  25. "code"=>200,
  26. "message"=>"已绑定",
  27. "data"=>[
  28. "room_id"=>$rawData['id'],
  29. "meetingRoomName"=>$rawData['room_name'],
  30. "meetingTime"=>$now,
  31. "stateText"=>"空闲中"
  32. ]
  33. ];
  34. } else {
  35. return [
  36. "code"=>0,
  37. "message"=>"设备未绑定!"
  38. ];
  39. }
  40. }
  41. // 获取会议信息
  42. public function getMeetInfoAction() {
  43. $rawArr = $this->getpostarr();
  44. if (!isset($rawArr['room_id'])) {
  45. return [
  46. "code"=>-1,
  47. "message"=>"参数错误!"
  48. ];
  49. }
  50. $rawData = m('meeting_room')->getone(" id = '{$rawArr['room_id']}'");
  51. if (!isset($rawData['room_name'])) {
  52. return [
  53. "code"=>-1,
  54. "message"=>"未找到会议室!"
  55. ];
  56. }
  57. $meetData = m('meeting')->getone(" state = 1 and meeting_room = '{$rawData['room_name']}'");
  58. if (!isset($meetData['id'])) {
  59. return [
  60. "code"=>2,
  61. "message"=>"暂无会议!"
  62. ];
  63. }
  64. $topics = $this->db->getall("select `id`, `topic_title`, `topic_attendee`, `topic_state` from `[Q]topics` where mid = {$meetData['id']} order by sort");
  65. $now = date('Y年m月d日('.$this->getWeek($meetData['meeting_time']).') H:i:s');
  66. $date = date('Y年m月d日('.$this->getWeek($meetData['meeting_time']).') H:i:s');
  67. $datetime = "2021-09-30 15:45:30"; // 给定的日期时间字符串
  68. // 将日期时间字符串转换为UNIX时间戳
  69. $ts = strtotime($meetData['meeting_time']);
  70. // 根据需要格式化日期
  71. $meetStartDate = date("Y年m月d日", $ts);
  72. $meetDate=$meetStartDate." (".$this->getWeek($meetStartDate).") ".date("H:i", strtotime($meetData['meeting_time']))."~".date("H:i", strtotime($meetData['end_time']));
  73. $topicsList = [];
  74. for ($i = 0; $i < count($topics); $i++) {
  75. $info = $topics[$i];
  76. $topicsList[$i]['id'] = $info['id'];
  77. $topicsList[$i]['text'] = $info['topic_title'];
  78. $topicsList[$i]['tip'] = $this->topicState($info['topic_state']);
  79. $topicsList[$i]['state'] = $info['topic_state'];
  80. $topicsList[$i]['person'] = explode(',', $info['topic_attendee'] );
  81. }
  82. $res=[
  83. "code"=>200,
  84. "message"=>"请求成功!",
  85. "data"=>[
  86. "meetingId"=>$rawData['id'],
  87. "meetingRoomName"=>$rawData['room_name'],
  88. "meetingName"=>$meetData['title'],
  89. "meetingTime"=>$meetDate,
  90. "meetingPerson"=>explode(",", $meetData['attendees']),
  91. "meetingTopic"=>$topicsList ?? []
  92. ]
  93. ];
  94. return $res;
  95. }
  96. // 切换议题
  97. public function switchTopicsAction() {
  98. $rawArr = $this->getpostarr();
  99. if (!isset($rawArr['meet_id']) || !isset($rawArr['topic_id'])) {
  100. return [
  101. "code"=>-1,
  102. "message"=>"参数错误!"
  103. ];
  104. }
  105. // 获取议题信息
  106. $topics = $this->db->getall("select `id`, `topic_title`, `topic_attendee`, `topic_attendee_id`, `topic_state` from `[Q]topics` where mid = {$rawArr['meet_id']} order by sort");
  107. if (!isset($topics) || !isset($rawArr['meet_id'])) {
  108. return [
  109. "code"=>-1,
  110. "message"=>"会议不存在!"
  111. ];
  112. }
  113. $topic_id = $rawArr['topic_id'];
  114. for ($i = 0; $i < count($topics); $i++) {
  115. $info = $topics[$i];
  116. if ($topic_id == $info['id']) {
  117. $topics[$i]['topic_state'] = $topics[$i]['topic_state'] + 1;
  118. $topics[$i]['topic_state_info'] = $this->topicState($topics[$i]['topic_state']);
  119. if (isset($topics[$i - 1])) {
  120. $topics[$i-1]['topic_state'] = $topics[$i-1]['topic_state'] + 1;
  121. $topics[$i-1]['topic_state_info'] = $this->topicState($topics[$i-1]['topic_state']);
  122. }
  123. if (isset($topics[$i + 1])) {
  124. $topics[$i+1]['topic_state'] = $topics[$i+1]['topic_state'] + 1;
  125. $topics[$i+1]['topic_state_info'] = $this->topicState($topics[$i+1]['topic_state']);
  126. }
  127. // 发送短信给 topic_attendee_id
  128. } else {
  129. $topics[$i]['topic_state_info'] = $this->topicState($topics[$i]['topic_state']);
  130. }
  131. }
  132. return [
  133. "code"=>200,
  134. "message"=>"切换成功!",
  135. "data"=>$topics
  136. ];
  137. }
  138. protected function topicState($code): string
  139. {
  140. $info = '等待';
  141. switch ($code) {
  142. case 1:
  143. $info = '待进行';
  144. break;
  145. case 2:
  146. $info = '进行中';
  147. break;
  148. case 3:
  149. $info = '已进行';
  150. break;
  151. }
  152. return $info;
  153. }
  154. protected function getWeek($date=null) {
  155. if (!isset($date)) {
  156. $date = date("Y-m-d H:i:s");
  157. }
  158. // 将日期转换为时间戳
  159. $timestamp = strtotime($date);
  160. // 格式化输出星期几(返回值为英文)
  161. $weekday_en = date('l', $timestamp);
  162. // 如果需要显示中文星期几,则需要进行相关处理
  163. switch ($weekday_en) {
  164. case 'Monday':
  165. $weekday_cn = "星期一";
  166. break;
  167. case 'Tuesday':
  168. $weekday_cn = "星期二";
  169. break;
  170. case 'Wednesday':
  171. $weekday_cn = "星期三";
  172. break;
  173. case 'Thursday':
  174. $weekday_cn = "星期四";
  175. break;
  176. case 'Friday':
  177. $weekday_cn = "星期五";
  178. break;
  179. case 'Saturday':
  180. $weekday_cn = "星期六";
  181. break;
  182. default:
  183. $weekday_cn = "星期天";
  184. }
  185. return $weekday_cn;
  186. }
  187. }