Usercenter.php 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438
  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,jewel,
  44. age_id,constellation_id,province_id,city_id,desc,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($this->auth->id,$val['user_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. $where = [];
  570. $where["id"] = $this->auth->id;
  571. $data = [];
  572. $avatar && $data["avatar"] = $avatar;
  573. if($nickname){
  574. if (mb_strlen($nickname) > 30) {
  575. $this->error('用户昵称最多支持30个汉字或组合');
  576. }
  577. $data["nickname"] = $nickname;
  578. }
  579. $gender && $data["gender"] = $gender;
  580. $age && $data["age"] = $age;
  581. $image && $data["image"] = $image;
  582. $ageId && $data['age_id'] = $ageId;
  583. $constellationId && $data['constellation_id'] = $constellationId;
  584. $provinceId && $data['province_id'] = $provinceId;
  585. $cityId && $data['city_id'] = $cityId;
  586. $desc && $data['desc'] = $desc;
  587. $res = $this->userModel->update($data,$where);
  588. if($res) {
  589. $user = $this->userModel->where($where)->find();
  590. if (!empty($user['nickname']) && !empty($user['avatar']) && !empty($user['age_id']) && $user['has_info']==0) {
  591. $data['has_info'] = 1;
  592. $this->userModel->update($data,$where);
  593. }
  594. $this->success("修改成功!");
  595. } else {
  596. $this->error("网络错误,请稍后重试!");
  597. }
  598. }*/
  599. /**
  600. * 编辑个人信息(修改昵称和头像需要后台审核)
  601. */
  602. /*public function editUser() {
  603. $avatar = $this->request->request('avatar'); // 头像
  604. $nickname = $this->request->request('nickname'); // 昵称
  605. if (!$avatar && !$nickname) {
  606. $this->error(__('请输入要修改的信息'));
  607. }
  608. $data = [];
  609. if ($avatar && $avatar != $this->auth->avatar) {
  610. $data["pre_avatar"] = $avatar;
  611. }
  612. if($nickname && $nickname != $this->auth->nickname){
  613. if (mb_strlen($nickname) > 8) {
  614. $this->error('用户昵称最多支持8个汉字或组合');
  615. }
  616. $data["pre_nickname"] = $nickname;
  617. }
  618. if (!empty($data)) {
  619. $data['need_check'] = 1;
  620. $where["id"] = $this->auth->id;
  621. $res = $this->userModel->update($data,$where);
  622. if(!$res) {
  623. $this->error("网络错误,请稍后重试!");
  624. }
  625. }
  626. $this->success("修改成功!");
  627. }*/
  628. /**
  629. * 主播申请
  630. */
  631. public function anchorApply() {
  632. $type_id = $this->request->request('type_id',0); // 技能分类ID
  633. $party_type_id = $this->request->request('party_type_id'); //分类ID
  634. $desc = $this->request->request('desc'); // 申请备注
  635. if (!$party_type_id && !$desc) {
  636. $this->error(__('Invalid parameters'));
  637. }
  638. $useranchorModel = new \app\common\model\UserAnchor();
  639. $data = [];
  640. $data["user_id"] = $this->auth->id;
  641. $data["type_id"] = $type_id;
  642. $data["party_type_id"] = $party_type_id;
  643. if($useranchorModel->where($data)->find()) $this->error(__('您已申请过该类型的主播,请勿重复申请!'));
  644. $data["desc"] = $desc;
  645. $data["createtime"] = time();
  646. $res = $useranchorModel->insertGetId($data);
  647. if($res) {
  648. \app\common\model\User::update(["is_anchor"=>1],["id"=>$this->auth->id]);
  649. $vbot = new \addons\vbot\Vbot();
  650. $vbot->vbotSendMsg('Anchor_Application_Notice', [], []);
  651. $this->success("申请发送成功!");
  652. } else {
  653. $this->error("网络错误,请稍后重试");
  654. }
  655. }
  656. /**
  657. * 实名认证
  658. */
  659. public function authApply() {
  660. $realname = $this->request->request('realname'); // 真实姓名
  661. $idcard = $this->request->request('idcard'); // 身份证号
  662. $zimage = $this->request->request('zimage'); // 身份证正面照
  663. $fimage = $this->request->request('fimage'); // 身份证反面照
  664. if (!$realname && !$idcard && !$zimage && !$fimage) {
  665. $this->error(__('Invalid parameters'));
  666. }
  667. $userauthModel = new \app\common\model\UserAuth();
  668. $data = [];
  669. $data["user_id"] = $this->auth->id;
  670. //$data["idcard"] = $idcard;
  671. $userAuth = $userauthModel->where($data)->find();
  672. if (!empty($userAuth)) {
  673. if(in_array($userAuth['status'],[0,1])) $this->error('您已经申请过了,请勿重复操作!');
  674. }
  675. // 测试需要 开始
  676. $data["realname"] = $realname;
  677. $zimage && $data["zimage"] = $zimage;
  678. $fimage && $data["fimage"] = $fimage;
  679. $data["status"] = 1;
  680. if (!empty($userAuth)) {
  681. $data["updatetime"] = time();
  682. $authWhere['user_id'] = $this->auth->id;
  683. $res = $userauthModel->where($authWhere)->update($data);
  684. } else {
  685. $data["createtime"] = time();
  686. $res = $userauthModel->insertGetId($data);
  687. }
  688. if($res) {
  689. \app\common\model\User::update(["is_auth"=>2],["id"=>$this->auth->id]);
  690. $this->success("恭喜,实名认证成功!");
  691. } else {
  692. $this->error("网络错误,请稍后重试");
  693. }
  694. // 测试需要 结束
  695. // 实名认证验证
  696. $configInfo = config("auth");
  697. $outh = new outh($configInfo["api_url"],$configInfo["customer_code"],$configInfo["private_key"],$configInfo["key"]);
  698. $out_trade_no = date("YmdHis").rand(1000,9999);
  699. $ret = $outh->toVerify($out_trade_no,$realname,$idcard);
  700. if(isset($ret["code"])) {
  701. if($ret["code"] == "1008") {
  702. $this->error(__('身份证格式错误'));
  703. }
  704. if($ret["code"] == "1009") {
  705. $this->error(__('身份证格式错误'));
  706. }
  707. if($ret["code"] == "0001") {
  708. $this->error(__('姓名和身份证号不匹配!'));
  709. }
  710. if($ret["code"] == "0000") {
  711. $data["realname"] = $realname;
  712. $zimage && $data["zimage"] = $zimage;
  713. $fimage && $data["fimage"] = $fimage;
  714. $data["status"] = 1;
  715. $data["createtime"] = time();
  716. $res = $userauthModel->insertGetId($data);
  717. if($res) {
  718. \app\common\model\User::update(["is_auth"=>2],["id"=>$this->auth->id]);
  719. $this->success("恭喜,实名认证成功!");
  720. } else {
  721. $this->error("网络错误,请稍后重试");
  722. }
  723. }
  724. } else {
  725. $this->error("网络错误,请稍后重试");
  726. }
  727. }
  728. /**
  729. * 获取主播分类
  730. */
  731. public function getAnchorType() {
  732. $this->success("获取成功!",\app\common\model\UserAnchorType::select());
  733. }
  734. /**
  735. * 加入黑名单
  736. */
  737. public function addBlacklist() {
  738. Db::startTrans();
  739. try {
  740. $black_user_id = $this->request->request('black_user_id'); // 黑名单用户ID
  741. if (!$black_user_id) {
  742. throw new Exception(__('Invalid parameters'));
  743. }
  744. $userblacklistModel = new \app\common\model\UserBlacklist();
  745. $data = [];
  746. $data["user_id"] = $this->auth->id;
  747. $data["black_user_id"] = $black_user_id;
  748. if($userblacklistModel->where($data)->find()) $this->error(__('已在黑名单!'));
  749. $data["createtime"] = time();
  750. $res = $userblacklistModel->insertGetId($data);
  751. if(!$res) {
  752. throw new Exception("网络错误,请稍后重试");
  753. }
  754. //im加入黑名单
  755. $tenimService = new TenimService();
  756. $params = [
  757. 'user_id' => $this->auth->id,
  758. 'black_user_ids' => [(string)$black_user_id],
  759. ];
  760. $imResult = $tenimService->addBlack($params);
  761. if (!$imResult['status']) {
  762. throw new Exception($imResult['msg']);
  763. }
  764. Db::commit();
  765. $this->success("加入成功!");
  766. } catch (Exception $e) {
  767. Db::rollback();
  768. $this->error($e->getMessage());
  769. }
  770. }
  771. /**
  772. * 获取黑名单用户
  773. */
  774. public function getBlacklist() {
  775. $page = $this->request->request('page',1); // 分页
  776. $pageNum = $this->request->request('pageNum',10); // 分页
  777. // 分页搜索构建
  778. $pageStart = ($page-1)*$pageNum;
  779. $userblacklistModel = new \app\common\model\UserBlacklist();// ->limit($pageStart,$pageNum)
  780. $where = [];
  781. $where["a.user_id"] = $this->auth->id;
  782. $list = $userblacklistModel->alias("a")
  783. ->field("a.id,a.black_user_id,u.avatar,u.nickname,u.level,u.gender")
  784. ->join("hx_user u","u.id = a.black_user_id")
  785. ->where($where)
  786. ->limit($pageStart,$pageNum)
  787. ->select();
  788. if($list) {
  789. $this->success("获取成功!",$list);
  790. } else {
  791. $this->success("数据为空",[]);
  792. }
  793. }
  794. /**
  795. * 移除用户黑名单
  796. */
  797. public function removeUserBlack() {
  798. Db::startTrans();
  799. try {
  800. $id = $this->request->request('id'); // 黑名单ID
  801. $userId = $this->request->request('user_id'); // 用户ID
  802. if (!$id && !$userId) {
  803. throw new Exception(__('Invalid parameters'));
  804. }
  805. $userblacklistModel = new \app\common\model\UserBlacklist();
  806. $where = [];
  807. $id && $where["id"] = $id;
  808. if ($userId) {
  809. $where['user_id'] = $this->auth->id;
  810. $where['black_user_id'] = $userId;
  811. }
  812. $userBlack = $userblacklistModel->where($where)->find();
  813. if (empty($userBlack)) {
  814. throw new Exception('未找到黑名单信息');
  815. }
  816. $blackUserId = isset($userBlack['black_user_id']) ? $userBlack['black_user_id'] : 0;
  817. $res = false;
  818. if (!empty($userBlack)) {
  819. $res = $userblacklistModel->where($where)->delete();
  820. }
  821. if(!$res) {
  822. $this->error("网络错误,请稍后重试!");
  823. }
  824. //im加入黑名单
  825. if (!empty($blackUserId)) {
  826. $tenimService = new TenimService();
  827. $params = [
  828. 'user_id' => $this->auth->id,
  829. 'black_user_ids' => [(string)$blackUserId],
  830. ];
  831. $imResult = $tenimService->delBlack($params);
  832. if (!$imResult['status']) {
  833. throw new Exception($imResult['msg']);
  834. }
  835. }
  836. Db::commit();
  837. $this->success("移除成功!",$res);
  838. } catch (Exception $e) {
  839. Db::rollback();
  840. $this->error($e->getMessage());
  841. }
  842. }
  843. /**
  844. * 举报用户
  845. */
  846. /*public function addReport() {
  847. $ruser_id = $this->request->request('ruser_id'); // 被举报用户ID
  848. $content = $this->request->request('content'); // 举报内容
  849. $image = $this->request->request('image'); // 图片描述(多个用半角逗号隔开)
  850. if (!$ruser_id) {
  851. $this->error(__('Invalid parameters'));
  852. }
  853. $userreportModel = new \app\common\model\UserReport();
  854. $data = [];
  855. $data["user_id"] = $this->auth->id;
  856. $data["reportable_id"] = $ruser_id;
  857. $data['reportable_type'] = $this->getModelName('user');
  858. $data["content"] = $content;
  859. $data["image"] = $image;
  860. $data["createtime"] = time();
  861. $res = $userreportModel->insertGetId($data);
  862. if($res) {
  863. $this->success("举报成功!");
  864. } else {
  865. $this->error("网络错误,请稍后重试");
  866. }
  867. }*/
  868. /**
  869. * 举报
  870. */
  871. /*public function addReportNew() {
  872. $params = $this->request->param();
  873. $validate = new Report();
  874. $result = $validate->check($params);
  875. if (!$result) {
  876. $this->error($validate->getError());
  877. }
  878. $userreportModel = new \app\common\model\UserReport();
  879. $data = [];
  880. $data["user_id"] = $this->auth->id;
  881. $data["reportable_id"] = $params['reportable_id'];
  882. $data['reportable_type'] = $this->getModelName($params['reportable_type']);
  883. $data["content"] = $params['content'];
  884. $data["image"] = $params['image'];
  885. $data["createtime"] = time();
  886. $res = $userreportModel->insertGetId($data);
  887. if($res) {
  888. $this->success("举报成功!");
  889. } else {
  890. $this->error("网络错误,请稍后重试");
  891. }
  892. }*/
  893. /**
  894. * redis 数据恢复---非redis数据丢失请勿使用!!!!
  895. */
  896. public function shujuhuifu() {
  897. $key = $this->request->request("key");// 操作验证 123456
  898. if($key != 123456) {
  899. $this->error(__('Invalid parameters'));
  900. }
  901. $giftuserpartyModel = new \app\common\model\GiftUserParty();
  902. $redis = new Redis();
  903. $redisconfig = config("redis");
  904. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  905. if ($redisconfig['redis_pwd']) {
  906. $redis->auth($redisconfig['redis_pwd']);
  907. }
  908. if($redisconfig['redis_selectdb'] > 0){
  909. $redis->select($redisconfig['redis_selectdb']);
  910. }
  911. // 获取本周第一天
  912. $weekday = $this->firstOfWeek(date("Y-m-d H:i:s"));
  913. // 获取本月第一天
  914. $monthday = date("Ym01");
  915. $where = [];
  916. $where["createtime"] = ["gt",strtotime($weekday)];
  917. $list1 = $giftuserpartyModel->where($where)->select();
  918. foreach($list1 as $k => $v) {
  919. // 添加redis记录做财富排行榜周榜用
  920. $redis->zIncrBy("jewel_get_".$v["party_id"].":".$weekday,$v["value"],$v["user_to_id"]);
  921. // 添加redis记录做贡献排行榜周榜用
  922. $redis->zIncrBy("jewel_to_".$v["party_id"].":".$weekday,$v["value"],$v["user_id"]);
  923. }
  924. $where = [];
  925. $where["createtime"] = ["gt",strtotime(date("Y-m-01"))];
  926. $list2 = $giftuserpartyModel->where($where)->select();
  927. foreach($list2 as $k => $v) {
  928. // 添加redis记录做财富排行榜月榜用
  929. $redis->zIncrBy("jewel_get_".$v["party_id"].":".$monthday,$v["value"],$v["user_to_id"]);
  930. // 添加redis记录做贡献排行榜月榜用
  931. $redis->zIncrBy("jewel_to_".$v["party_id"].":".$monthday,$v["value"],$v["user_id"]);
  932. }
  933. $this->success("执行成功!");
  934. }
  935. /**
  936. * 获取用户钻石余额
  937. */
  938. public function getUserJewel() {
  939. //用户钱包
  940. $data = Db::name('user_wallet')->field("jewel,money")->where('user_id',$this->auth->id)->find();
  941. return $this->success("获取成功!",$data);
  942. }
  943. /**
  944. * 获取用户等级说明
  945. */
  946. public function getLevelExplain() {
  947. $data = \app\common\model\UserLevelExplain::field("title,content")->select();
  948. return $this->success("获取成功!",$data);
  949. }
  950. /**
  951. * 获取用户等级信息
  952. */
  953. public function getUserLevelInfo() {
  954. $res = [];$exstart = 0;$exend = 0;
  955. $userModel = new \app\common\model\User();
  956. $userInfo = $userModel->field("id,nickname,avatar,level,empirical")->where(["id"=>$this->auth->id])->find();
  957. if(!$userInfo) {
  958. $this->error("用户信息获取失败!");
  959. }
  960. $res["avatar"] = $userInfo['avatar'];
  961. $res["nickname"] = $userInfo['nickname'];
  962. // 获取用户当前经验值对应等级
  963. $userconfigModel = new \app\common\model\UserLevelConfig();
  964. $where = [];
  965. $where["empirical"] = ["elt",$userInfo["empirical"]];
  966. $userexplainstart = $userconfigModel->where($where)->order("empirical","desc")->limit(1)->select();
  967. $where = [];
  968. $where["empirical"] = ["gt",$userInfo["empirical"]];
  969. $userexplainend = $userconfigModel->where($where)->order("empirical","asc")->limit(1)->select();
  970. if(!$userexplainstart && !$userexplainend) {
  971. $this->error("经验等级信息获取失败!");
  972. } elseif(!$userexplainstart && $userexplainend) {
  973. $res["level_start"] = 0;
  974. $res["level_end"] = $userexplainend[0]["level"];
  975. } elseif($userexplainstart && !$userexplainend) {
  976. $res["level_start"] = $userexplainstart[0]["level"];
  977. $res["level_end"] = $userexplainstart[0]["level"];
  978. } elseif($userexplainstart && $userexplainend) {
  979. $res["level_start"] = $userexplainstart[0]["level"];
  980. $res["level_end"] = $userexplainend[0]["level"];
  981. }
  982. $userexplainstart && $exstart = $userexplainstart[0]["empirical"];
  983. $userexplainend && $exend = $userexplainend[0]["empirical"];
  984. $r1 = $exend-$exstart; // 等级经验值差
  985. $r2 = $userInfo["empirical"]-$exstart; // 当前等级与最低等级经验值差
  986. $r3 = $exend-$userInfo["empirical"]; // 还需多少经验值升级
  987. if($r1 == 0) {
  988. $res["level_rate"] = 1;
  989. } elseif($r2 == 0) {
  990. $res["level_rate"] = 0;
  991. if($res["level_start"] == $res["level_end"]) {
  992. $res["level_rate"] = 1;
  993. }
  994. } else {
  995. $res["level_rate"] = intval(($r2/$r1)*100)/100;
  996. }
  997. $res["to_up_need"] = $r3>0?$r3:0;
  998. // // 满级
  999. // if($r3 == 0 && !$userexplainend) {
  1000. // $res["level_rate"] = 1;
  1001. // }
  1002. $this->success("获取成功!",$res);
  1003. }
  1004. /**
  1005. * 邀请
  1006. * @return void
  1007. */
  1008. public function addInvite()
  1009. {
  1010. try {
  1011. $inviteNo = $this->request->param('invite_no','');
  1012. $userId = $this->auth->id;
  1013. if (empty($inviteNo)) {
  1014. throw new Exception('参数错误');
  1015. }
  1016. $where['invite_no'] = $inviteNo;
  1017. $userField = 'id,invite_no,pre_userid';
  1018. $user = model('User')->field($userField)->where($where)->find();
  1019. if (empty($user)) {
  1020. throw new Exception('无效的邀请码');
  1021. }
  1022. //判断邀请码用户不能是自己的下级
  1023. if ($user['pre_userid'] == $userId) {
  1024. throw new Exception('对方已被您邀请过');
  1025. }
  1026. $userInviteWhere['invite_user_id'] = $userId;
  1027. $userInvite = model('UserInvite')->where($userInviteWhere)->find();
  1028. if (!empty($userInvite)) {
  1029. throw new Exception('您已经被邀请过');
  1030. }
  1031. $userInviteData = [
  1032. 'user_id' => $user['id'],
  1033. 'invite_user_id' => $userId,
  1034. 'createtime' => time(),
  1035. ];
  1036. $userInviteRes = model('UserInvite')->insertGetId($userInviteData);
  1037. if (!$userInviteRes) {
  1038. throw new Exception('邀请失败');
  1039. }
  1040. $userUpWhere['id'] = $userId;
  1041. $userUpdate = ['pre_userid'=>$user['id']];
  1042. $userUpdateRes = model('User')->where($userUpWhere)->update($userUpdate);
  1043. if (!$userUpdateRes) {
  1044. throw new Exception('更新邀请人失败');
  1045. }
  1046. $this->success('邀请成功');
  1047. } catch (Exception $e) {
  1048. $this->error($e->getMessage());
  1049. }
  1050. }
  1051. /**
  1052. * 邀请详情
  1053. * @return void
  1054. */
  1055. public function inviteInfo()
  1056. {
  1057. try {
  1058. $userId = $this->auth->id;
  1059. $field = 'id,invite_no';
  1060. $where['id'] = $userId;
  1061. $user = model('User')->field($field)->where($where)->find();
  1062. $inviteNo = isset($user['invite_no']) ? $user['invite_no'] : '';
  1063. $todayNow = day_now();
  1064. $todayStart = $todayNow[0];
  1065. $todayEnd = $todayNow[1]+1;
  1066. $userMoneyLogWhere['user_id'] = $userId;
  1067. $userMoneyLogWhere['type'] = 103;
  1068. $appendWhere['createtime'] = [['egt', $todayStart],['lt', $todayEnd],'and'];
  1069. $todayMoney = model('UserMoneyLog')->where($userMoneyLogWhere)->where($appendWhere)->sum('value');
  1070. $totalMoney = model('UserMoneyLog')->where($userMoneyLogWhere)->sum('value');
  1071. //本周
  1072. $weekNow = week_now();
  1073. $userInviteWhere['user_id'] = $userId;
  1074. $userInviteAppendWhere['createtime'] = [['egt', $weekNow[0]],['lt', $weekNow[1]+1],'and'];
  1075. $userInviteModel = model('UserInvite');
  1076. $weekNowNum = $userInviteModel->where($userInviteWhere)->where($userInviteAppendWhere)->count();
  1077. //上周
  1078. $lastWeek = last_week();
  1079. $appendLastWhere['createtime'] = [['egt', $lastWeek[0]],['lt', $lastWeek[1]+1],'and'];
  1080. $lastWeekNum = $userInviteModel->where($userInviteWhere)->where($appendLastWhere)->count();
  1081. //全部
  1082. $totalNum = $userInviteModel->where($userInviteWhere)->count();
  1083. $inviteMoney = config('site.invite_money');
  1084. $inviteRule = config('site.invite_rule');
  1085. $result = [
  1086. 'invite_money' => (int)$inviteMoney,
  1087. 'invite_no' => $inviteNo,//邀请码
  1088. 'today_money' => $todayMoney,//今日收益
  1089. 'total_money' => $totalMoney,//总收益
  1090. 'week_now_num' => $weekNowNum,//本周邀请数
  1091. 'last_week_num' => $lastWeekNum,//上周邀请数
  1092. 'total_num' => $totalNum,//总邀请数
  1093. 'invite_rule' => $inviteRule,//规则说明
  1094. ];
  1095. $this->success('获取成功',$result);
  1096. } catch (Exception $e) {
  1097. $this->error($e->getMessage());
  1098. }
  1099. }
  1100. /**
  1101. * 邀请列表
  1102. * @return void
  1103. */
  1104. public function inviteList()
  1105. {
  1106. try {
  1107. $userId = $this->auth->id;
  1108. $where['user_id'] = $userId;
  1109. $userInvite = model('UserInvite')->where($where)->with(['user'=>function($uQuery){
  1110. $uQuery->field('id,avatar,u_id,nickname');
  1111. }])->autopage()->order('createtime desc')->select();
  1112. $result = [];
  1113. if (!empty($userInvite)) {
  1114. foreach ($userInvite as $key => $value) {
  1115. $user = isset($value['user']) ? $value['user'] : [];
  1116. $temp = [
  1117. 'user_id' => isset($user['id']) ? $user['id'] : 0,
  1118. 'u_id' => isset($user['u_id']) ? $user['u_id'] : 0,
  1119. 'avatar' => isset($user['avatar']) ? $user['avatar'] : 0,
  1120. 'nickname' => isset($user['nickname']) ? $user['nickname'] : 0,
  1121. 'create_time_text' => !empty($value['createtime']) ? date('Y-m-d', $value['createtime']) : '',
  1122. ];
  1123. $result[] = $temp;
  1124. }
  1125. }
  1126. $this->success('获取成功',$result);
  1127. } catch (Exception $e) {
  1128. $this->error($e->getMessage());
  1129. }
  1130. }
  1131. /**
  1132. * 钻石兑换记录
  1133. * @return void
  1134. */
  1135. public function exchangeList()
  1136. {
  1137. try {
  1138. $field = 'id,sound_coin,createtime';
  1139. $where['user_id'] = $this->auth->id;
  1140. $result = model('UserExchangeLog')->field($field)->where($where)->autopage()->order('createtime desc')->select();
  1141. if (!empty($result)) {
  1142. foreach ($result as $key => &$value) {
  1143. $value['jewel'] = '+'.$value['sound_coin'];
  1144. $value['createtime'] = !empty($value['createtime']) ? date('Y-m-d H:i',$value['createtime']) : '';
  1145. unset($value['sound_coin']);
  1146. }
  1147. }
  1148. $this->success('获取成功',$result);
  1149. } catch (Exception $e) {
  1150. $this->error($e->getMessage());
  1151. }
  1152. }
  1153. /**
  1154. * 钻石充值记录
  1155. * @return void
  1156. */
  1157. public function rechargeList()
  1158. {
  1159. try {
  1160. $field = 'id,detail,mode,value,createtime';
  1161. $where['user_id'] = $this->auth->id;
  1162. $result = model('UserJewelLog')->field($field)->where($where)->autopage()->order('createtime desc')->select();
  1163. if (!empty($result)) {
  1164. foreach ($result as $key => &$value) {
  1165. $value['value'] = $value['mode'].$value['value'];
  1166. $value['createtime'] = !empty($value['createtime']) ? date('Y-m-d H:i',$value['createtime']) : '';
  1167. }
  1168. }
  1169. $this->success('获取成功',$result);
  1170. } catch (Exception $e) {
  1171. $this->error($e->getMessage());
  1172. }
  1173. }
  1174. /**
  1175. * 提现配置列表
  1176. * @return void
  1177. */
  1178. public function withdrawalConfigList()
  1179. {
  1180. try {
  1181. $field = 'id,money,real_money';
  1182. $result = model('WithdrawalConfig')->field($field)->autopage()->order('weigh asc')->select();
  1183. if (!empty($result)) {
  1184. //设置是否使用自定义
  1185. $withdrawDefine = config('site.withdraw_define');
  1186. if ($withdrawDefine == 1) {
  1187. $fieldArr = [[
  1188. 'id' => -1,
  1189. 'money' => 0,
  1190. 'real_money' => 0.00,
  1191. ],];
  1192. $result = array_merge($result,$fieldArr);
  1193. }
  1194. }
  1195. $this->success('获取成功',$result);
  1196. } catch (Exception $e) {
  1197. $this->error($e->getMessage());
  1198. }
  1199. }
  1200. /**
  1201. * 提现
  1202. * @return void
  1203. */
  1204. public function withdrawal()
  1205. {
  1206. Db::startTrans();
  1207. try {
  1208. $withdrawConfigId = $this->request->param('id',0);
  1209. $money = $this->request->param('money',0.00);
  1210. $type = $this->request->param('type',0);
  1211. $userId = $this->auth->id;
  1212. $isAnchor = $this->auth->is_anchor;
  1213. $userMoney = $this->auth->money;
  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, '-', $userMoney, '申请提现', 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. $realMoney = bcsub($inputMoney,$platformMoney,2);
  1280. if ($realMoney < 0.1) {
  1281. throw new Exception('输入金额请大于0.1');
  1282. }
  1283. $data = [
  1284. 'user_id' => $userId,//用户ID
  1285. 'money' => $inputMoney,//金额
  1286. 'handingfee' => $platformMoney,//手续费
  1287. 'real_money' => $realMoney,//金额
  1288. 'taxes' => 0.00,//税费
  1289. 'type' => $typeStr,//类型
  1290. 'account' => $account,//提现账户
  1291. 'name' => $name,//真实姓名
  1292. //'memo' => '',//备注
  1293. 'orderid' => getMillisecond() . mt_rand(1, 1000),//订单号
  1294. //'transactionid' => '',//流水号
  1295. 'status' => 'created',//状态:created=申请中,successed=成功,rejected=已拒绝
  1296. //'transfertime' => '',//转账时间
  1297. 'createtime' => time(),//添加时间
  1298. ];
  1299. $withdrawRes = model('Withdraw')->insertGetId($data);
  1300. if (!$withdrawRes) {
  1301. throw new Exception('提现失败');
  1302. }
  1303. Db::commit();
  1304. $vbot = new \addons\vbot\Vbot();
  1305. $vbot->vbotSendMsg('Withdrawal_Application_Notice', [], [
  1306. 'name' => $name,
  1307. 'account' => $account,
  1308. 'real_money' => $realMoney,
  1309. 'type' => $typeStr,
  1310. 'handingfee' => $platformMoney
  1311. ]);
  1312. $this->success('操作成功待审核');
  1313. } catch (Exception $e) {
  1314. Db::rollback();
  1315. $this->error($e->getMessage());
  1316. }
  1317. }
  1318. /**
  1319. * 提现列表
  1320. * @return void
  1321. */
  1322. public function withdrawalList()
  1323. {
  1324. try {
  1325. $field = 'id,money,type,status,createtime,transfertime';
  1326. $where=[];
  1327. $where['user_id'] = $this->auth->id;
  1328. //$where['status'] = 'successed';//状态:created=申请中,successed=成功,rejected=已拒绝
  1329. $result = model('Withdraw')->field($field)->where($where)->autopage()->order('createtime desc')->select();
  1330. if (!empty($result)) {
  1331. foreach ($result as $key => &$value) {
  1332. $value['money'] = '-'.$value['money'];
  1333. $value['createtime'] = !empty($value['createtime']) ? date('Y-m-d H:i', $value['createtime']) : '';
  1334. $value['transfertime'] = !empty($value['transfertime']) ? date('Y-m-d H:i', $value['transfertime']) : '';
  1335. }
  1336. }
  1337. $this->success('获取成功',$result);
  1338. } catch (Exception $e) {
  1339. $this->error($e->getMessage());
  1340. }
  1341. }
  1342. }