Index.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  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. // function getUinqueNo($length = 8) {
  37. // $newid = Random::build("alnum",$length);
  38. //// if(in_array($newid,$nos)) {
  39. //// $this->getUinqueNo(8);
  40. //// }
  41. // return $newid;
  42. // }
  43. /**
  44. * 获取主播魅力值排行
  45. */
  46. public function getUserCharmRankList() {
  47. $time = $this->request->request("time",0,"intval"); //时间筛选 1=小时榜,2=今日榜,3=本周榜,4=月榜
  48. if(!in_array($time,[1,2,3,4])) {
  49. $this->error("参数传入错误!");
  50. }
  51. $hour = strtotime(date("Y-m-d H:00:00"));
  52. $today = strtotime(date("Y-m-d 00:00:00"));
  53. $weekend = strtotime('monday this week');
  54. // $weekend = mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y"));
  55. $month = strtotime(date("Y-m-01 00:00:00"));
  56. // 剩余时间
  57. $thistime = time();
  58. switch ($time) {
  59. case 1:
  60. $redtime = 3600-($thistime - $hour);
  61. break;
  62. case 2:
  63. $redtime = 3600*24-($thistime - $today);
  64. break;
  65. case 3:
  66. $redtime = 3600*24*7-($thistime - $weekend);
  67. break;
  68. case 4:
  69. $monthend = mktime(23,59,59,date("m"),date("t"),date("Y"));
  70. $redtime = ($monthend - $month)-($thistime - $month);
  71. break;
  72. }
  73. $timeArr = [1=>$hour,2=>$today,3=>$weekend,4=>$month];
  74. $where = [];
  75. $where["a.createtime"] = ["gt",$timeArr[$time]];
  76. $list = \app\common\model\UserCharmRank::alias("a")
  77. ->field("a.party_id as id,sum(a.charm) as charm,u.avatar,u.nickname,u.gender,u.level,u.is_live")
  78. ->where($where)
  79. ->join("hx_user u","u.id = a.user_id",'LEFT')
  80. // ->join("hx_party p","p.user_id = a.user_id",'LEFT')
  81. ->group("a.user_id")
  82. ->order("charm","desc")
  83. ->limit(100)
  84. ->select();
  85. $data = [];
  86. $data["redtime"] = $redtime;
  87. $data["data"] = $list;
  88. $this->success("获取成功!",$data);
  89. }
  90. /**
  91. * 获取收礼排行
  92. */
  93. public function getUserGiftRank() {
  94. $time = $this->request->request("time",0,"intval"); //时间筛选 1=小时榜,2=今日榜,3=本周榜,4=月榜
  95. if(!in_array($time,[1,2,3,4])) {
  96. $this->error("参数传入错误!");
  97. }
  98. $hour = strtotime(date("Y-m-d H:00:00"));
  99. $today = strtotime(date("Y-m-d 00:00:00"));
  100. $weekend = strtotime('monday this week');
  101. $month = strtotime(date("Y-m-01 00:00:00"));
  102. // 剩余时间
  103. $thistime = time();
  104. switch ($time) {
  105. case 1:
  106. $redtime = 3600-($thistime - $hour);
  107. break;
  108. case 2:
  109. $redtime = 3600*24-($thistime - $today);
  110. break;
  111. case 3:
  112. $redtime = 3600*24*7-($thistime - $weekend);
  113. break;
  114. case 4:
  115. $monthend = mktime(23,59,59,date("m"),date("t"),date("Y"));
  116. $redtime = ($monthend - $month)-($thistime - $month);
  117. break;
  118. }
  119. $timeArr = [1=>$hour,2=>$today,3=>$weekend,4=>$month];
  120. $where = [];
  121. $where["a.createtime"] = ["gt",$timeArr[$time]];
  122. $list = model('GiftUserParty')->alias("a")
  123. ->field("sum(a.value) as total_price,a.user_to_id,u.avatar,u.nickname")
  124. ->where($where)
  125. ->join("hx_user u","u.id = a.user_to_id")
  126. ->group("a.user_to_id")
  127. ->order("total_price","desc")
  128. ->limit(100)
  129. ->select();
  130. $data = [];
  131. $data["redtime"] = $redtime;
  132. $data["data"] = $list;
  133. $this->success("获取成功!",$data);
  134. }
  135. /**
  136. * 获取消费排行
  137. */
  138. public function getUserPayRank() {
  139. $time = $this->request->request("time",0,"intval"); //时间筛选 1=小时榜,2=今日榜,3=本周榜,4=月榜
  140. if(!in_array($time,[1,2,3,4])) {
  141. $this->error("参数传入错误!");
  142. }
  143. $hour = strtotime(date("Y-m-d H:00:00"));
  144. $today = strtotime(date("Y-m-d 00:00:00"));
  145. $weekend = strtotime('monday this week');
  146. $month = strtotime(date("Y-m-01 00:00:00"));
  147. // 剩余时间
  148. $thistime = time();
  149. switch ($time) {
  150. case 1:
  151. $redtime = 3600-($thistime - $hour);
  152. break;
  153. case 2:
  154. $redtime = 3600*24-($thistime - $today);
  155. break;
  156. case 3:
  157. $redtime = 3600*24*7-($thistime - $weekend);
  158. break;
  159. case 4:
  160. $monthend = mktime(23,59,59,date("m"),date("t"),date("Y"));
  161. $redtime = ($monthend - $month)-($thistime - $month);
  162. break;
  163. }
  164. $timeArr = [1=>$hour,2=>$today,3=>$weekend,4=>$month];
  165. $where = [];
  166. $where["a.type"] = ["in",[0,2,3,5,6,13]];//查看wallet.php文件
  167. $where["a.createtime"] = ["gt",$timeArr[$time]];
  168. $list = model('UserJewelLog')->alias("a")
  169. ->field("sum(a.value) as total_price,a.user_id,u.avatar,u.nickname")
  170. ->where($where)
  171. ->join("hx_user u","u.id = a.user_id")
  172. ->group("a.user_id")
  173. ->order("total_price","desc")
  174. ->limit(100)
  175. ->select();
  176. $data = [];
  177. $data["redtime"] = $redtime;
  178. $data["data"] = $list;
  179. $this->success("获取成功!",$data);
  180. }
  181. /**
  182. * 获取派对热度排序
  183. */
  184. public function getPartyHotList() {
  185. // 剩余时间
  186. $thistime = time();
  187. $hour = strtotime(date("Y-m-d H:00:00"));
  188. $redtime = 3600-($thistime - $hour);
  189. $where = [];
  190. $where["a.createtime"] = ["gt",$hour];
  191. $where["p.room_type"] = 1;
  192. $list = \app\common\model\PartyHot::alias("a")
  193. ->field("sum(a.hot) as hot,p.id,u.avatar,p.party_name,p.party_logo")
  194. ->where($where)
  195. ->join("hx_party p","p.id = a.party_id")
  196. ->join("hx_user u","u.id = p.user_id")
  197. ->group("a.party_id")
  198. ->order("hot","desc")
  199. ->limit(100)
  200. ->select();
  201. $data = [];
  202. $data["redtime"] = $redtime;
  203. $data["data"] = $list;
  204. $this->success("获取成功!",$data);
  205. }
  206. /**
  207. * 首页搜索
  208. */
  209. public function searchUsers() {
  210. $search = $this->request->request("search"); //关键词筛选
  211. if(!$search) {
  212. $this->error("请输入搜索内容!");
  213. }
  214. // 搜索派对
  215. global $whereOr;
  216. $where = [];
  217. $whereOr["party_id"] = $search;
  218. $whereOr["party_name"] = ["like","%$search%"];
  219. $where["room_type"] = 1;
  220. $partyList = \app\common\model\Party::field("id,party_logo,party_id,party_name")
  221. ->where($where)
  222. ->where(function ($query) {
  223. global $whereOr;
  224. $query->whereOr($whereOr);
  225. })->order("party_hot","desc")->select();
  226. // 搜索直播间
  227. global $whereOrlive;
  228. $where = [];
  229. $whereOrlive["party_id"] = $search;
  230. $whereOrlive["party_name"] = ["like","%$search%"];
  231. $where["room_type"] = 2;
  232. $liveList = \app\common\model\Party::field("id,party_logo,party_id,party_name")
  233. ->where($where)
  234. ->where(function ($query) {
  235. global $whereOrlive;
  236. $query->whereOr($whereOrlive);
  237. })
  238. ->order("party_hot","desc")->select();
  239. // 相关用户
  240. $where = [];
  241. $where["a.nickname"] = ["like","%$search%"];
  242. $where["a.u_id"] = $search;
  243. $userList = \app\common\model\User::alias("a")->field("id,avatar,nickname,u_id,f.fans")
  244. ->join("hx_view_fans f","f.user_id = a.id","left")
  245. ->order("a.is_online,a.noble,a.level")
  246. ->whereOr($where)->select();
  247. $res = [];
  248. $res["partylist"] = $partyList;
  249. $res["livelist"] = $liveList;
  250. $res["userlist"] = $userList;
  251. $this->success("获取成功!",$res);
  252. }
  253. /**
  254. * 首页搜索
  255. */
  256. public function searchList() {
  257. $search = $this->request->request("search"); //关键词筛选
  258. if(!$search) {
  259. $this->error("请输入搜索内容!");
  260. }
  261. // 搜索房间(派对和直播)
  262. global $whereOr;
  263. $where = [];
  264. $whereOr["party_id"] = $search;
  265. $whereOr["party_name"] = ["like","%$search%"];
  266. //$where['is_online'] = 1;
  267. $where['is_close'] = 0;
  268. $where['status'] = 1;
  269. $partyList = \app\common\model\Party::field("id,room_type,party_logo,party_id,party_name,party_type")
  270. ->where($where)
  271. ->where(function ($query) {
  272. global $whereOr;
  273. $query->whereOr($whereOr);
  274. })->order("party_hot","desc")->select();
  275. $partyList = collection($partyList)->toArray();
  276. if (!empty($partyList)) {//在线信息
  277. $partyListIds = array_column($partyList,'id');
  278. /*$tenimService = new TenimService();
  279. $partyParams = ['party_ids'=>$partyListIds];
  280. $partyRes = $tenimService->getRoomUser($partyParams);*/
  281. /*if ($partyRes['status'] == 1) {
  282. }*/
  283. $roomService = new RoomService();
  284. foreach ($partyList as $pKey => &$pVal) {
  285. // 派对类型
  286. $partyTypeName = "普通房";
  287. if($pVal["party_type"]) {
  288. $partyTypeName = \app\common\model\PartyType::where(["id"=>$pVal["party_type"]])->value("name");
  289. }
  290. $mod = isset($pVal["party_type"])?intval($pVal["party_type"])%5:1;
  291. $pVal["party_type_color"] = $mod == 0?5:$mod;
  292. $pVal["type_name"] = $partyTypeName;
  293. $userDataResult = $roomService->getPartyUserList(['party_id'=>$pVal['id']]);
  294. $userDataRes = isset($userDataResult['data']) ? $userDataResult['data'] : [];
  295. $pVal['member_list'] = isset($userDataRes['member_list']) ? $userDataRes['member_list'] : [];
  296. $pVal['online_num'] = isset($userDataRes['online_num']) ? $userDataRes['online_num'] : [];
  297. }
  298. }
  299. // 家族
  300. $guildWhere['status'] = 1;
  301. $guildWhere['name'] = ["like","%$search%"];
  302. $guildList = model('Guild')->where($guildWhere)->with(['guildmember'=>function($gquery){
  303. $gquery->where(['status'=>1]);
  304. }])->field('id,g_id,name,image')->select();
  305. if (!empty($guildList)) {
  306. $userField = 'id,nickname,avatar';
  307. foreach ($guildList as $gKey => &$gVal) {
  308. $userData =[];
  309. if (isset($gVal['guildmember'])) {
  310. $memberUids = array_column($gVal['guildmember'],'user_id');
  311. $userWhere['is_online'] = 1;
  312. $userWhere['id'] = ['in',$memberUids];
  313. $userData = model('User')->field($userField)->where($userWhere)->select();
  314. }
  315. /*$mod = intval($gKey)%5;
  316. $pVal["party_type_color"] = $mod == 0?5:$mod;*/
  317. $gVal["party_type_color"] = 1;
  318. $gVal["type_name"] = '普通房';
  319. $gVal['member_list'] = $userData;
  320. $gVal['online_num'] = count($userData);
  321. unset($gVal['guildmember']);
  322. }
  323. }
  324. // 相关用户
  325. $where = [];
  326. $where["a.nickname"] = ["like","%$search%"];
  327. $where["a.u_id"] = $search;
  328. $userList = \app\common\model\User::alias("a")->field("id,avatar,nickname,u_id,f.fans")
  329. ->join("hx_view_fans f","f.user_id = a.id","left")
  330. ->order("a.is_online,a.noble,a.level")
  331. ->whereOr($where)->select();
  332. $res = [];
  333. $res["roomlist"] = $partyList;
  334. $res["guildlist"] = $guildList;
  335. $res["userlist"] = $userList;
  336. $this->success("获取成功!",$res);
  337. }
  338. /**
  339. * 获取下载二维码和邀请码
  340. */
  341. public function getInviteCode() {
  342. // 获取二维码
  343. $host = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"];
  344. $qrcode = $this->httpurl($host.config("site.qrcode"));
  345. $miniqrcode = $this->httpurl($host.config("site.miniqrcode"));
  346. // 获取用户邀请码
  347. $inviteCode = \app\common\model\User::where(["id"=>$this->auth->id])->value("invite_no");
  348. $downlowdLink = $host."/index/index/appJump?t=wlt".rand(10,999).Random::alpha(8);
  349. $this->success("获取成功!",["qrcode"=>$qrcode,"miniqrcode"=>$miniqrcode,"inviteCode"=>$inviteCode,"downlowdLink"=>$downlowdLink]);
  350. }
  351. /**
  352. * 获取app分享海报
  353. */
  354. public function getAppShare() {
  355. $this->success("获取成功!",["url"=>$this->httpurl(config("site.appShare"))]);
  356. }
  357. /**
  358. * 获取邀请图片
  359. */
  360. public function getInviteImg() {
  361. $plat = $this->request->request("plat",1); //平台:1=小程序,2=app
  362. if(!in_array($plat,[1,2])) $this->error("参数错误");
  363. // 获取用户的邀请码
  364. $invitecode = \app\common\model\User::where(["id"=>$this->auth->id])->value("invite_no");
  365. // 文字图片合成
  366. $bigImgPath = $this->httpurlLocal('/assets/img/inviteimg.jpeg');
  367. $img = imagecreatefromstring(file_get_contents($bigImgPath));
  368. //字体文件
  369. $font = realpath('./assets/fonts/lato/lato-black.ttf');
  370. //字体颜色(RGB)
  371. $black = imagecolorallocate($img, 217, 76, 41);
  372. //字体大小
  373. $fontSize = 30;
  374. //旋转角度
  375. $circleSize = 0;
  376. //左边距
  377. $left = 275;
  378. //上边距
  379. $top = 540;
  380. imagefttext($img, $fontSize, $circleSize, $left, $top, $black, $font, $invitecode);
  381. $filename = date("YmdH").".jpeg";
  382. $path = "/uploads/qrcode/".$filename;
  383. $file = $_SERVER['DOCUMENT_ROOT'] . $path;//打开文件准备写入
  384. list($bgWidth, $bgHight, $bgType) = getimagesize($bigImgPath);
  385. switch ($bgType) {
  386. case 1://gif
  387. header('Content-Type:image/gif');
  388. imagegif($img,$file);
  389. break;
  390. case 2://jpg
  391. header('Content-Type:image/jpg');
  392. imagejpeg($img,$file);
  393. break;
  394. case 3://jpg
  395. header('Content-Type:image/png');
  396. imagepng($img,$file);
  397. break;
  398. default:
  399. break;
  400. }
  401. //销毁照片
  402. imagedestroy($img);
  403. // 图片和二维码合成
  404. $qrcode = $plat == 1 ? config("site.miniqrcode"):config("site.qrcode");
  405. $background = $file;
  406. $target = $this->httpurl($qrcode);
  407. $background_iamge = imagecreatefromstring(file_get_contents($background));
  408. $target_image = imagecreatefromstring(file_get_contents($target));
  409. list($target_width, $target_height, $target_type) = getimagesize($target);
  410. imagecopymerge($background_iamge , $target_image , 250, 700, 0, 0, $target_width, $target_height, 100);
  411. list($background_width, $background_height, $background_type) = getimagesize($background);
  412. switch ($background_type) {
  413. case 1://gif
  414. header('Content-Type:image/gif');
  415. imagegif($background_iamge,$file);
  416. break;
  417. case 2://jpg
  418. header('Content-Type:image/jpg');
  419. imagejpeg($background_iamge,$file);
  420. break;
  421. case 3://jpg
  422. header('Content-Type:image/png');
  423. imagepng($background_iamge,$file);
  424. break;
  425. default:
  426. break;
  427. }
  428. $savepath = $this->httpurlLocal($path);
  429. $this->success("获取成功!",$savepath);
  430. }
  431. /**
  432. * 获取银行列表
  433. */
  434. public function getBankList() {
  435. $this->success("获取成功!",["banklist"=>\app\common\model\Bank::select()]);
  436. }
  437. /**
  438. * 获取开关配置
  439. */
  440. public function getSwitch() {
  441. $this->success("获取成功!",["switch"=>config("site.switch")]);
  442. }
  443. /**
  444. * 星座列表
  445. * @return void
  446. */
  447. public function starList()
  448. {
  449. try {
  450. $field = 'id,name,image';
  451. $where['status'] = 1;
  452. $result = model('Constellation')->field($field)->where($where)->order('weigh asc')->select();
  453. if (!$result) {
  454. $result = list_domain_image($result,['image']);
  455. }
  456. $this->success('获取成功',$result);
  457. } catch (Exception $e) {
  458. $this->error($e->getMessage());
  459. }
  460. }
  461. //开关设置
  462. public function switchenum(){
  463. $rs = [
  464. 'alipay_switch' => config('site.alipay_switch'), //支付宝支付开关
  465. 'wechat_switch' => config('site.wechat_switch'), //微信支付开关
  466. 'recharge_switch' => config('site.recharge_switch'), //所有充值开关
  467. ];
  468. $this->success('success',$rs);
  469. }
  470. /////////////
  471. public function index(){
  472. echo 'apisuccess';
  473. exit;
  474. }
  475. //附近
  476. public function fujin(){
  477. $where = [
  478. 'user.id' => ['neq',$this->auth->id],
  479. 'user.status' => 1,
  480. 'user.city_id' => $this->auth->city_id,
  481. ];
  482. //排除黑名单的
  483. $where_black = [];
  484. $black_ids = Db::name('user_blacklist')->where(['user_id'=>$this->auth->id])->column('black_user_id');
  485. if(!empty($black_ids)){
  486. $where_black['user.id'] = ['NOTIN',$black_ids];
  487. }
  488. $field = [
  489. 'user.id',
  490. 'user.u_id',
  491. 'user.username',
  492. 'user.nickname',
  493. 'user.avatar',
  494. 'user.gender',
  495. 'user.desc',
  496. 'age.name as age_text',
  497. 'job.name as job_text',
  498. 'area.name as city_text',
  499. '(st_distance(point (' . $this->auth->longitude . ', ' . $this->auth->latitude . '),point(user.longitude,user.latitude))*111195) as distance',
  500. ];
  501. $list = Db::name('user')->alias('user')->field($field)
  502. ->join('age','user.age_id = age.id','LEFT')
  503. ->join('enum_job job','user.job_id = job.id','LEFT')
  504. ->join('shopro_area area','user.city_id = area.id','LEFT')
  505. ->where($where)
  506. ->where($where_black)
  507. ->order('distance asc')
  508. ->autopage()
  509. ->select();
  510. $list = list_domain_image($list,['avatar']);
  511. foreach($list as $key => &$val){
  512. $val['distance'] = bcdiv(intval($val['distance']),1000,1).'km';
  513. $val['is_follow'] = $this->is_follow($this->auth->id,$val['id']);
  514. $val['is_friend'] = $this->is_friend($this->auth->id,$val['id']);
  515. }
  516. $this->success(1,$list);
  517. }
  518. //同城
  519. public function samecity(){
  520. $where = [
  521. 'user.id' => ['neq',$this->auth->id],
  522. 'user.status' => 1,
  523. 'user.city_id' => $this->auth->city_id,
  524. ];
  525. //排除黑名单的
  526. $where_black = [];
  527. $black_ids = Db::name('user_blacklist')->where(['user_id'=>$this->auth->id])->column('black_user_id');
  528. if(!empty($black_ids)){
  529. $where_black['user.id'] = ['NOTIN',$black_ids];
  530. }
  531. $field = [
  532. 'user.id',
  533. 'user.u_id',
  534. 'user.username',
  535. 'user.nickname',
  536. 'user.avatar',
  537. 'user.gender',
  538. 'user.desc',
  539. 'age.name as age_text',
  540. 'job.name as job_text',
  541. 'area.name as city_text',
  542. ];
  543. $list = Db::name('user')->alias('user')->field($field)
  544. ->join('age age','user.age_id = age.id','LEFT')
  545. ->join('enum_job job','user.job_id = job.id','LEFT')
  546. ->join('shopro_area area','user.city_id = area.id','LEFT')
  547. ->where($where)
  548. ->where($where_black)
  549. ->autopage()
  550. ->select();
  551. $list = list_domain_image($list,['avatar']);
  552. $this->success(1,$list);
  553. }
  554. //匹配配置
  555. /*public function pipei_config(){
  556. $result = [
  557. 'index_pipei_switch' => config('site.index_pipei_switch'), //匹配开关
  558. ];
  559. //首页匹配每天每人匹配次数
  560. $user_id = $this->auth->id;
  561. $is_vip = $this->is_vip($this->auth->id);
  562. $times_limit = $is_vip == 1 ? config('site.pipei_oneday_vipuser_times') : config('site.index_pipei_oneday_user_times');
  563. $times_limit_redis = 'pipei_times_limit_'.$user_id;
  564. $user_times = Cache::get($times_limit_redis) ?: 0;
  565. if($times_limit > -1){
  566. $remain_times = $times_limit - $user_times;
  567. if($remain_times < 0){
  568. $remain_times = 0;
  569. }
  570. }else{
  571. $remain_times = -1;
  572. }
  573. $result['remain_times'] = $remain_times;
  574. $this->success(1,$result);
  575. }*/
  576. //匹配
  577. //做防止重复处理,参照荔枝
  578. //做用户在线处理,参照mita,用户不在线,用户语音视频中,用户房间内时,不能被匹配到
  579. public function pipei(){
  580. //首页匹配功能开关
  581. /*$index_pipei_switch = config('site.index_pipei_switch');
  582. if($index_pipei_switch != 1){
  583. $this->error('匹配功能维护中,请稍后再试');
  584. }*/
  585. //缓存,防重复
  586. $user_id = $this->auth->id;
  587. $user_id_redis = 'pipei_repeat_'.$user_id;
  588. $redis_ids = json_decode(Cache::get($user_id_redis),true);
  589. //首页匹配每天每人匹配次数
  590. /*$is_vip = $this->is_vip($this->auth->id);
  591. $times_limit = $is_vip == 1 ? config('site.pipei_oneday_vipuser_times') : config('site.index_pipei_oneday_user_times');
  592. $times_limit_redis = 'pipei_times_limit_'.$user_id;
  593. $user_times = Cache::get($times_limit_redis) ?: 0;
  594. if($times_limit > -1 && $user_times >= $times_limit){
  595. $this->error('今日已超匹配上限'.$times_limit.'次');
  596. }*/
  597. //where
  598. $where = [
  599. 'user.id' => ['neq',$this->auth->id],
  600. 'user.status' => 1,
  601. ];
  602. //性别
  603. $gender = input('gender','all');
  604. if($gender != 'all'){
  605. $where['user.gender'] = $gender;
  606. }
  607. //排除黑名单的
  608. $where_black = [];
  609. $black_ids = Db::name('user_blacklist')->where(['user_id'=>$this->auth->id])->column('black_user_id');
  610. if(!empty($black_ids)){
  611. $where_black['user.id'] = ['NOTIN',$black_ids];
  612. }
  613. //匹配一个
  614. $result = $this->pipei_action($redis_ids,$where,$where_black);
  615. //匹配不到,移除防重复
  616. if(!$result) {
  617. Cache::rm($user_id_redis);
  618. $redis_ids = [];
  619. $result = $this->pipei_action($redis_ids,$where,$where_black);
  620. }
  621. // 追加一个防重复
  622. if($result){
  623. if($redis_ids) {
  624. $redis_ids[] = $result;
  625. } else {
  626. $redis_ids = [$result];
  627. }
  628. Cache::set($user_id_redis,json_encode($redis_ids));
  629. //设置次数
  630. /*$second = strtotime(date('Y-m-d'))+86400 - time();
  631. Cache::set($times_limit_redis,$user_times+1,$second);*/
  632. }else{
  633. Cache::rm($user_id_redis);
  634. }
  635. $this->success(1,$result);
  636. }
  637. private function pipei_action($redis_ids,$where,$where_black){
  638. $where_op = [];
  639. if(!empty($redis_ids)){
  640. $where_op['user.id'] = ['NOTIN',$redis_ids];
  641. }
  642. $result = Db::name('user')->alias('user')
  643. // ->join('user_active active' ,'user.id = active.user_id','LEFT')
  644. ->where($where)
  645. ->where($where_op)
  646. ->where($where_black)
  647. ->orderRaw('rand()')
  648. ->value('user.id');
  649. return $result;
  650. }
  651. public function test(){
  652. //缓存,防重复
  653. $user_id = $this->auth->id;
  654. $user_id_redis = 'pipei_repeat_'.$user_id;
  655. $redis_ids = json_decode(Cache::get($user_id_redis),true);
  656. dump($redis_ids);
  657. $times_limit_redis = 'pipei_times_limit_'.$user_id;
  658. $user_times = Cache::get($times_limit_redis) ?: 0;
  659. dump($user_times);
  660. }
  661. public function testrm(){
  662. $user_id = $this->auth->id;
  663. $user_id_redis = 'pipei_repeat_'.$user_id;
  664. Cache::rm($user_id_redis);
  665. $times_limit_redis = 'pipei_times_limit_'.$user_id;
  666. Cache::rm($times_limit_redis);
  667. }
  668. }