增加游戏模块
This commit is contained in:
@@ -9,7 +9,7 @@ use app\admin\model\Resource\ResourceCategory;
|
||||
use think\facade\View;
|
||||
use think\facade\Request;
|
||||
use think\facade\Db;
|
||||
use app\admin\controller\Log;
|
||||
use app\admin\controller\LogController as Log;
|
||||
use think\App;
|
||||
|
||||
class ResourcesController extends BaseController
|
||||
@@ -100,14 +100,17 @@ class ResourcesController extends BaseController
|
||||
{
|
||||
if (Request::isPost()) {
|
||||
$data = [
|
||||
'name' => input('post.name'),
|
||||
'title' => input('post.title'),
|
||||
'cate' => input('post.cate'),
|
||||
'icon' => input('post.icon'),
|
||||
'url' => input('post.url'),
|
||||
'code' => input('post.code'),
|
||||
'uploader' => input('post.uploader'),
|
||||
'desc' => input('post.desc'),
|
||||
'content' => input('post.content'),
|
||||
'number' => input('post.number'),
|
||||
'status' => input('post.status', 2),
|
||||
|
||||
'create_time' => time()
|
||||
];
|
||||
|
||||
@@ -130,6 +133,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'],
|
||||
'number' => $data['number'],
|
||||
'content' => $data['content'],
|
||||
'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()
|
||||
{
|
||||
@@ -167,6 +228,29 @@ class ResourcesController extends BaseController
|
||||
->order('sort asc, id asc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
// 获取每个分类下的资源总数
|
||||
foreach ($lists as &$item) {
|
||||
if ($item['cid'] == 0) {
|
||||
// 父级分类 - 统计所有子分类的资源总数
|
||||
$childIds = ResourceCategory::where('cid', $item['id'])
|
||||
->where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->column('id');
|
||||
|
||||
$item['total'] = Resource::where('cate', 'in', array_merge([$item['id']], $childIds))
|
||||
->where('delete_time', null)
|
||||
->where('status', '<>', 3)
|
||||
->count();
|
||||
} else {
|
||||
// 子分类 - 只统计当前分类的资源
|
||||
$item['total'] = Resource::where('cate', $item['id'])
|
||||
->where('delete_time', null)
|
||||
->where('status', '<>', 3)
|
||||
->count();
|
||||
}
|
||||
}
|
||||
|
||||
$tree = $this->buildParentChild($lists);
|
||||
return json(['code' => 0, 'msg' => '获取成功', 'data' => $tree]);
|
||||
}
|
||||
@@ -179,6 +263,7 @@ class ResourcesController extends BaseController
|
||||
'name' => input('post.name'),
|
||||
'icon' => input('post.icon'),
|
||||
'cid' => input('post.cid'),
|
||||
'number' => input('post.number'),
|
||||
'sort' => input('post.sort', 0),
|
||||
'status' => input('post.status', 1),
|
||||
'create_time' => time()
|
||||
@@ -217,6 +302,7 @@ class ResourcesController extends BaseController
|
||||
'name' => input('post.name'),
|
||||
'icon' => input('post.icon'),
|
||||
'cid' => input('post.cid'),
|
||||
'number' => input('post.number'),
|
||||
'sort' => input('post.sort', 0),
|
||||
'status' => input('post.status', 1),
|
||||
'update_time' => time()
|
||||
@@ -309,64 +395,6 @@ class ResourcesController extends BaseController
|
||||
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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user