You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
136 lines
3.8 KiB
136 lines
3.8 KiB
<?php
|
|
|
|
namespace app\home\controller;
|
|
|
|
use app\home\service\CarouselService;
|
|
use app\model\BannerModel;
|
|
use app\model\LanguageSettingModel;
|
|
use think\response\Json;
|
|
|
|
class Carousel extends HomeBaseController
|
|
{
|
|
|
|
/**
|
|
* 获取首页广告图
|
|
* @return Json
|
|
*/
|
|
public function getCarousel(): Json
|
|
{
|
|
$result = (new CarouselService())->getCarousel();
|
|
return json($result);
|
|
}
|
|
|
|
// 广告图
|
|
public function index()
|
|
{
|
|
// 语言筛选
|
|
$lang = $this->request->header('Language');
|
|
if(empty($lang)){
|
|
$lang = 'zh-cn';
|
|
}
|
|
|
|
$langId = 1;
|
|
$langModel = LanguageSettingModel::where('language_code', $lang)->find();
|
|
if(!empty($langModel)){
|
|
$langId = $langModel->id;
|
|
}
|
|
|
|
$banner = BannerModel::where('status', BannerModel::STATUS_ON)
|
|
->where('is_delete', BannerModel::IS_DELETE_NO)
|
|
->where('lang', $langId)
|
|
->select();
|
|
|
|
$res = [];
|
|
if(!$banner->isEmpty()){
|
|
foreach ($banner as $item){
|
|
$res[] = [
|
|
'id' => $item['id'],
|
|
'title' => $item['title'],
|
|
'content' => $item['content'],
|
|
'image' => $item['path'],
|
|
'redirect_url' => '',
|
|
'type'=> '1'
|
|
];
|
|
}
|
|
}
|
|
|
|
return json([
|
|
'code'=>'0',
|
|
'message' => 'Request successful.',
|
|
'data' => $res,
|
|
]);
|
|
}
|
|
|
|
// 广告图详情
|
|
public function detail()
|
|
{
|
|
$id = $this->request->param('id');
|
|
if(empty($id)){
|
|
return json([
|
|
'code'=>'0',
|
|
'message' => 'Request successful.',
|
|
'data' => ['content' => '','title'=>''],
|
|
]);
|
|
}
|
|
|
|
$banner = BannerModel::where('id', $id)->where('status', BannerModel::STATUS_ON)->find();
|
|
if(empty($banner)){
|
|
return json([
|
|
'code'=>'0',
|
|
'message' => 'Request successful.',
|
|
'data' => ['content' => '','title'=>''],
|
|
]);
|
|
}
|
|
|
|
|
|
// 判断是否修改了语言
|
|
$lang = $this->request->header('Language');
|
|
if(empty($lang)){
|
|
return json([
|
|
'code'=>'0',
|
|
'message' => 'Request successful.',
|
|
'data' => ['content' => $banner['content'],'title'=>$banner['title']],
|
|
]);
|
|
}
|
|
|
|
// 无效语言
|
|
$langModel = LanguageSettingModel::where('language_code', $lang)->find();
|
|
if(empty($langModel)){
|
|
return json([
|
|
'code'=>'0',
|
|
'message' => 'Request successful.',
|
|
'data' => ['content' => $banner['content'],'title'=>$banner['title']],
|
|
]);
|
|
}
|
|
|
|
// 语言相同
|
|
if($langModel['id'] == $banner['lang']){
|
|
return json([
|
|
'code'=>'0',
|
|
'message' => 'Request successful.',
|
|
'data' => ['content' => $banner['content'],'title'=>$banner['title']],
|
|
]);
|
|
}
|
|
|
|
// 查询同名 其他语言文件
|
|
$bannerChange = BannerModel::where('name', $banner['name'])
|
|
->where('status', BannerModel::STATUS_ON)
|
|
->where('lang', $langModel['id'])
|
|
->find();
|
|
if(empty($bannerChange)){
|
|
return json([
|
|
'code'=>'0',
|
|
'message' => 'Request successful.',
|
|
'data' => ['content' => $banner['content'],'title'=>$banner['title']],
|
|
]);
|
|
}
|
|
|
|
// 返回原数据
|
|
return json([
|
|
'code'=>'0',
|
|
'message' => 'Request successful.',
|
|
'data' => ['content' => $bannerChange['content'],'title'=>$bannerChange['title']],
|
|
]);
|
|
|
|
}
|
|
}
|