Usercenter.php 54 KB

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