diff --git a/app/common/controller/SkuController.php b/app/common/controller/SkuController.php index 67849c4..f0f8d57 100644 --- a/app/common/controller/SkuController.php +++ b/app/common/controller/SkuController.php @@ -4,6 +4,7 @@ namespace app\common\controller; use app\common\controller\BaseController; use app\common\traits\crud\CrudControllerTrait; use app\common\service\SkuService; +use support\Request; use function Symfony\Component\Translation\t; class SkuController extends BaseController @@ -17,6 +18,28 @@ class SkuController extends BaseController $this->service = new SkuService(); } + /** + * 获取列表 + * + * @param Request $request 请求对象 + * @return mixed 返回分页数据及总数 + */ + public function preset(Request $request) + { + try { + $raw = $this->service->serviceListAll($request); + $data = []; + foreach ($raw as $item) { + unset($item['created_at']); + unset($item['updated_at']); + $data[] = $this->indexFormat($item); + } + return $this->success($data); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } + /** * 列表页数据格式化 * diff --git a/app/common/service/SkuService.php b/app/common/service/SkuService.php index 109465c..2399a48 100644 --- a/app/common/service/SkuService.php +++ b/app/common/service/SkuService.php @@ -32,6 +32,42 @@ class SkuService 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': + $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 626b1a6..e0f5921 100644 --- a/config/route.php +++ b/config/route.php @@ -103,6 +103,7 @@ Route::group('/common', function () { // sku Route::group('/sku', function () { Route::any('/list', [app\common\controller\SkuController::class, 'index']); + Route::any('/preset', [app\common\controller\SkuController::class, 'preset']); }); // 弹幕