Usercenter.php 50 KB

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