Usercenter.php 53 KB

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