Index.php 24 KB

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