Usercenter.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989
  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. public function getFollowsLive() {
  113. $is_online = $this->request->request("is_online");// 是否在线:1=直播中,0=未开播
  114. $page = $this->request->request('page',1); // 分页
  115. $pageNum = $this->request->request('pageNum',10); // 分页
  116. // 分页搜索构建
  117. $pageStart = ($page-1)*$pageNum;
  118. $is_online == 1 || $is_online = 0;
  119. $fanfollowModel = new \app\common\model\UserFansFollow();
  120. $where = [];
  121. $where["a.fans_id"] = $this->auth->id;
  122. $where["p.room_type"] = 2;
  123. $where["p.is_online"] = $is_online;
  124. if($is_online == 1) {
  125. $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";
  126. } else {
  127. $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";
  128. }
  129. $list = $fanfollowModel->alias("a")
  130. ->field($field)
  131. ->join("hx_user u","u.id = a.user_id")
  132. ->join("hx_party p","p.user_id = a.user_id")
  133. ->join("hx_party_type t","t.id = p.party_type","left")
  134. ->limit($pageStart,$pageNum)
  135. ->where($where)->select();
  136. if($list) {
  137. foreach($list as $k => $v) {
  138. $mod = isset($v["party_type"])?intval($v["party_type"])%5:1;
  139. if(isset($v["type_name"]) && $v["type_name"]) {
  140. $type_name = $v["type_name"];
  141. } else {
  142. $type_name = "普通房";
  143. }
  144. $list[$k]["party_type"] = $type_name;
  145. $list[$k]["party_type_color"] = $mod == 0?5:$mod;
  146. }
  147. $this->success("获取成功!",$list);
  148. } else {
  149. $this->success("数据为空!",[]);
  150. }
  151. }
  152. /**
  153. * 获取最近访客
  154. * (消息)
  155. */
  156. public function getMyVisitList(){
  157. $list = Db::name('user_visitlist')->alias('uv')
  158. ->field('uv.user_id,uv.updatetime,user.id,user.nickname,user.avatar,user.gender,user.desc')
  159. ->join('user','uv.user_id = user.id','LEFT')
  160. ->where('uv.visit_user_id',$this->auth->id) //被访问者
  161. ->order('uv.id desc')->autopage()->select();
  162. $list = list_domain_image($list,['avatar']);
  163. if(!empty($list)){
  164. foreach($list as $key => &$val){
  165. //关注
  166. $val['is_follow'] = $this->is_follow($this->auth->id,$val['user_id']);
  167. }
  168. }
  169. $this->success(1,$list);
  170. }
  171. /**
  172. * 获取个人技能列表
  173. */
  174. public function getMySkillList() {
  175. $user_id = $this->request->request('user_id',0); // 用户ID
  176. $page = $this->request->request('page',1); // 分页
  177. $pageNum = $this->request->request('pageNum',10); // 分页
  178. if ($user_id == -1) {
  179. $user_id = $this->auth->id;
  180. } elseif($user_id>0) {
  181. $user_id = intval($user_id);
  182. } else {
  183. $this->error(__('Invalid parameters'));
  184. }
  185. // 分页搜索构建
  186. $pageStart = ($page-1)*$pageNum;
  187. $authModel = new \app\common\model\DispatchAuth();
  188. $where = [];
  189. $where["a.user_id"] = $user_id;
  190. $where["a.status"] = 1;
  191. $authskillList = $authModel->alias("a")
  192. ->field("a.id,ds.image,ds.name,a.voice,a.voice_time,a.price,a.is_main,ds.unit")
  193. ->join("hx_dispatch_skill ds","ds.id = a.skill_id")
  194. ->where($where)
  195. ->limit($pageStart,$pageNum)
  196. ->select();
  197. $this->success("获取成功!",$authskillList);
  198. }
  199. /**
  200. * 删除个人技能信息
  201. */
  202. public function delMySkillInfo() {
  203. $id = $this->request->request('id'); // 认证ID
  204. if (!$id) {
  205. $this->error(__('Invalid parameters'));
  206. }
  207. $authModel = new \app\common\model\DispatchAuth();
  208. $where = [];
  209. $where["id"] = $id;
  210. $where["user_id"] = $this->auth->id;
  211. $authInfo = $authModel->where($where)->find();
  212. if(!$authInfo) $this->error("技能认证未找到");
  213. // if($authInfo->is_main == 1) $this->error("请先取消主技能,再删除!");
  214. Db::startTrans();
  215. try{
  216. $res1 = $authInfo->delete();
  217. $res2 = \app\common\model\UserSkill::where(["user_id"=>$this->auth->id,"skill_id"=>$authInfo->skill_id])->delete();
  218. if($res1 && $res2) {
  219. Db::commit();
  220. $this->success("删除成功!");
  221. } else {
  222. $this->error("网络错误,请稍后重试!");
  223. }
  224. }catch (ValidateException $e) {
  225. Db::rollback();
  226. $this->error($e->getMessage());
  227. } catch (PDOException $e) {
  228. Db::rollback();
  229. $this->error($e->getMessage());
  230. } catch (Exception $e) {
  231. Db::rollback();
  232. $this->error($e->getMessage());
  233. }
  234. }
  235. /**
  236. * 修改个人技能信息
  237. */
  238. public function editMySkillInfo() {
  239. $price = $this->request->request('price'); // 价格
  240. $id = $this->request->request('id'); // 认证ID
  241. $is_main = $this->request->request('is_main'); // 是否设置为主技能
  242. if (!$id && !$price) {
  243. $this->error(__('Invalid parameters'));
  244. }
  245. $authModel = new \app\common\model\DispatchAuth();
  246. $where = [];
  247. $where["id"] = $id;
  248. if(!$authModel->where($where)->find()) $this->error("技能认证未找到");
  249. Db::startTrans();
  250. try{
  251. if($is_main == 1) {
  252. $where = [];
  253. $where["user_id"] = $this->auth->id;
  254. $authModel->update(["is_main"=>0],$where);
  255. }
  256. $where = [];
  257. $where["id"] = $id;
  258. $data = [];
  259. $data["price"] = $price;
  260. $data["is_main"] = $is_main;
  261. $res = $authModel->update($data,$where);
  262. $myAuthList = $authModel->where(["user_id"=>$this->auth->id,"is_main"=>1])->find();
  263. if(!$myAuthList) {
  264. $this->error("必须至少设置一个主技能");
  265. Db::rollback();
  266. }
  267. if($res) {
  268. Db::commit();
  269. $this->success("修改成功!",$data);
  270. } else {
  271. $this->error("网络错误,请稍后重试!");
  272. }
  273. }catch (ValidateException $e) {
  274. Db::rollback();
  275. $this->error($e->getMessage());
  276. } catch (PDOException $e) {
  277. Db::rollback();
  278. $this->error($e->getMessage());
  279. } catch (Exception $e) {
  280. Db::rollback();
  281. $this->error($e->getMessage());
  282. }
  283. }
  284. /**
  285. * 编辑个人信息(完善资料)
  286. */
  287. /*public function editUserInfo() {
  288. $avatar = $this->request->request('avatar'); // 头像
  289. $nickname = $this->request->request('nickname'); // 昵称
  290. $age = $this->request->request('age'); // 年龄
  291. $ageId = $this->request->request('age_id'); // 年龄段
  292. $gender = $this->request->request('gender'); // 性别 0=女,1=男
  293. $image = $this->request->request('image'); // 个人形象照
  294. $constellationId = $this->request->request('star_id'); //星座ID
  295. $provinceId = $this->request->request('province_id'); //省ID
  296. $cityId = $this->request->request('city_id'); //城市ID
  297. $desc = $this->request->request('desc'); //个性签名
  298. $where = [];
  299. $where["id"] = $this->auth->id;
  300. $data = [];
  301. $avatar && $data["avatar"] = $avatar;
  302. if($nickname){
  303. if (mb_strlen($nickname) > 30) {
  304. $this->error('用户昵称最多支持30个汉字或组合');
  305. }
  306. $data["nickname"] = $nickname;
  307. }
  308. $gender && $data["gender"] = $gender;
  309. $age && $data["age"] = $age;
  310. $image && $data["image"] = $image;
  311. $ageId && $data['age_id'] = $ageId;
  312. $constellationId && $data['constellation_id'] = $constellationId;
  313. $provinceId && $data['province_id'] = $provinceId;
  314. $cityId && $data['city_id'] = $cityId;
  315. $desc && $data['desc'] = $desc;
  316. $res = $this->userModel->update($data,$where);
  317. if($res) {
  318. $user = $this->userModel->where($where)->find();
  319. if (!empty($user['nickname']) && !empty($user['avatar']) && !empty($user['age_id']) && $user['has_info']==0) {
  320. $data['has_info'] = 1;
  321. $this->userModel->update($data,$where);
  322. }
  323. $this->success("修改成功!");
  324. } else {
  325. $this->error("网络错误,请稍后重试!");
  326. }
  327. }*/
  328. /**
  329. * 编辑个人信息(修改昵称和头像需要后台审核)
  330. */
  331. /*public function editUser() {
  332. $avatar = $this->request->request('avatar'); // 头像
  333. $nickname = $this->request->request('nickname'); // 昵称
  334. if (!$avatar && !$nickname) {
  335. $this->error(__('请输入要修改的信息'));
  336. }
  337. $data = [];
  338. if ($avatar && $avatar != $this->auth->avatar) {
  339. $data["pre_avatar"] = $avatar;
  340. }
  341. if($nickname && $nickname != $this->auth->nickname){
  342. if (mb_strlen($nickname) > 8) {
  343. $this->error('用户昵称最多支持8个汉字或组合');
  344. }
  345. $data["pre_nickname"] = $nickname;
  346. }
  347. if (!empty($data)) {
  348. $data['need_check'] = 1;
  349. $where["id"] = $this->auth->id;
  350. $res = $this->userModel->update($data,$where);
  351. if(!$res) {
  352. $this->error("网络错误,请稍后重试!");
  353. }
  354. }
  355. $this->success("修改成功!");
  356. }*/
  357. /**
  358. * 主播申请
  359. */
  360. public function anchorApply() {
  361. $type_id = $this->request->request('type_id',0); // 技能分类ID
  362. $party_type_id = $this->request->request('party_type_id'); //分类ID
  363. $desc = $this->request->request('desc'); // 申请备注
  364. if (!$party_type_id && !$desc) {
  365. $this->error(__('Invalid parameters'));
  366. }
  367. $useranchorModel = new \app\common\model\UserAnchor();
  368. $data = [];
  369. $data["user_id"] = $this->auth->id;
  370. $data["type_id"] = $type_id;
  371. $data["party_type_id"] = $party_type_id;
  372. if($useranchorModel->where($data)->find()) $this->error(__('您已申请过该类型的主播,请勿重复申请!'));
  373. $data["desc"] = $desc;
  374. $data["createtime"] = time();
  375. $res = $useranchorModel->insertGetId($data);
  376. if($res) {
  377. \app\common\model\User::update(["is_anchor"=>1],["id"=>$this->auth->id]);
  378. $vbot = new \addons\vbot\Vbot();
  379. $vbot->vbotSendMsg('Anchor_Application_Notice', [], []);
  380. $this->success("申请发送成功!");
  381. } else {
  382. $this->error("网络错误,请稍后重试");
  383. }
  384. }
  385. /**
  386. * 实名认证
  387. */
  388. public function authApply() {
  389. $realname = $this->request->request('realname'); // 真实姓名
  390. $idcard = $this->request->request('idcard'); // 身份证号
  391. $zimage = $this->request->request('zimage'); // 身份证正面照
  392. $fimage = $this->request->request('fimage'); // 身份证反面照
  393. if (!$realname && !$idcard && !$zimage && !$fimage) {
  394. $this->error(__('Invalid parameters'));
  395. }
  396. $userauthModel = new \app\common\model\UserAuth();
  397. $data = [];
  398. $data["user_id"] = $this->auth->id;
  399. //$data["idcard"] = $idcard;
  400. $userAuth = $userauthModel->where($data)->find();
  401. if (!empty($userAuth)) {
  402. if(in_array($userAuth['status'],[0,1])) $this->error('您已经申请过了,请勿重复操作!');
  403. }
  404. // 测试需要 开始
  405. $data["realname"] = $realname;
  406. $zimage && $data["zimage"] = $zimage;
  407. $fimage && $data["fimage"] = $fimage;
  408. $data["status"] = 1;
  409. if (!empty($userAuth)) {
  410. $data["updatetime"] = time();
  411. $authWhere['user_id'] = $this->auth->id;
  412. $res = $userauthModel->where($authWhere)->update($data);
  413. } else {
  414. $data["createtime"] = time();
  415. $res = $userauthModel->insertGetId($data);
  416. }
  417. if($res) {
  418. \app\common\model\User::update(["is_auth"=>2],["id"=>$this->auth->id]);
  419. $this->success("恭喜,实名认证成功!");
  420. } else {
  421. $this->error("网络错误,请稍后重试");
  422. }
  423. // 测试需要 结束
  424. // 实名认证验证
  425. $configInfo = config("auth");
  426. $outh = new outh($configInfo["api_url"],$configInfo["customer_code"],$configInfo["private_key"],$configInfo["key"]);
  427. $out_trade_no = date("YmdHis").rand(1000,9999);
  428. $ret = $outh->toVerify($out_trade_no,$realname,$idcard);
  429. if(isset($ret["code"])) {
  430. if($ret["code"] == "1008") {
  431. $this->error(__('身份证格式错误'));
  432. }
  433. if($ret["code"] == "1009") {
  434. $this->error(__('身份证格式错误'));
  435. }
  436. if($ret["code"] == "0001") {
  437. $this->error(__('姓名和身份证号不匹配!'));
  438. }
  439. if($ret["code"] == "0000") {
  440. $data["realname"] = $realname;
  441. $zimage && $data["zimage"] = $zimage;
  442. $fimage && $data["fimage"] = $fimage;
  443. $data["status"] = 1;
  444. $data["createtime"] = time();
  445. $res = $userauthModel->insertGetId($data);
  446. if($res) {
  447. \app\common\model\User::update(["is_auth"=>2],["id"=>$this->auth->id]);
  448. $this->success("恭喜,实名认证成功!");
  449. } else {
  450. $this->error("网络错误,请稍后重试");
  451. }
  452. }
  453. } else {
  454. $this->error("网络错误,请稍后重试");
  455. }
  456. }
  457. /**
  458. * 获取主播分类
  459. */
  460. public function getAnchorType() {
  461. $this->success("获取成功!",\app\common\model\UserAnchorType::select());
  462. }
  463. /**
  464. * redis 数据恢复---非redis数据丢失请勿使用!!!!
  465. */
  466. public function shujuhuifu() {
  467. $key = $this->request->request("key");// 操作验证 123456
  468. if($key != 123456) {
  469. $this->error(__('Invalid parameters'));
  470. }
  471. $giftuserpartyModel = new \app\common\model\GiftUserParty();
  472. $redis = new Redis();
  473. $redisconfig = config("redis");
  474. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  475. if ($redisconfig['redis_pwd']) {
  476. $redis->auth($redisconfig['redis_pwd']);
  477. }
  478. if($redisconfig['redis_selectdb'] > 0){
  479. $redis->select($redisconfig['redis_selectdb']);
  480. }
  481. // 获取本周第一天
  482. $weekday = $this->firstOfWeek(date("Y-m-d H:i:s"));
  483. // 获取本月第一天
  484. $monthday = date("Ym01");
  485. $where = [];
  486. $where["createtime"] = ["gt",strtotime($weekday)];
  487. $list1 = $giftuserpartyModel->where($where)->select();
  488. foreach($list1 as $k => $v) {
  489. // 添加redis记录做财富排行榜周榜用
  490. $redis->zIncrBy("jewel_get_".$v["party_id"].":".$weekday,$v["value"],$v["user_to_id"]);
  491. // 添加redis记录做贡献排行榜周榜用
  492. $redis->zIncrBy("jewel_to_".$v["party_id"].":".$weekday,$v["value"],$v["user_id"]);
  493. }
  494. $where = [];
  495. $where["createtime"] = ["gt",strtotime(date("Y-m-01"))];
  496. $list2 = $giftuserpartyModel->where($where)->select();
  497. foreach($list2 as $k => $v) {
  498. // 添加redis记录做财富排行榜月榜用
  499. $redis->zIncrBy("jewel_get_".$v["party_id"].":".$monthday,$v["value"],$v["user_to_id"]);
  500. // 添加redis记录做贡献排行榜月榜用
  501. $redis->zIncrBy("jewel_to_".$v["party_id"].":".$monthday,$v["value"],$v["user_id"]);
  502. }
  503. $this->success("执行成功!");
  504. }
  505. /**
  506. * 获取用户钻石余额
  507. */
  508. public function getUserJewel() {
  509. //用户钱包
  510. $data = Db::name('user_wallet')->field("jewel,money")->where('user_id',$this->auth->id)->find();
  511. return $this->success("获取成功!",$data);
  512. }
  513. /**
  514. * 获取用户等级说明
  515. */
  516. public function getLevelExplain() {
  517. $data = \app\common\model\UserLevelExplain::field("title,content")->select();
  518. return $this->success("获取成功!",$data);
  519. }
  520. /**
  521. * 获取用户等级信息
  522. */
  523. public function getUserLevelInfo() {
  524. $res = [];$exstart = 0;$exend = 0;
  525. $userModel = new \app\common\model\User();
  526. $userInfo = $userModel->field("id,nickname,avatar,level,empirical")->where(["id"=>$this->auth->id])->find();
  527. if(!$userInfo) {
  528. $this->error("用户信息获取失败!");
  529. }
  530. $res["avatar"] = $userInfo['avatar'];
  531. $res["nickname"] = $userInfo['nickname'];
  532. // 获取用户当前经验值对应等级
  533. $userconfigModel = new \app\common\model\UserLevelConfig();
  534. $where = [];
  535. $where["empirical"] = ["elt",$userInfo["empirical"]];
  536. $userexplainstart = $userconfigModel->where($where)->order("empirical","desc")->limit(1)->select();
  537. $where = [];
  538. $where["empirical"] = ["gt",$userInfo["empirical"]];
  539. $userexplainend = $userconfigModel->where($where)->order("empirical","asc")->limit(1)->select();
  540. if(!$userexplainstart && !$userexplainend) {
  541. $this->error("经验等级信息获取失败!");
  542. } elseif(!$userexplainstart && $userexplainend) {
  543. $res["level_start"] = 0;
  544. $res["level_end"] = $userexplainend[0]["level"];
  545. } elseif($userexplainstart && !$userexplainend) {
  546. $res["level_start"] = $userexplainstart[0]["level"];
  547. $res["level_end"] = $userexplainstart[0]["level"];
  548. } elseif($userexplainstart && $userexplainend) {
  549. $res["level_start"] = $userexplainstart[0]["level"];
  550. $res["level_end"] = $userexplainend[0]["level"];
  551. }
  552. $userexplainstart && $exstart = $userexplainstart[0]["empirical"];
  553. $userexplainend && $exend = $userexplainend[0]["empirical"];
  554. $r1 = $exend-$exstart; // 等级经验值差
  555. $r2 = $userInfo["empirical"]-$exstart; // 当前等级与最低等级经验值差
  556. $r3 = $exend-$userInfo["empirical"]; // 还需多少经验值升级
  557. if($r1 == 0) {
  558. $res["level_rate"] = 1;
  559. } elseif($r2 == 0) {
  560. $res["level_rate"] = 0;
  561. if($res["level_start"] == $res["level_end"]) {
  562. $res["level_rate"] = 1;
  563. }
  564. } else {
  565. $res["level_rate"] = intval(($r2/$r1)*100)/100;
  566. }
  567. $res["to_up_need"] = $r3>0?$r3:0;
  568. // // 满级
  569. // if($r3 == 0 && !$userexplainend) {
  570. // $res["level_rate"] = 1;
  571. // }
  572. $this->success("获取成功!",$res);
  573. }
  574. /**
  575. * 邀请
  576. * @return void
  577. */
  578. public function addInvite()
  579. {
  580. try {
  581. $inviteNo = $this->request->param('invite_no','');
  582. $userId = $this->auth->id;
  583. if (empty($inviteNo)) {
  584. throw new Exception('参数错误');
  585. }
  586. $where['invite_no'] = $inviteNo;
  587. $userField = 'id,invite_no,pre_userid';
  588. $user = model('User')->field($userField)->where($where)->find();
  589. if (empty($user)) {
  590. throw new Exception('无效的邀请码');
  591. }
  592. //判断邀请码用户不能是自己的下级
  593. if ($user['pre_userid'] == $userId) {
  594. throw new Exception('对方已被您邀请过');
  595. }
  596. $userInviteWhere['invite_user_id'] = $userId;
  597. $userInvite = model('UserInvite')->where($userInviteWhere)->find();
  598. if (!empty($userInvite)) {
  599. throw new Exception('您已经被邀请过');
  600. }
  601. $userInviteData = [
  602. 'user_id' => $user['id'],
  603. 'invite_user_id' => $userId,
  604. 'createtime' => time(),
  605. ];
  606. $userInviteRes = model('UserInvite')->insertGetId($userInviteData);
  607. if (!$userInviteRes) {
  608. throw new Exception('邀请失败');
  609. }
  610. $userUpWhere['id'] = $userId;
  611. $userUpdate = ['pre_userid'=>$user['id']];
  612. $userUpdateRes = model('User')->where($userUpWhere)->update($userUpdate);
  613. if (!$userUpdateRes) {
  614. throw new Exception('更新邀请人失败');
  615. }
  616. $this->success('邀请成功');
  617. } catch (Exception $e) {
  618. $this->error($e->getMessage());
  619. }
  620. }
  621. /**
  622. * 邀请详情
  623. * @return void
  624. */
  625. public function inviteInfo()
  626. {
  627. try {
  628. $userId = $this->auth->id;
  629. $field = 'id,invite_no';
  630. $where['id'] = $userId;
  631. $user = model('User')->field($field)->where($where)->find();
  632. $inviteNo = isset($user['invite_no']) ? $user['invite_no'] : '';
  633. $todayNow = day_now();
  634. $todayStart = $todayNow[0];
  635. $todayEnd = $todayNow[1]+1;
  636. $userMoneyLogWhere['user_id'] = $userId;
  637. $userMoneyLogWhere['type'] = 103;
  638. $appendWhere['createtime'] = [['egt', $todayStart],['lt', $todayEnd],'and'];
  639. $todayMoney = model('UserMoneyLog')->where($userMoneyLogWhere)->where($appendWhere)->sum('value');
  640. $totalMoney = model('UserMoneyLog')->where($userMoneyLogWhere)->sum('value');
  641. //本周
  642. $weekNow = week_now();
  643. $userInviteWhere['user_id'] = $userId;
  644. $userInviteAppendWhere['createtime'] = [['egt', $weekNow[0]],['lt', $weekNow[1]+1],'and'];
  645. $userInviteModel = model('UserInvite');
  646. $weekNowNum = $userInviteModel->where($userInviteWhere)->where($userInviteAppendWhere)->count();
  647. //上周
  648. $lastWeek = last_week();
  649. $appendLastWhere['createtime'] = [['egt', $lastWeek[0]],['lt', $lastWeek[1]+1],'and'];
  650. $lastWeekNum = $userInviteModel->where($userInviteWhere)->where($appendLastWhere)->count();
  651. //全部
  652. $totalNum = $userInviteModel->where($userInviteWhere)->count();
  653. $inviteMoney = config('site.invite_money');
  654. $inviteRule = config('site.invite_rule');
  655. $result = [
  656. 'invite_money' => (int)$inviteMoney,
  657. 'invite_no' => $inviteNo,//邀请码
  658. 'today_money' => $todayMoney,//今日收益
  659. 'total_money' => $totalMoney,//总收益
  660. 'week_now_num' => $weekNowNum,//本周邀请数
  661. 'last_week_num' => $lastWeekNum,//上周邀请数
  662. 'total_num' => $totalNum,//总邀请数
  663. 'invite_rule' => $inviteRule,//规则说明
  664. ];
  665. $this->success('获取成功',$result);
  666. } catch (Exception $e) {
  667. $this->error($e->getMessage());
  668. }
  669. }
  670. /**
  671. * 邀请列表
  672. * @return void
  673. */
  674. public function inviteList()
  675. {
  676. try {
  677. $userId = $this->auth->id;
  678. $where['user_id'] = $userId;
  679. $userInvite = model('UserInvite')->where($where)->with(['user'=>function($uQuery){
  680. $uQuery->field('id,avatar,u_id,nickname');
  681. }])->autopage()->order('createtime desc')->select();
  682. $result = [];
  683. if (!empty($userInvite)) {
  684. foreach ($userInvite as $key => $value) {
  685. $user = isset($value['user']) ? $value['user'] : [];
  686. $temp = [
  687. 'user_id' => isset($user['id']) ? $user['id'] : 0,
  688. 'u_id' => isset($user['u_id']) ? $user['u_id'] : 0,
  689. 'avatar' => isset($user['avatar']) ? $user['avatar'] : 0,
  690. 'nickname' => isset($user['nickname']) ? $user['nickname'] : 0,
  691. 'create_time_text' => !empty($value['createtime']) ? date('Y-m-d', $value['createtime']) : '',
  692. ];
  693. $result[] = $temp;
  694. }
  695. }
  696. $this->success('获取成功',$result);
  697. } catch (Exception $e) {
  698. $this->error($e->getMessage());
  699. }
  700. }
  701. /**
  702. * 钻石兑换记录
  703. * @return void
  704. */
  705. public function exchangeList()
  706. {
  707. try {
  708. $field = 'id,sound_coin,createtime';
  709. $where['user_id'] = $this->auth->id;
  710. $result = model('UserExchangeLog')->field($field)->where($where)->autopage()->order('createtime desc')->select();
  711. if (!empty($result)) {
  712. foreach ($result as $key => &$value) {
  713. $value['jewel'] = '+'.$value['sound_coin'];
  714. $value['createtime'] = !empty($value['createtime']) ? date('Y-m-d H:i',$value['createtime']) : '';
  715. unset($value['sound_coin']);
  716. }
  717. }
  718. $this->success('获取成功',$result);
  719. } catch (Exception $e) {
  720. $this->error($e->getMessage());
  721. }
  722. }
  723. /**
  724. * 钻石充值记录
  725. * @return void
  726. */
  727. public function rechargeList()
  728. {
  729. try {
  730. $field = 'id,detail,mode,value,createtime';
  731. $where['user_id'] = $this->auth->id;
  732. $result = model('UserJewelLog')->field($field)->where($where)->autopage()->order('createtime desc')->select();
  733. if (!empty($result)) {
  734. foreach ($result as $key => &$value) {
  735. $value['value'] = $value['mode'].$value['value'];
  736. $value['createtime'] = !empty($value['createtime']) ? date('Y-m-d H:i',$value['createtime']) : '';
  737. }
  738. }
  739. $this->success('获取成功',$result);
  740. } catch (Exception $e) {
  741. $this->error($e->getMessage());
  742. }
  743. }
  744. /**
  745. * 提现配置列表
  746. * @return void
  747. */
  748. public function withdrawalConfigList()
  749. {
  750. try {
  751. $field = 'id,money,real_money';
  752. $result = model('WithdrawalConfig')->field($field)->autopage()->order('weigh asc')->select();
  753. if (!empty($result)) {
  754. //设置是否使用自定义
  755. $withdrawDefine = config('site.withdraw_define');
  756. if ($withdrawDefine == 1) {
  757. $fieldArr = [[
  758. 'id' => -1,
  759. 'money' => 0,
  760. 'real_money' => 0.00,
  761. ],];
  762. $result = array_merge($result,$fieldArr);
  763. }
  764. }
  765. $this->success('获取成功',$result);
  766. } catch (Exception $e) {
  767. $this->error($e->getMessage());
  768. }
  769. }
  770. /**
  771. * 提现
  772. * @return void
  773. */
  774. public function withdrawal()
  775. {
  776. Db::startTrans();
  777. try {
  778. $withdrawConfigId = $this->request->param('id',0);
  779. $money = $this->request->param('money',0.00);
  780. $type = $this->request->param('type',0);
  781. $userId = $this->auth->id;
  782. $isAnchor = $this->auth->is_anchor;
  783. $userMoney = $this->auth->money;
  784. if (empty($withdrawConfigId) && empty($money)) {
  785. throw new Exception('参数错误');
  786. }
  787. //只有主播可以提现
  788. if ($isAnchor != 2) {
  789. throw new Exception('您不是主播不允许提现');
  790. }
  791. if ($this->auth->power->withdraw == 1) {
  792. throw new Exception('您已被禁止提现');
  793. }
  794. //验证提现类型
  795. $withdrawTypeConfig = config('wallet.withdraw_type');
  796. $typeIds = array_keys($withdrawTypeConfig);
  797. if (!in_array($type,$typeIds)) {
  798. throw new Exception('未知的提现类型');
  799. }
  800. $typeStr = isset($withdrawTypeConfig[$type]) ? $withdrawTypeConfig[$type] : '';
  801. $withdrawRateConfig = config('site.withdrawRate');//用户获取的金额比例(需要/100)
  802. $withdrawRate = bcdiv($withdrawRateConfig,100,2);
  803. if (!empty($money)) {//自定义金额
  804. if ($money <= 0) {
  805. throw new Exception('金额有误');
  806. }
  807. $inputMoney = $money;
  808. $moneys = bcmul($money,$withdrawRate,2);
  809. $platformMoney = bcsub($money,$moneys,2);
  810. } else {//提现配置
  811. $where['id'] = $withdrawConfigId;
  812. $withdrawalConfig = model('WithdrawalConfig')->where($where)->find();
  813. if (empty($withdrawalConfig)) {
  814. throw new Exception('未知的配置信息');
  815. }
  816. $inputMoney = $withdrawalConfig['money'];
  817. $moneys = $withdrawalConfig['money'];
  818. $platformMoney = bcsub($moneys,$withdrawalConfig['real_money'],2);;
  819. }
  820. if ($moneys <= 0) {
  821. throw new Exception('申请金额异常');
  822. }
  823. //扣减余额 记录余额日志
  824. $walletRes = model('wallet')->lockChangeAccountRemain($userId, $inputMoney, '-', $userMoney, '申请提现', 104,'money');
  825. if (!$walletRes['status']) {
  826. throw new Exception($walletRes['msg']);
  827. }
  828. $account = $name = '';
  829. if ($type == 1) {//微信
  830. $account = '';
  831. $name = '';
  832. } elseif ($type == 2) {//支付宝
  833. $userAlipayWhere['user_id'] = $userId;
  834. $userAlipay = model('UserAlipay')->where($userAlipayWhere)->find();
  835. if (empty($userAlipay)) {
  836. throw new Exception('请绑定支付宝');
  837. }
  838. $account = $userAlipay['pay_no'];
  839. $name = $userAlipay['realname'];
  840. } elseif ($type == 3) {//银行
  841. $userBankWhere['user_id'] = $userId;
  842. $userBank = model('UserBank')->where($userBankWhere)->find();
  843. if (empty($userBank)) {
  844. throw new Exception('请绑定银行卡');
  845. }
  846. $account = $userBank['bank_no'];
  847. $name = $userBank['realname'];
  848. }
  849. $realMoney = bcsub($inputMoney,$platformMoney,2);
  850. if ($realMoney < 0.1) {
  851. throw new Exception('输入金额请大于0.1');
  852. }
  853. $data = [
  854. 'user_id' => $userId,//用户ID
  855. 'money' => $inputMoney,//金额
  856. 'handingfee' => $platformMoney,//手续费
  857. 'real_money' => $realMoney,//金额
  858. 'taxes' => 0.00,//税费
  859. 'type' => $typeStr,//类型
  860. 'account' => $account,//提现账户
  861. 'name' => $name,//真实姓名
  862. //'memo' => '',//备注
  863. 'orderid' => getMillisecond() . mt_rand(1, 1000),//订单号
  864. //'transactionid' => '',//流水号
  865. 'status' => 'created',//状态:created=申请中,successed=成功,rejected=已拒绝
  866. //'transfertime' => '',//转账时间
  867. 'createtime' => time(),//添加时间
  868. ];
  869. $withdrawRes = model('Withdraw')->insertGetId($data);
  870. if (!$withdrawRes) {
  871. throw new Exception('提现失败');
  872. }
  873. Db::commit();
  874. $vbot = new \addons\vbot\Vbot();
  875. $vbot->vbotSendMsg('Withdrawal_Application_Notice', [], [
  876. 'name' => $name,
  877. 'account' => $account,
  878. 'real_money' => $realMoney,
  879. 'type' => $typeStr,
  880. 'handingfee' => $platformMoney
  881. ]);
  882. $this->success('操作成功待审核');
  883. } catch (Exception $e) {
  884. Db::rollback();
  885. $this->error($e->getMessage());
  886. }
  887. }
  888. /**
  889. * 提现列表
  890. * @return void
  891. */
  892. public function withdrawalList()
  893. {
  894. try {
  895. $field = 'id,money,type,status,createtime,transfertime';
  896. $where=[];
  897. $where['user_id'] = $this->auth->id;
  898. //$where['status'] = 'successed';//状态:created=申请中,successed=成功,rejected=已拒绝
  899. $result = model('Withdraw')->field($field)->where($where)->autopage()->order('createtime desc')->select();
  900. if (!empty($result)) {
  901. foreach ($result as $key => &$value) {
  902. $value['money'] = '-'.$value['money'];
  903. $value['createtime'] = !empty($value['createtime']) ? date('Y-m-d H:i', $value['createtime']) : '';
  904. $value['transfertime'] = !empty($value['transfertime']) ? date('Y-m-d H:i', $value['transfertime']) : '';
  905. }
  906. }
  907. $this->success('获取成功',$result);
  908. } catch (Exception $e) {
  909. $this->error($e->getMessage());
  910. }
  911. }
  912. }