aerwen_web_api/app/api/controller/News/News.php

94 lines
2.4 KiB
PHP

<?php
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;
use think\facade\Filesystem;
use app\common\arw\adjfut\src\Excel;
use app\common\arw\adjfut\src\UploadFile;
use think\facade\Db;
use app\common\exception\Tool;
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)
{
$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_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',
])
->order('news_sort', 'asc');
return msg("获取新闻列表成功!", $query);
}
/**
* 获取新闻详情
*/
public function getNewsInfo(Request $request): array
{
$params = $request->param();
$this->validate($params, ['news_id' => 'require']);
$find = ModelNews::field([
'news_id',
'news_type',
'news_title',
'news_intro',
'news_source',
'news_link',
'news_issue_date',
'news_views_num',
'news_sort',
'news_content'
])
->where('news_id', $params['news_id'])
->find();
return msg(0, '获取新闻详情成功!', ['data' => $find]);
}
}