Index.php 25 KB

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