Usercenter.php 55 KB

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