Guild.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use think\Exception;
  6. use Redis;
  7. use app\api\controller\Tenim;
  8. use app\common\service\RoomService;
  9. /**
  10. * 公会控制器
  11. */
  12. class Guild extends Api
  13. {
  14. protected $noNeedLogin = ['getGuildList'];
  15. protected $noNeedRight = ['*'];
  16. /**
  17. * 获取公会信息
  18. */
  19. public function getGuildInfo() {
  20. $guild_id = $this->request->request("guild_id"); //公会ID
  21. $is_member = 0;
  22. if($guild_id <= 0) {
  23. $is_member = 1;
  24. $user_id = $this->auth->id;
  25. // 获取当前用户是否是公会成员
  26. $idcardfind = \app\common\model\GuildJoinin::where(["user_id"=>$user_id,"status"=>0])->find();
  27. if($idcardfind) $this->error("您存在加入公会的申请,正在审核中,请耐心等待!");
  28. $memberfind = \app\common\model\GuildMember::where(["user_id"=>$user_id,"status"=>1,"sign_time"=>["gt",time()]])->find();
  29. if($memberfind) $guild_id = $memberfind->guild_id;
  30. if(!$guild_id) {
  31. $res["is_member"] = 2; // 是否为派对成员
  32. $this->success("获取成功!",$res);
  33. }
  34. }
  35. $res = [];
  36. $guildInfo = \app\common\model\Guild::field("id,image,name,g_id,user_id,party_id,desc,notice")->where(["id"=>$guild_id])->find();
  37. // 获取公会成员信息
  38. $guildMemberInfo = \app\common\model\GuildMember::alias("a")
  39. ->field("a.user_id,a.role,u.nickname,u.avatar,u.gender,u.age")
  40. ->join("hx_user u","a.user_id = u.id")
  41. ->where(["a.guild_id"=>$guild_id])->limit(5)->order("a.role","desc")->select();
  42. if(!$guildInfo || !$guildMemberInfo) $this->error("公会信息获取失败!");
  43. // 获取公会成员总数
  44. $guildMemberCount = \app\common\model\GuildMember::where(["guild_id"=>$guild_id])->count("id");
  45. // 获取会长信息
  46. $guilderInfo = \app\common\model\User::field("avatar,nickname,u_id")->where(["id"=>$guildInfo->user_id])->find();
  47. // 获取房间信息
  48. $partyInfo = \app\common\model\Party::field("party_logo,party_type,is_online,party_name,party_notice_detail")->where(["id"=>$guildInfo->party_id])->find();
  49. // 派对类型
  50. $partyTypeName = "普通房";
  51. if($partyInfo["party_type"]) {
  52. $partyTypeName = \app\common\model\PartyType::where(["id"=>$partyInfo["party_type"]])->value("name");
  53. }
  54. $mod = isset($partyInfo["party_type"])?intval($partyInfo["party_type"])%5:1;
  55. $partyInfo["party_type_color"] = $mod == 0?5:$mod;
  56. $partyInfo["type_name"] = $partyTypeName;
  57. // 返回参数拼接
  58. $res["guildInfo"] = $guildInfo; // 公会基本信息
  59. $res["guildMemberInfo"] = $guildMemberInfo; // 成员列表
  60. $res["guildMemberCount"] = $guildMemberCount; // 成员总数
  61. $res["guilderInfo"] = $guilderInfo; // 会长
  62. $res["partyInfo"] = $partyInfo; // 派对悉尼下
  63. $res["is_member"] = $is_member; // 是否为派对成员
  64. $this->success("获取成功!",$res);
  65. }
  66. /**
  67. * 获取公会信息-新
  68. */
  69. public function getGuildInfoNew() {
  70. $guild_id = $this->request->request("guild_id"); //公会ID
  71. $is_member = 0;
  72. if($guild_id <= 0) {
  73. $is_member = 1;
  74. $user_id = $this->auth->id;
  75. // 获取当前用户是否是公会成员
  76. $idcardfind = \app\common\model\GuildJoinin::where(["user_id"=>$user_id,"status"=>0])->find();
  77. if($idcardfind) $this->error("您存在加入公会的申请,正在审核中,请耐心等待!");
  78. $memberfind = \app\common\model\GuildMember::where(["user_id"=>$user_id,"status"=>1,"sign_time"=>["gt",time()]])->find();
  79. if($memberfind) $guild_id = $memberfind->guild_id;
  80. if(!$guild_id) {
  81. $res["is_member"] = 2; // 是否为派对成员
  82. $this->success("获取成功!",$res);
  83. }
  84. }
  85. $res = [];
  86. $guildInfo = \app\common\model\Guild::field("id,image,name,g_id,user_id,party_id,desc,notice")->where(["id"=>$guild_id])->find();
  87. // 获取公会成员信息
  88. $guildMemberInfo = \app\common\model\GuildMember::alias("a")
  89. ->field("a.user_id,a.role,u.nickname,u.avatar")
  90. ->join("hx_user u","a.user_id = u.id")
  91. ->where(["a.guild_id"=>$guild_id])->limit(5)->order("a.role","desc")->select();
  92. if(!$guildInfo || !$guildMemberInfo) $this->error("公会信息获取失败!");
  93. // 获取公会成员总数
  94. $guildMemberCount = \app\common\model\GuildMember::where(["guild_id"=>$guild_id])->count("id");
  95. // 获取会长信息
  96. //$guilderInfo = \app\common\model\User::field("avatar,nickname,u_id")->where(["id"=>$guildInfo->user_id])->find();
  97. // 获取房间信息
  98. $partyInfo = \app\common\model\Party::field("id,party_logo,party_type,is_online,party_name,party_notice_detail")->where(["id"=>$guildInfo->party_id])->find();
  99. $partyParams = ['party_id' => $guildInfo->party_id];
  100. $roomService = new RoomService();
  101. $partyOnlineRes = $roomService->getPartyUserList($partyParams);
  102. $onlineData = isset($partyOnlineRes['data']) ? $partyOnlineRes['data'] : [];
  103. $partyInfo['user_list'] = isset($onlineData['user_list']) ? $onlineData['user_list'] : [];
  104. $partyInfo['online_num'] = isset($onlineData['online_num']) ? $onlineData['online_num'] : 0;
  105. // 派对类型
  106. $partyTypeName = "普通房";
  107. if($partyInfo["party_type"]) {
  108. $partyTypeName = \app\common\model\PartyType::where(["id"=>$partyInfo["party_type"]])->value("name");
  109. }
  110. $mod = isset($partyInfo["party_type"])?intval($partyInfo["party_type"])%5:1;
  111. $partyInfo["party_type_color"] = $mod == 0?5:$mod;
  112. $partyInfo["type_name"] = $partyTypeName;
  113. // 返回参数拼接
  114. $res["guildInfo"] = $guildInfo; // 公会基本信息
  115. $res["partyInfo"] = $partyInfo; // 派对悉尼下
  116. $res["guildMemberInfo"] = $guildMemberInfo; // 成员列表
  117. $res["guildMemberCount"] = $guildMemberCount; // 成员总数
  118. //$res["guilderInfo"] = $guilderInfo; // 会长
  119. $res["is_member"] = $is_member; // 是否为派对成员
  120. $this->success("获取成功!",$res);
  121. }
  122. /**
  123. * 更新公会基本信息
  124. */
  125. public function guildSaveInfo() {
  126. $guild_id = $this->request->request("guild_id"); //公会id
  127. $guild_name = $this->request->request("guild_name"); //公会简介
  128. $guild_image = $this->request->request("guild_image"); //公会简介
  129. $guild_desc = $this->request->request("guild_desc"); //公会简介
  130. $guild_notice = $this->request->request("guild_notice"); //公会公告
  131. if(!$guild_name && !$guild_image && !$guild_desc && !$guild_notice) $this->error("请输入要修改的内容!");
  132. if (empty($guild_id)) {
  133. $guildInfo = new \app\common\model\Guild();
  134. } else {
  135. $user_id = $this->auth->id;
  136. // 获取公会信息
  137. $guildInfo = \app\common\model\Guild::where(["id"=>$guild_id])->find();
  138. // 验证更新条件
  139. if($user_id !== $guildInfo->user_id) $this->error("身份验证失败!您不是公会长,无权限更改!");
  140. }
  141. $guild_name && $guildInfo->name = $guild_name;
  142. $guild_image && $guildInfo->image = $guild_image;
  143. $guild_desc && $guildInfo->desc = $guild_desc;
  144. $guild_notice && $guildInfo->notice = $guild_notice;
  145. $res = $guildInfo->save();
  146. if($res !== false) {
  147. $this->success("操作成功!");
  148. } else {
  149. $this->error("网络错误,请稍后重试!");
  150. }
  151. }
  152. /**
  153. * 获取搜索公会列表
  154. */
  155. public function getGuildList() {
  156. $search = $this->request->request("search","","string"); //搜索的字段 公会名称/公会ID
  157. $page = $this->request->request("page",1);
  158. $pageNum = $this->request->request("pageNum",10);
  159. $offset = ($page-1) * $pageNum;
  160. //if(!$search) $this->error("请输入要搜索的公会名称或公会ID");
  161. global $whereOr;
  162. $where = [];$whereOr = [];
  163. $where['status'] = 1;
  164. if (!empty($search)) {
  165. $whereOr['name'] = array('like', '%' . $search . '%');
  166. $whereOr['g_id'] = $search;
  167. }
  168. $res = \app\common\model\Guild::field("id,g_id,user_id,party_id,name,image,desc,member")
  169. ->where($where)
  170. ->where(function ($query) {
  171. global $whereOr;
  172. $query->whereOr($whereOr);
  173. })
  174. ->limit($offset,$pageNum)
  175. ->select();
  176. $this->success("获取成功!",$res);
  177. }
  178. /**
  179. * 公会申请页面信息
  180. */
  181. public function guildApplyInfo() {
  182. $guild_id = $this->request->request("guild_id"); //公会ID
  183. if($guild_id <= 0) $this->error("参数缺失!");
  184. $guildInfo = \app\common\model\Guild::alias("a")
  185. ->join("hx_user u","u.id = a.user_id","inner")
  186. ->field("a.id,a.image,a.name,a.g_id,a.user_id,u.avatar,u.nickname,u.u_id")
  187. ->where(["a.id"=>$guild_id])
  188. ->find();
  189. $guildInfo["status"] = 0;
  190. // 获取申请用户是否已经有正在申请的记录
  191. $user_id = $this->auth->id;
  192. $joinStatus = \app\common\model\GuildJoinin::where(["user_id"=>$user_id])->value("status");
  193. if($joinStatus === 0) $guildInfo["status"] = 1;
  194. $Member = \app\common\model\GuildMember::where(["user_id"=>$user_id,"status"=>1,"sign_time"=>["gt",time()]])->value("id");
  195. if($Member > 0) $guildInfo["status"] = 2;
  196. $this->success("获取成功!",$guildInfo);
  197. }
  198. /**
  199. * 开厅申请
  200. */
  201. public function guildApply() {
  202. $user_id = $this->auth->id;
  203. // 获取用户实名认证信息
  204. $authUserRealname = \app\common\model\UserAuth::where(["user_id"=>$user_id])->value("realname");
  205. if(!$authUserRealname) $this->error("未查询到实名认证信息,请实名认证先!");
  206. // 获取用户信息
  207. $userInfo = \app\common\model\User::field("id,mobile,nickname")->where(["id"=>$user_id])->find();
  208. $data = [];
  209. $data["user_id"] = $user_id;
  210. // 查看是否申请过
  211. $applyInfo = \app\common\model\GuildApply::where($data)->find();
  212. if($applyInfo && $applyInfo->status>=0) $this->error("您已经发送过开厅申请了,请勿重复发送!");
  213. // 查看是否有加入公会的申请
  214. $joinInfo = \app\common\model\GuildJoinin::where(["user_id"=>$user_id,"status"=>0])->find();
  215. if($joinInfo) $this->error("您存在申请加入公会信息,请联系工会长处理完毕后方可申请开厅!");
  216. // 查看是已经是公会成员
  217. $memberInfo = \app\common\model\GuildMember::where(["user_id"=>$user_id,"status"=>1,"sign_time"=>["gt",time()]])->find();
  218. if($memberInfo) $this->error("您已存在签约中的公会,无法开新厅!");
  219. Db::startTrans();
  220. try{
  221. $data["user_name"] = $authUserRealname;
  222. $data["user_nickname"] = $userInfo->nickname;
  223. $data["user_mobile"] = $userInfo->mobile;
  224. $data["createtime"] = time();
  225. $res1 = \app\common\model\GuildApply::insert($data);
  226. // 更新用户状态
  227. $userInfo->is_guild = 1;
  228. $res2 = $userInfo->save();
  229. if($res1 && $res2) {
  230. Db::commit();
  231. $this->success("申请发送成功!");
  232. } else {
  233. $this->error("网络错误,请稍后重试!");
  234. }
  235. }catch (ValidateException $e) {
  236. Db::rollback();
  237. $this->error($e->getMessage());
  238. } catch (PDOException $e) {
  239. Db::rollback();
  240. $this->error($e->getMessage());
  241. } catch (Exception $e) {
  242. Db::rollback();
  243. $this->error($e->getMessage());
  244. }
  245. }
  246. /**
  247. * 公会签约申请
  248. */
  249. public function guildJoinin() {
  250. $join_time = $this->request->request("join_time"); //签约时长:1=3个月,2=6个月,3=12个月
  251. $guild_id = $this->request->request("guild_id"); //公会ID
  252. if(!in_array($join_time,[1,2,3]) || !$guild_id) $this->error("参数错误!");
  253. // 一个身份证号只能申请一次
  254. $user_id = $this->auth->id;
  255. // 实名认证
  256. $userAuthInfo = \app\common\model\UserAuth::where(["user_id"=>$user_id])->find();
  257. if($userAuthInfo) {
  258. if($userAuthInfo->status == 0) {
  259. $this->error("您的实名认证还在这审核中...,请耐心等待!");
  260. } elseif($userAuthInfo->status == 2) {
  261. $this->error("您的实名认证审核未通过,请重新审核!");
  262. }
  263. } else {
  264. $this->error("请先申请实名认证!");
  265. }
  266. // 获取用户实名认证信息
  267. $authUserIdcard = \app\common\model\UserAuth::where(["user_id"=>$user_id])->value("idcard");
  268. // 搜索签约申请中是否有此身份证号
  269. $idcardfind = \app\common\model\GuildJoinin::where(["user_id"=>$user_id,"status"=>0])->find();
  270. if($idcardfind) $this->error("当前账号正在审核,请耐心等待!");
  271. $memberfind = \app\common\model\GuildMember::where(["user_id"=>$user_id,"status"=>1,"sign_time"=>["gt",time()]])->find();
  272. if($memberfind) $this->error("一个账号只能加入一个公会哟!");
  273. // 查看是否申请过
  274. $applyInfo = \app\common\model\GuildApply::where(["user_id"=>$user_id,"status"=>0])->find();
  275. if($applyInfo && $applyInfo->status>=0) $this->error("您已经发送过开厅申请了,请勿重复发送!");
  276. // // 获取公会信息
  277. // $guildInfo = \app\common\model\Guild::where(["user_id"=>$user_id,"status"=>1])->find();
  278. // // 验证更新条件
  279. // if($guildInfo) $this->error("您存在公会会长身份,请先解散相应的公会才可申请");
  280. // 获取公会信息
  281. $guildName = \app\common\model\Guild::where(["id"=>$guild_id])->value("name");
  282. // 获取用户信息
  283. $userInfo = \app\common\model\User::field("id,avatar,nickname")->where(["id"=>$user_id])->find();
  284. // 添加数据
  285. $data = [];
  286. $data["user_id"] = $user_id;
  287. $data["guild_id"] = $guild_id;
  288. $data["join_time"] = $join_time;
  289. $data["user_avatar"] = $userInfo->avatar;
  290. $data["user_idcard"] = $authUserIdcard;
  291. $data["user_nickname"] = $userInfo->nickname;
  292. $data["guild_name"] = $guildName;
  293. $data["createtime"] = time();
  294. $res = \app\common\model\GuildJoinin::insert($data);
  295. if($res) {
  296. // +message
  297. // \app\common\model\Message::addMessage($user_id,"公会消息","申请加入公会消息");
  298. $this->success("申请发送成功!");
  299. } else {
  300. $this->error("网络错误,请稍后重试!");
  301. }
  302. }
  303. /**
  304. * 公会签约申请审核
  305. */
  306. public function guildJoininExamine() {
  307. $joinin_id = $this->request->request("joinin_id"); // 申请加入的申请ID
  308. $is_pass = $this->request->request("is_pass"); // 是否通过:1=通过,-1=拒绝
  309. if(!in_array($is_pass,[1,-1]) || !$joinin_id) $this->error("参数错误!");
  310. $user_id = $this->auth->id;
  311. // 获取申请信息
  312. $joininInfo = \app\common\model\GuildJoinin::where(["id"=>$joinin_id])->find();
  313. // 获取公会信息
  314. $guildInfo = \app\common\model\Guild::where(["id"=>$joininInfo->guild_id])->find();
  315. // 验证更新条件
  316. if($user_id !== $guildInfo->user_id) $this->error("身份验证失败!您不是公会长,无权限更改!");
  317. // 获取用户信息
  318. $userInfo = \app\common\model\User::field("id,u_id,mobile,nickname")->where(["id"=>$joininInfo->user_id])->find();
  319. // 计算签约时间段
  320. $join_time = $joininInfo->join_time;
  321. $timeArr = [1=>3,2=>6,3=>12];
  322. $endtime = strtotime('+'.$timeArr[$join_time].' month');
  323. $sign_time_slot = date("Y.m.d")."-".date('Y.m.d',$endtime);
  324. Db::startTrans();
  325. try{
  326. $data = [];
  327. $data["user_id"] = $joininInfo->user_id;
  328. $data["operator"] = $user_id;
  329. $data["user_nickname"] = $userInfo->nickname;
  330. $data["user_u_id"] = $userInfo->u_id;
  331. $data["guild_id"] = $guildInfo->id;
  332. $data["guild_name"] = $guildInfo->name;
  333. $data["guild_g_id"] = $guildInfo->g_id;
  334. $data["sign_time_slot"] = $sign_time_slot;
  335. $data["status"] = $is_pass;
  336. $data["createtime"] = time();
  337. $res1 = \app\common\model\GuildJoininLog::insert($data);
  338. // 更新申请状态
  339. $joininInfo->status = $is_pass;
  340. $joininInfo->updatetime = time();
  341. $res2 = $joininInfo->save();
  342. if($is_pass == 1) {
  343. // 同意后 加入公会成员
  344. $data = [];
  345. $data["guild_id"] = $guildInfo->id;
  346. $data["user_id"] = $joininInfo->user_id;
  347. $data["role"] = 0;
  348. $data["sign_type"] = $join_time; // 签约类型:1=三个月,2=半年,3=一年
  349. $data["sign_time"] = $endtime;
  350. $data["status"] = 1;
  351. $data["createtime"] = time();
  352. $res3 = \app\common\model\GuildMember::insert($data);
  353. $res4 = \app\common\model\Guild::where(["id"=>$guildInfo->id])->setInc("member");
  354. if($res1 && $res2 && $res3 && $res4) {
  355. // +message
  356. \app\common\model\Message::addMessage($joininInfo->user_id,"公会审核通知","恭喜,您的加入公会审核通过啦!公会ID:".$guildInfo->g_id);
  357. Db::commit();
  358. $this->success("已审核通过!");
  359. }
  360. } else {
  361. if($res1 && $res2) {
  362. // +message
  363. \app\common\model\Message::addMessage($joininInfo->user_id,"公会审核通知","您的公会加入申请,公会长审核失败,没关系,调整姿势再来一遍!");
  364. Db::commit();
  365. $this->success("已审核拒绝!");
  366. }
  367. }
  368. $this->error("网络错误,请稍后重试!");
  369. }catch (ValidateException $e) {
  370. Db::rollback();
  371. $this->error($e->getMessage());
  372. } catch (PDOException $e) {
  373. Db::rollback();
  374. $this->error($e->getMessage());
  375. } catch (Exception $e) {
  376. Db::rollback();
  377. $this->error($e->getMessage());
  378. }
  379. }
  380. /**
  381. * 公会助手列表
  382. */
  383. public function guildAssistantList() {
  384. $user_id = $this->auth->id;
  385. // 获取公会信息
  386. $guildInfo = \app\common\model\Guild::where(["user_id"=>$user_id])->find();
  387. if(!$guildInfo) $this->error("公会信息获取失败!");
  388. // 先获取申请列表
  389. $where = [];
  390. $where["guild_id"] = $guildInfo->id;
  391. $where["status"] = 0;
  392. $joinList = \app\common\model\GuildJoinin::field("id,user_avatar,user_nickname,guild_name,createtime")->where($where)->order("createtime","desc")->select();
  393. if($joinList) foreach($joinList as $k => $v) {
  394. $joinList[$k]["createtime"] = date("Y-m-d H:i",$v["createtime"]);
  395. }
  396. // 再获取审核记录
  397. $where = [];
  398. $where["a.guild_id"] = $guildInfo->id;
  399. $where["a.user_id"] = $user_id;
  400. $joinlogList = \app\common\model\GuildJoininLog::alias("a")
  401. ->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")
  402. ->join("hx_user u","a.operator = u.id")
  403. ->whereOr($where)
  404. ->order("a.createtime","desc")
  405. ->select();
  406. if($joinlogList) foreach($joinlogList as $k => $v) {
  407. $joinlogList[$k]["createtime"] = date("Y-m-d H:i",$v["createtime"]);
  408. }
  409. $res = [];
  410. $res["joinList"] = $joinList;
  411. $res["joinlogList"] = $joinlogList;
  412. $this->success("获取成功!",$res);
  413. }
  414. /**
  415. * 公会申请加入列表
  416. */
  417. public function guildJoinList() {
  418. try {
  419. $user_id = $this->auth->id;
  420. // 获取公会信息
  421. $guildInfo = model('Guild')->where(["user_id"=>$user_id])->find();
  422. if(!$guildInfo) throw new Exception('公会信息获取失败!');
  423. // 先获取申请列表
  424. $where = [];
  425. $where["guild_id"] = $guildInfo->id;
  426. $where["status"] = 0;
  427. $result = model('GuildJoinin')->field("id,user_id,user_avatar,user_nickname,guild_name,createtime")
  428. ->with(['user'=>function($uQuery){
  429. $uQuery->field('id,is_online,onlinetime');
  430. }])
  431. ->where($where)->order("createtime","desc")->select();
  432. if($result) {
  433. foreach($result as $k => &$v) {
  434. $user = isset($v['user']) ? $v['user'] : [];
  435. $onlineText = '';
  436. if (!empty($user)) {
  437. if ($user['is_online'] == 1) {
  438. $onlineText = '在线';
  439. } else {
  440. $onlineTime = get_last_time($user['onlinetime']);
  441. $onlineText = $onlineTime.'在线';
  442. }
  443. }
  444. $v['online_text'] = $onlineText;
  445. $v['createtime'] = !empty($v["createtime"]) ? date("Y-m-d H:i", $v["createtime"]) : '';
  446. unset($v['user']);
  447. }
  448. }
  449. $this->success("获取成功",$result);
  450. } catch (Exception $e) {
  451. $this->error($e->getMessage());
  452. }
  453. }
  454. /**
  455. * 公会成员列表
  456. */
  457. public function guildMember() {
  458. $guild_id = $this->request->request("guild_id",0,"intval"); //公会ID
  459. $page = $this->request->request('page',1); // 分页
  460. $pageNum = $this->request->request('pageNum',10); // 分页
  461. // 分页搜索构建
  462. $pageStart = ($page-1)*$pageNum;
  463. if($guild_id <= 0) $this->error("参数错误!");
  464. $where = [];
  465. $where["a.guild_id"] = $guild_id;
  466. $where["a.status"] = 1;
  467. $where["a.sign_time"] = ["gt",time()];
  468. // 获取公会成员总数
  469. $guildMemberCount = \app\common\model\GuildMember::alias("a")->where($where)->count("id");
  470. // 获取公会成员列表
  471. $guildMemberList = \app\common\model\GuildMember::alias("a")
  472. ->field("a.id,u.avatar,u.nickname,u.gender,u.age,a.role")
  473. ->join("hx_user u","a.user_id = u.id")
  474. ->where($where)
  475. ->limit($pageStart,$pageNum)
  476. ->order("a.role","desc")
  477. ->select();
  478. $role = ["","管理","会长"];
  479. if($guildMemberList) foreach($guildMemberList as $k => &$v) {
  480. $v["role"] = $role[$v["role"]];
  481. }
  482. $res = [];
  483. $res["memberCount"] = $guildMemberCount;
  484. $res["memberList"] = $guildMemberList;
  485. $this->success("获取成功!",$res);
  486. }
  487. /**
  488. * 获取公会成员信息
  489. */
  490. public function getGuildMemberInfo() {
  491. $member_id = $this->request->request("member_id",0,"intval"); //公会成员ID
  492. if($member_id <= 0) $this->error("参数错误!");
  493. $memberInfo = \app\common\model\GuildMember::alias("a")
  494. ->join("hx_user u","u.id = a.user_id")
  495. ->field("u.id,u.avatar,u.nickname,u.gender,u.age,a.wealth,a.charm,a.gift_num,a.role,a.guild_id,a.createtime,u.logintime")
  496. ->find($member_id);
  497. if(!$memberInfo) $this->error("用户信息获取失败!");
  498. $memberInfo["createtime"] = date("Y-m-d",$memberInfo["createtime"]);
  499. $memberInfo["logintime"] = date("Y-m-d",$memberInfo["logintime"]);
  500. $memberInfo["my_role"] = \app\common\model\GuildMember::where(["user_id"=>$this->auth->id,"guild_id"=>$memberInfo->guild_id])->value("role");
  501. $this->success("获取成功!",$memberInfo);
  502. }
  503. /**
  504. * 公会管理-设为管理员
  505. */
  506. public function guildSetManage() {
  507. $guild_id = $this->request->request("guild_id",0,"intval"); //公会ID
  508. $member_user_id = $this->request->request("member_user_id",0,"intval"); //成员用户ID
  509. $type = $this->request->request("type",1); // 设置类型:1=设为管理员,2=取消管理员
  510. if(!$guild_id || !$member_user_id || !in_array($type,[1,2])) $this->error("参数缺失!");
  511. // 先判断是否为公会会长
  512. $user_id = $this->auth->id;
  513. // 获取公会信息
  514. $guildInfo = \app\common\model\Guild::where(["id"=>$guild_id])->find();
  515. // 验证更新条件
  516. if($user_id !== $guildInfo->user_id) $this->error("身份验证失败!您不是公会长,无权限更改!");
  517. $memberInfo = \app\common\model\GuildMember::where(["user_id"=>$member_user_id])->find();
  518. if(!$memberInfo) $this->error("会员信息查询失败!");
  519. if($type == 2) {
  520. $memberInfo->role = 0;
  521. $memberInfo->updatetime = time();
  522. $res = $memberInfo->save();
  523. if($res) {
  524. $this->success("取消成功!");
  525. } else {
  526. $this->error("网络错误,请稍后重试!");
  527. }
  528. }
  529. $memberInfo->role = 1;
  530. $memberInfo->updatetime = time();
  531. $res = $memberInfo->save();
  532. if($res) {
  533. // 获取房间id
  534. $party_id = $guildInfo->party_id;
  535. // 添加房间管理员
  536. $redis = new Redis();
  537. $redisconfig = config("redis");
  538. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  539. if ($redisconfig['redis_pwd']) {
  540. $redis->auth($redisconfig['redis_pwd']);
  541. }
  542. if($redisconfig['redis_selectdb'] > 0){
  543. $redis->select($redisconfig['redis_selectdb']);
  544. }
  545. // 获取成员用户信息
  546. $memberuserInfo = \app\common\model\User::field("id,avatar,nickname,gender,level")->find($member_user_id);
  547. $data = [];
  548. $data["user_id"] = $memberuserInfo->id;
  549. $data["avatar"] = $memberuserInfo->avatar;
  550. $data["nickname"] = $memberuserInfo->nickname;
  551. $data["gender"] = $memberuserInfo->gender;
  552. $data["level"] = $memberuserInfo->level;
  553. $data["item"] = 1;
  554. $data["time"] = 0;
  555. $data["createtime"] = time();
  556. $redis->hSet("party_manage_".$party_id,$memberuserInfo->id."-1",serialize($data));
  557. // 腾讯im设置管理员
  558. $tenim = new Tenim();
  559. $tenim->setImManage($member_user_id,$party_id);
  560. $this->success("设置成功!");
  561. } else {
  562. $this->error("网络错误,请稍后重试!");
  563. }
  564. }
  565. /**
  566. * 公会管理-踢出公会
  567. */
  568. public function guildDelMember() {
  569. $guild_id = $this->request->request("guild_id",0,"intval"); //公会ID
  570. $member_user_id = $this->request->request("member_user_id",0,"intval"); //成员用户ID
  571. if(!$guild_id || !$member_user_id) $this->error("参数缺失!");
  572. // 先判断是否为公会会长
  573. $user_id = $this->auth->id;
  574. // 获取公会信息
  575. $guildInfo = \app\common\model\Guild::where(["id"=>$guild_id])->find();
  576. // 验证更新条件
  577. if($user_id !== $guildInfo->user_id) $this->error("身份验证失败!您不是公会长,无权限更改!");
  578. $memberInfo = \app\common\model\GuildMember::where(["user_id"=>$member_user_id])->find();
  579. if(!$memberInfo) $this->error("会员信息查询失败!");
  580. Db::startTrans();
  581. try{
  582. $res1 = $memberInfo->delete();
  583. $res2 = \app\common\model\Guild::where(["id"=>$guild_id])->setDec("member");
  584. if($res1 && $res2) {
  585. Db::commit();
  586. $this->success("踢出成功!");
  587. } else {
  588. $this->error("网络错误,请稍后重试!");
  589. }
  590. }catch (ValidateException $e) {
  591. Db::rollback();
  592. $this->error($e->getMessage());
  593. } catch (PDOException $e) {
  594. Db::rollback();
  595. $this->error($e->getMessage());
  596. } catch (Exception $e) {
  597. Db::rollback();
  598. $this->error($e->getMessage());
  599. }
  600. }
  601. /**
  602. * 家族贡献榜排行
  603. * @return void
  604. */
  605. public function getRankList()
  606. {
  607. try {
  608. $id = $this->request->param('guild_id',0);
  609. $guildMemberWhere['guild_id'] = $id;
  610. $guildMemberWhere['status'] = 1;
  611. $guildMember = model('GuildMember')->field('id,user_id')->where($guildMemberWhere)->select();
  612. $list = [];
  613. if (!empty($guildMember)) {
  614. $userIds = array_column($guildMember,'user_id');
  615. $where = [];
  616. $where['a.user_to_id'] = ['in', $userIds];
  617. $list = model('GiftUserParty')->alias("a")
  618. ->field('sum(a.value) as total_price,a.user_id,u.avatar,u.nickname')
  619. ->where($where)
  620. ->join('hx_user u','u.id = a.user_id')
  621. ->group('a.user_to_id')
  622. ->order('total_price',"desc")
  623. ->limit(100)
  624. ->select();
  625. if (!empty($list)) {
  626. foreach ($list as $key => &$value) {
  627. $value['total_price_text'] = $value['total_price'];
  628. if ($value['total_price'] >= 10000) {
  629. $value['total_price_text'] = bcdiv($value['total_price'],10000,1).'w';
  630. }
  631. unset($value['total_price']);
  632. }
  633. }
  634. }
  635. $this->success(__('Operation completed'),$list);
  636. } catch (Exception $e) {
  637. $this->error($e->getMessage());
  638. }
  639. }
  640. }