diff --git a/app/admin/controller/PostCategoryController.php b/app/admin/controller/PostCategoryController.php index 8b724ce..23ef772 100644 --- a/app/admin/controller/PostCategoryController.php +++ b/app/admin/controller/PostCategoryController.php @@ -31,7 +31,7 @@ class PostCategoryController extends BaseController $result = $this->service->getList($params); return $this->success($result, '获取分类列表'); } catch (\Throwable $e) { - return $this->error($e->getMessage().$e->getFile().$e->getLine()); + return $this->error($e->getMessage()); } } diff --git a/app/common/controller/BannerController.php b/app/common/controller/BannerController.php index e4c861d..9c08acb 100644 --- a/app/common/controller/BannerController.php +++ b/app/common/controller/BannerController.php @@ -4,6 +4,7 @@ namespace app\common\controller; use app\common\controller\BaseController; use app\common\traits\crud\CrudControllerTrait; use app\common\service\BannerService; +use support\Request; class BannerController extends BaseController { @@ -16,6 +17,22 @@ class BannerController extends BaseController $this->service = new BannerService(); } + /** + * 轮播 + * @param Request $request + * @return \support\Response + */ + public function getAll(Request $request) + { + try { + $params = $request->all(); + $result = $this->service->getBanner($params); + return $this->success($result, '获取轮播列表'); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } + /** * 列表页数据格式化 * diff --git a/app/common/controller/PostController.php b/app/common/controller/PostController.php index b75f19f..a554a59 100644 --- a/app/common/controller/PostController.php +++ b/app/common/controller/PostController.php @@ -37,7 +37,6 @@ class PostController extends BaseController foreach ($records as &$record) { if (!isset($record['id'])) break; - var_dump($record['id']); $where = [ 'post_id' => $record['id'], 'user_id' => $request->user->uid diff --git a/app/common/service/BannerService.php b/app/common/service/BannerService.php index b24a308..e8e819e 100644 --- a/app/common/service/BannerService.php +++ b/app/common/service/BannerService.php @@ -30,6 +30,14 @@ class BannerService return new $this->validator; } + public function getBanner($params){ + $where = []; + if(isset($params['module'])){ + $where['module'] = $params['module']; + } + return Banner::where('status','1')->where($where)->get(); + } + public function getBannerModule(){ return BannerModule::where('status','1')->get(); } diff --git a/app/common/service/PostService.php b/app/common/service/PostService.php index 307fffc..d4c213e 100644 --- a/app/common/service/PostService.php +++ b/app/common/service/PostService.php @@ -32,6 +32,49 @@ class PostService return new $this->validator; } + /** + * 构造 CrudUtil 查询配置 + */ + protected function buildQueryConfig(Request $request, string $scene = 'default'): array + { + $p = $request->all(); + + $config = []; + $config['model'] = $this->modelClass; + switch ($scene) { + case 'default': + $config['where']['status'] = 1; + $config['order']['sort'] = 'desc'; + $config['order']['id'] = 'desc'; + break; + case 'index': + if (isset($p['category_id']) && $p['category_id']) { + $config['where']['category_id'] = $p['category_id']; + } + if (isset($p['self']) && $p['self']) { + $config['where']['user_id'] = $request->user->uid; + } + $config['where']['status'] = 1; + $config['order']['sort'] = 'desc'; + $config['order']['id'] = 'desc'; + break; + case 'show': + $config['where']['id'] = $p['id']; + $config['where']['status'] = 1; + break; + case 'store': + break; + case 'update': + $config['where']['id'] = $p['id']; + break; + case 'destroy': + $config['where']['id'] = $p['id']; + break; + } + + return $config; + } + /** * 添加前置处理 */ diff --git a/config/route.php b/config/route.php index 4edec43..62740cc 100644 --- a/config/route.php +++ b/config/route.php @@ -92,22 +92,10 @@ Route::group('/common', function () { //协议 Route::any('/agreement', [app\admin\controller\AgreementController::class, 'show']); - // 分类 -// Route::group('/nav/categories', function () { -// Route::any('/preset', [app\common\controller\NavCategoriesController::class, 'preset']); -// Route::any('/complete', [app\common\controller\NavCategoriesController::class, 'complete']); -// }); - - // 分类下内容 -// Route::group('/nav/item', function () { -// Route::any('/list', [app\common\controller\NavItemsController::class, 'index']); -// }); -// -// // 设置 -// Route::group('/config', function () { -// Route::any('/show', [app\common\controller\ConfigController::class, 'show']); -// Route::any('/find', [app\common\controller\ConfigController::class, 'find']); -// }); + // 轮播 + Route::group('/banner', function () { + Route::any('/list', [app\common\controller\BannerController::class, 'getAll']); + }); });