Usercenter.php 53 KB

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