Usercenter.php 53 KB

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