优化接口

This commit is contained in:
2025-12-25 23:16:10 +08:00
parent acf9bc0952
commit 3e9a3731e5
13 changed files with 2860 additions and 1145 deletions
@@ -308,6 +308,65 @@ class ArticlesController extends BaseController
}
}
// 获取articleDetail详情
public function getArticleDetail()
{
try {
// 获取前端传递的ID
$id = input('id/d', 0);
// 验证ID
if ($id <= 0) {
return json([
'code' => 1,
'msg' => 'ID参数错误'
]);
}
// 构建查询条件
$where = [
['r.id', '=', $id],
['r.delete_time', '=', null],
['r.status', '=', 1], // 已审核的资源
['r.push', '=', 1], // 已推送的资源
];
// 查询资源详情,联查分类名称
$resource = Resources::where($where)
->field('r.id,r.title,r.cate,r.icon,r.price,r.code,r.desc,r.number,r.content,r.views,r.downloads,r.create_time,r.update_time,r.url,r.fileurl,c.name as cate_name')
->alias('r')
->join('resources_category c', 'r.cate = c.id')
->find();
if (!$resource) {
return json([
'code' => 1,
'msg' => '资源不存在或已删除'
]);
}
// 转换为数组并处理数据
$resource = $resource->toArray();
// 将cate字段替换为分类名称
$resource['cate'] = $resource['cate_name'];
unset($resource['cate_name']);
// 返回数据
return json([
'code' => 0,
'msg' => '获取成功',
'data' => $resource
]);
} catch (\Exception $e) {
return json([
'code' => 1,
'msg' => '获取失败:' . $e->getMessage()
]);
}
}
//文章中心
public function index()
{