IndexController.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Http\Controllers\FrontController;
  4. use App\Models\SysModels\Banner;
  5. use App\Models\SysModels\Config;
  6. use App\Servers\Common\RedisDataServer;
  7. class IndexController extends FrontController
  8. {
  9. public function __construct()
  10. {
  11. parent::__construct();
  12. }
  13. /**
  14. * 获取网站基础信息
  15. * @return \Illuminate\Http\JsonResponse
  16. */
  17. function getWebsite(){
  18. $key_name = 'gw_configs';
  19. $data = RedisDataServer::creatServer()->getData( $key_name, 'json');
  20. if(!$data){
  21. //数据库查找当前数据
  22. $configs = Config::whereIn('key',['logo','cn_title','en_title','tel','email','cn_address','en_address','wx_image','icp','put_on_record','lon','lat'])->pluck('value','key')->toArray();
  23. //中英文数据分组
  24. $data['cn']['address'] = $configs['cn_address'];
  25. $data['cn']['title'] = $configs['cn_title'];
  26. $data['en']['address'] = $configs['en_address'];
  27. $data['en']['title'] = $configs['en_title'];
  28. unset($configs['cn_address']);
  29. unset($configs['en_address']);
  30. unset($configs['cn_title']);
  31. unset($configs['en_title']);
  32. foreach ($configs as $key=>$value){
  33. $data[$key] = $value;
  34. }
  35. //写入redis
  36. RedisDataServer::creatServer()->setData($key_name, $data, 'json', 300);
  37. }
  38. return $this->apiResponseSuccess('获取成功',$data);
  39. }
  40. /**
  41. * 获取轮播图
  42. * @return \Illuminate\Http\JsonResponse
  43. */
  44. function getBanners(){
  45. $where = [['is_del',0]];
  46. //获取数据
  47. $list = Banner::where($where)
  48. ->select(['cn_image','en_image','title','url'])
  49. ->orderBy('sort','asc')
  50. ->get();
  51. $cn_data = [];
  52. $en_data = [];
  53. foreach ($list as $value){
  54. $cn['title'] = $value['title'];
  55. $cn['url'] = $value['url'];
  56. $cn['image'] = $value['cn_image'];
  57. $en['title'] = $value['title'];
  58. $en['url'] = $value['url'];
  59. $en['image'] = $value['en_image'];
  60. $cn_data[] = $cn;
  61. $en_data[] = $en;
  62. }
  63. $cn_datas['items'] = $cn_data;
  64. $en_datas['items'] = $en_data;
  65. return $this->apiResponseSuccess('获取成功',[
  66. 'cn' => $cn_datas,
  67. 'en' => $en_datas,
  68. ]);
  69. }
  70. }