diff --git a/app/common/model/SkuAttributeValue.php b/app/common/model/SkuAttributeValue.php index 346928f..1d55ada 100644 --- a/app/common/model/SkuAttributeValue.php +++ b/app/common/model/SkuAttributeValue.php @@ -45,5 +45,5 @@ class SkuAttributeValue extends Model /** * 不允许自动填充模型字段 */ - protected $guarded = []; + protected $guarded = ['created_at', 'updated_at']; } \ No newline at end of file diff --git a/app/common/service/SkuService.php b/app/common/service/SkuService.php index 8c6217d..109465c 100644 --- a/app/common/service/SkuService.php +++ b/app/common/service/SkuService.php @@ -102,6 +102,54 @@ class SkuService return $res; } + /** + * 添加前置处理 + */ + public function beforeServiceUpdate($data, Request $request) + { + $spec = []; + SkuAttributeValue::where('sku_id', $data['id'])->delete(); + foreach ($data['spec'] as $key => $value) { + $specItem = []; + $specItem['category_id'] = $data['category_id']; + $specItem['attr_id'] = $value['attr_id']; + $specItem['attr_name'] = $value['attr_name']; + $specItem['attr_value'] = $value['attr_value']; + $spec[] = $specItem; + SkuAttributeValue::create($specItem); + } + $spec_json = json_encode($spec,JSON_UNESCAPED_UNICODE); + + unset($data['spec']); + $data['spec_json'] = $spec_json; + $data['user_id'] = $request->user->uid; + $data['image'] = implode(',',$data['image']); + + // 将OSS直连地址替换为代理地址 + $ossDomain = 'https://vehicle-album.oss-cn-beijing.aliyuncs.com/'; + $proxyPath = '/proxy/ossurl?file='; + + $data['desc'] = str_replace( + '?Expires=', + '&Expires=', + $data['desc'] + ); + $data['desc'] = str_replace( + $ossDomain, + $proxyPath, + $data['desc'] + ); + // 将OSS直连地址替换为代理地址 + $ossDomain = 'https://oss-cn-beijing.aliyuncs.com/'; + $proxyPath = '/proxy/ossurl?file='; + $data['desc'] = str_replace( + $ossDomain, + $proxyPath, + $data['desc'] + ); + + return $data; + } /**