Usercenter.php 54 KB

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