Usercenter.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  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,a.createtime,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,a.createtime,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. $followlist[$k]['createtime_text'] = get_last_time($v['createtime']);
  236. if(in_array($v["user_id"],$ids)) {
  237. $followlist[$k]["is_hu"] = 1;
  238. } else {
  239. $followlist[$k]["is_hu"] = 0;
  240. }
  241. }
  242. }
  243. $fansfollow = $followlist;
  244. } else {
  245. $ids = [];
  246. if($followlist) {
  247. foreach($followlist as $k => $v) {
  248. $ids[] = $v["user_id"];
  249. }
  250. }
  251. if($fanslist) {
  252. foreach($fanslist as $k => $v) {
  253. $fanslist[$k]['createtime_text'] = get_last_time($v['createtime']);
  254. if(in_array($v["fans_id"],$ids)) {
  255. $fanslist[$k]["is_hu"] = 1;
  256. } else {
  257. $fanslist[$k]["is_hu"] = 0;
  258. }
  259. }
  260. }
  261. $fansfollow = $fanslist;
  262. }
  263. if($fansfollow) {
  264. $data = [];
  265. foreach($fansfollow as $k => $v) {
  266. if($k >= $pageStart && $k < $pageEnd) {
  267. $data[] = $v;
  268. }
  269. }
  270. $this->success("获取成功!",$data);
  271. } else {
  272. $this->success("数据为空!",[]);
  273. }
  274. }
  275. /**
  276. * 获取个人技能列表
  277. */
  278. public function getMySkillList() {
  279. $user_id = $this->request->request('user_id',0); // 用户ID
  280. $page = $this->request->request('page',1); // 分页
  281. $pageNum = $this->request->request('pageNum',10); // 分页
  282. if ($user_id == -1) {
  283. $user_id = $this->auth->id;
  284. } elseif($user_id>0) {
  285. $user_id = intval($user_id);
  286. } else {
  287. $this->error(__('Invalid parameters'));
  288. }
  289. // 分页搜索构建
  290. $pageStart = ($page-1)*$pageNum;
  291. $authModel = new \app\common\model\DispatchAuth();
  292. $where = [];
  293. $where["a.user_id"] = $user_id;
  294. $where["a.status"] = 1;
  295. $authskillList = $authModel->alias("a")
  296. ->field("a.id,ds.image,ds.name,a.voice,a.voice_time,a.price,a.is_main,ds.unit")
  297. ->join("hx_dispatch_skill ds","ds.id = a.skill_id")
  298. ->where($where)
  299. ->limit($pageStart,$pageNum)
  300. ->select();
  301. $this->success("获取成功!",$authskillList);
  302. }
  303. /**
  304. * 删除个人技能信息
  305. */
  306. public function delMySkillInfo() {
  307. $id = $this->request->request('id'); // 认证ID
  308. if (!$id) {
  309. $this->error(__('Invalid parameters'));
  310. }
  311. $authModel = new \app\common\model\DispatchAuth();
  312. $where = [];
  313. $where["id"] = $id;
  314. $where["user_id"] = $this->auth->id;
  315. $authInfo = $authModel->where($where)->find();
  316. if(!$authInfo) $this->error("技能认证未找到");
  317. // if($authInfo->is_main == 1) $this->error("请先取消主技能,再删除!");
  318. Db::startTrans();
  319. try{
  320. $res1 = $authInfo->delete();
  321. $res2 = \app\common\model\UserSkill::where(["user_id"=>$this->auth->id,"skill_id"=>$authInfo->skill_id])->delete();
  322. if($res1 && $res2) {
  323. Db::commit();
  324. $this->success("删除成功!");
  325. } else {
  326. $this->error("网络错误,请稍后重试!");
  327. }
  328. }catch (ValidateException $e) {
  329. Db::rollback();
  330. $this->error($e->getMessage());
  331. } catch (PDOException $e) {
  332. Db::rollback();
  333. $this->error($e->getMessage());
  334. } catch (Exception $e) {
  335. Db::rollback();
  336. $this->error($e->getMessage());
  337. }
  338. }
  339. /**
  340. * 修改个人技能信息
  341. */
  342. public function editMySkillInfo() {
  343. $price = $this->request->request('price'); // 价格
  344. $id = $this->request->request('id'); // 认证ID
  345. $is_main = $this->request->request('is_main'); // 是否设置为主技能
  346. if (!$id && !$price) {
  347. $this->error(__('Invalid parameters'));
  348. }
  349. $authModel = new \app\common\model\DispatchAuth();
  350. $where = [];
  351. $where["id"] = $id;
  352. if(!$authModel->where($where)->find()) $this->error("技能认证未找到");
  353. Db::startTrans();
  354. try{
  355. if($is_main == 1) {
  356. $where = [];
  357. $where["user_id"] = $this->auth->id;
  358. $authModel->update(["is_main"=>0],$where);
  359. }
  360. $where = [];
  361. $where["id"] = $id;
  362. $data = [];
  363. $data["price"] = $price;
  364. $data["is_main"] = $is_main;
  365. $res = $authModel->update($data,$where);
  366. $myAuthList = $authModel->where(["user_id"=>$this->auth->id,"is_main"=>1])->find();
  367. if(!$myAuthList) {
  368. $this->error("必须至少设置一个主技能");
  369. Db::rollback();
  370. }
  371. if($res) {
  372. Db::commit();
  373. $this->success("修改成功!",$data);
  374. } else {
  375. $this->error("网络错误,请稍后重试!");
  376. }
  377. }catch (ValidateException $e) {
  378. Db::rollback();
  379. $this->error($e->getMessage());
  380. } catch (PDOException $e) {
  381. Db::rollback();
  382. $this->error($e->getMessage());
  383. } catch (Exception $e) {
  384. Db::rollback();
  385. $this->error($e->getMessage());
  386. }
  387. }
  388. /**
  389. * 编辑个人信息
  390. */
  391. public function editUserInfo() {
  392. $avatar = $this->request->request('avatar'); // 头像
  393. $nickname = $this->request->request('nickname'); // 昵称
  394. $age = $this->request->request('age'); // 年龄
  395. $ageId = $this->request->request('age_id'); // 年龄段
  396. $gender = $this->request->request('gender'); // 性别 0=女,1=男
  397. $image = $this->request->request('image'); // 个人形象照
  398. $constellationId = $this->request->request('star_id'); //星座ID
  399. $provinceId = $this->request->request('province_id'); //省ID
  400. $cityId = $this->request->request('city_id'); //城市ID
  401. $desc = $this->request->request('desc'); //个性签名
  402. /*if (!$avatar && !$nickname && !$age && !$image && !in_array($gender,[0,1])) {
  403. $this->error(__('请输入要修改的信息'));
  404. }*/
  405. $where = [];
  406. $where["id"] = $this->auth->id;
  407. $data = [];
  408. $avatar && $data["avatar"] = $avatar;
  409. if($nickname){
  410. if (mb_strlen($nickname) > 8) {
  411. $this->error('用户昵称最多支持8个汉字或组合');
  412. }
  413. $data["nickname"] = $nickname;
  414. }
  415. $gender && $data["gender"] = $gender;
  416. $age && $data["age"] = $age;
  417. $image && $data["image"] = $image;
  418. $ageId && $data['age_id'] = $ageId;
  419. $constellationId && $data['constellation_id'] = $constellationId;
  420. $provinceId && $data['province_id'] = $provinceId;
  421. $cityId && $data['city_id'] = $cityId;
  422. $desc && $data['desc'] = $desc;
  423. $res = $this->userModel->update($data,$where);
  424. if($res) {
  425. $user = $this->userModel->where($where)->find();
  426. if (!empty($user['nickname']) && !empty($user['avatar']) && !empty($user['age_id']) && $user['has_info']==0) {
  427. $data['has_info'] = 1;
  428. $this->userModel->update($data,$where);
  429. }
  430. $this->success("修改成功!");
  431. } else {
  432. $this->error("网络错误,请稍后重试!");
  433. }
  434. }
  435. /**
  436. * 主播申请
  437. */
  438. public function anchorApply() {
  439. $type_id = $this->request->request('type_id'); // 技能分类ID
  440. $desc = $this->request->request('desc'); // 申请备注
  441. if (!$type_id && !$desc) {
  442. $this->error(__('Invalid parameters'));
  443. }
  444. $useranchorModel = new \app\common\model\UserAnchor();
  445. $data = [];
  446. $data["user_id"] = $this->auth->id;
  447. $data["type_id"] = $type_id;
  448. if($useranchorModel->where($data)->find()) $this->error(__('您已申请过该类型的主播,请勿重复申请!'));
  449. $data["desc"] = $desc;
  450. $data["createtime"] = time();
  451. $res = $useranchorModel->insertGetId($data);
  452. if($res) {
  453. \app\common\model\User::update(["is_anchor"=>1],["id"=>$this->auth->id]);
  454. $this->success("申请发送成功!");
  455. } else {
  456. $this->error("网络错误,请稍后重试");
  457. }
  458. }
  459. /**
  460. * 实名认证
  461. */
  462. public function authApply() {
  463. $realname = $this->request->request('realname'); // 真实姓名
  464. $idcard = $this->request->request('idcard'); // 身份证号
  465. $zimage = $this->request->request('zimage'); // 身份证正面照
  466. $fimage = $this->request->request('fimage'); // 身份证反面照
  467. if (!$realname && !$idcard && !$zimage && !$fimage) {
  468. $this->error(__('Invalid parameters'));
  469. }
  470. $userauthModel = new \app\common\model\UserAuth();
  471. $data = [];
  472. $data["user_id"] = $this->auth->id;
  473. //$data["idcard"] = $idcard;
  474. $userAuth = $userauthModel->where($data)->find();
  475. if (!empty($userAuth)) {
  476. if(in_array($userAuth['status'],[0,1])) $this->error('您已经申请过了,请勿重复操作!');
  477. }
  478. // 测试需要 开始
  479. $data["realname"] = $realname;
  480. $zimage && $data["zimage"] = $zimage;
  481. $fimage && $data["fimage"] = $fimage;
  482. $data["status"] = 1;
  483. if (!empty($userAuth)) {
  484. $data["updatetime"] = time();
  485. $authWhere['user_id'] = $this->auth->id;
  486. $res = $userauthModel->where($authWhere)->update($data);
  487. } else {
  488. $data["createtime"] = time();
  489. $res = $userauthModel->insertGetId($data);
  490. }
  491. if($res) {
  492. \app\common\model\User::update(["is_auth"=>2],["id"=>$this->auth->id]);
  493. $this->success("恭喜,实名认证成功!");
  494. } else {
  495. $this->error("网络错误,请稍后重试");
  496. }
  497. // 测试需要 结束
  498. // 实名认证验证
  499. $configInfo = config("auth");
  500. $outh = new outh($configInfo["api_url"],$configInfo["customer_code"],$configInfo["private_key"],$configInfo["key"]);
  501. $out_trade_no = date("YmdHis").rand(1000,9999);
  502. $ret = $outh->toVerify($out_trade_no,$realname,$idcard);
  503. if(isset($ret["code"])) {
  504. if($ret["code"] == "1008") {
  505. $this->error(__('身份证格式错误'));
  506. }
  507. if($ret["code"] == "1009") {
  508. $this->error(__('身份证格式错误'));
  509. }
  510. if($ret["code"] == "0001") {
  511. $this->error(__('姓名和身份证号不匹配!'));
  512. }
  513. if($ret["code"] == "0000") {
  514. $data["realname"] = $realname;
  515. $zimage && $data["zimage"] = $zimage;
  516. $fimage && $data["fimage"] = $fimage;
  517. $data["status"] = 1;
  518. $data["createtime"] = time();
  519. $res = $userauthModel->insertGetId($data);
  520. if($res) {
  521. \app\common\model\User::update(["is_auth"=>2],["id"=>$this->auth->id]);
  522. $this->success("恭喜,实名认证成功!");
  523. } else {
  524. $this->error("网络错误,请稍后重试");
  525. }
  526. }
  527. } else {
  528. $this->error("网络错误,请稍后重试");
  529. }
  530. }
  531. /**
  532. * 获取主播分类
  533. */
  534. public function getAnchorType() {
  535. $this->success("获取成功!",\app\common\model\UserAnchorType::select());
  536. }
  537. /**
  538. * 加入黑名单
  539. */
  540. public function addBlacklist() {
  541. $black_user_id = $this->request->request('black_user_id'); // 黑名单用户ID
  542. if (!$black_user_id) {
  543. $this->error(__('Invalid parameters'));
  544. }
  545. $userblacklistModel = new \app\common\model\UserBlacklist();
  546. $data = [];
  547. $data["user_id"] = $this->auth->id;
  548. $data["black_user_id"] = $black_user_id;
  549. if($userblacklistModel->where($data)->find()) $this->error(__('已在黑名单!'));
  550. $data["createtime"] = time();
  551. $res = $userblacklistModel->insertGetId($data);
  552. if($res) {
  553. $this->success("加入成功!");
  554. } else {
  555. $this->error("网络错误,请稍后重试");
  556. }
  557. }
  558. /**
  559. * 获取黑名单用户
  560. */
  561. public function getBlacklist() {
  562. $page = $this->request->request('page',1); // 分页
  563. $pageNum = $this->request->request('pageNum',10); // 分页
  564. // 分页搜索构建
  565. $pageStart = ($page-1)*$pageNum;
  566. $userblacklistModel = new \app\common\model\UserBlacklist();// ->limit($pageStart,$pageNum)
  567. $where = [];
  568. $where["a.user_id"] = $this->auth->id;
  569. $list = $userblacklistModel->alias("a")
  570. ->field("a.id,a.black_user_id,u.avatar,u.nickname,u.level,u.gender")
  571. ->join("hx_user u","u.id = a.black_user_id")
  572. ->where($where)
  573. ->limit($pageStart,$pageNum)
  574. ->select();
  575. if($list) {
  576. $this->success("获取成功!",$list);
  577. } else {
  578. $this->success("数据为空",[]);
  579. }
  580. }
  581. /**
  582. * 移除用户黑名单
  583. */
  584. public function removeUserBlack() {
  585. $id = $this->request->request('id'); // 黑名单ID
  586. if (!$id) {
  587. $this->error(__('Invalid parameters'));
  588. }
  589. $userblacklistModel = new \app\common\model\UserBlacklist();
  590. $where = [];
  591. $where["id"] = $id;
  592. $res = $userblacklistModel->where($where)->delete();
  593. if($res) {
  594. $this->success("移除成功!",$res);
  595. } else {
  596. $this->error("网络错误,请稍后重试!");
  597. }
  598. }
  599. /**
  600. * 举报用户
  601. */
  602. public function addReport() {
  603. $ruser_id = $this->request->request('ruser_id'); // 被举报用户ID
  604. $content = $this->request->request('content'); // 举报内容
  605. $image = $this->request->request('image'); // 图片描述(多个用半角逗号隔开)
  606. if (!$ruser_id) {
  607. $this->error(__('Invalid parameters'));
  608. }
  609. $userreportModel = new \app\common\model\UserReport();
  610. $data = [];
  611. $data["user_id"] = $this->auth->id;
  612. $data["reportable_id"] = $ruser_id;
  613. $data['reportable_type'] = $this->getModelName('user');
  614. $data["content"] = $content;
  615. $data["image"] = $image;
  616. $data["createtime"] = time();
  617. $res = $userreportModel->insertGetId($data);
  618. if($res) {
  619. $this->success("举报成功!");
  620. } else {
  621. $this->error("网络错误,请稍后重试");
  622. }
  623. }
  624. /**
  625. * 举报
  626. */
  627. public function addReportNew() {
  628. $params = $this->request->param();
  629. $validate = new Report();
  630. $result = $validate->check($params);
  631. if (!$result) {
  632. $this->error($validate->getError());
  633. }
  634. $userreportModel = new \app\common\model\UserReport();
  635. $data = [];
  636. $data["user_id"] = $this->auth->id;
  637. $data["reportable_id"] = $params['reportable_id'];
  638. $data['reportable_type'] = $this->getModelName($params['reportable_type']);
  639. $data["content"] = $params['content'];
  640. $data["image"] = $params['image'];
  641. $data["createtime"] = time();
  642. $res = $userreportModel->insertGetId($data);
  643. if($res) {
  644. $this->success("举报成功!");
  645. } else {
  646. $this->error("网络错误,请稍后重试");
  647. }
  648. }
  649. /**
  650. * redis 数据恢复---非redis数据丢失请勿使用!!!!
  651. */
  652. public function shujuhuifu() {
  653. $key = $this->request->request("key");// 操作验证 123456
  654. if($key != 123456) {
  655. $this->error(__('Invalid parameters'));
  656. }
  657. $giftuserpartyModel = new \app\common\model\GiftUserParty();
  658. $redis = new Redis();
  659. $redisconfig = config("redis");
  660. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  661. if ($redisconfig['redis_pwd']) {
  662. $redis->auth(config('redis_pwd'));
  663. }
  664. if($redisconfig['redis_selectdb'] > 0){
  665. $redis->select(config('redis_selectdb'));
  666. }
  667. // 获取本周第一天
  668. $weekday = $this->firstOfWeek(date("Y-m-d H:i:s"));
  669. // 获取本月第一天
  670. $monthday = date("Ym01");
  671. $where = [];
  672. $where["createtime"] = ["gt",strtotime($weekday)];
  673. $list1 = $giftuserpartyModel->where($where)->select();
  674. foreach($list1 as $k => $v) {
  675. // 添加redis记录做财富排行榜周榜用
  676. $redis->zIncrBy("jewel_get_".$v["party_id"].":".$weekday,$v["value"],$v["user_to_id"]);
  677. // 添加redis记录做贡献排行榜周榜用
  678. $redis->zIncrBy("jewel_to_".$v["party_id"].":".$weekday,$v["value"],$v["user_id"]);
  679. }
  680. $where = [];
  681. $where["createtime"] = ["gt",strtotime(date("Y-m-01"))];
  682. $list2 = $giftuserpartyModel->where($where)->select();
  683. foreach($list2 as $k => $v) {
  684. // 添加redis记录做财富排行榜月榜用
  685. $redis->zIncrBy("jewel_get_".$v["party_id"].":".$monthday,$v["value"],$v["user_to_id"]);
  686. // 添加redis记录做贡献排行榜月榜用
  687. $redis->zIncrBy("jewel_to_".$v["party_id"].":".$monthday,$v["value"],$v["user_id"]);
  688. }
  689. $this->success("执行成功!");
  690. }
  691. /**
  692. * 获取用户钻石余额
  693. */
  694. public function getUserJewel() {
  695. $data = \app\common\model\User::field("Jewel,money")->where(["id"=>$this->auth->id])->find();
  696. return $this->success("获取成功!",$data);
  697. }
  698. /**
  699. * 获取用户等级说明
  700. */
  701. public function getLevelExplain() {
  702. $data = \app\common\model\UserLevelExplain::field("title,content")->select();
  703. return $this->success("获取成功!",$data);
  704. }
  705. /**
  706. * 获取用户等级信息
  707. */
  708. public function getUserLevelInfo() {
  709. $res = [];$exstart = 0;$exend = 0;
  710. $userModel = new \app\common\model\User();
  711. $userInfo = $userModel->field("id,nickname,avatar,level,empirical")->where(["id"=>$this->auth->id])->find();
  712. if(!$userInfo) {
  713. $this->error("用户信息获取失败!");
  714. }
  715. $res["avatar"] = $userInfo['avatar'];
  716. $res["nickname"] = $userInfo['nickname'];
  717. // 获取用户当前经验值对应等级
  718. $userconfigModel = new \app\common\model\UserLevelConfig();
  719. $where = [];
  720. $where["empirical"] = ["elt",$userInfo["empirical"]];
  721. $userexplainstart = $userconfigModel->where($where)->order("empirical","desc")->limit(1)->select();
  722. $where = [];
  723. $where["empirical"] = ["gt",$userInfo["empirical"]];
  724. $userexplainend = $userconfigModel->where($where)->order("empirical","asc")->limit(1)->select();
  725. if(!$userexplainstart && !$userexplainend) {
  726. $this->error("经验等级信息获取失败!");
  727. } elseif(!$userexplainstart && $userexplainend) {
  728. $res["level_start"] = 0;
  729. $res["level_end"] = $userexplainend[0]["level"];
  730. } elseif($userexplainstart && !$userexplainend) {
  731. $res["level_start"] = $userexplainstart[0]["level"];
  732. $res["level_end"] = $userexplainstart[0]["level"];
  733. } elseif($userexplainstart && $userexplainend) {
  734. $res["level_start"] = $userexplainstart[0]["level"];
  735. $res["level_end"] = $userexplainend[0]["level"];
  736. }
  737. $userexplainstart && $exstart = $userexplainstart[0]["empirical"];
  738. $userexplainend && $exend = $userexplainend[0]["empirical"];
  739. $r1 = $exend-$exstart; // 等级经验值差
  740. $r2 = $userInfo["empirical"]-$exstart; // 当前等级与最低等级经验值差
  741. $r3 = $exend-$userInfo["empirical"]; // 还需多少经验值升级
  742. if($r1 == 0) {
  743. $res["level_rate"] = 1;
  744. } elseif($r2 == 0) {
  745. $res["level_rate"] = 0;
  746. if($res["level_start"] == $res["level_end"]) {
  747. $res["level_rate"] = 1;
  748. }
  749. } else {
  750. $res["level_rate"] = intval(($r2/$r1)*100)/100;
  751. }
  752. $res["to_up_need"] = $r3>0?$r3:0;
  753. // // 满级
  754. // if($r3 == 0 && !$userexplainend) {
  755. // $res["level_rate"] = 1;
  756. // }
  757. $this->success("获取成功!",$res);
  758. }
  759. }