Usercenter.php 37 KB

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