Usercenter.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862
  1. <?php
  2. namespace app\api\controller;
  3. use addons\epay\library\Service;
  4. use app\api\controller\Common;
  5. use app\api\validate\user\Report;
  6. use app\common\model\UserPower;
  7. use app\common\service\TenimService;
  8. use outh\outh;
  9. use think\Db;
  10. use app\common\controller\RedisLeaderboard;
  11. use Redis;
  12. use GatewayClient\Gateway;
  13. use think\Exception;
  14. /**
  15. * 会员中心接口
  16. */
  17. class UserCenter extends Common
  18. {
  19. protected $noNeedLogin = ['shujuhuifu','getAnchorType','getRecharConfig','getExchangeConfig','getLevelExplain'];
  20. protected $noNeedRight = '*';
  21. public function _initialize()
  22. {
  23. parent::_initialize();
  24. $this->userModel = new \app\common\model\User();
  25. }
  26. /**
  27. * 获取个人信息
  28. */
  29. public function getUserInfo() {
  30. $user_id = input("user_id");
  31. if (!$user_id) {
  32. $this->error(__('Invalid parameters'));
  33. }
  34. // 获取基本信息
  35. $where = [];
  36. $where["id"] = $user_id;
  37. $userInfo = $this->userModel->field("id,nickname,mobile,avatar,gender,u_id,level,age_id,province_id,city_id,desc,charm_level,wealth_level,job_id")->where($where)->find();
  38. if(!$userInfo){
  39. $this->error('不存在的用户');
  40. }
  41. $userInfo = info_domain_image($userInfo,['avatar']);
  42. //用户钱包
  43. $userwallet = Db::name('user_wallet')->where('user_id',$user_id)->find();
  44. $userInfo['wallet'] = $userwallet;
  45. $userInfoA = $this->userModel->getAppendData($userInfo);
  46. $userInfo['age_text'] = $userInfoA['age_text'];
  47. $userInfo['province_text'] = $userInfoA['province_text'];
  48. $userInfo['city_text'] = $userInfoA['city_text'];
  49. // $userInfo['friends_num'] = $userInfoA['friends_num'];
  50. $userInfo['look_num'] = $userInfoA['look_num'];
  51. //关注人数,粉丝人数
  52. $follow_num = Db::name('user_follow')->where(['uid'=>$user_id])->count('id');
  53. $fans_num = Db::name('user_follow')->where(['follow_uid'=>$user_id])->count('id');
  54. $userinfo['follow_num'] = $follow_num;
  55. $userinfo['fans_num'] = $fans_num;
  56. // 查看者是否已关注
  57. $userInfo["is_follow"] = $this->is_follow($this->auth->id,$user_id);
  58. $userInfo['is_friend'] = $this->is_friend($this->auth->id,$user_id);
  59. $userInfo['is_black'] = $this->is_black($this->auth->id,$user_id);
  60. // 获取用户在派对直播间情况信息
  61. $redis = new Redis();
  62. $redisconfig = config("redis");
  63. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  64. if ($redisconfig['redis_pwd']) {
  65. $redis->auth($redisconfig['redis_pwd']);
  66. }
  67. if($redisconfig['redis_selectdb'] > 0){
  68. $redis->select($redisconfig['redis_selectdb']);
  69. }
  70. $livingUserPartyId = $redis->hGet("livingUser", $user_id);
  71. $userInfo['party_info'] = json([]);
  72. if ($livingUserPartyId) {
  73. $party = \app\common\model\Party::where('id',$livingUserPartyId)->field('id,room_type')->find();
  74. $userInfo['party_info'] = ['party_id' => $party['id'], 'room_type' => $party['room_type']];
  75. }
  76. $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();
  77. if ($memberinfo) {
  78. $userInfo['memberinfo'] = $memberinfo;
  79. }
  80. //家族信息
  81. $guildField = 'g.id,g.g_id,g.user_id,g.party_id,g.name,g.image,g.desc,g.member,g.status';
  82. $guildWhere['gm.user_id'] = $user_id;
  83. $guildWhere['g.status'] = 1;
  84. $guildInfo = model('Guild')->alias('g')->field($guildField)
  85. ->join('guild_member gm','gm.guild_id = g.id','LEFT')
  86. ->where($guildWhere)->order('id desc')->find();
  87. $userInfo['guild_info'] = !empty($guildInfo) ? $guildInfo : [];
  88. $guildStatus = -2;
  89. if (!empty($guildInfo)) {
  90. $guildStatus = (int)$guildInfo['status'];
  91. }
  92. $userInfo['guild_status'] = $guildStatus;//家族状态:公会状态:0=待审核,1=正常,-1=已解散,-2无公会
  93. //访客记录
  94. if ($this->auth->id != $user_id) {
  95. $visit_data = [
  96. 'user_id' => $this->auth->id,
  97. 'visit_user_id' => $user_id,
  98. ];
  99. $visit_check = Db::name('user_visitlist')->where($visit_data)->find();
  100. if(empty($visit_check)){
  101. $visit_data['updatetime'] = time();
  102. Db::name('user_visitlist')->insertGetId($visit_data);
  103. }else{
  104. Db::name('user_visitlist')->where('id',$visit_check['id'])->update(['updatetime'=>time()]);
  105. }
  106. }
  107. $this->success("获取成功!",$userInfo);
  108. }
  109. /**
  110. * 获取最近访客
  111. * (消息)
  112. */
  113. public function getMyVisitList(){
  114. $list = Db::name('user_visitlist')->alias('uv')
  115. ->field('uv.user_id,uv.updatetime,user.nickname,user.avatar,user.gender,user.desc')
  116. ->join('user','uv.user_id = user.id','LEFT')
  117. ->where('uv.visit_user_id',$this->auth->id) //被访问者
  118. ->order('uv.id desc')->autopage()->select();
  119. $list = list_domain_image($list,['avatar']);
  120. if(!empty($list)){
  121. foreach($list as $key => &$val){
  122. //关注
  123. $val['is_follow'] = $this->is_follow($this->auth->id,$val['user_id']);
  124. }
  125. }
  126. $this->success(1,$list);
  127. }
  128. ///////////////////////////////////////////////////
  129. /**
  130. * 获取关注人列表.派对信息
  131. */
  132. public function getFollowsLive() {
  133. $is_online = $this->request->request("is_online");// 是否在线:1=直播中,0=未开播
  134. $page = $this->request->request('page',1); // 分页
  135. $pageNum = $this->request->request('pageNum',10); // 分页
  136. // 分页搜索构建
  137. $pageStart = ($page-1)*$pageNum;
  138. $is_online == 1 || $is_online = 0;
  139. $fanfollowModel = new \app\common\model\UserFansFollow();
  140. $where = [];
  141. $where["a.fans_id"] = $this->auth->id;
  142. $where["p.room_type"] = 2;
  143. $where["p.is_online"] = $is_online;
  144. if($is_online == 1) {
  145. $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";
  146. } else {
  147. $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";
  148. }
  149. $list = $fanfollowModel->alias("a")
  150. ->field($field)
  151. ->join("hx_user u","u.id = a.user_id")
  152. ->join("hx_party p","p.user_id = a.user_id")
  153. ->join("hx_party_type t","t.id = p.party_type","left")
  154. ->limit($pageStart,$pageNum)
  155. ->where($where)->select();
  156. if($list) {
  157. foreach($list as $k => $v) {
  158. $mod = isset($v["party_type"])?intval($v["party_type"])%5:1;
  159. if(isset($v["type_name"]) && $v["type_name"]) {
  160. $type_name = $v["type_name"];
  161. } else {
  162. $type_name = "普通房";
  163. }
  164. $list[$k]["party_type"] = $type_name;
  165. $list[$k]["party_type_color"] = $mod == 0?5:$mod;
  166. }
  167. $this->success("获取成功!",$list);
  168. } else {
  169. $this->success("数据为空!",[]);
  170. }
  171. }
  172. /**
  173. * 获取个人技能列表
  174. */
  175. public function getMySkillList() {
  176. $user_id = $this->request->request('user_id',0); // 用户ID
  177. $page = $this->request->request('page',1); // 分页
  178. $pageNum = $this->request->request('pageNum',10); // 分页
  179. if ($user_id == -1) {
  180. $user_id = $this->auth->id;
  181. } elseif($user_id>0) {
  182. $user_id = intval($user_id);
  183. } else {
  184. $this->error(__('Invalid parameters'));
  185. }
  186. // 分页搜索构建
  187. $pageStart = ($page-1)*$pageNum;
  188. $authModel = new \app\common\model\DispatchAuth();
  189. $where = [];
  190. $where["a.user_id"] = $user_id;
  191. $where["a.status"] = 1;
  192. $authskillList = $authModel->alias("a")
  193. ->field("a.id,ds.image,ds.name,a.voice,a.voice_time,a.price,a.is_main,ds.unit")
  194. ->join("hx_dispatch_skill ds","ds.id = a.skill_id")
  195. ->where($where)
  196. ->limit($pageStart,$pageNum)
  197. ->select();
  198. $this->success("获取成功!",$authskillList);
  199. }
  200. /**
  201. * 删除个人技能信息
  202. */
  203. public function delMySkillInfo() {
  204. $id = $this->request->request('id'); // 认证ID
  205. if (!$id) {
  206. $this->error(__('Invalid parameters'));
  207. }
  208. $authModel = new \app\common\model\DispatchAuth();
  209. $where = [];
  210. $where["id"] = $id;
  211. $where["user_id"] = $this->auth->id;
  212. $authInfo = $authModel->where($where)->find();
  213. if(!$authInfo) $this->error("技能认证未找到");
  214. // if($authInfo->is_main == 1) $this->error("请先取消主技能,再删除!");
  215. Db::startTrans();
  216. try{
  217. $res1 = $authInfo->delete();
  218. $res2 = \app\common\model\UserSkill::where(["user_id"=>$this->auth->id,"skill_id"=>$authInfo->skill_id])->delete();
  219. if($res1 && $res2) {
  220. Db::commit();
  221. $this->success("删除成功!");
  222. } else {
  223. $this->error("网络错误,请稍后重试!");
  224. }
  225. }catch (ValidateException $e) {
  226. Db::rollback();
  227. $this->error($e->getMessage());
  228. } catch (PDOException $e) {
  229. Db::rollback();
  230. $this->error($e->getMessage());
  231. } catch (Exception $e) {
  232. Db::rollback();
  233. $this->error($e->getMessage());
  234. }
  235. }
  236. /**
  237. * 修改个人技能信息
  238. */
  239. public function editMySkillInfo() {
  240. $price = $this->request->request('price'); // 价格
  241. $id = $this->request->request('id'); // 认证ID
  242. $is_main = $this->request->request('is_main'); // 是否设置为主技能
  243. if (!$id && !$price) {
  244. $this->error(__('Invalid parameters'));
  245. }
  246. $authModel = new \app\common\model\DispatchAuth();
  247. $where = [];
  248. $where["id"] = $id;
  249. if(!$authModel->where($where)->find()) $this->error("技能认证未找到");
  250. Db::startTrans();
  251. try{
  252. if($is_main == 1) {
  253. $where = [];
  254. $where["user_id"] = $this->auth->id;
  255. $authModel->update(["is_main"=>0],$where);
  256. }
  257. $where = [];
  258. $where["id"] = $id;
  259. $data = [];
  260. $data["price"] = $price;
  261. $data["is_main"] = $is_main;
  262. $res = $authModel->update($data,$where);
  263. $myAuthList = $authModel->where(["user_id"=>$this->auth->id,"is_main"=>1])->find();
  264. if(!$myAuthList) {
  265. $this->error("必须至少设置一个主技能");
  266. Db::rollback();
  267. }
  268. if($res) {
  269. Db::commit();
  270. $this->success("修改成功!",$data);
  271. } else {
  272. $this->error("网络错误,请稍后重试!");
  273. }
  274. }catch (ValidateException $e) {
  275. Db::rollback();
  276. $this->error($e->getMessage());
  277. } catch (PDOException $e) {
  278. Db::rollback();
  279. $this->error($e->getMessage());
  280. } catch (Exception $e) {
  281. Db::rollback();
  282. $this->error($e->getMessage());
  283. }
  284. }
  285. /**
  286. * 编辑个人信息(完善资料)
  287. */
  288. /*public function editUserInfo() {
  289. $avatar = $this->request->request('avatar'); // 头像
  290. $nickname = $this->request->request('nickname'); // 昵称
  291. $age = $this->request->request('age'); // 年龄
  292. $ageId = $this->request->request('age_id'); // 年龄段
  293. $gender = $this->request->request('gender'); // 性别 0=女,1=男
  294. $image = $this->request->request('image'); // 个人形象照
  295. $constellationId = $this->request->request('star_id'); //星座ID
  296. $provinceId = $this->request->request('province_id'); //省ID
  297. $cityId = $this->request->request('city_id'); //城市ID
  298. $desc = $this->request->request('desc'); //个性签名
  299. $where = [];
  300. $where["id"] = $this->auth->id;
  301. $data = [];
  302. $avatar && $data["avatar"] = $avatar;
  303. if($nickname){
  304. if (mb_strlen($nickname) > 30) {
  305. $this->error('用户昵称最多支持30个汉字或组合');
  306. }
  307. $data["nickname"] = $nickname;
  308. }
  309. $gender && $data["gender"] = $gender;
  310. $age && $data["age"] = $age;
  311. $image && $data["image"] = $image;
  312. $ageId && $data['age_id'] = $ageId;
  313. $constellationId && $data['constellation_id'] = $constellationId;
  314. $provinceId && $data['province_id'] = $provinceId;
  315. $cityId && $data['city_id'] = $cityId;
  316. $desc && $data['desc'] = $desc;
  317. $res = $this->userModel->update($data,$where);
  318. if($res) {
  319. $user = $this->userModel->where($where)->find();
  320. if (!empty($user['nickname']) && !empty($user['avatar']) && !empty($user['age_id']) && $user['has_info']==0) {
  321. $data['has_info'] = 1;
  322. $this->userModel->update($data,$where);
  323. }
  324. $this->success("修改成功!");
  325. } else {
  326. $this->error("网络错误,请稍后重试!");
  327. }
  328. }*/
  329. /**
  330. * 编辑个人信息(修改昵称和头像需要后台审核)
  331. */
  332. /*public function editUser() {
  333. $avatar = $this->request->request('avatar'); // 头像
  334. $nickname = $this->request->request('nickname'); // 昵称
  335. if (!$avatar && !$nickname) {
  336. $this->error(__('请输入要修改的信息'));
  337. }
  338. $data = [];
  339. if ($avatar && $avatar != $this->auth->avatar) {
  340. $data["pre_avatar"] = $avatar;
  341. }
  342. if($nickname && $nickname != $this->auth->nickname){
  343. if (mb_strlen($nickname) > 8) {
  344. $this->error('用户昵称最多支持8个汉字或组合');
  345. }
  346. $data["pre_nickname"] = $nickname;
  347. }
  348. if (!empty($data)) {
  349. $data['need_check'] = 1;
  350. $where["id"] = $this->auth->id;
  351. $res = $this->userModel->update($data,$where);
  352. if(!$res) {
  353. $this->error("网络错误,请稍后重试!");
  354. }
  355. }
  356. $this->success("修改成功!");
  357. }*/
  358. /**
  359. * 主播申请
  360. */
  361. public function anchorApply() {
  362. $type_id = $this->request->request('type_id',0); // 技能分类ID
  363. $party_type_id = $this->request->request('party_type_id'); //分类ID
  364. $desc = $this->request->request('desc'); // 申请备注
  365. if (!$party_type_id && !$desc) {
  366. $this->error(__('Invalid parameters'));
  367. }
  368. $useranchorModel = new \app\common\model\UserAnchor();
  369. $data = [];
  370. $data["user_id"] = $this->auth->id;
  371. $data["type_id"] = $type_id;
  372. $data["party_type_id"] = $party_type_id;
  373. if($useranchorModel->where($data)->find()) $this->error(__('您已申请过该类型的主播,请勿重复申请!'));
  374. $data["desc"] = $desc;
  375. $data["createtime"] = time();
  376. $res = $useranchorModel->insertGetId($data);
  377. if($res) {
  378. \app\common\model\User::update(["is_anchor"=>1],["id"=>$this->auth->id]);
  379. $vbot = new \addons\vbot\Vbot();
  380. $vbot->vbotSendMsg('Anchor_Application_Notice', [], []);
  381. $this->success("申请发送成功!");
  382. } else {
  383. $this->error("网络错误,请稍后重试");
  384. }
  385. }
  386. /**
  387. * 实名认证
  388. */
  389. public function authApply() {
  390. $realname = $this->request->request('realname'); // 真实姓名
  391. $idcard = $this->request->request('idcard'); // 身份证号
  392. $zimage = $this->request->request('zimage'); // 身份证正面照
  393. $fimage = $this->request->request('fimage'); // 身份证反面照
  394. if (!$realname && !$idcard && !$zimage && !$fimage) {
  395. $this->error(__('Invalid parameters'));
  396. }
  397. $userauthModel = new \app\common\model\UserAuth();
  398. $data = [];
  399. $data["user_id"] = $this->auth->id;
  400. //$data["idcard"] = $idcard;
  401. $userAuth = $userauthModel->where($data)->find();
  402. if (!empty($userAuth)) {
  403. if(in_array($userAuth['status'],[0,1])) $this->error('您已经申请过了,请勿重复操作!');
  404. }
  405. // 测试需要 开始
  406. $data["realname"] = $realname;
  407. $zimage && $data["zimage"] = $zimage;
  408. $fimage && $data["fimage"] = $fimage;
  409. $data["status"] = 1;
  410. if (!empty($userAuth)) {
  411. $data["updatetime"] = time();
  412. $authWhere['user_id'] = $this->auth->id;
  413. $res = $userauthModel->where($authWhere)->update($data);
  414. } else {
  415. $data["createtime"] = time();
  416. $res = $userauthModel->insertGetId($data);
  417. }
  418. if($res) {
  419. \app\common\model\User::update(["is_auth"=>2],["id"=>$this->auth->id]);
  420. $this->success("恭喜,实名认证成功!");
  421. } else {
  422. $this->error("网络错误,请稍后重试");
  423. }
  424. // 测试需要 结束
  425. // 实名认证验证
  426. $configInfo = config("auth");
  427. $outh = new outh($configInfo["api_url"],$configInfo["customer_code"],$configInfo["private_key"],$configInfo["key"]);
  428. $out_trade_no = date("YmdHis").rand(1000,9999);
  429. $ret = $outh->toVerify($out_trade_no,$realname,$idcard);
  430. if(isset($ret["code"])) {
  431. if($ret["code"] == "1008") {
  432. $this->error(__('身份证格式错误'));
  433. }
  434. if($ret["code"] == "1009") {
  435. $this->error(__('身份证格式错误'));
  436. }
  437. if($ret["code"] == "0001") {
  438. $this->error(__('姓名和身份证号不匹配!'));
  439. }
  440. if($ret["code"] == "0000") {
  441. $data["realname"] = $realname;
  442. $zimage && $data["zimage"] = $zimage;
  443. $fimage && $data["fimage"] = $fimage;
  444. $data["status"] = 1;
  445. $data["createtime"] = time();
  446. $res = $userauthModel->insertGetId($data);
  447. if($res) {
  448. \app\common\model\User::update(["is_auth"=>2],["id"=>$this->auth->id]);
  449. $this->success("恭喜,实名认证成功!");
  450. } else {
  451. $this->error("网络错误,请稍后重试");
  452. }
  453. }
  454. } else {
  455. $this->error("网络错误,请稍后重试");
  456. }
  457. }
  458. /**
  459. * 获取主播分类
  460. */
  461. public function getAnchorType() {
  462. $this->success("获取成功!",\app\common\model\UserAnchorType::select());
  463. }
  464. /**
  465. * redis 数据恢复---非redis数据丢失请勿使用!!!!
  466. */
  467. public function shujuhuifu() {
  468. $key = $this->request->request("key");// 操作验证 123456
  469. if($key != 123456) {
  470. $this->error(__('Invalid parameters'));
  471. }
  472. $giftuserpartyModel = new \app\common\model\GiftUserParty();
  473. $redis = new Redis();
  474. $redisconfig = config("redis");
  475. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  476. if ($redisconfig['redis_pwd']) {
  477. $redis->auth($redisconfig['redis_pwd']);
  478. }
  479. if($redisconfig['redis_selectdb'] > 0){
  480. $redis->select($redisconfig['redis_selectdb']);
  481. }
  482. // 获取本周第一天
  483. $weekday = $this->firstOfWeek(date("Y-m-d H:i:s"));
  484. // 获取本月第一天
  485. $monthday = date("Ym01");
  486. $where = [];
  487. $where["createtime"] = ["gt",strtotime($weekday)];
  488. $list1 = $giftuserpartyModel->where($where)->select();
  489. foreach($list1 as $k => $v) {
  490. // 添加redis记录做财富排行榜周榜用
  491. $redis->zIncrBy("jewel_get_".$v["party_id"].":".$weekday,$v["value"],$v["user_to_id"]);
  492. // 添加redis记录做贡献排行榜周榜用
  493. $redis->zIncrBy("jewel_to_".$v["party_id"].":".$weekday,$v["value"],$v["user_id"]);
  494. }
  495. $where = [];
  496. $where["createtime"] = ["gt",strtotime(date("Y-m-01"))];
  497. $list2 = $giftuserpartyModel->where($where)->select();
  498. foreach($list2 as $k => $v) {
  499. // 添加redis记录做财富排行榜月榜用
  500. $redis->zIncrBy("jewel_get_".$v["party_id"].":".$monthday,$v["value"],$v["user_to_id"]);
  501. // 添加redis记录做贡献排行榜月榜用
  502. $redis->zIncrBy("jewel_to_".$v["party_id"].":".$monthday,$v["value"],$v["user_id"]);
  503. }
  504. $this->success("执行成功!");
  505. }
  506. /**
  507. * 获取用户钻石余额
  508. */
  509. public function getUserJewel() {
  510. //用户钱包
  511. $data = Db::name('user_wallet')->field("jewel,money")->where('user_id',$this->auth->id)->find();
  512. return $this->success("获取成功!",$data);
  513. }
  514. /**
  515. * 获取用户等级说明
  516. */
  517. public function getLevelExplain() {
  518. $data = \app\common\model\UserLevelExplain::field("title,content")->select();
  519. return $this->success("获取成功!",$data);
  520. }
  521. /**
  522. * 获取用户等级信息
  523. */
  524. public function getUserLevelInfo() {
  525. $res = [];$exstart = 0;$exend = 0;
  526. $userModel = new \app\common\model\User();
  527. $userInfo = $userModel->field("id,nickname,avatar,level,empirical")->where(["id"=>$this->auth->id])->find();
  528. if(!$userInfo) {
  529. $this->error("用户信息获取失败!");
  530. }
  531. $res["avatar"] = $userInfo['avatar'];
  532. $res["nickname"] = $userInfo['nickname'];
  533. // 获取用户当前经验值对应等级
  534. $userconfigModel = new \app\common\model\UserLevelConfig();
  535. $where = [];
  536. $where["empirical"] = ["elt",$userInfo["empirical"]];
  537. $userexplainstart = $userconfigModel->where($where)->order("empirical","desc")->limit(1)->select();
  538. $where = [];
  539. $where["empirical"] = ["gt",$userInfo["empirical"]];
  540. $userexplainend = $userconfigModel->where($where)->order("empirical","asc")->limit(1)->select();
  541. if(!$userexplainstart && !$userexplainend) {
  542. $this->error("经验等级信息获取失败!");
  543. } elseif(!$userexplainstart && $userexplainend) {
  544. $res["level_start"] = 0;
  545. $res["level_end"] = $userexplainend[0]["level"];
  546. } elseif($userexplainstart && !$userexplainend) {
  547. $res["level_start"] = $userexplainstart[0]["level"];
  548. $res["level_end"] = $userexplainstart[0]["level"];
  549. } elseif($userexplainstart && $userexplainend) {
  550. $res["level_start"] = $userexplainstart[0]["level"];
  551. $res["level_end"] = $userexplainend[0]["level"];
  552. }
  553. $userexplainstart && $exstart = $userexplainstart[0]["empirical"];
  554. $userexplainend && $exend = $userexplainend[0]["empirical"];
  555. $r1 = $exend-$exstart; // 等级经验值差
  556. $r2 = $userInfo["empirical"]-$exstart; // 当前等级与最低等级经验值差
  557. $r3 = $exend-$userInfo["empirical"]; // 还需多少经验值升级
  558. if($r1 == 0) {
  559. $res["level_rate"] = 1;
  560. } elseif($r2 == 0) {
  561. $res["level_rate"] = 0;
  562. if($res["level_start"] == $res["level_end"]) {
  563. $res["level_rate"] = 1;
  564. }
  565. } else {
  566. $res["level_rate"] = intval(($r2/$r1)*100)/100;
  567. }
  568. $res["to_up_need"] = $r3>0?$r3:0;
  569. // // 满级
  570. // if($r3 == 0 && !$userexplainend) {
  571. // $res["level_rate"] = 1;
  572. // }
  573. $this->success("获取成功!",$res);
  574. }
  575. /**
  576. * 钻石兑换记录
  577. * @return void
  578. */
  579. public function exchangeList()
  580. {
  581. try {
  582. $field = 'id,sound_coin,createtime';
  583. $where['user_id'] = $this->auth->id;
  584. $result = model('UserExchangeLog')->field($field)->where($where)->autopage()->order('createtime desc')->select();
  585. if (!empty($result)) {
  586. foreach ($result as $key => &$value) {
  587. $value['jewel'] = '+'.$value['sound_coin'];
  588. $value['createtime'] = !empty($value['createtime']) ? date('Y-m-d H:i',$value['createtime']) : '';
  589. unset($value['sound_coin']);
  590. }
  591. }
  592. $this->success('获取成功',$result);
  593. } catch (Exception $e) {
  594. $this->error($e->getMessage());
  595. }
  596. }
  597. /**
  598. * 钻石充值记录
  599. * @return void
  600. */
  601. public function rechargeList()
  602. {
  603. try {
  604. $field = 'id,detail,mode,value,createtime';
  605. $where['user_id'] = $this->auth->id;
  606. $result = model('UserJewelLog')->field($field)->where($where)->autopage()->order('createtime desc')->select();
  607. if (!empty($result)) {
  608. foreach ($result as $key => &$value) {
  609. $value['value'] = $value['mode'].$value['value'];
  610. $value['createtime'] = !empty($value['createtime']) ? date('Y-m-d H:i',$value['createtime']) : '';
  611. }
  612. }
  613. $this->success('获取成功',$result);
  614. } catch (Exception $e) {
  615. $this->error($e->getMessage());
  616. }
  617. }
  618. /**
  619. * 提现配置列表
  620. * @return void
  621. */
  622. public function withdrawalConfigList()
  623. {
  624. try {
  625. $field = 'id,money,real_money';
  626. $result = model('WithdrawalConfig')->field($field)->autopage()->order('weigh asc')->select();
  627. if (!empty($result)) {
  628. //设置是否使用自定义
  629. $withdrawDefine = config('site.withdraw_define');
  630. if ($withdrawDefine == 1) {
  631. $fieldArr = [[
  632. 'id' => -1,
  633. 'money' => 0,
  634. 'real_money' => 0.00,
  635. ],];
  636. $result = array_merge($result,$fieldArr);
  637. }
  638. }
  639. $this->success('获取成功',$result);
  640. } catch (Exception $e) {
  641. $this->error($e->getMessage());
  642. }
  643. }
  644. /**
  645. * 提现
  646. * @return void
  647. */
  648. public function withdrawal()
  649. {
  650. Db::startTrans();
  651. try {
  652. $withdrawConfigId = $this->request->param('id',0);
  653. $money = $this->request->param('money',0.00);
  654. $type = $this->request->param('type',0);
  655. $userId = $this->auth->id;
  656. $isAnchor = $this->auth->is_anchor;
  657. $userMoney = $this->auth->money;
  658. if (empty($withdrawConfigId) && empty($money)) {
  659. throw new Exception('参数错误');
  660. }
  661. //只有主播可以提现
  662. if ($isAnchor != 2) {
  663. throw new Exception('您不是主播不允许提现');
  664. }
  665. if ($this->auth->power->withdraw == 1) {
  666. throw new Exception('您已被禁止提现');
  667. }
  668. //验证提现类型
  669. $withdrawTypeConfig = config('wallet.withdraw_type');
  670. $typeIds = array_keys($withdrawTypeConfig);
  671. if (!in_array($type,$typeIds)) {
  672. throw new Exception('未知的提现类型');
  673. }
  674. $typeStr = isset($withdrawTypeConfig[$type]) ? $withdrawTypeConfig[$type] : '';
  675. $withdrawRateConfig = config('site.withdrawRate');//用户获取的金额比例(需要/100)
  676. $withdrawRate = bcdiv($withdrawRateConfig,100,2);
  677. if (!empty($money)) {//自定义金额
  678. if ($money <= 0) {
  679. throw new Exception('金额有误');
  680. }
  681. $inputMoney = $money;
  682. $moneys = bcmul($money,$withdrawRate,2);
  683. $platformMoney = bcsub($money,$moneys,2);
  684. } else {//提现配置
  685. $where['id'] = $withdrawConfigId;
  686. $withdrawalConfig = model('WithdrawalConfig')->where($where)->find();
  687. if (empty($withdrawalConfig)) {
  688. throw new Exception('未知的配置信息');
  689. }
  690. $inputMoney = $withdrawalConfig['money'];
  691. $moneys = $withdrawalConfig['money'];
  692. $platformMoney = bcsub($moneys,$withdrawalConfig['real_money'],2);;
  693. }
  694. if ($moneys <= 0) {
  695. throw new Exception('申请金额异常');
  696. }
  697. //扣减余额 记录余额日志
  698. $walletRes = model('wallet')->lockChangeAccountRemain($userId, $inputMoney, '-', $userMoney, '申请提现', 104,'money');
  699. if (!$walletRes['status']) {
  700. throw new Exception($walletRes['msg']);
  701. }
  702. $account = $name = '';
  703. if ($type == 1) {//微信
  704. $account = '';
  705. $name = '';
  706. } elseif ($type == 2) {//支付宝
  707. $userAlipayWhere['user_id'] = $userId;
  708. $userAlipay = model('UserAlipay')->where($userAlipayWhere)->find();
  709. if (empty($userAlipay)) {
  710. throw new Exception('请绑定支付宝');
  711. }
  712. $account = $userAlipay['pay_no'];
  713. $name = $userAlipay['realname'];
  714. } elseif ($type == 3) {//银行
  715. $userBankWhere['user_id'] = $userId;
  716. $userBank = model('UserBank')->where($userBankWhere)->find();
  717. if (empty($userBank)) {
  718. throw new Exception('请绑定银行卡');
  719. }
  720. $account = $userBank['bank_no'];
  721. $name = $userBank['realname'];
  722. }
  723. $realMoney = bcsub($inputMoney,$platformMoney,2);
  724. if ($realMoney < 0.1) {
  725. throw new Exception('输入金额请大于0.1');
  726. }
  727. $data = [
  728. 'user_id' => $userId,//用户ID
  729. 'money' => $inputMoney,//金额
  730. 'handingfee' => $platformMoney,//手续费
  731. 'real_money' => $realMoney,//金额
  732. 'taxes' => 0.00,//税费
  733. 'type' => $typeStr,//类型
  734. 'account' => $account,//提现账户
  735. 'name' => $name,//真实姓名
  736. //'memo' => '',//备注
  737. 'orderid' => getMillisecond() . mt_rand(1, 1000),//订单号
  738. //'transactionid' => '',//流水号
  739. 'status' => 'created',//状态:created=申请中,successed=成功,rejected=已拒绝
  740. //'transfertime' => '',//转账时间
  741. 'createtime' => time(),//添加时间
  742. ];
  743. $withdrawRes = model('Withdraw')->insertGetId($data);
  744. if (!$withdrawRes) {
  745. throw new Exception('提现失败');
  746. }
  747. Db::commit();
  748. $vbot = new \addons\vbot\Vbot();
  749. $vbot->vbotSendMsg('Withdrawal_Application_Notice', [], [
  750. 'name' => $name,
  751. 'account' => $account,
  752. 'real_money' => $realMoney,
  753. 'type' => $typeStr,
  754. 'handingfee' => $platformMoney
  755. ]);
  756. $this->success('操作成功待审核');
  757. } catch (Exception $e) {
  758. Db::rollback();
  759. $this->error($e->getMessage());
  760. }
  761. }
  762. /**
  763. * 提现列表
  764. * @return void
  765. */
  766. public function withdrawalList()
  767. {
  768. try {
  769. $field = 'id,money,type,status,createtime,transfertime';
  770. $where=[];
  771. $where['user_id'] = $this->auth->id;
  772. //$where['status'] = 'successed';//状态:created=申请中,successed=成功,rejected=已拒绝
  773. $result = model('Withdraw')->field($field)->where($where)->autopage()->order('createtime desc')->select();
  774. if (!empty($result)) {
  775. foreach ($result as $key => &$value) {
  776. $value['money'] = '-'.$value['money'];
  777. $value['createtime'] = !empty($value['createtime']) ? date('Y-m-d H:i', $value['createtime']) : '';
  778. $value['transfertime'] = !empty($value['transfertime']) ? date('Y-m-d H:i', $value['transfertime']) : '';
  779. }
  780. }
  781. $this->success('获取成功',$result);
  782. } catch (Exception $e) {
  783. $this->error($e->getMessage());
  784. }
  785. }
  786. }