Usercenter.php 55 KB

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