Usercenter.php 35 KB

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