Index.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  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,a.user_to_id,u.avatar,u.nickname")
  218. ->where($where)
  219. ->join("hx_user u","u.id = a.user_to_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,13]];//查看wallet.php文件
  261. $where["a.createtime"] = ["gt",$timeArr[$time]];
  262. $list = model('UserJewelLog')->alias("a")
  263. ->field("sum(a.value) as total_price,a.user_id,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['is_close'] = 0;
  362. $where['status'] = 1;
  363. $partyList = \app\common\model\Party::field("id,room_type,party_logo,party_id,party_name,party_type")
  364. ->where($where)
  365. ->where(function ($query) {
  366. global $whereOr;
  367. $query->whereOr($whereOr);
  368. })->order("party_hot","desc")->select();
  369. $partyList = collection($partyList)->toArray();
  370. if (!empty($partyList)) {//在线信息
  371. $partyListIds = array_column($partyList,'id');
  372. /*$tenimService = new TenimService();
  373. $partyParams = ['party_ids'=>$partyListIds];
  374. $partyRes = $tenimService->getRoomUser($partyParams);*/
  375. /*if ($partyRes['status'] == 1) {
  376. }*/
  377. $roomService = new RoomService();
  378. foreach ($partyList as $pKey => &$pVal) {
  379. // 派对类型
  380. $partyTypeName = "普通房";
  381. if($pVal["party_type"]) {
  382. $partyTypeName = \app\common\model\PartyType::where(["id"=>$pVal["party_type"]])->value("name");
  383. }
  384. $mod = isset($pVal["party_type"])?intval($pVal["party_type"])%5:1;
  385. $pVal["party_type_color"] = $mod == 0?5:$mod;
  386. $pVal["type_name"] = $partyTypeName;
  387. $userDataResult = $roomService->getPartyUserList(['party_id'=>$pVal['id']]);
  388. $userDataRes = isset($userDataResult['data']) ? $userDataResult['data'] : [];
  389. $pVal['member_list'] = isset($userDataRes['member_list']) ? $userDataRes['member_list'] : [];
  390. $pVal['online_num'] = isset($userDataRes['online_num']) ? $userDataRes['online_num'] : [];
  391. }
  392. }
  393. // 家族
  394. $guildWhere['status'] = 1;
  395. $guildWhere['name'] = ["like","%$search%"];
  396. $guildList = model('Guild')->where($guildWhere)->with(['guildmember'=>function($gquery){
  397. $gquery->where(['status'=>1]);
  398. }])->field('id,g_id,name,image')->select();
  399. if (!empty($guildList)) {
  400. $userField = 'id,nickname,avatar';
  401. foreach ($guildList as $gKey => &$gVal) {
  402. $userData =[];
  403. if (isset($gVal['guildmember'])) {
  404. $memberUids = array_column($gVal['guildmember'],'user_id');
  405. $userWhere['is_online'] = 1;
  406. $userWhere['id'] = ['in',$memberUids];
  407. $userData = model('User')->field($userField)->where($userWhere)->select();
  408. }
  409. /*$mod = intval($gKey)%5;
  410. $pVal["party_type_color"] = $mod == 0?5:$mod;*/
  411. $gVal["party_type_color"] = 1;
  412. $gVal["type_name"] = '普通房';
  413. $gVal['member_list'] = $userData;
  414. $gVal['online_num'] = count($userData);
  415. unset($gVal['guildmember']);
  416. }
  417. }
  418. // 相关用户
  419. $where = [];
  420. $where["a.nickname"] = ["like","%$search%"];
  421. $where["a.u_id"] = $search;
  422. $userList = \app\common\model\User::alias("a")->field("id,avatar,nickname,u_id,f.fans")
  423. ->join("hx_view_fans f","f.user_id = a.id","left")
  424. ->order("a.is_online,a.noble,a.level")
  425. ->whereOr($where)->select();
  426. $res = [];
  427. $res["roomlist"] = $partyList;
  428. $res["guildlist"] = $guildList;
  429. $res["userlist"] = $userList;
  430. $this->success("获取成功!",$res);
  431. }
  432. /**
  433. * 获取下载二维码和邀请码
  434. */
  435. public function getInviteCode() {
  436. // 获取二维码
  437. $host = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"];
  438. $qrcode = $this->httpurl($host.config("site.qrcode"));
  439. $miniqrcode = $this->httpurl($host.config("site.miniqrcode"));
  440. // 获取用户邀请码
  441. $inviteCode = \app\common\model\User::where(["id"=>$this->auth->id])->value("invite_no");
  442. $downlowdLink = $host."/index/index/appJump?t=wlt".rand(10,999).Random::alpha(8);
  443. $this->success("获取成功!",["qrcode"=>$qrcode,"miniqrcode"=>$miniqrcode,"inviteCode"=>$inviteCode,"downlowdLink"=>$downlowdLink]);
  444. }
  445. /**
  446. * 获取app分享海报
  447. */
  448. public function getAppShare() {
  449. $this->success("获取成功!",["url"=>$this->httpurl(config("site.appShare"))]);
  450. }
  451. /**
  452. * 获取版本更新信息
  453. */
  454. public function getEdition() {
  455. // 获取二维码
  456. $is_force = config("site.is_force");
  457. $apkUrl = config("site.apkUrl");
  458. $apkName = config("site.apkName");
  459. $desc = config("site.desc");
  460. $versionCode = config("site.versionCode");
  461. $this->success("获取成功!",["versionCode"=>$versionCode,"isForceUpdate"=>$is_force,"apkUrl"=>$apkUrl,"apkName"=>$apkName,"desc"=>$desc]);
  462. }
  463. /**
  464. * 获取邀请图片
  465. */
  466. public function getInviteImg() {
  467. $plat = $this->request->request("plat",1); //平台:1=小程序,2=app
  468. if(!in_array($plat,[1,2])) $this->error("参数错误");
  469. // 获取用户的邀请码
  470. $invitecode = \app\common\model\User::where(["id"=>$this->auth->id])->value("invite_no");
  471. // 文字图片合成
  472. $bigImgPath = $this->httpurlLocal('/assets/img/inviteimg.jpeg');
  473. $img = imagecreatefromstring(file_get_contents($bigImgPath));
  474. //字体文件
  475. $font = realpath('./assets/fonts/lato/lato-black.ttf');
  476. //字体颜色(RGB)
  477. $black = imagecolorallocate($img, 217, 76, 41);
  478. //字体大小
  479. $fontSize = 30;
  480. //旋转角度
  481. $circleSize = 0;
  482. //左边距
  483. $left = 275;
  484. //上边距
  485. $top = 540;
  486. imagefttext($img, $fontSize, $circleSize, $left, $top, $black, $font, $invitecode);
  487. $filename = date("YmdH").".jpeg";
  488. $path = "/uploads/qrcode/".$filename;
  489. $file = $_SERVER['DOCUMENT_ROOT'] . $path;//打开文件准备写入
  490. list($bgWidth, $bgHight, $bgType) = getimagesize($bigImgPath);
  491. switch ($bgType) {
  492. case 1://gif
  493. header('Content-Type:image/gif');
  494. imagegif($img,$file);
  495. break;
  496. case 2://jpg
  497. header('Content-Type:image/jpg');
  498. imagejpeg($img,$file);
  499. break;
  500. case 3://jpg
  501. header('Content-Type:image/png');
  502. imagepng($img,$file);
  503. break;
  504. default:
  505. break;
  506. }
  507. //销毁照片
  508. imagedestroy($img);
  509. // 图片和二维码合成
  510. $qrcode = $plat == 1 ? config("site.miniqrcode"):config("site.qrcode");
  511. $background = $file;
  512. $target = $this->httpurl($qrcode);
  513. $background_iamge = imagecreatefromstring(file_get_contents($background));
  514. $target_image = imagecreatefromstring(file_get_contents($target));
  515. list($target_width, $target_height, $target_type) = getimagesize($target);
  516. imagecopymerge($background_iamge , $target_image , 250, 700, 0, 0, $target_width, $target_height, 100);
  517. list($background_width, $background_height, $background_type) = getimagesize($background);
  518. switch ($background_type) {
  519. case 1://gif
  520. header('Content-Type:image/gif');
  521. imagegif($background_iamge,$file);
  522. break;
  523. case 2://jpg
  524. header('Content-Type:image/jpg');
  525. imagejpeg($background_iamge,$file);
  526. break;
  527. case 3://jpg
  528. header('Content-Type:image/png');
  529. imagepng($background_iamge,$file);
  530. break;
  531. default:
  532. break;
  533. }
  534. $savepath = $this->httpurlLocal($path);
  535. $this->success("获取成功!",$savepath);
  536. }
  537. /**
  538. * 获取银行列表
  539. */
  540. public function getBankList() {
  541. $this->success("获取成功!",["banklist"=>\app\common\model\Bank::select()]);
  542. }
  543. /**
  544. * 获取开关配置
  545. */
  546. public function getSwitch() {
  547. $this->success("获取成功!",["switch"=>config("site.switch")]);
  548. }
  549. /**
  550. * 评论时间转换
  551. * @param null $time
  552. * @return false|string
  553. */
  554. private function get_last_time($time = NULL) {
  555. $text = '';
  556. $time = $time === NULL || $time > time() ? time() : intval($time);
  557. $t = time() - $time; //时间差 (秒)
  558. $y = date('Y', $time)-date('Y', time());//是否跨年
  559. switch($t){
  560. case $t == 0:
  561. $text = '刚刚';
  562. break;
  563. case $t < 60:
  564. $text = $t . '秒前'; // 一分钟内
  565. break;
  566. case $t < 60 * 60:
  567. $text = floor($t / 60) . '分钟前'; //一小时内
  568. break;
  569. case $t < 60 * 60 * 24:
  570. $text = floor($t / (60 * 60)) . '小时前'; // 一天内
  571. break;
  572. case $t < 60 * 60 * 24 * 3:
  573. $text = floor($time/(60*60*24)) ==1 ?'昨天 ' . date('H:i', $time) : '前天 ' . date('H:i', $time) ; //昨天和前天
  574. break;
  575. case $t < 60 * 60 * 24 * 30:
  576. $text = date('m月d日 H:i', $time); //一个月内
  577. break;
  578. case $t < 60 * 60 * 24 * 365&&$y==0:
  579. $text = date('m月d日', $time); //一年内
  580. break;
  581. default:
  582. $text = date('Y年m月d日', $time); //一年以前
  583. break;
  584. }
  585. return $text;
  586. }
  587. /**
  588. * 年龄段列表
  589. * @return void
  590. */
  591. public function ageList()
  592. {
  593. try {
  594. $field = 'id,name';
  595. $where['status'] = 1;
  596. $result = model('Age')->field($field)->where($where)->order('weigh asc')->select();
  597. $this->success('获取成功',$result);
  598. } catch (Exception $e) {
  599. $this->error($e->getMessage());
  600. }
  601. }
  602. /**
  603. * 星座列表
  604. * @return void
  605. */
  606. public function starList()
  607. {
  608. try {
  609. $field = 'id,name,image';
  610. $where['status'] = 1;
  611. $result = model('Constellation')->field($field)->where($where)->order('weigh asc')->select();
  612. if (!$result) {
  613. $result = list_domain_image($result,['image']);
  614. }
  615. $this->success('获取成功',$result);
  616. } catch (Exception $e) {
  617. $this->error($e->getMessage());
  618. }
  619. }
  620. /**
  621. * 轮播图列表
  622. * @return void
  623. */
  624. public function bannerList()
  625. {
  626. try {
  627. $field = 'id,title,image,url';
  628. $where['status'] = 1;
  629. $result = model('Banner')->field($field)->where($where)->order('weigh asc')->select();
  630. if (!$result) {
  631. $result = list_domain_image($result,['image']);
  632. }
  633. $this->success('获取成功',$result);
  634. } catch (Exception $e) {
  635. $this->error($e->getMessage());
  636. }
  637. }
  638. }