Guild.php 40 KB

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