Index.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  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','getInviteImg','getWebsiteInfoForMini','getBankList',
  19. 'getSwitch','ageList','starList','bannerList'];
  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. if($params == "boxGiftLogo") {
  48. echo $this->success("获取成功!",$this->httpurl(config("site.".$params)));
  49. exit;
  50. }
  51. echo "<html><body>";
  52. echo config("site.".$params);
  53. echo "</body></html>";exit;
  54. }
  55. /**
  56. * 获取用户协议等 小程序
  57. */
  58. public function getWebsiteInfoForMini() {
  59. $params = $this->request->request("params"); //内容
  60. $res = config("site.".$params);
  61. if($params == "boxGiftLogo") $res = $this->httpurl(config("site.".$params));
  62. $this->success("获取成功!",$res);
  63. }
  64. /**
  65. * 联系我们
  66. */
  67. public function contactus() {
  68. $list = \app\common\model\Config::where(["group"=>"basic","name"=>["in",["email","mobile"]]])->select();
  69. $data = [];
  70. foreach($list as $k => $v) {
  71. $v["name"] == "email" && $data["email"] = $v["value"];
  72. $v["name"] == "mobile" && $data["mobile"] = $v["value"];
  73. }
  74. $this->success("获取成功!",$data);
  75. }
  76. /*
  77. * 获取系统消息列表
  78. */
  79. public function getMessageSys() {
  80. $page = $this->request->request('page',1); // 分页
  81. $pageNum = $this->request->request('pageNum',10); // 分页
  82. // 分页搜索构建
  83. $pageStart = ($page-1)*$pageNum;
  84. $flag = $this->request->request("flag",1,"intval"); //标识:1=只取一条,0=全部
  85. $type = $this->request->request("type",1);
  86. $obj = Db::name('message_sys')->where('type',$type)->order("id","desc")->limit($pageStart,$pageNum);
  87. if($flag == 1) {
  88. $list = $obj->find();
  89. $list || $list = [];
  90. $list && $list["createtime"] = $this->get_last_time($list["createtime"]);
  91. } else {
  92. $list = $obj->select();
  93. if($list) foreach($list as $k => &$v) {
  94. $v["createtime"] = $this->get_last_time($v["createtime"]);
  95. }
  96. }
  97. $this->success("获取成功!",$list);
  98. }
  99. /*
  100. * 获取个人消息列表
  101. */
  102. public function getMessage() {
  103. $page = $this->request->request('page',1); // 分页
  104. $pageNum = $this->request->request('pageNum',10); // 分页
  105. // 分页搜索构建
  106. $pageStart = ($page-1)*$pageNum;
  107. $flag = $this->request->request("flag",1,"intval"); //标识:1=只取一条,0=全部
  108. $user_id = $this->auth->id;
  109. $obj = \app\common\model\Message::where(["user_id"=>$user_id])->order("createtime","desc")->limit($pageStart,$pageNum);
  110. if($flag == 1) {
  111. $list = $obj->find();
  112. $list || $list = [];
  113. $list && $list["createtime"] = $this->get_last_time($list["createtime"]);
  114. } else {
  115. $list = $obj->select();
  116. if($list) foreach($list as $k => &$v) {
  117. $v["createtime"] = $this->get_last_time($v["createtime"]);
  118. }
  119. }
  120. $this->success("获取成功!",$list);
  121. }
  122. /**
  123. * 删除个人消息
  124. */
  125. public function delMessage() {
  126. $id = $this->request->request("id",0,"intval"); //消息ID
  127. if($id <= 0) {
  128. $this->error("参数传入错误!");
  129. }
  130. $res = \app\common\model\Message::where(["id"=>$id,"user_id"=>$this->auth->id])->delete();
  131. if($res) {
  132. $this->success("删除成功!");
  133. } else {
  134. $this->error("删除失败!");
  135. }
  136. }
  137. /**
  138. * 获取主播魅力值排行
  139. */
  140. public function getUserCharmRankList() {
  141. $time = $this->request->request("time",0,"intval"); //时间筛选 1=小时榜,2=今日榜,3=本周榜,4=月榜
  142. if(!in_array($time,[1,2,3,4])) {
  143. $this->error("参数传入错误!");
  144. }
  145. $hour = strtotime(date("Y-m-d H:00:00"));
  146. $today = strtotime(date("Y-m-d 00:00:00"));
  147. $weekend = strtotime('monday this week');
  148. // $weekend = mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y"));
  149. $month = strtotime(date("Y-m-01 00:00:00"));
  150. // 剩余时间
  151. $thistime = time();
  152. switch ($time) {
  153. case 1:
  154. $redtime = 3600-($thistime - $hour);
  155. break;
  156. case 2:
  157. $redtime = 3600*24-($thistime - $today);
  158. break;
  159. case 3:
  160. $redtime = 3600*24*7-($thistime - $weekend);
  161. break;
  162. case 4:
  163. $monthend = mktime(23,59,59,date("m"),date("t"),date("Y"));
  164. $redtime = ($monthend - $month)-($thistime - $month);
  165. break;
  166. }
  167. $timeArr = [1=>$hour,2=>$today,3=>$weekend,4=>$month];
  168. $where = [];
  169. $where["a.createtime"] = ["gt",$timeArr[$time]];
  170. $list = \app\common\model\UserCharmRank::alias("a")
  171. ->field("a.party_id as id,sum(a.charm) as charm,u.avatar,u.nickname,u.gender,u.level,u.is_live")
  172. ->where($where)
  173. ->join("hx_user u","u.id = a.user_id",'LEFT')
  174. // ->join("hx_party p","p.user_id = a.user_id",'LEFT')
  175. ->group("a.user_id")
  176. ->order("charm","desc")
  177. ->limit(100)
  178. ->select();
  179. $data = [];
  180. $data["redtime"] = $redtime;
  181. $data["data"] = $list;
  182. $this->success("获取成功!",$data);
  183. }
  184. /**
  185. * 获取收礼排行
  186. */
  187. public function getUserGiftRank() {
  188. $time = $this->request->request("time",0,"intval"); //时间筛选 1=小时榜,2=今日榜,3=本周榜,4=月榜
  189. if(!in_array($time,[1,2,3,4])) {
  190. $this->error("参数传入错误!");
  191. }
  192. $hour = strtotime(date("Y-m-d H:00:00"));
  193. $today = strtotime(date("Y-m-d 00:00:00"));
  194. $weekend = strtotime('monday this week');
  195. $month = strtotime(date("Y-m-01 00:00:00"));
  196. // 剩余时间
  197. $thistime = time();
  198. switch ($time) {
  199. case 1:
  200. $redtime = 3600-($thistime - $hour);
  201. break;
  202. case 2:
  203. $redtime = 3600*24-($thistime - $today);
  204. break;
  205. case 3:
  206. $redtime = 3600*24*7-($thistime - $weekend);
  207. break;
  208. case 4:
  209. $monthend = mktime(23,59,59,date("m"),date("t"),date("Y"));
  210. $redtime = ($monthend - $month)-($thistime - $month);
  211. break;
  212. }
  213. $timeArr = [1=>$hour,2=>$today,3=>$weekend,4=>$month];
  214. $where = [];
  215. $where["a.createtime"] = ["gt",$timeArr[$time]];
  216. $list = model('GiftUserParty')->alias("a")
  217. ->field("sum(a.value) as total_price,u.avatar,u.nickname")
  218. ->where($where)
  219. ->join("hx_user u","u.id = a.user_id")
  220. ->group("a.user_to_id")
  221. ->order("total_price","desc")
  222. ->limit(100)
  223. ->select();
  224. $data = [];
  225. $data["redtime"] = $redtime;
  226. $data["data"] = $list;
  227. $this->success("获取成功!",$data);
  228. }
  229. /**
  230. * 获取消费排行
  231. */
  232. public function getUserPayRank() {
  233. $time = $this->request->request("time",0,"intval"); //时间筛选 1=小时榜,2=今日榜,3=本周榜,4=月榜
  234. if(!in_array($time,[1,2,3,4])) {
  235. $this->error("参数传入错误!");
  236. }
  237. $hour = strtotime(date("Y-m-d H:00:00"));
  238. $today = strtotime(date("Y-m-d 00:00:00"));
  239. $weekend = strtotime('monday this week');
  240. $month = strtotime(date("Y-m-01 00:00:00"));
  241. // 剩余时间
  242. $thistime = time();
  243. switch ($time) {
  244. case 1:
  245. $redtime = 3600-($thistime - $hour);
  246. break;
  247. case 2:
  248. $redtime = 3600*24-($thistime - $today);
  249. break;
  250. case 3:
  251. $redtime = 3600*24*7-($thistime - $weekend);
  252. break;
  253. case 4:
  254. $monthend = mktime(23,59,59,date("m"),date("t"),date("Y"));
  255. $redtime = ($monthend - $month)-($thistime - $month);
  256. break;
  257. }
  258. $timeArr = [1=>$hour,2=>$today,3=>$weekend,4=>$month];
  259. $where = [];
  260. $where["a.type"] = ["in",[0,2,3,5,6,11,13]];//查看wallet.php文件
  261. $where["a.createtime"] = ["gt",$timeArr[$time]];
  262. $list = model('UserJewelLog')->alias("a")
  263. ->field("sum(a.value) as total_price,u.avatar,u.nickname")
  264. ->where($where)
  265. ->join("hx_user u","u.id = a.user_id")
  266. ->group("a.user_id")
  267. ->order("total_price","desc")
  268. ->limit(100)
  269. ->select();
  270. $data = [];
  271. $data["redtime"] = $redtime;
  272. $data["data"] = $list;
  273. $this->success("获取成功!",$data);
  274. }
  275. /**
  276. * 获取派对热度排序
  277. */
  278. public function getPartyHotList() {
  279. // 剩余时间
  280. $thistime = time();
  281. $hour = strtotime(date("Y-m-d H:00:00"));
  282. $redtime = 3600-($thistime - $hour);
  283. $where = [];
  284. $where["a.createtime"] = ["gt",$hour];
  285. $where["p.room_type"] = 1;
  286. $list = \app\common\model\PartyHot::alias("a")
  287. ->field("sum(a.hot) as hot,p.id,u.avatar,p.party_name,p.party_logo")
  288. ->where($where)
  289. ->join("hx_party p","p.id = a.party_id")
  290. ->join("hx_user u","u.id = p.user_id")
  291. ->group("a.party_id")
  292. ->order("hot","desc")
  293. ->limit(100)
  294. ->select();
  295. $data = [];
  296. $data["redtime"] = $redtime;
  297. $data["data"] = $list;
  298. $this->success("获取成功!",$data);
  299. }
  300. /**
  301. * 首页搜索
  302. */
  303. public function searchUsers() {
  304. $search = $this->request->request("search"); //关键词筛选
  305. if(!$search) {
  306. $this->error("请输入搜索内容!");
  307. }
  308. // 搜索派对
  309. global $whereOr;
  310. $where = [];
  311. $whereOr["party_id"] = $search;
  312. $whereOr["party_name"] = ["like","%$search%"];
  313. $where["room_type"] = 1;
  314. $partyList = \app\common\model\Party::field("id,party_logo,party_id,party_name")
  315. ->where($where)
  316. ->where(function ($query) {
  317. global $whereOr;
  318. $query->whereOr($whereOr);
  319. })->order("party_hot","desc")->select();
  320. // 搜索直播间
  321. global $whereOrlive;
  322. $where = [];
  323. $whereOrlive["party_id"] = $search;
  324. $whereOrlive["party_name"] = ["like","%$search%"];
  325. $where["room_type"] = 2;
  326. $liveList = \app\common\model\Party::field("id,party_logo,party_id,party_name")
  327. ->where($where)
  328. ->where(function ($query) {
  329. global $whereOrlive;
  330. $query->whereOr($whereOrlive);
  331. })
  332. ->order("party_hot","desc")->select();
  333. // 相关用户
  334. $where = [];
  335. $where["a.nickname"] = ["like","%$search%"];
  336. $where["a.u_id"] = $search;
  337. $userList = \app\common\model\User::alias("a")->field("id,avatar,nickname,u_id,f.fans")
  338. ->join("hx_view_fans f","f.user_id = a.id","left")
  339. ->order("a.is_online,a.noble,a.level")
  340. ->whereOr($where)->select();
  341. $res = [];
  342. $res["partylist"] = $partyList;
  343. $res["livelist"] = $liveList;
  344. $res["userlist"] = $userList;
  345. $this->success("获取成功!",$res);
  346. }
  347. /**
  348. * 首页搜索
  349. */
  350. public function searchList() {
  351. $search = $this->request->request("search"); //关键词筛选
  352. if(!$search) {
  353. $this->error("请输入搜索内容!");
  354. }
  355. // 搜索房间(派对和直播)
  356. global $whereOr;
  357. $where = [];
  358. $whereOr["party_id"] = $search;
  359. $whereOr["party_name"] = ["like","%$search%"];
  360. //$where['is_online'] = 1;
  361. $where['status'] = 1;
  362. $partyList = \app\common\model\Party::field("id,party_logo,party_id,party_name,party_type")
  363. ->where($where)
  364. ->where(function ($query) {
  365. global $whereOr;
  366. $query->whereOr($whereOr);
  367. })->order("party_hot","desc")->select();
  368. $partyList = collection($partyList)->toArray();
  369. if (!empty($partyList)) {//在线信息
  370. $partyListIds = array_column($partyList,'id');
  371. /*$tenimService = new TenimService();
  372. $partyParams = ['party_ids'=>$partyListIds];
  373. $partyRes = $tenimService->getRoomUser($partyParams);*/
  374. /*if ($partyRes['status'] == 1) {
  375. }*/
  376. $roomService = new RoomService();
  377. foreach ($partyList as $pKey => &$pVal) {
  378. // 派对类型
  379. $partyTypeName = "普通房";
  380. if($pVal["party_type"]) {
  381. $partyTypeName = \app\common\model\PartyType::where(["id"=>$pVal["party_type"]])->value("name");
  382. }
  383. $mod = isset($pVal["party_type"])?intval($pVal["party_type"])%5:1;
  384. $pVal["party_type_color"] = $mod == 0?5:$mod;
  385. $pVal["type_name"] = $partyTypeName;
  386. $userDataResult = $roomService->getPartyUserList(['party_id'=>$pVal['id']]);
  387. $userDataRes = isset($userDataResult['data']) ? $userDataResult['data'] : [];
  388. $pVal['member_list'] = isset($userDataRes['member_list']) ? $userDataRes['member_list'] : [];
  389. $pVal['online_num'] = isset($userDataRes['online_num']) ? $userDataRes['online_num'] : [];
  390. }
  391. }
  392. // 家族
  393. $guildWhere['status'] = 1;
  394. $guildWhere['name'] = ["like","%$search%"];
  395. $guildList = model('Guild')->where($guildWhere)->with(['guildmember'=>function($gquery){
  396. $gquery->where(['status'=>1]);
  397. }])->field('id,g_id,name,image')->select();
  398. if (!empty($guildList)) {
  399. $userField = 'id,nickname,avatar';
  400. foreach ($guildList as $gKey => &$gVal) {
  401. $userData =[];
  402. if (isset($gVal['guildmember'])) {
  403. $memberUids = array_column($gVal['guildmember'],'user_id');
  404. $userWhere['is_online'] = 1;
  405. $userWhere['id'] = ['in',$memberUids];
  406. $userData = model('User')->field($userField)->where($userWhere)->select();
  407. }
  408. /*$mod = intval($gKey)%5;
  409. $pVal["party_type_color"] = $mod == 0?5:$mod;*/
  410. $pVal["party_type_color"] = 1;
  411. $pVal["type_name"] = '普通房';
  412. $gVal['member_list'] = $userData;
  413. $gVal['online_num'] = count($userData);
  414. unset($gVal['guildmember']);
  415. }
  416. }
  417. // 相关用户
  418. $where = [];
  419. $where["a.nickname"] = ["like","%$search%"];
  420. $where["a.u_id"] = $search;
  421. $userList = \app\common\model\User::alias("a")->field("id,avatar,nickname,u_id,f.fans")
  422. ->join("hx_view_fans f","f.user_id = a.id","left")
  423. ->order("a.is_online,a.noble,a.level")
  424. ->whereOr($where)->select();
  425. $res = [];
  426. $res["roomlist"] = $partyList;
  427. $res["guildlist"] = $guildList;
  428. $res["userlist"] = $userList;
  429. $this->success("获取成功!",$res);
  430. }
  431. /**
  432. * 获取下载二维码和邀请码
  433. */
  434. public function getInviteCode() {
  435. // 获取二维码
  436. $host = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"];
  437. $qrcode = $this->httpurl($host.config("site.qrcode"));
  438. $miniqrcode = $this->httpurl($host.config("site.miniqrcode"));
  439. // 获取用户邀请码
  440. $inviteCode = \app\common\model\User::where(["id"=>$this->auth->id])->value("invite_no");
  441. $downlowdLink = $host."/index/index/appJump?t=wlt".rand(10,999).Random::alpha(8);
  442. $this->success("获取成功!",["qrcode"=>$qrcode,"miniqrcode"=>$miniqrcode,"inviteCode"=>$inviteCode,"downlowdLink"=>$downlowdLink]);
  443. }
  444. /**
  445. * 获取app分享海报
  446. */
  447. public function getAppShare() {
  448. $this->success("获取成功!",["url"=>$this->httpurl(config("site.appShare"))]);
  449. }
  450. /**
  451. * 获取版本更新信息
  452. */
  453. public function getEdition() {
  454. // 获取二维码
  455. $is_force = config("site.is_force");
  456. $apkUrl = config("site.apkUrl");
  457. $apkName = config("site.apkName");
  458. $desc = config("site.desc");
  459. $versionCode = config("site.versionCode");
  460. $this->success("获取成功!",["versionCode"=>$versionCode,"isForceUpdate"=>$is_force,"apkUrl"=>$apkUrl,"apkName"=>$apkName,"desc"=>$desc]);
  461. }
  462. /**
  463. * 获取邀请图片
  464. */
  465. public function getInviteImg() {
  466. $plat = $this->request->request("plat",1); //平台:1=小程序,2=app
  467. if(!in_array($plat,[1,2])) $this->error("参数错误");
  468. // 获取用户的邀请码
  469. $invitecode = \app\common\model\User::where(["id"=>$this->auth->id])->value("invite_no");
  470. // 文字图片合成
  471. $bigImgPath = $this->httpurlLocal('/assets/img/inviteimg.jpeg');
  472. $img = imagecreatefromstring(file_get_contents($bigImgPath));
  473. //字体文件
  474. $font = realpath('./assets/fonts/lato/lato-black.ttf');
  475. //字体颜色(RGB)
  476. $black = imagecolorallocate($img, 217, 76, 41);
  477. //字体大小
  478. $fontSize = 30;
  479. //旋转角度
  480. $circleSize = 0;
  481. //左边距
  482. $left = 275;
  483. //上边距
  484. $top = 540;
  485. imagefttext($img, $fontSize, $circleSize, $left, $top, $black, $font, $invitecode);
  486. $filename = date("YmdH").".jpeg";
  487. $path = "/uploads/qrcode/".$filename;
  488. $file = $_SERVER['DOCUMENT_ROOT'] . $path;//打开文件准备写入
  489. list($bgWidth, $bgHight, $bgType) = getimagesize($bigImgPath);
  490. switch ($bgType) {
  491. case 1://gif
  492. header('Content-Type:image/gif');
  493. imagegif($img,$file);
  494. break;
  495. case 2://jpg
  496. header('Content-Type:image/jpg');
  497. imagejpeg($img,$file);
  498. break;
  499. case 3://jpg
  500. header('Content-Type:image/png');
  501. imagepng($img,$file);
  502. break;
  503. default:
  504. break;
  505. }
  506. //销毁照片
  507. imagedestroy($img);
  508. // 图片和二维码合成
  509. $qrcode = $plat == 1 ? config("site.miniqrcode"):config("site.qrcode");
  510. $background = $file;
  511. $target = $this->httpurl($qrcode);
  512. $background_iamge = imagecreatefromstring(file_get_contents($background));
  513. $target_image = imagecreatefromstring(file_get_contents($target));
  514. list($target_width, $target_height, $target_type) = getimagesize($target);
  515. imagecopymerge($background_iamge , $target_image , 250, 700, 0, 0, $target_width, $target_height, 100);
  516. list($background_width, $background_height, $background_type) = getimagesize($background);
  517. switch ($background_type) {
  518. case 1://gif
  519. header('Content-Type:image/gif');
  520. imagegif($background_iamge,$file);
  521. break;
  522. case 2://jpg
  523. header('Content-Type:image/jpg');
  524. imagejpeg($background_iamge,$file);
  525. break;
  526. case 3://jpg
  527. header('Content-Type:image/png');
  528. imagepng($background_iamge,$file);
  529. break;
  530. default:
  531. break;
  532. }
  533. $savepath = $this->httpurlLocal($path);
  534. $this->success("获取成功!",$savepath);
  535. }
  536. /**
  537. * 获取银行列表
  538. */
  539. public function getBankList() {
  540. $this->success("获取成功!",["banklist"=>\app\common\model\Bank::select()]);
  541. }
  542. /**
  543. * 获取开关配置
  544. */
  545. public function getSwitch() {
  546. $this->success("获取成功!",["switch"=>config("site.switch")]);
  547. }
  548. /**
  549. * 评论时间转换
  550. * @param null $time
  551. * @return false|string
  552. */
  553. private function get_last_time($time = NULL) {
  554. $text = '';
  555. $time = $time === NULL || $time > time() ? time() : intval($time);
  556. $t = time() - $time; //时间差 (秒)
  557. $y = date('Y', $time)-date('Y', time());//是否跨年
  558. switch($t){
  559. case $t == 0:
  560. $text = '刚刚';
  561. break;
  562. case $t < 60:
  563. $text = $t . '秒前'; // 一分钟内
  564. break;
  565. case $t < 60 * 60:
  566. $text = floor($t / 60) . '分钟前'; //一小时内
  567. break;
  568. case $t < 60 * 60 * 24:
  569. $text = floor($t / (60 * 60)) . '小时前'; // 一天内
  570. break;
  571. case $t < 60 * 60 * 24 * 3:
  572. $text = floor($time/(60*60*24)) ==1 ?'昨天 ' . date('H:i', $time) : '前天 ' . date('H:i', $time) ; //昨天和前天
  573. break;
  574. case $t < 60 * 60 * 24 * 30:
  575. $text = date('m月d日 H:i', $time); //一个月内
  576. break;
  577. case $t < 60 * 60 * 24 * 365&&$y==0:
  578. $text = date('m月d日', $time); //一年内
  579. break;
  580. default:
  581. $text = date('Y年m月d日', $time); //一年以前
  582. break;
  583. }
  584. return $text;
  585. }
  586. /**
  587. * 年龄段列表
  588. * @return void
  589. */
  590. public function ageList()
  591. {
  592. try {
  593. $field = 'id,name';
  594. $where['status'] = 1;
  595. $result = model('Age')->field($field)->where($where)->order('weigh asc')->select();
  596. $this->success('获取成功',$result);
  597. } catch (Exception $e) {
  598. $this->error($e->getMessage());
  599. }
  600. }
  601. /**
  602. * 星座列表
  603. * @return void
  604. */
  605. public function starList()
  606. {
  607. try {
  608. $field = 'id,name,image';
  609. $where['status'] = 1;
  610. $result = model('Constellation')->field($field)->where($where)->order('weigh asc')->select();
  611. if (!$result) {
  612. $result = list_domain_image($result,['image']);
  613. }
  614. $this->success('获取成功',$result);
  615. } catch (Exception $e) {
  616. $this->error($e->getMessage());
  617. }
  618. }
  619. /**
  620. * 轮播图列表
  621. * @return void
  622. */
  623. public function bannerList()
  624. {
  625. try {
  626. $field = 'id,title,image,url';
  627. $where['status'] = 1;
  628. $result = model('Banner')->field($field)->where($where)->order('weigh asc')->select();
  629. if (!$result) {
  630. $result = list_domain_image($result,['image']);
  631. }
  632. $this->success('获取成功',$result);
  633. } catch (Exception $e) {
  634. $this->error($e->getMessage());
  635. }
  636. }
  637. }