Usercenter.php 33 KB

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