Usercenter.php 34 KB

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