From bad63200c1056fe2e5add631a2079bc98575364c Mon Sep 17 00:00:00 2001 From: lwh <2679599887@qq.com> Date: Fri, 30 Jun 2023 10:50:08 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E6=B7=BB=E5=8A=A0=E6=96=B0=E9=97=BB?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/News/News.php | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/app/api/controller/News/News.php b/app/api/controller/News/News.php index 425fce3..4666790 100644 --- a/app/api/controller/News/News.php +++ b/app/api/controller/News/News.php @@ -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',