tpl_group_home.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: huangdong
  5. * Date: 2018/8/9
  6. * Time: 下午5:04
  7. */
  8. namespace room;
  9. require_once(BASE_ROOT_PATH . '/helper/room/factory.php');
  10. require_once(BASE_ROOT_PATH . '/helper/url_helper.php');
  11. require_once(BASE_ROOT_PATH . '/helper/util_helper.php');
  12. use Exception;
  13. use url_helper;
  14. use author_url;
  15. use util;
  16. class tpl_group_home
  17. {
  18. private $mod_room = null;
  19. private $room_info = null;
  20. private $cur_user = 0;
  21. private $room_id = 0;
  22. private $participants = [];
  23. public function __construct($user, $room_id)
  24. {
  25. if ($room_id <= 0) {
  26. throw new Exception("聊天参数有误");
  27. }
  28. $this->mod_room = Model('room');
  29. $this->room_id = $room_id;
  30. $this->cur_user = intval($user);
  31. $room = $this->mod_room->getRoom($room_id);
  32. if(empty($room)) throw new Exception("房间不存在");
  33. $this->room_info = new room_info($room);
  34. if(empty($this->room_info)) throw new Exception("聊天参数有误");
  35. $this->participants = factory::participants($this->room_id);
  36. }
  37. public function show_cover()
  38. {
  39. $html = "";
  40. $url = RESOURCE_SITE_URL. "/mobile/talk/images/cover.png";
  41. $html.="<div class=\"cover\">
  42. <img src=\" {$url} \" alt=\"cover\">
  43. </div>";
  44. echo $html;
  45. }
  46. public function show_group_header()
  47. {
  48. if($this->room_info->has_name()){
  49. $name = $this->room_info->name();
  50. }else{
  51. $name = "未命名";
  52. }
  53. $avartar = $this->room_info->avatar();
  54. $desc = $this->room_info->room_desc();
  55. $html ="<div class=\"group_avatar\">
  56. <img src=\"{$avartar}\" class='g_avatar' alt=\"group_avatar\">
  57. </div>
  58. <div class=\"group_name\">
  59. <h3>
  60. {$name}";
  61. if($this->room_info->level() > 0) {
  62. $html.= "<span class='certification_logo'></span>";
  63. };
  64. $html.= "</h3>";
  65. $html.= "<p>{$desc}</p>
  66. </div>";
  67. echo $html;
  68. }
  69. public function show_qrcode_btn()
  70. {
  71. if(isset($this->participants[$this->cur_user])){
  72. echo "<div class='qrcode_btn'></div>";
  73. }
  74. }
  75. public function show_group_notice()
  76. {
  77. $html = "";
  78. $notice = $this->room_info->notice();
  79. if(empty($notice))
  80. {
  81. $html.= "<div class=\"group_notice_board\" style=\"display: none;\">
  82. <p class=\"text_overflow\"></p>
  83. </div>";
  84. }
  85. else
  86. {
  87. $html.= "<div class=\"group_notice_board\">
  88. <p class=\"text_overflow\">【公告】{$notice}</p>
  89. </div>";
  90. }
  91. echo $html;
  92. }
  93. public function show_group_activity()
  94. {
  95. $html = "";
  96. if(isset($this->participants[$this->cur_user])){
  97. $html.="<div class=\"weui-flex__item group_bonus\">
  98. <a href=\"/mobile/index.php?act=member_talk&op=share_bonus&room_id={$this->room_id}\">
  99. <img src=\"".RESOURCE_SITE_URL."/mobile/talk/images/group_bonus.png\" alt=\"\">
  100. </a>
  101. </div>
  102. <div class=\"weui-flex__item group_goods\">
  103. <a href=\"/mobile/index.php?act=member_talk&op=room_goods&talk_id={$this->room_id}\">
  104. <img src=\"".RESOURCE_SITE_URL."/mobile/talk/images/group_goods.png\" alt=\"\">
  105. </a>
  106. </div>
  107. <div class=\"weui-flex__item group_sport\">
  108. <a href=\"/mobile/index.php?act=member_talk&op=steps_home&talk_id={$this->room_id}\">
  109. <img src=\"".RESOURCE_SITE_URL."/mobile/talk/images/group_sport.png\" alt=\"\">
  110. </a>
  111. </div>";
  112. }
  113. echo $html;
  114. }
  115. private function isManager($user)
  116. {
  117. return intval($user) === $this->room_info->owner();
  118. }
  119. public function show_members()
  120. {
  121. $html = '';
  122. if (!empty($this->participants) && isset($this->participants[$this->cur_user])) {
  123. $i = 1;
  124. $cnt = count($this->participants);
  125. foreach ($this->participants as $uids => $member) {
  126. if ($i < $cnt) {
  127. $div_head = "<div class=\"weui-flex__item member-detail\" data-member-id={$member['userid']}>";
  128. } else {
  129. $div_head = "<div class=\"weui-flex__item member-detail\" data-member-id={$member['userid']} data-last='true'> ";
  130. }
  131. if($this->isManager($uids))
  132. {
  133. $head = "<img src=\"{$member['avatar']}\" alt=\"\">
  134. <p>{$member['nickname']}</p>
  135. <span class=\"admin\">管理员</span>
  136. </div>";
  137. $html = $div_head . $head . $html;
  138. }
  139. else
  140. {
  141. $html .= $div_head;
  142. $html .= "
  143. <img src=\"{$member['avatar']}\" alt=\"\">
  144. <p>{$member['nickname']}</p>
  145. </div>";
  146. }
  147. $i++;
  148. }
  149. }
  150. if (isset($this->participants[$this->cur_user])) {
  151. $html .= "<div class=\"weui-flex__item\">
  152. <img src=\"" . RESOURCE_SITE_URL . "/mobile/talk/images/add_member.png\" id=\"add_member\" alt=\"\">
  153. </div>";
  154. }
  155. if ($this->isManager($this->cur_user)) {
  156. $html .= "<div class=\"weui-flex__item\">
  157. <img src=\"" . RESOURCE_SITE_URL . "/mobile/talk/images/del_member.png\" id=\"del_member\" alt=\"\">
  158. </div>";
  159. }
  160. echo $html;
  161. }
  162. public function show_group_body()
  163. {
  164. $html = "";
  165. if (!empty($this->room_info) && isset($this->participants[$this->cur_user])) {
  166. $avartar = $this->room_info->avatar();
  167. $name = $this->room_info->has_name() ? $this->room_info->name() : "未命名";
  168. $notice = empty($this->room_info->notice()) ? "未设置" : "已设置";
  169. $desc = empty($this->room_info->room_desc()) ? "未设置" : "已设置";
  170. $cnt = $this->mod_room->applyCnts(['room_id'=>$this->room_id,"step"=>0]);
  171. $apply = $cnt > 0 ? "待处理" . $cnt : "暂无申请";
  172. $click = false;
  173. $level = "已认证";
  174. if($this->room_info->level() == 0) {
  175. $certs = $this->mod_room->findCert(["room_id"=>$this->room_id]);
  176. if(!empty($certs)) {
  177. if($certs['cstatus'] == 0) {
  178. $level = "待审核";
  179. }elseif($certs['cstatus'] == 2 || $certs['cstatus'] == 3){
  180. $click = true;
  181. $level = "待修改";
  182. }
  183. }else{
  184. $click = true;
  185. $level = "未认证";
  186. }
  187. }
  188. $html.= "<div class=\"weui-cells\">";
  189. $html.= $this->room_name_btn($click,$name);
  190. $html.= $this->room_avatar_btn($avartar);
  191. $html.= $this->room_cert_btn($click,$level);
  192. $html.= "</div>";
  193. $html.= $this->room_manager_btn($desc,$notice,$apply,$cnt);
  194. }
  195. echo $html;
  196. }
  197. private function room_name_btn($click,$name)
  198. {
  199. if($click){
  200. $html = "<div class=\"weui-cell weui-cell_access\" id='edit_group_name'>
  201. <div class=\"weui-cell__bd\">
  202. <p>群名称</p>
  203. </div>
  204. <div class=\"weui-cell__ft\">{$name}</div>
  205. </div>";
  206. } else {
  207. $html = "<div class=\"weui-cell\">
  208. <div class=\"weui-cell__bd\">
  209. <p>群名称</p>
  210. </div>
  211. <div class=\"weui-cell__ft\">{$name}</div>
  212. </div>";
  213. }
  214. return $html;
  215. }
  216. private function room_avatar_btn($avartar){
  217. $html = "<div class=\"weui-cell weui-cell_access\" id=\"edit_group_avatar\" onclick='uploader.click()'>
  218. <div class=\"weui-cell__bd\">
  219. <p>群头像</p>
  220. </div>
  221. <div class=\"weui-cell__ft\">
  222. <img src='{$avartar}' class='g_avatar' alt=''>
  223. <input type='file' name='file' enctype='multipart/form-data' id='uploader' style=\"display: none;\">
  224. </div>
  225. </div>";
  226. return $html;
  227. }
  228. private function room_cert_btn($click,$level)
  229. { if(!$this->isManager($this->cur_user)){
  230. return "";
  231. }
  232. if($click){
  233. $html = "<div class=\"weui-cell weui-cell_access\" id=\"group_AC\">
  234. <div class=\"weui-cell__bd\">
  235. <p>群认证</p>
  236. </div>
  237. <div class=\"weui-cell__ft\">{$level}</div>
  238. </div>";
  239. }else{
  240. $html = "<div class=\"weui-cell\">
  241. <div class=\"weui-cell__bd\">
  242. <p>群认证</p>
  243. </div>
  244. <div class=\"weui-cell__ft\">{$level}</div>
  245. </div>";
  246. }
  247. return $html;
  248. }
  249. private function room_manager_btn($desc,$notice,$apply,$cnt){
  250. if ($this->isManager($this->cur_user))
  251. {
  252. $html = "<div class=\"weui-cells\">";
  253. $html.= "<div class=\"weui-cell weui-cell_access\" href=\"javascript:;\" id=\"edit_room_notice\">
  254. <div class=\"weui-cell__bd\">
  255. <p>群公告</p>
  256. </div>
  257. <div class=\"weui-cell__ft\" id=\"room-notice-btn\">{$notice}</div>
  258. </div>
  259. <div class=\"weui-cell weui-cell_access\" href=\"javascript:;\" id=\"edit_room_desc\">
  260. <div class=\"weui-cell__bd\">
  261. <p>群介绍</p>
  262. </div>
  263. <div class=\"weui-cell__ft\" id=\"room-desc-btn\">{$desc}</div>
  264. </div>
  265. ";
  266. if ($cnt > 0)
  267. {
  268. $html.="
  269. <div class=\"weui-cell weui-cell_access\">
  270. <div class=\"weui-cell__bd\">
  271. <p>入群申请</p>
  272. </div>
  273. <div class=\"weui-cell__ft\" id=\"room-apply-btn\" style=\"color: #FF4E4E\">{$apply}</div>
  274. </div>";
  275. }
  276. else
  277. {
  278. $html.="
  279. <div class=\"weui-cell weui-cell_access\">
  280. <div class=\"weui-cell__bd\">
  281. <p>入群申请</p>
  282. </div>
  283. <div class=\"weui-cell__ft\">{$apply}</div>
  284. </div>";
  285. }
  286. $html .="</div>";
  287. }else{
  288. $html = "";
  289. }
  290. return $html;
  291. }
  292. public function show_personal_settings()
  293. {
  294. $html = "";
  295. if (!empty($this->participants) && isset($this->participants[$this->cur_user])) {
  296. $html .= "
  297. <div class=\"weui-cells\">
  298. <div class=\"weui-cell weui-cell_access\" href=\"javascript:;\" id='edit_nickname'>
  299. <div class=\"weui-cell__bd\">
  300. <p>我在本群的昵称</p>
  301. </div>
  302. <div class=\"weui-cell__ft group-nickname\">{$this->participants[$this->cur_user]['nickname']}</div>
  303. </div>
  304. </div>";
  305. }
  306. if ($this->isManager($this->cur_user)) {
  307. $html .= "
  308. <div class=\"weui-cells\">
  309. <div class=\"weui-cell weui-cell_access\" href=\"javascript:;\" id='change_owner' >
  310. <div class=\"weui-cell__bd\">
  311. <p>转让管理员</p>
  312. </div>
  313. </div>
  314. </div>";
  315. }
  316. echo $html;
  317. }
  318. public function show_group_footer()
  319. {
  320. $html = "";
  321. if(isset($this->participants[$this->cur_user]))
  322. {
  323. $html .="<div class=\"weui-cells\">";
  324. if ($this->isManager($this->cur_user)) {
  325. $pwd = $this->room_info->passwd();
  326. if($pwd)
  327. {
  328. $html .= "<div class=\"weui-cell weui-cell_switch\" href=\"javascript:;\">
  329. <div class=\"weui-cell__bd\">
  330. <p>群密码</p>
  331. </div>
  332. <div class=\"weui-cell__ft\">
  333. <label for=\"group_pwd\" class=\"weui-switch-cp\">
  334. <input id=\"group_pwd\" class=\"weui-switch-cp__input\" type=\"checkbox\" checked>
  335. <div class=\"weui-switch-cp__box\"></div>
  336. </label>
  337. </div>
  338. </div>";
  339. }
  340. else
  341. {
  342. $html .= "<div class=\"weui-cell weui-cell_switch\" href=\"javascript:;\">
  343. <div class=\"weui-cell__bd\">
  344. <p>群密码</p>
  345. </div>
  346. <div class=\"weui-cell__ft\">
  347. <label for=\"group_pwd\" class=\"weui-switch-cp\">
  348. <input id=\"group_pwd\" class=\"weui-switch-cp__input\" type=\"checkbox\">
  349. <div class=\"weui-switch-cp__box\"></div>
  350. </label>
  351. </div>
  352. </div>";
  353. }
  354. }
  355. $html .="<div class=\"weui-cell weui-cell_switch\" href=\"javascript:;\">
  356. <div class=\"weui-cell__bd\">
  357. <p>置顶聊天</p>
  358. </div>
  359. <div class=\"weui-cell__ft\">
  360. <label for=\"talk_top\" class=\"weui-switch-cp\">
  361. <input id=\"talk_top\" class=\"weui-switch-cp__input\" type=\"checkbox\">
  362. <div class=\"weui-switch-cp__box\"></div>
  363. </label>
  364. </div>
  365. </div>
  366. <div class=\"weui-cell weui-cell_switch\" href=\"javascript:;\">
  367. <div class=\"weui-cell__bd\">
  368. <p>消息免打扰</p>
  369. </div>
  370. <div class=\"weui-cell__ft\">
  371. <label for=\"no_disturb\" class=\"weui-switch-cp\">
  372. <input id=\"no_disturb\" class=\"weui-switch-cp__input\" type=\"checkbox\">
  373. <div class=\"weui-switch-cp__box\"></div>
  374. </label>
  375. </div>
  376. </div>
  377. </div>";
  378. }
  379. if(isset($this->participants[$this->cur_user]))
  380. {
  381. $html.="<div class=\"weui-cells\">
  382. <a class=\"weui-cell weui-cell_access\" href=\"javascript:;\" id=\"hide_msg\">
  383. <div class=\"weui-cell__bd\">
  384. <p>清空聊天记录</p>
  385. </div>
  386. </a>
  387. </div>";
  388. }
  389. echo $html;
  390. }
  391. public function show_footer_btn()
  392. {
  393. $html = "";
  394. if (isset($this->participants[$this->cur_user]))
  395. {
  396. if($this->isManager($this->cur_user))
  397. {
  398. //todo 解散群按钮
  399. }
  400. else
  401. {
  402. $html .= "
  403. <div class=\"quit\" id=\"quit_group\">
  404. <a href=\"javascript:;\" class=\"weui-btn weui-btn_primary\">删除并退出</a>
  405. </div>";
  406. }
  407. }
  408. else
  409. {
  410. $pwd = $this->room_info->passwd();
  411. if($pwd){
  412. $html .= "
  413. <div class=\"join_item_btn\">
  414. <div class=\"quit\" id=\"add_group_pwd\">
  415. <a href=\"javascript:;\" class=\"weui-btn weui-btn_primary\">密码入群</a>
  416. </div>
  417. <div class=\"quit\" id=\"add_group_apply\">
  418. <a href=\"javascript:;\" class=\"weui-btn weui-btn_primary\">申请加群</a>
  419. </div>
  420. </div>";
  421. }
  422. else
  423. {
  424. $html .= "
  425. <div class=\"join_item_btn\">
  426. <div class=\"quit\" id=\"add_group\">
  427. <a href=\"javascript:;\" class=\"weui-btn weui-btn_primary\">立即入群</a>
  428. </div>
  429. </div>";
  430. }
  431. }
  432. echo $html;
  433. }
  434. public function show_qrcode()
  435. {
  436. $name = $this->room_info->name();
  437. if(strlen($name) > 18) $name =mb_substr($name,0,6,'utf8')."...";
  438. $avatar = $this->room_info->avatar();
  439. $desc = $this->room_info->room_desc();
  440. // $url = url_helper::room_invite_url($this->room_id,$this->cur_user);
  441. // $save_path = BASE_UPLOAD_PATH."/room/qrcodes/{$this->room_id}_{$this->cur_user}.png";
  442. // $qrcode_path = BASE_SITE_URL . "/data/upload/room/qrcodes/{$this->room_id}_{$this->cur_user}.png?v=" . time();
  443. $url = author_url::room_detail_url('room',$this->room_id);
  444. $save_path = BASE_UPLOAD_PATH."/room/qrcodes/{$this->room_id}.png";
  445. $qrcode_path = BASE_SITE_URL . "/data/upload/room/qrcodes/{$this->room_id}.png?v=" . time();
  446. if(!file_exists($save_path)) {
  447. util::qrcode_path($url, $save_path);
  448. }
  449. $html = "<div class=\"qrcode\">
  450. <div class=\"qrcode_info\">
  451. <img src=\"$avatar\" class=\"qrcode_avatar_img\" alt=\"\">
  452. <div class=\"group_name\">
  453. <h3>$name</h3>
  454. <p>$desc</p>
  455. </div>
  456. </div>
  457. <div class=\"group_qrcode\">
  458. <img src=\"$qrcode_path\" alt=\"\">
  459. </div>
  460. <p class=\"prompt\">
  461. 扫一扫上面的二维码图案。加入群聊
  462. </p>
  463. <span class=\"close_btn\"></span>
  464. </div>
  465. </div>";
  466. echo $html;
  467. }
  468. }