feat 添加新闻类型接口

This commit is contained in:
lwh 2023-06-30 10:50:08 +08:00
parent ad376c5bb8
commit bad63200c1

View File

@ -4,6 +4,7 @@ namespace app\api\controller\News;
use app\BaseController;
use app\common\model\News\News as ModelNews;
use app\common\model\Dictionary\Dictionary as ModelDictionary;
use app\Request;
use think\Validate;
use think\exception\ValidateException;
@ -17,22 +18,43 @@ use think\facade\Env;
class News extends BaseController
{
/**
* 获取新闻类型
*/
public function getNewsType(Request $request): array
{
$params = $request->param();
$query = ModelDictionary::getDictionaryData('news_type');
return msg("获取新闻类型成功!", $query);
}
/**
* 获取新闻列表
*/
public function getNewsList(Request $request): array
public function getNewsList(Request $request)
{
$params = $request->param();
$this->validate($params, ['idx' => 'require']);
// 根据字典index获取新闻类型的值
$news_type_arr = ModelDictionary::getDictionaryData('news_type');
$news_type = $news_type_arr[$params['idx']];
if(!$news_type) throwErrorMsg("传值不正确!");
$news_type_value = $news_type['dictionary_value'];
$con = [];
$con = Tool::getOptionalQuery(['news_type', '='], ['news_title', 'LIKE'],);
$con = Tool::getOptionalQuery(['news_title', 'LIKE'],);
$query = ModelNews::where($con)
->where('news_type', $news_type_value)
->field([
'news_id',
'news_type',
'news_title',
'news_intro',
'news_cover',
'news_link',
'news_issue_date',
'news_sort',