优化接口
This commit is contained in:
@@ -156,9 +156,6 @@ class ResourcesController extends BaseController
|
||||
]);
|
||||
|
||||
return View::fetch();
|
||||
} catch (\Exception $e) {
|
||||
Log::record('添加资源页面加载', 0, $e->getMessage(), '资源管理');
|
||||
$this->error('页面加载失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -516,65 +516,6 @@ class ProgramController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
// 获取downloadPrograms详情
|
||||
public function getDownloadProgramsDetail()
|
||||
{
|
||||
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()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取downloadGames分类
|
||||
public function getDownloadGamesCategory()
|
||||
{
|
||||
|
||||
@@ -32,6 +32,66 @@ use app\index\model\Articles\Articles;
|
||||
|
||||
class ResourcesController extends BaseController
|
||||
{
|
||||
|
||||
// 获取resourceDetail详情
|
||||
public function getResourceDetail()
|
||||
{
|
||||
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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user