Usercenter.php 34 KB

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