Usercenter.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
  1. <?php
  2. namespace app\api\controller;
  3. use addons\epay\library\Service;
  4. use app\api\controller\Common;
  5. use app\api\validate\user\Report;
  6. use outh\outh;
  7. use think\Db;
  8. use app\common\controller\RedisLeaderboard;
  9. use Redis;
  10. use GatewayClient\Gateway;
  11. /**
  12. * 会员中心接口
  13. */
  14. class UserCenter extends Common
  15. {
  16. protected $noNeedLogin = ['shujuhuifu','getAnchorType','getRecharConfig','getExchangeConfig','getLevelExplain'];
  17. protected $noNeedRight = '*';
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->userModel = new \app\common\model\User();
  22. }
  23. /**
  24. * 获取当前用户信息
  25. */
  26. public function getMyUserInfo() {
  27. $this->success("获取成功!",$this->auth->getUserinfo());
  28. }
  29. /**
  30. * 获取个人信息
  31. */
  32. public function getUserInfo() {
  33. $user_id = $this->request->request("user_id");
  34. if (!$user_id) {
  35. $this->error(__('Invalid parameters'));
  36. }
  37. // 获取基本信息
  38. $where = [];
  39. $where["id"] = $user_id;
  40. $userInfo = $this->userModel->field("id,nickname,image,mobile,avatar,gender,money,age,u_id,level,jewel")->where($where)->find();
  41. // 获取技能信息
  42. $skillList = Model("ViewUserSkill")->getSkillInfo($user_id);
  43. $userInfo["skill"] = implode("/",$skillList);
  44. // 获取关注粉丝信息
  45. $followModel = new \app\common\model\ViewFollows();
  46. $fansModel = new \app\common\model\ViewFans();
  47. // 获取关注信息
  48. $where = [];
  49. $where["user_id"] = $user_id;
  50. $userCount = $followModel->where($where)->value("follows");
  51. // 获取粉丝数
  52. $where = [];
  53. $where["user_id"] = $user_id;
  54. $fansCount = $fansModel->where($where)->value("fans");
  55. $userInfo["follows_count"] = $userCount?$userCount:0;
  56. $userInfo["fans_count"] = $fansCount?$fansCount:0;
  57. // 获取贵族信息
  58. $nobleInfo = $this->userModel->getUserNobleInfo($user_id);
  59. // 查看者是否已关注
  60. $followid = \app\common\model\UserFansFollow::where(["fans_id"=>$this->auth->id,"user_id"=>$user_id])->value("id");
  61. $userInfo["is_follow"] = $followid>0?1:0;
  62. $userInfo = json_decode(json_encode($userInfo),true);
  63. $userInfo = array_merge($userInfo,$nobleInfo);
  64. // 获取用户在派对直播间情况信息
  65. $redis = new Redis();
  66. $redisconfig = config("redis");
  67. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  68. if ($redisconfig['redis_pwd']) {
  69. $redis->auth(config('redis_pwd'));
  70. }
  71. if($redisconfig['redis_selectdb'] > 0){
  72. $redis->select(config('redis_selectdb'));
  73. }
  74. $livingUserPartyId = $redis->hGet("livingUser", $user_id);
  75. $userInfo['party_info'] = json([]);
  76. if ($livingUserPartyId) {
  77. $party = \app\common\model\Party::where('id',$livingUserPartyId)->field('id,room_type')->find();
  78. $userInfo['party_info'] = ['party_id' => $party['id'], 'room_type' => $party['room_type']];
  79. }
  80. $this->success("获取成功!",$userInfo);
  81. }
  82. /**
  83. * 添加关注
  84. */
  85. public function addFollows() {
  86. $user_id = $this->request->request("user_id",0,"intval");// 关注者ID
  87. $type = $this->request->request("type",1);// 类型:1=关注,2=取消关注
  88. if (!$user_id || $user_id<=0) {
  89. $this->error(__('Invalid parameters'));
  90. }
  91. if($type == 1) {
  92. if($user_id == $this->auth->id) {
  93. $this->error("不需要关注自己哦!");
  94. }
  95. $fansfollowModel = new \app\common\model\UserFansFollow();
  96. $data = [];
  97. $data["user_id"] = $user_id;
  98. $data["fans_id"] = $this->auth->id;
  99. if($fansfollowModel->where($data)->find()) {
  100. $this->error("你已经关注过ta啦!");
  101. }
  102. $data["createtime"] = time();
  103. $id = $fansfollowModel->insertGetId($data);
  104. if($id > 0) {
  105. // 增加任务进度 +exp
  106. \app\common\model\TaskLog::tofinish($this->auth->id,"ebxLwnXj3L",1);
  107. // 增加任务进度 +exp
  108. \app\common\model\TaskLog::tofinish($this->auth->id,"iA1QgRhL",1);
  109. // 增加任务进度 +exp
  110. \app\common\model\TaskLog::tofinish($this->auth->id,"ghopE4Ou",1);
  111. // 增加任务进度 +exp
  112. \app\common\model\TaskLog::tofinish($this->auth->id,"TryNGc1x",1);
  113. $this->success("关注成功!");
  114. } else {
  115. $this->error("网络错误,请稍后重试!");
  116. }
  117. } else {
  118. $fansfollowModel = new \app\common\model\UserFansFollow();
  119. $where = [];
  120. $where["user_id"] = $user_id;
  121. $where["fans_id"] = $this->auth->id;
  122. $fansfollowInfo = $fansfollowModel->where($where)->find();
  123. if(!$fansfollowInfo) {
  124. $this->error("关注信息获取失败!");
  125. }
  126. $res = $fansfollowModel->where($where)->delete();
  127. if($res > 0) {
  128. $this->success("取消成功!");
  129. } else {
  130. $this->error("网络错误,请稍后重试!");
  131. }
  132. }
  133. }
  134. /**
  135. * 是否关注
  136. */
  137. public function isFollows() {
  138. $user_id = $this->request->request("user_id",0,"intval");// 关注者ID
  139. if (!$user_id || $user_id<=0) {
  140. $this->error(__('Invalid parameters'));
  141. }
  142. $fansfollowModel = new \app\common\model\UserFansFollow();
  143. $where = [];
  144. $where["user_id"] = $user_id;
  145. $where["fans_id"] = $this->auth->id;
  146. $fansfollowInfo = $fansfollowModel->where($where)->find();
  147. $data = [];
  148. if($fansfollowInfo) {
  149. $data["is_show_follow"] = 0;
  150. } else {
  151. $data["is_show_follow"] = 1;
  152. }
  153. $this->success("获取成功!",$data);
  154. }
  155. /**
  156. * 获取关注人列表.派对信息
  157. */
  158. public function getFollowsLive() {
  159. $is_online = $this->request->request("is_online");// 是否在线:1=直播中,0=未开播
  160. $page = $this->request->request('page',1); // 分页
  161. $pageNum = $this->request->request('pageNum',10); // 分页
  162. // 分页搜索构建
  163. $pageStart = ($page-1)*$pageNum;
  164. $is_online == 1 || $is_online = 0;
  165. $fanfollowModel = new \app\common\model\UserFansFollow();
  166. $where = [];
  167. $where["a.fans_id"] = $this->auth->id;
  168. $where["p.room_type"] = 2;
  169. $where["p.is_online"] = $is_online;
  170. if($is_online == 1) {
  171. $field = "p.id as party_id,u.u_id,u.nickname,p.party_name,p.party_hot,p.party_logo,u.avatar,t.id as party_type";
  172. } else {
  173. $field = "p.id as party_id,a.user_id,u.avatar,u.gender,u.level,u.nickname,p.party_name,p.party_logo,t.id as party_type";
  174. }
  175. $list = $fanfollowModel->alias("a")
  176. ->field($field)
  177. ->join("hx_user u","u.id = a.user_id")
  178. ->join("hx_party p","p.user_id = a.user_id")
  179. ->join("hx_party_type t","t.id = p.party_type","left")
  180. ->limit($pageStart,$pageNum)
  181. ->where($where)->select();
  182. if($list) {
  183. foreach($list as $k => $v) {
  184. $mod = isset($v["party_type"])?intval($v["party_type"])%5:1;
  185. if(isset($v["type_name"]) && $v["type_name"]) {
  186. $type_name = $v["type_name"];
  187. } else {
  188. $type_name = "普通房";
  189. }
  190. $list[$k]["party_type"] = $type_name;
  191. $list[$k]["party_type_color"] = $mod == 0?5:$mod;
  192. }
  193. $this->success("获取成功!",$list);
  194. } else {
  195. $this->success("数据为空!",[]);
  196. }
  197. }
  198. /**
  199. * 获取关注列表(个人中心模块)
  200. */
  201. public function getFollowsUser() {
  202. $type = $this->request->request('type',1); // 1=关注,2=粉丝
  203. $page = $this->request->request('page',1); // 分页
  204. $pageNum = $this->request->request('pageNum',10); // 分页
  205. // 分页搜索构建
  206. $pageStart = ($page-1)*$pageNum;
  207. $pageEnd = $pageStart + $pageNum;
  208. $fanfollowModel = new \app\common\model\UserFansFollow();
  209. // 获取关注列表
  210. $where = [];
  211. $where["a.fans_id"] = $this->auth->id;
  212. $followlist = $fanfollowModel->alias("a")
  213. ->field("a.id,a.user_id,u.avatar,u.nickname,u.level,u.gender")
  214. ->join("hx_user u","u.id = a.user_id")
  215. // ->limit($pageStart,$pageNum)
  216. ->where($where)->select();
  217. // 获取粉丝列表
  218. $where = [];
  219. $where["a.user_id"] = $this->auth->id;
  220. $fanslist = $fanfollowModel->alias("a")
  221. ->field("a.id,a.fans_id,u.avatar,u.nickname,u.level,u.gender")
  222. ->join("hx_user u","u.id = a.fans_id")
  223. // ->limit($pageStart,$pageNum)
  224. ->where($where)->select();
  225. // print_r(json_encode($followlist));exit;
  226. if($type == 1) {
  227. $ids = [];
  228. if($fanslist) {
  229. foreach($fanslist as $k => $v) {
  230. $ids[] = $v["fans_id"];
  231. }
  232. }
  233. if($followlist) {
  234. foreach($followlist as $k => $v) {
  235. if(in_array($v["user_id"],$ids)) {
  236. $followlist[$k]["is_hu"] = 1;
  237. } else {
  238. $followlist[$k]["is_hu"] = 0;
  239. }
  240. }
  241. }
  242. $fansfollow = $followlist;
  243. } else {
  244. $ids = [];
  245. if($followlist) {
  246. foreach($followlist as $k => $v) {
  247. $ids[] = $v["user_id"];
  248. }
  249. }
  250. if($fanslist) {
  251. foreach($fanslist as $k => $v) {
  252. if(in_array($v["fans_id"],$ids)) {
  253. $fanslist[$k]["is_hu"] = 1;
  254. } else {
  255. $fanslist[$k]["is_hu"] = 0;
  256. }
  257. }
  258. }
  259. $fansfollow = $fanslist;
  260. }
  261. if($fansfollow) {
  262. $data = [];
  263. foreach($fansfollow as $k => $v) {
  264. if($k >= $pageStart && $k < $pageEnd) {
  265. $data[] = $v;
  266. }
  267. }
  268. $this->success("获取成功!",$data);
  269. } else {
  270. $this->success("数据为空!",[]);
  271. }
  272. }
  273. /**
  274. * 获取个人技能列表
  275. */
  276. public function getMySkillList() {
  277. $user_id = $this->request->request('user_id',0); // 用户ID
  278. $page = $this->request->request('page',1); // 分页
  279. $pageNum = $this->request->request('pageNum',10); // 分页
  280. if ($user_id == -1) {
  281. $user_id = $this->auth->id;
  282. } elseif($user_id>0) {
  283. $user_id = intval($user_id);
  284. } else {
  285. $this->error(__('Invalid parameters'));
  286. }
  287. // 分页搜索构建
  288. $pageStart = ($page-1)*$pageNum;
  289. $authModel = new \app\common\model\DispatchAuth();
  290. $where = [];
  291. $where["a.user_id"] = $user_id;
  292. $where["a.status"] = 1;
  293. $authskillList = $authModel->alias("a")
  294. ->field("a.id,ds.image,ds.name,a.voice,a.voice_time,a.price,a.is_main,ds.unit")
  295. ->join("hx_dispatch_skill ds","ds.id = a.skill_id")
  296. ->where($where)
  297. ->limit($pageStart,$pageNum)
  298. ->select();
  299. $this->success("获取成功!",$authskillList);
  300. }
  301. /**
  302. * 删除个人技能信息
  303. */
  304. public function delMySkillInfo() {
  305. $id = $this->request->request('id'); // 认证ID
  306. if (!$id) {
  307. $this->error(__('Invalid parameters'));
  308. }
  309. $authModel = new \app\common\model\DispatchAuth();
  310. $where = [];
  311. $where["id"] = $id;
  312. $where["user_id"] = $this->auth->id;
  313. $authInfo = $authModel->where($where)->find();
  314. if(!$authInfo) $this->error("技能认证未找到");
  315. // if($authInfo->is_main == 1) $this->error("请先取消主技能,再删除!");
  316. Db::startTrans();
  317. try{
  318. $res1 = $authInfo->delete();
  319. $res2 = \app\common\model\UserSkill::where(["user_id"=>$this->auth->id,"skill_id"=>$authInfo->skill_id])->delete();
  320. if($res1 && $res2) {
  321. Db::commit();
  322. $this->success("删除成功!");
  323. } else {
  324. $this->error("网络错误,请稍后重试!");
  325. }
  326. }catch (ValidateException $e) {
  327. Db::rollback();
  328. $this->error($e->getMessage());
  329. } catch (PDOException $e) {
  330. Db::rollback();
  331. $this->error($e->getMessage());
  332. } catch (Exception $e) {
  333. Db::rollback();
  334. $this->error($e->getMessage());
  335. }
  336. }
  337. /**
  338. * 修改个人技能信息
  339. */
  340. public function editMySkillInfo() {
  341. $price = $this->request->request('price'); // 价格
  342. $id = $this->request->request('id'); // 认证ID
  343. $is_main = $this->request->request('is_main'); // 是否设置为主技能
  344. if (!$id && !$price) {
  345. $this->error(__('Invalid parameters'));
  346. }
  347. $authModel = new \app\common\model\DispatchAuth();
  348. $where = [];
  349. $where["id"] = $id;
  350. if(!$authModel->where($where)->find()) $this->error("技能认证未找到");
  351. Db::startTrans();
  352. try{
  353. if($is_main == 1) {
  354. $where = [];
  355. $where["user_id"] = $this->auth->id;
  356. $authModel->update(["is_main"=>0],$where);
  357. }
  358. $where = [];
  359. $where["id"] = $id;
  360. $data = [];
  361. $data["price"] = $price;
  362. $data["is_main"] = $is_main;
  363. $res = $authModel->update($data,$where);
  364. $myAuthList = $authModel->where(["user_id"=>$this->auth->id,"is_main"=>1])->find();
  365. if(!$myAuthList) {
  366. $this->error("必须至少设置一个主技能");
  367. Db::rollback();
  368. }
  369. if($res) {
  370. Db::commit();
  371. $this->success("修改成功!",$data);
  372. } else {
  373. $this->error("网络错误,请稍后重试!");
  374. }
  375. }catch (ValidateException $e) {
  376. Db::rollback();
  377. $this->error($e->getMessage());
  378. } catch (PDOException $e) {
  379. Db::rollback();
  380. $this->error($e->getMessage());
  381. } catch (Exception $e) {
  382. Db::rollback();
  383. $this->error($e->getMessage());
  384. }
  385. }
  386. /**
  387. * 编辑个人信息
  388. */
  389. public function editUserInfo() {
  390. $avatar = $this->request->request('avatar'); // 头像
  391. $nickname = $this->request->request('nickname'); // 昵称
  392. $age = $this->request->request('age'); // 年龄
  393. $ageId = $this->request->request('age_id'); // 年龄段
  394. $gender = $this->request->request('gender'); // 性别 0=女,1=男
  395. $image = $this->request->request('image'); // 个人形象照
  396. $constellationId = $this->request->request('star_id'); //星座ID
  397. $provinceId = $this->request->request('province_id'); //省ID
  398. $cityId = $this->request->request('city_id'); //城市ID
  399. $desc = $this->request->request('desc'); //个性签名
  400. /*if (!$avatar && !$nickname && !$age && !$image && !in_array($gender,[0,1])) {
  401. $this->error(__('请输入要修改的信息'));
  402. }*/
  403. $where = [];
  404. $where["id"] = $this->auth->id;
  405. $data = [];
  406. $avatar && $data["avatar"] = $avatar;
  407. if($nickname){
  408. if (mb_strlen($nickname) > 8) {
  409. $this->error('用户昵称最多支持8个汉字或组合');
  410. }
  411. $data["nickname"] = $nickname;
  412. }
  413. $gender && $data["gender"] = $gender;
  414. $age && $data["age"] = $age;
  415. $image && $data["image"] = $image;
  416. $ageId && $data['age_id'] = $ageId;
  417. $constellationId && $data['constellation_id'] = $constellationId;
  418. $provinceId && $data['province_id'] = $provinceId;
  419. $cityId && $data['city_id'] = $cityId;
  420. $desc && $data['desc'] = $desc;
  421. $res = $this->userModel->update($data,$where);
  422. if($res) {
  423. $user = $this->userModel->where($where)->find();
  424. if (!empty($user['nickname']) && !empty($user['avatar']) && !empty($user['age_id']) && $user['has_info']==0) {
  425. $data['has_info'] = 1;
  426. $this->userModel->update($data,$where);
  427. }
  428. $this->success("修改成功!");
  429. } else {
  430. $this->error("网络错误,请稍后重试!");
  431. }
  432. }
  433. /**
  434. * 主播申请
  435. */
  436. public function anchorApply() {
  437. $type_id = $this->request->request('type_id'); // 技能分类ID
  438. $desc = $this->request->request('desc'); // 申请备注
  439. if (!$type_id && !$desc) {
  440. $this->error(__('Invalid parameters'));
  441. }
  442. $useranchorModel = new \app\common\model\UserAnchor();
  443. $data = [];
  444. $data["user_id"] = $this->auth->id;
  445. $data["type_id"] = $type_id;
  446. if($useranchorModel->where($data)->find()) $this->error(__('您已申请过该类型的主播,请勿重复申请!'));
  447. $data["desc"] = $desc;
  448. $data["createtime"] = time();
  449. $res = $useranchorModel->insertGetId($data);
  450. if($res) {
  451. \app\common\model\User::update(["is_anchor"=>1],["id"=>$this->auth->id]);
  452. $this->success("申请发送成功!");
  453. } else {
  454. $this->error("网络错误,请稍后重试");
  455. }
  456. }
  457. /**
  458. * 实名认证
  459. */
  460. public function authApply() {
  461. $realname = $this->request->request('realname'); // 真实姓名
  462. $idcard = $this->request->request('idcard'); // 身份证号
  463. $zimage = $this->request->request('zimage'); // 身份证正面照
  464. $fimage = $this->request->request('fimage'); // 身份证反面照
  465. if (!$realname && !$idcard && !$zimage && !$fimage) {
  466. $this->error(__('Invalid parameters'));
  467. }
  468. $userauthModel = new \app\common\model\UserAuth();
  469. $data = [];
  470. $data["user_id"] = $this->auth->id;
  471. //$data["idcard"] = $idcard;
  472. $userAuth = $userauthModel->where($data)->find();
  473. if (!empty($userAuth)) {
  474. if(in_array($userAuth['status'],[0,1])) $this->error('您已经申请过了,请勿重复操作!');
  475. }
  476. // 测试需要 开始
  477. $data["realname"] = $realname;
  478. $zimage && $data["zimage"] = $zimage;
  479. $fimage && $data["fimage"] = $fimage;
  480. $data["status"] = 1;
  481. if (!empty($userAuth)) {
  482. $data["updatetime"] = time();
  483. $authWhere['user_id'] = $this->auth->id;
  484. $res = $userauthModel->where($authWhere)->update($data);
  485. } else {
  486. $data["createtime"] = time();
  487. $res = $userauthModel->insertGetId($data);
  488. }
  489. if($res) {
  490. \app\common\model\User::update(["is_auth"=>2],["id"=>$this->auth->id]);
  491. $this->success("恭喜,实名认证成功!");
  492. } else {
  493. $this->error("网络错误,请稍后重试");
  494. }
  495. // 测试需要 结束
  496. // 实名认证验证
  497. $configInfo = config("auth");
  498. $outh = new outh($configInfo["api_url"],$configInfo["customer_code"],$configInfo["private_key"],$configInfo["key"]);
  499. $out_trade_no = date("YmdHis").rand(1000,9999);
  500. $ret = $outh->toVerify($out_trade_no,$realname,$idcard);
  501. if(isset($ret["code"])) {
  502. if($ret["code"] == "1008") {
  503. $this->error(__('身份证格式错误'));
  504. }
  505. if($ret["code"] == "1009") {
  506. $this->error(__('身份证格式错误'));
  507. }
  508. if($ret["code"] == "0001") {
  509. $this->error(__('姓名和身份证号不匹配!'));
  510. }
  511. if($ret["code"] == "0000") {
  512. $data["realname"] = $realname;
  513. $zimage && $data["zimage"] = $zimage;
  514. $fimage && $data["fimage"] = $fimage;
  515. $data["status"] = 1;
  516. $data["createtime"] = time();
  517. $res = $userauthModel->insertGetId($data);
  518. if($res) {
  519. \app\common\model\User::update(["is_auth"=>2],["id"=>$this->auth->id]);
  520. $this->success("恭喜,实名认证成功!");
  521. } else {
  522. $this->error("网络错误,请稍后重试");
  523. }
  524. }
  525. } else {
  526. $this->error("网络错误,请稍后重试");
  527. }
  528. }
  529. /**
  530. * 获取主播分类
  531. */
  532. public function getAnchorType() {
  533. $this->success("获取成功!",\app\common\model\UserAnchorType::select());
  534. }
  535. /**
  536. * 加入黑名单
  537. */
  538. public function addBlacklist() {
  539. $black_user_id = $this->request->request('black_user_id'); // 黑名单用户ID
  540. if (!$black_user_id) {
  541. $this->error(__('Invalid parameters'));
  542. }
  543. $userblacklistModel = new \app\common\model\UserBlacklist();
  544. $data = [];
  545. $data["user_id"] = $this->auth->id;
  546. $data["black_user_id"] = $black_user_id;
  547. if($userblacklistModel->where($data)->find()) $this->error(__('已在黑名单!'));
  548. $data["createtime"] = time();
  549. $res = $userblacklistModel->insertGetId($data);
  550. if($res) {
  551. $this->success("加入成功!");
  552. } else {
  553. $this->error("网络错误,请稍后重试");
  554. }
  555. }
  556. /**
  557. * 获取黑名单用户
  558. */
  559. public function getBlacklist() {
  560. $page = $this->request->request('page',1); // 分页
  561. $pageNum = $this->request->request('pageNum',10); // 分页
  562. // 分页搜索构建
  563. $pageStart = ($page-1)*$pageNum;
  564. $userblacklistModel = new \app\common\model\UserBlacklist();// ->limit($pageStart,$pageNum)
  565. $where = [];
  566. $where["a.user_id"] = $this->auth->id;
  567. $list = $userblacklistModel->alias("a")
  568. ->field("a.id,a.black_user_id,u.avatar,u.nickname,u.level,u.gender")
  569. ->join("hx_user u","u.id = a.black_user_id")
  570. ->where($where)
  571. ->limit($pageStart,$pageNum)
  572. ->select();
  573. if($list) {
  574. $this->success("获取成功!",$list);
  575. } else {
  576. $this->success("数据为空",[]);
  577. }
  578. }
  579. /**
  580. * 移除用户黑名单
  581. */
  582. public function removeUserBlack() {
  583. $id = $this->request->request('id'); // 黑名单ID
  584. if (!$id) {
  585. $this->error(__('Invalid parameters'));
  586. }
  587. $userblacklistModel = new \app\common\model\UserBlacklist();
  588. $where = [];
  589. $where["id"] = $id;
  590. $res = $userblacklistModel->where($where)->delete();
  591. if($res) {
  592. $this->success("移除成功!",$res);
  593. } else {
  594. $this->error("网络错误,请稍后重试!");
  595. }
  596. }
  597. /**
  598. * 举报用户
  599. */
  600. public function addReport() {
  601. $ruser_id = $this->request->request('ruser_id'); // 被举报用户ID
  602. $content = $this->request->request('content'); // 举报内容
  603. $image = $this->request->request('image'); // 图片描述(多个用半角逗号隔开)
  604. if (!$ruser_id) {
  605. $this->error(__('Invalid parameters'));
  606. }
  607. $userreportModel = new \app\common\model\UserReport();
  608. $data = [];
  609. $data["user_id"] = $this->auth->id;
  610. $data["reportable_id"] = $ruser_id;
  611. $data['reportable_type'] = $this->getModelName('user');
  612. $data["content"] = $content;
  613. $data["image"] = $image;
  614. $data["createtime"] = time();
  615. $res = $userreportModel->insertGetId($data);
  616. if($res) {
  617. $this->success("举报成功!");
  618. } else {
  619. $this->error("网络错误,请稍后重试");
  620. }
  621. }
  622. /**
  623. * 举报
  624. */
  625. public function addReportNew() {
  626. $params = $this->request->param();
  627. $validate = new Report();
  628. $result = $validate->check($params);
  629. if (!$result) {
  630. $this->error($validate->getError());
  631. }
  632. $userreportModel = new \app\common\model\UserReport();
  633. $data = [];
  634. $data["user_id"] = $this->auth->id;
  635. $data["reportable_id"] = $params['reportable_id'];
  636. $data['reportable_type'] = $this->getModelName($params['reportable_type']);
  637. $data["content"] = $params['content'];
  638. $data["image"] = $params['image'];
  639. $data["createtime"] = time();
  640. $res = $userreportModel->insertGetId($data);
  641. if($res) {
  642. $this->success("举报成功!");
  643. } else {
  644. $this->error("网络错误,请稍后重试");
  645. }
  646. }
  647. /**
  648. * redis 数据恢复---非redis数据丢失请勿使用!!!!
  649. */
  650. public function shujuhuifu() {
  651. $key = $this->request->request("key");// 操作验证 123456
  652. if($key != 123456) {
  653. $this->error(__('Invalid parameters'));
  654. }
  655. $giftuserpartyModel = new \app\common\model\GiftUserParty();
  656. $redis = new Redis();
  657. $redisconfig = config("redis");
  658. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  659. if ($redisconfig['redis_pwd']) {
  660. $redis->auth(config('redis_pwd'));
  661. }
  662. if($redisconfig['redis_selectdb'] > 0){
  663. $redis->select(config('redis_selectdb'));
  664. }
  665. // 获取本周第一天
  666. $weekday = $this->firstOfWeek(date("Y-m-d H:i:s"));
  667. // 获取本月第一天
  668. $monthday = date("Ym01");
  669. $where = [];
  670. $where["createtime"] = ["gt",strtotime($weekday)];
  671. $list1 = $giftuserpartyModel->where($where)->select();
  672. foreach($list1 as $k => $v) {
  673. // 添加redis记录做财富排行榜周榜用
  674. $redis->zIncrBy("jewel_get_".$v["party_id"].":".$weekday,$v["value"],$v["user_to_id"]);
  675. // 添加redis记录做贡献排行榜周榜用
  676. $redis->zIncrBy("jewel_to_".$v["party_id"].":".$weekday,$v["value"],$v["user_id"]);
  677. }
  678. $where = [];
  679. $where["createtime"] = ["gt",strtotime(date("Y-m-01"))];
  680. $list2 = $giftuserpartyModel->where($where)->select();
  681. foreach($list2 as $k => $v) {
  682. // 添加redis记录做财富排行榜月榜用
  683. $redis->zIncrBy("jewel_get_".$v["party_id"].":".$monthday,$v["value"],$v["user_to_id"]);
  684. // 添加redis记录做贡献排行榜月榜用
  685. $redis->zIncrBy("jewel_to_".$v["party_id"].":".$monthday,$v["value"],$v["user_id"]);
  686. }
  687. $this->success("执行成功!");
  688. }
  689. /**
  690. * 获取用户钻石余额
  691. */
  692. public function getUserJewel() {
  693. $data = \app\common\model\User::field("Jewel,money")->where(["id"=>$this->auth->id])->find();
  694. return $this->success("获取成功!",$data);
  695. }
  696. /**
  697. * 获取用户等级说明
  698. */
  699. public function getLevelExplain() {
  700. $data = \app\common\model\UserLevelExplain::field("title,content")->select();
  701. return $this->success("获取成功!",$data);
  702. }
  703. /**
  704. * 获取用户等级信息
  705. */
  706. public function getUserLevelInfo() {
  707. $res = [];$exstart = 0;$exend = 0;
  708. $userModel = new \app\common\model\User();
  709. $userInfo = $userModel->field("id,nickname,avatar,level,empirical")->where(["id"=>$this->auth->id])->find();
  710. if(!$userInfo) {
  711. $this->error("用户信息获取失败!");
  712. }
  713. $res["avatar"] = $userInfo['avatar'];
  714. $res["nickname"] = $userInfo['nickname'];
  715. // 获取用户当前经验值对应等级
  716. $userconfigModel = new \app\common\model\UserLevelConfig();
  717. $where = [];
  718. $where["empirical"] = ["elt",$userInfo["empirical"]];
  719. $userexplainstart = $userconfigModel->where($where)->order("empirical","desc")->limit(1)->select();
  720. $where = [];
  721. $where["empirical"] = ["gt",$userInfo["empirical"]];
  722. $userexplainend = $userconfigModel->where($where)->order("empirical","asc")->limit(1)->select();
  723. if(!$userexplainstart && !$userexplainend) {
  724. $this->error("经验等级信息获取失败!");
  725. } elseif(!$userexplainstart && $userexplainend) {
  726. $res["level_start"] = 0;
  727. $res["level_end"] = $userexplainend[0]["level"];
  728. } elseif($userexplainstart && !$userexplainend) {
  729. $res["level_start"] = $userexplainstart[0]["level"];
  730. $res["level_end"] = $userexplainstart[0]["level"];
  731. } elseif($userexplainstart && $userexplainend) {
  732. $res["level_start"] = $userexplainstart[0]["level"];
  733. $res["level_end"] = $userexplainend[0]["level"];
  734. }
  735. $userexplainstart && $exstart = $userexplainstart[0]["empirical"];
  736. $userexplainend && $exend = $userexplainend[0]["empirical"];
  737. $r1 = $exend-$exstart; // 等级经验值差
  738. $r2 = $userInfo["empirical"]-$exstart; // 当前等级与最低等级经验值差
  739. $r3 = $exend-$userInfo["empirical"]; // 还需多少经验值升级
  740. if($r1 == 0) {
  741. $res["level_rate"] = 1;
  742. } elseif($r2 == 0) {
  743. $res["level_rate"] = 0;
  744. if($res["level_start"] == $res["level_end"]) {
  745. $res["level_rate"] = 1;
  746. }
  747. } else {
  748. $res["level_rate"] = intval(($r2/$r1)*100)/100;
  749. }
  750. $res["to_up_need"] = $r3>0?$r3:0;
  751. // // 满级
  752. // if($r3 == 0 && !$userexplainend) {
  753. // $res["level_rate"] = 1;
  754. // }
  755. $this->success("获取成功!",$res);
  756. }
  757. }