Usercenter.php 48 KB

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