Usercenter.php 33 KB

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