diff --git a/app/admin/controller/BarrageController.php b/app/admin/controller/BarrageController.php index a2ab076..5a293ee 100644 --- a/app/admin/controller/BarrageController.php +++ b/app/admin/controller/BarrageController.php @@ -4,6 +4,7 @@ namespace app\admin\controller; use app\common\controller\BaseController; use app\common\traits\crud\CrudControllerTrait; use app\common\service\BarrageService; +use support\Request; class BarrageController extends BaseController { @@ -16,6 +17,25 @@ class BarrageController extends BaseController $this->service = new BarrageService(); } + /** + * 获取列表 + * + * @param Request $request 请求对象 + * @return mixed 返回分页数据及总数 + */ + public function index(Request $request) + { + try { + $raw = $this->service->serviceList($request, 'default'); + $data = $this->transformData($raw, method_exists($this, 'indexFormat') + ? [$this, 'indexFormat'] + : null); + return $this->success($data); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } + /** * 列表页数据格式化 * diff --git a/app/admin/controller/SkuAttributeController.php b/app/admin/controller/SkuAttributeController.php index ebf4bd3..b4e4b63 100644 --- a/app/admin/controller/SkuAttributeController.php +++ b/app/admin/controller/SkuAttributeController.php @@ -53,9 +53,9 @@ class SkuAttributeController extends BaseController $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); if (isset($data['options_json'])){ $data['options_json'] = json_decode($data['options_json'], true); -// foreach ($data['options_json'] as $k => $v){ -// $data['options_json'][$k] = ['value' => $v]; -// } + foreach ($data['options_json'] as $k => $v){ + $data['options_json'][$k] = ['value' => $v]; + } } return $data; } diff --git a/app/common/controller/BarrageController.php b/app/common/controller/BarrageController.php index 6c97853..942ca73 100644 --- a/app/common/controller/BarrageController.php +++ b/app/common/controller/BarrageController.php @@ -4,6 +4,7 @@ namespace app\common\controller; use app\common\controller\BaseController; use app\common\traits\crud\CrudControllerTrait; use app\common\service\BarrageService; +use support\Request; class BarrageController extends BaseController { @@ -16,6 +17,25 @@ class BarrageController extends BaseController $this->service = new BarrageService(); } + /** + * 获取列表 + * + * @param Request $request 请求对象 + * @return mixed 返回分页数据及总数 + */ + public function index(Request $request) + { + try { + $raw = $this->service->serviceList($request, 'index'); + $data = $this->transformData($raw, method_exists($this, 'indexFormat') + ? [$this, 'indexFormat'] + : null); + return $this->success($data); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } + /** * 列表页数据格式化 * diff --git a/app/common/service/BarrageService.php b/app/common/service/BarrageService.php index 078003e..b599a58 100644 --- a/app/common/service/BarrageService.php +++ b/app/common/service/BarrageService.php @@ -31,6 +31,41 @@ class BarrageService 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['order']['sort'] = 'desc'; + $config['order']['id'] = 'desc'; + break; + case 'index': + $config['order']['is_blocked'] = '0'; + $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/app/common/service/SkuAttributeService.php b/app/common/service/SkuAttributeService.php index 52d1361..7b2e615 100644 --- a/app/common/service/SkuAttributeService.php +++ b/app/common/service/SkuAttributeService.php @@ -72,11 +72,11 @@ class SkuAttributeService */ public function beforeServiceStore($data, Request $request) { -// $options = []; -// foreach ($data['options_json'] as $v){ -// $options[] = $v['value']; -// } -// $data['options_json'] = json_encode($options, JSON_UNESCAPED_UNICODE); + $options = []; + foreach ($data['options_json'] as $v){ + $options[] = $v['value']; + } + $data['options_json'] = json_encode($options, JSON_UNESCAPED_UNICODE); return $data; }