Usercenter.php 43 KB

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