Usercenter.php 33 KB

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