request->request("guild_id"); //公会ID $is_member = 0; if($guild_id <= 0) { $is_member = 1; $user_id = $this->auth->id; // 获取当前用户是否是公会成员 $idcardfind = \app\common\model\GuildJoinin::where(["user_id"=>$user_id,"status"=>0])->find(); if($idcardfind) $this->error("您存在加入公会的申请,正在审核中,请耐心等待!"); $memberfind = \app\common\model\GuildMember::where(["user_id"=>$user_id,"status"=>1,"sign_time"=>["gt",time()]])->find(); if($memberfind) $guild_id = $memberfind->guild_id; if(!$guild_id) { $res["is_member"] = 2; // 是否为派对成员 $this->success("获取成功!",$res); } } $res = []; $guildInfo = \app\common\model\Guild::field("id,image,name,g_id,user_id,party_id,desc,notice")->where(["id"=>$guild_id])->find(); // 获取公会成员信息 $guildMemberInfo = \app\common\model\GuildMember::alias("a") ->field("a.user_id,a.role,u.nickname,u.avatar,u.gender,u.age") ->join("hx_user u","a.user_id = u.id") ->where(["a.guild_id"=>$guild_id])->limit(5)->order("a.role","desc")->select(); if(!$guildInfo || !$guildMemberInfo) $this->error("公会信息获取失败!"); // 获取公会成员总数 $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("party_logo,party_type,is_online,party_name,party_notice_detail")->where(["id"=>$guildInfo->party_id])->find(); // 派对类型 $partyTypeName = "普通房"; if($partyInfo["party_type"]) { $partyTypeName = \app\common\model\PartyType::where(["id"=>$partyInfo["party_type"]])->value("name"); } $mod = isset($partyInfo["party_type"])?intval($partyInfo["party_type"])%5:1; $partyInfo["party_type_color"] = $mod == 0?5:$mod; $partyInfo["type_name"] = $partyTypeName; // 返回参数拼接 $res["guildInfo"] = $guildInfo; // 公会基本信息 $res["guildMemberInfo"] = $guildMemberInfo; // 成员列表 $res["guildMemberCount"] = $guildMemberCount; // 成员总数 $res["guilderInfo"] = $guilderInfo; // 会长 $res["partyInfo"] = $partyInfo; // 派对悉尼下 $res["is_member"] = $is_member; // 是否为派对成员 $this->success("获取成功!",$res); } /** * 获取公会信息-新 */ public function getGuildInfoNew() { $guild_id = $this->request->request("guild_id"); //公会ID $is_member = 0; $user_id = $this->auth->id; if($guild_id <= 0) { $is_member = 1; // 获取当前用户是否是公会成员 $idcardfind = \app\common\model\GuildJoinin::where(["user_id"=>$user_id,"status"=>0])->find(); if($idcardfind) $this->error("您存在加入公会的申请,正在审核中,请耐心等待!"); $memberfind = \app\common\model\GuildMember::where(["user_id"=>$user_id,"status"=>1,"sign_time"=>["gt",time()]])->find(); if($memberfind) $guild_id = $memberfind->guild_id; $guildWhere['user_id'] = $user_id; $guildWhere['status'] = ['in',[0,1]]; $guildInfo = \app\common\model\Guild::field("id,image,name,g_id,user_id,party_id,desc,notice,status")->where($guildWhere)->find(); if(!$guild_id) { $res["is_member"] = 2; // 是否为派对成员 $res["guild_status"] = isset($guildInfo['status']) ? (int)$guildInfo['status'] : -2; // 是否为派对成员 $this->success("获取成功!",$res); } } $res = []; $guildInfo = \app\common\model\Guild::field("id,image,name,g_id,user_id,party_id,desc,notice,status")->where(["id"=>$guild_id])->find(); // 获取公会成员信息 $guildMemberInfo = \app\common\model\GuildMember::alias("a") ->field("a.id,a.user_id,a.role,u.nickname,u.avatar") ->join("hx_user u","a.user_id = u.id") ->where(["a.guild_id"=>$guild_id])->limit(5)->order("a.role","desc")->select(); if(!$guildInfo || !$guildMemberInfo) $this->error("公会信息获取失败!"); $guildStatus = (int)$guildInfo['status']; // 获取公会成员总数 $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,party_notice_detail")->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; // 派对类型 $partyTypeName = "普通房"; if(isset($partyInfo["party_type"])) { $partyTypeName = \app\common\model\PartyType::where(["id"=>$partyInfo["party_type"]])->value("name"); } $mod = isset($partyInfo["party_type"])?intval($partyInfo["party_type"])%5:1; $partyInfo["party_type_color"] = $mod == 0?5:$mod; $partyInfo["type_name"] = $partyTypeName; } //获取家族角色 $userService = new UserService(); $userParams = [ 'user_id' => $user_id, 'guild_id' => $guild_id, ]; $userRes = $userService->getGuildRole($userParams); $guildStatus = isset($userRes['data']['guild_role']) ? $userRes['data']['guild_role'] : 4; // 返回参数拼接 $res["guildInfo"] = $guildInfo; // 公会基本信息 $res["partyInfo"] = $partyInfo; // 派对悉尼下 $res["guildMemberInfo"] = $guildMemberInfo; // 成员列表 $res["guildMemberCount"] = $guildMemberCount; // 成员总数 $res["guilderInfo"] = $guilderInfo; // 会长 $res["is_member"] = $is_member; // 是否为派对成员 $res['guild_status'] = $guildStatus; //家族状态 $res['guild_role'] = $guildStatus; //家族角色:1组长,2副族长,3成员,4非成员 $this->success("获取成功!",$res); } /** * 更新公会基本信息 */ public function guildSaveInfo() { Db::startTrans(); try { $guild_id = $this->request->request("guild_id"); //公会id $guild_name = $this->request->request("guild_name"); //公会简介 $guild_image = $this->request->request("guild_image"); //公会简介 $guild_desc = $this->request->request("guild_desc"); //公会简介 $guild_notice = $this->request->request("guild_notice"); //公会公告 if(!$guild_name && !$guild_image && !$guild_desc && !$guild_notice) throw new Exception("请输入要修改的内容!"); $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)) { throw new Exception('您已创建过家族!'); } $guildInfo = new \app\common\model\Guild(); $guildInfo->user_id = $user_id; $ids = \app\common\model\Guild::column("g_id"); $guildInfo->g_id = getUinqueId(4, [$ids]); $guildInfo->status = 0; } else { // 获取公会信息 $guildInfo = \app\common\model\Guild::where(["id"=>$guild_id])->find(); // 验证更新条件 if($user_id !== $guildInfo->user_id) throw new Exception("身份验证失败!您不是公会长,无权限更改!"); } $guild_name && $guildInfo->name = $guild_name; $guild_image && $guildInfo->image = $guild_image; $guild_desc && $guildInfo->desc = $guild_desc; $guild_notice && $guildInfo->notice = $guild_notice; $res = $guildInfo->save(); if($res !== false) { if (empty($guild_id)) { $guildMemberData = [ 'guild_id' => $guildInfo->id, 'user_id' => $user_id, 'role' => 2, 'sign_type' => 3, 'sign_time' => 0, 'status' => 1, '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()); } } /** * 获取搜索公会列表 */ public function getGuildList() { $search = $this->request->request("search","","string"); //搜索的字段 公会名称/公会ID $page = $this->request->request("page",1); $pageNum = $this->request->request("pageNum",10); $offset = ($page-1) * $pageNum; //if(!$search) $this->error("请输入要搜索的公会名称或公会ID"); global $whereOr; $where = [];$whereOr = []; $where['status'] = 1; if (!empty($search)) { $whereOr['name'] = array('like', '%' . $search . '%'); $whereOr['g_id'] = $search; } $res = \app\common\model\Guild::field("id,g_id,user_id,party_id,name,image,desc,member") ->where($where) ->where(function ($query) { global $whereOr; $query->whereOr($whereOr); }) ->limit($offset,$pageNum) ->select(); $this->success("获取成功!",$res); } /** * 公会申请页面信息 */ public function guildApplyInfo() { $guild_id = $this->request->request("guild_id"); //公会ID if($guild_id <= 0) $this->error("参数缺失!"); $guildInfo = \app\common\model\Guild::alias("a") ->join("hx_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,"status"=>1,"sign_time"=>["gt",time()]])->value("id"); if($Member > 0) $guildInfo["status"] = 2; $this->success("获取成功!",$guildInfo); } /** * 开厅申请 */ 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,"status"=>1,"sign_time"=>["gt",time()]])->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 guildJoinin() { $join_time = $this->request->request("join_time",1); //签约时长:1=3个月,2=6个月,3=12个月 $guild_id = $this->request->request("guild_id"); //公会ID //if(!in_array($join_time,[1,2,3]) || !$guild_id) $this->error("参数错误!"); // 一个身份证号只能申请一次 $user_id = $this->auth->id; // 实名认证 $userAuthInfo = \app\common\model\UserAuth::where(["user_id"=>$user_id])->find(); if($userAuthInfo) { if($userAuthInfo->status == 0) { $this->error("您的实名认证还在这审核中...,请耐心等待!"); } elseif($userAuthInfo->status == 2) { $this->error("您的实名认证审核未通过,请重新审核!"); } } else { $this->error("请先申请实名认证!"); } // 获取用户实名认证信息 $authUserIdcard = \app\common\model\UserAuth::where(["user_id"=>$user_id])->value("idcard"); // 搜索签约申请中是否有此身份证号 $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,"status"=>1])->find(); if($memberfind) $this->error("一个账号只能加入一个公会哟!"); // 查看是否申请过 /*$applyInfo = \app\common\model\GuildApply::where(["user_id"=>$user_id,"status"=>0])->find(); if($applyInfo && $applyInfo->status>=0) $this->error("您已经发送过开厅申请了,请勿重复发送!");*/ // // 获取公会信息 // $guildInfo = \app\common\model\Guild::where(["user_id"=>$user_id,"status"=>1])->find(); // // 验证更新条件 // if($guildInfo) $this->error("您存在公会会长身份,请先解散相应的公会才可申请"); // 获取公会信息 $guildName = \app\common\model\Guild::where(["id"=>$guild_id])->value("name"); // 获取用户信息 $userInfo = \app\common\model\User::field("id,avatar,nickname")->where(["id"=>$user_id])->find(); // 添加数据 $data = []; $data["user_id"] = $user_id; $data["guild_id"] = $guild_id; $data["join_time"] = $join_time; $data["user_avatar"] = $userInfo->avatar; $data["user_idcard"] = $authUserIdcard; $data["user_nickname"] = $userInfo->nickname; $data["guild_name"] = $guildName; $data["createtime"] = time(); $res = \app\common\model\GuildJoinin::insert($data); if($res) { // +message // \app\common\model\Message::addMessage($user_id,"公会消息","申请加入公会消息"); $this->success("申请发送成功!"); } else { $this->error("网络错误,请稍后重试!"); } } /** * 公会签约申请审核 */ public function guildJoininExamine() { $joinin_id = $this->request->request("joinin_id"); // 申请加入的申请ID $is_pass = $this->request->request("is_pass"); // 是否通过:1=通过,-1=拒绝 if(!in_array($is_pass,[1,-1]) || !$joinin_id) $this->error("参数错误!"); $user_id = $this->auth->id; $memberfind = \app\common\model\GuildMember::where(["user_id"=>$joinin_id,"status"=>1])->find(); if($memberfind) $this->error("该用户已有家族!"); // 获取申请信息 $joininInfo = \app\common\model\GuildJoinin::where(["id"=>$joinin_id])->find(); if ($is_pass == 1) {//清理其他公会未审核的数据 if (!empty($joininInfo)) { $joinWhere['user_id'] = $joininInfo['user_id']; $joinWhere['guild_id'] = ['neq',$joininInfo['guild_id']]; $joinWhere['status'] = 0; $joinData = model('GuildJoinin')->where($joinWhere)->select(); if (!empty($joinData)) { $joinIds = array_column($joinData,'id'); $delWhere['id'] = ['in',$joinIds]; model('GuildJoinin')->where($delWhere)->delete(); } } } // 获取公会信息 $guildInfo = \app\common\model\Guild::where(["id"=>$joininInfo->guild_id])->find(); // 验证更新条件 if($user_id !== $guildInfo->user_id) $this->error("身份验证失败!您不是族长,无权限更改!"); // 获取用户信息 $userInfo = \app\common\model\User::field("id,u_id,mobile,nickname")->where(["id"=>$joininInfo->user_id])->find(); // 计算签约时间段 $join_time = $joininInfo->join_time; $timeArr = [1=>3,2=>6,3=>12]; $endtime = strtotime('+'.$timeArr[$join_time].' month'); $sign_time_slot = date("Y.m.d")."-".date('Y.m.d',$endtime); Db::startTrans(); try{ $data = []; $data["user_id"] = $joininInfo->user_id; $data["operator"] = $user_id; $data["user_nickname"] = $userInfo->nickname; $data["user_u_id"] = $userInfo->u_id; $data["guild_id"] = $guildInfo->id; $data["guild_name"] = $guildInfo->name; $data["guild_g_id"] = $guildInfo->g_id; $data["sign_time_slot"] = $sign_time_slot; $data["status"] = $is_pass; $data["createtime"] = time(); $res1 = \app\common\model\GuildJoininLog::insert($data); // 更新申请状态 $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["sign_type"] = $join_time; // 签约类型:1=三个月,2=半年,3=一年 $data["sign_time"] = $endtime; $data["status"] = 1; $data["createtime"] = time(); $res3 = \app\common\model\GuildMember::insert($data); $res4 = \app\common\model\Guild::where(["id"=>$guildInfo->id])->setInc("member"); if($res1 && $res2 && $res3 && $res4) { // +message \app\common\model\Message::addMessage($joininInfo->user_id,"家族审核通知","恭喜,您的加入家族审核通过啦!家族ID:".$guildInfo->g_id); Db::commit(); $this->success("已审核通过!"); } } else { if($res1 && $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 guildAssistantList() { $user_id = $this->auth->id; // 获取公会信息 $guildInfo = \app\common\model\Guild::where(["user_id"=>$user_id])->find(); if(!$guildInfo) $this->error("公会信息获取失败!"); // 先获取申请列表 $where = []; $where["guild_id"] = $guildInfo->id; $where["status"] = 0; $joinList = \app\common\model\GuildJoinin::field("id,user_avatar,user_nickname,guild_name,createtime")->where($where)->order("createtime","desc")->select(); if($joinList) foreach($joinList as $k => $v) { $joinList[$k]["createtime"] = date("Y-m-d H:i",$v["createtime"]); } // 再获取审核记录 $where = []; $where["a.guild_id"] = $guildInfo->id; $where["a.user_id"] = $user_id; $joinlogList = \app\common\model\GuildJoininLog::alias("a") ->field("a.id,a.user_nickname,a.user_u_id,a.guild_name,a.guild_g_id,a.sign_time_slot,a.status,u.nickname as operator,a.createtime") ->join("hx_user u","a.operator = u.id") ->whereOr($where) ->order("a.createtime","desc") ->select(); if($joinlogList) foreach($joinlogList as $k => $v) { $joinlogList[$k]["createtime"] = date("Y-m-d H:i",$v["createtime"]); } $res = []; $res["joinList"] = $joinList; $res["joinlogList"] = $joinlogList; $this->success("获取成功!",$res); } /** * 公会申请加入列表 */ public function guildJoinList() { try { $user_id = $this->auth->id; // 获取公会信息 $guildInfo = model('Guild')->where(["user_id"=>$user_id])->find(); if(!$guildInfo) throw new Exception('公会信息获取失败!'); // 先获取申请列表 $where = []; $where["guild_id"] = $guildInfo->id; $where["status"] = 0; $result = model('GuildJoinin')->field("id,user_id,user_avatar,user_nickname,guild_name,createtime") ->with(['user'=>function($uQuery){ $uQuery->field('id,is_online,onlinetime'); }]) ->where($where)->order("createtime","desc")->select(); if($result) { foreach($result as $k => &$v) { $user = isset($v['user']) ? $v['user'] : []; $onlineText = ''; if (!empty($user)) { if ($user['is_online'] == 1) { $onlineText = '在线'; } else { $onlineTime = get_last_time($user['onlinetime']); $onlineText = $onlineTime.'在线'; $limitTime = time() - (3600 * 6); if ($user['onlinetime'] < $limitTime) { $onlineText = '离线'; } } } $v['online_text'] = $onlineText; $v['createtime'] = !empty($v["createtime"]) ? date("Y-m-d H:i", $v["createtime"]) : ''; unset($v['user']); } } $this->success("获取成功",$result); } catch (Exception $e) { $this->error($e->getMessage()); } } /** * 公会成员列表 */ public function guildMember() { $guild_id = $this->request->request("guild_id",0,"intval"); //公会ID $page = $this->request->request('page',1); // 分页 $pageNum = $this->request->request('pageNum',10); // 分页 // 分页搜索构建 $pageStart = ($page-1)*$pageNum; if($guild_id <= 0) $this->error("参数错误!"); $where = []; $where["a.guild_id"] = $guild_id; $where["a.status"] = 1; //$where["a.sign_time"] = ["gt",time()]; // 获取公会成员总数 $guildMemberCount = \app\common\model\GuildMember::alias("a")->where($where)->count("id"); // 获取公会成员列表 $guildMemberList = \app\common\model\GuildMember::alias("a") ->field("a.id,u.avatar,u.nickname,u.gender,u.age,a.role,u.is_online,u.onlinetime") ->join("hx_user u","a.user_id = u.id") ->where($where) ->limit($pageStart,$pageNum) ->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 = $this->request->request("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']]); $memberInfo = model('GuildMember') ->field('id,user_id,wealth,charm,gift_num,role,guild_id,createtime') ->with(['user'=>function($uQuery){ $uQuery->field('id,avatar,nickname,gender,age,logintime,age_id,constellation_id,province_id,city_id'); }])->find($member_id); if(!$memberInfo) $this->error("用户信息获取失败!"); $userData = isset($memberInfo['user']) ? $memberInfo['user'] : []; $gender = isset($userData['gender']) ? $userData['gender'] : 1; $logintime = isset($userData['logintime']) ? $userData['logintime'] : 0; $userFieldInt = ['age']; $userFieldStr = ['avatar','nickname','age_text','constellation_text','province_text','city_text']; foreach ($userFieldInt as $keyInt => $valInt) { if (!isset($memberInfo[$valInt])) { $memberInfo[$valInt] = isset($userData[$valInt]) ? $userData[$valInt] : 0; } } foreach ($userFieldStr as $keyStr => $valStr) { if (!isset($memberInfo[$valStr])) { $memberInfo[$valStr] = isset($userData[$valStr]) ? $userData[$valStr] : ''; } } unset($memberInfo['user']); $memberInfo['gender_text'] = $gender == 1 ? '男' : '女'; $memberInfo["createtime"] = !empty($memberInfo["createtime"]) ? date("Y-m-d", $memberInfo["createtime"]) : ''; $memberInfo["logintime"] = !empty($logintime) ? date("Y-m-d", $logintime) : ''; $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; $fieldArr = ['wealth','charm','gift_num']; foreach ($fieldArr as $fkey => $fval) { if ($memberInfo[$fval] > 10000) { $memberInfo[$fval] = bcdiv($memberInfo[$fval],10000,2).'w'; } } /*$userJewelLogWhere["type"] = ["in",[0,2,3,5,6,13]];//查看wallet.php文件 $userJewelLogWhere["user_id"] = $userData['id']; $userJewelLogPay = model('UserJewelLog') ->field("sum(value) as total_price") ->where($userJewelLogWhere) ->select(); $memberInfo['wealth'] = isset($userJewelLogPay[0]['total_price']) ? (int)$userJewelLogPay[0]['total_price'] : 0; if ($memberInfo['wealth'] > 10000) { $memberInfo['wealth'] = bcdiv($memberInfo['wealth'],10000,2).'w'; } $userGiftWhere = []; $userGiftWhere["user_to_id"] = $userData['id']; $userGift = model('GiftUserParty') ->field("sum(value) as total_price,sum(number)as gift_total_num") ->where($userGiftWhere) ->select(); $memberInfo['charm'] = isset($userGift[0]['total_price']) ? (int)$userGift[0]['total_price'] : 0; $memberInfo['gift_num'] = isset($userGift[0]['gift_total_num']) ? (int)$userGift[0]['gift_total_num'] : 0; if ($memberInfo['charm'] > 10000) { $memberInfo['charm'] = bcdiv($memberInfo['charm'],10000,2).'w'; } if ($memberInfo['gift_num'] > 10000) { $memberInfo['gift_num'] = bcdiv($memberInfo['gift_num'],10000,2).'w'; }*/ $this->success("获取成功!",$memberInfo); } /** * 公会管理-设为管理员 */ public function guildSetManage() { $guild_id = $this->request->request("guild_id",0,"intval"); //公会ID $member_user_id = $this->request->request("member_user_id",0,"intval"); //成员用户ID $type = $this->request->request("type",1); // 设置类型:1=设为管理员,2=取消管理员 if(!$guild_id || !$member_user_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(["user_id"=>$member_user_id])->find(); if(!$memberInfo) $this->error("会员信息查询失败!"); if($type == 2) { $memberInfo->role = 0; $memberInfo->updatetime = time(); $res = $memberInfo->save(); if($res) { $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")->find($member_user_id); $data = []; $data["user_id"] = $memberuserInfo->id; $data["avatar"] = $memberuserInfo->avatar; $data["nickname"] = $memberuserInfo->nickname; $data["gender"] = $memberuserInfo->gender; $data["level"] = $memberuserInfo->level; $data["item"] = 1; $data["time"] = 0; $data["createtime"] = time(); $redis->hSet("party_manage_".$party_id,$memberuserInfo->id."-1",serialize($data)); // 腾讯im设置管理员 $tenim = new Tenim(); $tenim->setImManage($member_user_id,$party_id); $this->success("设置成功!"); } else { $this->error("网络错误,请稍后重试!"); } } /** * 公会管理-踢出公会 */ public function guildDelMember() { $guild_id = $this->request->request("guild_id",0,"intval"); //公会ID $member_user_id = $this->request->request("member_user_id",0,"intval"); //成员用户ID if(!$guild_id || !$member_user_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(["user_id"=>$member_user_id])->find(); if(!$memberInfo) $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 = $this->request->param('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('hx_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() { try { $id = $this->request->param('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); } catch (Exception $e) { $this->error($e->getMessage()); } } }