Index.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\service\RoomService;
  5. use fast\Random;
  6. use think\Collection;
  7. use \think\Log;
  8. use Redis;
  9. use app\common\library\Sms as Smslib;
  10. use app\common\service\TenimService;
  11. use think\Db;
  12. use think\Cache;
  13. /**
  14. * 首页接口
  15. */
  16. class Index extends Api
  17. {
  18. protected $noNeedLogin = ['index','contactus','tcpTest','getAppShare','getWebsiteInfo','getUserCharmRankList',
  19. 'getPartyHotList','searchUsers','getInviteCode','getEdition','getiosEdition','getInviteImg','getWebsiteInfoForMini','getBankList',
  20. 'getSwitch','ageList','starList','bannerList','keyworldconfig','switchenum'];
  21. protected $noNeedRight = ['*'];
  22. /**
  23. * 获取主播魅力值排行,完全可以从送礼物日志表拿数据
  24. */
  25. public function getUserCharmRankList() {
  26. $time = $this->request->request("time",0,"intval"); //时间筛选 1=小时榜,2=今日榜,3=本周榜,4=月榜
  27. if(!in_array($time,[1,2,3,4])) {
  28. $this->error("参数传入错误!");
  29. }
  30. $hour = strtotime(date("Y-m-d H:00:00"));
  31. $today = strtotime(date("Y-m-d 00:00:00"));
  32. $weekend = strtotime('monday this week');
  33. // $weekend = mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y"));
  34. $month = strtotime(date("Y-m-01 00:00:00"));
  35. // 剩余时间
  36. $thistime = time();
  37. switch ($time) {
  38. case 1:
  39. $redtime = 3600-($thistime - $hour);
  40. break;
  41. case 2:
  42. $redtime = 3600*24-($thistime - $today);
  43. break;
  44. case 3:
  45. $redtime = 3600*24*7-($thistime - $weekend);
  46. break;
  47. case 4:
  48. $monthend = mktime(23,59,59,date("m"),date("t"),date("Y"));
  49. $redtime = ($monthend - $month)-($thistime - $month);
  50. break;
  51. }
  52. $timeArr = [1=>$hour,2=>$today,3=>$weekend,4=>$month];
  53. $where = [];
  54. $where["a.createtime"] = ["gt",$timeArr[$time]];
  55. $list = \app\common\model\UserCharmRank::alias("a")
  56. ->field("a.party_id as id,sum(a.charm) as charm,u.avatar,u.nickname,u.gender,u.level,u.is_live")
  57. ->where($where)
  58. ->join("hx_user u","u.id = a.user_id",'LEFT')
  59. // ->join("hx_party p","p.user_id = a.user_id",'LEFT')
  60. ->group("a.user_id")
  61. ->order("charm","desc")
  62. ->limit(100)
  63. ->select();
  64. $data = [];
  65. $data["redtime"] = $redtime;
  66. $data["data"] = $list;
  67. $this->success("获取成功!",$data);
  68. }
  69. /**
  70. * 获取收礼排行
  71. */
  72. public function getUserGiftRank() {
  73. $time = $this->request->request("time",0,"intval"); //时间筛选 1=小时榜,2=今日榜,3=本周榜,4=月榜
  74. if(!in_array($time,[1,2,3,4])) {
  75. $this->error("参数传入错误!");
  76. }
  77. $hour = strtotime(date("Y-m-d H:00:00"));
  78. $today = strtotime(date("Y-m-d 00:00:00"));
  79. $weekend = strtotime('monday this week');
  80. $month = strtotime(date("Y-m-01 00:00:00"));
  81. // 剩余时间
  82. $thistime = time();
  83. switch ($time) {
  84. case 1:
  85. $redtime = 3600-($thistime - $hour);
  86. break;
  87. case 2:
  88. $redtime = 3600*24-($thistime - $today);
  89. break;
  90. case 3:
  91. $redtime = 3600*24*7-($thistime - $weekend);
  92. break;
  93. case 4:
  94. $monthend = mktime(23,59,59,date("m"),date("t"),date("Y"));
  95. $redtime = ($monthend - $month)-($thistime - $month);
  96. break;
  97. }
  98. $timeArr = [1=>$hour,2=>$today,3=>$weekend,4=>$month];
  99. $where = [];
  100. $where["a.createtime"] = ["gt",$timeArr[$time]];
  101. $list = model('GiftUserParty')->alias("a")
  102. ->field("sum(a.value) as total_price,a.user_to_id,u.avatar,u.nickname")
  103. ->where($where)
  104. ->join("hx_user u","u.id = a.user_to_id")
  105. ->group("a.user_to_id")
  106. ->order("total_price","desc")
  107. ->limit(100)
  108. ->select();
  109. $data = [];
  110. $data["redtime"] = $redtime;
  111. $data["data"] = $list;
  112. $this->success("获取成功!",$data);
  113. }
  114. /**
  115. * 获取消费排行
  116. */
  117. public function getUserPayRank() {
  118. $time = $this->request->request("time",0,"intval"); //时间筛选 1=小时榜,2=今日榜,3=本周榜,4=月榜
  119. if(!in_array($time,[1,2,3,4])) {
  120. $this->error("参数传入错误!");
  121. }
  122. $hour = strtotime(date("Y-m-d H:00:00"));
  123. $today = strtotime(date("Y-m-d 00:00:00"));
  124. $weekend = strtotime('monday this week');
  125. $month = strtotime(date("Y-m-01 00:00:00"));
  126. // 剩余时间
  127. $thistime = time();
  128. switch ($time) {
  129. case 1:
  130. $redtime = 3600-($thistime - $hour);
  131. break;
  132. case 2:
  133. $redtime = 3600*24-($thistime - $today);
  134. break;
  135. case 3:
  136. $redtime = 3600*24*7-($thistime - $weekend);
  137. break;
  138. case 4:
  139. $monthend = mktime(23,59,59,date("m"),date("t"),date("Y"));
  140. $redtime = ($monthend - $month)-($thistime - $month);
  141. break;
  142. }
  143. $timeArr = [1=>$hour,2=>$today,3=>$weekend,4=>$month];
  144. $where = [];
  145. $where["a.type"] = ["in",[0,2,3,5,6,13]];//查看wallet.php文件
  146. $where["a.createtime"] = ["gt",$timeArr[$time]];
  147. $list = model('UserJewelLog')->alias("a")
  148. ->field("sum(a.value) as total_price,a.user_id,u.avatar,u.nickname")
  149. ->where($where)
  150. ->join("hx_user u","u.id = a.user_id")
  151. ->group("a.user_id")
  152. ->order("total_price","desc")
  153. ->limit(100)
  154. ->select();
  155. $data = [];
  156. $data["redtime"] = $redtime;
  157. $data["data"] = $list;
  158. $this->success("获取成功!",$data);
  159. }
  160. /**
  161. * 获取派对热度排序
  162. */
  163. public function getPartyHotList() {
  164. // 剩余时间
  165. $thistime = time();
  166. $hour = strtotime(date("Y-m-d H:00:00"));
  167. $redtime = 3600-($thistime - $hour);
  168. $where = [];
  169. $where["a.createtime"] = ["gt",$hour];
  170. $where["p.room_type"] = 1;
  171. $list = \app\common\model\PartyHot::alias("a")
  172. ->field("sum(a.hot) as hot,p.id,u.avatar,p.party_name,p.party_logo")
  173. ->where($where)
  174. ->join("hx_party p","p.id = a.party_id")
  175. ->join("hx_user u","u.id = p.user_id")
  176. ->group("a.party_id")
  177. ->order("hot","desc")
  178. ->limit(100)
  179. ->select();
  180. $data = [];
  181. $data["redtime"] = $redtime;
  182. $data["data"] = $list;
  183. $this->success("获取成功!",$data);
  184. }
  185. /**
  186. * 首页搜索
  187. */
  188. public function searchUsers() {
  189. $search = $this->request->request("search"); //关键词筛选
  190. if(!$search) {
  191. $this->error("请输入搜索内容!");
  192. }
  193. // 搜索派对
  194. global $whereOr;
  195. $where = [];
  196. $whereOr["party_id"] = $search;
  197. $whereOr["party_name"] = ["like","%$search%"];
  198. $where["room_type"] = 1;
  199. $partyList = \app\common\model\Party::field("id,party_logo,party_id,party_name")
  200. ->where($where)
  201. ->where(function ($query) {
  202. global $whereOr;
  203. $query->whereOr($whereOr);
  204. })->order("party_hot","desc")->select();
  205. // 搜索直播间
  206. global $whereOrlive;
  207. $where = [];
  208. $whereOrlive["party_id"] = $search;
  209. $whereOrlive["party_name"] = ["like","%$search%"];
  210. $where["room_type"] = 2;
  211. $liveList = \app\common\model\Party::field("id,party_logo,party_id,party_name")
  212. ->where($where)
  213. ->where(function ($query) {
  214. global $whereOrlive;
  215. $query->whereOr($whereOrlive);
  216. })
  217. ->order("party_hot","desc")->select();
  218. // 相关用户
  219. $where = [];
  220. $where["a.nickname"] = ["like","%$search%"];
  221. $where["a.u_id"] = $search;
  222. $userList = \app\common\model\User::alias("a")->field("id,avatar,nickname,u_id,f.fans")
  223. ->join("hx_view_fans f","f.user_id = a.id","left")
  224. ->order("a.is_online,a.noble,a.level")
  225. ->whereOr($where)->select();
  226. $res = [];
  227. $res["partylist"] = $partyList;
  228. $res["livelist"] = $liveList;
  229. $res["userlist"] = $userList;
  230. $this->success("获取成功!",$res);
  231. }
  232. /**
  233. * 首页搜索
  234. */
  235. public function searchList() {
  236. $search = $this->request->request("search"); //关键词筛选
  237. if(!$search) {
  238. $this->error("请输入搜索内容!");
  239. }
  240. // 搜索房间(派对和直播)
  241. global $whereOr;
  242. $where = [];
  243. $whereOr["party_id"] = $search;
  244. $whereOr["party_name"] = ["like","%$search%"];
  245. //$where['is_online'] = 1;
  246. $where['is_close'] = 0;
  247. $where['status'] = 1;
  248. $partyList = \app\common\model\Party::field("id,room_type,party_logo,party_id,party_name,party_type")
  249. ->where($where)
  250. ->where(function ($query) {
  251. global $whereOr;
  252. $query->whereOr($whereOr);
  253. })->order("party_hot","desc")->select();
  254. $partyList = collection($partyList)->toArray();
  255. if (!empty($partyList)) {//在线信息
  256. $partyListIds = array_column($partyList,'id');
  257. /*$tenimService = new TenimService();
  258. $partyParams = ['party_ids'=>$partyListIds];
  259. $partyRes = $tenimService->getRoomUser($partyParams);*/
  260. /*if ($partyRes['status'] == 1) {
  261. }*/
  262. $roomService = new RoomService();
  263. foreach ($partyList as $pKey => &$pVal) {
  264. // 派对类型
  265. $partyTypeName = "普通房";
  266. if($pVal["party_type"]) {
  267. $partyTypeName = \app\common\model\PartyType::where(["id"=>$pVal["party_type"]])->value("name");
  268. }
  269. $mod = isset($pVal["party_type"])?intval($pVal["party_type"])%5:1;
  270. $pVal["party_type_color"] = $mod == 0?5:$mod;
  271. $pVal["type_name"] = $partyTypeName;
  272. $userDataResult = $roomService->getPartyUserList(['party_id'=>$pVal['id']]);
  273. $userDataRes = isset($userDataResult['data']) ? $userDataResult['data'] : [];
  274. $pVal['member_list'] = isset($userDataRes['member_list']) ? $userDataRes['member_list'] : [];
  275. $pVal['online_num'] = isset($userDataRes['online_num']) ? $userDataRes['online_num'] : [];
  276. }
  277. }
  278. // 家族
  279. $guildWhere['status'] = 1;
  280. $guildWhere['name'] = ["like","%$search%"];
  281. $guildList = model('Guild')->where($guildWhere)->with(['guildmember'=>function($gquery){
  282. $gquery->where(['status'=>1]);
  283. }])->field('id,g_id,name,image')->select();
  284. if (!empty($guildList)) {
  285. $userField = 'id,nickname,avatar';
  286. foreach ($guildList as $gKey => &$gVal) {
  287. $userData =[];
  288. if (isset($gVal['guildmember'])) {
  289. $memberUids = array_column($gVal['guildmember'],'user_id');
  290. $userWhere['is_online'] = 1;
  291. $userWhere['id'] = ['in',$memberUids];
  292. $userData = model('User')->field($userField)->where($userWhere)->select();
  293. }
  294. /*$mod = intval($gKey)%5;
  295. $pVal["party_type_color"] = $mod == 0?5:$mod;*/
  296. $gVal["party_type_color"] = 1;
  297. $gVal["type_name"] = '普通房';
  298. $gVal['member_list'] = $userData;
  299. $gVal['online_num'] = count($userData);
  300. unset($gVal['guildmember']);
  301. }
  302. }
  303. // 相关用户
  304. $where = [];
  305. $where["a.nickname"] = ["like","%$search%"];
  306. $where["a.u_id"] = $search;
  307. $userList = \app\common\model\User::alias("a")->field("id,avatar,nickname,u_id,f.fans")
  308. ->join("hx_view_fans f","f.user_id = a.id","left")
  309. ->order("a.is_online,a.noble,a.level")
  310. ->whereOr($where)->select();
  311. $res = [];
  312. $res["roomlist"] = $partyList;
  313. $res["guildlist"] = $guildList;
  314. $res["userlist"] = $userList;
  315. $this->success("获取成功!",$res);
  316. }
  317. //开关设置
  318. public function switchenum(){
  319. $rs = [
  320. 'alipay_switch' => config('site.alipay_switch'), //支付宝支付开关
  321. 'wechat_switch' => config('site.wechat_switch'), //微信支付开关
  322. 'recharge_switch' => config('site.recharge_switch'), //所有充值开关
  323. ];
  324. $this->success('success',$rs);
  325. }
  326. ///////上面的没用到//////
  327. public function index(){
  328. echo 'apisuccess';
  329. exit;
  330. }
  331. //附近
  332. public function fujin(){
  333. $where = [
  334. 'user.id' => ['neq',$this->auth->id],
  335. 'user.status' => 1,
  336. 'user.city_id' => $this->auth->city_id,
  337. ];
  338. //排除黑名单的
  339. $where_black = [];
  340. $black_ids = Db::name('user_blacklist')->where(['user_id'=>$this->auth->id])->column('black_user_id');
  341. if(!empty($black_ids)){
  342. $where_black['user.id'] = ['NOTIN',$black_ids];
  343. }
  344. $field = [
  345. 'user.id',
  346. 'user.u_id',
  347. 'user.username',
  348. 'user.nickname',
  349. 'user.avatar',
  350. 'user.gender',
  351. 'user.desc',
  352. 'age.name as age_text',
  353. 'job.name as job_text',
  354. 'area.name as city_text',
  355. '(st_distance(point (' . $this->auth->longitude . ', ' . $this->auth->latitude . '),point(user.longitude,user.latitude))*111195) as distance',
  356. ];
  357. $list = Db::name('user')->alias('user')->field($field)
  358. ->join('age','user.age_id = age.id','LEFT')
  359. ->join('enum_job job','user.job_id = job.id','LEFT')
  360. ->join('shopro_area area','user.city_id = area.id','LEFT')
  361. ->where($where)
  362. ->where($where_black)
  363. ->order('distance asc')
  364. ->autopage()
  365. ->select();
  366. $list = list_domain_image($list,['avatar']);
  367. foreach($list as $key => &$val){
  368. $val['distance'] = bcdiv(intval($val['distance']),1000,1).'km';
  369. $val['is_follow'] = $this->is_follow($this->auth->id,$val['id']);
  370. $val['is_friend'] = $this->is_friend($this->auth->id,$val['id']);
  371. }
  372. $this->success(1,$list);
  373. }
  374. //同城
  375. public function samecity(){
  376. $where = [
  377. 'user.id' => ['neq',$this->auth->id],
  378. 'user.status' => 1,
  379. 'user.city_id' => $this->auth->city_id,
  380. ];
  381. //排除黑名单的
  382. $where_black = [];
  383. $black_ids = Db::name('user_blacklist')->where(['user_id'=>$this->auth->id])->column('black_user_id');
  384. if(!empty($black_ids)){
  385. $where_black['user.id'] = ['NOTIN',$black_ids];
  386. }
  387. $field = [
  388. 'user.id',
  389. 'user.u_id',
  390. 'user.username',
  391. 'user.nickname',
  392. 'user.avatar',
  393. 'user.gender',
  394. 'user.desc',
  395. 'age.name as age_text',
  396. 'job.name as job_text',
  397. 'area.name as city_text',
  398. ];
  399. $list = Db::name('user')->alias('user')->field($field)
  400. ->join('age age','user.age_id = age.id','LEFT')
  401. ->join('enum_job job','user.job_id = job.id','LEFT')
  402. ->join('shopro_area area','user.city_id = area.id','LEFT')
  403. ->where($where)
  404. ->where($where_black)
  405. ->autopage()
  406. ->select();
  407. $list = list_domain_image($list,['avatar']);
  408. $this->success(1,$list);
  409. }
  410. //匹配配置
  411. /*public function pipei_config(){
  412. $result = [
  413. 'index_pipei_switch' => config('site.index_pipei_switch'), //匹配开关
  414. ];
  415. //首页匹配每天每人匹配次数
  416. $user_id = $this->auth->id;
  417. $is_vip = $this->is_vip($this->auth->id);
  418. $times_limit = $is_vip == 1 ? config('site.pipei_oneday_vipuser_times') : config('site.index_pipei_oneday_user_times');
  419. $times_limit_redis = 'pipei_times_limit_'.$user_id;
  420. $user_times = Cache::get($times_limit_redis) ?: 0;
  421. if($times_limit > -1){
  422. $remain_times = $times_limit - $user_times;
  423. if($remain_times < 0){
  424. $remain_times = 0;
  425. }
  426. }else{
  427. $remain_times = -1;
  428. }
  429. $result['remain_times'] = $remain_times;
  430. $this->success(1,$result);
  431. }*/
  432. //匹配
  433. //做防止重复处理,参照荔枝
  434. //做用户在线处理,参照mita,用户不在线,用户语音视频中,用户房间内时,不能被匹配到
  435. public function pipei(){
  436. //首页匹配功能开关
  437. /*$index_pipei_switch = config('site.index_pipei_switch');
  438. if($index_pipei_switch != 1){
  439. $this->error('匹配功能维护中,请稍后再试');
  440. }*/
  441. //缓存,防重复
  442. $user_id = $this->auth->id;
  443. $user_id_redis = 'pipei_repeat_'.$user_id;
  444. $redis_ids = json_decode(Cache::get($user_id_redis),true);
  445. //首页匹配每天每人匹配次数
  446. /*$is_vip = $this->is_vip($this->auth->id);
  447. $times_limit = $is_vip == 1 ? config('site.pipei_oneday_vipuser_times') : config('site.index_pipei_oneday_user_times');
  448. $times_limit_redis = 'pipei_times_limit_'.$user_id;
  449. $user_times = Cache::get($times_limit_redis) ?: 0;
  450. if($times_limit > -1 && $user_times >= $times_limit){
  451. $this->error('今日已超匹配上限'.$times_limit.'次');
  452. }*/
  453. //where
  454. $where = [
  455. 'user.id' => ['neq',$this->auth->id],
  456. 'user.status' => 1,
  457. ];
  458. //性别
  459. $gender = input('gender','all');
  460. if($gender != 'all'){
  461. $where['user.gender'] = $gender;
  462. }
  463. //排除黑名单的
  464. $where_black = [];
  465. $black_ids = Db::name('user_blacklist')->where(['user_id'=>$this->auth->id])->column('black_user_id');
  466. if(!empty($black_ids)){
  467. $where_black['user.id'] = ['NOTIN',$black_ids];
  468. }
  469. //匹配一个
  470. $result = $this->pipei_action($redis_ids,$where,$where_black);
  471. //匹配不到,移除防重复
  472. if(!$result) {
  473. Cache::rm($user_id_redis);
  474. $redis_ids = [];
  475. $result = $this->pipei_action($redis_ids,$where,$where_black);
  476. }
  477. // 追加一个防重复
  478. if($result){
  479. if($redis_ids) {
  480. $redis_ids[] = $result;
  481. } else {
  482. $redis_ids = [$result];
  483. }
  484. Cache::set($user_id_redis,json_encode($redis_ids));
  485. //设置次数
  486. /*$second = strtotime(date('Y-m-d'))+86400 - time();
  487. Cache::set($times_limit_redis,$user_times+1,$second);*/
  488. }else{
  489. Cache::rm($user_id_redis);
  490. }
  491. $this->success(1,$result);
  492. }
  493. private function pipei_action($redis_ids,$where,$where_black){
  494. $where_op = [];
  495. if(!empty($redis_ids)){
  496. $where_op['user.id'] = ['NOTIN',$redis_ids];
  497. }
  498. $result = Db::name('user')->alias('user')
  499. // ->join('user_active active' ,'user.id = active.user_id','LEFT')
  500. ->where($where)
  501. ->where($where_op)
  502. ->where($where_black)
  503. ->orderRaw('rand()')
  504. ->value('user.id');
  505. return $result;
  506. }
  507. public function test(){
  508. //缓存,防重复
  509. $user_id = $this->auth->id;
  510. $user_id_redis = 'pipei_repeat_'.$user_id;
  511. $redis_ids = json_decode(Cache::get($user_id_redis),true);
  512. dump($redis_ids);
  513. $times_limit_redis = 'pipei_times_limit_'.$user_id;
  514. $user_times = Cache::get($times_limit_redis) ?: 0;
  515. dump($user_times);
  516. }
  517. public function testrm(){
  518. $user_id = $this->auth->id;
  519. $user_id_redis = 'pipei_repeat_'.$user_id;
  520. Cache::rm($user_id_redis);
  521. $times_limit_redis = 'pipei_times_limit_'.$user_id;
  522. Cache::rm($times_limit_redis);
  523. }
  524. }