Usercenter.php 54 KB

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