Index.php 30 KB

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