Usercenter.php 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397
  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 app\common\model\UserPower;
  7. use app\common\service\TenimService;
  8. use outh\outh;
  9. use think\Db;
  10. use app\common\controller\RedisLeaderboard;
  11. use Redis;
  12. use GatewayClient\Gateway;
  13. use think\Exception;
  14. /**
  15. * 会员中心接口
  16. */
  17. class UserCenter extends Common
  18. {
  19. protected $noNeedLogin = ['shujuhuifu','getAnchorType','getRecharConfig','getExchangeConfig','getLevelExplain'];
  20. protected $noNeedRight = '*';
  21. public function _initialize()
  22. {
  23. parent::_initialize();
  24. $this->userModel = new \app\common\model\User();
  25. }
  26. /**
  27. * 获取当前用户信息
  28. */
  29. public function getMyUserInfo() {
  30. $this->success("获取成功!",$this->auth->getUserinfo());
  31. }
  32. /**
  33. * 获取个人信息
  34. */
  35. public function getUserInfo() {
  36. $user_id = $this->request->param("user_id");
  37. if (!$user_id) {
  38. $this->error(__('Invalid parameters'));
  39. }
  40. // 获取基本信息
  41. $where = [];
  42. $where["id"] = $user_id;
  43. $userInfo = $this->userModel->field("id,nickname,pre_nickname,image,mobile,avatar,pre_avatar,gender,money,age,u_id,level,jewel,
  44. age_id,constellation_id,province_id,city_id,desc,ipaddress,is_cool,is_manager,is_stealth")->where($where)->find();
  45. $userInfo['nickname_status'] = $userInfo['avatar_status'] = 0;
  46. if (!empty($userInfo['pre_nickname']) && $userInfo['pre_nickname'] != $userInfo['nickname']) {
  47. $userInfo['nickname_status'] = 1;
  48. }
  49. if (!empty($userInfo['pre_avatar']) && $userInfo['pre_avatar'] != $userInfo['avatar']) {
  50. $userInfo['avatar_status'] = 1;
  51. }
  52. // 获取技能信息
  53. $skillList = Model("ViewUserSkill")->getSkillInfo($user_id);
  54. $userInfo["skill"] = implode("/",$skillList);
  55. // 获取关注粉丝信息
  56. $followModel = new \app\common\model\ViewFollows();
  57. $fansModel = new \app\common\model\ViewFans();
  58. // 获取关注信息
  59. $where = [];
  60. $where["user_id"] = $user_id;
  61. $userCount = $followModel->where($where)->value("follows"); //该用户关注了几个人
  62. $userInfo["follows_count"] = $userCount?$userCount:0;
  63. $userInfo["follows"] = $userInfo["follows_count"];//前端字段使用不一致添加
  64. // 获取粉丝数
  65. $where = [];
  66. $where["user_id"] = $user_id;
  67. $fansCount = $fansModel->where($where)->value("fans"); //该用户的粉丝数
  68. $userInfo["fans_count"] = $fansCount?$fansCount:0;
  69. $userInfo["fans"] = $userInfo["fans_count"];//前端字段使用不一致添加
  70. // 获取贵族信息
  71. $nobleInfo = $this->userModel->getUserNobleInfo($user_id);
  72. // 查看者是否已关注
  73. $followid = \app\common\model\UserFansFollow::where(["fans_id"=>$this->auth->id,"user_id"=>$user_id])->value("id");
  74. $userInfo["is_follow"] = $followid>0?1:0;
  75. $userInfo = json_decode(json_encode($userInfo),true);
  76. $userInfo = array_merge($userInfo,$nobleInfo);
  77. // 获取用户在派对直播间情况信息
  78. $redis = new Redis();
  79. $redisconfig = config("redis");
  80. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  81. if ($redisconfig['redis_pwd']) {
  82. $redis->auth($redisconfig['redis_pwd']);
  83. }
  84. if($redisconfig['redis_selectdb'] > 0){
  85. $redis->select($redisconfig['redis_selectdb']);
  86. }
  87. $livingUserPartyId = $redis->hGet("livingUser", $user_id);
  88. $userInfo['party_info'] = json([]);
  89. if ($livingUserPartyId) {
  90. $party = \app\common\model\Party::where('id',$livingUserPartyId)->field('id,room_type')->find();
  91. $userInfo['party_info'] = ['party_id' => $party['id'], 'room_type' => $party['room_type']];
  92. }
  93. $blackWhere['user_id'] = $this->auth->id;
  94. $blackList = model('UserBlacklist')->where($blackWhere)->select();
  95. $blackIds = !empty($blackList) ? array_column($blackList,'black_user_id') : [];
  96. $userInfo['is_black'] = in_array($user_id,$blackIds) ? 1 : 0;
  97. $memberinfo = Db::name('guild_member')->alias('m')->field('m.id as `member_id`,m.user_id,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();
  98. if ($memberinfo) {
  99. $userInfo['memberinfo'] = $memberinfo;
  100. }
  101. //家族信息
  102. $guildField = 'g.id,g.g_id,g.user_id,g.party_id,g.name,g.image,g.desc,g.member,g.status';
  103. $guildWhere['gm.user_id'] = $user_id;
  104. $guildWhere['g.status'] = 1;
  105. $guildInfo = model('Guild')->alias('g')->field($guildField)
  106. ->join('guild_member gm','gm.guild_id = g.id','LEFT')
  107. ->where($guildWhere)->order('id desc')->find();
  108. $userInfo['guild_info'] = !empty($guildInfo) ? $guildInfo : [];
  109. $guildStatus = -2;
  110. if (!empty($guildInfo)) {
  111. $guildStatus = (int)$guildInfo['status'];
  112. }
  113. $userInfo['guild_status'] = $guildStatus;//家族状态:公会状态:0=待审核,1=正常,-1=已解散,-2无公会
  114. //动态
  115. //技能
  116. //礼物
  117. $power = UserPower::where(['user_id'=>$user_id])->find();
  118. $userInfo['user_power'] = $power;
  119. //访客记录
  120. if ($this->auth->id != $user_id) {
  121. $visit_data = [
  122. 'user_id' => $this->auth->id,
  123. 'visit_user_id' => $user_id,
  124. ];
  125. $visit_check = Db::name('user_visitlist')->where($visit_data)->find();
  126. if(empty($visit_check)){
  127. $visit_data['updatetime'] = time();
  128. Db::name('user_visitlist')->insertGetId($visit_data);
  129. }else{
  130. Db::name('user_visitlist')->where('id',$visit_check['id'])->update(['updatetime'=>time()]);
  131. }
  132. }
  133. $this->success("获取成功!",$userInfo);
  134. }
  135. /**
  136. * 添加关注
  137. */
  138. public function addFollows() {
  139. $user_id = $this->request->request("user_id",0,"intval");// 被关注者ID
  140. $type = $this->request->request("type",1);// 类型:1=关注,2=取消关注
  141. if (!$user_id || $user_id<=0) {
  142. $this->error(__('Invalid parameters'));
  143. }
  144. if($type == 1) {
  145. if($user_id == $this->auth->id) {
  146. $this->error("不需要关注自己哦!");
  147. }
  148. $fansfollowModel = new \app\common\model\UserFansFollow();
  149. $data = [];
  150. $data["user_id"] = $user_id;
  151. $data["fans_id"] = $this->auth->id;
  152. if($fansfollowModel->where($data)->find()) {
  153. $this->error("你已经关注过ta啦!");
  154. }
  155. $data["createtime"] = time();
  156. $id = $fansfollowModel->insertGetId($data);
  157. //关注通知
  158. $msgdata = [
  159. 'user_id'=>$user_id,
  160. 'title' => '有人刚刚关注了你',
  161. 'content'=> '打开[消息][最新关注]即可查看',
  162. 'createtime' => time(),
  163. ];
  164. Db::name('message')->insertGetId($msgdata);
  165. if($id > 0) {
  166. // 增加任务进度 +exp
  167. \app\common\model\TaskLog::tofinish($this->auth->id,"ebxLwnXj3L",1);
  168. // 增加任务进度 +exp
  169. \app\common\model\TaskLog::tofinish($this->auth->id,"iA1QgRhL",1);
  170. // 增加任务进度 +exp
  171. \app\common\model\TaskLog::tofinish($this->auth->id,"ghopE4Ou",1);
  172. // 增加任务进度 +exp
  173. \app\common\model\TaskLog::tofinish($this->auth->id,"TryNGc1x",1);
  174. $this->success("关注成功!");
  175. } else {
  176. $this->error("网络错误,请稍后重试!");
  177. }
  178. } else {
  179. $fansfollowModel = new \app\common\model\UserFansFollow();
  180. $where = [];
  181. $where["user_id"] = $user_id;
  182. $where["fans_id"] = $this->auth->id;
  183. $fansfollowInfo = $fansfollowModel->where($where)->find();
  184. if(!$fansfollowInfo) {
  185. $this->error("关注信息获取失败!");
  186. }
  187. $res = $fansfollowModel->where($where)->delete();
  188. if($res > 0) {
  189. $this->success("取消成功!");
  190. } else {
  191. $this->error("网络错误,请稍后重试!");
  192. }
  193. }
  194. }
  195. /**
  196. * 是否关注
  197. */
  198. public function isFollows() {
  199. $user_id = $this->request->request("user_id",0,"intval");// 关注者ID
  200. if (!$user_id || $user_id<=0) {
  201. $this->error(__('Invalid parameters'));
  202. }
  203. $fansfollowModel = new \app\common\model\UserFansFollow();
  204. $where = [];
  205. $where["user_id"] = $user_id;
  206. $where["fans_id"] = $this->auth->id;
  207. $fansfollowInfo = $fansfollowModel->where($where)->find();
  208. $data = [];
  209. if($fansfollowInfo) {
  210. $data["is_show_follow"] = 0;
  211. } else {
  212. $data["is_show_follow"] = 1;
  213. }
  214. $this->success("获取成功!",$data);
  215. }
  216. /**
  217. * 获取关注人列表.派对信息
  218. */
  219. public function getFollowsLive() {
  220. $is_online = $this->request->request("is_online");// 是否在线:1=直播中,0=未开播
  221. $page = $this->request->request('page',1); // 分页
  222. $pageNum = $this->request->request('pageNum',10); // 分页
  223. // 分页搜索构建
  224. $pageStart = ($page-1)*$pageNum;
  225. $is_online == 1 || $is_online = 0;
  226. $fanfollowModel = new \app\common\model\UserFansFollow();
  227. $where = [];
  228. $where["a.fans_id"] = $this->auth->id;
  229. $where["p.room_type"] = 2;
  230. $where["p.is_online"] = $is_online;
  231. if($is_online == 1) {
  232. $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";
  233. } else {
  234. $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";
  235. }
  236. $list = $fanfollowModel->alias("a")
  237. ->field($field)
  238. ->join("hx_user u","u.id = a.user_id")
  239. ->join("hx_party p","p.user_id = a.user_id")
  240. ->join("hx_party_type t","t.id = p.party_type","left")
  241. ->limit($pageStart,$pageNum)
  242. ->where($where)->select();
  243. if($list) {
  244. foreach($list as $k => $v) {
  245. $mod = isset($v["party_type"])?intval($v["party_type"])%5:1;
  246. if(isset($v["type_name"]) && $v["type_name"]) {
  247. $type_name = $v["type_name"];
  248. } else {
  249. $type_name = "普通房";
  250. }
  251. $list[$k]["party_type"] = $type_name;
  252. $list[$k]["party_type_color"] = $mod == 0?5:$mod;
  253. }
  254. $this->success("获取成功!",$list);
  255. } else {
  256. $this->success("数据为空!",[]);
  257. }
  258. }
  259. /**
  260. * 获取关注列表
  261. * (个人中心模块)(消息-最新关注)
  262. */
  263. public function getFollowsUser() {
  264. $type = $this->request->request('type',1); // 1=关注,2=粉丝,3=好友
  265. $page = $this->request->request('page',1); // 分页
  266. $pageNum = $this->request->request('pageNum',10); // 分页
  267. // 分页搜索构建
  268. $pageStart = ($page-1)*$pageNum;
  269. $pageEnd = $pageStart + $pageNum;
  270. $fanfollowModel = new \app\common\model\UserFansFollow();
  271. // 获取关注列表
  272. $where = [];
  273. $where["a.fans_id"] = $this->auth->id;
  274. $followlist = $fanfollowModel->alias("a")
  275. ->field("a.id,a.user_id,a.createtime,u.avatar,u.nickname,u.level,u.gender,u.desc")
  276. ->join("hx_user u","u.id = a.user_id")
  277. // ->limit($pageStart,$pageNum)
  278. ->where($where)->order('a.id desc')->select();
  279. $followlist = list_domain_image($followlist,['avatar']);
  280. // 获取粉丝列表
  281. $where = [];
  282. $where["a.user_id"] = $this->auth->id;
  283. $fanslist = $fanfollowModel->alias("a")
  284. ->field("a.id,a.fans_id,a.createtime,u.avatar,u.nickname,u.level,u.gender,u.desc")
  285. ->join("hx_user u","u.id = a.fans_id")
  286. // ->limit($pageStart,$pageNum)
  287. ->where($where)->order('a.id desc')->select();
  288. $fanslist = list_domain_image($fanslist,['avatar']);
  289. // print_r(json_encode($followlist));exit;
  290. if($type == 1) {
  291. $ids = [];
  292. if($fanslist) {
  293. foreach($fanslist as $k => $v) {
  294. $ids[] = $v["fans_id"];
  295. }
  296. }
  297. if($followlist) {
  298. foreach($followlist as $k => $v) {
  299. $followlist[$k]['createtime_text'] = get_last_time($v['createtime']);
  300. $followlist[$k]["is_follow"] = 1;
  301. if(in_array($v["user_id"],$ids)) {
  302. $followlist[$k]["is_hu"] = 1;
  303. } else {
  304. $followlist[$k]["is_hu"] = 0;
  305. }
  306. }
  307. }
  308. $fansfollow = $followlist;
  309. } elseif($type == 2) {
  310. $ids = [];
  311. if($followlist) {
  312. foreach($followlist as $k => $v) {
  313. $ids[] = $v["user_id"];
  314. }
  315. }
  316. if($fanslist) {
  317. foreach($fanslist as $k => $v) {
  318. $fanslist[$k]['createtime_text'] = get_last_time($v['createtime']);
  319. if(in_array($v["fans_id"],$ids)) {
  320. $fanslist[$k]["is_hu"] = 1;
  321. $fanslist[$k]["is_follow"] = 1;
  322. } else {
  323. $fanslist[$k]["is_hu"] = 0;
  324. }
  325. }
  326. }
  327. $fansfollow = $fanslist;
  328. }else {
  329. $ids = [];
  330. if($followlist) {
  331. foreach($followlist as $k => $v) {
  332. $ids[] = $v["user_id"];
  333. }
  334. }
  335. if($fanslist) {
  336. foreach($fanslist as $k => $v) {
  337. $fanslist[$k]['createtime_text'] = get_last_time($v['createtime']);
  338. $fanslist[$k]["is_follow"] = 1;
  339. if(in_array($v["fans_id"],$ids)) {
  340. $fanslist[$k]["is_hu"] = 1;
  341. } else {
  342. unset($fanslist[$k]); //不是好友的 直接unset掉
  343. }
  344. }
  345. }
  346. $fansfollow = $fanslist;
  347. }
  348. if($fansfollow) {
  349. $data = [];
  350. foreach($fansfollow as $k => $v) {
  351. if($k >= $pageStart && $k < $pageEnd) {
  352. $data[] = $v;
  353. }
  354. }
  355. $this->success("获取成功!",$data);
  356. } else {
  357. $this->success("数据为空!",[]);
  358. }
  359. }
  360. /**
  361. * 获取最近访客
  362. * (消息)
  363. */
  364. public function getMyVisitList(){
  365. $list = Db::name('user_visitlist')->alias('uv')
  366. ->field('uv.user_id,uv.updatetime,user.id,user.nickname,user.avatar,user.gender,user.desc')
  367. ->join('user','uv.user_id = user.id','LEFT')
  368. ->where('uv.visit_user_id',$this->auth->id) //被访问者
  369. ->order('uv.id desc')->autopage()->select();
  370. $list = list_domain_image($list,['avatar']);
  371. if(!empty($list)){
  372. foreach($list as $key => &$val){
  373. //关注
  374. $val['is_follow'] = $this->is_follow($val['user_id'],$this->auth->id);
  375. }
  376. }
  377. $this->success(1,$list);
  378. }
  379. /**
  380. * 获取附近的人
  381. * (消息-同城)
  382. */
  383. public function getSamecityList(){
  384. if(!$this->auth->city_id){
  385. $this->success(1,[]);
  386. }
  387. $where = [
  388. 'status' => 'normal',
  389. 'city_id'=> $this->auth->city_id,
  390. ];
  391. //排除黑名单的
  392. $black_ids = Db::name('user_blacklist')->where('user_id',$this->auth->id)->column('black_user_id');
  393. if(!empty($black_ids)){
  394. $where['id'] = ['NOTIN',$black_ids];
  395. }
  396. $list = Db::name('user')->where($where)->where('id','neq',$this->auth->id)->field('id,nickname,avatar,gender,desc')->order('id desc')->autopage()->select();
  397. $list = list_domain_image($list,['avatar']);
  398. if(!empty($list)){
  399. foreach($list as $key => &$val){
  400. //关注
  401. $val['is_follow'] = $this->is_follow($val['id'],$this->auth->id);
  402. }
  403. }
  404. $this->success(1,$list);
  405. }
  406. //是否关注
  407. private function is_follow($user_id,$fans_id){
  408. $where = [
  409. 'user_id' => $user_id,
  410. 'fans_id' => $fans_id,
  411. ];
  412. $check = Db::name('user_fans_follow')->where($where)->find();
  413. if($check){
  414. return 1;
  415. }else{
  416. return 0;
  417. }
  418. }
  419. /**
  420. * 获取个人技能列表
  421. */
  422. public function getMySkillList() {
  423. $user_id = $this->request->request('user_id',0); // 用户ID
  424. $page = $this->request->request('page',1); // 分页
  425. $pageNum = $this->request->request('pageNum',10); // 分页
  426. if ($user_id == -1) {
  427. $user_id = $this->auth->id;
  428. } elseif($user_id>0) {
  429. $user_id = intval($user_id);
  430. } else {
  431. $this->error(__('Invalid parameters'));
  432. }
  433. // 分页搜索构建
  434. $pageStart = ($page-1)*$pageNum;
  435. $authModel = new \app\common\model\DispatchAuth();
  436. $where = [];
  437. $where["a.user_id"] = $user_id;
  438. $where["a.status"] = 1;
  439. $authskillList = $authModel->alias("a")
  440. ->field("a.id,ds.image,ds.name,a.voice,a.voice_time,a.price,a.is_main,ds.unit")
  441. ->join("hx_dispatch_skill ds","ds.id = a.skill_id")
  442. ->where($where)
  443. ->limit($pageStart,$pageNum)
  444. ->select();
  445. $this->success("获取成功!",$authskillList);
  446. }
  447. /**
  448. * 删除个人技能信息
  449. */
  450. public function delMySkillInfo() {
  451. $id = $this->request->request('id'); // 认证ID
  452. if (!$id) {
  453. $this->error(__('Invalid parameters'));
  454. }
  455. $authModel = new \app\common\model\DispatchAuth();
  456. $where = [];
  457. $where["id"] = $id;
  458. $where["user_id"] = $this->auth->id;
  459. $authInfo = $authModel->where($where)->find();
  460. if(!$authInfo) $this->error("技能认证未找到");
  461. // if($authInfo->is_main == 1) $this->error("请先取消主技能,再删除!");
  462. Db::startTrans();
  463. try{
  464. $res1 = $authInfo->delete();
  465. $res2 = \app\common\model\UserSkill::where(["user_id"=>$this->auth->id,"skill_id"=>$authInfo->skill_id])->delete();
  466. if($res1 && $res2) {
  467. Db::commit();
  468. $this->success("删除成功!");
  469. } else {
  470. $this->error("网络错误,请稍后重试!");
  471. }
  472. }catch (ValidateException $e) {
  473. Db::rollback();
  474. $this->error($e->getMessage());
  475. } catch (PDOException $e) {
  476. Db::rollback();
  477. $this->error($e->getMessage());
  478. } catch (Exception $e) {
  479. Db::rollback();
  480. $this->error($e->getMessage());
  481. }
  482. }
  483. /**
  484. * 修改个人技能信息
  485. */
  486. public function editMySkillInfo() {
  487. $price = $this->request->request('price'); // 价格
  488. $id = $this->request->request('id'); // 认证ID
  489. $is_main = $this->request->request('is_main'); // 是否设置为主技能
  490. if (!$id && !$price) {
  491. $this->error(__('Invalid parameters'));
  492. }
  493. $authModel = new \app\common\model\DispatchAuth();
  494. $where = [];
  495. $where["id"] = $id;
  496. if(!$authModel->where($where)->find()) $this->error("技能认证未找到");
  497. Db::startTrans();
  498. try{
  499. if($is_main == 1) {
  500. $where = [];
  501. $where["user_id"] = $this->auth->id;
  502. $authModel->update(["is_main"=>0],$where);
  503. }
  504. $where = [];
  505. $where["id"] = $id;
  506. $data = [];
  507. $data["price"] = $price;
  508. $data["is_main"] = $is_main;
  509. $res = $authModel->update($data,$where);
  510. $myAuthList = $authModel->where(["user_id"=>$this->auth->id,"is_main"=>1])->find();
  511. if(!$myAuthList) {
  512. $this->error("必须至少设置一个主技能");
  513. Db::rollback();
  514. }
  515. if($res) {
  516. Db::commit();
  517. $this->success("修改成功!",$data);
  518. } else {
  519. $this->error("网络错误,请稍后重试!");
  520. }
  521. }catch (ValidateException $e) {
  522. Db::rollback();
  523. $this->error($e->getMessage());
  524. } catch (PDOException $e) {
  525. Db::rollback();
  526. $this->error($e->getMessage());
  527. } catch (Exception $e) {
  528. Db::rollback();
  529. $this->error($e->getMessage());
  530. }
  531. }
  532. /**
  533. * 编辑个人信息(完善资料)
  534. */
  535. public function editUserInfo() {
  536. $avatar = $this->request->request('avatar'); // 头像
  537. $nickname = $this->request->request('nickname'); // 昵称
  538. $age = $this->request->request('age'); // 年龄
  539. $ageId = $this->request->request('age_id'); // 年龄段
  540. $gender = $this->request->request('gender'); // 性别 0=女,1=男
  541. $image = $this->request->request('image'); // 个人形象照
  542. $constellationId = $this->request->request('star_id'); //星座ID
  543. $provinceId = $this->request->request('province_id'); //省ID
  544. $cityId = $this->request->request('city_id'); //城市ID
  545. $desc = $this->request->request('desc'); //个性签名
  546. /*if (!$avatar && !$nickname && !$age && !$image && !in_array($gender,[0,1])) {
  547. $this->error(__('请输入要修改的信息'));
  548. }*/
  549. $where = [];
  550. $where["id"] = $this->auth->id;
  551. $data = [];
  552. $avatar && $data["avatar"] = $avatar;
  553. if($nickname){
  554. if (mb_strlen($nickname) > 30) {
  555. $this->error('用户昵称最多支持30个汉字或组合');
  556. }
  557. $data["nickname"] = $nickname;
  558. }
  559. $gender && $data["gender"] = $gender;
  560. $age && $data["age"] = $age;
  561. $image && $data["image"] = $image;
  562. $ageId && $data['age_id'] = $ageId;
  563. $constellationId && $data['constellation_id'] = $constellationId;
  564. $provinceId && $data['province_id'] = $provinceId;
  565. $cityId && $data['city_id'] = $cityId;
  566. $desc && $data['desc'] = $desc;
  567. $res = $this->userModel->update($data,$where);
  568. if($res) {
  569. $user = $this->userModel->where($where)->find();
  570. if (!empty($user['nickname']) && !empty($user['avatar']) && !empty($user['age_id']) && $user['has_info']==0) {
  571. $data['has_info'] = 1;
  572. $this->userModel->update($data,$where);
  573. }
  574. $this->success("修改成功!");
  575. } else {
  576. $this->error("网络错误,请稍后重试!");
  577. }
  578. }
  579. /**
  580. * 编辑个人信息(修改昵称和头像需要后台审核)
  581. */
  582. public function editUser() {
  583. $avatar = $this->request->request('avatar'); // 头像
  584. $nickname = $this->request->request('nickname'); // 昵称
  585. if (!$avatar && !$nickname) {
  586. $this->error(__('请输入要修改的信息'));
  587. }
  588. $data = [];
  589. if ($avatar && $avatar != $this->auth->avatar) {
  590. $data["pre_avatar"] = $avatar;
  591. }
  592. if($nickname && $nickname != $this->auth->nickname){
  593. if (mb_strlen($nickname) > 8) {
  594. $this->error('用户昵称最多支持8个汉字或组合');
  595. }
  596. $data["pre_nickname"] = $nickname;
  597. }
  598. if (!empty($data)) {
  599. $where["id"] = $this->auth->id;
  600. $res = $this->userModel->update($data,$where);
  601. if(!$res) {
  602. $this->error("网络错误,请稍后重试!");
  603. }
  604. }
  605. $this->success("修改成功!");
  606. }
  607. /**
  608. * 主播申请
  609. */
  610. public function anchorApply() {
  611. $type_id = $this->request->request('type_id',0); // 技能分类ID
  612. $party_type_id = $this->request->request('party_type_id'); //分类ID
  613. $desc = $this->request->request('desc'); // 申请备注
  614. if (!$party_type_id && !$desc) {
  615. $this->error(__('Invalid parameters'));
  616. }
  617. $useranchorModel = new \app\common\model\UserAnchor();
  618. $data = [];
  619. $data["user_id"] = $this->auth->id;
  620. $data["type_id"] = $type_id;
  621. $data["party_type_id"] = $party_type_id;
  622. if($useranchorModel->where($data)->find()) $this->error(__('您已申请过该类型的主播,请勿重复申请!'));
  623. $data["desc"] = $desc;
  624. $data["createtime"] = time();
  625. $res = $useranchorModel->insertGetId($data);
  626. if($res) {
  627. \app\common\model\User::update(["is_anchor"=>1],["id"=>$this->auth->id]);
  628. $this->success("申请发送成功!");
  629. } else {
  630. $this->error("网络错误,请稍后重试");
  631. }
  632. }
  633. /**
  634. * 实名认证
  635. */
  636. public function authApply() {
  637. $realname = $this->request->request('realname'); // 真实姓名
  638. $idcard = $this->request->request('idcard'); // 身份证号
  639. $zimage = $this->request->request('zimage'); // 身份证正面照
  640. $fimage = $this->request->request('fimage'); // 身份证反面照
  641. if (!$realname && !$idcard && !$zimage && !$fimage) {
  642. $this->error(__('Invalid parameters'));
  643. }
  644. $userauthModel = new \app\common\model\UserAuth();
  645. $data = [];
  646. $data["user_id"] = $this->auth->id;
  647. //$data["idcard"] = $idcard;
  648. $userAuth = $userauthModel->where($data)->find();
  649. if (!empty($userAuth)) {
  650. if(in_array($userAuth['status'],[0,1])) $this->error('您已经申请过了,请勿重复操作!');
  651. }
  652. // 测试需要 开始
  653. $data["realname"] = $realname;
  654. $zimage && $data["zimage"] = $zimage;
  655. $fimage && $data["fimage"] = $fimage;
  656. $data["status"] = 1;
  657. if (!empty($userAuth)) {
  658. $data["updatetime"] = time();
  659. $authWhere['user_id'] = $this->auth->id;
  660. $res = $userauthModel->where($authWhere)->update($data);
  661. } else {
  662. $data["createtime"] = time();
  663. $res = $userauthModel->insertGetId($data);
  664. }
  665. if($res) {
  666. \app\common\model\User::update(["is_auth"=>2],["id"=>$this->auth->id]);
  667. $this->success("恭喜,实名认证成功!");
  668. } else {
  669. $this->error("网络错误,请稍后重试");
  670. }
  671. // 测试需要 结束
  672. // 实名认证验证
  673. $configInfo = config("auth");
  674. $outh = new outh($configInfo["api_url"],$configInfo["customer_code"],$configInfo["private_key"],$configInfo["key"]);
  675. $out_trade_no = date("YmdHis").rand(1000,9999);
  676. $ret = $outh->toVerify($out_trade_no,$realname,$idcard);
  677. if(isset($ret["code"])) {
  678. if($ret["code"] == "1008") {
  679. $this->error(__('身份证格式错误'));
  680. }
  681. if($ret["code"] == "1009") {
  682. $this->error(__('身份证格式错误'));
  683. }
  684. if($ret["code"] == "0001") {
  685. $this->error(__('姓名和身份证号不匹配!'));
  686. }
  687. if($ret["code"] == "0000") {
  688. $data["realname"] = $realname;
  689. $zimage && $data["zimage"] = $zimage;
  690. $fimage && $data["fimage"] = $fimage;
  691. $data["status"] = 1;
  692. $data["createtime"] = time();
  693. $res = $userauthModel->insertGetId($data);
  694. if($res) {
  695. \app\common\model\User::update(["is_auth"=>2],["id"=>$this->auth->id]);
  696. $this->success("恭喜,实名认证成功!");
  697. } else {
  698. $this->error("网络错误,请稍后重试");
  699. }
  700. }
  701. } else {
  702. $this->error("网络错误,请稍后重试");
  703. }
  704. }
  705. /**
  706. * 获取主播分类
  707. */
  708. public function getAnchorType() {
  709. $this->success("获取成功!",\app\common\model\UserAnchorType::select());
  710. }
  711. /**
  712. * 加入黑名单
  713. */
  714. public function addBlacklist() {
  715. Db::startTrans();
  716. try {
  717. $black_user_id = $this->request->request('black_user_id'); // 黑名单用户ID
  718. if (!$black_user_id) {
  719. throw new Exception(__('Invalid parameters'));
  720. }
  721. $userblacklistModel = new \app\common\model\UserBlacklist();
  722. $data = [];
  723. $data["user_id"] = $this->auth->id;
  724. $data["black_user_id"] = $black_user_id;
  725. if($userblacklistModel->where($data)->find()) $this->error(__('已在黑名单!'));
  726. $data["createtime"] = time();
  727. $res = $userblacklistModel->insertGetId($data);
  728. if(!$res) {
  729. throw new Exception("网络错误,请稍后重试");
  730. }
  731. //im加入黑名单
  732. $tenimService = new TenimService();
  733. $params = [
  734. 'user_id' => $this->auth->id,
  735. 'black_user_ids' => [(string)$black_user_id],
  736. ];
  737. $imResult = $tenimService->addBlack($params);
  738. if (!$imResult['status']) {
  739. throw new Exception($imResult['msg']);
  740. }
  741. Db::commit();
  742. $this->success("加入成功!");
  743. } catch (Exception $e) {
  744. Db::rollback();
  745. $this->error($e->getMessage());
  746. }
  747. }
  748. /**
  749. * 获取黑名单用户
  750. */
  751. public function getBlacklist() {
  752. $page = $this->request->request('page',1); // 分页
  753. $pageNum = $this->request->request('pageNum',10); // 分页
  754. // 分页搜索构建
  755. $pageStart = ($page-1)*$pageNum;
  756. $userblacklistModel = new \app\common\model\UserBlacklist();// ->limit($pageStart,$pageNum)
  757. $where = [];
  758. $where["a.user_id"] = $this->auth->id;
  759. $list = $userblacklistModel->alias("a")
  760. ->field("a.id,a.black_user_id,u.avatar,u.nickname,u.level,u.gender")
  761. ->join("hx_user u","u.id = a.black_user_id")
  762. ->where($where)
  763. ->limit($pageStart,$pageNum)
  764. ->select();
  765. if($list) {
  766. $this->success("获取成功!",$list);
  767. } else {
  768. $this->success("数据为空",[]);
  769. }
  770. }
  771. /**
  772. * 移除用户黑名单
  773. */
  774. public function removeUserBlack() {
  775. Db::startTrans();
  776. try {
  777. $id = $this->request->request('id'); // 黑名单ID
  778. $userId = $this->request->request('user_id'); // 用户ID
  779. if (!$id && !$userId) {
  780. throw new Exception(__('Invalid parameters'));
  781. }
  782. $userblacklistModel = new \app\common\model\UserBlacklist();
  783. $where = [];
  784. $id && $where["id"] = $id;
  785. if ($userId) {
  786. $where['user_id'] = $this->auth->id;
  787. $where['black_user_id'] = $userId;
  788. }
  789. $userBlack = $userblacklistModel->where($where)->find();
  790. if (empty($userBlack)) {
  791. throw new Exception('未找到黑名单信息');
  792. }
  793. $blackUserId = isset($userBlack['black_user_id']) ? $userBlack['black_user_id'] : 0;
  794. $res = false;
  795. if (!empty($userBlack)) {
  796. $res = $userblacklistModel->where($where)->delete();
  797. }
  798. if(!$res) {
  799. $this->error("网络错误,请稍后重试!");
  800. }
  801. //im加入黑名单
  802. if (!empty($blackUserId)) {
  803. $tenimService = new TenimService();
  804. $params = [
  805. 'user_id' => $this->auth->id,
  806. 'black_user_ids' => [(string)$blackUserId],
  807. ];
  808. $imResult = $tenimService->delBlack($params);
  809. if (!$imResult['status']) {
  810. throw new Exception($imResult['msg']);
  811. }
  812. }
  813. Db::commit();
  814. $this->success("移除成功!",$res);
  815. } catch (Exception $e) {
  816. Db::rollback();
  817. $this->error($e->getMessage());
  818. }
  819. }
  820. /**
  821. * 举报用户
  822. */
  823. /*public function addReport() {
  824. $ruser_id = $this->request->request('ruser_id'); // 被举报用户ID
  825. $content = $this->request->request('content'); // 举报内容
  826. $image = $this->request->request('image'); // 图片描述(多个用半角逗号隔开)
  827. if (!$ruser_id) {
  828. $this->error(__('Invalid parameters'));
  829. }
  830. $userreportModel = new \app\common\model\UserReport();
  831. $data = [];
  832. $data["user_id"] = $this->auth->id;
  833. $data["reportable_id"] = $ruser_id;
  834. $data['reportable_type'] = $this->getModelName('user');
  835. $data["content"] = $content;
  836. $data["image"] = $image;
  837. $data["createtime"] = time();
  838. $res = $userreportModel->insertGetId($data);
  839. if($res) {
  840. $this->success("举报成功!");
  841. } else {
  842. $this->error("网络错误,请稍后重试");
  843. }
  844. }*/
  845. /**
  846. * 举报
  847. */
  848. /*public function addReportNew() {
  849. $params = $this->request->param();
  850. $validate = new Report();
  851. $result = $validate->check($params);
  852. if (!$result) {
  853. $this->error($validate->getError());
  854. }
  855. $userreportModel = new \app\common\model\UserReport();
  856. $data = [];
  857. $data["user_id"] = $this->auth->id;
  858. $data["reportable_id"] = $params['reportable_id'];
  859. $data['reportable_type'] = $this->getModelName($params['reportable_type']);
  860. $data["content"] = $params['content'];
  861. $data["image"] = $params['image'];
  862. $data["createtime"] = time();
  863. $res = $userreportModel->insertGetId($data);
  864. if($res) {
  865. $this->success("举报成功!");
  866. } else {
  867. $this->error("网络错误,请稍后重试");
  868. }
  869. }*/
  870. /**
  871. * redis 数据恢复---非redis数据丢失请勿使用!!!!
  872. */
  873. public function shujuhuifu() {
  874. $key = $this->request->request("key");// 操作验证 123456
  875. if($key != 123456) {
  876. $this->error(__('Invalid parameters'));
  877. }
  878. $giftuserpartyModel = new \app\common\model\GiftUserParty();
  879. $redis = new Redis();
  880. $redisconfig = config("redis");
  881. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  882. if ($redisconfig['redis_pwd']) {
  883. $redis->auth($redisconfig['redis_pwd']);
  884. }
  885. if($redisconfig['redis_selectdb'] > 0){
  886. $redis->select($redisconfig['redis_selectdb']);
  887. }
  888. // 获取本周第一天
  889. $weekday = $this->firstOfWeek(date("Y-m-d H:i:s"));
  890. // 获取本月第一天
  891. $monthday = date("Ym01");
  892. $where = [];
  893. $where["createtime"] = ["gt",strtotime($weekday)];
  894. $list1 = $giftuserpartyModel->where($where)->select();
  895. foreach($list1 as $k => $v) {
  896. // 添加redis记录做财富排行榜周榜用
  897. $redis->zIncrBy("jewel_get_".$v["party_id"].":".$weekday,$v["value"],$v["user_to_id"]);
  898. // 添加redis记录做贡献排行榜周榜用
  899. $redis->zIncrBy("jewel_to_".$v["party_id"].":".$weekday,$v["value"],$v["user_id"]);
  900. }
  901. $where = [];
  902. $where["createtime"] = ["gt",strtotime(date("Y-m-01"))];
  903. $list2 = $giftuserpartyModel->where($where)->select();
  904. foreach($list2 as $k => $v) {
  905. // 添加redis记录做财富排行榜月榜用
  906. $redis->zIncrBy("jewel_get_".$v["party_id"].":".$monthday,$v["value"],$v["user_to_id"]);
  907. // 添加redis记录做贡献排行榜月榜用
  908. $redis->zIncrBy("jewel_to_".$v["party_id"].":".$monthday,$v["value"],$v["user_id"]);
  909. }
  910. $this->success("执行成功!");
  911. }
  912. /**
  913. * 获取用户钻石余额
  914. */
  915. public function getUserJewel() {
  916. $data = \app\common\model\User::field("Jewel,money")->where(["id"=>$this->auth->id])->find();
  917. return $this->success("获取成功!",$data);
  918. }
  919. /**
  920. * 获取用户等级说明
  921. */
  922. public function getLevelExplain() {
  923. $data = \app\common\model\UserLevelExplain::field("title,content")->select();
  924. return $this->success("获取成功!",$data);
  925. }
  926. /**
  927. * 获取用户等级信息
  928. */
  929. public function getUserLevelInfo() {
  930. $res = [];$exstart = 0;$exend = 0;
  931. $userModel = new \app\common\model\User();
  932. $userInfo = $userModel->field("id,nickname,avatar,level,empirical")->where(["id"=>$this->auth->id])->find();
  933. if(!$userInfo) {
  934. $this->error("用户信息获取失败!");
  935. }
  936. $res["avatar"] = $userInfo['avatar'];
  937. $res["nickname"] = $userInfo['nickname'];
  938. // 获取用户当前经验值对应等级
  939. $userconfigModel = new \app\common\model\UserLevelConfig();
  940. $where = [];
  941. $where["empirical"] = ["elt",$userInfo["empirical"]];
  942. $userexplainstart = $userconfigModel->where($where)->order("empirical","desc")->limit(1)->select();
  943. $where = [];
  944. $where["empirical"] = ["gt",$userInfo["empirical"]];
  945. $userexplainend = $userconfigModel->where($where)->order("empirical","asc")->limit(1)->select();
  946. if(!$userexplainstart && !$userexplainend) {
  947. $this->error("经验等级信息获取失败!");
  948. } elseif(!$userexplainstart && $userexplainend) {
  949. $res["level_start"] = 0;
  950. $res["level_end"] = $userexplainend[0]["level"];
  951. } elseif($userexplainstart && !$userexplainend) {
  952. $res["level_start"] = $userexplainstart[0]["level"];
  953. $res["level_end"] = $userexplainstart[0]["level"];
  954. } elseif($userexplainstart && $userexplainend) {
  955. $res["level_start"] = $userexplainstart[0]["level"];
  956. $res["level_end"] = $userexplainend[0]["level"];
  957. }
  958. $userexplainstart && $exstart = $userexplainstart[0]["empirical"];
  959. $userexplainend && $exend = $userexplainend[0]["empirical"];
  960. $r1 = $exend-$exstart; // 等级经验值差
  961. $r2 = $userInfo["empirical"]-$exstart; // 当前等级与最低等级经验值差
  962. $r3 = $exend-$userInfo["empirical"]; // 还需多少经验值升级
  963. if($r1 == 0) {
  964. $res["level_rate"] = 1;
  965. } elseif($r2 == 0) {
  966. $res["level_rate"] = 0;
  967. if($res["level_start"] == $res["level_end"]) {
  968. $res["level_rate"] = 1;
  969. }
  970. } else {
  971. $res["level_rate"] = intval(($r2/$r1)*100)/100;
  972. }
  973. $res["to_up_need"] = $r3>0?$r3:0;
  974. // // 满级
  975. // if($r3 == 0 && !$userexplainend) {
  976. // $res["level_rate"] = 1;
  977. // }
  978. $this->success("获取成功!",$res);
  979. }
  980. /**
  981. * 邀请
  982. * @return void
  983. */
  984. public function addInvite()
  985. {
  986. try {
  987. $inviteNo = $this->request->param('invite_no','');
  988. $userId = $this->auth->id;
  989. if (empty($inviteNo)) {
  990. throw new Exception('参数错误');
  991. }
  992. $where['invite_no'] = $inviteNo;
  993. $userField = 'id,invite_no,pre_userid';
  994. $user = model('User')->field($userField)->where($where)->find();
  995. if (empty($user)) {
  996. throw new Exception('无效的邀请码');
  997. }
  998. //判断邀请码用户不能是自己的下级
  999. if ($user['pre_userid'] == $userId) {
  1000. throw new Exception('对方已被您邀请过');
  1001. }
  1002. $userInviteWhere['invite_user_id'] = $userId;
  1003. $userInvite = model('UserInvite')->where($userInviteWhere)->find();
  1004. if (!empty($userInvite)) {
  1005. throw new Exception('您已经被邀请过');
  1006. }
  1007. $userInviteData = [
  1008. 'user_id' => $user['id'],
  1009. 'invite_user_id' => $userId,
  1010. 'createtime' => time(),
  1011. ];
  1012. $userInviteRes = model('UserInvite')->insertGetId($userInviteData);
  1013. if (!$userInviteRes) {
  1014. throw new Exception('邀请失败');
  1015. }
  1016. $userUpWhere['id'] = $userId;
  1017. $userUpdate = ['pre_userid'=>$user['id']];
  1018. $userUpdateRes = model('User')->where($userUpWhere)->update($userUpdate);
  1019. if (!$userUpdateRes) {
  1020. throw new Exception('更新邀请人失败');
  1021. }
  1022. $this->success('邀请成功');
  1023. } catch (Exception $e) {
  1024. $this->error($e->getMessage());
  1025. }
  1026. }
  1027. /**
  1028. * 邀请详情
  1029. * @return void
  1030. */
  1031. public function inviteInfo()
  1032. {
  1033. try {
  1034. $userId = $this->auth->id;
  1035. $field = 'id,invite_no';
  1036. $where['id'] = $userId;
  1037. $user = model('User')->field($field)->where($where)->find();
  1038. $inviteNo = isset($user['invite_no']) ? $user['invite_no'] : '';
  1039. $todayNow = day_now();
  1040. $todayStart = $todayNow[0];
  1041. $todayEnd = $todayNow[1]+1;
  1042. $userMoneyLogWhere['user_id'] = $userId;
  1043. $userMoneyLogWhere['type'] = 103;
  1044. $appendWhere['createtime'] = [['egt', $todayStart],['lt', $todayEnd],'and'];
  1045. $todayMoney = model('UserMoneyLog')->where($userMoneyLogWhere)->where($appendWhere)->sum('value');
  1046. $totalMoney = model('UserMoneyLog')->where($userMoneyLogWhere)->sum('value');
  1047. //本周
  1048. $weekNow = week_now();
  1049. $userInviteWhere['user_id'] = $userId;
  1050. $userInviteAppendWhere['createtime'] = [['egt', $weekNow[0]],['lt', $weekNow[1]+1],'and'];
  1051. $userInviteModel = model('UserInvite');
  1052. $weekNowNum = $userInviteModel->where($userInviteWhere)->where($userInviteAppendWhere)->count();
  1053. //上周
  1054. $lastWeek = last_week();
  1055. $appendLastWhere['createtime'] = [['egt', $lastWeek[0]],['lt', $lastWeek[1]+1],'and'];
  1056. $lastWeekNum = $userInviteModel->where($userInviteWhere)->where($appendLastWhere)->count();
  1057. //全部
  1058. $totalNum = $userInviteModel->where($userInviteWhere)->count();
  1059. $inviteMoney = config('site.invite_money');
  1060. $inviteRule = config('site.invite_rule');
  1061. $result = [
  1062. 'invite_money' => (int)$inviteMoney,
  1063. 'invite_no' => $inviteNo,//邀请码
  1064. 'today_money' => $todayMoney,//今日收益
  1065. 'total_money' => $totalMoney,//总收益
  1066. 'week_now_num' => $weekNowNum,//本周邀请数
  1067. 'last_week_num' => $lastWeekNum,//上周邀请数
  1068. 'total_num' => $totalNum,//总邀请数
  1069. 'invite_rule' => $inviteRule,//规则说明
  1070. ];
  1071. $this->success('获取成功',$result);
  1072. } catch (Exception $e) {
  1073. $this->error($e->getMessage());
  1074. }
  1075. }
  1076. /**
  1077. * 邀请列表
  1078. * @return void
  1079. */
  1080. public function inviteList()
  1081. {
  1082. try {
  1083. $userId = $this->auth->id;
  1084. $where['user_id'] = $userId;
  1085. $userInvite = model('UserInvite')->where($where)->with(['user'=>function($uQuery){
  1086. $uQuery->field('id,avatar,u_id,nickname');
  1087. }])->autopage()->order('createtime desc')->select();
  1088. $result = [];
  1089. if (!empty($userInvite)) {
  1090. foreach ($userInvite as $key => $value) {
  1091. $user = isset($value['user']) ? $value['user'] : [];
  1092. $temp = [
  1093. 'user_id' => isset($user['id']) ? $user['id'] : 0,
  1094. 'u_id' => isset($user['u_id']) ? $user['u_id'] : 0,
  1095. 'avatar' => isset($user['avatar']) ? $user['avatar'] : 0,
  1096. 'nickname' => isset($user['nickname']) ? $user['nickname'] : 0,
  1097. 'create_time_text' => !empty($value['createtime']) ? date('Y-m-d', $value['createtime']) : '',
  1098. ];
  1099. $result[] = $temp;
  1100. }
  1101. }
  1102. $this->success('获取成功',$result);
  1103. } catch (Exception $e) {
  1104. $this->error($e->getMessage());
  1105. }
  1106. }
  1107. /**
  1108. * 钻石兑换记录
  1109. * @return void
  1110. */
  1111. public function exchangeList()
  1112. {
  1113. try {
  1114. $field = 'id,sound_coin,createtime';
  1115. $where['user_id'] = $this->auth->id;
  1116. $result = model('UserExchangeLog')->field($field)->where($where)->autopage()->order('createtime desc')->select();
  1117. if (!empty($result)) {
  1118. foreach ($result as $key => &$value) {
  1119. $value['jewel'] = '+'.$value['sound_coin'];
  1120. $value['createtime'] = !empty($value['createtime']) ? date('Y-m-d H:i',$value['createtime']) : '';
  1121. unset($value['sound_coin']);
  1122. }
  1123. }
  1124. $this->success('获取成功',$result);
  1125. } catch (Exception $e) {
  1126. $this->error($e->getMessage());
  1127. }
  1128. }
  1129. /**
  1130. * 钻石充值记录
  1131. * @return void
  1132. */
  1133. public function rechargeList()
  1134. {
  1135. try {
  1136. $field = 'id,detail,mode,value,createtime';
  1137. $where['user_id'] = $this->auth->id;
  1138. $result = model('UserJewelLog')->field($field)->where($where)->autopage()->order('createtime desc')->select();
  1139. if (!empty($result)) {
  1140. foreach ($result as $key => &$value) {
  1141. $value['value'] = $value['mode'].$value['value'];
  1142. $value['createtime'] = !empty($value['createtime']) ? date('Y-m-d H:i',$value['createtime']) : '';
  1143. }
  1144. }
  1145. $this->success('获取成功',$result);
  1146. } catch (Exception $e) {
  1147. $this->error($e->getMessage());
  1148. }
  1149. }
  1150. /**
  1151. * 提现配置列表
  1152. * @return void
  1153. */
  1154. public function withdrawalConfigList()
  1155. {
  1156. try {
  1157. $field = 'id,money,real_money';
  1158. $result = model('WithdrawalConfig')->field($field)->autopage()->order('weigh asc')->select();
  1159. if (!empty($result)) {
  1160. //设置是否使用自定义
  1161. $withdrawDefine = config('site.withdraw_define');
  1162. if ($withdrawDefine == 1) {
  1163. $fieldArr = [[
  1164. 'id' => -1,
  1165. 'money' => 0,
  1166. 'real_money' => 0.00,
  1167. ],];
  1168. $result = array_merge($result,$fieldArr);
  1169. }
  1170. }
  1171. $this->success('获取成功',$result);
  1172. } catch (Exception $e) {
  1173. $this->error($e->getMessage());
  1174. }
  1175. }
  1176. /**
  1177. * 提现
  1178. * @return void
  1179. */
  1180. public function withdrawal()
  1181. {
  1182. Db::startTrans();
  1183. try {
  1184. $withdrawConfigId = $this->request->param('id',0);
  1185. $money = $this->request->param('money',0.00);
  1186. $type = $this->request->param('type',0);
  1187. $userId = $this->auth->id;
  1188. $isAnchor = $this->auth->is_anchor;
  1189. $userMoney = $this->auth->money;
  1190. if (empty($withdrawConfigId) && empty($money)) {
  1191. throw new Exception('参数错误');
  1192. }
  1193. //只有主播可以提现
  1194. if ($isAnchor != 2) {
  1195. throw new Exception('您不是主播不允许提现');
  1196. }
  1197. if ($this->auth->power->withdraw == 1) {
  1198. throw new Exception('您已被禁止提现');
  1199. }
  1200. //验证提现类型
  1201. $withdrawTypeConfig = config('wallet.withdraw_type');
  1202. $typeIds = array_keys($withdrawTypeConfig);
  1203. if (!in_array($type,$typeIds)) {
  1204. throw new Exception('未知的提现类型');
  1205. }
  1206. $typeStr = isset($withdrawTypeConfig[$type]) ? $withdrawTypeConfig[$type] : '';
  1207. $withdrawRateConfig = config('site.withdrawRate');//用户获取的金额比例(需要/100)
  1208. $withdrawRate = bcdiv($withdrawRateConfig,100,2);
  1209. if (!empty($money)) {//自定义金额
  1210. if ($money <= 0) {
  1211. throw new Exception('金额有误');
  1212. }
  1213. $inputMoney = $money;
  1214. $moneys = bcmul($money,$withdrawRate,2);
  1215. $platformMoney = bcsub($money,$moneys,2);
  1216. } else {//提现配置
  1217. $where['id'] = $withdrawConfigId;
  1218. $withdrawalConfig = model('WithdrawalConfig')->where($where)->find();
  1219. if (empty($withdrawalConfig)) {
  1220. throw new Exception('未知的配置信息');
  1221. }
  1222. $inputMoney = $withdrawalConfig['money'];
  1223. $moneys = $withdrawalConfig['money'];
  1224. $platformMoney = bcsub($moneys,$withdrawalConfig['real_money'],2);;
  1225. }
  1226. if ($moneys <= 0) {
  1227. throw new Exception('申请金额异常');
  1228. }
  1229. //扣减余额 记录余额日志
  1230. $walletRes = model('wallet')->lockChangeAccountRemain($userId, $inputMoney, '-', $userMoney, '申请提现', 104,'money');
  1231. if (!$walletRes['status']) {
  1232. throw new Exception($walletRes['msg']);
  1233. }
  1234. $account = $name = '';
  1235. if ($type == 1) {//微信
  1236. $account = '';
  1237. $name = '';
  1238. } elseif ($type == 2) {//支付宝
  1239. $userAlipayWhere['user_id'] = $userId;
  1240. $userAlipay = model('UserAlipay')->where($userAlipayWhere)->find();
  1241. if (empty($userAlipay)) {
  1242. throw new Exception('请绑定支付宝');
  1243. }
  1244. $account = $userAlipay['pay_no'];
  1245. $name = $userAlipay['realname'];
  1246. } elseif ($type == 3) {//银行
  1247. $userBankWhere['user_id'] = $userId;
  1248. $userBank = model('UserBank')->where($userBankWhere)->find();
  1249. if (empty($userBank)) {
  1250. throw new Exception('请绑定银行卡');
  1251. }
  1252. $account = $userBank['bank_no'];
  1253. $name = $userBank['realname'];
  1254. }
  1255. $data = [
  1256. 'user_id' => $userId,//用户ID
  1257. 'money' => $inputMoney,//金额
  1258. 'handingfee' => $platformMoney,//手续费
  1259. 'real_money' => bcsub($inputMoney,$platformMoney,2),//金额
  1260. 'taxes' => 0.00,//税费
  1261. 'type' => $typeStr,//类型
  1262. 'account' => $account,//提现账户
  1263. 'name' => $name,//真实姓名
  1264. //'memo' => '',//备注
  1265. //'orderid' => '',//订单号
  1266. //'transactionid' => '',//流水号
  1267. 'status' => 'created',//状态:created=申请中,successed=成功,rejected=已拒绝
  1268. //'transfertime' => '',//转账时间
  1269. 'createtime' => time(),//添加时间
  1270. ];
  1271. $withdrawRes = model('Withdraw')->insertGetId($data);
  1272. if (!$withdrawRes) {
  1273. throw new Exception('提现失败');
  1274. }
  1275. Db::commit();
  1276. $this->success('操作成功待审核');
  1277. } catch (Exception $e) {
  1278. Db::rollback();
  1279. $this->error($e->getMessage());
  1280. }
  1281. }
  1282. /**
  1283. * 提现列表
  1284. * @return void
  1285. */
  1286. public function withdrawalList()
  1287. {
  1288. try {
  1289. $field = 'id,money,type,status,createtime,transfertime';
  1290. $where=[];
  1291. $where['user_id'] = $this->auth->id;
  1292. //$where['status'] = 'successed';//状态:created=申请中,successed=成功,rejected=已拒绝
  1293. $result = model('Withdraw')->field($field)->where($where)->autopage()->order('createtime desc')->select();
  1294. if (!empty($result)) {
  1295. foreach ($result as $key => &$value) {
  1296. $value['money'] = '-'.$value['money'];
  1297. $value['createtime'] = !empty($value['createtime']) ? date('Y-m-d H:i', $value['createtime']) : '';
  1298. $value['transfertime'] = !empty($value['transfertime']) ? date('Y-m-d H:i', $value['transfertime']) : '';
  1299. }
  1300. }
  1301. $this->success('获取成功',$result);
  1302. } catch (Exception $e) {
  1303. $this->error($e->getMessage());
  1304. }
  1305. }
  1306. }