Usercenter.php 35 KB

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