Index.php 30 KB

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