logic = (new SkuAttributeLogic()); } /** * 获取验证器 */ public function getValidator() { 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': case 'index': $config['order']['sort'] = 'desc'; $config['order']['id'] = 'desc'; break; case 'show': $config['where']['id'] = $p['id']; break; case 'store': break; case 'update': case 'destroy': $config['where']['id'] = $p['id']; break; } return $config; } /** * 添加前置处理 */ 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); return $data; } /** * 添加前置处理 */ public function beforeServiceUpdate($data, Request $request) { $options = []; if (!empty($data['options_json'])) { foreach ($data['options_json'] as $v){ $options[] = $v['value']; } } $data['options_json'] = json_encode($options, JSON_UNESCAPED_UNICODE); return $data; } /** * 获取系统list */ public function preset($params) { $where = []; if(isset($params['category_id']) && $params['category_id']) { $where['category_id'] = $params['category_id']; } $result = $this->logic->getList($where)->toArray(); return $result; } }