From 02ee7fda9ca01bc24bb19d2695b553d570216180 Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Fri, 30 May 2025 14:19:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=A6=96=E5=AD=97=E6=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/console/model/BrandTranslationModel.php | 14 ++++++++++++++ app/console/service/VehicleNewService.php | 6 ++++++ 2 files changed, 20 insertions(+) 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('提交失败');