Usercenter.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  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. $gender = $this->request->request('gender'); // 性别 0=女,1=男
  394. $image = $this->request->request('image'); // 个人形象照
  395. if (!$avatar && !$nickname && !$age && !$image && !in_array($gender,[0,1])) {
  396. $this->error(__('请输入要修改的信息'));
  397. }
  398. $where = [];
  399. $where["id"] = $this->auth->id;
  400. $data = [];
  401. $avatar && $data["avatar"] = $avatar;
  402. if($nickname){
  403. if (mb_strlen($nickname) > 8) {
  404. $this->error('用户昵称最多支持8个汉字或组合');
  405. }
  406. $data["nickname"] = $nickname;
  407. }
  408. $gender && $data["gender"] = $gender;
  409. $age && $data["age"] = $age;
  410. $image && $data["image"] = $image;
  411. $data["has_info"] = 1;
  412. $res = $this->userModel->update($data,$where);
  413. if($res) {
  414. $this->success("修改成功!");
  415. } else {
  416. $this->error("网络错误,请稍后重试!");
  417. }
  418. }
  419. /**
  420. * 主播申请
  421. */
  422. public function anchorApply() {
  423. $type_id = $this->request->request('type_id'); // 技能分类ID
  424. $desc = $this->request->request('desc'); // 申请备注
  425. if (!$type_id && !$desc) {
  426. $this->error(__('Invalid parameters'));
  427. }
  428. $useranchorModel = new \app\common\model\UserAnchor();
  429. $data = [];
  430. $data["user_id"] = $this->auth->id;
  431. $data["type_id"] = $type_id;
  432. if($useranchorModel->where($data)->find()) $this->error(__('您已申请过该类型的主播,请勿重复申请!'));
  433. $data["desc"] = $desc;
  434. $data["createtime"] = time();
  435. $res = $useranchorModel->insertGetId($data);
  436. if($res) {
  437. \app\common\model\User::update(["is_anchor"=>1],["id"=>$this->auth->id]);
  438. $this->success("申请发送成功!");
  439. } else {
  440. $this->error("网络错误,请稍后重试");
  441. }
  442. }
  443. /**
  444. * 实名认证
  445. */
  446. public function authApply() {
  447. $realname = $this->request->request('realname'); // 真实姓名
  448. $idcard = $this->request->request('idcard'); // 身份证号
  449. $zimage = $this->request->request('zimage'); // 身份证正面照
  450. $fimage = $this->request->request('fimage'); // 身份证反面照
  451. if (!$realname && !$idcard && !$zimage && !$fimage) {
  452. $this->error(__('Invalid parameters'));
  453. }
  454. $userauthModel = new \app\common\model\UserAuth();
  455. $data = [];
  456. $data["user_id"] = $this->auth->id;
  457. //$data["idcard"] = $idcard;
  458. $userAuth = $userauthModel->where($data)->find();
  459. if (!empty($userAuth)) {
  460. if(in_array($userAuth['status'],[0,1])) $this->error('您已经申请过了,请勿重复操作!');
  461. }
  462. // 测试需要 开始
  463. $data["realname"] = $realname;
  464. $zimage && $data["zimage"] = $zimage;
  465. $fimage && $data["fimage"] = $fimage;
  466. $data["status"] = 1;
  467. if (!empty($userAuth)) {
  468. $data["updatetime"] = time();
  469. $authWhere['user_id'] = $this->auth->id;
  470. $res = $userauthModel->where($authWhere)->update($data);
  471. } else {
  472. $data["createtime"] = time();
  473. $res = $userauthModel->insertGetId($data);
  474. }
  475. if($res) {
  476. \app\common\model\User::update(["is_auth"=>2],["id"=>$this->auth->id]);
  477. $this->success("恭喜,实名认证成功!");
  478. } else {
  479. $this->error("网络错误,请稍后重试");
  480. }
  481. // 测试需要 结束
  482. // 实名认证验证
  483. $configInfo = config("auth");
  484. $outh = new outh($configInfo["api_url"],$configInfo["customer_code"],$configInfo["private_key"],$configInfo["key"]);
  485. $out_trade_no = date("YmdHis").rand(1000,9999);
  486. $ret = $outh->toVerify($out_trade_no,$realname,$idcard);
  487. if(isset($ret["code"])) {
  488. if($ret["code"] == "1008") {
  489. $this->error(__('身份证格式错误'));
  490. }
  491. if($ret["code"] == "1009") {
  492. $this->error(__('身份证格式错误'));
  493. }
  494. if($ret["code"] == "0001") {
  495. $this->error(__('姓名和身份证号不匹配!'));
  496. }
  497. if($ret["code"] == "0000") {
  498. $data["realname"] = $realname;
  499. $zimage && $data["zimage"] = $zimage;
  500. $fimage && $data["fimage"] = $fimage;
  501. $data["status"] = 1;
  502. $data["createtime"] = time();
  503. $res = $userauthModel->insertGetId($data);
  504. if($res) {
  505. \app\common\model\User::update(["is_auth"=>2],["id"=>$this->auth->id]);
  506. $this->success("恭喜,实名认证成功!");
  507. } else {
  508. $this->error("网络错误,请稍后重试");
  509. }
  510. }
  511. } else {
  512. $this->error("网络错误,请稍后重试");
  513. }
  514. }
  515. /**
  516. * 获取主播分类
  517. */
  518. public function getAnchorType() {
  519. $this->success("获取成功!",\app\common\model\UserAnchorType::select());
  520. }
  521. /**
  522. * 加入黑名单
  523. */
  524. public function addBlacklist() {
  525. $black_user_id = $this->request->request('black_user_id'); // 黑名单用户ID
  526. if (!$black_user_id) {
  527. $this->error(__('Invalid parameters'));
  528. }
  529. $userblacklistModel = new \app\common\model\UserBlacklist();
  530. $data = [];
  531. $data["user_id"] = $this->auth->id;
  532. $data["black_user_id"] = $black_user_id;
  533. if($userblacklistModel->where($data)->find()) $this->error(__('已在黑名单!'));
  534. $data["createtime"] = time();
  535. $res = $userblacklistModel->insertGetId($data);
  536. if($res) {
  537. $this->success("加入成功!");
  538. } else {
  539. $this->error("网络错误,请稍后重试");
  540. }
  541. }
  542. /**
  543. * 获取黑名单用户
  544. */
  545. public function getBlacklist() {
  546. $page = $this->request->request('page',1); // 分页
  547. $pageNum = $this->request->request('pageNum',10); // 分页
  548. // 分页搜索构建
  549. $pageStart = ($page-1)*$pageNum;
  550. $userblacklistModel = new \app\common\model\UserBlacklist();// ->limit($pageStart,$pageNum)
  551. $where = [];
  552. $where["a.user_id"] = $this->auth->id;
  553. $list = $userblacklistModel->alias("a")
  554. ->field("a.id,a.black_user_id,u.avatar,u.nickname,u.level,u.gender")
  555. ->join("hx_user u","u.id = a.black_user_id")
  556. ->where($where)
  557. ->limit($pageStart,$pageNum)
  558. ->select();
  559. if($list) {
  560. $this->success("获取成功!",$list);
  561. } else {
  562. $this->success("数据为空",[]);
  563. }
  564. }
  565. /**
  566. * 移除用户黑名单
  567. */
  568. public function removeUserBlack() {
  569. $id = $this->request->request('id'); // 黑名单ID
  570. if (!$id) {
  571. $this->error(__('Invalid parameters'));
  572. }
  573. $userblacklistModel = new \app\common\model\UserBlacklist();
  574. $where = [];
  575. $where["id"] = $id;
  576. $res = $userblacklistModel->where($where)->delete();
  577. if($res) {
  578. $this->success("移除成功!",$res);
  579. } else {
  580. $this->error("网络错误,请稍后重试!");
  581. }
  582. }
  583. /**
  584. * 举报用户
  585. */
  586. public function addReport() {
  587. $ruser_id = $this->request->request('ruser_id'); // 被举报用户ID
  588. $content = $this->request->request('content'); // 举报内容
  589. $image = $this->request->request('image'); // 图片描述(多个用半角逗号隔开)
  590. if (!$ruser_id) {
  591. $this->error(__('Invalid parameters'));
  592. }
  593. $userreportModel = new \app\common\model\UserReport();
  594. $data = [];
  595. $data["user_id"] = $this->auth->id;
  596. $data["reportable_id"] = $ruser_id;
  597. $data['reportable_type'] = $this->getModelName('user');
  598. $data["content"] = $content;
  599. $data["image"] = $image;
  600. $data["createtime"] = time();
  601. $res = $userreportModel->insertGetId($data);
  602. if($res) {
  603. $this->success("举报成功!");
  604. } else {
  605. $this->error("网络错误,请稍后重试");
  606. }
  607. }
  608. /**
  609. * 举报
  610. */
  611. public function addReportNew() {
  612. $params = $this->request->param();
  613. $validate = new Report();
  614. $result = $validate->check($params);
  615. if (!$result) {
  616. $this->error($validate->getError());
  617. }
  618. $userreportModel = new \app\common\model\UserReport();
  619. $data = [];
  620. $data["user_id"] = $this->auth->id;
  621. $data["reportable_id"] = $params['reportable_id'];
  622. $data['reportable_type'] = $this->getModelName($params['reportable_type']);
  623. $data["content"] = $params['content'];
  624. $data["image"] = $params['image'];
  625. $data["createtime"] = time();
  626. $res = $userreportModel->insertGetId($data);
  627. if($res) {
  628. $this->success("举报成功!");
  629. } else {
  630. $this->error("网络错误,请稍后重试");
  631. }
  632. }
  633. /**
  634. * redis 数据恢复---非redis数据丢失请勿使用!!!!
  635. */
  636. public function shujuhuifu() {
  637. $key = $this->request->request("key");// 操作验证 123456
  638. if($key != 123456) {
  639. $this->error(__('Invalid parameters'));
  640. }
  641. $giftuserpartyModel = new \app\common\model\GiftUserParty();
  642. $redis = new Redis();
  643. $redisconfig = config("redis");
  644. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  645. if ($redisconfig['redis_pwd']) {
  646. $redis->auth(config('redis_pwd'));
  647. }
  648. if($redisconfig['redis_selectdb'] > 0){
  649. $redis->select(config('redis_selectdb'));
  650. }
  651. // 获取本周第一天
  652. $weekday = $this->firstOfWeek(date("Y-m-d H:i:s"));
  653. // 获取本月第一天
  654. $monthday = date("Ym01");
  655. $where = [];
  656. $where["createtime"] = ["gt",strtotime($weekday)];
  657. $list1 = $giftuserpartyModel->where($where)->select();
  658. foreach($list1 as $k => $v) {
  659. // 添加redis记录做财富排行榜周榜用
  660. $redis->zIncrBy("jewel_get_".$v["party_id"].":".$weekday,$v["value"],$v["user_to_id"]);
  661. // 添加redis记录做贡献排行榜周榜用
  662. $redis->zIncrBy("jewel_to_".$v["party_id"].":".$weekday,$v["value"],$v["user_id"]);
  663. }
  664. $where = [];
  665. $where["createtime"] = ["gt",strtotime(date("Y-m-01"))];
  666. $list2 = $giftuserpartyModel->where($where)->select();
  667. foreach($list2 as $k => $v) {
  668. // 添加redis记录做财富排行榜月榜用
  669. $redis->zIncrBy("jewel_get_".$v["party_id"].":".$monthday,$v["value"],$v["user_to_id"]);
  670. // 添加redis记录做贡献排行榜月榜用
  671. $redis->zIncrBy("jewel_to_".$v["party_id"].":".$monthday,$v["value"],$v["user_id"]);
  672. }
  673. $this->success("执行成功!");
  674. }
  675. /**
  676. * 获取用户钻石余额
  677. */
  678. public function getUserJewel() {
  679. $data = \app\common\model\User::field("Jewel,money")->where(["id"=>$this->auth->id])->find();
  680. return $this->success("获取成功!",$data);
  681. }
  682. /**
  683. * 获取用户等级说明
  684. */
  685. public function getLevelExplain() {
  686. $data = \app\common\model\UserLevelExplain::field("title,content")->select();
  687. return $this->success("获取成功!",$data);
  688. }
  689. /**
  690. * 获取用户等级信息
  691. */
  692. public function getUserLevelInfo() {
  693. $res = [];$exstart = 0;$exend = 0;
  694. $userModel = new \app\common\model\User();
  695. $userInfo = $userModel->field("id,nickname,avatar,level,empirical")->where(["id"=>$this->auth->id])->find();
  696. if(!$userInfo) {
  697. $this->error("用户信息获取失败!");
  698. }
  699. $res["avatar"] = $userInfo['avatar'];
  700. $res["nickname"] = $userInfo['nickname'];
  701. // 获取用户当前经验值对应等级
  702. $userconfigModel = new \app\common\model\UserLevelConfig();
  703. $where = [];
  704. $where["empirical"] = ["elt",$userInfo["empirical"]];
  705. $userexplainstart = $userconfigModel->where($where)->order("empirical","desc")->limit(1)->select();
  706. $where = [];
  707. $where["empirical"] = ["gt",$userInfo["empirical"]];
  708. $userexplainend = $userconfigModel->where($where)->order("empirical","asc")->limit(1)->select();
  709. if(!$userexplainstart && !$userexplainend) {
  710. $this->error("经验等级信息获取失败!");
  711. } elseif(!$userexplainstart && $userexplainend) {
  712. $res["level_start"] = 0;
  713. $res["level_end"] = $userexplainend[0]["level"];
  714. } elseif($userexplainstart && !$userexplainend) {
  715. $res["level_start"] = $userexplainstart[0]["level"];
  716. $res["level_end"] = $userexplainstart[0]["level"];
  717. } elseif($userexplainstart && $userexplainend) {
  718. $res["level_start"] = $userexplainstart[0]["level"];
  719. $res["level_end"] = $userexplainend[0]["level"];
  720. }
  721. $userexplainstart && $exstart = $userexplainstart[0]["empirical"];
  722. $userexplainend && $exend = $userexplainend[0]["empirical"];
  723. $r1 = $exend-$exstart; // 等级经验值差
  724. $r2 = $userInfo["empirical"]-$exstart; // 当前等级与最低等级经验值差
  725. $r3 = $exend-$userInfo["empirical"]; // 还需多少经验值升级
  726. if($r1 == 0) {
  727. $res["level_rate"] = 1;
  728. } elseif($r2 == 0) {
  729. $res["level_rate"] = 0;
  730. if($res["level_start"] == $res["level_end"]) {
  731. $res["level_rate"] = 1;
  732. }
  733. } else {
  734. $res["level_rate"] = intval(($r2/$r1)*100)/100;
  735. }
  736. $res["to_up_need"] = $r3>0?$r3:0;
  737. // // 满级
  738. // if($r3 == 0 && !$userexplainend) {
  739. // $res["level_rate"] = 1;
  740. // }
  741. $this->success("获取成功!",$res);
  742. }
  743. }