更新后端接口
This commit is contained in:
parent
2161113eae
commit
2e89705815
@ -170,6 +170,144 @@ class ArticlesController extends BaseController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取technicalArticles分类
|
||||||
|
public function getTechnicalArticlesCategory()
|
||||||
|
{
|
||||||
|
// 获取名为 '技术文章' 的分类
|
||||||
|
$siteInfoCategory = ArticlesCategory::where('name', '技术文章')
|
||||||
|
->where('delete_time', null)
|
||||||
|
->where('status', 1)
|
||||||
|
->field('id,cid,name,image,sort')
|
||||||
|
->find();
|
||||||
|
|
||||||
|
if (!$siteInfoCategory) {
|
||||||
|
return json([
|
||||||
|
'code' => 1,
|
||||||
|
'msg' => '未找到技术文章分类'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 只返回其子分类,cid等于'技术文章'的id
|
||||||
|
$children = ArticlesCategory::where('cid', $siteInfoCategory['id'])
|
||||||
|
->where('delete_time', null)
|
||||||
|
->where('status', 1)
|
||||||
|
->field('id,cid,name,image,sort')
|
||||||
|
->select()
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
return json([
|
||||||
|
'code' => 0,
|
||||||
|
'msg' => '获取技术文章子分类成功',
|
||||||
|
'data' => $children
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取technicalArticles内容,传参
|
||||||
|
public function getTechnicalArticlesLists()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
// 获取前端传递的分类ID
|
||||||
|
$cateid = input('cateid/d', 0);
|
||||||
|
|
||||||
|
// 验证分类ID
|
||||||
|
if ($cateid <= 0) {
|
||||||
|
return json([
|
||||||
|
'code' => 1,
|
||||||
|
'msg' => '分类ID不能为空'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查分类是否存在且有效
|
||||||
|
$category = ArticlesCategory::where('id', $cateid)
|
||||||
|
->where('delete_time', null)
|
||||||
|
->where('status', 1)
|
||||||
|
->find();
|
||||||
|
|
||||||
|
if (!$category) {
|
||||||
|
return json([
|
||||||
|
'code' => 1,
|
||||||
|
'msg' => '分类不存在或已禁用'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取分页参数
|
||||||
|
$page = input('page/d', 1);
|
||||||
|
$limit = input('limit/d', 10);
|
||||||
|
|
||||||
|
// 获取该分类下的所有子分类ID(包括自身)
|
||||||
|
$subCategoryIds = [$cateid];
|
||||||
|
|
||||||
|
// 查找所有子分类
|
||||||
|
$subCategories = ArticlesCategory::where('cid', $cateid)
|
||||||
|
->where('delete_time', null)
|
||||||
|
->where('status', 1)
|
||||||
|
->column('id');
|
||||||
|
|
||||||
|
if (!empty($subCategories)) {
|
||||||
|
$subCategoryIds = array_merge($subCategoryIds, $subCategories);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建查询条件
|
||||||
|
$where = [
|
||||||
|
['delete_time', '=', null],
|
||||||
|
['status', '=', 2], // 已发布的文章
|
||||||
|
['cate', 'in', $subCategoryIds]
|
||||||
|
];
|
||||||
|
|
||||||
|
// 查询文章总数
|
||||||
|
$total = Articles::where($where)->count();
|
||||||
|
|
||||||
|
// 查询文章列表
|
||||||
|
$articles = Articles::where($where)
|
||||||
|
->field('id,title,cate,image,desc,author,content,publishdate,views,likes,is_trans,transurl,push,create_time')
|
||||||
|
->order('sort DESC, id DESC')
|
||||||
|
->page($page, $limit)
|
||||||
|
->select()
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
// 处理文章数据
|
||||||
|
foreach ($articles as &$article) {
|
||||||
|
// 如果文章没有封面图,使用分类封面图
|
||||||
|
if (empty($article['image'])) {
|
||||||
|
$article['image'] = $category['image'] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 格式化时间
|
||||||
|
$article['publishdate'] = date('Y-m-d H:i:s', strtotime($article['publishdate']));
|
||||||
|
$article['create_time'] = date('Y-m-d H:i:s', strtotime($article['create_time']));
|
||||||
|
|
||||||
|
// 获取分类名称
|
||||||
|
$articleCategory = ArticlesCategory::where('id', $article['cate'])->find();
|
||||||
|
$article['category_name'] = $articleCategory ? $articleCategory['name'] : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 返回数据
|
||||||
|
return json([
|
||||||
|
'code' => 0,
|
||||||
|
'msg' => '获取成功',
|
||||||
|
'data' => [
|
||||||
|
'category' => [
|
||||||
|
'id' => $category['id'],
|
||||||
|
'name' => $category['name'],
|
||||||
|
'desc' => $category['desc'],
|
||||||
|
'image' => $category['image']
|
||||||
|
],
|
||||||
|
'articles' => $articles,
|
||||||
|
'total' => $total,
|
||||||
|
'page' => $page,
|
||||||
|
'limit' => $limit,
|
||||||
|
'total_pages' => ceil($total / $limit)
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return json([
|
||||||
|
'code' => 1,
|
||||||
|
'msg' => '获取失败:' . $e->getMessage()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//文章中心
|
//文章中心
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -33,6 +33,417 @@ use app\index\model\Articles\Articles;
|
|||||||
|
|
||||||
class ProgramController extends BaseController
|
class ProgramController extends BaseController
|
||||||
{
|
{
|
||||||
|
// 获取officeResources分类
|
||||||
|
public function getOfficeResourcesCategory()
|
||||||
|
{
|
||||||
|
// 获取名为 '办公资源' 的分类
|
||||||
|
$resourceCategory = ResourcesCategory::where('name', '办公资源')
|
||||||
|
->where('delete_time', null)
|
||||||
|
->where('status', 1)
|
||||||
|
->field('id,cid,name,icon,sort')
|
||||||
|
->find();
|
||||||
|
|
||||||
|
if (!$resourceCategory) {
|
||||||
|
return json([
|
||||||
|
'code' => 1,
|
||||||
|
'msg' => '未找到办公资源分类'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 只返回其子分类,cid等于'办公资源'的id
|
||||||
|
$children = ResourcesCategory::where('cid', $resourceCategory['id'])
|
||||||
|
->where('delete_time', null)
|
||||||
|
->where('status', 1)
|
||||||
|
->field('id,cid,name,icon,sort')
|
||||||
|
->select()
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
return json([
|
||||||
|
'code' => 0,
|
||||||
|
'msg' => '获取办公资源子分类成功',
|
||||||
|
'data' => $children
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取officeResources内容,传参
|
||||||
|
public function getOfficeResourcesLists()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
// 获取前端传递的分类ID
|
||||||
|
$cateid = input('cateid/d', 0);
|
||||||
|
|
||||||
|
// 验证分类ID
|
||||||
|
if ($cateid <= 0) {
|
||||||
|
return json([
|
||||||
|
'code' => 1,
|
||||||
|
'msg' => '分类ID不能为空'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查分类是否存在且有效
|
||||||
|
$category = ResourcesCategory::where('id', $cateid)
|
||||||
|
->where('delete_time', null)
|
||||||
|
->where('status', 1)
|
||||||
|
->find();
|
||||||
|
|
||||||
|
if (!$category) {
|
||||||
|
return json([
|
||||||
|
'code' => 1,
|
||||||
|
'msg' => '分类不存在或已禁用'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取分页参数
|
||||||
|
$page = input('page/d', 1);
|
||||||
|
$limit = input('limit/d', 10);
|
||||||
|
|
||||||
|
// 获取该分类下的所有子分类ID(包括自身)
|
||||||
|
$subCategoryIds = [$cateid];
|
||||||
|
|
||||||
|
// 查找所有子分类
|
||||||
|
$subCategories = ResourcesCategory::where('cid', $cateid)
|
||||||
|
->where('delete_time', null)
|
||||||
|
->where('status', 1)
|
||||||
|
->column('id');
|
||||||
|
|
||||||
|
if (!empty($subCategories)) {
|
||||||
|
$subCategoryIds = array_merge($subCategoryIds, $subCategories);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建查询条件
|
||||||
|
$where = [
|
||||||
|
['delete_time', '=', null],
|
||||||
|
['status', '=', 1], // 已发布的文章
|
||||||
|
['cate', 'in', $subCategoryIds]
|
||||||
|
];
|
||||||
|
|
||||||
|
// 查询文章总数
|
||||||
|
$total = Resources::where($where)->count();
|
||||||
|
|
||||||
|
// 查询文章列表
|
||||||
|
$resources = Resources::where($where)
|
||||||
|
->field('id,title,cate,icon,desc,uploader,content,views,downloads,push,create_time')
|
||||||
|
->order('sort DESC, id DESC')
|
||||||
|
->page($page, $limit)
|
||||||
|
->select()
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
// 处理文章数据
|
||||||
|
foreach ($resources as &$resource) {
|
||||||
|
// 如果文章没有封面图,使用分类封面图
|
||||||
|
if (empty($resource['icon'])) {
|
||||||
|
$resource['icon'] = $category['icon'] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 格式化时间
|
||||||
|
//$resource['create_time'] = date('Y-m-d H:i:s', strtotime($resource['create_time']));
|
||||||
|
|
||||||
|
// 获取分类名称
|
||||||
|
$resourceCategory = ResourcesCategory::where('id', $resource['cate'])->find();
|
||||||
|
$resource['category_name'] = $resourceCategory ? $resourceCategory['name'] : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 返回数据
|
||||||
|
return json([
|
||||||
|
'code' => 0,
|
||||||
|
'msg' => '获取成功',
|
||||||
|
'data' => [
|
||||||
|
'category' => [
|
||||||
|
'id' => $category['id'],
|
||||||
|
'name' => $category['name'],
|
||||||
|
'desc' => $category['desc'],
|
||||||
|
'image' => $category['image']
|
||||||
|
],
|
||||||
|
'resources' => $resources,
|
||||||
|
'total' => $total,
|
||||||
|
'page' => $page,
|
||||||
|
'limit' => $limit,
|
||||||
|
'total_pages' => ceil($total / $limit)
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return json([
|
||||||
|
'code' => 1,
|
||||||
|
'msg' => '获取失败:' . $e->getMessage()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取downloadPrograms分类
|
||||||
|
public function getDownloadProgramsCategory()
|
||||||
|
{
|
||||||
|
// 获取名为 '程序下载' 的分类
|
||||||
|
$resourceCategory = ResourcesCategory::where('name', '程序下载')
|
||||||
|
->where('delete_time', null)
|
||||||
|
->where('status', 1)
|
||||||
|
->field('id,cid,name,icon,sort')
|
||||||
|
->find();
|
||||||
|
|
||||||
|
if (!$resourceCategory) {
|
||||||
|
return json([
|
||||||
|
'code' => 1,
|
||||||
|
'msg' => '未找到程序下载分类'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 只返回其子分类,cid等于'程序下载'的id
|
||||||
|
$children = ResourcesCategory::where('cid', $resourceCategory['id'])
|
||||||
|
->where('delete_time', null)
|
||||||
|
->where('status', 1)
|
||||||
|
->field('id,cid,name,icon,sort')
|
||||||
|
->select()
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
return json([
|
||||||
|
'code' => 0,
|
||||||
|
'msg' => '获取程序下载子分类成功',
|
||||||
|
'data' => $children
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取downloadPrograms内容,传参
|
||||||
|
public function getDownloadProgramsLists()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
// 获取前端传递的分类ID
|
||||||
|
$cateid = input('cateid/d', 0);
|
||||||
|
|
||||||
|
// 验证分类ID
|
||||||
|
if ($cateid <= 0) {
|
||||||
|
return json([
|
||||||
|
'code' => 1,
|
||||||
|
'msg' => '分类ID不能为空'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查分类是否存在且有效
|
||||||
|
$category = ResourcesCategory::where('id', $cateid)
|
||||||
|
->where('delete_time', null)
|
||||||
|
->where('status', 1)
|
||||||
|
->find();
|
||||||
|
|
||||||
|
if (!$category) {
|
||||||
|
return json([
|
||||||
|
'code' => 1,
|
||||||
|
'msg' => '分类不存在或已禁用'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取分页参数
|
||||||
|
$page = input('page/d', 1);
|
||||||
|
$limit = input('limit/d', 10);
|
||||||
|
|
||||||
|
// 获取该分类下的所有子分类ID(包括自身)
|
||||||
|
$subCategoryIds = [$cateid];
|
||||||
|
|
||||||
|
// 查找所有子分类
|
||||||
|
$subCategories = ResourcesCategory::where('cid', $cateid)
|
||||||
|
->where('delete_time', null)
|
||||||
|
->where('status', 1)
|
||||||
|
->column('id');
|
||||||
|
|
||||||
|
if (!empty($subCategories)) {
|
||||||
|
$subCategoryIds = array_merge($subCategoryIds, $subCategories);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建查询条件
|
||||||
|
$where = [
|
||||||
|
['delete_time', '=', null],
|
||||||
|
['status', '=', 1], // 已发布的文章
|
||||||
|
['cate', 'in', $subCategoryIds]
|
||||||
|
];
|
||||||
|
|
||||||
|
// 查询文章总数
|
||||||
|
$total = Resources::where($where)->count();
|
||||||
|
|
||||||
|
// 查询文章列表
|
||||||
|
$resources = Resources::where($where)
|
||||||
|
->field('id,title,cate,icon,desc,uploader,content,views,downloads,push,create_time')
|
||||||
|
->order('sort DESC, id DESC')
|
||||||
|
->page($page, $limit)
|
||||||
|
->select()
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
// 处理文章数据
|
||||||
|
foreach ($resources as &$resource) {
|
||||||
|
// 如果文章没有封面图,使用分类封面图
|
||||||
|
if (empty($resource['icon'])) {
|
||||||
|
$resource['icon'] = $category['icon'] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 格式化时间
|
||||||
|
//$resource['create_time'] = date('Y-m-d H:i:s', strtotime($resource['create_time']));
|
||||||
|
|
||||||
|
// 获取分类名称
|
||||||
|
$resourceCategory = ResourcesCategory::where('id', $resource['cate'])->find();
|
||||||
|
$resource['category_name'] = $resourceCategory ? $resourceCategory['name'] : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 返回数据
|
||||||
|
return json([
|
||||||
|
'code' => 0,
|
||||||
|
'msg' => '获取成功',
|
||||||
|
'data' => [
|
||||||
|
'category' => [
|
||||||
|
'id' => $category['id'],
|
||||||
|
'name' => $category['name'],
|
||||||
|
'desc' => $category['desc'],
|
||||||
|
'image' => $category['image']
|
||||||
|
],
|
||||||
|
'resources' => $resources,
|
||||||
|
'total' => $total,
|
||||||
|
'page' => $page,
|
||||||
|
'limit' => $limit,
|
||||||
|
'total_pages' => ceil($total / $limit)
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return json([
|
||||||
|
'code' => 1,
|
||||||
|
'msg' => '获取失败:' . $e->getMessage()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取downloadGames分类
|
||||||
|
public function getDownloadGamesCategory()
|
||||||
|
{
|
||||||
|
// 获取名为 '游戏下载' 的分类
|
||||||
|
$resourceCategory = ResourcesCategory::where('name', '游戏下载')
|
||||||
|
->where('delete_time', null)
|
||||||
|
->where('status', 1)
|
||||||
|
->field('id,cid,name,icon,sort')
|
||||||
|
->find();
|
||||||
|
|
||||||
|
if (!$resourceCategory) {
|
||||||
|
return json([
|
||||||
|
'code' => 1,
|
||||||
|
'msg' => '未找到游戏下载分类'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 只返回其子分类,cid等于'游戏下载'的id
|
||||||
|
$children = ResourcesCategory::where('cid', $resourceCategory['id'])
|
||||||
|
->where('delete_time', null)
|
||||||
|
->where('status', 1)
|
||||||
|
->field('id,cid,name,icon,sort')
|
||||||
|
->select()
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
return json([
|
||||||
|
'code' => 0,
|
||||||
|
'msg' => '获取游戏下载子分类成功',
|
||||||
|
'data' => $children
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取downloadGames内容,传参
|
||||||
|
public function getDownloadGamesLists()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
// 获取前端传递的分类ID
|
||||||
|
$cateid = input('cateid/d', 0);
|
||||||
|
|
||||||
|
// 验证分类ID
|
||||||
|
if ($cateid <= 0) {
|
||||||
|
return json([
|
||||||
|
'code' => 1,
|
||||||
|
'msg' => '分类ID不能为空'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查分类是否存在且有效
|
||||||
|
$category = ResourcesCategory::where('id', $cateid)
|
||||||
|
->where('delete_time', null)
|
||||||
|
->where('status', 1)
|
||||||
|
->find();
|
||||||
|
|
||||||
|
if (!$category) {
|
||||||
|
return json([
|
||||||
|
'code' => 1,
|
||||||
|
'msg' => '分类不存在或已禁用'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取分页参数
|
||||||
|
$page = input('page/d', 1);
|
||||||
|
$limit = input('limit/d', 10);
|
||||||
|
|
||||||
|
// 获取该分类下的所有子分类ID(包括自身)
|
||||||
|
$subCategoryIds = [$cateid];
|
||||||
|
|
||||||
|
// 查找所有子分类
|
||||||
|
$subCategories = ResourcesCategory::where('cid', $cateid)
|
||||||
|
->where('delete_time', null)
|
||||||
|
->where('status', 1)
|
||||||
|
->column('id');
|
||||||
|
|
||||||
|
if (!empty($subCategories)) {
|
||||||
|
$subCategoryIds = array_merge($subCategoryIds, $subCategories);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建查询条件
|
||||||
|
$where = [
|
||||||
|
['delete_time', '=', null],
|
||||||
|
['status', '=', 1], // 已发布的文章
|
||||||
|
['cate', 'in', $subCategoryIds]
|
||||||
|
];
|
||||||
|
|
||||||
|
// 查询文章总数
|
||||||
|
$total = Resources::where($where)->count();
|
||||||
|
|
||||||
|
// 查询文章列表
|
||||||
|
$resources = Resources::where($where)
|
||||||
|
->field('id,title,cate,icon,desc,uploader,content,views,downloads,push,create_time')
|
||||||
|
->order('sort DESC, id DESC')
|
||||||
|
->page($page, $limit)
|
||||||
|
->select()
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
// 处理文章数据
|
||||||
|
foreach ($resources as &$resource) {
|
||||||
|
// 如果文章没有封面图,使用分类封面图
|
||||||
|
if (empty($resource['icon'])) {
|
||||||
|
$resource['icon'] = $category['icon'] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 格式化时间
|
||||||
|
//$resource['create_time'] = date('Y-m-d H:i:s', strtotime($resource['create_time']));
|
||||||
|
|
||||||
|
// 获取分类名称
|
||||||
|
$resourceCategory = ResourcesCategory::where('id', $resource['cate'])->find();
|
||||||
|
$resource['category_name'] = $resourceCategory ? $resourceCategory['name'] : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 返回数据
|
||||||
|
return json([
|
||||||
|
'code' => 0,
|
||||||
|
'msg' => '获取成功',
|
||||||
|
'data' => [
|
||||||
|
'category' => [
|
||||||
|
'id' => $category['id'],
|
||||||
|
'name' => $category['name'],
|
||||||
|
'desc' => $category['desc'],
|
||||||
|
'image' => $category['image']
|
||||||
|
],
|
||||||
|
'resources' => $resources,
|
||||||
|
'total' => $total,
|
||||||
|
'page' => $page,
|
||||||
|
'limit' => $limit,
|
||||||
|
'total_pages' => ceil($total / $limit)
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return json([
|
||||||
|
'code' => 1,
|
||||||
|
'msg' => '获取失败:' . $e->getMessage()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//资源中心
|
//资源中心
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user