Usercenter.php 53 KB

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