Index.php 21 KB

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