修改资源列表显示错误

This commit is contained in:
李志强 2025-05-20 08:51:48 +08:00
parent 747ccb093b
commit 4977872d98
5 changed files with 81 additions and 84 deletions

View File

@ -23,12 +23,12 @@ class ResourcesController extends BaseController
'name' => input('post.name'), 'name' => input('post.name'),
'uploader' => input('post.uploader') 'uploader' => input('post.uploader')
]; ];
$page = (int)input('post.page', 1); $page = (int) input('post.page', 1);
$limit = (int)input('post.limit', 10); $limit = (int) input('post.limit', 10);
$query = Resource::where('delete_time', null) $query = Resource::where('delete_time', null)
->where('status', 1); ->where('status', 1);
// 分类筛选 // 分类筛选
if (!empty($params['category'])) { if (!empty($params['category'])) {
$cateInfo = ResourceCategory::where('name', $params['category']) $cateInfo = ResourceCategory::where('name', $params['category'])
@ -36,20 +36,20 @@ class ResourcesController extends BaseController
->where('status', 1) ->where('status', 1)
->field('id') ->field('id')
->find(); ->find();
if ($cateInfo) { if ($cateInfo) {
$query = $query->where('cate', (int)$cateInfo['id']); $query = $query->where('cate', (int) $cateInfo['id']);
} }
} }
// 名称搜索 // 名称搜索
if (!empty($params['name'])) { if (!empty($params['name'])) {
$query = $query->where('name', 'like', '%'.$params['name'].'%'); $query = $query->where('name', 'like', '%' . $params['name'] . '%');
} }
// 上传者搜索 // 上传者搜索
if (!empty($params['uploader'])) { if (!empty($params['uploader'])) {
$query = $query->where('uploader', 'like', '%'.$params['uploader'].'%'); $query = $query->where('uploader', 'like', '%' . $params['uploader'] . '%');
} }
$count = $query->count(); $count = $query->count();
@ -59,7 +59,7 @@ class ResourcesController extends BaseController
->select() ->select()
->each(function ($item) { ->each(function ($item) {
// 获取分类信息 // 获取分类信息
$cateInfo = ResourceCategory::where('id', (int)$item['cate']) $cateInfo = ResourceCategory::where('id', (int) $item['cate'])
->field('name, icon') ->field('name, icon')
->find(); ->find();
if ($cateInfo) { if ($cateInfo) {
@ -68,7 +68,7 @@ class ResourcesController extends BaseController
$item['icon'] = $cateInfo['icon']; $item['icon'] = $cateInfo['icon'];
} }
} }
$item['create_time'] = date('Y-m-d H:i:s', (int)$item['create_time']); $item['create_time'] = date('Y-m-d H:i:s', (int) $item['create_time']);
return $item; return $item;
}); });
@ -85,7 +85,7 @@ class ResourcesController extends BaseController
->order('sort asc, id asc') ->order('sort asc, id asc')
->select() ->select()
->toArray(); ->toArray();
$categories = $this->buildParentChild($allCategories); $categories = $this->buildParentChild($allCategories);
View::assign([ View::assign([
@ -104,10 +104,11 @@ class ResourcesController extends BaseController
'cate' => input('post.cate'), 'cate' => input('post.cate'),
'icon' => input('post.icon'), 'icon' => input('post.icon'),
'url' => input('post.url'), 'url' => input('post.url'),
'fileurl' => input('post.fileurl'),
'code' => input('post.code'), 'code' => input('post.code'),
'uploader' => input('post.uploader'), 'uploader' => input('post.uploader'),
'desc' => input('post.desc'), 'desc' => input('post.desc'),
'status' => input('post.status', 2), 'status' => input('post.status', 1),
'create_time' => time() 'create_time' => time()
]; ];
@ -130,6 +131,64 @@ class ResourcesController extends BaseController
} }
} }
/**
* 编辑资源
*/
public function edit()
{
if (Request::isPost()) {
$data = input('post.');
$id = input('id/d', 0);
if (!$id) {
Log::record('编辑资源', 0, '参数错误', '资源管理');
return json(['code' => 1, 'msg' => '参数错误']);
}
$updateData = [
'title' => $data['title'],
'cate' => $data['cate'],
'desc' => $data['desc'],
'uploader' => $data['uploader'],
'icon' => $data['icon'],
'fileurl' => $data['fileurl'],
'url' => $data['url'],
'code' => $data['code'],
'sort' => $data['sort'],
'update_time' => time()
];
$result = Resource::where('id', $id)
->update($updateData);
if ($result !== false) {
Log::record('编辑资源', 1, '', '资源管理');
return json(['code' => 0, 'msg' => '编辑成功']);
} else {
Log::record('编辑资源', 0, '编辑资源失败', '资源管理');
return json(['code' => 1, 'msg' => '编辑失败']);
}
}
$id = input('id/d', 0);
if (!$id) {
Log::record('编辑资源', 0, '参数错误', '资源管理');
$this->error('参数错误');
}
$resource = Resource::where('id', $id)
->where('delete_time', null)
->find();
if (!$resource) {
Log::record('编辑资源', 0, '资源不存在', '资源管理');
$this->error('资源不存在');
}
View::assign('resource', $resource);
return View::fetch();
}
// 删除资源 // 删除资源
public function delete() public function delete()
{ {
@ -290,7 +349,7 @@ class ResourcesController extends BaseController
$resource = Resource::where('id', $id) $resource = Resource::where('id', $id)
->where('delete_time', null) ->where('delete_time', null)
->find(); ->find();
if (!$resource) { if (!$resource) {
Log::record('获取资源详情', 0, '资源不存在', '资源管理'); Log::record('获取资源详情', 0, '资源不存在', '资源管理');
return json(['code' => 1, 'msg' => '资源不存在']); return json(['code' => 1, 'msg' => '资源不存在']);
@ -309,64 +368,6 @@ class ResourcesController extends BaseController
return json(['code' => 0, 'msg' => '获取成功', 'data' => $resource]); return json(['code' => 0, 'msg' => '获取成功', 'data' => $resource]);
} }
/**
* 编辑资源
*/
public function edit()
{
if (Request::isPost()) {
$data = input('post.');
$id = input('id/d', 0);
if (!$id) {
Log::record('编辑资源', 0, '参数错误', '资源管理');
return json(['code' => 1, 'msg' => '参数错误']);
}
$updateData = [
'title' => $data['title'],
'cate' => $data['cate'],
'desc' => $data['desc'],
'uploader' => $data['uploader'],
'icon' => $data['icon'],
'fileurl' => $data['fileurl'],
'url' => $data['url'],
'code' => $data['code'],
'sort' => $data['sort'],
'update_time' => time()
];
$result = Resource::where('id', $id)
->update($updateData);
if ($result !== false) {
Log::record('编辑资源', 1, '', '资源管理');
return json(['code' => 0, 'msg' => '编辑成功']);
} else {
Log::record('编辑资源', 0, '编辑资源失败', '资源管理');
return json(['code' => 1, 'msg' => '编辑失败']);
}
}
$id = input('id/d', 0);
if (!$id) {
Log::record('编辑资源', 0, '参数错误', '资源管理');
$this->error('参数错误');
}
$resource = Resource::where('id', $id)
->where('delete_time', null)
->find();
if (!$resource) {
Log::record('编辑资源', 0, '资源不存在', '资源管理');
$this->error('资源不存在');
}
View::assign('resource', $resource);
return View::fetch();
}
//统计资源数量 //统计资源数量
public function counts() public function counts()
{ {
@ -375,42 +376,42 @@ class ResourcesController extends BaseController
$total = Resource::where('delete_time', null) $total = Resource::where('delete_time', null)
->where('status', '<>', 3) ->where('status', '<>', 3)
->count(); ->count();
// 获取今日新增资源数 // 获取今日新增资源数
$today = strtotime(date('Y-m-d')); $today = strtotime(date('Y-m-d'));
$todayNew = Resource::where('delete_time', null) $todayNew = Resource::where('delete_time', null)
->where('status', '<>', 3) ->where('status', '<>', 3)
->where('create_time', '>=', $today) ->where('create_time', '>=', $today)
->count(); ->count();
// 获取最近7天的资源数据 // 获取最近7天的资源数据
$dates = []; $dates = [];
$counts = []; $counts = [];
$totalCounts = []; // 存储每天的总资源数 $totalCounts = []; // 存储每天的总资源数
for ($i = 6; $i >= 0; $i--) { for ($i = 6; $i >= 0; $i--) {
$date = date('Y-m-d', strtotime("-$i days")); $date = date('Y-m-d', strtotime("-$i days"));
$start = strtotime($date); $start = strtotime($date);
$end = $start + 86400; $end = $start + 86400;
// 获取当天新增资源数 // 获取当天新增资源数
$count = Resource::where('delete_time', null) $count = Resource::where('delete_time', null)
->where('status', '<>', 3) ->where('status', '<>', 3)
->where('create_time', '>=', $start) ->where('create_time', '>=', $start)
->where('create_time', '<', $end) ->where('create_time', '<', $end)
->count(); ->count();
// 获取截至当天的总资源数 // 获取截至当天的总资源数
$totalCount = Resource::where('delete_time', null) $totalCount = Resource::where('delete_time', null)
->where('status', '<>', 3) ->where('status', '<>', 3)
->where('create_time', '<', $end) ->where('create_time', '<', $end)
->count(); ->count();
$dates[] = $date; $dates[] = $date;
$counts[] = $count; $counts[] = $count;
$totalCounts[] = $totalCount; $totalCounts[] = $totalCount;
} }
return json([ return json([
'code' => 0, 'code' => 0,
'msg' => '获取成功', 'msg' => '获取成功',
@ -441,7 +442,7 @@ class ResourcesController extends BaseController
'title' => $item['name'], 'title' => $item['name'],
'children' => [] 'children' => []
]; ];
// 查找子分类 // 查找子分类
foreach ($lists as $subItem) { foreach ($lists as $subItem) {
if ($subItem['cid'] == $item['id']) { if ($subItem['cid'] == $item['id']) {
@ -452,7 +453,7 @@ class ResourcesController extends BaseController
]; ];
} }
} }
$tree[] = $node; $tree[] = $node;
} }
} }

View File

@ -60,11 +60,7 @@
{{# if(d.status == '0'){ }} {{# if(d.status == '0'){ }}
<span style="color:red;">未审核</span> <span style="color:red;">未审核</span>
{{# } else if(d.status == '1'){ }} {{# } else if(d.status == '1'){ }}
<span style="color:orange;">待审核</span> <span style="color:orange;">已审核</span>
{{# } else if(d.status == '2'){ }}
<span style="color:green;">已发布</span>
{{# } else if(d.status == '3'){ }}
<span style="color:gray;">已下架</span>
{{# } }} {{# } }}
</script> </script>