123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520 |
- <?php
- /**
- * Created by PhpStorm.
- * User: huangdong
- * Date: 2018/8/9
- * Time: 下午5:04
- */
- namespace room;
- require_once(BASE_ROOT_PATH . '/helper/room/factory.php');
- require_once(BASE_ROOT_PATH . '/helper/url_helper.php');
- require_once(BASE_ROOT_PATH . '/helper/util_helper.php');
- use Exception;
- use url_helper;
- use author_url;
- use util;
- class tpl_group_home
- {
- private $mod_room = null;
- private $room_info = null;
- private $cur_user = 0;
- private $room_id = 0;
- private $participants = [];
- public function __construct($user, $room_id)
- {
- if ($room_id <= 0) {
- throw new Exception("聊天参数有误");
- }
- $this->mod_room = Model('room');
- $this->room_id = $room_id;
- $this->cur_user = intval($user);
- $room = $this->mod_room->getRoom($room_id);
- if(empty($room)) throw new Exception("房间不存在");
- $this->room_info = new room_info($room);
- if(empty($this->room_info)) throw new Exception("聊天参数有误");
- $this->participants = factory::participants($this->room_id);
- }
- public function show_cover()
- {
- $html = "";
- $url = RESOURCE_SITE_URL. "/mobile/talk/images/cover.png";
- $html.="<div class=\"cover\">
- <img src=\" {$url} \" alt=\"cover\">
- </div>";
- echo $html;
- }
- public function show_group_header()
- {
- if($this->room_info->has_name()){
- $name = $this->room_info->name();
- }else{
- $name = "未命名";
- }
- $avartar = $this->room_info->avatar();
- $desc = $this->room_info->room_desc();
- $html ="<div class=\"group_avatar\">
- <img src=\"{$avartar}\" class='g_avatar' alt=\"group_avatar\">
- </div>
- <div class=\"group_name\">
- <h3>
- {$name}";
- if($this->room_info->level() > 0) {
- $html.= "<span class='certification_logo'></span>";
- };
- $html.= "</h3>";
- $html.= "<p>{$desc}</p>
- </div>";
- echo $html;
- }
- public function show_qrcode_btn()
- {
- if(isset($this->participants[$this->cur_user])){
- echo "<div class='qrcode_btn'></div>";
- }
- }
- public function show_group_notice()
- {
- $html = "";
- $notice = $this->room_info->notice();
- if(empty($notice))
- {
- $html.= "<div class=\"group_notice_board\" style=\"display: none;\">
- <p class=\"text_overflow\"></p>
- </div>";
- }
- else
- {
- $html.= "<div class=\"group_notice_board\">
- <p class=\"text_overflow\">【公告】{$notice}</p>
- </div>";
- }
- echo $html;
- }
- public function show_group_activity()
- {
- $html = "";
- if(isset($this->participants[$this->cur_user])){
- $html.="<div class=\"weui-flex__item group_bonus\">
- <a href=\"/mobile/index.php?act=member_talk&op=share_bonus&room_id={$this->room_id}\">
- <img src=\"".RESOURCE_SITE_URL."/mobile/talk/images/group_bonus.png\" alt=\"\">
- </a>
- </div>
- <div class=\"weui-flex__item group_goods\">
- <a href=\"/mobile/index.php?act=member_talk&op=room_goods&talk_id={$this->room_id}\">
- <img src=\"".RESOURCE_SITE_URL."/mobile/talk/images/group_goods.png\" alt=\"\">
- </a>
- </div>
- <div class=\"weui-flex__item group_sport\">
- <a href=\"/mobile/index.php?act=member_talk&op=steps_home&talk_id={$this->room_id}\">
- <img src=\"".RESOURCE_SITE_URL."/mobile/talk/images/group_sport.png\" alt=\"\">
- </a>
- </div>";
- }
- echo $html;
- }
- private function isManager($user)
- {
- return intval($user) === $this->room_info->owner();
- }
- public function show_members()
- {
- $html = '';
- if (!empty($this->participants) && isset($this->participants[$this->cur_user])) {
- $i = 1;
- $cnt = count($this->participants);
- foreach ($this->participants as $uids => $member) {
- if ($i < $cnt) {
- $div_head = "<div class=\"weui-flex__item member-detail\" data-member-id={$member['userid']}>";
- } else {
- $div_head = "<div class=\"weui-flex__item member-detail\" data-member-id={$member['userid']} data-last='true'> ";
- }
- if($this->isManager($uids))
- {
- $head = "<img src=\"{$member['avatar']}\" alt=\"\">
- <p>{$member['nickname']}</p>
- <span class=\"admin\">管理员</span>
- </div>";
- $html = $div_head . $head . $html;
- }
- else
- {
- $html .= $div_head;
- $html .= "
- <img src=\"{$member['avatar']}\" alt=\"\">
- <p>{$member['nickname']}</p>
- </div>";
- }
- $i++;
- }
- }
- if (isset($this->participants[$this->cur_user])) {
- $html .= "<div class=\"weui-flex__item\">
- <img src=\"" . RESOURCE_SITE_URL . "/mobile/talk/images/add_member.png\" id=\"add_member\" alt=\"\">
- </div>";
- }
- if ($this->isManager($this->cur_user)) {
- $html .= "<div class=\"weui-flex__item\">
- <img src=\"" . RESOURCE_SITE_URL . "/mobile/talk/images/del_member.png\" id=\"del_member\" alt=\"\">
- </div>";
- }
- echo $html;
- }
- public function show_group_body()
- {
- $html = "";
- if (!empty($this->room_info) && isset($this->participants[$this->cur_user])) {
- $avartar = $this->room_info->avatar();
- $name = $this->room_info->has_name() ? $this->room_info->name() : "未命名";
- $notice = empty($this->room_info->notice()) ? "未设置" : "已设置";
- $desc = empty($this->room_info->room_desc()) ? "未设置" : "已设置";
- $cnt = $this->mod_room->applyCnts(['room_id'=>$this->room_id,"step"=>0]);
- $apply = $cnt > 0 ? "待处理" . $cnt : "暂无申请";
- $click = false;
- $level = "已认证";
- if($this->room_info->level() == 0) {
- $certs = $this->mod_room->findCert(["room_id"=>$this->room_id]);
- if(!empty($certs)) {
- if($certs['cstatus'] == 0) {
- $level = "待审核";
- }elseif($certs['cstatus'] == 2 || $certs['cstatus'] == 3){
- $click = true;
- $level = "待修改";
- }
- }else{
- $click = true;
- $level = "未认证";
- }
- }
- $html.= "<div class=\"weui-cells\">";
- $html.= $this->room_name_btn($click,$name);
- $html.= $this->room_avatar_btn($avartar);
- $html.= $this->room_cert_btn($click,$level);
- $html.= "</div>";
- $html.= $this->room_manager_btn($desc,$notice,$apply,$cnt);
- }
- echo $html;
- }
- private function room_name_btn($click,$name)
- {
- if($click){
- $html = "<div class=\"weui-cell weui-cell_access\" id='edit_group_name'>
- <div class=\"weui-cell__bd\">
- <p>群名称</p>
- </div>
- <div class=\"weui-cell__ft\">{$name}</div>
- </div>";
- } else {
- $html = "<div class=\"weui-cell\">
- <div class=\"weui-cell__bd\">
- <p>群名称</p>
- </div>
- <div class=\"weui-cell__ft\">{$name}</div>
- </div>";
- }
- return $html;
- }
- private function room_avatar_btn($avartar){
- $html = "<div class=\"weui-cell weui-cell_access\" id=\"edit_group_avatar\" onclick='uploader.click()'>
- <div class=\"weui-cell__bd\">
- <p>群头像</p>
- </div>
- <div class=\"weui-cell__ft\">
- <img src='{$avartar}' class='g_avatar' alt=''>
- <input type='file' name='file' enctype='multipart/form-data' id='uploader' style=\"display: none;\">
- </div>
- </div>";
- return $html;
- }
- private function room_cert_btn($click,$level)
- { if(!$this->isManager($this->cur_user)){
- return "";
- }
- if($click){
- $html = "<div class=\"weui-cell weui-cell_access\" id=\"group_AC\">
- <div class=\"weui-cell__bd\">
- <p>群认证</p>
- </div>
- <div class=\"weui-cell__ft\">{$level}</div>
- </div>";
- }else{
- $html = "<div class=\"weui-cell\">
- <div class=\"weui-cell__bd\">
- <p>群认证</p>
- </div>
- <div class=\"weui-cell__ft\">{$level}</div>
- </div>";
- }
- return $html;
- }
- private function room_manager_btn($desc,$notice,$apply,$cnt){
- if ($this->isManager($this->cur_user))
- {
- $html = "<div class=\"weui-cells\">";
- $html.= "<div class=\"weui-cell weui-cell_access\" href=\"javascript:;\" id=\"edit_room_notice\">
- <div class=\"weui-cell__bd\">
- <p>群公告</p>
- </div>
- <div class=\"weui-cell__ft\" id=\"room-notice-btn\">{$notice}</div>
- </div>
-
- <div class=\"weui-cell weui-cell_access\" href=\"javascript:;\" id=\"edit_room_desc\">
- <div class=\"weui-cell__bd\">
- <p>群介绍</p>
- </div>
- <div class=\"weui-cell__ft\" id=\"room-desc-btn\">{$desc}</div>
- </div>
- ";
- if ($cnt > 0)
- {
- $html.="
- <div class=\"weui-cell weui-cell_access\">
- <div class=\"weui-cell__bd\">
- <p>入群申请</p>
- </div>
- <div class=\"weui-cell__ft\" id=\"room-apply-btn\" style=\"color: #FF4E4E\">{$apply}</div>
- </div>";
- }
- else
- {
- $html.="
- <div class=\"weui-cell weui-cell_access\">
- <div class=\"weui-cell__bd\">
- <p>入群申请</p>
- </div>
- <div class=\"weui-cell__ft\">{$apply}</div>
- </div>";
- }
- $html .="</div>";
- }else{
- $html = "";
- }
- return $html;
- }
- public function show_personal_settings()
- {
- $html = "";
- if (!empty($this->participants) && isset($this->participants[$this->cur_user])) {
- $html .= "
- <div class=\"weui-cells\">
- <div class=\"weui-cell weui-cell_access\" href=\"javascript:;\" id='edit_nickname'>
- <div class=\"weui-cell__bd\">
- <p>我在本群的昵称</p>
- </div>
- <div class=\"weui-cell__ft group-nickname\">{$this->participants[$this->cur_user]['nickname']}</div>
- </div>
- </div>";
- }
- if ($this->isManager($this->cur_user)) {
- $html .= "
- <div class=\"weui-cells\">
- <div class=\"weui-cell weui-cell_access\" href=\"javascript:;\" id='change_owner' >
- <div class=\"weui-cell__bd\">
- <p>转让管理员</p>
- </div>
- </div>
- </div>";
- }
- echo $html;
- }
- public function show_group_footer()
- {
- $html = "";
- if(isset($this->participants[$this->cur_user]))
- {
- $html .="<div class=\"weui-cells\">";
- if ($this->isManager($this->cur_user)) {
- $pwd = $this->room_info->passwd();
- if($pwd)
- {
- $html .= "<div class=\"weui-cell weui-cell_switch\" href=\"javascript:;\">
- <div class=\"weui-cell__bd\">
- <p>群密码</p>
- </div>
- <div class=\"weui-cell__ft\">
- <label for=\"group_pwd\" class=\"weui-switch-cp\">
- <input id=\"group_pwd\" class=\"weui-switch-cp__input\" type=\"checkbox\" checked>
- <div class=\"weui-switch-cp__box\"></div>
- </label>
- </div>
- </div>";
- }
- else
- {
- $html .= "<div class=\"weui-cell weui-cell_switch\" href=\"javascript:;\">
- <div class=\"weui-cell__bd\">
- <p>群密码</p>
- </div>
- <div class=\"weui-cell__ft\">
- <label for=\"group_pwd\" class=\"weui-switch-cp\">
- <input id=\"group_pwd\" class=\"weui-switch-cp__input\" type=\"checkbox\">
- <div class=\"weui-switch-cp__box\"></div>
- </label>
- </div>
- </div>";
- }
- }
- $html .="<div class=\"weui-cell weui-cell_switch\" href=\"javascript:;\">
- <div class=\"weui-cell__bd\">
- <p>置顶聊天</p>
- </div>
- <div class=\"weui-cell__ft\">
- <label for=\"talk_top\" class=\"weui-switch-cp\">
- <input id=\"talk_top\" class=\"weui-switch-cp__input\" type=\"checkbox\">
- <div class=\"weui-switch-cp__box\"></div>
- </label>
- </div>
- </div>
- <div class=\"weui-cell weui-cell_switch\" href=\"javascript:;\">
- <div class=\"weui-cell__bd\">
- <p>消息免打扰</p>
- </div>
- <div class=\"weui-cell__ft\">
- <label for=\"no_disturb\" class=\"weui-switch-cp\">
- <input id=\"no_disturb\" class=\"weui-switch-cp__input\" type=\"checkbox\">
- <div class=\"weui-switch-cp__box\"></div>
- </label>
- </div>
- </div>
- </div>";
- }
- if(isset($this->participants[$this->cur_user]))
- {
- $html.="<div class=\"weui-cells\">
- <a class=\"weui-cell weui-cell_access\" href=\"javascript:;\" id=\"hide_msg\">
- <div class=\"weui-cell__bd\">
- <p>清空聊天记录</p>
- </div>
- </a>
- </div>";
- }
- echo $html;
- }
- public function show_footer_btn()
- {
- $html = "";
- if (isset($this->participants[$this->cur_user]))
- {
- if($this->isManager($this->cur_user))
- {
- //todo 解散群按钮
- }
- else
- {
- $html .= "
- <div class=\"quit\" id=\"quit_group\">
- <a href=\"javascript:;\" class=\"weui-btn weui-btn_primary\">删除并退出</a>
- </div>";
- }
- }
- else
- {
- $pwd = $this->room_info->passwd();
- if($pwd){
- $html .= "
- <div class=\"join_item_btn\">
- <div class=\"quit\" id=\"add_group_pwd\">
- <a href=\"javascript:;\" class=\"weui-btn weui-btn_primary\">密码入群</a>
- </div>
- <div class=\"quit\" id=\"add_group_apply\">
- <a href=\"javascript:;\" class=\"weui-btn weui-btn_primary\">申请加群</a>
- </div>
- </div>";
- }
- else
- {
- $html .= "
- <div class=\"join_item_btn\">
- <div class=\"quit\" id=\"add_group\">
- <a href=\"javascript:;\" class=\"weui-btn weui-btn_primary\">立即入群</a>
- </div>
- </div>";
- }
- }
- echo $html;
- }
- public function show_qrcode()
- {
- $name = $this->room_info->name();
- if(strlen($name) > 18) $name =mb_substr($name,0,6,'utf8')."...";
- $avatar = $this->room_info->avatar();
- $desc = $this->room_info->room_desc();
- // $url = url_helper::room_invite_url($this->room_id,$this->cur_user);
- // $save_path = BASE_UPLOAD_PATH."/room/qrcodes/{$this->room_id}_{$this->cur_user}.png";
- // $qrcode_path = BASE_SITE_URL . "/data/upload/room/qrcodes/{$this->room_id}_{$this->cur_user}.png?v=" . time();
- $url = author_url::room_detail_url('room',$this->room_id);
- $save_path = BASE_UPLOAD_PATH."/room/qrcodes/{$this->room_id}.png";
- $qrcode_path = BASE_SITE_URL . "/data/upload/room/qrcodes/{$this->room_id}.png?v=" . time();
- if(!file_exists($save_path)) {
- util::qrcode_path($url, $save_path);
- }
- $html = "<div class=\"qrcode\">
- <div class=\"qrcode_info\">
- <img src=\"$avatar\" class=\"qrcode_avatar_img\" alt=\"\">
- <div class=\"group_name\">
- <h3>$name</h3>
- <p>$desc</p>
- </div>
- </div>
- <div class=\"group_qrcode\">
- <img src=\"$qrcode_path\" alt=\"\">
- </div>
- <p class=\"prompt\">
- 扫一扫上面的二维码图案。加入群聊
- </p>
- <span class=\"close_btn\"></span>
- </div>
- </div>";
- echo $html;
- }
- }
|