diff --git a/app/console/model/BrandTranslationModel.php b/app/console/model/BrandTranslationModel.php index 62b0abe..199958b 100644 --- a/app/console/model/BrandTranslationModel.php +++ b/app/console/model/BrandTranslationModel.php @@ -59,4 +59,18 @@ class BrandTranslationModel extends Model { return $this->belongsTo(BrandModel::class, 'brand_id'); } + + // 初始化钩子 + public static function boot() + { + parent::boot(); + + // 保存后触发(包括创建和更新) + static::saved(function ($model) { + // 业务逻辑 + if($model->locale == 'en'){ + BrandModel::updateOrCreate(['id' => $model->id],['letter' => mb_substr($model->name, 0, 1, 'UTF-8')]); + } + }); + } } \ No newline at end of file diff --git a/app/console/service/VehicleNewService.php b/app/console/service/VehicleNewService.php index 9516f5f..9ea6dff 100644 --- a/app/console/service/VehicleNewService.php +++ b/app/console/service/VehicleNewService.php @@ -128,6 +128,9 @@ class VehicleNewService extends BaseService Db::beginTransaction(); try { + if(empty($params['model'])){ + $params['model'] = 0; + } $info = $this->create($params); if (!$info) { throw new BusinessException('提交失败'); @@ -253,6 +256,9 @@ class VehicleNewService extends BaseService Db::beginTransaction(); try { + if(empty($params['model'])){ + $params['model'] = 0; + } $info = $this->update($id, $params); if (!$info) { throw new BusinessException('提交失败');