param(); $query = ModelDictionary::getDictionaryData('news_type'); return msg("获取新闻类型成功!", $query); } /** * 获取新闻列表 */ 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("传值不正确!"); $con = Tool::getOptionalQuery(['news_title', 'LIKE'], ['c.i18n_lang_type_code', '=', 'locale']); $query = ModelNews::where($con) ->field([ 'c.i18n_lang_type_code', 'a.i18n_lang_type_guid', 'news_id', 'news_type', 'news_title', 'news_intro', 'news_cover', 'news_link', 'news_issue_date', 'news_sort', ]) ->alias('a') ->leftjoin('i18n_lang_type c', 'a.i18n_lang_type_guid = c.i18n_lang_type_guid') //i18n ->order('news_sort', 'asc'); return msg("获取新闻列表成功!", $query); } /** * 获取新闻详情 */ public function getNewsInfo(Request $request): array { $params = $request->param(); $this->validate($params, ['news_id' => 'require', 'locale' => 'require']); $find = ModelNews::where('news_id', $params['news_id']) ->field([ 'news_id', 'news_type', 'news_title', 'news_intro', 'news_source', 'news_link', 'news_issue_date', 'news_views_num', 'news_sort', 'news_content' ])->find(); $field = [ 'news_id', 'news_title', 'c.i18n_lang_type_code', 'a.i18n_lang_type_guid', ]; # 上一篇文章 $find['prev'] = ModelNews::where('news_id', '<', $params['news_id']) ->where('c.i18n_lang_type_code', '=', $params['locale']) ->alias('a') ->leftjoin('i18n_lang_type c', 'a.i18n_lang_type_guid = c.i18n_lang_type_guid') //i18n ->order('news_id', 'desc') ->field($field) ->find(); # 下一篇文章 $find['next'] = ModelNews::where('news_id', '>', $params['news_id']) ->where('c.i18n_lang_type_code', '=', $params['locale']) ->alias('a') ->leftjoin('i18n_lang_type c', 'a.i18n_lang_type_guid = c.i18n_lang_type_guid') //i18n ->order('news_id', 'asc') ->field($field) ->find(); return msg(0, '获取新闻详情成功!', ['data' => $find]); } }