Usercenter.php 52 KB

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