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