diff --git a/app/admin/controller/content/Resource.php b/app/admin/controller/content/Resource.php index 06a5494..cad0517 100644 --- a/app/admin/controller/content/Resource.php +++ b/app/admin/controller/content/Resource.php @@ -71,10 +71,17 @@ class Resource extends AdminBase return JsonServer::success('编辑成功'); } + $id = $this->request->get('id'); + $detail = ResourceLogic::detail($id); + $category2 = []; + if($detail['cid']>0){ + $category2 = ResourceCategoryLogic::getCategory($detail['cid']); + } return view('', [ - 'detail' => ResourceLogic::detail($id), - 'category' => ResourceCategoryLogic::getCategory() + 'detail' => $detail, + 'category' => ResourceCategoryLogic::getCategory(), + 'category2' => $category2 ]); } diff --git a/app/admin/controller/content/ResourceCategory.php b/app/admin/controller/content/ResourceCategory.php index 6d3b20a..24da0ce 100644 --- a/app/admin/controller/content/ResourceCategory.php +++ b/app/admin/controller/content/ResourceCategory.php @@ -45,7 +45,9 @@ class ResourceCategory extends AdminBase } - return view(); + return view('', [ + 'category' => ResourceCategoryLogic::getCategory() + ]); } /** @@ -66,7 +68,8 @@ class ResourceCategory extends AdminBase $id = $this->request->get('id'); return view('', [ - 'detail' => ResourceCategoryLogic::detail($id) + 'detail' => ResourceCategoryLogic::detail($id), + 'category' => ResourceCategoryLogic::getCategory() ]); } diff --git a/app/admin/logic/content/ResourceCategoryLogic.php b/app/admin/logic/content/ResourceCategoryLogic.php index b4d1fbe..ffdd129 100644 --- a/app/admin/logic/content/ResourceCategoryLogic.php +++ b/app/admin/logic/content/ResourceCategoryLogic.php @@ -20,8 +20,11 @@ class ResourceCategoryLogic extends Logic { try { $where = [ - ['del', '=', 0] + ['del', '=', 0], ]; + if(isset($get['pid']) && $get['pid']>0){ + $where[] = ['pid', '=', $get['pid']]; + } $model = new ResourceCategory(); $lists = $model->field(true) @@ -36,6 +39,21 @@ class ResourceCategoryLogic extends Logic foreach ($lists['data'] as &$item) { $item['is_show'] = $item['is_show'] ? '启用' : '停用'; + if($item['pid']){ + $where2 = [ + ['del', '=', 0], + ['id', '=', $item['pid']], + ]; + $cates = $model->where($where2)->find(); + if($cates){ + $item['p_name'] = $cates['name']; + }else{ + $item['p_name'] = '无'; + } + }else{ + $item['p_name'] = '无'; + } + } return ['count'=>$lists['total'], 'lists'=>$lists['data']]; @@ -49,12 +67,12 @@ class ResourceCategoryLogic extends Logic * @Author: 张无忌 * @return array */ - public static function getCategory() + public static function getCategory($pid=0) { try { $model = new ResourceCategory(); return $model->field(true) - ->where(['del'=>0, 'is_show'=>1]) + ->where(['del'=>0, 'is_show'=>1,'pid'=>$pid]) ->order('id', 'desc') ->select() ->toArray(); @@ -85,7 +103,8 @@ class ResourceCategoryLogic extends Logic try { ResourceCategory::create([ 'name' => $post['name'], - 'is_show' => $post['is_show'] + 'is_show' => $post['is_show'], + 'pid' => $post['pid'] ]); return true; @@ -106,6 +125,7 @@ class ResourceCategoryLogic extends Logic ResourceCategory::update([ 'name' => $post['name'], + 'pid' => $post['pid'], 'is_show' => $post['is_show'] ], ['id'=>$post['id']]); diff --git a/app/admin/logic/content/ResourceLogic.php b/app/admin/logic/content/ResourceLogic.php index 86fbec5..b2a41b0 100644 --- a/app/admin/logic/content/ResourceLogic.php +++ b/app/admin/logic/content/ResourceLogic.php @@ -44,8 +44,16 @@ class ResourceLogic extends Logic ]) ->toArray(); + foreach ($lists['data'] as &$item) { $item['category'] = $item['category']['name'] ?? '未知'; + if($item['cid2']){ + $cates = ResourceCategoryLogic::detail($item['cid2']); + $item['category2'] = $cates ? $cates['name'] : '无'; + }else{ + $item['category2'] = '无'; + } + $item['is_show'] = $item['is_show'] ? '显示' : '隐藏'; $item['path'] = $item['path']?UrlServer::getFileUrl($item['path']):''; $item['path_name']= $item['path']?substr($item['path'],strrpos($item['path'],"/")+1):''; @@ -90,6 +98,7 @@ class ResourceLogic extends Logic try { Resource::create([ 'cid' => $post['cid'], + 'cid2' => $post['cid2'], 'title' => $post['title'], 'image' => $post['image'] ?? '', 'path' => $post['path'] ?? '', @@ -125,6 +134,7 @@ class ResourceLogic extends Logic try { Resource::update([ 'cid' => $post['cid'], + 'cid2' => $post['cid2'], 'title' => $post['title'], 'image' => $post['image'] ?? '', 'path' => $post['path'] ?? '', diff --git a/app/admin/view/content/resource/add.html b/app/admin/view/content/resource/add.html index 62b3bf5..b0e14c0 100644 --- a/app/admin/view/content/resource/add.html +++ b/app/admin/view/content/resource/add.html @@ -74,7 +74,7 @@