123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace App\Http\Controllers\Api;
- use App\Http\Controllers\FrontController;
- use App\Models\SysModels\Banner;
- use App\Models\SysModels\Config;
- use App\Servers\Common\RedisDataServer;
- class IndexController extends FrontController
- {
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * 获取网站基础信息
- * @return \Illuminate\Http\JsonResponse
- */
- function getWebsite(){
- $key_name = 'gw_configs';
- $data = RedisDataServer::creatServer()->getData( $key_name, 'json');
- if(!$data){
- //数据库查找当前数据
- $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();
- //中英文数据分组
- $data['cn']['address'] = $configs['cn_address'];
- $data['cn']['title'] = $configs['cn_title'];
- $data['en']['address'] = $configs['en_address'];
- $data['en']['title'] = $configs['en_title'];
- unset($configs['cn_address']);
- unset($configs['en_address']);
- unset($configs['cn_title']);
- unset($configs['en_title']);
- foreach ($configs as $key=>$value){
- $data[$key] = $value;
- }
- //写入redis
- RedisDataServer::creatServer()->setData($key_name, $data, 'json', 300);
- }
- return $this->apiResponseSuccess('获取成功',$data);
- }
- /**
- * 获取轮播图
- * @return \Illuminate\Http\JsonResponse
- */
- function getBanners(){
- $where = [['is_del',0]];
- //获取数据
- $list = Banner::where($where)
- ->select(['cn_image','en_image','title','url'])
- ->orderBy('sort','asc')
- ->get();
- $cn_data = [];
- $en_data = [];
- foreach ($list as $value){
- $cn['title'] = $value['title'];
- $cn['url'] = $value['url'];
- $cn['image'] = $value['cn_image'];
- $en['title'] = $value['title'];
- $en['url'] = $value['url'];
- $en['image'] = $value['en_image'];
- $cn_data[] = $cn;
- $en_data[] = $en;
- }
- $cn_datas['items'] = $cn_data;
- $en_datas['items'] = $en_data;
- return $this->apiResponseSuccess('获取成功',[
- 'cn' => $cn_datas,
- 'en' => $en_datas,
- ]);
- }
- }
|