Usercenter.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098
  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. use think\Exception;
  12. /**
  13. * 会员中心接口
  14. */
  15. class UserCenter extends Common
  16. {
  17. protected $noNeedLogin = ['shujuhuifu','getAnchorType','getRecharConfig','getExchangeConfig','getLevelExplain'];
  18. protected $noNeedRight = '*';
  19. public function _initialize()
  20. {
  21. parent::_initialize();
  22. $this->userModel = new \app\common\model\User();
  23. }
  24. /**
  25. * 获取当前用户信息
  26. */
  27. public function getMyUserInfo() {
  28. $this->success("获取成功!",$this->auth->getUserinfo());
  29. }
  30. /**
  31. * 获取个人信息
  32. */
  33. public function getUserInfo() {
  34. $user_id = $this->request->request("user_id");
  35. if (!$user_id) {
  36. $this->error(__('Invalid parameters'));
  37. }
  38. // 获取基本信息
  39. $where = [];
  40. $where["id"] = $user_id;
  41. $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();
  42. // 获取技能信息
  43. $skillList = Model("ViewUserSkill")->getSkillInfo($user_id);
  44. $userInfo["skill"] = implode("/",$skillList);
  45. // 获取关注粉丝信息
  46. $followModel = new \app\common\model\ViewFollows();
  47. $fansModel = new \app\common\model\ViewFans();
  48. // 获取关注信息
  49. $where = [];
  50. $where["user_id"] = $user_id;
  51. $userCount = $followModel->where($where)->value("follows"); //该用户关注了几个人
  52. $userInfo["follows_count"] = $userCount?$userCount:0;
  53. // 获取粉丝数
  54. $where = [];
  55. $where["user_id"] = $user_id;
  56. $fansCount = $fansModel->where($where)->value("fans"); //该用户的粉丝数
  57. $userInfo["fans_count"] = $fansCount?$fansCount:0;
  58. // 获取贵族信息
  59. $nobleInfo = $this->userModel->getUserNobleInfo($user_id);
  60. // 查看者是否已关注
  61. $followid = \app\common\model\UserFansFollow::where(["fans_id"=>$this->auth->id,"user_id"=>$user_id])->value("id");
  62. $userInfo["is_follow"] = $followid>0?1:0;
  63. $userInfo = json_decode(json_encode($userInfo),true);
  64. $userInfo = array_merge($userInfo,$nobleInfo);
  65. // 获取用户在派对直播间情况信息
  66. $redis = new Redis();
  67. $redisconfig = config("redis");
  68. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  69. if ($redisconfig['redis_pwd']) {
  70. $redis->auth($redisconfig['redis_pwd']);
  71. }
  72. if($redisconfig['redis_selectdb'] > 0){
  73. $redis->select($redisconfig['redis_selectdb']);
  74. }
  75. $livingUserPartyId = $redis->hGet("livingUser", $user_id);
  76. $userInfo['party_info'] = json([]);
  77. if ($livingUserPartyId) {
  78. $party = \app\common\model\Party::where('id',$livingUserPartyId)->field('id,room_type')->find();
  79. $userInfo['party_info'] = ['party_id' => $party['id'], 'room_type' => $party['room_type']];
  80. }
  81. $blackWhere['user_id'] = $this->auth->id;
  82. $blackList = model('UserBlacklist')->where($blackWhere)->select();
  83. $blackIds = !empty($blackList) ? array_column($blackList,'black_user_id') : [];
  84. $userInfo['is_black'] = in_array($user_id,$blackIds) ? 1 : 0;
  85. $memberinfo = Db::name('guild_member')->alias('m')->field('guild.name,guild.image,guild.member,guild.desc')->join('guild','m.guild_id = guild.id','LEFT')->where(['m.user_id'=>$user_id,'m.status'=>1])->find();
  86. if ($memberinfo) {
  87. $userInfo['memberinfo'] = $memberinfo;
  88. }
  89. //家族信息
  90. $guildField = 'id,g_id,user_id,party_id,name,image,desc,member';
  91. $guildWhere['status'] = 1;
  92. $guildWhere['user_id'] = $user_id;
  93. $guildInfo = model('Guild')->field($guildField)->where($guildWhere)->find();
  94. $userInfo['guild_info'] = !empty($guildInfo) ? $guildInfo : [];
  95. //动态
  96. //技能
  97. //礼物
  98. //访客记录
  99. if ($this->auth->id != $user_id) {
  100. $visit_data = [
  101. 'user_id' => $this->auth->id,
  102. 'visit_user_id' => $user_id,
  103. ];
  104. $visit_check = Db::name('user_visitlist')->where($visit_data)->find();
  105. if(empty($visit_check)){
  106. $visit_data['updatetime'] = time();
  107. Db::name('user_visitlist')->insertGetId($visit_data);
  108. }else{
  109. Db::name('user_visitlist')->where('id',$visit_check['id'])->update(['updatetime'=>time()]);
  110. }
  111. }
  112. $this->success("获取成功!",$userInfo);
  113. }
  114. /**
  115. * 添加关注
  116. */
  117. public function addFollows() {
  118. $user_id = $this->request->request("user_id",0,"intval");// 被关注者ID
  119. $type = $this->request->request("type",1);// 类型:1=关注,2=取消关注
  120. if (!$user_id || $user_id<=0) {
  121. $this->error(__('Invalid parameters'));
  122. }
  123. if($type == 1) {
  124. if($user_id == $this->auth->id) {
  125. $this->error("不需要关注自己哦!");
  126. }
  127. $fansfollowModel = new \app\common\model\UserFansFollow();
  128. $data = [];
  129. $data["user_id"] = $user_id;
  130. $data["fans_id"] = $this->auth->id;
  131. if($fansfollowModel->where($data)->find()) {
  132. $this->error("你已经关注过ta啦!");
  133. }
  134. $data["createtime"] = time();
  135. $id = $fansfollowModel->insertGetId($data);
  136. //关注通知
  137. $msgdata = [
  138. 'user_id'=>$user_id,
  139. 'title' => '有人刚刚关注了你',
  140. 'content'=> '打开[消息][最新关注]即可查看',
  141. 'createtime' => time(),
  142. ];
  143. Db::name('message')->insertGetId($msgdata);
  144. if($id > 0) {
  145. // 增加任务进度 +exp
  146. \app\common\model\TaskLog::tofinish($this->auth->id,"ebxLwnXj3L",1);
  147. // 增加任务进度 +exp
  148. \app\common\model\TaskLog::tofinish($this->auth->id,"iA1QgRhL",1);
  149. // 增加任务进度 +exp
  150. \app\common\model\TaskLog::tofinish($this->auth->id,"ghopE4Ou",1);
  151. // 增加任务进度 +exp
  152. \app\common\model\TaskLog::tofinish($this->auth->id,"TryNGc1x",1);
  153. $this->success("关注成功!");
  154. } else {
  155. $this->error("网络错误,请稍后重试!");
  156. }
  157. } else {
  158. $fansfollowModel = new \app\common\model\UserFansFollow();
  159. $where = [];
  160. $where["user_id"] = $user_id;
  161. $where["fans_id"] = $this->auth->id;
  162. $fansfollowInfo = $fansfollowModel->where($where)->find();
  163. if(!$fansfollowInfo) {
  164. $this->error("关注信息获取失败!");
  165. }
  166. $res = $fansfollowModel->where($where)->delete();
  167. if($res > 0) {
  168. $this->success("取消成功!");
  169. } else {
  170. $this->error("网络错误,请稍后重试!");
  171. }
  172. }
  173. }
  174. /**
  175. * 是否关注
  176. */
  177. public function isFollows() {
  178. $user_id = $this->request->request("user_id",0,"intval");// 关注者ID
  179. if (!$user_id || $user_id<=0) {
  180. $this->error(__('Invalid parameters'));
  181. }
  182. $fansfollowModel = new \app\common\model\UserFansFollow();
  183. $where = [];
  184. $where["user_id"] = $user_id;
  185. $where["fans_id"] = $this->auth->id;
  186. $fansfollowInfo = $fansfollowModel->where($where)->find();
  187. $data = [];
  188. if($fansfollowInfo) {
  189. $data["is_show_follow"] = 0;
  190. } else {
  191. $data["is_show_follow"] = 1;
  192. }
  193. $this->success("获取成功!",$data);
  194. }
  195. /**
  196. * 获取关注人列表.派对信息
  197. */
  198. public function getFollowsLive() {
  199. $is_online = $this->request->request("is_online");// 是否在线:1=直播中,0=未开播
  200. $page = $this->request->request('page',1); // 分页
  201. $pageNum = $this->request->request('pageNum',10); // 分页
  202. // 分页搜索构建
  203. $pageStart = ($page-1)*$pageNum;
  204. $is_online == 1 || $is_online = 0;
  205. $fanfollowModel = new \app\common\model\UserFansFollow();
  206. $where = [];
  207. $where["a.fans_id"] = $this->auth->id;
  208. $where["p.room_type"] = 2;
  209. $where["p.is_online"] = $is_online;
  210. if($is_online == 1) {
  211. $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";
  212. } else {
  213. $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";
  214. }
  215. $list = $fanfollowModel->alias("a")
  216. ->field($field)
  217. ->join("hx_user u","u.id = a.user_id")
  218. ->join("hx_party p","p.user_id = a.user_id")
  219. ->join("hx_party_type t","t.id = p.party_type","left")
  220. ->limit($pageStart,$pageNum)
  221. ->where($where)->select();
  222. if($list) {
  223. foreach($list as $k => $v) {
  224. $mod = isset($v["party_type"])?intval($v["party_type"])%5:1;
  225. if(isset($v["type_name"]) && $v["type_name"]) {
  226. $type_name = $v["type_name"];
  227. } else {
  228. $type_name = "普通房";
  229. }
  230. $list[$k]["party_type"] = $type_name;
  231. $list[$k]["party_type_color"] = $mod == 0?5:$mod;
  232. }
  233. $this->success("获取成功!",$list);
  234. } else {
  235. $this->success("数据为空!",[]);
  236. }
  237. }
  238. /**
  239. * 获取关注列表
  240. * (个人中心模块)(消息-最新关注)
  241. */
  242. public function getFollowsUser() {
  243. $type = $this->request->request('type',1); // 1=关注,2=粉丝,3=好友
  244. $page = $this->request->request('page',1); // 分页
  245. $pageNum = $this->request->request('pageNum',10); // 分页
  246. // 分页搜索构建
  247. $pageStart = ($page-1)*$pageNum;
  248. $pageEnd = $pageStart + $pageNum;
  249. $fanfollowModel = new \app\common\model\UserFansFollow();
  250. // 获取关注列表
  251. $where = [];
  252. $where["a.fans_id"] = $this->auth->id;
  253. $followlist = $fanfollowModel->alias("a")
  254. ->field("a.id,a.user_id,a.createtime,u.avatar,u.nickname,u.level,u.gender,u.desc")
  255. ->join("hx_user u","u.id = a.user_id")
  256. // ->limit($pageStart,$pageNum)
  257. ->where($where)->order('a.id desc')->select();
  258. $followlist = list_domain_image($followlist,['avatar']);
  259. // 获取粉丝列表
  260. $where = [];
  261. $where["a.user_id"] = $this->auth->id;
  262. $fanslist = $fanfollowModel->alias("a")
  263. ->field("a.id,a.fans_id,a.createtime,u.avatar,u.nickname,u.level,u.gender,u.desc")
  264. ->join("hx_user u","u.id = a.fans_id")
  265. // ->limit($pageStart,$pageNum)
  266. ->where($where)->order('a.id desc')->select();
  267. $fanslist = list_domain_image($fanslist,['avatar']);
  268. // print_r(json_encode($followlist));exit;
  269. if($type == 1) {
  270. $ids = [];
  271. if($fanslist) {
  272. foreach($fanslist as $k => $v) {
  273. $ids[] = $v["fans_id"];
  274. }
  275. }
  276. if($followlist) {
  277. foreach($followlist as $k => $v) {
  278. $followlist[$k]['createtime_text'] = get_last_time($v['createtime']);
  279. $followlist[$k]["is_follow"] = 1;
  280. if(in_array($v["user_id"],$ids)) {
  281. $followlist[$k]["is_hu"] = 1;
  282. } else {
  283. $followlist[$k]["is_hu"] = 0;
  284. }
  285. }
  286. }
  287. $fansfollow = $followlist;
  288. } elseif($type == 2) {
  289. $ids = [];
  290. if($followlist) {
  291. foreach($followlist as $k => $v) {
  292. $ids[] = $v["user_id"];
  293. }
  294. }
  295. if($fanslist) {
  296. foreach($fanslist as $k => $v) {
  297. $fanslist[$k]['createtime_text'] = get_last_time($v['createtime']);
  298. if(in_array($v["fans_id"],$ids)) {
  299. $fanslist[$k]["is_hu"] = 1;
  300. $fanslist[$k]["is_follow"] = 1;
  301. } else {
  302. $fanslist[$k]["is_hu"] = 0;
  303. }
  304. }
  305. }
  306. $fansfollow = $fanslist;
  307. }else {
  308. $ids = [];
  309. if($followlist) {
  310. foreach($followlist as $k => $v) {
  311. $ids[] = $v["user_id"];
  312. }
  313. }
  314. if($fanslist) {
  315. foreach($fanslist as $k => $v) {
  316. $fanslist[$k]['createtime_text'] = get_last_time($v['createtime']);
  317. $fanslist[$k]["is_follow"] = 1;
  318. if(in_array($v["fans_id"],$ids)) {
  319. $fanslist[$k]["is_hu"] = 1;
  320. } else {
  321. unset($fanslist[$k]); //不是好友的 直接unset掉
  322. }
  323. }
  324. }
  325. $fansfollow = $fanslist;
  326. }
  327. if($fansfollow) {
  328. $data = [];
  329. foreach($fansfollow as $k => $v) {
  330. if($k >= $pageStart && $k < $pageEnd) {
  331. $data[] = $v;
  332. }
  333. }
  334. $this->success("获取成功!",$data);
  335. } else {
  336. $this->success("数据为空!",[]);
  337. }
  338. }
  339. /**
  340. * 获取最近访客
  341. * (消息)
  342. */
  343. public function getMyVisitList(){
  344. $list = Db::name('user_visitlist')->alias('uv')
  345. ->field('uv.user_id,uv.updatetime,user.id,user.nickname,user.avatar,user.gender,user.desc')
  346. ->join('user','uv.user_id = user.id','LEFT')
  347. ->where('uv.visit_user_id',$this->auth->id) //被访问者
  348. ->order('uv.id desc')->autopage()->select();
  349. $list = list_domain_image($list,['avatar']);
  350. if(!empty($list)){
  351. foreach($list as $key => &$val){
  352. //关注
  353. $val['is_follow'] = $this->is_follow($val['user_id'],$this->auth->id);
  354. }
  355. }
  356. $this->success(1,$list);
  357. }
  358. /**
  359. * 获取附近的人
  360. * (消息-同城)
  361. */
  362. public function getSamecityList(){
  363. if(!$this->auth->city_id){
  364. $this->success(1,[]);
  365. }
  366. $where = [
  367. 'status' => 'normal',
  368. 'city_id'=> $this->auth->city_id,
  369. ];
  370. //排除黑名单的
  371. $black_ids = Db::name('user_blacklist')->where('user_id',$this->auth->id)->column('black_user_id');
  372. if(!empty($black_ids)){
  373. $where['id'] = ['NOTIN',$black_ids];
  374. }
  375. $list = Db::name('user')->where($where)->where('id','neq',$this->auth->id)->field('id,nickname,avatar,gender,desc')->order('id desc')->autopage()->select();
  376. $list = list_domain_image($list,['avatar']);
  377. if(!empty($list)){
  378. foreach($list as $key => &$val){
  379. //关注
  380. $val['is_follow'] = $this->is_follow($val['id'],$this->auth->id);
  381. }
  382. }
  383. $this->success(1,$list);
  384. }
  385. //是否关注
  386. private function is_follow($user_id,$fans_id){
  387. $where = [
  388. 'user_id' => $user_id,
  389. 'fans_id' => $fans_id,
  390. ];
  391. $check = Db::name('user_fans_follow')->where($where)->find();
  392. if($check){
  393. return 1;
  394. }else{
  395. return 0;
  396. }
  397. }
  398. /**
  399. * 获取个人技能列表
  400. */
  401. public function getMySkillList() {
  402. $user_id = $this->request->request('user_id',0); // 用户ID
  403. $page = $this->request->request('page',1); // 分页
  404. $pageNum = $this->request->request('pageNum',10); // 分页
  405. if ($user_id == -1) {
  406. $user_id = $this->auth->id;
  407. } elseif($user_id>0) {
  408. $user_id = intval($user_id);
  409. } else {
  410. $this->error(__('Invalid parameters'));
  411. }
  412. // 分页搜索构建
  413. $pageStart = ($page-1)*$pageNum;
  414. $authModel = new \app\common\model\DispatchAuth();
  415. $where = [];
  416. $where["a.user_id"] = $user_id;
  417. $where["a.status"] = 1;
  418. $authskillList = $authModel->alias("a")
  419. ->field("a.id,ds.image,ds.name,a.voice,a.voice_time,a.price,a.is_main,ds.unit")
  420. ->join("hx_dispatch_skill ds","ds.id = a.skill_id")
  421. ->where($where)
  422. ->limit($pageStart,$pageNum)
  423. ->select();
  424. $this->success("获取成功!",$authskillList);
  425. }
  426. /**
  427. * 删除个人技能信息
  428. */
  429. public function delMySkillInfo() {
  430. $id = $this->request->request('id'); // 认证ID
  431. if (!$id) {
  432. $this->error(__('Invalid parameters'));
  433. }
  434. $authModel = new \app\common\model\DispatchAuth();
  435. $where = [];
  436. $where["id"] = $id;
  437. $where["user_id"] = $this->auth->id;
  438. $authInfo = $authModel->where($where)->find();
  439. if(!$authInfo) $this->error("技能认证未找到");
  440. // if($authInfo->is_main == 1) $this->error("请先取消主技能,再删除!");
  441. Db::startTrans();
  442. try{
  443. $res1 = $authInfo->delete();
  444. $res2 = \app\common\model\UserSkill::where(["user_id"=>$this->auth->id,"skill_id"=>$authInfo->skill_id])->delete();
  445. if($res1 && $res2) {
  446. Db::commit();
  447. $this->success("删除成功!");
  448. } else {
  449. $this->error("网络错误,请稍后重试!");
  450. }
  451. }catch (ValidateException $e) {
  452. Db::rollback();
  453. $this->error($e->getMessage());
  454. } catch (PDOException $e) {
  455. Db::rollback();
  456. $this->error($e->getMessage());
  457. } catch (Exception $e) {
  458. Db::rollback();
  459. $this->error($e->getMessage());
  460. }
  461. }
  462. /**
  463. * 修改个人技能信息
  464. */
  465. public function editMySkillInfo() {
  466. $price = $this->request->request('price'); // 价格
  467. $id = $this->request->request('id'); // 认证ID
  468. $is_main = $this->request->request('is_main'); // 是否设置为主技能
  469. if (!$id && !$price) {
  470. $this->error(__('Invalid parameters'));
  471. }
  472. $authModel = new \app\common\model\DispatchAuth();
  473. $where = [];
  474. $where["id"] = $id;
  475. if(!$authModel->where($where)->find()) $this->error("技能认证未找到");
  476. Db::startTrans();
  477. try{
  478. if($is_main == 1) {
  479. $where = [];
  480. $where["user_id"] = $this->auth->id;
  481. $authModel->update(["is_main"=>0],$where);
  482. }
  483. $where = [];
  484. $where["id"] = $id;
  485. $data = [];
  486. $data["price"] = $price;
  487. $data["is_main"] = $is_main;
  488. $res = $authModel->update($data,$where);
  489. $myAuthList = $authModel->where(["user_id"=>$this->auth->id,"is_main"=>1])->find();
  490. if(!$myAuthList) {
  491. $this->error("必须至少设置一个主技能");
  492. Db::rollback();
  493. }
  494. if($res) {
  495. Db::commit();
  496. $this->success("修改成功!",$data);
  497. } else {
  498. $this->error("网络错误,请稍后重试!");
  499. }
  500. }catch (ValidateException $e) {
  501. Db::rollback();
  502. $this->error($e->getMessage());
  503. } catch (PDOException $e) {
  504. Db::rollback();
  505. $this->error($e->getMessage());
  506. } catch (Exception $e) {
  507. Db::rollback();
  508. $this->error($e->getMessage());
  509. }
  510. }
  511. /**
  512. * 编辑个人信息
  513. */
  514. public function editUserInfo() {
  515. $avatar = $this->request->request('avatar'); // 头像
  516. $nickname = $this->request->request('nickname'); // 昵称
  517. $age = $this->request->request('age'); // 年龄
  518. $ageId = $this->request->request('age_id'); // 年龄段
  519. $gender = $this->request->request('gender'); // 性别 0=女,1=男
  520. $image = $this->request->request('image'); // 个人形象照
  521. $constellationId = $this->request->request('star_id'); //星座ID
  522. $provinceId = $this->request->request('province_id'); //省ID
  523. $cityId = $this->request->request('city_id'); //城市ID
  524. $desc = $this->request->request('desc'); //个性签名
  525. /*if (!$avatar && !$nickname && !$age && !$image && !in_array($gender,[0,1])) {
  526. $this->error(__('请输入要修改的信息'));
  527. }*/
  528. $where = [];
  529. $where["id"] = $this->auth->id;
  530. $data = [];
  531. $avatar && $data["avatar"] = $avatar;
  532. if($nickname){
  533. if (mb_strlen($nickname) > 8) {
  534. $this->error('用户昵称最多支持8个汉字或组合');
  535. }
  536. $data["nickname"] = $nickname;
  537. }
  538. $gender && $data["gender"] = $gender;
  539. $age && $data["age"] = $age;
  540. $image && $data["image"] = $image;
  541. $ageId && $data['age_id'] = $ageId;
  542. $constellationId && $data['constellation_id'] = $constellationId;
  543. $provinceId && $data['province_id'] = $provinceId;
  544. $cityId && $data['city_id'] = $cityId;
  545. $desc && $data['desc'] = $desc;
  546. $res = $this->userModel->update($data,$where);
  547. if($res) {
  548. $user = $this->userModel->where($where)->find();
  549. if (!empty($user['nickname']) && !empty($user['avatar']) && !empty($user['age_id']) && $user['has_info']==0) {
  550. $data['has_info'] = 1;
  551. $this->userModel->update($data,$where);
  552. }
  553. $this->success("修改成功!");
  554. } else {
  555. $this->error("网络错误,请稍后重试!");
  556. }
  557. }
  558. /**
  559. * 主播申请
  560. */
  561. public function anchorApply() {
  562. $type_id = $this->request->request('type_id',0); // 技能分类ID
  563. $party_type_id = $this->request->request('party_type_id'); //分类ID
  564. $desc = $this->request->request('desc'); // 申请备注
  565. if (!$party_type_id && !$desc) {
  566. $this->error(__('Invalid parameters'));
  567. }
  568. $useranchorModel = new \app\common\model\UserAnchor();
  569. $data = [];
  570. $data["user_id"] = $this->auth->id;
  571. $data["type_id"] = $type_id;
  572. $data["party_type_id"] = $party_type_id;
  573. if($useranchorModel->where($data)->find()) $this->error(__('您已申请过该类型的主播,请勿重复申请!'));
  574. $data["desc"] = $desc;
  575. $data["createtime"] = time();
  576. $res = $useranchorModel->insertGetId($data);
  577. if($res) {
  578. \app\common\model\User::update(["is_anchor"=>1],["id"=>$this->auth->id]);
  579. $this->success("申请发送成功!");
  580. } else {
  581. $this->error("网络错误,请稍后重试");
  582. }
  583. }
  584. /**
  585. * 实名认证
  586. */
  587. public function authApply() {
  588. $realname = $this->request->request('realname'); // 真实姓名
  589. $idcard = $this->request->request('idcard'); // 身份证号
  590. $zimage = $this->request->request('zimage'); // 身份证正面照
  591. $fimage = $this->request->request('fimage'); // 身份证反面照
  592. if (!$realname && !$idcard && !$zimage && !$fimage) {
  593. $this->error(__('Invalid parameters'));
  594. }
  595. $userauthModel = new \app\common\model\UserAuth();
  596. $data = [];
  597. $data["user_id"] = $this->auth->id;
  598. //$data["idcard"] = $idcard;
  599. $userAuth = $userauthModel->where($data)->find();
  600. if (!empty($userAuth)) {
  601. if(in_array($userAuth['status'],[0,1])) $this->error('您已经申请过了,请勿重复操作!');
  602. }
  603. // 测试需要 开始
  604. $data["realname"] = $realname;
  605. $zimage && $data["zimage"] = $zimage;
  606. $fimage && $data["fimage"] = $fimage;
  607. $data["status"] = 1;
  608. if (!empty($userAuth)) {
  609. $data["updatetime"] = time();
  610. $authWhere['user_id'] = $this->auth->id;
  611. $res = $userauthModel->where($authWhere)->update($data);
  612. } else {
  613. $data["createtime"] = time();
  614. $res = $userauthModel->insertGetId($data);
  615. }
  616. if($res) {
  617. \app\common\model\User::update(["is_auth"=>2],["id"=>$this->auth->id]);
  618. $this->success("恭喜,实名认证成功!");
  619. } else {
  620. $this->error("网络错误,请稍后重试");
  621. }
  622. // 测试需要 结束
  623. // 实名认证验证
  624. $configInfo = config("auth");
  625. $outh = new outh($configInfo["api_url"],$configInfo["customer_code"],$configInfo["private_key"],$configInfo["key"]);
  626. $out_trade_no = date("YmdHis").rand(1000,9999);
  627. $ret = $outh->toVerify($out_trade_no,$realname,$idcard);
  628. if(isset($ret["code"])) {
  629. if($ret["code"] == "1008") {
  630. $this->error(__('身份证格式错误'));
  631. }
  632. if($ret["code"] == "1009") {
  633. $this->error(__('身份证格式错误'));
  634. }
  635. if($ret["code"] == "0001") {
  636. $this->error(__('姓名和身份证号不匹配!'));
  637. }
  638. if($ret["code"] == "0000") {
  639. $data["realname"] = $realname;
  640. $zimage && $data["zimage"] = $zimage;
  641. $fimage && $data["fimage"] = $fimage;
  642. $data["status"] = 1;
  643. $data["createtime"] = time();
  644. $res = $userauthModel->insertGetId($data);
  645. if($res) {
  646. \app\common\model\User::update(["is_auth"=>2],["id"=>$this->auth->id]);
  647. $this->success("恭喜,实名认证成功!");
  648. } else {
  649. $this->error("网络错误,请稍后重试");
  650. }
  651. }
  652. } else {
  653. $this->error("网络错误,请稍后重试");
  654. }
  655. }
  656. /**
  657. * 获取主播分类
  658. */
  659. public function getAnchorType() {
  660. $this->success("获取成功!",\app\common\model\UserAnchorType::select());
  661. }
  662. /**
  663. * 加入黑名单
  664. */
  665. public function addBlacklist() {
  666. $black_user_id = $this->request->request('black_user_id'); // 黑名单用户ID
  667. if (!$black_user_id) {
  668. $this->error(__('Invalid parameters'));
  669. }
  670. $userblacklistModel = new \app\common\model\UserBlacklist();
  671. $data = [];
  672. $data["user_id"] = $this->auth->id;
  673. $data["black_user_id"] = $black_user_id;
  674. if($userblacklistModel->where($data)->find()) $this->error(__('已在黑名单!'));
  675. $data["createtime"] = time();
  676. $res = $userblacklistModel->insertGetId($data);
  677. if($res) {
  678. $this->success("加入成功!");
  679. } else {
  680. $this->error("网络错误,请稍后重试");
  681. }
  682. }
  683. /**
  684. * 获取黑名单用户
  685. */
  686. public function getBlacklist() {
  687. $page = $this->request->request('page',1); // 分页
  688. $pageNum = $this->request->request('pageNum',10); // 分页
  689. // 分页搜索构建
  690. $pageStart = ($page-1)*$pageNum;
  691. $userblacklistModel = new \app\common\model\UserBlacklist();// ->limit($pageStart,$pageNum)
  692. $where = [];
  693. $where["a.user_id"] = $this->auth->id;
  694. $list = $userblacklistModel->alias("a")
  695. ->field("a.id,a.black_user_id,u.avatar,u.nickname,u.level,u.gender")
  696. ->join("hx_user u","u.id = a.black_user_id")
  697. ->where($where)
  698. ->limit($pageStart,$pageNum)
  699. ->select();
  700. if($list) {
  701. $this->success("获取成功!",$list);
  702. } else {
  703. $this->success("数据为空",[]);
  704. }
  705. }
  706. /**
  707. * 移除用户黑名单
  708. */
  709. public function removeUserBlack() {
  710. $id = $this->request->request('id'); // 黑名单ID
  711. $userId = $this->request->request('user_id'); // 用户ID
  712. if (!$id && !$userId) {
  713. $this->error(__('Invalid parameters'));
  714. }
  715. $userblacklistModel = new \app\common\model\UserBlacklist();
  716. $where = [];
  717. $id && $where["id"] = $id;
  718. if ($userId) {
  719. $where['user_id'] = $this->auth->id;
  720. $where['black_user_id'] = $userId;
  721. }
  722. $res = false;
  723. if (!empty($where)) {
  724. $res = $userblacklistModel->where($where)->delete();
  725. }
  726. if($res) {
  727. $this->success("移除成功!",$res);
  728. } else {
  729. $this->error("网络错误,请稍后重试!");
  730. }
  731. }
  732. /**
  733. * 举报用户
  734. */
  735. /*public function addReport() {
  736. $ruser_id = $this->request->request('ruser_id'); // 被举报用户ID
  737. $content = $this->request->request('content'); // 举报内容
  738. $image = $this->request->request('image'); // 图片描述(多个用半角逗号隔开)
  739. if (!$ruser_id) {
  740. $this->error(__('Invalid parameters'));
  741. }
  742. $userreportModel = new \app\common\model\UserReport();
  743. $data = [];
  744. $data["user_id"] = $this->auth->id;
  745. $data["reportable_id"] = $ruser_id;
  746. $data['reportable_type'] = $this->getModelName('user');
  747. $data["content"] = $content;
  748. $data["image"] = $image;
  749. $data["createtime"] = time();
  750. $res = $userreportModel->insertGetId($data);
  751. if($res) {
  752. $this->success("举报成功!");
  753. } else {
  754. $this->error("网络错误,请稍后重试");
  755. }
  756. }*/
  757. /**
  758. * 举报
  759. */
  760. /*public function addReportNew() {
  761. $params = $this->request->param();
  762. $validate = new Report();
  763. $result = $validate->check($params);
  764. if (!$result) {
  765. $this->error($validate->getError());
  766. }
  767. $userreportModel = new \app\common\model\UserReport();
  768. $data = [];
  769. $data["user_id"] = $this->auth->id;
  770. $data["reportable_id"] = $params['reportable_id'];
  771. $data['reportable_type'] = $this->getModelName($params['reportable_type']);
  772. $data["content"] = $params['content'];
  773. $data["image"] = $params['image'];
  774. $data["createtime"] = time();
  775. $res = $userreportModel->insertGetId($data);
  776. if($res) {
  777. $this->success("举报成功!");
  778. } else {
  779. $this->error("网络错误,请稍后重试");
  780. }
  781. }*/
  782. /**
  783. * redis 数据恢复---非redis数据丢失请勿使用!!!!
  784. */
  785. public function shujuhuifu() {
  786. $key = $this->request->request("key");// 操作验证 123456
  787. if($key != 123456) {
  788. $this->error(__('Invalid parameters'));
  789. }
  790. $giftuserpartyModel = new \app\common\model\GiftUserParty();
  791. $redis = new Redis();
  792. $redisconfig = config("redis");
  793. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  794. if ($redisconfig['redis_pwd']) {
  795. $redis->auth($redisconfig['redis_pwd']);
  796. }
  797. if($redisconfig['redis_selectdb'] > 0){
  798. $redis->select($redisconfig['redis_selectdb']);
  799. }
  800. // 获取本周第一天
  801. $weekday = $this->firstOfWeek(date("Y-m-d H:i:s"));
  802. // 获取本月第一天
  803. $monthday = date("Ym01");
  804. $where = [];
  805. $where["createtime"] = ["gt",strtotime($weekday)];
  806. $list1 = $giftuserpartyModel->where($where)->select();
  807. foreach($list1 as $k => $v) {
  808. // 添加redis记录做财富排行榜周榜用
  809. $redis->zIncrBy("jewel_get_".$v["party_id"].":".$weekday,$v["value"],$v["user_to_id"]);
  810. // 添加redis记录做贡献排行榜周榜用
  811. $redis->zIncrBy("jewel_to_".$v["party_id"].":".$weekday,$v["value"],$v["user_id"]);
  812. }
  813. $where = [];
  814. $where["createtime"] = ["gt",strtotime(date("Y-m-01"))];
  815. $list2 = $giftuserpartyModel->where($where)->select();
  816. foreach($list2 as $k => $v) {
  817. // 添加redis记录做财富排行榜月榜用
  818. $redis->zIncrBy("jewel_get_".$v["party_id"].":".$monthday,$v["value"],$v["user_to_id"]);
  819. // 添加redis记录做贡献排行榜月榜用
  820. $redis->zIncrBy("jewel_to_".$v["party_id"].":".$monthday,$v["value"],$v["user_id"]);
  821. }
  822. $this->success("执行成功!");
  823. }
  824. /**
  825. * 获取用户钻石余额
  826. */
  827. public function getUserJewel() {
  828. $data = \app\common\model\User::field("Jewel,money")->where(["id"=>$this->auth->id])->find();
  829. return $this->success("获取成功!",$data);
  830. }
  831. /**
  832. * 获取用户等级说明
  833. */
  834. public function getLevelExplain() {
  835. $data = \app\common\model\UserLevelExplain::field("title,content")->select();
  836. return $this->success("获取成功!",$data);
  837. }
  838. /**
  839. * 获取用户等级信息
  840. */
  841. public function getUserLevelInfo() {
  842. $res = [];$exstart = 0;$exend = 0;
  843. $userModel = new \app\common\model\User();
  844. $userInfo = $userModel->field("id,nickname,avatar,level,empirical")->where(["id"=>$this->auth->id])->find();
  845. if(!$userInfo) {
  846. $this->error("用户信息获取失败!");
  847. }
  848. $res["avatar"] = $userInfo['avatar'];
  849. $res["nickname"] = $userInfo['nickname'];
  850. // 获取用户当前经验值对应等级
  851. $userconfigModel = new \app\common\model\UserLevelConfig();
  852. $where = [];
  853. $where["empirical"] = ["elt",$userInfo["empirical"]];
  854. $userexplainstart = $userconfigModel->where($where)->order("empirical","desc")->limit(1)->select();
  855. $where = [];
  856. $where["empirical"] = ["gt",$userInfo["empirical"]];
  857. $userexplainend = $userconfigModel->where($where)->order("empirical","asc")->limit(1)->select();
  858. if(!$userexplainstart && !$userexplainend) {
  859. $this->error("经验等级信息获取失败!");
  860. } elseif(!$userexplainstart && $userexplainend) {
  861. $res["level_start"] = 0;
  862. $res["level_end"] = $userexplainend[0]["level"];
  863. } elseif($userexplainstart && !$userexplainend) {
  864. $res["level_start"] = $userexplainstart[0]["level"];
  865. $res["level_end"] = $userexplainstart[0]["level"];
  866. } elseif($userexplainstart && $userexplainend) {
  867. $res["level_start"] = $userexplainstart[0]["level"];
  868. $res["level_end"] = $userexplainend[0]["level"];
  869. }
  870. $userexplainstart && $exstart = $userexplainstart[0]["empirical"];
  871. $userexplainend && $exend = $userexplainend[0]["empirical"];
  872. $r1 = $exend-$exstart; // 等级经验值差
  873. $r2 = $userInfo["empirical"]-$exstart; // 当前等级与最低等级经验值差
  874. $r3 = $exend-$userInfo["empirical"]; // 还需多少经验值升级
  875. if($r1 == 0) {
  876. $res["level_rate"] = 1;
  877. } elseif($r2 == 0) {
  878. $res["level_rate"] = 0;
  879. if($res["level_start"] == $res["level_end"]) {
  880. $res["level_rate"] = 1;
  881. }
  882. } else {
  883. $res["level_rate"] = intval(($r2/$r1)*100)/100;
  884. }
  885. $res["to_up_need"] = $r3>0?$r3:0;
  886. // // 满级
  887. // if($r3 == 0 && !$userexplainend) {
  888. // $res["level_rate"] = 1;
  889. // }
  890. $this->success("获取成功!",$res);
  891. }
  892. /**
  893. * 邀请
  894. * @return void
  895. */
  896. public function addInvite()
  897. {
  898. try {
  899. $inviteNo = $this->request->param('invite_no','');
  900. $userId = $this->auth->id;
  901. if (empty($inviteNo)) {
  902. throw new Exception('参数错误');
  903. }
  904. $where['invite_no'] = $inviteNo;
  905. $userField = 'id,invite_no';
  906. $user = model('User')->field($userField)->where($where)->find();
  907. if (empty($user)) {
  908. throw new Exception('无效的邀请码');
  909. }
  910. $userInviteWhere['invite_user_id'] = $userId;
  911. $userInvite = model('UserInvite')->where($userInviteWhere)->find();
  912. if (!empty($userInvite)) {
  913. throw new Exception('您已经被邀请过');
  914. }
  915. $userInviteData = [
  916. 'user_id' => $user['id'],
  917. 'invite_user_id' => $userId,
  918. 'createtime' => time(),
  919. ];
  920. $userInviteRes = model('UserInvite')->insertGetId($userInviteData);
  921. if (!$userInviteRes) {
  922. throw new Exception('邀请失败');
  923. }
  924. $userUpWhere['id'] = $userId;
  925. $userUpdate = ['pre_userid'=>$user['id']];
  926. $userUpdateRes = model('User')->where($userUpWhere)->update($userUpdate);
  927. if (!$userUpdateRes) {
  928. throw new Exception('更新邀请人失败');
  929. }
  930. $this->success('邀请成功');
  931. } catch (Exception $e) {
  932. $this->error($e->getMessage());
  933. }
  934. }
  935. /**
  936. * 邀请详情
  937. * @return void
  938. */
  939. public function inviteInfo()
  940. {
  941. try {
  942. $userId = $this->auth->id;
  943. $field = 'id,invite_no';
  944. $where['id'] = $userId;
  945. $user = model('User')->field($field)->where($where)->find();
  946. $inviteNo = isset($user['invite_no']) ? $user['invite_no'] : '';
  947. $todayNow = day_now();
  948. $todayStart = $todayNow[0];
  949. $todayEnd = $todayNow[1]+1;
  950. $userMoneyLogWhere['user_id'] = $userId;
  951. $userMoneyLogWhere['type'] = 15;
  952. $appendWhere['createtime'] = [['egt', $todayStart],['lt', $todayEnd],'and'];
  953. $todayMoney = model('UserMoneyLog')->where($userMoneyLogWhere)->where($appendWhere)->sum('value');
  954. $totalMoney = model('UserMoneyLog')->where($userMoneyLogWhere)->sum('value');
  955. //本周
  956. $weekNow = week_now();
  957. $userInviteWhere['user_id'] = $userId;
  958. $userInviteAppendWhere['createtime'] = [['egt', $weekNow[0]],['lt', $weekNow[1]+1],'and'];
  959. $userInviteModel = model('UserInvite');
  960. $weekNowNum = $userInviteModel->where($userInviteWhere)->where($userInviteAppendWhere)->count();
  961. //上周
  962. $lastWeek = last_week();
  963. $appendLastWhere['createtime'] = [['egt', $lastWeek[0]],['lt', $lastWeek[1]+1],'and'];
  964. $lastWeekNum = $userInviteModel->where($userInviteWhere)->where($appendLastWhere)->count();
  965. //全部
  966. $totalNum = $userInviteModel->where($userInviteWhere)->count();
  967. $result = [
  968. 'invite_no' => $inviteNo,//邀请码
  969. 'today_money' => $todayMoney,//今日收益
  970. 'total_money' => $totalMoney,//总收益
  971. 'week_now_num' => $weekNowNum,//本周邀请数
  972. 'last_week_num' => $lastWeekNum,//上周邀请数
  973. 'total_num' => $totalNum,//总邀请数
  974. ];
  975. $this->success('获取成功',$result);
  976. } catch (Exception $e) {
  977. $this->error($e->getMessage());
  978. }
  979. }
  980. /**
  981. * 邀请列表
  982. * @return void
  983. */
  984. public function inviteList()
  985. {
  986. try {
  987. $userId = $this->auth->id;
  988. $where['user_id'] = $userId;
  989. $userInvite = model('UserInvite')->where($where)->with(['user'=>function($uQuery){
  990. $uQuery->field('id,avatar,u_id,nickname');
  991. }])->autopage()->order('createtime desc')->select();
  992. $result = [];
  993. if (!empty($userInvite)) {
  994. foreach ($userInvite as $key => $value) {
  995. $user = isset($value['user']) ? $value['user'] : [];
  996. $temp = [
  997. 'user_id' => isset($user['id']) ? $user['id'] : 0,
  998. 'u_id' => isset($user['u_id']) ? $user['u_id'] : 0,
  999. 'avatar' => isset($user['avatar']) ? $user['avatar'] : 0,
  1000. 'nickname' => isset($user['nickname']) ? $user['nickname'] : 0,
  1001. 'create_time_text' => !empty($value['createtime']) ? date('Y-m-d', $value['createtime']) : '',
  1002. ];
  1003. $result[] = $temp;
  1004. }
  1005. }
  1006. $this->success('获取成功',$result);
  1007. } catch (Exception $e) {
  1008. $this->error($e->getMessage());
  1009. }
  1010. }
  1011. }