Usercenter.php 34 KB

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