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.
120 lines
3.3 KiB
120 lines
3.3 KiB
<?php
|
|
|
|
namespace app\home\controller;
|
|
|
|
use app\model\FaqModel;
|
|
use app\model\LanguageSettingModel;
|
|
|
|
class Faq extends HomeBaseController
|
|
{
|
|
|
|
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;
|
|
}
|
|
|
|
$faq = FaqModel::where('status', FaqModel::STATUS_ON)
|
|
->where('is_delete', FaqModel::IS_DELETE_NO)
|
|
->where('lang', $langId)
|
|
->order('weight', 'desc')
|
|
->select();
|
|
|
|
$res = [];
|
|
if(!$faq->isEmpty()){
|
|
foreach ($faq as $item){
|
|
$res[] = [
|
|
'id' => $item['id'],
|
|
'title' => $item['title'],
|
|
'content' => $item['content'],
|
|
];
|
|
}
|
|
}
|
|
|
|
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'=>''],
|
|
]);
|
|
}
|
|
|
|
$faq = FaqModel::where('id', $id)->where('status', FaqModel::STATUS_ON)->find();
|
|
if(empty($faq)){
|
|
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' => $faq['content'],'title'=>$faq['title']],
|
|
]);
|
|
}
|
|
|
|
// 无效语言
|
|
$langModel = LanguageSettingModel::where('language_code', $lang)->find();
|
|
if(empty($langModel)){
|
|
return json([
|
|
'code'=>'0',
|
|
'message' => 'Request successful.',
|
|
'data' => ['content' => $faq['content'],'title'=>$faq['title']],
|
|
]);
|
|
}
|
|
|
|
// 语言相同
|
|
if($langModel['id'] == $faq['lang']){
|
|
return json([
|
|
'code'=>'0',
|
|
'message' => 'Request successful.',
|
|
'data' => ['content' => $faq['content'],'title'=>$faq['title']],
|
|
]);
|
|
}
|
|
|
|
// 查询同名 其他语言文件
|
|
$faqChange = FaqModel::where('name', $faq['name'])
|
|
->where('status', FaqModel::STATUS_ON)
|
|
->where('lang', $langModel['id'])
|
|
->find();
|
|
if(empty($faqChange)){
|
|
return json([
|
|
'code'=>'0',
|
|
'message' => 'Request successful.',
|
|
'data' => ['content' => $faq['content'],'title'=>$faq['title']],
|
|
]);
|
|
}
|
|
|
|
// 返回原数据
|
|
return json([
|
|
'code'=>'0',
|
|
'message' => 'Request successful.',
|
|
'data' => ['content' => $faqChange['content'],'title'=>$faqChange['title']],
|
|
]);
|
|
|
|
}
|
|
}
|