Usercenter.php 50 KB

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