Usercenter.php 40 KB

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