123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use app\common\service\UserService;
- use think\Db;
- use think\Exception;
- use Redis;
- use app\common\service\RoomService;
- use app\common\library\Easemob;
- /**
- * 公会控制器
- */
- class Guild extends Api
- {
- protected $noNeedLogin = ['getGuildList'];
- protected $noNeedRight = ['*'];
- protected $roomTypeArr;
- public function __construct()
- {
- parent::__construct();
- $this->roomTypeArr = [1=>"party",2=>"live"];
- }
- /**
- * 获取搜索公会列表
- */
- public function getGuildList() {
- $search = input("search","","string"); //搜索的字段 公会名称/公会ID
- $where = [];$whereOr = [];
- $where['g.status'] = 1;
- if (!empty($search)) {
- $whereOr['g.name'] = array('like', '%' . $search . '%');
- $whereOr['g.g_id'] = $search;
- }
- $res = Db::name('guild')->alias('g')->field("g.id,g.g_id,g.user_id,g.party_id,g.name,g.image,g.desc,g.member,
- area.province_name,area.name as city_name")
- ->join('shopro_area area','g.city_id = area.id','LEFT')
- ->where($where)
- ->where(function ($query) use($whereOr) {
- $query->whereOr($whereOr);
- })
- ->autopage()
- ->select();
- $res = list_domain_image($res,['image']);
- $this->success("获取成功!",$res);
- }
- /**
- * 获取公会信息-新
- */
- public function getGuildInfoNew() {
- $guild_id = input("guild_id"); //公会ID
- $user_id = $this->auth->id;
- //结果
- $res = [];
- //公会信息
- $guildInfo = \app\common\model\Guild::field("id,image,name,g_id,user_id,party_id,desc,notice,status")->where(["id"=>$guild_id])->find();
- if(!$guildInfo) $this->error("公会信息获取失败!");
- // 获取公会成员信息
- $guildMemberInfo = \app\common\model\GuildMember::alias("a")
- ->field("a.id,a.user_id,a.role,u.nickname,u.avatar,u.gender")
- ->join("user u","a.user_id = u.id")
- ->where(["a.guild_id"=>$guild_id])->limit(10)->order("a.role","desc")->select();
- // 获取公会成员总数
- $guildMemberCount = \app\common\model\GuildMember::where(["guild_id"=>$guild_id])->count("id");
- // 获取会长信息
- $guilderInfo = \app\common\model\User::field("avatar,nickname,u_id")->where(["id"=>$guildInfo->user_id])->find();
- // 获取房间信息
- $partyInfo = \app\common\model\Party::field("id,party_logo,party_type,is_online,party_name")->where(["id"=>$guildInfo->party_id])->find();
- $partyParams = ['party_id' => $guildInfo->party_id];
- $roomService = new RoomService();
- $partyOnlineRes = $roomService->getPartyUserList($partyParams);
- $onlineData = isset($partyOnlineRes['data']) ? $partyOnlineRes['data'] : [];
- if (!empty($partyInfo)) {
- $partyInfo['user_list'] = isset($onlineData['member_list']) ? $onlineData['member_list'] : [];
- $partyInfo['online_num'] = isset($onlineData['online_num']) ? $onlineData['online_num'] : 0;
- // 派对类型
- $mod = isset($partyInfo["party_type"])?intval($partyInfo["party_type"])%5:1;
- $partyInfo["party_type_color"] = $mod == 0?5:$mod;
- $partyInfo["type_name"] = '工会房';
- }
- //获取公会角色 角色:0=成员,1=副会长,2=会长,3=非会员
- $guildMember = \app\common\model\GuildMember::field('id,role')->where(['guild_id'=>$guild_id,'user_id'=>$this->auth->id])->find();
- if (!empty($guildMember)) {
- $guildRole = $guildMember['role'];
- }else{
- $guildRole = 3;
- }
- // 返回参数拼接
- $res["guildInfo"] = $guildInfo; // 公会基本信息
- $res["partyInfo"] = $partyInfo; // 派对基本信息
- $res["guildMemberInfo"] = $guildMemberInfo; // 成员列表
- $res["guildMemberCount"] = $guildMemberCount; // 成员总数
- $res["guilderInfo"] = $guilderInfo; // 会长
- $res['guild_role'] = $guildRole; //公会角色
- $this->success("获取成功!",$res);
- }
- /**
- * 更新公会基本信息
- */
- public function guildSaveInfo() {
- Db::startTrans();
- try {
- if($this->auth->is_auth != 2){
- $this->error('请先完成实名认证');
- }
- $guild_id = input("guild_id"); //公会id
- $guild_name = input("guild_name"); //公会名
- $guild_image = input("guild_image"); //logo
- $guild_desc = input("guild_desc"); //公会简介
- $guild_notice = input("guild_notice"); //公会公告
- $guild_info = input("guild_info"); //公会宣言
- $province_id = input("province_id"); //省id
- $city_id = input("city_id"); //市id
- if(!$guild_name || !$guild_image){
- throw new Exception("公会名和logo必填!");
- }
- $user_id = $this->auth->id;
- if (empty($guild_id)) {
- //检查
- $guildWhere['user_id'] = $user_id;
- $guildWhere['status'] = ['in',[0,1]];
- $guildData = model('Guild')->where($guildWhere)->find();
- if (!empty($guildData)) {
- if($guildData['status'] == 1){
- throw new Exception('您已创建过公会!');
- }else{
- throw new Exception('您创建的公会正在审核中!');
- }
- }
- //检查不能是其他家族的成员
- $checkmember = model('GuildMember')->where('user_id',$this->auth->id)->find();
- if (!empty($checkmember)) {
- $this->error('您已经加入了其他公会');
- }
- //检查删除这个人的所有加入申请
- $joinData = model('GuildJoinin')->where('user_id',$this->auth->id)->where('status',0)->find();
- if (!empty($joinData)) {
- $this->error('您已经申请加入了其他公会,需等待被拒或退出,才能创建公会');
- }
- //准备创建
- $guildInfo = new \app\common\model\Guild();
- $ids = \app\common\model\Guild::column("g_id");
- $guildInfo->user_id = $user_id;
- $guildInfo->g_id = getUinqueId(4, [$ids]);
- $guildInfo->status = 0;
- //去派对建个房间
- $party_info = $this->createParty($user_id,$guild_name,$guild_image,$guild_desc,$guild_notice,8,1,1);
- $guildInfo->party_id = $party_info['party_id'];
- $guildInfo->easemob_room_id = $party_info['easemob_room_id'];
- } else {
- // 获取公会信息
- $guildInfo = \app\common\model\Guild::where(["id"=>$guild_id])->find();
- // 验证更新条件
- if($user_id !== $guildInfo->user_id) throw new Exception("身份验证失败!您不是公会长,无权限更改!");
- //去派对建个房间
- if(!$guildInfo['party_id']){
- $party_info = $this->createParty($user_id,$guild_name,$guild_image,$guild_desc,$guild_notice,8,1,1,$guildInfo['status']);
- $guildInfo->party_id = $party_info['party_id'];
- $guildInfo->easemob_room_id = $party_info['easemob_room_id'];
- }
- }
- //传参信息
- $guild_name && $guildInfo->name = $guild_name;
- $guild_image && $guildInfo->image = $guild_image;
- $guild_desc && $guildInfo->desc = $guild_desc;
- $guild_notice && $guildInfo->notice = $guild_notice;
- $guild_info && $guildInfo->info = $guild_info;
- $province_id && $guildInfo->province_id = $province_id;
- $city_id && $guildInfo->city_id = $city_id;
- $res = $guildInfo->save();
- if($res !== false) {
- if (empty($guild_id)) {
- //新公会,会长也是成员之一
- $guildMemberData = [
- 'guild_id' => $guildInfo->id,
- 'user_id' => $user_id,
- 'role' => 2, //角色:0=成员,1=副会长,2=会长
- // 'sign_type' => 3,//签约类型:1=三个月,2=半年,3=一年
- // 'sign_time' => 0,
- // 'status' => 1, //状态:1=签约中,2=已解约
- 'createtime' => time(),
- ];
- $guildRes = model('GuildMember')->insertGetId($guildMemberData);
- if (!$guildRes) {
- throw new Exception('生成成员失败');
- }
- //更新用户资料
- $userWhere['id'] = $user_id;
- $user = model('User')->where($userWhere)->find();
- if (!empty($user) && $user['guild_id'] != $guildInfo->id) {
- $userRes = model('User')->where($userWhere)->update(['is_guild'=>3,'guild_id'=>$guildInfo->id]);
- if (!$userRes) {
- throw new Exception('用户绑定公会失败');
- }
- }
- }
- Db::commit();
- $this->success("操作成功!");
- } else {
- throw new Exception("网络错误,请稍后重试!");
- }
- } catch (Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- }
- /**
- * 创建/进入派对
- */
- private function createParty($user_id,$party_name,$party_logo,$guild_desc,$guild_notice,$seatnum = 8,$is_public = 1,$room_type = 1,$status = -1) {
- $partyModel = new \app\common\model\Party();
- // 判断派对是否存在
- // sql中不存在派对信息
- $party_type = 7; // 派对类型(情感互动,心动点单 等)
- $party_notice = $guild_desc; // 派对公告
- $party_notice_detail = $guild_notice; // 派对公告详情
- $party_ids = $partyModel->column("party_id");
- // 创建派对ID (临时ID四位,派对数不超过8999)
- $party_id = $this->auth->getUinqueId(4,$party_ids);
- if($party_id > 9999) {
- $this->error("房间超限,请联系客服");
- }
- //创建房间,初始化环信
- $easemob_room_id = $this->easemob_createroom($party_name,$party_logo,$seatnum,$is_public,$room_type);
- //写入派对
- $data = [];
- $data["user_id"] = $user_id;
- $data["room_type"] = $room_type;
- $data["party_id"] = $party_id;
- $data["party_hot"] = 0;
- $data["party_name"] = $party_name;
- $data["party_logo"] = $party_logo;
- $data["party_type"] = $party_type;
- $data["party_notice"] = $party_notice;
- $data["party_notice_detail"] = $party_notice_detail;
- $data["is_online"] = 1;
- $data["status"] = $status;//跟随公会状态
- $data["is_recommend"] = 0;
- $data["createtime"] = time();
- $data["easemob_room_id"] = $easemob_room_id;
- $id = $partyModel->insertGetId($data);
- if(!$id) {
- $this->error("工会房间创建失败,请稍后重试!");
- }
- $data["id"] = $id;
- $partyInfo = $partyModel->where(["id"=>$id])->find();
- $partyInfo["is_new"] = 1;
- $partyInfo["type_name"] = '工会房';
- //redis
- $redis = new Redis();
- $redisconfig = config("redis");
- $redis->connect($redisconfig["host"], $redisconfig["port"]);
- if ($redisconfig['redis_pwd']) {
- $redis->auth($redisconfig['redis_pwd']);
- }
- if($redisconfig['redis_selectdb'] > 0){
- $redis->select($redisconfig['redis_selectdb']);
- }
- // 加入缓存排序,rediskey:派对热度
- $redis->zAdd($this->roomTypeArr[$room_type]."Rank", $partyInfo['party_hot'], $partyInfo["id"]);
- // 加入缓存,rediskey:派对详情
- $redis->set($this->roomTypeArr[$room_type]."_".$partyInfo["id"],json_encode($partyInfo));
- //更新家族 party_id
- $rs = [
- 'party_id' => $id,
- 'easemob_room_id' => $easemob_room_id,
- ];
- return $rs;
- //声网三个token
- // $partyInfo['shengwang_token'] = $this->shengwang_token_private($easemob_room_id);
- }
- //创建房间,初始化环信
- private function easemob_createroom($party_name,$party_logo,$seatnum,$is_public,$room_type){
- //[环信]创建聊天室
- $easemob = new Easemob();
- $easemob_room_id = $easemob->room_createRoom($party_name,$party_name,$this->auth->id);
- if(empty($easemob_room_id)){
- $this->error('创建房间失败');
- }
- //[环信]初始化房间,初始化自定义属性
- $matedata = [
- 'seatnum'=> $seatnum,//麦位数量
- 'waitsing_list' => json_encode([]),//已点歌曲列表
- 'party_name' => $party_name,//房名字
- 'party_logo' => $party_logo,//logo
- 'is_public' => $is_public,//是否公开
- 'room_type' => $room_type,//房间类型
- 'online_user_num' => 0,//当前房间在线的人
- 'wealth_top3_userlist' => json_encode([]),//财富榜前3个人列表
- 'background' => '', //房间背景
- ];
- $rs = $easemob->room_setRoomCustomAttributeForced($easemob_room_id,$this->auth->id,$matedata);
- //[环信]初始化N个麦位
- $seatdata = [];
- for($i=0;$i<$seatnum;$i++){
- $seat = [
- 'charm' => 0, //红心,魅力值
- 'isMaster' => false, // 是否是房主
- 'headUrl' => '', // 头像
- 'userNo' => '', // 座位上用户no
- 'rtcUid' => '', // 座位上用户id,与rtc的userId一致
- 'name' => '', // 座位上用户昵称
- 'seatIndex' => -1, // 座位编号
- 'chorusSongCode' => '', // 是否合唱
- 'isAudioMuted' => 1, // 是否静音
- 'isVideoMuted' => 0, // 是否开启视频
- 'checked' => false, // 用于送礼物选择用户
- 'isUsed' => true, // 用于送礼物选择用户
- 'gender' => 1, //性别
- ];
- //创建完房间就进入,所以房主直接在麦位0
- if($i == 0){
- $seat['isMaster'] = true;
- $seat['headUrl'] = localpath_to_netpath($this->auth->avatar);
- $seat['userNo'] = $this->auth->id;
- $seat['rtcUid'] = $this->auth->id;
- $seat['name'] = $this->auth->nickname;
- $seat['seatIndex'] = $i;
- }
- $seatdata['seat'.$i] = json_encode($seat);
- }
- $rs = $easemob->room_setRoomCustomAttributeForced($easemob_room_id,$this->auth->id,$seatdata);
- return $easemob_room_id;
- }
- /**
- * 公会签约申请
- */
- public function guildJoinin() {
- $guild_id = input("guild_id"); //公会ID
- // 一个身份证号只能申请一次
- $user_id = $this->auth->id;
- // 实名认证
- if($this->auth->is_auth != 2){
- $this->error("请完成实名认证!");
- }
- $check = \app\common\model\Guild::where(["user_id"=>$this->auth->id])->find();
- if($check){
- if($check['status'] == 1){
- $this->error('您已经有自己的公会了');
- }elseif($check['status'] == 0){
- $this->error('您已经申请了自己的公会了');
- }
- }
- // 搜索签约申请中是否有此身份证号
- $idcardfind = \app\common\model\GuildJoinin::where(["user_id"=>$user_id,'guild_id'=>$guild_id,"status"=>0])->find();
- if($idcardfind) $this->error("当前账号正在审核,请耐心等待!");
- $memberfind = \app\common\model\GuildMember::where(["user_id"=>$user_id])->find();
- if($memberfind) $this->error("一个账号只能加入一个公会哟!");
- // 添加数据
- $data = [];
- $data["user_id"] = $user_id;
- $data["guild_id"] = $guild_id;
- $data["createtime"] = time();
- $res = \app\common\model\GuildJoinin::insert($data);
- if($res) {
- $this->success("申请发送成功!");
- } else {
- $this->error("网络错误,请稍后重试!");
- }
- }
- /**
- * 公会签约申请审核
- */
- public function guildJoininExamine() {
- $joinin_id = input("joinin_id"); // 申请加入的申请ID
- $is_pass = input("is_pass"); // 是否通过:1=通过,-1=拒绝
- if(!in_array($is_pass,[1,-1]) || !$joinin_id) $this->error("参数错误!");
- $user_id = $this->auth->id;
- // 获取申请信息
- $joininInfo = \app\common\model\GuildJoinin::where(["id"=>$joinin_id])->find();
- if(empty($joininInfo)){
- $this->error('未找到申请信息');
- }
- // 获取公会信息
- $guildInfo = \app\common\model\Guild::where(["id"=>$joininInfo->guild_id])->find();
- // 验证更新条件
- if($user_id !== $guildInfo->user_id) $this->error("身份验证失败!您不是公会长,无权限更改!");
- //判断重复
- $memberfind = \app\common\model\GuildMember::where(["user_id"=>$joininInfo['user_id']])->find();
- if($memberfind) $this->error("该用户已有公会!");//包括成员,副会,会长角色
- //清理其他公会未审核的数据
- if ($is_pass == 1) {
- $joinWhere['user_id'] = $joininInfo['user_id'];
- $joinWhere['guild_id'] = ['neq',$joininInfo['guild_id']];
- $joinWhere['status'] = 0;
- $joinData = model('GuildJoinin')->where($joinWhere)->delete();
- }
- // 计算签约时间段
- Db::startTrans();
- try{
- // 更新申请状态
- $joininInfo->status = $is_pass;
- $joininInfo->updatetime = time();
- $res2 = $joininInfo->save();
- if($is_pass == 1) {
- // 同意后 加入公会成员
- $data = [];
- $data["guild_id"] = $guildInfo->id;
- $data["user_id"] = $joininInfo->user_id;
- $data["role"] = 0;
- $data["createtime"] = time();
- $res3 = \app\common\model\GuildMember::insert($data);
- $res4 = \app\common\model\Guild::where(["id"=>$guildInfo->id])->setInc("member");
- if($res2 && $res3 && $res4) {
- // +message
- \app\common\model\Message::addMessage($joininInfo->user_id,"公会审核通知","恭喜,您的加入公会审核通过啦!");
- Db::commit();
- $this->success("已审核通过!");
- }
- } else {
- if($res2) {
- // +message
- \app\common\model\Message::addMessage($joininInfo->user_id,"公会审核通知","您的公会加入申请,会长审核拒绝,没关系,调整姿势再来一遍!");
- Db::commit();
- $this->success("已审核拒绝!");
- }
- }
- $this->error("网络错误,请稍后重试!");
- }catch (ValidateException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (PDOException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- }
- /**
- * 公会申请加入列表
- */
- public function guildJoinList() {
- $user_id = $this->auth->id;
- // 获取公会信息
- $guildInfo = model('Guild')->where(["user_id"=>$user_id])->find();
- if(!$guildInfo) {
- $this->success("获取成功",[]);
- }
- // 先获取申请列表
- $where = [];
- $where["m.guild_id"] = $guildInfo->id;
- $where["m.status"] = 0;
- $result = Db::name('guild_joinin')->alias('m')
- ->field("m.id,m.user_id,m.createtime,user.is_online,user.onlinetime,user.nickname,user.avatar")
- ->join('user','m.user_id = user.id','LEFT')
- ->where($where)->order("createtime","desc")->select();
- if($result) {
- foreach($result as $k => &$v) {
- if ($v['is_online'] == 1) {
- $onlineText = '在线';
- } else {
- $onlineTime = get_last_time($v['onlinetime']);
- $onlineText = $onlineTime.'在线';
- $limitTime = time() - (3600 * 6);
- if ($v['onlinetime'] < $limitTime) {
- $onlineText = '离线';
- }
- }
- $v['online_text'] = $onlineText;
- unset($v['user']);
- }
- }
- $this->success("获取成功",$result);
- }
- /**
- * 公会成员列表
- */
- public function guildMember() {
- $guild_id = input("guild_id",0,"intval"); //公会ID
- if($guild_id <= 0) $this->error("参数错误!");
- $where = [];
- $where["a.guild_id"] = $guild_id;
- // 获取公会成员总数
- $guildMemberCount = \app\common\model\GuildMember::alias("a")->where($where)->count("id");
- // 获取公会成员列表
- $guildMemberList = \app\common\model\GuildMember::alias("a")
- ->field("a.id,a.user_id,u.avatar,u.nickname,u.gender,a.role,u.is_online,u.onlinetime")
- ->join("user u","a.user_id = u.id")
- ->where($where)
- ->autopage()
- ->order("a.role","desc")
- ->select();
- $role = [0=>'成员',1=>'副会长',2=>'会长'];
- if($guildMemberList) {
- foreach($guildMemberList as $k => &$v) {
- $v["role_text"] = $role[$v["role"]];
- if ($v['is_online'] == 1) {
- $onlineText = '在线';
- } else {
- $onlineTime = get_last_time($v['onlinetime']);
- $onlineText = $onlineTime.'在线';
- $limitTime = time() - (3600 * 6);
- if ($v['onlinetime'] < $limitTime) {
- $onlineText = '离线';
- }
- }
- $v['online_text'] = $onlineText;
- }
- }
- $res = [];
- $res["memberCount"] = $guildMemberCount;
- $res["memberList"] = $guildMemberList;
- $this->success("获取成功!",$res);
- }
- /**
- * 获取公会成员信息
- */
- public function getGuildMemberInfo() {
- $member_id = input("member_id",0,"intval"); //公会成员ID
- if($member_id <= 0) $this->error("参数错误!");
- //成员信息
- $memberData = model('GuildMember')->field('id,user_id')->find($member_id);
- //更新成员的 财富值 ,魅力值,收到的礼物数量
- $userService = new UserService();
- $userService->updateGuildMember(['user_id'=>$memberData['user_id']]);
- //从user表拿一些用户信息
- $memberInfo = model('GuildMember')->alias('m')
- ->join('user','m.user_id = user.id','LEFT')
- ->field('m.id,m.user_id,m.wealth,m.charm,m.gift_num,m.role,m.guild_id,m.createtime,
- user.avatar,user.nickname,user.gender,user.logintime,user.is_online,user.onlinetime')
- ->where('m.id',$member_id)
- ->find();
- if(!$memberInfo) $this->error("用户信息获取失败!");
- $memberInfo = info_domain_image($memberInfo,['avatar']);
- //角色
- $role = [0=>'成员',1=>'副会长',2=>'公会长'];
- $memberInfo["role_text"] = $role[$memberInfo["role"]];
- //在线
- if ($memberInfo['is_online'] == 1) {
- $onlineText = '在线';
- } else {
- $onlineTime = get_last_time($memberInfo['onlinetime']);
- $onlineText = $onlineTime.'在线';
- $limitTime = time() - (3600 * 6);
- if ($memberInfo['onlinetime'] < $limitTime) {
- $onlineText = '离线';
- }
- }
- $memberInfo['online_text'] = $onlineText;
- //我在这个公会的角色
- /*$myGuildMember = model('GuildMember')->field('role')->where(["user_id"=>$this->auth->id,"guild_id"=>$memberInfo->guild_id])->find();
- $memberInfo["my_role"] = !empty($myGuildMember) ? $myGuildMember['role'] : -1;*/
- //几个比较大的值,改w单位
- $fieldArr = ['wealth','charm','gift_num'];
- foreach ($fieldArr as $fkey => $fval) {
- if ($memberInfo[$fval] > 10000) {
- $memberInfo[$fval] = bcdiv($memberInfo[$fval],10000,2).'w';
- }
- }
- $this->success("获取成功!",$memberInfo);
- }
- /**
- * 公会管理-设为管理员
- */
- public function guildSetManage() {
- $guild_id = input("guild_id",0,"intval"); //公会ID
- $member_id = input("member_id",0,"intval"); //成员ID
- $type = input("type",1); // 设置类型:1=设为管理员,2=取消管理员
- if(!$guild_id || !$member_id || !in_array($type,[1,2])) $this->error("参数缺失!");
- $user_id = $this->auth->id;
- // 获取公会信息
- $guildInfo = \app\common\model\Guild::where(["id"=>$guild_id])->find();
- // 验证更新条件
- if($user_id !== $guildInfo->user_id) $this->error("身份验证失败!您不是公会长,无权限更改!");
- $memberInfo = \app\common\model\GuildMember::where(["id"=>$member_id,'guild_id'=>$guild_id])->find();
- if(!$memberInfo) $this->error("会员信息查询失败!");
- //取消管理员
- if($type == 2) {
- $memberInfo->role = 0;
- $memberInfo->updatetime = time();
- $res = $memberInfo->save();
- if($res) {
- //[环信]取消聊天室管理员
- $easemob = new Easemob();
- $easemob->room_demoteRoomAdmin($guildInfo['easemob_room_id'],$memberInfo['user_id']);
- $this->success("取消成功!");
- } else {
- $this->error("网络错误,请稍后重试!");
- }
- }
- //设置管理员
- $memberInfo->role = 1;
- $memberInfo->updatetime = time();
- $res = $memberInfo->save();
- if($res) {
- // 获取房间id
- $party_id = $guildInfo->party_id;
- // 添加房间管理员
- $redis = new Redis();
- $redisconfig = config("redis");
- $redis->connect($redisconfig["host"], $redisconfig["port"]);
- if ($redisconfig['redis_pwd']) {
- $redis->auth($redisconfig['redis_pwd']);
- }
- if($redisconfig['redis_selectdb'] > 0){
- $redis->select($redisconfig['redis_selectdb']);
- }
- // 获取成员用户信息
- $memberuserInfo = \app\common\model\User::field("id,avatar,nickname,gender,level")->where('id',$memberInfo['user_id'])->find();
- $data = [];
- $data["user_id"] = $memberuserInfo->id;
- $data["avatar"] = $memberuserInfo->avatar;
- $data["nickname"] = $memberuserInfo->nickname;
- $data["gender"] = $memberuserInfo->gender;
- $data["item"] = 1;
- $data["time"] = 0;
- $data["createtime"] = time();
- $redis->hSet("party_manage_".$party_id,$memberuserInfo->id."-1",serialize($data));
- //[环信]设置群组管理员
- $easemob = new Easemob();
- $easemob->room_promoteRoomAdmin($guildInfo['easemob_room_id'],$memberInfo['user_id']);
- $this->success("设置成功!");
- } else {
- $this->error("网络错误,请稍后重试!");
- }
- }
- /**
- * 公会管理-踢出公会
- */
- public function guildDelMember() {
- $guild_id = input("guild_id",0,"intval"); //公会ID
- $member_id = input("member_id",0,"intval"); //成员ID
- if(!$guild_id || !$member_id) $this->error("参数缺失!");
- // 先判断是否为公会会长
- $user_id = $this->auth->id;
- // 获取公会信息
- $guildInfo = \app\common\model\Guild::where(["id"=>$guild_id])->find();
- // 验证更新条件
- if($user_id !== $guildInfo->user_id) $this->error("身份验证失败!您不是公会长,无权限更改!");
- $memberInfo = \app\common\model\GuildMember::where(["id"=>$member_id,'guild_id'=>$guild_id])->find();
- if(!$memberInfo) $this->error("会员信息查询失败!");
- if($memberInfo['role'] == 2 || $memberInfo['user_id'] == $guildInfo['user_id']){
- $this->error('会长不能被踢出公会');
- }
- Db::startTrans();
- try{
- $res1 = $memberInfo->delete();
- $res2 = \app\common\model\Guild::where(["id"=>$guild_id])->setDec("member");
- if($res1 && $res2) {
- Db::commit();
- $this->success("踢出成功!");
- } else {
- $this->error("网络错误,请稍后重试!");
- }
- }catch (ValidateException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (PDOException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- }
- /**
- * 公会贡献榜排行
- * @return void
- */
- public function getRankList()
- {
- try {
- $id = input('guild_id',0);
- $guildMemberWhere['guild_id'] = $id;
- $guildMemberWhere['status'] = 1;
- $guildMember = model('GuildMember')->field('id,user_id,role')->where($guildMemberWhere)->select();
- $list = [];
- if (!empty($guildMember)) {
- $userIds = array_column($guildMember,'user_id');
- $where = [];
- $where['a.user_to_id'] = ['in', $userIds];
- $list = model('GiftUserParty')->alias("a")
- ->field('sum(a.value) as total_price,a.user_to_id,u.avatar,u.nickname,u.is_online,u.onlinetime')
- ->where($where)
- ->join('user u','u.id = a.user_to_id')
- ->group('a.user_to_id')
- ->order('total_price',"desc")
- ->autopage()
- ->select();
- if (!empty($list)) {
- $role = [0=>'成员',1=>'副会长',2=>'会长'];
- $guildMemberData = [];
- foreach ($guildMember as $mKey => $mVal) {
- $guildMemberData[$mVal['user_id']] = [
- 'id' => $mVal['id'],
- 'role' => $mVal['role'],
- 'role_text' => isset($role[$mVal['role']]) ? $role[$mVal['role']] : '',
- ];
- }
- foreach ($list as $key => &$value) {
- $member = isset($guildMemberData[$value['user_to_id']]) ? $guildMemberData[$value['user_to_id']] : [];
- $value['member_id'] = isset($member['id']) ? $member['id'] : 0;
- $value['role'] = isset($member['role']) ? $member['role'] : 0;
- $value['role_text'] = isset($member['role_text']) ? $member['role_text'] : '';
- if ($value['is_online'] == 1) {
- $onlineText = '在线';
- } else {
- $onlineTime = get_last_time($value['onlinetime']);
- $onlineText = $onlineTime.'在线';
- $limitTime = time() - (3600 * 6);
- if ($value['onlinetime'] < $limitTime) {
- $onlineText = '离线';
- }
- }
- $value['online_text'] = $onlineText;
- $value['total_price_text'] = $value['total_price'];
- if ($value['total_price'] >= 10000) {
- $value['total_price_text'] = bcdiv($value['total_price'],10000,1).'w';
- }
- unset($value['total_price']);
- }
- }
- }
- $this->success(__('Operation completed'),$list);
- } catch (Exception $e) {
- $this->error($e->getMessage());
- }
- }
- /**
- * 获取公会状态
- * @return void
- */
- public function getStatus()
- {
- $id = input('guild_id',0);
- if (!empty($id)) {
- $where['id'] = $id;
- } else {
- $where['user_id'] = $this->auth->id;
- }
- $field = 'id,status';
- $guild = model('Guild')->field($field)->where($where)->find();
- $this->success('获取成功', $guild);
- }
- ///////////////没用到的///////////
- /**
- * 开厅申请
- */
- public function guildApply() {
- $user_id = $this->auth->id;
- // 获取用户实名认证信息
- $authUserRealname = \app\common\model\UserAuth::where(["user_id"=>$user_id])->value("realname");
- if(!$authUserRealname) $this->error("未查询到实名认证信息,请实名认证先!");
- // 获取用户信息
- $userInfo = \app\common\model\User::field("id,mobile,nickname")->where(["id"=>$user_id])->find();
- $data = [];
- $data["user_id"] = $user_id;
- // 查看是否申请过
- $applyInfo = \app\common\model\GuildApply::where($data)->find();
- if($applyInfo && $applyInfo->status>=0) $this->error("您已经发送过开厅申请了,请勿重复发送!");
- // 查看是否有加入公会的申请
- $joinInfo = \app\common\model\GuildJoinin::where(["user_id"=>$user_id,"status"=>0])->find();
- if($joinInfo) $this->error("您存在申请加入公会信息,请联系公会长处理完毕后方可申请开厅!");
- // 查看是已经是公会成员
- $memberInfo = \app\common\model\GuildMember::where(["user_id"=>$user_id])->find();
- if($memberInfo) $this->error("您已存在签约中的公会,无法开新厅!");
- Db::startTrans();
- try{
- $data["user_name"] = $authUserRealname;
- $data["user_nickname"] = $userInfo->nickname;
- $data["user_mobile"] = $userInfo->mobile;
- $data["createtime"] = time();
- $res1 = \app\common\model\GuildApply::insert($data);
- // 更新用户状态
- $userInfo->is_guild = 1;
- $res2 = $userInfo->save();
- if($res1 && $res2) {
- Db::commit();
- $this->success("申请发送成功!");
- } else {
- $this->error("网络错误,请稍后重试!");
- }
- }catch (ValidateException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (PDOException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- }
- /**
- * 公会申请页面信息
- */
- public function guildApplyInfo() {
- $guild_id = input("guild_id"); //公会ID
- if($guild_id <= 0) $this->error("参数缺失!");
- $guildInfo = \app\common\model\Guild::alias("a")
- ->join("user u","u.id = a.user_id","inner")
- ->field("a.id,a.image,a.name,a.g_id,a.user_id,u.avatar,u.nickname,u.u_id")
- ->where(["a.id"=>$guild_id])
- ->find();
- $guildInfo["status"] = 0;
- // 获取申请用户是否已经有正在申请的记录
- $user_id = $this->auth->id;
- $joinStatus = \app\common\model\GuildJoinin::where(["user_id"=>$user_id])->value("status");
- if($joinStatus === 0) $guildInfo["status"] = 1;
- $Member = \app\common\model\GuildMember::where(["user_id"=>$user_id])->value("id");
- if($Member > 0) $guildInfo["status"] = 2;
- $this->success("获取成功!",$guildInfo);
- }
- }
|