From f8fa2bf3a921879aed684e66dd0db8b6fecc6618 Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Wed, 21 May 2025 11:28:30 +0800 Subject: [PATCH 01/32] =?UTF-8?q?=E5=93=81=E7=89=8C=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/applet/controller/LocationController.php | 4 +- .../controller/BrandBannerController.php | 119 +++++++++++++++++ app/console/controller/BrandController.php | 28 +++- .../controller/BrandTraitController.php | 112 ++++++++++++++++ app/console/model/BrandBannerModel.php | 83 ++++++++++++ .../model/BrandBannerTranslationModel.php | 68 ++++++++++ app/console/model/BrandModel.php | 11 +- app/console/model/BrandTraitModel.php | 84 ++++++++++++ .../model/BrandTraitTranslationModel.php | 67 ++++++++++ app/console/model/BrandTranslationModel.php | 2 +- app/console/service/BrandBannerService.php | 120 ++++++++++++++++++ app/console/service/BrandService.php | 109 +++++++++++++++- app/console/service/BrandTraitService.php | 120 ++++++++++++++++++ app/console/validate/BrandBannerValidator.php | 30 +++++ app/console/validate/BrandTraitValidator.php | 30 +++++ app/mzl/modules/translation/config/trans.php | 8 ++ config/route.php | 14 ++ 17 files changed, 997 insertions(+), 12 deletions(-) create mode 100644 app/console/controller/BrandBannerController.php create mode 100644 app/console/controller/BrandTraitController.php create mode 100644 app/console/model/BrandBannerModel.php create mode 100644 app/console/model/BrandBannerTranslationModel.php create mode 100644 app/console/model/BrandTraitModel.php create mode 100644 app/console/model/BrandTraitTranslationModel.php create mode 100644 app/console/service/BrandBannerService.php create mode 100644 app/console/service/BrandTraitService.php create mode 100644 app/console/validate/BrandBannerValidator.php create mode 100644 app/console/validate/BrandTraitValidator.php diff --git a/app/applet/controller/LocationController.php b/app/applet/controller/LocationController.php index ae7d830..ca616d4 100644 --- a/app/applet/controller/LocationController.php +++ b/app/applet/controller/LocationController.php @@ -65,7 +65,9 @@ class LocationController extends BaseController $params = parent::prepareParams($request, $scene); if ($scene === 'default') { - + $params['filters'] = []; + $params['filters'][] = ['field' => 'user_id', 'operator' => '=', 'value' => $request->input('user_id')]; +// $params['filters'][] = ['field' => 'user_id', 'operator' => '=', 'value' => 111]; } return $params; diff --git a/app/console/controller/BrandBannerController.php b/app/console/controller/BrandBannerController.php new file mode 100644 index 0000000..fb7a051 --- /dev/null +++ b/app/console/controller/BrandBannerController.php @@ -0,0 +1,119 @@ + $item['id'], + 'status' => $item['status'], + 'sort' => $item['sort'], + 'brand_id' => $item['brand_id'], + 'title' => isset($item['translation']) ? $item['translation']['title'] : '', + 'content' => isset($item['translation']) ? $item['translation']['content'] : '', + 'created_at' => date('Y-m-d H:i:s', $item['created_at']), + 'updated_at' => date('Y-m-d H:i:s', $item['updated_at']) + ]; + } + + if ($scene === 'preset') { + return [ + 'id' => $item['id'], + 'name' => isset($item['translation']) ? $item['translation']['name'] : '' + ]; + } + + return $item; + } + + /** + * 参数预处理 (根据场景处理) + * @param Request $request + * @param string $scene + * @return array + */ + protected function prepareParams(Request $request, string $scene): array + { + $params = parent::prepareParams($request, $scene); + + if ($scene === 'default') { + + } + + return $params; + } + + /** + * 分页 + * + * @param Request $request 请求对象 + * @return Response 响应对象 + */ + public function index(Request $request, string $scene = 'default'): Response + { + try { + return parent::index($request, $scene); + } catch (\Throwable $th) { + return $this->errorResponse($th->getMessage().$th->getFile().$th->getLine()); + } + } + + public function add(Request $request): Response + { + try { + $id = $this->getService()->add($request->all()); + return $id ? $this->successResponse(['id' => $id]) + : $this->errorResponse(); + } catch (\Throwable $th) { + return $this->errorResponse($th->getMessage()); + } + } + + public function edit(Request $request, int $id): Response + { + try { + return $this->getService()->edit($request->all(), $id) + ? $this->successResponse() + : $this->errorResponse(); + } catch (\Throwable $th) { + return $this->errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/console/controller/BrandController.php b/app/console/controller/BrandController.php index c6c5307..3f1b1ca 100644 --- a/app/console/controller/BrandController.php +++ b/app/console/controller/BrandController.php @@ -41,14 +41,28 @@ class BrandController extends BaseController { if ($scene === 'default') { - return [ + $result = [ 'id' => $item['id'], 'status' => $item['status'], 'sort' => $item['sort'], + 'toppic' => $item['toppic'], + 'descpic' => $item['descpic'], + 'logo' => $item['logo'], 'name' => isset($item['translation']) ? $item['translation']['name'] : '', + 'desc' => isset($item['translation']) ? $item['translation']['desc'] : '', + 'toppic_alt' => isset($item['translation']) ? $item['translation']['toppic_alt'] : '', + 'descpic_alt' => isset($item['translation']) ? $item['translation']['descpic_alt'] : '', + 'logo_alt' => isset($item['translation']) ? $item['translation']['logo_alt'] : '', 'created_at' => date('Y-m-d H:i:s', $item['created_at']), - 'updated_at' => date('Y-m-d H:i:s', $item['updated_at']) + 'updated_at' => date('Y-m-d H:i:s', $item['updated_at']), ]; + foreach ($item['banner'] as $k => $v) { + $result['banner'][$k] = $v; + } + foreach ($item['trait'] as $k => $v) { + $result['trait'][$k] = $v; + } + return $result; } if ($scene === 'preset') { @@ -86,6 +100,9 @@ class BrandController extends BaseController */ public function index(Request $request, string $scene = 'default'): Response { +// $Brand = BrandModel::with('banner')->with('trait')->where('id',314)->first()->toArray(); +// var_dump($Brand); +// return json($Brand); try { return parent::index($request, $scene); } catch (\Throwable $th) { @@ -108,8 +125,8 @@ class BrandController extends BaseController public function add(Request $request): Response { try { - return $this->getService()->add($request->all()) - ? $this->successResponse() + $id = $this->getService()->add($request->all()); + return $id ? $this->successResponse(['id' => $id]) : $this->errorResponse(); } catch (\Throwable $th) { return $this->errorResponse($th->getMessage()); @@ -119,11 +136,12 @@ class BrandController extends BaseController public function edit(Request $request, int $id): Response { try { + $request->setPost('id',$id); return $this->getService()->edit($request->all(), $id) ? $this->successResponse() : $this->errorResponse(); } catch (\Throwable $th) { - return $this->errorResponse($th->getMessage()); + return $this->errorResponse($th->getMessage().$th->getFile().$th->getLine()); } } } \ No newline at end of file diff --git a/app/console/controller/BrandTraitController.php b/app/console/controller/BrandTraitController.php new file mode 100644 index 0000000..8f3cd5a --- /dev/null +++ b/app/console/controller/BrandTraitController.php @@ -0,0 +1,112 @@ + $item['id'], + 'status' => $item['status'], + 'sort' => $item['sort'], + 'brand_id' => $item['brand_id'], + 'title' => isset($item['translation']) ? $item['translation']['title'] : '', + 'content' => isset($item['translation']) ? $item['translation']['content'] : '', + 'created_at' => date('Y-m-d H:i:s', $item['created_at']), + 'updated_at' => date('Y-m-d H:i:s', $item['updated_at']) + ]; + } + + return $item; + } + + /** + * 参数预处理 (根据场景处理) + * @param Request $request + * @param string $scene + * @return array + */ + protected function prepareParams(Request $request, string $scene): array + { + $params = parent::prepareParams($request, $scene); + + if ($scene === 'default') { + + } + + return $params; + } + + /** + * 分页 + * + * @param Request $request 请求对象 + * @return Response 响应对象 + */ + public function index(Request $request, string $scene = 'default'): Response + { + try { + return parent::index($request, $scene); + } catch (\Throwable $th) { + return $this->errorResponse($th->getMessage().$th->getFile().$th->getLine()); + } + } + + public function add(Request $request): Response + { + try { + $id = $this->getService()->add($request->all()); + return $id ? $this->successResponse(['id' => $id]) + : $this->errorResponse(); + } catch (\Throwable $th) { + return $this->errorResponse($th->getMessage()); + } + } + + public function edit(Request $request, int $id): Response + { + try { + return $this->getService()->edit($request->all(), $id) + ? $this->successResponse() + : $this->errorResponse(); + } catch (\Throwable $th) { + return $this->errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/console/model/BrandBannerModel.php b/app/console/model/BrandBannerModel.php new file mode 100644 index 0000000..ac59ff7 --- /dev/null +++ b/app/console/model/BrandBannerModel.php @@ -0,0 +1,83 @@ +belongsTo(BrandModel::class, 'brand_id'); + } + + /** + * 单条翻译 + */ + public function translation() + { + return $this->hasOne(BrandBannerTranslationModel::class, 'brand_id')->where('locale', locale()); + } + + /** + * 多条翻译 + */ + public function translations() + { + return $this->hasMany(VehicleDataTranslationModel::class, 'brand_id'); + } + + + const TRANS_FIELDS = [ + 'name', 'condition_desc' + ]; +} \ No newline at end of file diff --git a/app/console/model/BrandBannerTranslationModel.php b/app/console/model/BrandBannerTranslationModel.php new file mode 100644 index 0000000..889e01f --- /dev/null +++ b/app/console/model/BrandBannerTranslationModel.php @@ -0,0 +1,68 @@ +belongsTo(BrandModel::class, 'brand_id'); + } + + public function banner() + { + return $this->belongsTo(BrandBannerModel::class, 'banner_id'); + } + +} \ No newline at end of file diff --git a/app/console/model/BrandModel.php b/app/console/model/BrandModel.php index be69cae..a6361b5 100644 --- a/app/console/model/BrandModel.php +++ b/app/console/model/BrandModel.php @@ -47,7 +47,7 @@ class BrandModel extends Model /** * 允许自动填充模型字段 */ - protected $fillable = ['id', 'status', 'sort', 'created_at', 'updated_at']; + protected $fillable = ['id', 'status', 'sort', 'toppic', 'descpic', 'logo', 'letter', 'created_at', 'updated_at']; /** * 不允许自动填充模型字段 @@ -64,4 +64,13 @@ class BrandModel extends Model { return $this->hasMany(BrandTranslationModel::class, 'brand_id'); } + + public function banner() + { + return $this->hasMany(BrandBannerModel::class, 'brand_id','id'); + } + public function trait() + { + return $this->hasMany(BrandTraitModel::class, 'brand_id','id'); + } } \ No newline at end of file diff --git a/app/console/model/BrandTraitModel.php b/app/console/model/BrandTraitModel.php new file mode 100644 index 0000000..52a505a --- /dev/null +++ b/app/console/model/BrandTraitModel.php @@ -0,0 +1,84 @@ +belongsTo(BrandModel::class, 'brand_id'); + } + + /** + * 单条翻译 + */ + public function translation() + { + return $this->hasOne(BrandTraitTranslationModel::class, 'trait_id')->where('locale', locale()); + } + + /** + * 多条翻译 + */ + public function translations() + { + return $this->hasMany(BrandTraitTranslationModel::class, 'trait_id'); + } + + + const TRANS_FIELDS = [ + 'name', 'condition_desc' + ]; +} \ No newline at end of file diff --git a/app/console/model/BrandTraitTranslationModel.php b/app/console/model/BrandTraitTranslationModel.php new file mode 100644 index 0000000..53b3201 --- /dev/null +++ b/app/console/model/BrandTraitTranslationModel.php @@ -0,0 +1,67 @@ +belongsTo(BrandModel::class, 'brand_id'); + } + + public function brandTrait() + { + return $this->belongsTo(BrandTraitModel::class, 'trait_id'); + } +} \ No newline at end of file diff --git a/app/console/model/BrandTranslationModel.php b/app/console/model/BrandTranslationModel.php index aff14ad..62b0abe 100644 --- a/app/console/model/BrandTranslationModel.php +++ b/app/console/model/BrandTranslationModel.php @@ -47,7 +47,7 @@ class BrandTranslationModel extends Model /** * 允许自动填充模型字段 */ - protected $fillable = ['id', 'brand_id', 'locale', 'name']; + protected $fillable = ['id', 'brand_id', 'locale', 'name', 'desc','toppic_alt','descpic_alt','logo_alt']; /** * 不允许自动填充模型字段 diff --git a/app/console/service/BrandBannerService.php b/app/console/service/BrandBannerService.php new file mode 100644 index 0000000..128fec0 --- /dev/null +++ b/app/console/service/BrandBannerService.php @@ -0,0 +1,120 @@ + function ($params) { + return [ + 'filters' => [ + ['field' => 'status', 'operator' => '=', 'value' => '1'], + ['field' => 'brand_id', 'operator' => '=', 'value' => $params['brand_id']], + ], + 'fields' => ['id', 'status', 'sort', 'brand_id', 'pic', 'created_at', 'updated_at'], + 'relations' => [ + 'translation' => ['brand_id','banner_id', 'title', 'content'] + ], + 'sorts' => [ + ['field' => 'id', 'direction' => 'desc'] + ], + 'pagination' => [ + 'page' => $params['page'] ?? 1, + 'per_page' => $params['per_page'] ?? 10, + ] + ]; + }, + ]; + } + + + protected array $translatable = [ + 'alt' + ]; + + public function add(array $params) + { + $sourceLocale = locale(); + $sourceFields = $this->extractSourceFields($params); + $sourceFields['brand_id'] = $params['brand_id']; + if (empty($sourceFields)) { + throw new \InvalidArgumentException("请传递至少一条 {$sourceLocale} 语言的翻译字段"); + }; + + Db::beginTransaction(); + try { + $info = $this->create($params); + if (!$info) { + throw new BusinessException('提交失败'); + } + + // 异步翻译并写入 hs_vehicle_data_translation 表 + (new TranslationService())->queueTranslations( + 'brandBanner', + $info->id, + $sourceLocale, + $sourceFields + ); + + Db::commit(); + return $info->id; + } catch (\Throwable $th) { + Db::rollBack(); + throw $th; + } + } + + + public function edit(array $params, int $id) + { + $sourceLocale = locale(); + $sourceFields = $this->extractSourceFields($params); + if (empty($sourceFields)) { + throw new \InvalidArgumentException("请传递至少一条 {$sourceLocale} 语言的翻译字段"); + }; + + Db::beginTransaction(); + try { + $info = $this->update($id, $params); + if (!$info) { + throw new BusinessException('提交失败'); + } + + // 异步翻译并写入 hs_vehicle_data_translation 表 + (new TranslationService())->queueTranslations( + 'brandBanner', + $id, + $sourceLocale, + $sourceFields + ); + + Db::commit(); + return $id; + } catch (\Throwable $th) { + Db::rollBack(); + throw $th; + } + } +} \ No newline at end of file diff --git a/app/console/service/BrandService.php b/app/console/service/BrandService.php index 7b0a4ff..3533edd 100644 --- a/app/console/service/BrandService.php +++ b/app/console/service/BrandService.php @@ -2,7 +2,9 @@ namespace app\console\service; +use app\console\model\BrandBannerModel; use app\console\model\BrandModel; +use app\console\model\BrandTraitModel; use app\mzl\common\services\BaseService; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; @@ -33,9 +35,13 @@ class BrandService extends BaseService 'filters' => [ ['field' => 'status', 'operator' => '=', 'value' => '1'] ], - 'fields' => ['id', 'status', 'sort', 'created_at', 'updated_at'], + 'fields' => ['id', 'status', 'sort', 'toppic', 'descpic', 'logo', 'letter', 'created_at', 'updated_at'], 'relations' => [ - 'translation' => ['brand_id', 'name'] + 'translation' => ['brand_id', 'name', 'desc','toppic_alt','descpic_alt','logo_alt'], + 'banner' => ['id', 'pic', 'sort',], + 'banner.translation' => ['id', 'alt',], + 'trait' => ['id', 'sort',], + 'trait.translation' => ['id', 'title', 'content',], ], 'sorts' => [ ['field' => 'id', 'direction' => 'desc'] @@ -65,12 +71,20 @@ class BrandService extends BaseService protected array $translatable = [ - 'name' + 'name', 'desc','toppic_alt','descpic_alt','logo_alt' ]; public function add(array $params) { $sourceLocale = locale(); + + $BrandBannerService = new BrandBannerService(new BrandBannerModel()); + $BrandTraitService = new BrandTraitService(new BrandTraitModel()); + $banners = $params['banners'] ?? null; + unset($params['banners']); + $traits = $params['traits'] ?? null; + unset($params['traits']); + $sourceFields = $this->extractSourceFields($params); if (empty($sourceFields)) { throw new \InvalidArgumentException("请传递至少一条 {$sourceLocale} 语言的翻译字段"); @@ -91,8 +105,44 @@ class BrandService extends BaseService $sourceFields ); + //品牌轮播图 + foreach ($banners as $banner) { + $bannersourceFields = $BrandBannerService->extractSourceFields($banner); + $bannersourceFields['brand_id'] = $info->id; + $banner['brand_id'] = $info->id; + $banner = $BrandBannerService->create($banner); + if (!$banner) { + throw new BusinessException('提交失败'); + } + + (new TranslationService())->queueTranslations( + 'brandBanner', + $banner->id, + $sourceLocale, + $bannersourceFields + ); + } + + //品牌特性 + foreach ($traits as $trait) { + $traitsourceFields = $BrandTraitService->extractSourceFields($trait); + $traitsourceFields['brand_id'] = $info->id; + $trait['brand_id'] = $info->id; + $trait = $BrandTraitService->create($trait); + if (!$trait) { + throw new BusinessException('提交失败'); + } + + (new TranslationService())->queueTranslations( + 'brandTrait', + $trait->id, + $sourceLocale, + $traitsourceFields + ); + } + Db::commit(); - return true; + return $info->id; } catch (\Throwable $th) { Db::rollBack(); throw $th; @@ -102,6 +152,14 @@ class BrandService extends BaseService public function edit(array $params, int $id) { $sourceLocale = locale(); + + $BrandBannerService = new BrandBannerService(new BrandBannerModel()); + $BrandTraitService = new BrandTraitService(new BrandTraitModel()); + $banners = $params['banners'] ?? null; + unset($params['banners']); + $traits = $params['traits'] ?? null; + unset($params['traits']); + $sourceFields = $this->extractSourceFields($params); if (empty($sourceFields)) { throw new \InvalidArgumentException("请传递至少一条 {$sourceLocale} 语言的翻译字段"); @@ -122,6 +180,49 @@ class BrandService extends BaseService $sourceFields ); + //品牌轮播图 + foreach ($banners as $banner) { + $bannersourceFields = $BrandBannerService->extractSourceFields($banner); + $bannersourceFields['brand_id'] = $id; + $bannerId = $banner['id']; + $banner['brand_id'] = $id; + $banner = $BrandBannerService->update($bannerId,$banner); + if (!$banner) { + throw new BusinessException('提交失败'); + } + + (new TranslationService())->queueTranslations( + 'brandBanner', + $bannerId, + $sourceLocale, + $bannersourceFields + ); + } + $ids = array_column($banners,'id'); + BrandBannerModel::whereNotIn('id', $ids)->where('brand_id',$id)->delete(); + + //品牌特性 + foreach ($traits as $trait) { + $traitsourceFields = $BrandTraitService->extractSourceFields($trait); + $traitsourceFields['brand_id'] = $id; + $traitId = $trait['id']; + $trait['brand_id'] = $id; + $trait = $BrandTraitService->update($traitId,$trait); + if (!$trait) { + throw new BusinessException('提交失败'); + } + + (new TranslationService())->queueTranslations( + 'brandTrait', + $traitId, + $sourceLocale, + $traitsourceFields + ); + } + $ids = array_column($traits,'id'); + BrandTraitModel::whereNotIn('id', $ids)->where('brand_id',$id)->delete(); + + Db::commit(); return true; } catch (\Throwable $th) { diff --git a/app/console/service/BrandTraitService.php b/app/console/service/BrandTraitService.php new file mode 100644 index 0000000..920c60e --- /dev/null +++ b/app/console/service/BrandTraitService.php @@ -0,0 +1,120 @@ + function ($params) { + return [ + 'filters' => [ + ['field' => 'status', 'operator' => '=', 'value' => '1'], + ['field' => 'brand_id', 'operator' => '=', 'value' => $params['brand_id']], + ], + 'fields' => ['id', 'status', 'sort', 'brand_id', 'created_at', 'updated_at'], + 'relations' => [ + 'translation' => ['brand_id','trait_id', 'title', 'content'] + ], + 'sorts' => [ + ['field' => 'id', 'direction' => 'desc'] + ], + 'pagination' => [ + 'page' => $params['page'] ?? 1, + 'per_page' => $params['per_page'] ?? 10, + ] + ]; + }, + ]; + } + + + protected array $translatable = [ + 'title', 'content' + ]; + + public function add(array $params) + { + $sourceLocale = locale(); + $sourceFields = $this->extractSourceFields($params); + $sourceFields['brand_id'] = $params['brand_id']; + if (empty($sourceFields)) { + throw new \InvalidArgumentException("请传递至少一条 {$sourceLocale} 语言的翻译字段"); + }; + + Db::beginTransaction(); + try { + $info = $this->create($params); + if (!$info) { + throw new BusinessException('提交失败'); + } + + // 异步翻译并写入 hs_vehicle_data_translation 表 + (new TranslationService())->queueTranslations( + 'brandTrait', + $info->id, + $sourceLocale, + $sourceFields + ); + + Db::commit(); + return $info->id; + } catch (\Throwable $th) { + Db::rollBack(); + throw $th; + } + } + + + public function edit(array $params, int $id) + { + $sourceLocale = locale(); + $sourceFields = $this->extractSourceFields($params); + if (empty($sourceFields)) { + throw new \InvalidArgumentException("请传递至少一条 {$sourceLocale} 语言的翻译字段"); + }; + + Db::beginTransaction(); + try { + $info = $this->update($id, $params); + if (!$info) { + throw new BusinessException('提交失败'); + } + + // 异步翻译并写入 hs_vehicle_data_translation 表 + (new TranslationService())->queueTranslations( + 'brandTrait', + $id, + $sourceLocale, + $sourceFields + ); + + Db::commit(); + return $id; + } catch (\Throwable $th) { + Db::rollBack(); + throw $th; + } + } +} \ No newline at end of file diff --git a/app/console/validate/BrandBannerValidator.php b/app/console/validate/BrandBannerValidator.php new file mode 100644 index 0000000..c2022f2 --- /dev/null +++ b/app/console/validate/BrandBannerValidator.php @@ -0,0 +1,30 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/console/validate/BrandTraitValidator.php b/app/console/validate/BrandTraitValidator.php new file mode 100644 index 0000000..bb92b1d --- /dev/null +++ b/app/console/validate/BrandTraitValidator.php @@ -0,0 +1,30 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/mzl/modules/translation/config/trans.php b/app/mzl/modules/translation/config/trans.php index 01b353a..7c55644 100644 --- a/app/mzl/modules/translation/config/trans.php +++ b/app/mzl/modules/translation/config/trans.php @@ -23,6 +23,14 @@ return [ 'translation_model' => \app\console\model\BrandTranslationModel::class, 'foreign_key' => 'brand_id', ], + 'brandBanner' => [ + 'translation_model' => \app\console\model\BrandBannerTranslationModel::class, + 'foreign_key' => 'banner_id', + ], + 'brandTrait' => [ + 'translation_model' => \app\console\model\BrandTraitTranslationModel::class, + 'foreign_key' => 'trait_id', + ], 'agreement' => [ 'translation_model' => \app\console\model\AgreementTranslationModel::class, 'foreign_key' => 'agreement_id', diff --git a/config/route.php b/config/route.php index c88c564..df425a2 100644 --- a/config/route.php +++ b/config/route.php @@ -40,6 +40,8 @@ Route::group('/apis', function() { Route::any('/vehicle/random', [\app\apis\controller\VehicleDataController::class, 'random']); // 隐私协议 Route::any('/agt/privacy', [\app\apis\controller\AgreementController::class, 'one']); + // 品牌按字母查询 + Route::any('/brand/letterAll', [\app\apis\controller\BrandController::class, 'letterAll']); }); // ====== ====== ====== 网站 ====== ====== ====== @@ -124,6 +126,18 @@ Route::group('/console', function() { Route::any('/brand/{id}/detail', [\app\console\controller\BrandController::class, 'show']); Route::any('/brand/preset', [\app\console\controller\BrandController::class, 'presets']); + // 品牌轮播 + Route::any('/brandbanner/add', [\app\console\controller\BrandBannerController::class, 'add']); + Route::any('/brandbanner/update/{id}', [\app\console\controller\BrandBannerController::class, 'edit']); + Route::any('/brandbanner/list', [\app\console\controller\BrandBannerController::class, 'index']); + Route::any('/brandbanner/delete/{id}', [\app\console\controller\BrandBannerController::class, 'destroy']); + + // 品牌特性 + Route::any('/brandtrait/add', [\app\console\controller\BrandTraitController::class, 'add']); + Route::any('/brandtrait/update/{id}', [\app\console\controller\BrandTraitController::class, 'edit']); + Route::any('/brandtrait/list', [\app\console\controller\BrandTraitController::class, 'index']); + Route::any('/brandtrait/delete/{id}', [\app\console\controller\BrandTraitController::class, 'destroy']); + // 能源管理 Route::any('/energy/list', [\app\console\controller\EnergyController::class, 'index']); Route::any('/energy/add', [\app\console\controller\EnergyController::class, 'add']); From 80b6ea20767b4f06a9652f173e8e47dfa178787e Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Thu, 22 May 2025 09:26:19 +0800 Subject: [PATCH 02/32] =?UTF-8?q?=E6=96=B0=E8=BD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/VehicleNewAlbumController.php | 81 ++++++++ .../VehicleNewAlbumTranslationController.php | 81 ++++++++ .../controller/VehicleNewAskedController.php | 81 ++++++++ .../VehicleNewAskedTranslationController.php | 81 ++++++++ .../VehicleNewContentController.php | 81 ++++++++ ...VehicleNewContentTranslationController.php | 81 ++++++++ .../controller/VehicleNewController.php | 92 +++++++++ .../controller/VehicleNewTraitController.php | 81 ++++++++ .../VehicleNewTraitTranslationController.php | 81 ++++++++ .../VehicleNewTranslationController.php | 81 ++++++++ app/console/model/VehicleNewAlbumModel.php | 72 +++++++ .../model/VehicleNewAlbumTranslationModel.php | 56 ++++++ app/console/model/VehicleNewAskedModel.php | 80 ++++++++ .../model/VehicleNewAskedTranslationModel.php | 56 ++++++ app/console/model/VehicleNewContentModel.php | 72 +++++++ .../VehicleNewContentTranslationModel.php | 56 ++++++ app/console/model/VehicleNewModel.php | 118 ++++++++++++ app/console/model/VehicleNewTraitModel.php | 72 +++++++ .../model/VehicleNewTraitTranslationModel.php | 56 ++++++ .../model/VehicleNewTranslationModel.php | 56 ++++++ .../service/VehicleNewAlbumService.php | 64 +++++++ .../VehicleNewAlbumTranslationService.php | 59 ++++++ .../service/VehicleNewAskedService.php | 66 +++++++ .../VehicleNewAskedTranslationService.php | 59 ++++++ .../service/VehicleNewContentService.php | 59 ++++++ .../VehicleNewContentTranslationService.php | 59 ++++++ app/console/service/VehicleNewService.php | 180 ++++++++++++++++++ .../service/VehicleNewTraitService.php | 59 ++++++ .../VehicleNewTraitTranslationService.php | 65 +++++++ .../service/VehicleNewTranslationService.php | 59 ++++++ .../VehicleNewAlbumTranslationValidator.php | 29 +++ .../validate/VehicleNewAlbumValidator.php | 29 +++ .../VehicleNewAskedTranslationValidator.php | 29 +++ .../validate/VehicleNewAskedValidator.php | 29 +++ .../VehicleNewContentTranslationValidator.php | 29 +++ .../validate/VehicleNewContentValidator.php | 29 +++ .../VehicleNewTraitTranslationValidator.php | 29 +++ .../validate/VehicleNewTraitValidator.php | 29 +++ .../VehicleNewTranslationValidator.php | 29 +++ app/console/validate/VehicleNewValidator.php | 29 +++ app/mzl/modules/translation/config/trans.php | 30 ++- config/route.php | 8 + 42 files changed, 2571 insertions(+), 1 deletion(-) create mode 100644 app/console/controller/VehicleNewAlbumController.php create mode 100644 app/console/controller/VehicleNewAlbumTranslationController.php create mode 100644 app/console/controller/VehicleNewAskedController.php create mode 100644 app/console/controller/VehicleNewAskedTranslationController.php create mode 100644 app/console/controller/VehicleNewContentController.php create mode 100644 app/console/controller/VehicleNewContentTranslationController.php create mode 100644 app/console/controller/VehicleNewController.php create mode 100644 app/console/controller/VehicleNewTraitController.php create mode 100644 app/console/controller/VehicleNewTraitTranslationController.php create mode 100644 app/console/controller/VehicleNewTranslationController.php create mode 100644 app/console/model/VehicleNewAlbumModel.php create mode 100644 app/console/model/VehicleNewAlbumTranslationModel.php create mode 100644 app/console/model/VehicleNewAskedModel.php create mode 100644 app/console/model/VehicleNewAskedTranslationModel.php create mode 100644 app/console/model/VehicleNewContentModel.php create mode 100644 app/console/model/VehicleNewContentTranslationModel.php create mode 100644 app/console/model/VehicleNewModel.php create mode 100644 app/console/model/VehicleNewTraitModel.php create mode 100644 app/console/model/VehicleNewTraitTranslationModel.php create mode 100644 app/console/model/VehicleNewTranslationModel.php create mode 100644 app/console/service/VehicleNewAlbumService.php create mode 100644 app/console/service/VehicleNewAlbumTranslationService.php create mode 100644 app/console/service/VehicleNewAskedService.php create mode 100644 app/console/service/VehicleNewAskedTranslationService.php create mode 100644 app/console/service/VehicleNewContentService.php create mode 100644 app/console/service/VehicleNewContentTranslationService.php create mode 100644 app/console/service/VehicleNewService.php create mode 100644 app/console/service/VehicleNewTraitService.php create mode 100644 app/console/service/VehicleNewTraitTranslationService.php create mode 100644 app/console/service/VehicleNewTranslationService.php create mode 100644 app/console/validate/VehicleNewAlbumTranslationValidator.php create mode 100644 app/console/validate/VehicleNewAlbumValidator.php create mode 100644 app/console/validate/VehicleNewAskedTranslationValidator.php create mode 100644 app/console/validate/VehicleNewAskedValidator.php create mode 100644 app/console/validate/VehicleNewContentTranslationValidator.php create mode 100644 app/console/validate/VehicleNewContentValidator.php create mode 100644 app/console/validate/VehicleNewTraitTranslationValidator.php create mode 100644 app/console/validate/VehicleNewTraitValidator.php create mode 100644 app/console/validate/VehicleNewTranslationValidator.php create mode 100644 app/console/validate/VehicleNewValidator.php diff --git a/app/console/controller/VehicleNewAlbumController.php b/app/console/controller/VehicleNewAlbumController.php new file mode 100644 index 0000000..21ba72a --- /dev/null +++ b/app/console/controller/VehicleNewAlbumController.php @@ -0,0 +1,81 @@ +errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/console/controller/VehicleNewAlbumTranslationController.php b/app/console/controller/VehicleNewAlbumTranslationController.php new file mode 100644 index 0000000..db08db7 --- /dev/null +++ b/app/console/controller/VehicleNewAlbumTranslationController.php @@ -0,0 +1,81 @@ +errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/console/controller/VehicleNewAskedController.php b/app/console/controller/VehicleNewAskedController.php new file mode 100644 index 0000000..8b3d835 --- /dev/null +++ b/app/console/controller/VehicleNewAskedController.php @@ -0,0 +1,81 @@ +errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/console/controller/VehicleNewAskedTranslationController.php b/app/console/controller/VehicleNewAskedTranslationController.php new file mode 100644 index 0000000..03ac132 --- /dev/null +++ b/app/console/controller/VehicleNewAskedTranslationController.php @@ -0,0 +1,81 @@ +errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/console/controller/VehicleNewContentController.php b/app/console/controller/VehicleNewContentController.php new file mode 100644 index 0000000..28d25a4 --- /dev/null +++ b/app/console/controller/VehicleNewContentController.php @@ -0,0 +1,81 @@ +errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/console/controller/VehicleNewContentTranslationController.php b/app/console/controller/VehicleNewContentTranslationController.php new file mode 100644 index 0000000..cfe52b7 --- /dev/null +++ b/app/console/controller/VehicleNewContentTranslationController.php @@ -0,0 +1,81 @@ +errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/console/controller/VehicleNewController.php b/app/console/controller/VehicleNewController.php new file mode 100644 index 0000000..203ab2f --- /dev/null +++ b/app/console/controller/VehicleNewController.php @@ -0,0 +1,92 @@ +getService()->add($request->all()) + ? $this->successResponse() + : $this->errorResponse(); + } catch (\Throwable $th) { + return $this->errorResponse($th->getMessage().$th->getLine().$th->getFile()); + } + } + + /** + * 分页 + * + * @param Request $request 请求对象 + * @return Response 响应对象 + */ + public function index(Request $request, string $scene = 'default'): Response + { + try { + return parent::index($request, $scene); + } catch (\Throwable $th) { + return $this->errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/console/controller/VehicleNewTraitController.php b/app/console/controller/VehicleNewTraitController.php new file mode 100644 index 0000000..aa72c2a --- /dev/null +++ b/app/console/controller/VehicleNewTraitController.php @@ -0,0 +1,81 @@ +errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/console/controller/VehicleNewTraitTranslationController.php b/app/console/controller/VehicleNewTraitTranslationController.php new file mode 100644 index 0000000..1e06604 --- /dev/null +++ b/app/console/controller/VehicleNewTraitTranslationController.php @@ -0,0 +1,81 @@ +errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/console/controller/VehicleNewTranslationController.php b/app/console/controller/VehicleNewTranslationController.php new file mode 100644 index 0000000..3a51378 --- /dev/null +++ b/app/console/controller/VehicleNewTranslationController.php @@ -0,0 +1,81 @@ +errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/console/model/VehicleNewAlbumModel.php b/app/console/model/VehicleNewAlbumModel.php new file mode 100644 index 0000000..ef88fee --- /dev/null +++ b/app/console/model/VehicleNewAlbumModel.php @@ -0,0 +1,72 @@ +hasOne(VehicleNewAlbumTranslationModel::class, 'album_id')->where('locale', locale()); + } + + /** + * 多条翻译 + */ + public function translations() + { + return $this->hasMany(VehicleNewAlbumTranslationModel::class, 'album_id'); + } +} \ No newline at end of file diff --git a/app/console/model/VehicleNewAlbumTranslationModel.php b/app/console/model/VehicleNewAlbumTranslationModel.php new file mode 100644 index 0000000..997da96 --- /dev/null +++ b/app/console/model/VehicleNewAlbumTranslationModel.php @@ -0,0 +1,56 @@ +hasOne(VehicleNewAskedTranslationModel::class, 'asked_id')->where('locale', locale()); + } + + /** + * 多条翻译 + */ + public function translations() + { + return $this->hasMany(VehicleNewAskedTranslationModel::class, 'asked_id'); + } +} \ No newline at end of file diff --git a/app/console/model/VehicleNewAskedTranslationModel.php b/app/console/model/VehicleNewAskedTranslationModel.php new file mode 100644 index 0000000..c590c45 --- /dev/null +++ b/app/console/model/VehicleNewAskedTranslationModel.php @@ -0,0 +1,56 @@ +hasOne(VehicleNewContentTranslationModel::class, 'content_id')->where('locale', locale()); + } + + /** + * 多条翻译 + */ + public function translations() + { + return $this->hasMany(VehicleNewContentTranslationModel::class, 'content_id'); + } +} \ No newline at end of file diff --git a/app/console/model/VehicleNewContentTranslationModel.php b/app/console/model/VehicleNewContentTranslationModel.php new file mode 100644 index 0000000..1389fee --- /dev/null +++ b/app/console/model/VehicleNewContentTranslationModel.php @@ -0,0 +1,56 @@ +hasOne(VehicleNewTranslationModel::class, 'vehicle_id')->where('locale', locale()); + } + + /** + * 多条翻译 + */ + public function translations() + { + return $this->hasMany(VehicleNewTranslationModel::class, 'vehicle_id'); + } + + public function brand() + { + return $this->belongsTo(BrandModel::class, 'brand'); + } + + public function models() + { + return $this->belongsTo(ModelModel::class, 'model'); + } + + public function location() + { + return $this->belongsTo(LocationModel::class, 'location'); + } + + public function types() + { + return $this->belongsTo(TypesModel::class, 'type', 'id'); + } + + public function energy() + { + return $this->belongsTo(EnergyModel::class, 'energy', 'id'); + } + + public function album() + { + return $this->hasMany(VehicleNewAlbumModel::class, 'vehicle_id', 'id'); + } + + public function asked() + { + return $this->hasMany(VehicleNewAskedModel::class, 'vehicle_id', 'id'); + } + + public function trait() + { + return $this->hasMany(VehicleNewTraitModel::class, 'vehicle_id', 'id'); + } + + public function content() + { + return $this->hasMany(VehicleNewContentModel::class, 'vehicle_id', 'id'); + } +} \ No newline at end of file diff --git a/app/console/model/VehicleNewTraitModel.php b/app/console/model/VehicleNewTraitModel.php new file mode 100644 index 0000000..a5b293e --- /dev/null +++ b/app/console/model/VehicleNewTraitModel.php @@ -0,0 +1,72 @@ +hasOne(VehicleNewTraitTranslationModel::class, 'trait_id')->where('locale', locale()); + } + + /** + * 多条翻译 + */ + public function translations() + { + return $this->hasMany(VehicleNewTraitTranslationModel::class, 'trait_id'); + } +} \ No newline at end of file diff --git a/app/console/model/VehicleNewTraitTranslationModel.php b/app/console/model/VehicleNewTraitTranslationModel.php new file mode 100644 index 0000000..d9b367d --- /dev/null +++ b/app/console/model/VehicleNewTraitTranslationModel.php @@ -0,0 +1,56 @@ + function ($params) { + // $keyword = $params['keyword'] ?? ''; + // return [ + // 'filters' => [ + // ['field' => '***', 'operator' => '=', 'value' => '***'] + // ], + // 'fields' => ['id'], + // 'relations' => [], + // 'custom' => function(Builder $q) use ($keyword) { + // // 示例 + // if ($keyword) { + // $q->where(function($q2) use($keyword) { + // $q2->whereHas('***', function($q3) use($keyword) { + // $q3->where('***', 'like', "%{$keyword}%"); + // })->orWhereHas('***', function($q4) use($keyword) { + // $q4->where('***', 'like', "%{$keyword}%"); + // }); + // }); + // } + // }, + // 'sorts' => [ + // ['field' => 'created_at', 'direction' => 'desc'] + // ], + // 'pagination' => [ + // 'page' => $params['page'] ?? 1, + // 'per_page' => $params['per_page'] ?? 10, + // ] + // ]; + // } + ]; + } + + // 声明需要多语言翻译 + protected array $translatable = [ + 'alt', + ]; +} \ No newline at end of file diff --git a/app/console/service/VehicleNewAlbumTranslationService.php b/app/console/service/VehicleNewAlbumTranslationService.php new file mode 100644 index 0000000..d9a7d88 --- /dev/null +++ b/app/console/service/VehicleNewAlbumTranslationService.php @@ -0,0 +1,59 @@ + function ($params) { + // $keyword = $params['keyword'] ?? ''; + // return [ + // 'filters' => [ + // ['field' => '***', 'operator' => '=', 'value' => '***'] + // ], + // 'fields' => ['id'], + // 'relations' => [], + // 'custom' => function(Builder $q) use ($keyword) { + // // 示例 + // if ($keyword) { + // $q->where(function($q2) use($keyword) { + // $q2->whereHas('***', function($q3) use($keyword) { + // $q3->where('***', 'like', "%{$keyword}%"); + // })->orWhereHas('***', function($q4) use($keyword) { + // $q4->where('***', 'like', "%{$keyword}%"); + // }); + // }); + // } + // }, + // 'sorts' => [ + // ['field' => 'created_at', 'direction' => 'desc'] + // ], + // 'pagination' => [ + // 'page' => $params['page'] ?? 1, + // 'per_page' => $params['per_page'] ?? 10, + // ] + // ]; + // } + ]; + } +} \ No newline at end of file diff --git a/app/console/service/VehicleNewAskedService.php b/app/console/service/VehicleNewAskedService.php new file mode 100644 index 0000000..5a03b45 --- /dev/null +++ b/app/console/service/VehicleNewAskedService.php @@ -0,0 +1,66 @@ + function ($params) { + // $keyword = $params['keyword'] ?? ''; + // return [ + // 'filters' => [ + // ['field' => '***', 'operator' => '=', 'value' => '***'] + // ], + // 'fields' => ['id'], + // 'relations' => [], + // 'custom' => function(Builder $q) use ($keyword) { + // // 示例 + // if ($keyword) { + // $q->where(function($q2) use($keyword) { + // $q2->whereHas('***', function($q3) use($keyword) { + // $q3->where('***', 'like', "%{$keyword}%"); + // })->orWhereHas('***', function($q4) use($keyword) { + // $q4->where('***', 'like', "%{$keyword}%"); + // }); + // }); + // } + // }, + // 'sorts' => [ + // ['field' => 'created_at', 'direction' => 'desc'] + // ], + // 'pagination' => [ + // 'page' => $params['page'] ?? 1, + // 'per_page' => $params['per_page'] ?? 10, + // ] + // ]; + // } + ]; + } + + + // 声明需要多语言翻译 + protected array $translatable = [ + 'title', + 'content', + ]; +} \ No newline at end of file diff --git a/app/console/service/VehicleNewAskedTranslationService.php b/app/console/service/VehicleNewAskedTranslationService.php new file mode 100644 index 0000000..1a21323 --- /dev/null +++ b/app/console/service/VehicleNewAskedTranslationService.php @@ -0,0 +1,59 @@ + function ($params) { + // $keyword = $params['keyword'] ?? ''; + // return [ + // 'filters' => [ + // ['field' => '***', 'operator' => '=', 'value' => '***'] + // ], + // 'fields' => ['id'], + // 'relations' => [], + // 'custom' => function(Builder $q) use ($keyword) { + // // 示例 + // if ($keyword) { + // $q->where(function($q2) use($keyword) { + // $q2->whereHas('***', function($q3) use($keyword) { + // $q3->where('***', 'like', "%{$keyword}%"); + // })->orWhereHas('***', function($q4) use($keyword) { + // $q4->where('***', 'like', "%{$keyword}%"); + // }); + // }); + // } + // }, + // 'sorts' => [ + // ['field' => 'created_at', 'direction' => 'desc'] + // ], + // 'pagination' => [ + // 'page' => $params['page'] ?? 1, + // 'per_page' => $params['per_page'] ?? 10, + // ] + // ]; + // } + ]; + } +} \ No newline at end of file diff --git a/app/console/service/VehicleNewContentService.php b/app/console/service/VehicleNewContentService.php new file mode 100644 index 0000000..cc9795d --- /dev/null +++ b/app/console/service/VehicleNewContentService.php @@ -0,0 +1,59 @@ + function ($params) { + // $keyword = $params['keyword'] ?? ''; + // return [ + // 'filters' => [ + // ['field' => '***', 'operator' => '=', 'value' => '***'] + // ], + // 'fields' => ['id'], + // 'relations' => [], + // 'custom' => function(Builder $q) use ($keyword) { + // // 示例 + // if ($keyword) { + // $q->where(function($q2) use($keyword) { + // $q2->whereHas('***', function($q3) use($keyword) { + // $q3->where('***', 'like', "%{$keyword}%"); + // })->orWhereHas('***', function($q4) use($keyword) { + // $q4->where('***', 'like', "%{$keyword}%"); + // }); + // }); + // } + // }, + // 'sorts' => [ + // ['field' => 'created_at', 'direction' => 'desc'] + // ], + // 'pagination' => [ + // 'page' => $params['page'] ?? 1, + // 'per_page' => $params['per_page'] ?? 10, + // ] + // ]; + // } + ]; + } +} \ No newline at end of file diff --git a/app/console/service/VehicleNewContentTranslationService.php b/app/console/service/VehicleNewContentTranslationService.php new file mode 100644 index 0000000..656894e --- /dev/null +++ b/app/console/service/VehicleNewContentTranslationService.php @@ -0,0 +1,59 @@ + function ($params) { + // $keyword = $params['keyword'] ?? ''; + // return [ + // 'filters' => [ + // ['field' => '***', 'operator' => '=', 'value' => '***'] + // ], + // 'fields' => ['id'], + // 'relations' => [], + // 'custom' => function(Builder $q) use ($keyword) { + // // 示例 + // if ($keyword) { + // $q->where(function($q2) use($keyword) { + // $q2->whereHas('***', function($q3) use($keyword) { + // $q3->where('***', 'like', "%{$keyword}%"); + // })->orWhereHas('***', function($q4) use($keyword) { + // $q4->where('***', 'like', "%{$keyword}%"); + // }); + // }); + // } + // }, + // 'sorts' => [ + // ['field' => 'created_at', 'direction' => 'desc'] + // ], + // 'pagination' => [ + // 'page' => $params['page'] ?? 1, + // 'per_page' => $params['per_page'] ?? 10, + // ] + // ]; + // } + ]; + } +} \ No newline at end of file diff --git a/app/console/service/VehicleNewService.php b/app/console/service/VehicleNewService.php new file mode 100644 index 0000000..bc7813f --- /dev/null +++ b/app/console/service/VehicleNewService.php @@ -0,0 +1,180 @@ + function ($params) { + $keyword = $params['keyword'] ?? ''; + return [ + 'filters' => [ +// ['field' => '***', 'operator' => '=', 'value' => '***'] + ], + 'fields' => ['id', 'vin', 'brand', 'cover', 'price', 'type', 'energy', 'model', 'video', 'views', 'created_at', 'updated_at'], + 'relations' => [ + 'translation' => ['vehicle_id', 'locale', 'condition_desc', 'location'], + 'asked' => ['id', 'vehicle_id', 'status', 'sort'], + 'asked.translation' => ['id', 'asked_id', 'locale', 'title', 'content'], + 'trait' => ['id', 'vehicle_id', 'status', 'sort'], + 'trait.translation' => ['id', 'trait_id', 'locale', 'title', 'content'], + 'album' => ['id', 'vehicle_id', 'status', 'sort'], + 'album.translation' => ['id', 'album_id', 'locale', 'alt'], + 'content' => ['id', 'vehicle_id', 'status', 'sort'], + 'content.translation' => ['id', 'content_id', 'locale', 'content'], + ], + 'sorts' => [ + ['field' => 'id', 'direction' => 'desc'] + ], + 'pagination' => [ + 'page' => $params['page'] ?? 1, + 'per_page' => $params['per_page'] ?? 10, + ] + ]; + } + ]; + } + + + // 声明需要多语言翻译 + protected array $translatable = [ + 'condition_desc', + ]; + + public function add(array $params) + { + $sourceLocale = locale(); + $sourceFields = $this->extractSourceFields($params); + + if (empty($sourceFields)) { + throw new \InvalidArgumentException("请传递至少一条 {$sourceLocale} 语言的翻译字段"); + }; + + $askeds = $params['asked']; + unset($params['asked']); + $traits = $params['trait']; + unset($params['trait']); + $albums = $params['album']; + unset($params['album']); + $contents = $params['content']; + unset($params['content']); + + $VehicleNewAskedService = new VehicleNewAskedService(new VehicleNewAskedModel()); + $VehicleNewTraitService = new VehicleNewTraitService(new VehicleNewTraitModel()); + $VehicleNewAlbumService = new VehicleNewAlbumService(new VehicleNewAlbumModel()); + $VehicleNewContentService = new VehicleNewContentService(new VehicleNewContentModel()); + + Db::beginTransaction(); + try { + $info = $this->create($params); + if (!$info) { + throw new BusinessException('提交失败'); + } + + // 异步翻译并写入 hs_vehicle_data_translation 表 + (new TranslationService())->queueTranslations( + 'vehicleNew', + $info->id, + $sourceLocale, + $sourceFields + ); + + foreach ($askeds as $asked) { + $askedsourceFields = $VehicleNewAskedService->extractSourceFields($asked); + $asked['vehicle_id'] = $info->id; + $asked_res = $VehicleNewAskedService->create($asked); + if (!$asked_res) { + throw new BusinessException('提交失败'); + } +// $askedsourceFields['asked_id'] = $asked_res->id; + (new TranslationService())->queueTranslations( + 'vehicleNewAsked', + $asked_res->id, + $sourceLocale, + $askedsourceFields + ); + } + + foreach ($traits as $trait) { + $traitsourceFields = $VehicleNewTraitService->extractSourceFields($trait); + $trait['vehicle_id'] = $info->id; + $trait_res = $VehicleNewTraitService->create($trait); + if (!$trait_res) { + throw new BusinessException('提交失败'); + } + + (new TranslationService())->queueTranslations( + 'vehicleNewTrait', + $trait_res->id, + $sourceLocale, + $traitsourceFields + ); + } + + foreach ($albums as $album) { + $albumsourceFields = $VehicleNewAlbumService->extractSourceFields($album); + $album['vehicle_id'] = $info->id; + $trait_res = $VehicleNewAlbumService->create($trait); + if (!$trait_res) { + throw new BusinessException('提交失败'); + } + + (new TranslationService())->queueTranslations( + 'vehicleNewTrait', + $trait_res->id, + $sourceLocale, + $albumsourceFields + ); + } + + foreach ($contents as $content) { + $contentsourceFields = $VehicleNewContentService->extractSourceFields($content); + $content['vehicle_id'] = $info->id; + $trait_res = $VehicleNewContentService->create($content); + if (!$trait_res) { + throw new BusinessException('提交失败'); + } + + (new TranslationService())->queueTranslations( + 'vehicleNewContent', + $trait_res->id, + $sourceLocale, + $contentsourceFields + ); + } + + Db::commit(); + return true; + } catch (\Throwable $th) { + Db::rollBack(); + throw $th; + } + } +} \ No newline at end of file diff --git a/app/console/service/VehicleNewTraitService.php b/app/console/service/VehicleNewTraitService.php new file mode 100644 index 0000000..b6d454e --- /dev/null +++ b/app/console/service/VehicleNewTraitService.php @@ -0,0 +1,59 @@ + function ($params) { + // $keyword = $params['keyword'] ?? ''; + // return [ + // 'filters' => [ + // ['field' => '***', 'operator' => '=', 'value' => '***'] + // ], + // 'fields' => ['id'], + // 'relations' => [], + // 'custom' => function(Builder $q) use ($keyword) { + // // 示例 + // if ($keyword) { + // $q->where(function($q2) use($keyword) { + // $q2->whereHas('***', function($q3) use($keyword) { + // $q3->where('***', 'like', "%{$keyword}%"); + // })->orWhereHas('***', function($q4) use($keyword) { + // $q4->where('***', 'like', "%{$keyword}%"); + // }); + // }); + // } + // }, + // 'sorts' => [ + // ['field' => 'created_at', 'direction' => 'desc'] + // ], + // 'pagination' => [ + // 'page' => $params['page'] ?? 1, + // 'per_page' => $params['per_page'] ?? 10, + // ] + // ]; + // } + ]; + } +} \ No newline at end of file diff --git a/app/console/service/VehicleNewTraitTranslationService.php b/app/console/service/VehicleNewTraitTranslationService.php new file mode 100644 index 0000000..dd308cd --- /dev/null +++ b/app/console/service/VehicleNewTraitTranslationService.php @@ -0,0 +1,65 @@ + function ($params) { + // $keyword = $params['keyword'] ?? ''; + // return [ + // 'filters' => [ + // ['field' => '***', 'operator' => '=', 'value' => '***'] + // ], + // 'fields' => ['id'], + // 'relations' => [], + // 'custom' => function(Builder $q) use ($keyword) { + // // 示例 + // if ($keyword) { + // $q->where(function($q2) use($keyword) { + // $q2->whereHas('***', function($q3) use($keyword) { + // $q3->where('***', 'like', "%{$keyword}%"); + // })->orWhereHas('***', function($q4) use($keyword) { + // $q4->where('***', 'like', "%{$keyword}%"); + // }); + // }); + // } + // }, + // 'sorts' => [ + // ['field' => 'created_at', 'direction' => 'desc'] + // ], + // 'pagination' => [ + // 'page' => $params['page'] ?? 1, + // 'per_page' => $params['per_page'] ?? 10, + // ] + // ]; + // } + ]; + } + + // 声明需要多语言翻译 + protected array $translatable = [ + 'title', + 'content', + ]; +} \ No newline at end of file diff --git a/app/console/service/VehicleNewTranslationService.php b/app/console/service/VehicleNewTranslationService.php new file mode 100644 index 0000000..53150c0 --- /dev/null +++ b/app/console/service/VehicleNewTranslationService.php @@ -0,0 +1,59 @@ + function ($params) { + // $keyword = $params['keyword'] ?? ''; + // return [ + // 'filters' => [ + // ['field' => '***', 'operator' => '=', 'value' => '***'] + // ], + // 'fields' => ['id'], + // 'relations' => [], + // 'custom' => function(Builder $q) use ($keyword) { + // // 示例 + // if ($keyword) { + // $q->where(function($q2) use($keyword) { + // $q2->whereHas('***', function($q3) use($keyword) { + // $q3->where('***', 'like', "%{$keyword}%"); + // })->orWhereHas('***', function($q4) use($keyword) { + // $q4->where('***', 'like', "%{$keyword}%"); + // }); + // }); + // } + // }, + // 'sorts' => [ + // ['field' => 'created_at', 'direction' => 'desc'] + // ], + // 'pagination' => [ + // 'page' => $params['page'] ?? 1, + // 'per_page' => $params['per_page'] ?? 10, + // ] + // ]; + // } + ]; + } +} \ No newline at end of file diff --git a/app/console/validate/VehicleNewAlbumTranslationValidator.php b/app/console/validate/VehicleNewAlbumTranslationValidator.php new file mode 100644 index 0000000..8348092 --- /dev/null +++ b/app/console/validate/VehicleNewAlbumTranslationValidator.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/console/validate/VehicleNewAlbumValidator.php b/app/console/validate/VehicleNewAlbumValidator.php new file mode 100644 index 0000000..f07fed0 --- /dev/null +++ b/app/console/validate/VehicleNewAlbumValidator.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/console/validate/VehicleNewAskedTranslationValidator.php b/app/console/validate/VehicleNewAskedTranslationValidator.php new file mode 100644 index 0000000..1dc2221 --- /dev/null +++ b/app/console/validate/VehicleNewAskedTranslationValidator.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/console/validate/VehicleNewAskedValidator.php b/app/console/validate/VehicleNewAskedValidator.php new file mode 100644 index 0000000..ec7810c --- /dev/null +++ b/app/console/validate/VehicleNewAskedValidator.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/console/validate/VehicleNewContentTranslationValidator.php b/app/console/validate/VehicleNewContentTranslationValidator.php new file mode 100644 index 0000000..d2f3e31 --- /dev/null +++ b/app/console/validate/VehicleNewContentTranslationValidator.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/console/validate/VehicleNewContentValidator.php b/app/console/validate/VehicleNewContentValidator.php new file mode 100644 index 0000000..de6747c --- /dev/null +++ b/app/console/validate/VehicleNewContentValidator.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/console/validate/VehicleNewTraitTranslationValidator.php b/app/console/validate/VehicleNewTraitTranslationValidator.php new file mode 100644 index 0000000..fef61d8 --- /dev/null +++ b/app/console/validate/VehicleNewTraitTranslationValidator.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/console/validate/VehicleNewTraitValidator.php b/app/console/validate/VehicleNewTraitValidator.php new file mode 100644 index 0000000..cc94dea --- /dev/null +++ b/app/console/validate/VehicleNewTraitValidator.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/console/validate/VehicleNewTranslationValidator.php b/app/console/validate/VehicleNewTranslationValidator.php new file mode 100644 index 0000000..4e936a8 --- /dev/null +++ b/app/console/validate/VehicleNewTranslationValidator.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/console/validate/VehicleNewValidator.php b/app/console/validate/VehicleNewValidator.php new file mode 100644 index 0000000..ff81a86 --- /dev/null +++ b/app/console/validate/VehicleNewValidator.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/mzl/modules/translation/config/trans.php b/app/mzl/modules/translation/config/trans.php index 7c55644..751ccbc 100644 --- a/app/mzl/modules/translation/config/trans.php +++ b/app/mzl/modules/translation/config/trans.php @@ -38,7 +38,35 @@ return [ 'location' => [ 'translation_model' => \app\console\model\LocationTranslationModel::class, 'foreign_key' => 'location_id', - ] + ], + 'seo' => [ + 'translation_model' => \app\console\model\SeoInfoTranslationModel::class, + 'foreign_key' => 'seo_id', + ], + 'drafts' => [ + 'translation_model' => \app\applet\model\DraftsDataTranslationModel::class, + 'foreign_key' => 'drafts_id', + ], + 'vehicleNew' => [ + 'translation_model' => \app\console\model\VehicleNewTranslationModel::class, + 'foreign_key' => 'vehicle_id', + ], + 'vehicleNewAsked' => [ + 'translation_model' => \app\console\model\VehicleNewAskedTranslationModel::class, + 'foreign_key' => 'asked_id', + ], + 'vehicleNewTrait' => [ + 'translation_model' => \app\console\model\VehicleNewTraitTranslationModel::class, + 'foreign_key' => 'trait_id', + ], + 'vehicleNewAlbum' => [ + 'translation_model' => \app\console\model\VehicleNewAlbumTranslationModel::class, + 'foreign_key' => 'album_id', + ], + 'vehicleNewContent' => [ + 'translation_model' => \app\console\model\VehicleNewContentTranslationModel::class, + 'foreign_key' => 'content_id', + ], ], // 默认支持的目标语种列表 diff --git a/config/route.php b/config/route.php index df425a2..73cede1 100644 --- a/config/route.php +++ b/config/route.php @@ -168,6 +168,14 @@ Route::group('/console', function() { Route::any('/vehicle/data/{id}/delete', [\app\console\controller\VehicleDataController::class, 'destroy']); Route::any('/vehicle/data/{id}/detail', [\app\console\controller\VehicleDataController::class, 'detail']); + // 新车管理 + Route::any('/vehicle/new/list', [\app\console\controller\VehicleNewController::class, 'index']); + Route::any('/vehicle/new/add', [\app\console\controller\VehicleNewController::class, 'add']); +// Route::any('/vehicle/{id}/update', [\app\console\controller\VehicleNewController::class, 'edit']); +// Route::any('/vehicle/new/{id}/do', [\app\console\controller\VehicleNewController::class, 'doSaled']); +// Route::any('/vehicle/new/{id}/delete', [\app\console\controller\VehicleNewController::class, 'destroy']); +// Route::any('/vehicle/new/{id}/detail', [\app\console\controller\VehicleNewController::class, 'detail']); + // 上传 Route::any('/upload/image', [\app\mzl\modules\upload\controller\UploadController::class, 'uploadImage']); From d9423e9bce55941ee38fd85631924429fc33dd28 Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Thu, 22 May 2025 10:59:47 +0800 Subject: [PATCH 03/32] =?UTF-8?q?=E6=96=B0=E8=BD=A6=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E3=80=81=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/VehicleNewController.php | 64 +++++++++- app/console/model/VehicleNewAlbumModel.php | 6 +- app/console/model/VehicleNewModel.php | 3 + .../model/VehicleNewTranslationModel.php | 2 +- app/console/service/VehicleNewService.php | 110 ++++++++++++++++-- config/route.php | 7 +- 6 files changed, 178 insertions(+), 14 deletions(-) diff --git a/app/console/controller/VehicleNewController.php b/app/console/controller/VehicleNewController.php index 203ab2f..938b68d 100644 --- a/app/console/controller/VehicleNewController.php +++ b/app/console/controller/VehicleNewController.php @@ -41,7 +41,48 @@ class VehicleNewController extends BaseController { if ($scene === 'default') { - + $result = [ + 'id' => $item['id'], + 'vin' => $item['vin'], + 'brand' => $item['brand'], + 'price' => $item['price'], + 'cover' => $item['cover'], + 'energy' => $item['energy'], + 'type' => $item['type'], + 'model' => $item['model'], + 'video' => $item['video'], + 'name' => isset($item['translation']) ? $item['translation']['name'] : '', + 'condition_desc' => isset($item['translation']) ? $item['translation']['condition_desc'] : '', + 'created_at' => date('Y-m-d H:i:s', $item['created_at']), + 'updated_at' => date('Y-m-d H:i:s', $item['updated_at']), + ]; + foreach ($item['asked'] as $asked) { + $result['asked']['id'] = $asked['id']; + $result['asked']['vehicle_id'] = $asked['vehicle_id']; + $result['asked']['status'] = $asked['status']; + $result['asked']['title'] = isset($asked['translation']) ? $asked['translation']['title']:''; + $result['asked']['content'] = isset($asked['translation']) ? $asked['translation']['content']:''; + } + foreach ($item['trait'] as $trait) { + $result['trait']['id'] = $trait['id']; + $result['trait']['vehicle_id'] = $trait['vehicle_id']; + $result['trait']['status'] = $trait['status']; + $result['trait']['title'] = isset($trait['translation']) ? $trait['translation']['title']:''; + $result['trait']['content'] = isset($trait['translation']) ? $trait['translation']['content']:''; + } + foreach ($item['album'] as $album) { + $result['album']['id'] = $album['id']; + $result['album']['vehicle_id'] = $album['vehicle_id']; + $result['album']['status'] = $album['status']; + $result['album']['alt'] = isset($album['translation']) ? $album['translation']['alt']:''; + } + foreach ($item['content'] as $content) { + $result['content']['id'] = $content['id']; + $result['content']['vehicle_id'] = $content['vehicle_id']; + $result['content']['status'] = $content['status']; + $result['content']['content'] = isset($content['translation']) ? $content['translation']['content']:''; + } + return $result; } return $item; @@ -75,6 +116,17 @@ class VehicleNewController extends BaseController } } + public function edit(Request $request, int $id): Response + { + try { + return $this->getService()->edit($request->all(), $id) + ? $this->successResponse() + : $this->errorResponse(); + } catch (\Throwable $th) { + return $this->errorResponse($th->getMessage()); + } + } + /** * 分页 * @@ -85,6 +137,16 @@ class VehicleNewController extends BaseController { try { return parent::index($request, $scene); + } catch (\Throwable $th) { + return $this->errorResponse($th->getMessage().$th->getLine().$th->getFile()); + } + } + + public function detail(Request $request, int $id, string $scene = 'show'): Response + { + try { + $request->setGet(['id'=>$id]); + return parent::one($request, $scene); } catch (\Throwable $th) { return $this->errorResponse($th->getMessage()); } diff --git a/app/console/model/VehicleNewAlbumModel.php b/app/console/model/VehicleNewAlbumModel.php index ef88fee..f22adaf 100644 --- a/app/console/model/VehicleNewAlbumModel.php +++ b/app/console/model/VehicleNewAlbumModel.php @@ -47,7 +47,7 @@ class VehicleNewAlbumModel extends Model /** * 允许自动填充模型字段 */ - protected $fillable = ['id', 'vehicle_id', 'status', 'sort', 'created_at', 'updated_at']; + protected $fillable = ['id', 'vehicle_id', 'pic', 'status', 'sort', 'created_at', 'updated_at']; /** * 不允许自动填充模型字段 @@ -69,4 +69,8 @@ class VehicleNewAlbumModel extends Model { return $this->hasMany(VehicleNewAlbumTranslationModel::class, 'album_id'); } + + const TRANS_FIELDS = [ + 'alt', + ]; } \ No newline at end of file diff --git a/app/console/model/VehicleNewModel.php b/app/console/model/VehicleNewModel.php index 6706a0f..e40c992 100644 --- a/app/console/model/VehicleNewModel.php +++ b/app/console/model/VehicleNewModel.php @@ -54,6 +54,9 @@ class VehicleNewModel extends Model */ protected $guarded = []; + const TRANS_FIELDS = [ + 'name', 'condition_desc' + ]; /** * 单条翻译 diff --git a/app/console/model/VehicleNewTranslationModel.php b/app/console/model/VehicleNewTranslationModel.php index 0767a83..352ef1e 100644 --- a/app/console/model/VehicleNewTranslationModel.php +++ b/app/console/model/VehicleNewTranslationModel.php @@ -47,7 +47,7 @@ class VehicleNewTranslationModel extends Model /** * 允许自动填充模型字段 */ - protected $fillable = ['id', 'vehicle_id', 'locale', 'condition_desc', 'location', 'created_at', 'updated_at']; + protected $fillable = ['id', 'vehicle_id', 'locale', 'name', 'condition_desc', 'location', 'created_at', 'updated_at']; /** * 不允许自动填充模型字段 diff --git a/app/console/service/VehicleNewService.php b/app/console/service/VehicleNewService.php index bc7813f..e14486b 100644 --- a/app/console/service/VehicleNewService.php +++ b/app/console/service/VehicleNewService.php @@ -40,12 +40,39 @@ class VehicleNewService extends BaseService ], 'fields' => ['id', 'vin', 'brand', 'cover', 'price', 'type', 'energy', 'model', 'video', 'views', 'created_at', 'updated_at'], 'relations' => [ - 'translation' => ['vehicle_id', 'locale', 'condition_desc', 'location'], + 'translation' => ['vehicle_id', 'locale', 'name', 'condition_desc', 'location'], 'asked' => ['id', 'vehicle_id', 'status', 'sort'], 'asked.translation' => ['id', 'asked_id', 'locale', 'title', 'content'], 'trait' => ['id', 'vehicle_id', 'status', 'sort'], 'trait.translation' => ['id', 'trait_id', 'locale', 'title', 'content'], - 'album' => ['id', 'vehicle_id', 'status', 'sort'], + 'album' => ['id', 'vehicle_id', 'pic', 'status', 'sort'], + 'album.translation' => ['id', 'album_id', 'locale', 'alt'], + 'content' => ['id', 'vehicle_id', 'status', 'sort'], + 'content.translation' => ['id', 'content_id', 'locale', 'content'], + ], + 'sorts' => [ + ['field' => 'id', 'direction' => 'desc'] + ], + 'pagination' => [ + 'page' => $params['page'] ?? 1, + 'per_page' => $params['per_page'] ?? 10, + ] + ]; + }, + 'show' => function ($params) { + $keyword = $params['keyword'] ?? ''; + return [ + 'filters' => [ +// ['field' => '***', 'operator' => '=', 'value' => '***'] + ], + 'fields' => ['id', 'vin', 'brand', 'cover', 'price', 'type', 'energy', 'model', 'video', 'views', 'created_at', 'updated_at'], + 'relations' => [ + 'translation' => ['vehicle_id', 'locale', 'name', 'condition_desc', 'location'], + 'asked' => ['id', 'vehicle_id', 'status', 'sort'], + 'asked.translation' => ['id', 'asked_id', 'locale', 'title', 'content'], + 'trait' => ['id', 'vehicle_id', 'status', 'sort'], + 'trait.translation' => ['id', 'trait_id', 'locale', 'title', 'content'], + 'album' => ['id', 'vehicle_id', 'pic', 'status', 'sort'], 'album.translation' => ['id', 'album_id', 'locale', 'alt'], 'content' => ['id', 'vehicle_id', 'status', 'sort'], 'content.translation' => ['id', 'content_id', 'locale', 'content'], @@ -65,7 +92,7 @@ class VehicleNewService extends BaseService // 声明需要多语言翻译 protected array $translatable = [ - 'condition_desc', + 'condition_desc','name', ]; public function add(array $params) @@ -141,14 +168,13 @@ class VehicleNewService extends BaseService foreach ($albums as $album) { $albumsourceFields = $VehicleNewAlbumService->extractSourceFields($album); $album['vehicle_id'] = $info->id; - $trait_res = $VehicleNewAlbumService->create($trait); + $album_res = $VehicleNewAlbumService->create($album); if (!$trait_res) { throw new BusinessException('提交失败'); } - (new TranslationService())->queueTranslations( - 'vehicleNewTrait', - $trait_res->id, + 'vehicleNewAlbum', + $album_res->id, $sourceLocale, $albumsourceFields ); @@ -177,4 +203,74 @@ class VehicleNewService extends BaseService throw $th; } } + + + public function edit(array $params, int $id) + { + $sourceLocale = locale(); + $sourceFields = $this->extractSourceFields($params); + if (empty($sourceFields)) { + throw new \InvalidArgumentException("请传递至少一条 {$sourceLocale} 语言的翻译字段"); + }; + + $album = []; + $trans = []; + $albums = VehicleNewAlbumModel::VEHICLE_New_ALBUM_FIELDS; + foreach ($params as $ko => $vo) { + if (in_array($ko, $albums)) { + $album[$ko] = $vo ?? ''; + } elseif (in_array($ko, VehicleNewModel::TRANS_FIELDS)) { + $trans[$ko] = $vo ?? ''; + }else{ + $data[$ko] = $vo ?? ''; + } + } + + Db::beginTransaction(); + try { + $info = $this->update($id, $params); + if (!$info) { + throw new BusinessException('提交失败'); + } + + // 异步翻译并写入 hs_vehicle_data_translation 表 + (new TranslationService())->queueTranslations( + 'vehicle', + $id, + $sourceLocale, + $sourceFields + ); + + if ($album) { + // $album['vehicle_data_id'] = $info->id; + $albumModel = new VehicleAlbumModel(); + if (!$albumModel->updateOrCreate( + ['vehicle_data_id' => $id], + $album + )) { + throw new BusinessException('提交失败'); + } + } + + // $applyModel = new VehicleApplyModel(); + // if (!$applyModel->create([ + // 'vehicle_data_id' => $info->id, + // 'desc' => '提交审核' + // ])) { + // throw new BusinessException('提交失败'); + // } + + // if (isset($params['draft_id']) && $params['draft_id']) { + // if (!DraftsModel::where('id', $params['draft_id'])->delete()) { + // throw new BusinessException('草稿移除失败'); + // } + // } + + Db::commit(); + return true; + } catch (\Throwable $th) { + Db::rollBack(); + throw $th; + } + } } \ No newline at end of file diff --git a/config/route.php b/config/route.php index 73cede1..0d73447 100644 --- a/config/route.php +++ b/config/route.php @@ -171,10 +171,9 @@ Route::group('/console', function() { // 新车管理 Route::any('/vehicle/new/list', [\app\console\controller\VehicleNewController::class, 'index']); Route::any('/vehicle/new/add', [\app\console\controller\VehicleNewController::class, 'add']); -// Route::any('/vehicle/{id}/update', [\app\console\controller\VehicleNewController::class, 'edit']); -// Route::any('/vehicle/new/{id}/do', [\app\console\controller\VehicleNewController::class, 'doSaled']); -// Route::any('/vehicle/new/{id}/delete', [\app\console\controller\VehicleNewController::class, 'destroy']); -// Route::any('/vehicle/new/{id}/detail', [\app\console\controller\VehicleNewController::class, 'detail']); + Route::any('/vehicle/{id}/update', [\app\console\controller\VehicleNewController::class, 'edit']); + Route::any('/vehicle/new/{id}/delete', [\app\console\controller\VehicleNewController::class, 'destroy']); + Route::any('/vehicle/new/{id}/detail', [\app\console\controller\VehicleNewController::class, 'detail']); // 上传 Route::any('/upload/image', [\app\mzl\modules\upload\controller\UploadController::class, 'uploadImage']); From 1c0d5d58823ee9f94f28864c7959ee51231cb1a0 Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Thu, 22 May 2025 11:09:56 +0800 Subject: [PATCH 04/32] =?UTF-8?q?=E6=96=B0=E8=BD=A6=E4=BF=AE=E6=94=B9url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/route.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/route.php b/config/route.php index 0d73447..70021f3 100644 --- a/config/route.php +++ b/config/route.php @@ -41,7 +41,7 @@ Route::group('/apis', function() { // 隐私协议 Route::any('/agt/privacy', [\app\apis\controller\AgreementController::class, 'one']); // 品牌按字母查询 - Route::any('/brand/letterAll', [\app\apis\controller\BrandController::class, 'letterAll']); +// Route::any('/brand/letterAll', [\app\apis\controller\BrandController::class, 'letterAll']); }); // ====== ====== ====== 网站 ====== ====== ====== @@ -171,7 +171,7 @@ Route::group('/console', function() { // 新车管理 Route::any('/vehicle/new/list', [\app\console\controller\VehicleNewController::class, 'index']); Route::any('/vehicle/new/add', [\app\console\controller\VehicleNewController::class, 'add']); - Route::any('/vehicle/{id}/update', [\app\console\controller\VehicleNewController::class, 'edit']); + Route::any('/vehicle/new/{id}/update', [\app\console\controller\VehicleNewController::class, 'edit']); Route::any('/vehicle/new/{id}/delete', [\app\console\controller\VehicleNewController::class, 'destroy']); Route::any('/vehicle/new/{id}/detail', [\app\console\controller\VehicleNewController::class, 'detail']); From 9c82aa5265d3bd9c71777edf85063b3e611fef62 Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Thu, 22 May 2025 14:38:48 +0800 Subject: [PATCH 05/32] =?UTF-8?q?=E6=96=B0=E8=BD=A6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/VehicleNewController.php | 59 +++-- .../service/VehicleNewContentService.php | 5 + app/console/service/VehicleNewService.php | 202 +++++++++++++++--- 3 files changed, 222 insertions(+), 44 deletions(-) diff --git a/app/console/controller/VehicleNewController.php b/app/console/controller/VehicleNewController.php index 938b68d..4a09ab5 100644 --- a/app/console/controller/VehicleNewController.php +++ b/app/console/controller/VehicleNewController.php @@ -40,7 +40,7 @@ class VehicleNewController extends BaseController protected function postProcessItem(array $item, string $scene): array { - if ($scene === 'default') { + if ($scene === 'default' || $scene === 'show') { $result = [ 'id' => $item['id'], 'vin' => $item['vin'], @@ -55,32 +55,53 @@ class VehicleNewController extends BaseController 'condition_desc' => isset($item['translation']) ? $item['translation']['condition_desc'] : '', 'created_at' => date('Y-m-d H:i:s', $item['created_at']), 'updated_at' => date('Y-m-d H:i:s', $item['updated_at']), + + 'brand_name' => is_array($item['brand']) ? $item['brand']['translation']['name'] : '', + 'energy_name' => is_array($item['energy']) ? $item['energy']['translation']['name'] : '', + 'type_name' => isset($item['types']) ? $item['types']['translation']['name'] : '', + 'model_name' => isset($item['models']) ? $item['models']['translation']['name'] : '', ]; + if ($item['cover']) { + $result['cover_full'] = (new \app\mzl\modules\upload\service\OssService())->generatePrivateUrl($item['cover']); + } + if ($item['video']) { + $result['video_full'] = (new \app\mzl\modules\upload\service\OssService())->generatePrivateUrl($item['video']); + } foreach ($item['asked'] as $asked) { - $result['asked']['id'] = $asked['id']; - $result['asked']['vehicle_id'] = $asked['vehicle_id']; - $result['asked']['status'] = $asked['status']; - $result['asked']['title'] = isset($asked['translation']) ? $asked['translation']['title']:''; - $result['asked']['content'] = isset($asked['translation']) ? $asked['translation']['content']:''; + $askedRes['id'] = $asked['id']; + $askedRes['vehicle_id'] = $asked['vehicle_id']; + $askedRes['status'] = $asked['status']; + $askedRes['title'] = isset($asked['translation']) ? $asked['translation']['title']:''; + $askedRes['content'] = isset($asked['translation']) ? $asked['translation']['content']:''; + $result['asked'][] = $askedRes; } foreach ($item['trait'] as $trait) { - $result['trait']['id'] = $trait['id']; - $result['trait']['vehicle_id'] = $trait['vehicle_id']; - $result['trait']['status'] = $trait['status']; - $result['trait']['title'] = isset($trait['translation']) ? $trait['translation']['title']:''; - $result['trait']['content'] = isset($trait['translation']) ? $trait['translation']['content']:''; + $traitRes['id'] = $trait['id']; + $traitRes['vehicle_id'] = $trait['vehicle_id']; + $traitRes['status'] = $trait['status']; + $traitRes['title'] = isset($trait['translation']) ? $trait['translation']['title']:''; + $traitRes['content'] = isset($trait['translation']) ? $trait['translation']['content']:''; + $result['trait'][] = $traitRes; } foreach ($item['album'] as $album) { - $result['album']['id'] = $album['id']; - $result['album']['vehicle_id'] = $album['vehicle_id']; - $result['album']['status'] = $album['status']; - $result['album']['alt'] = isset($album['translation']) ? $album['translation']['alt']:''; + $albumRes['id'] = $album['id']; + $albumRes['vehicle_id'] = $album['vehicle_id']; + $albumRes['pic'] = $album['pic']; + $albumRes['status'] = $album['status']; + $albumRes['alt'] = isset($album['translation']) ? $album['translation']['alt']:''; + + if ($albumRes['pic']) { + $albumRes['pic_full'] = (new \app\mzl\modules\upload\service\OssService())->generatePrivateUrl($albumRes['pic']); + } + + $result['album'][] = $albumRes; } foreach ($item['content'] as $content) { - $result['content']['id'] = $content['id']; - $result['content']['vehicle_id'] = $content['vehicle_id']; - $result['content']['status'] = $content['status']; - $result['content']['content'] = isset($content['translation']) ? $content['translation']['content']:''; + $contentRes['id'] = $content['id']; + $contentRes['vehicle_id'] = $content['vehicle_id']; + $contentRes['status'] = $content['status']; + $contentRes['content'] = isset($content['translation']) ? $content['translation']['content']:''; + $result['content'][] = $contentRes; } return $result; } diff --git a/app/console/service/VehicleNewContentService.php b/app/console/service/VehicleNewContentService.php index cc9795d..3d95f2b 100644 --- a/app/console/service/VehicleNewContentService.php +++ b/app/console/service/VehicleNewContentService.php @@ -56,4 +56,9 @@ class VehicleNewContentService extends BaseService // } ]; } + + // 声明需要多语言翻译 + protected array $translatable = [ + 'content', + ]; } \ No newline at end of file diff --git a/app/console/service/VehicleNewService.php b/app/console/service/VehicleNewService.php index e14486b..e662fb1 100644 --- a/app/console/service/VehicleNewService.php +++ b/app/console/service/VehicleNewService.php @@ -50,6 +50,10 @@ class VehicleNewService extends BaseService 'content' => ['id', 'vehicle_id', 'status', 'sort'], 'content.translation' => ['id', 'content_id', 'locale', 'content'], ], + 'brand.translation' => ['brand_id', 'name'], + 'types.translation' => ['type_id', 'name'], + 'energy.translation' => ['energy_id', 'name'], + 'models.translation' => ['model_id', 'name'], 'sorts' => [ ['field' => 'id', 'direction' => 'desc'] ], @@ -77,6 +81,10 @@ class VehicleNewService extends BaseService 'content' => ['id', 'vehicle_id', 'status', 'sort'], 'content.translation' => ['id', 'content_id', 'locale', 'content'], ], + 'brand.translation' => ['brand_id', 'name'], + 'types.translation' => ['type_id', 'name'], + 'energy.translation' => ['energy_id', 'name'], + 'models.translation' => ['model_id', 'name'], 'sorts' => [ ['field' => 'id', 'direction' => 'desc'] ], @@ -169,7 +177,7 @@ class VehicleNewService extends BaseService $albumsourceFields = $VehicleNewAlbumService->extractSourceFields($album); $album['vehicle_id'] = $info->id; $album_res = $VehicleNewAlbumService->create($album); - if (!$trait_res) { + if (!$album_res) { throw new BusinessException('提交失败'); } (new TranslationService())->queueTranslations( @@ -183,14 +191,14 @@ class VehicleNewService extends BaseService foreach ($contents as $content) { $contentsourceFields = $VehicleNewContentService->extractSourceFields($content); $content['vehicle_id'] = $info->id; - $trait_res = $VehicleNewContentService->create($content); - if (!$trait_res) { + $content_res = $VehicleNewContentService->create($content); + if (!$content_res) { throw new BusinessException('提交失败'); } (new TranslationService())->queueTranslations( 'vehicleNewContent', - $trait_res->id, + $content_res->id, $sourceLocale, $contentsourceFields ); @@ -213,18 +221,35 @@ class VehicleNewService extends BaseService throw new \InvalidArgumentException("请传递至少一条 {$sourceLocale} 语言的翻译字段"); }; - $album = []; - $trans = []; - $albums = VehicleNewAlbumModel::VEHICLE_New_ALBUM_FIELDS; - foreach ($params as $ko => $vo) { - if (in_array($ko, $albums)) { - $album[$ko] = $vo ?? ''; - } elseif (in_array($ko, VehicleNewModel::TRANS_FIELDS)) { - $trans[$ko] = $vo ?? ''; - }else{ - $data[$ko] = $vo ?? ''; - } - } + $askeds = $params['asked']; + unset($params['asked']); + $traits = $params['trait']; + unset($params['trait']); + $albums = $params['album']; + unset($params['album']); + $contents = $params['content']; + unset($params['content']); + $VehicleNewAskedService = new VehicleNewAskedService(new VehicleNewAskedModel()); + $VehicleNewTraitService = new VehicleNewTraitService(new VehicleNewTraitModel()); + $VehicleNewAlbumService = new VehicleNewAlbumService(new VehicleNewAlbumModel()); + $VehicleNewContentService = new VehicleNewContentService(new VehicleNewContentModel()); +// foreach ($params as $ko => $vo) { +// if (in_array($ko, $albums)) { +// $album[$ko] = $vo ?? ''; +// } elseif (in_array($ko, $albums)) { +// $album[$ko] = $vo ?? ''; +// } elseif (in_array($ko, $albums)) { +// $album[$ko] = $vo ?? ''; +// } elseif (in_array($ko, $albums)) { +// $album[$ko] = $vo ?? ''; +// } elseif (in_array($ko, $albums)) { +// $album[$ko] = $vo ?? ''; +// } elseif (in_array($ko, VehicleNewModel::TRANS_FIELDS)) { +// $trans[$ko] = $vo ?? ''; +// }else{ +// $data[$ko] = $vo ?? ''; +// } +// } Db::beginTransaction(); try { @@ -235,22 +260,149 @@ class VehicleNewService extends BaseService // 异步翻译并写入 hs_vehicle_data_translation 表 (new TranslationService())->queueTranslations( - 'vehicle', + 'vehicleNew', $id, $sourceLocale, $sourceFields ); - if ($album) { - // $album['vehicle_data_id'] = $info->id; - $albumModel = new VehicleAlbumModel(); - if (!$albumModel->updateOrCreate( - ['vehicle_data_id' => $id], - $album - )) { - throw new BusinessException('提交失败'); + foreach ($askeds as $asked) { + $askedsourceFields = $VehicleNewAskedService->extractSourceFields($asked); + $asked['vehicle_id'] = $id; + $askedsId = []; + if(!empty($asked['id'])){ + $askedId = $asked['id']; + $askedsId[] = $askedId; + $asked_res = $VehicleNewAskedService->update($askedId, $asked); + if (!$asked_res) { + throw new BusinessException('提交失败:常见问题'); + } + } else { + $asked_res = $VehicleNewAskedService->create($asked); + if (!$asked_res) { + throw new BusinessException('提交失败:常见问题'); + } + $askedId = $asked_res->id; + $askedsId[] = $askedId; } + (new TranslationService())->queueTranslations( + 'vehicleNewAsked', + $askedId, + $sourceLocale, + $askedsourceFields + ); } + VehicleNewAskedModel::whereNotIn('id', $askedsId)->where('vehicle_id',$id)->delete(); + + foreach ($traits as $trait) { + $traitsourceFields = $VehicleNewTraitService->extractSourceFields($trait); + $trait['vehicle_id'] = $id; + $traitsId = []; + if(!empty($trait['id'])){ + $traitId = $trait['id']; + $traitsId[] = $traitId; + $trait_res = $VehicleNewAskedService->update($traitId, $trait); + if (!$trait_res) { + throw new BusinessException('提交失败:车辆特性'); + } + } else { + $trait_res = $VehicleNewAskedService->create($trait); + if (!$trait_res) { + throw new BusinessException('提交失败:车辆特性'); + } + $traitId = $trait_res->id; + $traitsId[] = $traitId; + } + (new TranslationService())->queueTranslations( + 'vehicleNewTrait', + $traitId, + $sourceLocale, + $traitsourceFields + ); + } + VehicleNewTraitModel::whereNotIn('id', $traitsId)->where('vehicle_id',$id)->delete(); + + foreach ($albums as $album) { + $albumsourceFields = $VehicleNewAlbumService->extractSourceFields($album); + $album['vehicle_id'] = $id; +// $albumId = $album['id']; +// $album_res = $VehicleNewAskedService->update($albumId, $album); +// if (!$album_res) { +// throw new BusinessException('提交失败'); +// } + + $albumsId = []; +// var_dump(!empty($album['id'])); + $album['vehicle_id'] = 78; + if(!empty($album['id'])){ + $albumId =$album['id']; + $albumsId[] =$albumId; + $album_res = $VehicleNewAlbumService->update($albumId,$album); + if (!$album_res) { + throw new BusinessException('提交失败:车辆图册'); + } + } else { + $album_res = $VehicleNewAlbumService->create($album); + if (!$album_res) { + throw new BusinessException('提交失败:车辆图册1'); + } + $albumId = $album_res->id; + $albumsId[] = $albumId; + } + + (new TranslationService())->queueTranslations( + 'VehicleNewAlbum', + $albumId, + $sourceLocale, + $albumsourceFields + ); + } + + foreach ($contents as $content) { + $contentsourceFields = $VehicleNewContentService->extractSourceFields($content); + $content['vehicle_id'] = $id; +// $contentId = $content['id']; +// $trait_res = $VehicleNewContentService->update($contentId, $content); +// if (!$trait_res) { +// throw new BusinessException('提交失败'); +// } + + $contentsId = []; + if(!empty($content['id'])){ + $contentId =$content['id']; + $contentsId[] =$contentId; + $content['vehicle_id'] = 78; + $content_res = $VehicleNewContentService->update($contentId,$content); + if (!$content_res) { + throw new BusinessException('提交失败:车辆介绍1'); + } + } else { + $content_res = $VehicleNewAskedService->create($content); + if (!$content_res) { + throw new BusinessException('提交失败:车辆介绍'); + } + $contentId = $content_res->id; + $contentsId[] = $contentId; + } + + (new TranslationService())->queueTranslations( + 'vehicleNewContent', + $contentId, + $sourceLocale, + $contentsourceFields + ); + } + VehicleNewContentModel::whereNotIn('id', $contentsId)->where('vehicle_id',$id)->delete(); +// if ($album) { +// // $album['vehicle_data_id'] = $info->id; +// $albumModel = new VehicleAlbumModel(); +// if (!$albumModel->updateOrCreate( +// ['vehicle_data_id' => $id], +// $album +// )) { +// throw new BusinessException('提交失败'); +// } +// } // $applyModel = new VehicleApplyModel(); // if (!$applyModel->create([ From 246929ca6b88e4e0798b1c0412406ed4856d83cd Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Thu, 22 May 2025 14:52:24 +0800 Subject: [PATCH 06/32] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/console/service/VehicleNewService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/console/service/VehicleNewService.php b/app/console/service/VehicleNewService.php index e662fb1..0e8a9fc 100644 --- a/app/console/service/VehicleNewService.php +++ b/app/console/service/VehicleNewService.php @@ -67,7 +67,7 @@ class VehicleNewService extends BaseService $keyword = $params['keyword'] ?? ''; return [ 'filters' => [ -// ['field' => '***', 'operator' => '=', 'value' => '***'] + ['field'=>'id', 'operator'=>'=', 'value'=> $params['id']], ], 'fields' => ['id', 'vin', 'brand', 'cover', 'price', 'type', 'energy', 'model', 'video', 'views', 'created_at', 'updated_at'], 'relations' => [ From 9405c96677b88fe16bc6f389c2230292522b2044 Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Thu, 22 May 2025 17:02:26 +0800 Subject: [PATCH 07/32] =?UTF-8?q?=E5=A3=B0=E6=98=8E=E7=BF=BB=E8=AF=91?= =?UTF-8?q?=E7=9A=84=E5=A4=9A=E8=AF=AD=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/console/model/BrandBannerTranslationModel.php | 2 +- app/console/service/VehicleNewTraitService.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/console/model/BrandBannerTranslationModel.php b/app/console/model/BrandBannerTranslationModel.php index 889e01f..00df108 100644 --- a/app/console/model/BrandBannerTranslationModel.php +++ b/app/console/model/BrandBannerTranslationModel.php @@ -47,7 +47,7 @@ class BrandBannerTranslationModel extends Model /** * 允许自动填充模型字段 */ - protected $fillable = ['id', 'brand_id', 'banner_id', 'alt', 'created_at', 'updated_at']; + protected $fillable = ['id', 'brand_id', 'banner_id', 'alt', 'locale', 'created_at', 'updated_at']; /** * 不允许自动填充模型字段 diff --git a/app/console/service/VehicleNewTraitService.php b/app/console/service/VehicleNewTraitService.php index b6d454e..46b38c2 100644 --- a/app/console/service/VehicleNewTraitService.php +++ b/app/console/service/VehicleNewTraitService.php @@ -56,4 +56,10 @@ class VehicleNewTraitService extends BaseService // } ]; } + + // 声明需要多语言翻译 + protected array $translatable = [ + 'title', + 'content', + ]; } \ No newline at end of file From 5c37dd24d5807845212f7ccccc83c008f029eb87 Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Thu, 22 May 2025 17:08:42 +0800 Subject: [PATCH 08/32] =?UTF-8?q?=E5=85=BC=E5=AE=B9=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=97=B6=E7=9A=84id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/console/service/VehicleNewService.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/console/service/VehicleNewService.php b/app/console/service/VehicleNewService.php index 0e8a9fc..d377df2 100644 --- a/app/console/service/VehicleNewService.php +++ b/app/console/service/VehicleNewService.php @@ -278,6 +278,7 @@ class VehicleNewService extends BaseService throw new BusinessException('提交失败:常见问题'); } } else { + unset($asked['id']); $asked_res = $VehicleNewAskedService->create($asked); if (!$asked_res) { throw new BusinessException('提交失败:常见问题'); @@ -306,6 +307,7 @@ class VehicleNewService extends BaseService throw new BusinessException('提交失败:车辆特性'); } } else { + unset($trait['id']); $trait_res = $VehicleNewAskedService->create($trait); if (!$trait_res) { throw new BusinessException('提交失败:车辆特性'); @@ -332,8 +334,6 @@ class VehicleNewService extends BaseService // } $albumsId = []; -// var_dump(!empty($album['id'])); - $album['vehicle_id'] = 78; if(!empty($album['id'])){ $albumId =$album['id']; $albumsId[] =$albumId; @@ -342,6 +342,7 @@ class VehicleNewService extends BaseService throw new BusinessException('提交失败:车辆图册'); } } else { + unset($album['id']); $album_res = $VehicleNewAlbumService->create($album); if (!$album_res) { throw new BusinessException('提交失败:车辆图册1'); @@ -371,12 +372,12 @@ class VehicleNewService extends BaseService if(!empty($content['id'])){ $contentId =$content['id']; $contentsId[] =$contentId; - $content['vehicle_id'] = 78; $content_res = $VehicleNewContentService->update($contentId,$content); if (!$content_res) { throw new BusinessException('提交失败:车辆介绍1'); } } else { + unset($content['id']); $content_res = $VehicleNewAskedService->create($content); if (!$content_res) { throw new BusinessException('提交失败:车辆介绍'); From 6acef72d2226b0c4ffa54e680af92cf027cd9262 Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Thu, 22 May 2025 17:45:02 +0800 Subject: [PATCH 09/32] =?UTF-8?q?=E8=BD=A6=E8=BE=86=E7=89=B9=E6=80=A7?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/console/service/VehicleNewService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/console/service/VehicleNewService.php b/app/console/service/VehicleNewService.php index d377df2..e1a1787 100644 --- a/app/console/service/VehicleNewService.php +++ b/app/console/service/VehicleNewService.php @@ -302,13 +302,13 @@ class VehicleNewService extends BaseService if(!empty($trait['id'])){ $traitId = $trait['id']; $traitsId[] = $traitId; - $trait_res = $VehicleNewAskedService->update($traitId, $trait); + $trait_res = $VehicleNewTraitService->update($traitId, $trait); if (!$trait_res) { throw new BusinessException('提交失败:车辆特性'); } } else { unset($trait['id']); - $trait_res = $VehicleNewAskedService->create($trait); + $trait_res = $VehicleNewTraitService->create($trait); if (!$trait_res) { throw new BusinessException('提交失败:车辆特性'); } From 6597ea3a43df1198608b877de001cbd9dc1b2fb6 Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Fri, 23 May 2025 08:52:37 +0800 Subject: [PATCH 10/32] =?UTF-8?q?=E5=93=81=E7=89=8C=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/VehicleNewController.php | 8 +++---- app/console/service/VehicleNewService.php | 21 ++++++++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/app/console/controller/VehicleNewController.php b/app/console/controller/VehicleNewController.php index 4a09ab5..bcaecd5 100644 --- a/app/console/controller/VehicleNewController.php +++ b/app/console/controller/VehicleNewController.php @@ -44,12 +44,12 @@ class VehicleNewController extends BaseController $result = [ 'id' => $item['id'], 'vin' => $item['vin'], - 'brand' => $item['brand'], 'price' => $item['price'], 'cover' => $item['cover'], - 'energy' => $item['energy'], - 'type' => $item['type'], - 'model' => $item['model'], + 'brand' => is_array($item['brand']) ? $item['brand']['translation']['brand_id'] : $item['brand'], + 'energy' => is_array($item['energy']) ? $item['energy']['translation']['energy_id'] : $item['energy'], + 'type' => isset($item['types']) ? $item['types']['translation']['type_id'] : $item['type'], + 'model' => isset($item['models']) ? $item['models']['translation']['model_id'] : $item['model'], 'video' => $item['video'], 'name' => isset($item['translation']) ? $item['translation']['name'] : '', 'condition_desc' => isset($item['translation']) ? $item['translation']['condition_desc'] : '', diff --git a/app/console/service/VehicleNewService.php b/app/console/service/VehicleNewService.php index e1a1787..489f551 100644 --- a/app/console/service/VehicleNewService.php +++ b/app/console/service/VehicleNewService.php @@ -49,11 +49,11 @@ class VehicleNewService extends BaseService 'album.translation' => ['id', 'album_id', 'locale', 'alt'], 'content' => ['id', 'vehicle_id', 'status', 'sort'], 'content.translation' => ['id', 'content_id', 'locale', 'content'], + 'brand.translation' => ['brand_id', 'name'], + 'types.translation' => ['type_id', 'name'], + 'energy.translation' => ['energy_id', 'name'], + 'models.translation' => ['model_id', 'name'], ], - 'brand.translation' => ['brand_id', 'name'], - 'types.translation' => ['type_id', 'name'], - 'energy.translation' => ['energy_id', 'name'], - 'models.translation' => ['model_id', 'name'], 'sorts' => [ ['field' => 'id', 'direction' => 'desc'] ], @@ -266,22 +266,22 @@ class VehicleNewService extends BaseService $sourceFields ); + $askedsId = []; foreach ($askeds as $asked) { $askedsourceFields = $VehicleNewAskedService->extractSourceFields($asked); $asked['vehicle_id'] = $id; - $askedsId = []; if(!empty($asked['id'])){ $askedId = $asked['id']; $askedsId[] = $askedId; $asked_res = $VehicleNewAskedService->update($askedId, $asked); if (!$asked_res) { - throw new BusinessException('提交失败:常见问题'); + throw new BusinessException('提交失败:常见问题2'); } } else { unset($asked['id']); $asked_res = $VehicleNewAskedService->create($asked); if (!$asked_res) { - throw new BusinessException('提交失败:常见问题'); + throw new BusinessException('提交失败:常见问题1'); } $askedId = $asked_res->id; $askedsId[] = $askedId; @@ -295,10 +295,10 @@ class VehicleNewService extends BaseService } VehicleNewAskedModel::whereNotIn('id', $askedsId)->where('vehicle_id',$id)->delete(); + $traitsId = []; foreach ($traits as $trait) { $traitsourceFields = $VehicleNewTraitService->extractSourceFields($trait); $trait['vehicle_id'] = $id; - $traitsId = []; if(!empty($trait['id'])){ $traitId = $trait['id']; $traitsId[] = $traitId; @@ -324,6 +324,7 @@ class VehicleNewService extends BaseService } VehicleNewTraitModel::whereNotIn('id', $traitsId)->where('vehicle_id',$id)->delete(); + $albumsId = []; foreach ($albums as $album) { $albumsourceFields = $VehicleNewAlbumService->extractSourceFields($album); $album['vehicle_id'] = $id; @@ -333,7 +334,6 @@ class VehicleNewService extends BaseService // throw new BusinessException('提交失败'); // } - $albumsId = []; if(!empty($album['id'])){ $albumId =$album['id']; $albumsId[] =$albumId; @@ -358,7 +358,9 @@ class VehicleNewService extends BaseService $albumsourceFields ); } + VehicleNewAlbumModel::whereNotIn('id', $traitsId)->where('vehicle_id',$id)->delete(); + $contentsId = []; foreach ($contents as $content) { $contentsourceFields = $VehicleNewContentService->extractSourceFields($content); $content['vehicle_id'] = $id; @@ -368,7 +370,6 @@ class VehicleNewService extends BaseService // throw new BusinessException('提交失败'); // } - $contentsId = []; if(!empty($content['id'])){ $contentId =$content['id']; $contentsId[] =$contentId; From f8dc8a24e6250ca5f270a2bd0f123b49cd35dddd Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Fri, 23 May 2025 09:34:06 +0800 Subject: [PATCH 11/32] =?UTF-8?q?=E6=96=B0=E8=BD=A6=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/console/service/VehicleNewService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/console/service/VehicleNewService.php b/app/console/service/VehicleNewService.php index 489f551..a52f027 100644 --- a/app/console/service/VehicleNewService.php +++ b/app/console/service/VehicleNewService.php @@ -358,7 +358,7 @@ class VehicleNewService extends BaseService $albumsourceFields ); } - VehicleNewAlbumModel::whereNotIn('id', $traitsId)->where('vehicle_id',$id)->delete(); + VehicleNewAlbumModel::whereNotIn('id', $albumsId)->where('vehicle_id',$id)->delete(); $contentsId = []; foreach ($contents as $content) { @@ -379,7 +379,7 @@ class VehicleNewService extends BaseService } } else { unset($content['id']); - $content_res = $VehicleNewAskedService->create($content); + $content_res = $VehicleNewContentService->create($content); if (!$content_res) { throw new BusinessException('提交失败:车辆介绍'); } From 9592c2c7596b5f90f647e3a59345baf558c4cacb Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Fri, 23 May 2025 09:42:30 +0800 Subject: [PATCH 12/32] =?UTF-8?q?=E8=BD=A6=E8=BE=86=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/console/service/VehicleNewService.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/console/service/VehicleNewService.php b/app/console/service/VehicleNewService.php index a52f027..076225d 100644 --- a/app/console/service/VehicleNewService.php +++ b/app/console/service/VehicleNewService.php @@ -80,11 +80,11 @@ class VehicleNewService extends BaseService 'album.translation' => ['id', 'album_id', 'locale', 'alt'], 'content' => ['id', 'vehicle_id', 'status', 'sort'], 'content.translation' => ['id', 'content_id', 'locale', 'content'], + 'brand.translation' => ['brand_id', 'name'], + 'types.translation' => ['type_id', 'name'], + 'energy.translation' => ['energy_id', 'name'], + 'models.translation' => ['model_id', 'name'], ], - 'brand.translation' => ['brand_id', 'name'], - 'types.translation' => ['type_id', 'name'], - 'energy.translation' => ['energy_id', 'name'], - 'models.translation' => ['model_id', 'name'], 'sorts' => [ ['field' => 'id', 'direction' => 'desc'] ], From 23e9531badb7e30d185359fef6aed5188ea4ee19 Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Fri, 23 May 2025 10:28:59 +0800 Subject: [PATCH 13/32] =?UTF-8?q?=E6=96=B0=E8=BD=A6=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/VehicleNewAlbumController.php | 81 +++++++++ .../VehicleNewAlbumTranslationController.php | 81 +++++++++ .../controller/VehicleNewAskedController.php | 81 +++++++++ .../VehicleNewAskedTranslationController.php | 81 +++++++++ .../VehicleNewContentController.php | 81 +++++++++ ...VehicleNewContentTranslationController.php | 81 +++++++++ app/apis/controller/VehicleNewController.php | 154 ++++++++++++++++++ .../controller/VehicleNewTraitController.php | 81 +++++++++ .../VehicleNewTraitTranslationController.php | 81 +++++++++ .../VehicleNewTranslationController.php | 81 +++++++++ app/apis/model/VehicleNewAlbumModel.php | 76 +++++++++ .../model/VehicleNewAlbumTranslationModel.php | 56 +++++++ app/apis/model/VehicleNewAskedModel.php | 80 +++++++++ .../model/VehicleNewAskedTranslationModel.php | 56 +++++++ app/apis/model/VehicleNewContentModel.php | 73 +++++++++ .../VehicleNewContentTranslationModel.php | 56 +++++++ app/apis/model/VehicleNewModel.php | 121 ++++++++++++++ app/apis/model/VehicleNewTraitModel.php | 72 ++++++++ .../model/VehicleNewTraitTranslationModel.php | 56 +++++++ app/apis/model/VehicleNewTranslationModel.php | 56 +++++++ app/apis/service/VehicleNewAlbumService.php | 59 +++++++ .../VehicleNewAlbumTranslationService.php | 59 +++++++ app/apis/service/VehicleNewAskedService.php | 59 +++++++ .../VehicleNewAskedTranslationService.php | 59 +++++++ app/apis/service/VehicleNewContentService.php | 59 +++++++ .../VehicleNewContentTranslationService.php | 59 +++++++ app/apis/service/VehicleNewService.php | 99 +++++++++++ app/apis/service/VehicleNewTraitService.php | 59 +++++++ .../VehicleNewTraitTranslationService.php | 59 +++++++ .../service/VehicleNewTranslationService.php | 59 +++++++ .../VehicleNewAlbumTranslationValidator.php | 29 ++++ .../validate/VehicleNewAlbumValidator.php | 29 ++++ .../VehicleNewAskedTranslationValidator.php | 29 ++++ .../validate/VehicleNewAskedValidator.php | 29 ++++ .../VehicleNewContentTranslationValidator.php | 29 ++++ .../validate/VehicleNewContentValidator.php | 29 ++++ .../VehicleNewTraitTranslationValidator.php | 29 ++++ .../validate/VehicleNewTraitValidator.php | 29 ++++ .../VehicleNewTranslationValidator.php | 29 ++++ app/apis/validate/VehicleNewValidator.php | 29 ++++ app/console/model/BrandBannerModel.php | 6 +- app/console/model/BrandTraitModel.php | 2 +- app/console/model/VehicleNewAlbumModel.php | 3 + config/route.php | 3 + 44 files changed, 2515 insertions(+), 4 deletions(-) create mode 100644 app/apis/controller/VehicleNewAlbumController.php create mode 100644 app/apis/controller/VehicleNewAlbumTranslationController.php create mode 100644 app/apis/controller/VehicleNewAskedController.php create mode 100644 app/apis/controller/VehicleNewAskedTranslationController.php create mode 100644 app/apis/controller/VehicleNewContentController.php create mode 100644 app/apis/controller/VehicleNewContentTranslationController.php create mode 100644 app/apis/controller/VehicleNewController.php create mode 100644 app/apis/controller/VehicleNewTraitController.php create mode 100644 app/apis/controller/VehicleNewTraitTranslationController.php create mode 100644 app/apis/controller/VehicleNewTranslationController.php create mode 100644 app/apis/model/VehicleNewAlbumModel.php create mode 100644 app/apis/model/VehicleNewAlbumTranslationModel.php create mode 100644 app/apis/model/VehicleNewAskedModel.php create mode 100644 app/apis/model/VehicleNewAskedTranslationModel.php create mode 100644 app/apis/model/VehicleNewContentModel.php create mode 100644 app/apis/model/VehicleNewContentTranslationModel.php create mode 100644 app/apis/model/VehicleNewModel.php create mode 100644 app/apis/model/VehicleNewTraitModel.php create mode 100644 app/apis/model/VehicleNewTraitTranslationModel.php create mode 100644 app/apis/model/VehicleNewTranslationModel.php create mode 100644 app/apis/service/VehicleNewAlbumService.php create mode 100644 app/apis/service/VehicleNewAlbumTranslationService.php create mode 100644 app/apis/service/VehicleNewAskedService.php create mode 100644 app/apis/service/VehicleNewAskedTranslationService.php create mode 100644 app/apis/service/VehicleNewContentService.php create mode 100644 app/apis/service/VehicleNewContentTranslationService.php create mode 100644 app/apis/service/VehicleNewService.php create mode 100644 app/apis/service/VehicleNewTraitService.php create mode 100644 app/apis/service/VehicleNewTraitTranslationService.php create mode 100644 app/apis/service/VehicleNewTranslationService.php create mode 100644 app/apis/validate/VehicleNewAlbumTranslationValidator.php create mode 100644 app/apis/validate/VehicleNewAlbumValidator.php create mode 100644 app/apis/validate/VehicleNewAskedTranslationValidator.php create mode 100644 app/apis/validate/VehicleNewAskedValidator.php create mode 100644 app/apis/validate/VehicleNewContentTranslationValidator.php create mode 100644 app/apis/validate/VehicleNewContentValidator.php create mode 100644 app/apis/validate/VehicleNewTraitTranslationValidator.php create mode 100644 app/apis/validate/VehicleNewTraitValidator.php create mode 100644 app/apis/validate/VehicleNewTranslationValidator.php create mode 100644 app/apis/validate/VehicleNewValidator.php diff --git a/app/apis/controller/VehicleNewAlbumController.php b/app/apis/controller/VehicleNewAlbumController.php new file mode 100644 index 0000000..a2aaba8 --- /dev/null +++ b/app/apis/controller/VehicleNewAlbumController.php @@ -0,0 +1,81 @@ +errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/apis/controller/VehicleNewAlbumTranslationController.php b/app/apis/controller/VehicleNewAlbumTranslationController.php new file mode 100644 index 0000000..aabecde --- /dev/null +++ b/app/apis/controller/VehicleNewAlbumTranslationController.php @@ -0,0 +1,81 @@ +errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/apis/controller/VehicleNewAskedController.php b/app/apis/controller/VehicleNewAskedController.php new file mode 100644 index 0000000..6dc7395 --- /dev/null +++ b/app/apis/controller/VehicleNewAskedController.php @@ -0,0 +1,81 @@ +errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/apis/controller/VehicleNewAskedTranslationController.php b/app/apis/controller/VehicleNewAskedTranslationController.php new file mode 100644 index 0000000..1284b03 --- /dev/null +++ b/app/apis/controller/VehicleNewAskedTranslationController.php @@ -0,0 +1,81 @@ +errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/apis/controller/VehicleNewContentController.php b/app/apis/controller/VehicleNewContentController.php new file mode 100644 index 0000000..5669747 --- /dev/null +++ b/app/apis/controller/VehicleNewContentController.php @@ -0,0 +1,81 @@ +errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/apis/controller/VehicleNewContentTranslationController.php b/app/apis/controller/VehicleNewContentTranslationController.php new file mode 100644 index 0000000..91636ef --- /dev/null +++ b/app/apis/controller/VehicleNewContentTranslationController.php @@ -0,0 +1,81 @@ +errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/apis/controller/VehicleNewController.php b/app/apis/controller/VehicleNewController.php new file mode 100644 index 0000000..448c9ca --- /dev/null +++ b/app/apis/controller/VehicleNewController.php @@ -0,0 +1,154 @@ + $item['id'], + 'vin' => $item['vin'], + 'price' => $item['price'], + 'cover' => $item['cover'], + 'brand' => is_array($item['brand']) ? $item['brand']['translation']['brand_id'] : $item['brand'], + 'energy' => is_array($item['energy']) ? $item['energy']['translation']['energy_id'] : $item['energy'], + 'type' => isset($item['types']) ? $item['types']['translation']['type_id'] : $item['type'], + 'model' => isset($item['models']) ? $item['models']['translation']['model_id'] : $item['model'], + 'video' => $item['video'], + 'name' => isset($item['translation']) ? $item['translation']['name'] : '', + 'condition_desc' => isset($item['translation']) ? $item['translation']['condition_desc'] : '', + 'created_at' => date('Y-m-d H:i:s', $item['created_at']), + 'updated_at' => date('Y-m-d H:i:s', $item['updated_at']), + + 'brand_name' => is_array($item['brand']) ? $item['brand']['translation']['name'] : '', + 'energy_name' => is_array($item['energy']) ? $item['energy']['translation']['name'] : '', + 'type_name' => isset($item['types']) ? $item['types']['translation']['name'] : '', + 'model_name' => isset($item['models']) ? $item['models']['translation']['name'] : '', + ]; + if ($item['cover']) { + $result['cover_full'] = (new \app\mzl\modules\upload\service\OssService())->generatePrivateUrl($item['cover']); + } + if ($item['video']) { + $result['video_full'] = (new \app\mzl\modules\upload\service\OssService())->generatePrivateUrl($item['video']); + } + foreach ($item['asked'] as $asked) { + $askedRes['id'] = $asked['id']; + $askedRes['vehicle_id'] = $asked['vehicle_id']; + $askedRes['status'] = $asked['status']; + $askedRes['title'] = isset($asked['translation']) ? $asked['translation']['title']:''; + $askedRes['content'] = isset($asked['translation']) ? $asked['translation']['content']:''; + $result['asked'][] = $askedRes; + } + foreach ($item['trait'] as $trait) { + $traitRes['id'] = $trait['id']; + $traitRes['vehicle_id'] = $trait['vehicle_id']; + $traitRes['status'] = $trait['status']; + $traitRes['title'] = isset($trait['translation']) ? $trait['translation']['title']:''; + $traitRes['content'] = isset($trait['translation']) ? $trait['translation']['content']:''; + $result['trait'][] = $traitRes; + } + foreach ($item['album'] as $album) { + $albumRes['id'] = $album['id']; + $albumRes['vehicle_id'] = $album['vehicle_id']; + $albumRes['pic'] = $album['pic']; + $albumRes['status'] = $album['status']; + $albumRes['alt'] = isset($album['translation']) ? $album['translation']['alt']:''; + + if ($albumRes['pic']) { + $albumRes['pic_full'] = (new \app\mzl\modules\upload\service\OssService())->generatePrivateUrl($albumRes['pic']); + } + + $result['album'][] = $albumRes; + } + foreach ($item['content'] as $content) { + $contentRes['id'] = $content['id']; + $contentRes['vehicle_id'] = $content['vehicle_id']; + $contentRes['status'] = $content['status']; + $contentRes['content'] = isset($content['translation']) ? $content['translation']['content']:''; + $result['content'][] = $contentRes; + } + return $result; + } + + return $item; + } + + /** + * 参数预处理 (根据场景处理) + * @param Request $request + * @param string $scene + * @return array + */ + protected function prepareParams(Request $request, string $scene): array + { + $params = parent::prepareParams($request, $scene); + + if ($scene === 'default') { + + } + + return $params; + } + + /** + * 分页 + * + * @param Request $request 请求对象 + * @return Response 响应对象 + */ + public function index(Request $request, string $scene = 'default'): Response + { + try { + return parent::index($request, $scene); + } catch (\Throwable $th) { + return $this->errorResponse($th->getMessage()); + } + } + + public function detail(Request $request, int $id, string $scene = 'show'): Response + { + try { + $request->setGet(['id'=>$id]); + return parent::one($request, $scene); + } catch (\Throwable $th) { + return $this->errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/apis/controller/VehicleNewTraitController.php b/app/apis/controller/VehicleNewTraitController.php new file mode 100644 index 0000000..33097b8 --- /dev/null +++ b/app/apis/controller/VehicleNewTraitController.php @@ -0,0 +1,81 @@ +errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/apis/controller/VehicleNewTraitTranslationController.php b/app/apis/controller/VehicleNewTraitTranslationController.php new file mode 100644 index 0000000..035a18e --- /dev/null +++ b/app/apis/controller/VehicleNewTraitTranslationController.php @@ -0,0 +1,81 @@ +errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/apis/controller/VehicleNewTranslationController.php b/app/apis/controller/VehicleNewTranslationController.php new file mode 100644 index 0000000..ed9d13c --- /dev/null +++ b/app/apis/controller/VehicleNewTranslationController.php @@ -0,0 +1,81 @@ +errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/apis/model/VehicleNewAlbumModel.php b/app/apis/model/VehicleNewAlbumModel.php new file mode 100644 index 0000000..8af56c5 --- /dev/null +++ b/app/apis/model/VehicleNewAlbumModel.php @@ -0,0 +1,76 @@ +hasOne(VehicleNewAlbumTranslationModel::class, 'album_id')->where('locale', locale()); + } + + /** + * 多条翻译 + */ + public function translations() + { + return $this->hasMany(VehicleNewAlbumTranslationModel::class, 'album_id'); + } + + const TRANS_FIELDS = [ + 'alt', + ]; +} \ No newline at end of file diff --git a/app/apis/model/VehicleNewAlbumTranslationModel.php b/app/apis/model/VehicleNewAlbumTranslationModel.php new file mode 100644 index 0000000..cd89e19 --- /dev/null +++ b/app/apis/model/VehicleNewAlbumTranslationModel.php @@ -0,0 +1,56 @@ +hasOne(VehicleNewAskedTranslationModel::class, 'asked_id')->where('locale', locale()); + } + + /** + * 多条翻译 + */ + public function translations() + { + return $this->hasMany(VehicleNewAskedTranslationModel::class, 'asked_id'); + } +} \ No newline at end of file diff --git a/app/apis/model/VehicleNewAskedTranslationModel.php b/app/apis/model/VehicleNewAskedTranslationModel.php new file mode 100644 index 0000000..45ba51c --- /dev/null +++ b/app/apis/model/VehicleNewAskedTranslationModel.php @@ -0,0 +1,56 @@ +hasOne(VehicleNewContentTranslationModel::class, 'content_id')->where('locale', locale()); + } + + /** + * 多条翻译 + */ + public function translations() + { + return $this->hasMany(VehicleNewContentTranslationModel::class, 'content_id'); + } +} \ No newline at end of file diff --git a/app/apis/model/VehicleNewContentTranslationModel.php b/app/apis/model/VehicleNewContentTranslationModel.php new file mode 100644 index 0000000..1d22fff --- /dev/null +++ b/app/apis/model/VehicleNewContentTranslationModel.php @@ -0,0 +1,56 @@ +hasOne(VehicleNewTranslationModel::class, 'vehicle_id')->where('locale', locale()); + } + + /** + * 多条翻译 + */ + public function translations() + { + return $this->hasMany(VehicleNewTranslationModel::class, 'vehicle_id'); + } + + public function brand() + { + return $this->belongsTo(BrandModel::class, 'brand'); + } + + public function models() + { + return $this->belongsTo(ModelModel::class, 'model'); + } + + public function location() + { + return $this->belongsTo(LocationModel::class, 'location'); + } + + public function types() + { + return $this->belongsTo(TypesModel::class, 'type', 'id'); + } + + public function energy() + { + return $this->belongsTo(EnergyModel::class, 'energy', 'id'); + } + + public function album() + { + return $this->hasMany(VehicleNewAlbumModel::class, 'vehicle_id', 'id'); + } + + public function asked() + { + return $this->hasMany(VehicleNewAskedModel::class, 'vehicle_id', 'id'); + } + + public function trait() + { + return $this->hasMany(VehicleNewTraitModel::class, 'vehicle_id', 'id'); + } + + public function content() + { + return $this->hasMany(VehicleNewContentModel::class, 'vehicle_id', 'id'); + } +} \ No newline at end of file diff --git a/app/apis/model/VehicleNewTraitModel.php b/app/apis/model/VehicleNewTraitModel.php new file mode 100644 index 0000000..94a5fb2 --- /dev/null +++ b/app/apis/model/VehicleNewTraitModel.php @@ -0,0 +1,72 @@ +hasOne(VehicleNewTraitTranslationModel::class, 'trait_id')->where('locale', locale()); + } + + /** + * 多条翻译 + */ + public function translations() + { + return $this->hasMany(VehicleNewTraitTranslationModel::class, 'trait_id'); + } +} \ No newline at end of file diff --git a/app/apis/model/VehicleNewTraitTranslationModel.php b/app/apis/model/VehicleNewTraitTranslationModel.php new file mode 100644 index 0000000..63d05d4 --- /dev/null +++ b/app/apis/model/VehicleNewTraitTranslationModel.php @@ -0,0 +1,56 @@ + function ($params) { + // $keyword = $params['keyword'] ?? ''; + // return [ + // 'filters' => [ + // ['field' => '***', 'operator' => '=', 'value' => '***'] + // ], + // 'fields' => ['id'], + // 'relations' => [], + // 'custom' => function(Builder $q) use ($keyword) { + // // 示例 + // if ($keyword) { + // $q->where(function($q2) use($keyword) { + // $q2->whereHas('***', function($q3) use($keyword) { + // $q3->where('***', 'like', "%{$keyword}%"); + // })->orWhereHas('***', function($q4) use($keyword) { + // $q4->where('***', 'like', "%{$keyword}%"); + // }); + // }); + // } + // }, + // 'sorts' => [ + // ['field' => 'created_at', 'direction' => 'desc'] + // ], + // 'pagination' => [ + // 'page' => $params['page'] ?? 1, + // 'per_page' => $params['per_page'] ?? 10, + // ] + // ]; + // } + ]; + } +} \ No newline at end of file diff --git a/app/apis/service/VehicleNewAlbumTranslationService.php b/app/apis/service/VehicleNewAlbumTranslationService.php new file mode 100644 index 0000000..b3e3123 --- /dev/null +++ b/app/apis/service/VehicleNewAlbumTranslationService.php @@ -0,0 +1,59 @@ + function ($params) { + // $keyword = $params['keyword'] ?? ''; + // return [ + // 'filters' => [ + // ['field' => '***', 'operator' => '=', 'value' => '***'] + // ], + // 'fields' => ['id'], + // 'relations' => [], + // 'custom' => function(Builder $q) use ($keyword) { + // // 示例 + // if ($keyword) { + // $q->where(function($q2) use($keyword) { + // $q2->whereHas('***', function($q3) use($keyword) { + // $q3->where('***', 'like', "%{$keyword}%"); + // })->orWhereHas('***', function($q4) use($keyword) { + // $q4->where('***', 'like', "%{$keyword}%"); + // }); + // }); + // } + // }, + // 'sorts' => [ + // ['field' => 'created_at', 'direction' => 'desc'] + // ], + // 'pagination' => [ + // 'page' => $params['page'] ?? 1, + // 'per_page' => $params['per_page'] ?? 10, + // ] + // ]; + // } + ]; + } +} \ No newline at end of file diff --git a/app/apis/service/VehicleNewAskedService.php b/app/apis/service/VehicleNewAskedService.php new file mode 100644 index 0000000..4310391 --- /dev/null +++ b/app/apis/service/VehicleNewAskedService.php @@ -0,0 +1,59 @@ + function ($params) { + // $keyword = $params['keyword'] ?? ''; + // return [ + // 'filters' => [ + // ['field' => '***', 'operator' => '=', 'value' => '***'] + // ], + // 'fields' => ['id'], + // 'relations' => [], + // 'custom' => function(Builder $q) use ($keyword) { + // // 示例 + // if ($keyword) { + // $q->where(function($q2) use($keyword) { + // $q2->whereHas('***', function($q3) use($keyword) { + // $q3->where('***', 'like', "%{$keyword}%"); + // })->orWhereHas('***', function($q4) use($keyword) { + // $q4->where('***', 'like', "%{$keyword}%"); + // }); + // }); + // } + // }, + // 'sorts' => [ + // ['field' => 'created_at', 'direction' => 'desc'] + // ], + // 'pagination' => [ + // 'page' => $params['page'] ?? 1, + // 'per_page' => $params['per_page'] ?? 10, + // ] + // ]; + // } + ]; + } +} \ No newline at end of file diff --git a/app/apis/service/VehicleNewAskedTranslationService.php b/app/apis/service/VehicleNewAskedTranslationService.php new file mode 100644 index 0000000..c78307a --- /dev/null +++ b/app/apis/service/VehicleNewAskedTranslationService.php @@ -0,0 +1,59 @@ + function ($params) { + // $keyword = $params['keyword'] ?? ''; + // return [ + // 'filters' => [ + // ['field' => '***', 'operator' => '=', 'value' => '***'] + // ], + // 'fields' => ['id'], + // 'relations' => [], + // 'custom' => function(Builder $q) use ($keyword) { + // // 示例 + // if ($keyword) { + // $q->where(function($q2) use($keyword) { + // $q2->whereHas('***', function($q3) use($keyword) { + // $q3->where('***', 'like', "%{$keyword}%"); + // })->orWhereHas('***', function($q4) use($keyword) { + // $q4->where('***', 'like', "%{$keyword}%"); + // }); + // }); + // } + // }, + // 'sorts' => [ + // ['field' => 'created_at', 'direction' => 'desc'] + // ], + // 'pagination' => [ + // 'page' => $params['page'] ?? 1, + // 'per_page' => $params['per_page'] ?? 10, + // ] + // ]; + // } + ]; + } +} \ No newline at end of file diff --git a/app/apis/service/VehicleNewContentService.php b/app/apis/service/VehicleNewContentService.php new file mode 100644 index 0000000..f4b023c --- /dev/null +++ b/app/apis/service/VehicleNewContentService.php @@ -0,0 +1,59 @@ + function ($params) { + // $keyword = $params['keyword'] ?? ''; + // return [ + // 'filters' => [ + // ['field' => '***', 'operator' => '=', 'value' => '***'] + // ], + // 'fields' => ['id'], + // 'relations' => [], + // 'custom' => function(Builder $q) use ($keyword) { + // // 示例 + // if ($keyword) { + // $q->where(function($q2) use($keyword) { + // $q2->whereHas('***', function($q3) use($keyword) { + // $q3->where('***', 'like', "%{$keyword}%"); + // })->orWhereHas('***', function($q4) use($keyword) { + // $q4->where('***', 'like', "%{$keyword}%"); + // }); + // }); + // } + // }, + // 'sorts' => [ + // ['field' => 'created_at', 'direction' => 'desc'] + // ], + // 'pagination' => [ + // 'page' => $params['page'] ?? 1, + // 'per_page' => $params['per_page'] ?? 10, + // ] + // ]; + // } + ]; + } +} \ No newline at end of file diff --git a/app/apis/service/VehicleNewContentTranslationService.php b/app/apis/service/VehicleNewContentTranslationService.php new file mode 100644 index 0000000..fad2d57 --- /dev/null +++ b/app/apis/service/VehicleNewContentTranslationService.php @@ -0,0 +1,59 @@ + function ($params) { + // $keyword = $params['keyword'] ?? ''; + // return [ + // 'filters' => [ + // ['field' => '***', 'operator' => '=', 'value' => '***'] + // ], + // 'fields' => ['id'], + // 'relations' => [], + // 'custom' => function(Builder $q) use ($keyword) { + // // 示例 + // if ($keyword) { + // $q->where(function($q2) use($keyword) { + // $q2->whereHas('***', function($q3) use($keyword) { + // $q3->where('***', 'like', "%{$keyword}%"); + // })->orWhereHas('***', function($q4) use($keyword) { + // $q4->where('***', 'like', "%{$keyword}%"); + // }); + // }); + // } + // }, + // 'sorts' => [ + // ['field' => 'created_at', 'direction' => 'desc'] + // ], + // 'pagination' => [ + // 'page' => $params['page'] ?? 1, + // 'per_page' => $params['per_page'] ?? 10, + // ] + // ]; + // } + ]; + } +} \ No newline at end of file diff --git a/app/apis/service/VehicleNewService.php b/app/apis/service/VehicleNewService.php new file mode 100644 index 0000000..dbba182 --- /dev/null +++ b/app/apis/service/VehicleNewService.php @@ -0,0 +1,99 @@ + function ($params) { + $keyword = $params['keyword'] ?? ''; + return [ + 'filters' => [ +// ['field' => '***', 'operator' => '=', 'value' => '***'] + ], + 'fields' => ['id', 'vin', 'brand', 'cover', 'price', 'type', 'energy', 'model', 'video', 'views', 'created_at', 'updated_at'], + 'relations' => [ + 'translation' => ['vehicle_id', 'locale', 'name', 'condition_desc', 'location'], + 'asked' => ['id', 'vehicle_id', 'status', 'sort'], + 'asked.translation' => ['id', 'asked_id', 'locale', 'title', 'content'], + 'trait' => ['id', 'vehicle_id', 'status', 'sort'], + 'trait.translation' => ['id', 'trait_id', 'locale', 'title', 'content'], + 'album' => ['id', 'vehicle_id', 'pic', 'status', 'sort'], + 'album.translation' => ['id', 'album_id', 'locale', 'alt'], + 'content' => ['id', 'vehicle_id', 'status', 'sort'], + 'content.translation' => ['id', 'content_id', 'locale', 'content'], + 'brand.translation' => ['brand_id', 'name'], + 'types.translation' => ['type_id', 'name'], + 'energy.translation' => ['energy_id', 'name'], + 'models.translation' => ['model_id', 'name'], + ], + 'sorts' => [ + ['field' => 'id', 'direction' => 'desc'] + ], + 'pagination' => [ + 'page' => $params['page'] ?? 1, + 'per_page' => $params['per_page'] ?? 10, + ] + ]; + }, + 'show' => function ($params) { + $keyword = $params['keyword'] ?? ''; + return [ + 'filters' => [ + ['field'=>'id', 'operator'=>'=', 'value'=> $params['id']], + ], + 'fields' => ['id', 'vin', 'brand', 'cover', 'price', 'type', 'energy', 'model', 'video', 'views', 'created_at', 'updated_at'], + 'relations' => [ + 'translation' => ['vehicle_id', 'locale', 'name', 'condition_desc', 'location'], + 'asked' => ['id', 'vehicle_id', 'status', 'sort'], + 'asked.translation' => ['id', 'asked_id', 'locale', 'title', 'content'], + 'trait' => ['id', 'vehicle_id', 'status', 'sort'], + 'trait.translation' => ['id', 'trait_id', 'locale', 'title', 'content'], + 'album' => ['id', 'vehicle_id', 'pic', 'status', 'sort'], + 'album.translation' => ['id', 'album_id', 'locale', 'alt'], + 'content' => ['id', 'vehicle_id', 'status', 'sort'], + 'content.translation' => ['id', 'content_id', 'locale', 'content'], + 'brand.translation' => ['brand_id', 'name'], + 'types.translation' => ['type_id', 'name'], + 'energy.translation' => ['energy_id', 'name'], + 'models.translation' => ['model_id', 'name'], + ], + 'sorts' => [ + ['field' => 'id', 'direction' => 'desc'] + ], + 'pagination' => [ + 'page' => $params['page'] ?? 1, + 'per_page' => $params['per_page'] ?? 10, + ] + ]; + } + ]; + } + + + // 声明需要多语言翻译 + protected array $translatable = [ + 'condition_desc','name', + ]; +} \ No newline at end of file diff --git a/app/apis/service/VehicleNewTraitService.php b/app/apis/service/VehicleNewTraitService.php new file mode 100644 index 0000000..b830dfa --- /dev/null +++ b/app/apis/service/VehicleNewTraitService.php @@ -0,0 +1,59 @@ + function ($params) { + // $keyword = $params['keyword'] ?? ''; + // return [ + // 'filters' => [ + // ['field' => '***', 'operator' => '=', 'value' => '***'] + // ], + // 'fields' => ['id'], + // 'relations' => [], + // 'custom' => function(Builder $q) use ($keyword) { + // // 示例 + // if ($keyword) { + // $q->where(function($q2) use($keyword) { + // $q2->whereHas('***', function($q3) use($keyword) { + // $q3->where('***', 'like', "%{$keyword}%"); + // })->orWhereHas('***', function($q4) use($keyword) { + // $q4->where('***', 'like', "%{$keyword}%"); + // }); + // }); + // } + // }, + // 'sorts' => [ + // ['field' => 'created_at', 'direction' => 'desc'] + // ], + // 'pagination' => [ + // 'page' => $params['page'] ?? 1, + // 'per_page' => $params['per_page'] ?? 10, + // ] + // ]; + // } + ]; + } +} \ No newline at end of file diff --git a/app/apis/service/VehicleNewTraitTranslationService.php b/app/apis/service/VehicleNewTraitTranslationService.php new file mode 100644 index 0000000..2a97e02 --- /dev/null +++ b/app/apis/service/VehicleNewTraitTranslationService.php @@ -0,0 +1,59 @@ + function ($params) { + // $keyword = $params['keyword'] ?? ''; + // return [ + // 'filters' => [ + // ['field' => '***', 'operator' => '=', 'value' => '***'] + // ], + // 'fields' => ['id'], + // 'relations' => [], + // 'custom' => function(Builder $q) use ($keyword) { + // // 示例 + // if ($keyword) { + // $q->where(function($q2) use($keyword) { + // $q2->whereHas('***', function($q3) use($keyword) { + // $q3->where('***', 'like', "%{$keyword}%"); + // })->orWhereHas('***', function($q4) use($keyword) { + // $q4->where('***', 'like', "%{$keyword}%"); + // }); + // }); + // } + // }, + // 'sorts' => [ + // ['field' => 'created_at', 'direction' => 'desc'] + // ], + // 'pagination' => [ + // 'page' => $params['page'] ?? 1, + // 'per_page' => $params['per_page'] ?? 10, + // ] + // ]; + // } + ]; + } +} \ No newline at end of file diff --git a/app/apis/service/VehicleNewTranslationService.php b/app/apis/service/VehicleNewTranslationService.php new file mode 100644 index 0000000..153299c --- /dev/null +++ b/app/apis/service/VehicleNewTranslationService.php @@ -0,0 +1,59 @@ + function ($params) { + // $keyword = $params['keyword'] ?? ''; + // return [ + // 'filters' => [ + // ['field' => '***', 'operator' => '=', 'value' => '***'] + // ], + // 'fields' => ['id'], + // 'relations' => [], + // 'custom' => function(Builder $q) use ($keyword) { + // // 示例 + // if ($keyword) { + // $q->where(function($q2) use($keyword) { + // $q2->whereHas('***', function($q3) use($keyword) { + // $q3->where('***', 'like', "%{$keyword}%"); + // })->orWhereHas('***', function($q4) use($keyword) { + // $q4->where('***', 'like', "%{$keyword}%"); + // }); + // }); + // } + // }, + // 'sorts' => [ + // ['field' => 'created_at', 'direction' => 'desc'] + // ], + // 'pagination' => [ + // 'page' => $params['page'] ?? 1, + // 'per_page' => $params['per_page'] ?? 10, + // ] + // ]; + // } + ]; + } +} \ No newline at end of file diff --git a/app/apis/validate/VehicleNewAlbumTranslationValidator.php b/app/apis/validate/VehicleNewAlbumTranslationValidator.php new file mode 100644 index 0000000..dbd3954 --- /dev/null +++ b/app/apis/validate/VehicleNewAlbumTranslationValidator.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/apis/validate/VehicleNewAlbumValidator.php b/app/apis/validate/VehicleNewAlbumValidator.php new file mode 100644 index 0000000..269fbb0 --- /dev/null +++ b/app/apis/validate/VehicleNewAlbumValidator.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/apis/validate/VehicleNewAskedTranslationValidator.php b/app/apis/validate/VehicleNewAskedTranslationValidator.php new file mode 100644 index 0000000..99f7fb3 --- /dev/null +++ b/app/apis/validate/VehicleNewAskedTranslationValidator.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/apis/validate/VehicleNewAskedValidator.php b/app/apis/validate/VehicleNewAskedValidator.php new file mode 100644 index 0000000..db416fe --- /dev/null +++ b/app/apis/validate/VehicleNewAskedValidator.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/apis/validate/VehicleNewContentTranslationValidator.php b/app/apis/validate/VehicleNewContentTranslationValidator.php new file mode 100644 index 0000000..fe6f3d9 --- /dev/null +++ b/app/apis/validate/VehicleNewContentTranslationValidator.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/apis/validate/VehicleNewContentValidator.php b/app/apis/validate/VehicleNewContentValidator.php new file mode 100644 index 0000000..bb87038 --- /dev/null +++ b/app/apis/validate/VehicleNewContentValidator.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/apis/validate/VehicleNewTraitTranslationValidator.php b/app/apis/validate/VehicleNewTraitTranslationValidator.php new file mode 100644 index 0000000..57d6263 --- /dev/null +++ b/app/apis/validate/VehicleNewTraitTranslationValidator.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/apis/validate/VehicleNewTraitValidator.php b/app/apis/validate/VehicleNewTraitValidator.php new file mode 100644 index 0000000..d1800b6 --- /dev/null +++ b/app/apis/validate/VehicleNewTraitValidator.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/apis/validate/VehicleNewTranslationValidator.php b/app/apis/validate/VehicleNewTranslationValidator.php new file mode 100644 index 0000000..23fe8c4 --- /dev/null +++ b/app/apis/validate/VehicleNewTranslationValidator.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/apis/validate/VehicleNewValidator.php b/app/apis/validate/VehicleNewValidator.php new file mode 100644 index 0000000..1bdffd8 --- /dev/null +++ b/app/apis/validate/VehicleNewValidator.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/console/model/BrandBannerModel.php b/app/console/model/BrandBannerModel.php index ac59ff7..b2d1cf4 100644 --- a/app/console/model/BrandBannerModel.php +++ b/app/console/model/BrandBannerModel.php @@ -65,7 +65,7 @@ class BrandBannerModel extends Model */ public function translation() { - return $this->hasOne(BrandBannerTranslationModel::class, 'brand_id')->where('locale', locale()); + return $this->hasOne(BrandBannerTranslationModel::class, 'banner_id')->where('locale', locale()); } /** @@ -73,11 +73,11 @@ class BrandBannerModel extends Model */ public function translations() { - return $this->hasMany(VehicleDataTranslationModel::class, 'brand_id'); + return $this->hasMany(VehicleDataTranslationModel::class, 'banner_id'); } const TRANS_FIELDS = [ - 'name', 'condition_desc' + 'alt' ]; } \ No newline at end of file diff --git a/app/console/model/BrandTraitModel.php b/app/console/model/BrandTraitModel.php index 52a505a..cf4c671 100644 --- a/app/console/model/BrandTraitModel.php +++ b/app/console/model/BrandTraitModel.php @@ -79,6 +79,6 @@ class BrandTraitModel extends Model const TRANS_FIELDS = [ - 'name', 'condition_desc' + 'title', 'content' ]; } \ No newline at end of file diff --git a/app/console/model/VehicleNewAlbumModel.php b/app/console/model/VehicleNewAlbumModel.php index f22adaf..f5853c2 100644 --- a/app/console/model/VehicleNewAlbumModel.php +++ b/app/console/model/VehicleNewAlbumModel.php @@ -70,6 +70,9 @@ class VehicleNewAlbumModel extends Model return $this->hasMany(VehicleNewAlbumTranslationModel::class, 'album_id'); } + const VEHICLE_NEW_ALBUM_FIELDS = [ + 'pic', + ]; const TRANS_FIELDS = [ 'alt', ]; diff --git a/config/route.php b/config/route.php index 70021f3..1e2adba 100644 --- a/config/route.php +++ b/config/route.php @@ -42,6 +42,9 @@ Route::group('/apis', function() { Route::any('/agt/privacy', [\app\apis\controller\AgreementController::class, 'one']); // 品牌按字母查询 // Route::any('/brand/letterAll', [\app\apis\controller\BrandController::class, 'letterAll']); + // 新车管理 + Route::any('/vehicle/new/list', [\app\console\controller\VehicleNewController::class, 'index']); + Route::any('/vehicle/new/{id}/detail', [\app\console\controller\VehicleNewController::class, 'detail']); }); // ====== ====== ====== 网站 ====== ====== ====== From a5a50ae7fcfbc1762bcbd2bdd6b38910bca32436 Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Fri, 23 May 2025 13:29:56 +0800 Subject: [PATCH 14/32] =?UTF-8?q?=E5=93=81=E7=89=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/console/controller/BrandController.php | 13 +++++- app/console/service/BrandService.php | 50 ++++++++++++++++------ 2 files changed, 47 insertions(+), 16 deletions(-) diff --git a/app/console/controller/BrandController.php b/app/console/controller/BrandController.php index 3f1b1ca..ebbee64 100644 --- a/app/console/controller/BrandController.php +++ b/app/console/controller/BrandController.php @@ -2,6 +2,8 @@ namespace app\console\controller; +use app\console\model\BrandBannerModel; +use app\console\model\BrandTraitModel; use support\Request; use support\Response; use app\console\model\BrandModel; @@ -56,10 +58,17 @@ class BrandController extends BaseController 'created_at' => date('Y-m-d H:i:s', $item['created_at']), 'updated_at' => date('Y-m-d H:i:s', $item['updated_at']), ]; - foreach ($item['banner'] as $k => $v) { + $banners = BrandBannerModel::with('translation')->where(['brand_id' => $item['id']])->get(); + foreach ($banners as $k => $v) { + $v['alt'] = isset($v['translation']) ? $v['translation']['alt'] : ''; + unset($v['translation']); $result['banner'][$k] = $v; } - foreach ($item['trait'] as $k => $v) { + $traits = BrandTraitModel::with('translation')->where(['brand_id' => $item['id']])->get(); + foreach ($traits as $k => $v) { + $v['title'] = isset($v['translation']) ? $v['translation']['title'] : ''; + $v['content'] = isset($v['translation']) ? $v['translation']['content'] : ''; + unset($v['translation']); $result['trait'][$k] = $v; } return $result; diff --git a/app/console/service/BrandService.php b/app/console/service/BrandService.php index 3533edd..62dae3a 100644 --- a/app/console/service/BrandService.php +++ b/app/console/service/BrandService.php @@ -181,14 +181,26 @@ class BrandService extends BaseService ); //品牌轮播图 + $bannersId = []; foreach ($banners as $banner) { $bannersourceFields = $BrandBannerService->extractSourceFields($banner); $bannersourceFields['brand_id'] = $id; - $bannerId = $banner['id']; - $banner['brand_id'] = $id; - $banner = $BrandBannerService->update($bannerId,$banner); - if (!$banner) { - throw new BusinessException('提交失败'); + + if(!empty($banner['id'])){ + $bannerId = $banner['id']; + $bannersId[] = $bannerId; + $banner_res = $BrandBannerService->update($bannerId, $banner); + if (!$banner_res) { + throw new BusinessException('提交失败:品牌轮播图'); + } + } else { + unset($banner['id']); + $banner_res = $BrandBannerService->create($banner); + if (!$banner_res) { + throw new BusinessException('提交失败:品牌轮播图.'); + } + $bannerId = $banner_res->id; + $bannersId[] = $bannerId; } (new TranslationService())->queueTranslations( @@ -198,18 +210,29 @@ class BrandService extends BaseService $bannersourceFields ); } - $ids = array_column($banners,'id'); - BrandBannerModel::whereNotIn('id', $ids)->where('brand_id',$id)->delete(); + BrandBannerModel::whereNotIn('id', $bannersId)->where('brand_id',$id)->delete(); //品牌特性 + $traitsId = []; foreach ($traits as $trait) { $traitsourceFields = $BrandTraitService->extractSourceFields($trait); $traitsourceFields['brand_id'] = $id; - $traitId = $trait['id']; - $trait['brand_id'] = $id; - $trait = $BrandTraitService->update($traitId,$trait); - if (!$trait) { - throw new BusinessException('提交失败'); + + if(!empty($trait['id'])){ + $traitId = $trait['id']; + $traitsId[] = $traitId; + $trait_res = $BrandTraitService->update($traitId, $trait); + if (!$trait_res) { + throw new BusinessException('提交失败:品牌轮播图'); + } + } else { + unset($trait['id']); + $trait_res = $BrandTraitService->create($trait); + if (!$trait_res) { + throw new BusinessException('提交失败:品牌轮播图.'); + } + $traitId = $trait_res->id; + $traitsId[] = $traitId; } (new TranslationService())->queueTranslations( @@ -219,8 +242,7 @@ class BrandService extends BaseService $traitsourceFields ); } - $ids = array_column($traits,'id'); - BrandTraitModel::whereNotIn('id', $ids)->where('brand_id',$id)->delete(); + BrandTraitModel::whereNotIn('id', $traitsId)->where('brand_id',$id)->delete(); Db::commit(); From b69a9fdb24532539d1e3fd60d24f1dd14c0f9a60 Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Fri, 23 May 2025 13:59:10 +0800 Subject: [PATCH 15/32] =?UTF-8?q?=E5=93=81=E7=89=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/console/controller/BrandController.php | 12 ++++++++++++ app/console/model/BrandModel.php | 2 +- app/console/service/BrandService.php | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/console/controller/BrandController.php b/app/console/controller/BrandController.php index ebbee64..97d6bcb 100644 --- a/app/console/controller/BrandController.php +++ b/app/console/controller/BrandController.php @@ -58,10 +58,22 @@ class BrandController extends BaseController 'created_at' => date('Y-m-d H:i:s', $item['created_at']), 'updated_at' => date('Y-m-d H:i:s', $item['updated_at']), ]; + if ($item['toppic']) { + $result['toppic_full'] = (new \app\mzl\modules\upload\service\OssService())->generatePrivateUrl($item['toppic']); + } + if ($item['descpic']) { + $result['descpic_full'] = (new \app\mzl\modules\upload\service\OssService())->generatePrivateUrl($item['descpic']); + } + if ($item['logo']) { + $result['logo_full'] = (new \app\mzl\modules\upload\service\OssService())->generatePrivateUrl($item['logo']); + } $banners = BrandBannerModel::with('translation')->where(['brand_id' => $item['id']])->get(); foreach ($banners as $k => $v) { $v['alt'] = isset($v['translation']) ? $v['translation']['alt'] : ''; unset($v['translation']); + if ($v['pic']) { + $v['pic_full'] = (new \app\mzl\modules\upload\service\OssService())->generatePrivateUrl($v['pic']); + } $result['banner'][$k] = $v; } $traits = BrandTraitModel::with('translation')->where(['brand_id' => $item['id']])->get(); diff --git a/app/console/model/BrandModel.php b/app/console/model/BrandModel.php index a6361b5..19e1415 100644 --- a/app/console/model/BrandModel.php +++ b/app/console/model/BrandModel.php @@ -47,7 +47,7 @@ class BrandModel extends Model /** * 允许自动填充模型字段 */ - protected $fillable = ['id', 'status', 'sort', 'toppic', 'descpic', 'logo', 'letter', 'created_at', 'updated_at']; + protected $fillable = ['id', 'status', 'sort', 'toppic', 'descpic', 'logo', 'letter', 'is_hot', 'created_at', 'updated_at']; /** * 不允许自动填充模型字段 diff --git a/app/console/service/BrandService.php b/app/console/service/BrandService.php index 62dae3a..26af93d 100644 --- a/app/console/service/BrandService.php +++ b/app/console/service/BrandService.php @@ -35,7 +35,7 @@ class BrandService extends BaseService 'filters' => [ ['field' => 'status', 'operator' => '=', 'value' => '1'] ], - 'fields' => ['id', 'status', 'sort', 'toppic', 'descpic', 'logo', 'letter', 'created_at', 'updated_at'], + 'fields' => ['id', 'status', 'sort', 'toppic', 'descpic', 'logo', 'letter', 'is_hot', 'created_at', 'updated_at'], 'relations' => [ 'translation' => ['brand_id', 'name', 'desc','toppic_alt','descpic_alt','logo_alt'], 'banner' => ['id', 'pic', 'sort',], From 0ba3ff6ac58e9436b1a1b07bda8398e60deb6414 Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Fri, 23 May 2025 14:24:04 +0800 Subject: [PATCH 16/32] =?UTF-8?q?=E5=93=81=E7=89=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/console/service/BrandService.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/console/service/BrandService.php b/app/console/service/BrandService.php index 26af93d..494c434 100644 --- a/app/console/service/BrandService.php +++ b/app/console/service/BrandService.php @@ -38,10 +38,10 @@ class BrandService extends BaseService 'fields' => ['id', 'status', 'sort', 'toppic', 'descpic', 'logo', 'letter', 'is_hot', 'created_at', 'updated_at'], 'relations' => [ 'translation' => ['brand_id', 'name', 'desc','toppic_alt','descpic_alt','logo_alt'], - 'banner' => ['id', 'pic', 'sort',], - 'banner.translation' => ['id', 'alt',], - 'trait' => ['id', 'sort',], - 'trait.translation' => ['id', 'title', 'content',], + 'banners' => ['id', 'pic', 'sort',], + 'banners.translation' => ['id', 'alt',], + 'traits' => ['id', 'sort',], + 'traits.translation' => ['id', 'title', 'content',], ], 'sorts' => [ ['field' => 'id', 'direction' => 'desc'] @@ -114,7 +114,7 @@ class BrandService extends BaseService if (!$banner) { throw new BusinessException('提交失败'); } - + // 异步翻译并写入 hs_brand_banner_translation 表 (new TranslationService())->queueTranslations( 'brandBanner', $banner->id, @@ -185,6 +185,7 @@ class BrandService extends BaseService foreach ($banners as $banner) { $bannersourceFields = $BrandBannerService->extractSourceFields($banner); $bannersourceFields['brand_id'] = $id; + $banner['brand_id'] = $id; if(!empty($banner['id'])){ $bannerId = $banner['id']; @@ -217,6 +218,7 @@ class BrandService extends BaseService foreach ($traits as $trait) { $traitsourceFields = $BrandTraitService->extractSourceFields($trait); $traitsourceFields['brand_id'] = $id; + $trait['brand_id'] = $id; if(!empty($trait['id'])){ $traitId = $trait['id']; From 749db39a785d7ae7d038132d52198a3dbf536bb5 Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Fri, 23 May 2025 16:02:35 +0800 Subject: [PATCH 17/32] =?UTF-8?q?=E5=93=81=E7=89=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/apis/controller/BrandBannerController.php | 81 ++++++++++++++++++ .../BrandBannerTranslationController.php | 81 ++++++++++++++++++ app/apis/controller/BrandController.php | 73 +++++++++++++++- app/apis/controller/BrandTraitController.php | 81 ++++++++++++++++++ .../BrandTraitTranslationController.php | 81 ++++++++++++++++++ app/apis/model/BrandBannerModel.php | 83 ++++++++++++++++++ .../model/BrandBannerTranslationModel.php | 66 +++++++++++++++ app/apis/model/BrandModel.php | 9 ++ app/apis/model/BrandTraitModel.php | 84 +++++++++++++++++++ app/apis/model/BrandTraitTranslationModel.php | 67 +++++++++++++++ app/apis/service/BrandBannerService.php | 59 +++++++++++++ .../service/BrandBannerTranslationService.php | 59 +++++++++++++ app/apis/service/BrandService.php | 43 ++++++++-- app/apis/service/BrandTraitService.php | 59 +++++++++++++ .../service/BrandTraitTranslationService.php | 59 +++++++++++++ .../BrandBannerTranslationValidator.php | 29 +++++++ app/apis/validate/BrandBannerValidator.php | 29 +++++++ .../BrandTraitTranslationValidator.php | 29 +++++++ app/apis/validate/BrandTraitValidator.php | 29 +++++++ app/console/controller/BrandController.php | 2 +- config/route.php | 6 +- 21 files changed, 1099 insertions(+), 10 deletions(-) create mode 100644 app/apis/controller/BrandBannerController.php create mode 100644 app/apis/controller/BrandBannerTranslationController.php create mode 100644 app/apis/controller/BrandTraitController.php create mode 100644 app/apis/controller/BrandTraitTranslationController.php create mode 100644 app/apis/model/BrandBannerModel.php create mode 100644 app/apis/model/BrandBannerTranslationModel.php create mode 100644 app/apis/model/BrandTraitModel.php create mode 100644 app/apis/model/BrandTraitTranslationModel.php create mode 100644 app/apis/service/BrandBannerService.php create mode 100644 app/apis/service/BrandBannerTranslationService.php create mode 100644 app/apis/service/BrandTraitService.php create mode 100644 app/apis/service/BrandTraitTranslationService.php create mode 100644 app/apis/validate/BrandBannerTranslationValidator.php create mode 100644 app/apis/validate/BrandBannerValidator.php create mode 100644 app/apis/validate/BrandTraitTranslationValidator.php create mode 100644 app/apis/validate/BrandTraitValidator.php diff --git a/app/apis/controller/BrandBannerController.php b/app/apis/controller/BrandBannerController.php new file mode 100644 index 0000000..52cf1ee --- /dev/null +++ b/app/apis/controller/BrandBannerController.php @@ -0,0 +1,81 @@ +errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/apis/controller/BrandBannerTranslationController.php b/app/apis/controller/BrandBannerTranslationController.php new file mode 100644 index 0000000..9bb96f3 --- /dev/null +++ b/app/apis/controller/BrandBannerTranslationController.php @@ -0,0 +1,81 @@ +errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/apis/controller/BrandController.php b/app/apis/controller/BrandController.php index 6b0c058..de01980 100644 --- a/app/apis/controller/BrandController.php +++ b/app/apis/controller/BrandController.php @@ -2,6 +2,8 @@ namespace app\apis\controller; +use app\apis\model\BrandBannerModel; +use app\apis\model\BrandTraitModel; use support\Request; use support\Response; use app\apis\model\BrandModel; @@ -39,7 +41,50 @@ class BrandController extends BaseController */ protected function postProcessItem(array $item, string $scene): array { - + if ($scene === 'default' || $scene === 'letter' || $scene === 'hot') { + $result = [ + 'id' => $item['id'], + 'status' => $item['status'], + 'sort' => $item['sort'], + 'toppic' => $item['toppic'], + 'descpic' => $item['descpic'], + 'logo' => $item['logo'], + 'is_hot' => $item['is_hot'], + 'name' => isset($item['translation']) ? $item['translation']['name'] : '', + 'desc' => isset($item['translation']) ? $item['translation']['desc'] : '', + 'toppic_alt' => isset($item['translation']) ? $item['translation']['toppic_alt'] : '', + 'descpic_alt' => isset($item['translation']) ? $item['translation']['descpic_alt'] : '', + 'logo_alt' => isset($item['translation']) ? $item['translation']['logo_alt'] : '', + 'created_at' => date('Y-m-d H:i:s', $item['created_at']), + 'updated_at' => date('Y-m-d H:i:s', $item['updated_at']), + ]; + if ($item['toppic']) { + $result['toppic_full'] = (new \app\mzl\modules\upload\service\OssService())->generatePrivateUrl($item['toppic']); + } + if ($item['descpic']) { + $result['descpic_full'] = (new \app\mzl\modules\upload\service\OssService())->generatePrivateUrl($item['descpic']); + } + if ($item['logo']) { + $result['logo_full'] = (new \app\mzl\modules\upload\service\OssService())->generatePrivateUrl($item['logo']); + } + $banners = BrandBannerModel::with('translation')->where(['brand_id' => $item['id']])->get(); + foreach ($banners as $k => $v) { + $v['alt'] = isset($v['translation']) ? $v['translation']['alt'] : ''; + unset($v['translation']); + if ($v['pic']) { + $v['pic_full'] = (new \app\mzl\modules\upload\service\OssService())->generatePrivateUrl($v['pic']); + } + $result['banner'][$k] = $v; + } + $traits = BrandTraitModel::with('translation')->where(['brand_id' => $item['id']])->get(); + foreach ($traits as $k => $v) { + $v['title'] = isset($v['translation']) ? $v['translation']['title'] : ''; + $v['content'] = isset($v['translation']) ? $v['translation']['content'] : ''; + unset($v['translation']); + $result['trait'][$k] = $v; + } + return $result; + } return $item; } @@ -53,8 +98,14 @@ class BrandController extends BaseController { $params = parent::prepareParams($request, $scene); - if ($scene === 'default') { - + if ($scene === 'default' || $scene === 'letter') { + $params['filters'][] = ['field' => 'status', 'operator' => '=', 'value' => '1']; + if(!empty($params['letter'])){ + $params['filters'][] = ['field' => 'letter', 'operator' => '=', 'value' => $params['letter']]; + } + if(isset($params['is_hot']) && $params['is_hot'] == 1){ + $params['filters'][] = ['field' => 'is_hot', 'operator' => '=', 'value' => 1]; + } } return $params; @@ -74,4 +125,20 @@ class BrandController extends BaseController return $this->errorResponse($th->getMessage()); } } + + /** + * 分页 + * + * @param Request $request 请求对象 + * @return Response 响应对象 + */ + public function letterAll(Request $request, string $scene = 'letter'): Response + { + try { + return parent::index($request, $scene); + } catch (\Throwable $th) { + return $this->errorResponse($th->getMessage()); + } + } + } \ No newline at end of file diff --git a/app/apis/controller/BrandTraitController.php b/app/apis/controller/BrandTraitController.php new file mode 100644 index 0000000..fdcc2f0 --- /dev/null +++ b/app/apis/controller/BrandTraitController.php @@ -0,0 +1,81 @@ +errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/apis/controller/BrandTraitTranslationController.php b/app/apis/controller/BrandTraitTranslationController.php new file mode 100644 index 0000000..c135782 --- /dev/null +++ b/app/apis/controller/BrandTraitTranslationController.php @@ -0,0 +1,81 @@ +errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/apis/model/BrandBannerModel.php b/app/apis/model/BrandBannerModel.php new file mode 100644 index 0000000..ec91ab7 --- /dev/null +++ b/app/apis/model/BrandBannerModel.php @@ -0,0 +1,83 @@ +belongsTo(BrandModel::class, 'brand_id'); + } + + /** + * 单条翻译 + */ + public function translation() + { + return $this->hasOne(BrandBannerTranslationModel::class, 'banner_id')->where('locale', locale()); + } + + /** + * 多条翻译 + */ + public function translations() + { + return $this->hasMany(VehicleDataTranslationModel::class, 'banner_id'); + } + + + const TRANS_FIELDS = [ + 'alt' + ]; +} \ No newline at end of file diff --git a/app/apis/model/BrandBannerTranslationModel.php b/app/apis/model/BrandBannerTranslationModel.php new file mode 100644 index 0000000..6fb08b7 --- /dev/null +++ b/app/apis/model/BrandBannerTranslationModel.php @@ -0,0 +1,66 @@ +belongsTo(BrandModel::class, 'brand_id'); + } + + public function banner() + { + return $this->belongsTo(BrandBannerModel::class, 'banner_id'); + } +} \ No newline at end of file diff --git a/app/apis/model/BrandModel.php b/app/apis/model/BrandModel.php index 07fc804..280c25b 100644 --- a/app/apis/model/BrandModel.php +++ b/app/apis/model/BrandModel.php @@ -58,4 +58,13 @@ class BrandModel extends Model { return $this->hasOne(BrandTranslationModel::class, 'brand_id')->where('locale', locale()); } + + public function banners() + { + return $this->hasMany(BrandBannerModel::class, 'brand_id','id'); + } + public function traits() + { + return $this->hasMany(BrandTraitModel::class, 'brand_id','id'); + } } \ No newline at end of file diff --git a/app/apis/model/BrandTraitModel.php b/app/apis/model/BrandTraitModel.php new file mode 100644 index 0000000..4e79070 --- /dev/null +++ b/app/apis/model/BrandTraitModel.php @@ -0,0 +1,84 @@ +belongsTo(BrandModel::class, 'brand_id'); + } + + /** + * 单条翻译 + */ + public function translation() + { + return $this->hasOne(BrandTraitTranslationModel::class, 'trait_id')->where('locale', locale()); + } + + /** + * 多条翻译 + */ + public function translations() + { + return $this->hasMany(BrandTraitTranslationModel::class, 'trait_id'); + } + + + const TRANS_FIELDS = [ + 'title', 'content' + ]; +} \ No newline at end of file diff --git a/app/apis/model/BrandTraitTranslationModel.php b/app/apis/model/BrandTraitTranslationModel.php new file mode 100644 index 0000000..5ed31c6 --- /dev/null +++ b/app/apis/model/BrandTraitTranslationModel.php @@ -0,0 +1,67 @@ +belongsTo(BrandModel::class, 'brand_id'); + } + + public function brandTrait() + { + return $this->belongsTo(BrandTraitModel::class, 'trait_id'); + } +} \ No newline at end of file diff --git a/app/apis/service/BrandBannerService.php b/app/apis/service/BrandBannerService.php new file mode 100644 index 0000000..bb34182 --- /dev/null +++ b/app/apis/service/BrandBannerService.php @@ -0,0 +1,59 @@ + function ($params) { + // $keyword = $params['keyword'] ?? ''; + // return [ + // 'filters' => [ + // ['field' => '***', 'operator' => '=', 'value' => '***'] + // ], + // 'fields' => ['id'], + // 'relations' => [], + // 'custom' => function(Builder $q) use ($keyword) { + // // 示例 + // if ($keyword) { + // $q->where(function($q2) use($keyword) { + // $q2->whereHas('***', function($q3) use($keyword) { + // $q3->where('***', 'like', "%{$keyword}%"); + // })->orWhereHas('***', function($q4) use($keyword) { + // $q4->where('***', 'like', "%{$keyword}%"); + // }); + // }); + // } + // }, + // 'sorts' => [ + // ['field' => 'created_at', 'direction' => 'desc'] + // ], + // 'pagination' => [ + // 'page' => $params['page'] ?? 1, + // 'per_page' => $params['per_page'] ?? 10, + // ] + // ]; + // } + ]; + } +} \ No newline at end of file diff --git a/app/apis/service/BrandBannerTranslationService.php b/app/apis/service/BrandBannerTranslationService.php new file mode 100644 index 0000000..99f948c --- /dev/null +++ b/app/apis/service/BrandBannerTranslationService.php @@ -0,0 +1,59 @@ + function ($params) { + // $keyword = $params['keyword'] ?? ''; + // return [ + // 'filters' => [ + // ['field' => '***', 'operator' => '=', 'value' => '***'] + // ], + // 'fields' => ['id'], + // 'relations' => [], + // 'custom' => function(Builder $q) use ($keyword) { + // // 示例 + // if ($keyword) { + // $q->where(function($q2) use($keyword) { + // $q2->whereHas('***', function($q3) use($keyword) { + // $q3->where('***', 'like', "%{$keyword}%"); + // })->orWhereHas('***', function($q4) use($keyword) { + // $q4->where('***', 'like', "%{$keyword}%"); + // }); + // }); + // } + // }, + // 'sorts' => [ + // ['field' => 'created_at', 'direction' => 'desc'] + // ], + // 'pagination' => [ + // 'page' => $params['page'] ?? 1, + // 'per_page' => $params['per_page'] ?? 10, + // ] + // ]; + // } + ]; + } +} \ No newline at end of file diff --git a/app/apis/service/BrandService.php b/app/apis/service/BrandService.php index 8f7aaee..dcd4933 100644 --- a/app/apis/service/BrandService.php +++ b/app/apis/service/BrandService.php @@ -27,12 +27,14 @@ class BrandService extends BaseService return [ 'default' => function ($params) { return [ - 'filters' => [ - ['field' => 'status', 'operator' => '=', 'value' => '1'] - ], - 'fields' => ['id', 'status', 'sort', 'created_at', 'updated_at'], + 'filters' => $params['filters'], + 'fields' => ['id', 'status', 'sort', 'toppic', 'descpic', 'logo', 'letter', 'is_hot', 'created_at', 'updated_at'], 'relations' => [ - 'translation' => ['brand_id', 'name'] + 'translation' => ['brand_id', 'name', 'desc','toppic_alt','descpic_alt','logo_alt'], + 'banners' => ['id', 'pic', 'sort',], + 'banners.translation' => ['id', 'alt',], + 'traits' => ['id', 'sort',], + 'traits.translation' => ['id', 'title', 'content',], ], 'sorts' => [ ['field' => 'id', 'direction' => 'desc'] @@ -43,6 +45,37 @@ class BrandService extends BaseService ] ]; }, + 'letter' => function ($params) { + return [ + 'filters' => $params['filters'], + 'fields' => ['id', 'status', 'sort', 'toppic', 'descpic', 'logo', 'letter', 'is_hot', 'created_at', 'updated_at'], + 'relations' => [ + 'translation' => ['brand_id', 'name', 'desc','toppic_alt','descpic_alt','logo_alt'], + 'banners' => ['id', 'pic', 'sort',], + 'banners.translation' => ['id', 'alt',], + 'traits' => ['id', 'sort',], + 'traits.translation' => ['id', 'title', 'content',], + ], + 'sorts' => [ + ['field' => 'id', 'direction' => 'desc'] + ], + ]; + }, + 'hot' => function ($params) { + return [ + 'filters' => [ + ['field' => 'status', 'operator' => '=', 'value' => '1'], + ['field' => 'is_hot', 'operator' => '=', 'value' => 1], + ], + 'fields' => ['id', 'status', 'sort', 'toppic', 'descpic', 'logo', 'letter', 'is_hot', 'created_at', 'updated_at'], + 'relations' => [ + 'translation' => ['brand_id', 'name'] + ], + 'sorts' => [ + ['field' => 'id', 'direction' => 'desc'] + ], + ]; + }, ]; } } \ No newline at end of file diff --git a/app/apis/service/BrandTraitService.php b/app/apis/service/BrandTraitService.php new file mode 100644 index 0000000..40483b7 --- /dev/null +++ b/app/apis/service/BrandTraitService.php @@ -0,0 +1,59 @@ + function ($params) { + // $keyword = $params['keyword'] ?? ''; + // return [ + // 'filters' => [ + // ['field' => '***', 'operator' => '=', 'value' => '***'] + // ], + // 'fields' => ['id'], + // 'relations' => [], + // 'custom' => function(Builder $q) use ($keyword) { + // // 示例 + // if ($keyword) { + // $q->where(function($q2) use($keyword) { + // $q2->whereHas('***', function($q3) use($keyword) { + // $q3->where('***', 'like', "%{$keyword}%"); + // })->orWhereHas('***', function($q4) use($keyword) { + // $q4->where('***', 'like', "%{$keyword}%"); + // }); + // }); + // } + // }, + // 'sorts' => [ + // ['field' => 'created_at', 'direction' => 'desc'] + // ], + // 'pagination' => [ + // 'page' => $params['page'] ?? 1, + // 'per_page' => $params['per_page'] ?? 10, + // ] + // ]; + // } + ]; + } +} \ No newline at end of file diff --git a/app/apis/service/BrandTraitTranslationService.php b/app/apis/service/BrandTraitTranslationService.php new file mode 100644 index 0000000..cdbb328 --- /dev/null +++ b/app/apis/service/BrandTraitTranslationService.php @@ -0,0 +1,59 @@ + function ($params) { + // $keyword = $params['keyword'] ?? ''; + // return [ + // 'filters' => [ + // ['field' => '***', 'operator' => '=', 'value' => '***'] + // ], + // 'fields' => ['id'], + // 'relations' => [], + // 'custom' => function(Builder $q) use ($keyword) { + // // 示例 + // if ($keyword) { + // $q->where(function($q2) use($keyword) { + // $q2->whereHas('***', function($q3) use($keyword) { + // $q3->where('***', 'like', "%{$keyword}%"); + // })->orWhereHas('***', function($q4) use($keyword) { + // $q4->where('***', 'like', "%{$keyword}%"); + // }); + // }); + // } + // }, + // 'sorts' => [ + // ['field' => 'created_at', 'direction' => 'desc'] + // ], + // 'pagination' => [ + // 'page' => $params['page'] ?? 1, + // 'per_page' => $params['per_page'] ?? 10, + // ] + // ]; + // } + ]; + } +} \ No newline at end of file diff --git a/app/apis/validate/BrandBannerTranslationValidator.php b/app/apis/validate/BrandBannerTranslationValidator.php new file mode 100644 index 0000000..aba6d95 --- /dev/null +++ b/app/apis/validate/BrandBannerTranslationValidator.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/apis/validate/BrandBannerValidator.php b/app/apis/validate/BrandBannerValidator.php new file mode 100644 index 0000000..7a9d1bd --- /dev/null +++ b/app/apis/validate/BrandBannerValidator.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/apis/validate/BrandTraitTranslationValidator.php b/app/apis/validate/BrandTraitTranslationValidator.php new file mode 100644 index 0000000..9a44e20 --- /dev/null +++ b/app/apis/validate/BrandTraitTranslationValidator.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/apis/validate/BrandTraitValidator.php b/app/apis/validate/BrandTraitValidator.php new file mode 100644 index 0000000..437f633 --- /dev/null +++ b/app/apis/validate/BrandTraitValidator.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/console/controller/BrandController.php b/app/console/controller/BrandController.php index 97d6bcb..d246cff 100644 --- a/app/console/controller/BrandController.php +++ b/app/console/controller/BrandController.php @@ -41,7 +41,6 @@ class BrandController extends BaseController */ protected function postProcessItem(array $item, string $scene): array { - if ($scene === 'default') { $result = [ 'id' => $item['id'], @@ -50,6 +49,7 @@ class BrandController extends BaseController 'toppic' => $item['toppic'], 'descpic' => $item['descpic'], 'logo' => $item['logo'], + 'is_hot' => $item['is_hot'], 'name' => isset($item['translation']) ? $item['translation']['name'] : '', 'desc' => isset($item['translation']) ? $item['translation']['desc'] : '', 'toppic_alt' => isset($item['translation']) ? $item['translation']['toppic_alt'] : '', diff --git a/config/route.php b/config/route.php index 1e2adba..abd0e5a 100644 --- a/config/route.php +++ b/config/route.php @@ -41,10 +41,14 @@ Route::group('/apis', function() { // 隐私协议 Route::any('/agt/privacy', [\app\apis\controller\AgreementController::class, 'one']); // 品牌按字母查询 -// Route::any('/brand/letterAll', [\app\apis\controller\BrandController::class, 'letterAll']); + Route::any('/brand/letterAll', [\app\apis\controller\BrandController::class, 'letterAll']); + // 品牌按字母查询 + Route::any('/brand/detail', [\app\apis\controller\BrandController::class, 'detail']); // 新车管理 Route::any('/vehicle/new/list', [\app\console\controller\VehicleNewController::class, 'index']); Route::any('/vehicle/new/{id}/detail', [\app\console\controller\VehicleNewController::class, 'detail']); + // 能源列表 + Route::any('/energy/preset', [\app\console\controller\EnergyController::class, 'presets']); }); // ====== ====== ====== 网站 ====== ====== ====== From 4a59c1dc0df80f540c3d48be68c36837ec5ab85f Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Fri, 23 May 2025 16:49:21 +0800 Subject: [PATCH 18/32] =?UTF-8?q?=E7=BD=91=E7=AB=99=E8=BD=A6=E8=BE=86?= =?UTF-8?q?=E7=AD=9B=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/apis/controller/BrandController.php | 20 ++++++++++++++++++-- app/apis/service/BrandService.php | 8 ++++++-- app/apis/service/VehicleNewService.php | 4 +--- config/route.php | 8 ++++---- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/app/apis/controller/BrandController.php b/app/apis/controller/BrandController.php index de01980..116ce5f 100644 --- a/app/apis/controller/BrandController.php +++ b/app/apis/controller/BrandController.php @@ -41,7 +41,7 @@ class BrandController extends BaseController */ protected function postProcessItem(array $item, string $scene): array { - if ($scene === 'default' || $scene === 'letter' || $scene === 'hot') { + if ($scene === 'default' || $scene === 'letter' || $scene === 'hot' || $scene === 'show') { $result = [ 'id' => $item['id'], 'status' => $item['status'], @@ -107,7 +107,7 @@ class BrandController extends BaseController $params['filters'][] = ['field' => 'is_hot', 'operator' => '=', 'value' => 1]; } } - + return $params; } @@ -141,4 +141,20 @@ class BrandController extends BaseController } } + /** + * 详情 + * + * @param Request $request 请求对象 + * @return Response 响应对象 + */ + public function detail(Request $request, int $id, string $scene = 'show'): Response + { + try { + $request->setGet(['id'=>$id]); + return parent::one($request, $scene); + } catch (\Throwable $th) { + return $this->errorResponse($th->getMessage()); + } + } + } \ No newline at end of file diff --git a/app/apis/service/BrandService.php b/app/apis/service/BrandService.php index dcd4933..37de96c 100644 --- a/app/apis/service/BrandService.php +++ b/app/apis/service/BrandService.php @@ -61,7 +61,7 @@ class BrandService extends BaseService ], ]; }, - 'hot' => function ($params) { + 'show' => function ($params) { return [ 'filters' => [ ['field' => 'status', 'operator' => '=', 'value' => '1'], @@ -69,7 +69,11 @@ class BrandService extends BaseService ], 'fields' => ['id', 'status', 'sort', 'toppic', 'descpic', 'logo', 'letter', 'is_hot', 'created_at', 'updated_at'], 'relations' => [ - 'translation' => ['brand_id', 'name'] + 'translation' => ['brand_id', 'name', 'desc','toppic_alt','descpic_alt','logo_alt'], + 'banners' => ['id', 'pic', 'sort',], + 'banners.translation' => ['id', 'alt',], + 'traits' => ['id', 'sort',], + 'traits.translation' => ['id', 'title', 'content',], ], 'sorts' => [ ['field' => 'id', 'direction' => 'desc'] diff --git a/app/apis/service/VehicleNewService.php b/app/apis/service/VehicleNewService.php index dbba182..f07d994 100644 --- a/app/apis/service/VehicleNewService.php +++ b/app/apis/service/VehicleNewService.php @@ -29,9 +29,7 @@ class VehicleNewService extends BaseService 'default' => function ($params) { $keyword = $params['keyword'] ?? ''; return [ - 'filters' => [ -// ['field' => '***', 'operator' => '=', 'value' => '***'] - ], + 'filters' => $params['filters'], 'fields' => ['id', 'vin', 'brand', 'cover', 'price', 'type', 'energy', 'model', 'video', 'views', 'created_at', 'updated_at'], 'relations' => [ 'translation' => ['vehicle_id', 'locale', 'name', 'condition_desc', 'location'], diff --git a/config/route.php b/config/route.php index abd0e5a..99beb21 100644 --- a/config/route.php +++ b/config/route.php @@ -42,11 +42,11 @@ Route::group('/apis', function() { Route::any('/agt/privacy', [\app\apis\controller\AgreementController::class, 'one']); // 品牌按字母查询 Route::any('/brand/letterAll', [\app\apis\controller\BrandController::class, 'letterAll']); - // 品牌按字母查询 - Route::any('/brand/detail', [\app\apis\controller\BrandController::class, 'detail']); + // 品牌详情 + Route::any('/brand/detail/{id}', [\app\apis\controller\BrandController::class, 'detail']); // 新车管理 - Route::any('/vehicle/new/list', [\app\console\controller\VehicleNewController::class, 'index']); - Route::any('/vehicle/new/{id}/detail', [\app\console\controller\VehicleNewController::class, 'detail']); + Route::any('/vehicle/new/list', [\app\apis\controller\VehicleNewController::class, 'index']); + Route::any('/vehicle/new/{id}/detail', [\app\apis\controller\VehicleNewController::class, 'detail']); // 能源列表 Route::any('/energy/preset', [\app\console\controller\EnergyController::class, 'presets']); }); From d292d6690fcf3607221e3b8b8e45577b86e3e771 Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Fri, 23 May 2025 16:54:08 +0800 Subject: [PATCH 19/32] =?UTF-8?q?=E8=BD=A6=E8=BE=86=E7=AD=9B=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/apis/controller/VehicleNewController.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/apis/controller/VehicleNewController.php b/app/apis/controller/VehicleNewController.php index 448c9ca..7f8661d 100644 --- a/app/apis/controller/VehicleNewController.php +++ b/app/apis/controller/VehicleNewController.php @@ -121,7 +121,12 @@ class VehicleNewController extends BaseController $params = parent::prepareParams($request, $scene); if ($scene === 'default') { - + if(!empty($params['brand'])){ + $params['filters'][] = ['field' => 'brand', 'operator' => '=', 'value' => $params['brand']]; + } + if(!empty($params['energy'])){ + $params['filters'][] = ['field' => 'energy', 'operator' => '=', 'value' => $params['energy']]; + } } return $params; From 17188855b6782f689464a45857a09376f65b1f3c Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Fri, 23 May 2025 17:49:11 +0800 Subject: [PATCH 20/32] =?UTF-8?q?=E5=93=81=E7=89=8C=E4=B8=8B=E8=83=BD?= =?UTF-8?q?=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/apis/controller/VehicleNewController.php | 16 ++++++++++++++++ app/apis/service/BrandService.php | 2 +- app/apis/service/VehicleNewService.php | 13 +++++++++++++ config/route.php | 2 ++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/app/apis/controller/VehicleNewController.php b/app/apis/controller/VehicleNewController.php index 7f8661d..9f549de 100644 --- a/app/apis/controller/VehicleNewController.php +++ b/app/apis/controller/VehicleNewController.php @@ -156,4 +156,20 @@ class VehicleNewController extends BaseController return $this->errorResponse($th->getMessage()); } } + + public function enegry(Request $request, string $scene = 'energy'): Response + { + try { + $enegry = VehicleNewService::enegry($request->all()); + foreach ($enegry as $key => $item) { + $enegry[$key] = [ + 'id' => $item['id'], + 'name' => $item['name'] + ]; + } + return $this->successResponse($enegry); + } catch (\Throwable $th) { + return $this->errorResponse($th->getMessage().$th->getLine().$th->getFile()); + } + } } \ No newline at end of file diff --git a/app/apis/service/BrandService.php b/app/apis/service/BrandService.php index 37de96c..e2683e4 100644 --- a/app/apis/service/BrandService.php +++ b/app/apis/service/BrandService.php @@ -65,7 +65,7 @@ class BrandService extends BaseService return [ 'filters' => [ ['field' => 'status', 'operator' => '=', 'value' => '1'], - ['field' => 'is_hot', 'operator' => '=', 'value' => 1], + ['field' => 'id', 'operator' => '=', 'value' => $params['id']], ], 'fields' => ['id', 'status', 'sort', 'toppic', 'descpic', 'logo', 'letter', 'is_hot', 'created_at', 'updated_at'], 'relations' => [ diff --git a/app/apis/service/VehicleNewService.php b/app/apis/service/VehicleNewService.php index f07d994..c444c01 100644 --- a/app/apis/service/VehicleNewService.php +++ b/app/apis/service/VehicleNewService.php @@ -2,6 +2,8 @@ namespace app\apis\service; +use app\apis\model\EnergyModel; +use app\apis\model\EnergyTranslationModel; use app\apis\model\VehicleNewModel; use app\mzl\common\services\BaseService; use Illuminate\Database\Eloquent\Builder; @@ -89,6 +91,17 @@ class VehicleNewService extends BaseService ]; } + public static function enegry($params) + { + $locale = locale(); + $energyId = VehicleNewModel::select('energy')->where(['brand'=>$params['brand']])->groupBy('energy')->get()->pluck('energy'); + $energys = EnergyModel::whereIn('id',$energyId)->get()->toArray(); + foreach ($energys as $key => $energy) { + $translation = EnergyTranslationModel::where(['locale'=>$locale,'energy_id'=>$energy['id']])->first()->toArray(); + $energys[$key]['name'] = isset($translation['name'])?$translation['name']:''; + } + return $energys; + } // 声明需要多语言翻译 protected array $translatable = [ diff --git a/config/route.php b/config/route.php index 99beb21..df60449 100644 --- a/config/route.php +++ b/config/route.php @@ -36,6 +36,8 @@ Route::group('/apis', function() { Route::any('/email/subscribe', [\app\apis\controller\SubscribeController::class, 'store']); // 车辆类型 Route::any('/vehicle/types', [\app\apis\controller\TypesController::class, 'all']); + // 品牌下车辆的能源类型 + Route::any('/vehicle/energy', [\app\apis\controller\VehicleNewController::class, 'enegry']); // 车辆随机 Route::any('/vehicle/random', [\app\apis\controller\VehicleDataController::class, 'random']); // 隐私协议 From 3c63565a02b61e394ceb09707400b812cc8443dd Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Mon, 26 May 2025 09:43:32 +0800 Subject: [PATCH 21/32] alt --- app/console/service/VehicleNewService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/console/service/VehicleNewService.php b/app/console/service/VehicleNewService.php index 076225d..9516f5f 100644 --- a/app/console/service/VehicleNewService.php +++ b/app/console/service/VehicleNewService.php @@ -352,7 +352,7 @@ class VehicleNewService extends BaseService } (new TranslationService())->queueTranslations( - 'VehicleNewAlbum', + 'vehicleNewAlbum', $albumId, $sourceLocale, $albumsourceFields From 61142de9c20377d67de012367fc4680f4a74642b Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Mon, 26 May 2025 10:47:48 +0800 Subject: [PATCH 22/32] =?UTF-8?q?=E5=9B=BE=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/console/model/VehicleNewAlbumTranslationModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/console/model/VehicleNewAlbumTranslationModel.php b/app/console/model/VehicleNewAlbumTranslationModel.php index 997da96..d02c1d0 100644 --- a/app/console/model/VehicleNewAlbumTranslationModel.php +++ b/app/console/model/VehicleNewAlbumTranslationModel.php @@ -47,7 +47,7 @@ class VehicleNewAlbumTranslationModel extends Model /** * 允许自动填充模型字段 */ - protected $fillable = ['id', 'content_id', 'locale', 'alt', 'created_at', 'updated_at']; + protected $fillable = ['id', 'album_id', 'locale', 'alt', 'created_at', 'updated_at']; /** * 不允许自动填充模型字段 From 628892dde6fb0e6d800c33cce894034a756c06a7 Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Mon, 26 May 2025 10:54:41 +0800 Subject: [PATCH 23/32] =?UTF-8?q?=E8=BD=A6=E8=BE=86=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/apis/controller/VehicleNewController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/apis/controller/VehicleNewController.php b/app/apis/controller/VehicleNewController.php index 9f549de..b28b832 100644 --- a/app/apis/controller/VehicleNewController.php +++ b/app/apis/controller/VehicleNewController.php @@ -121,6 +121,7 @@ class VehicleNewController extends BaseController $params = parent::prepareParams($request, $scene); if ($scene === 'default') { + $params['filters'] = []; if(!empty($params['brand'])){ $params['filters'][] = ['field' => 'brand', 'operator' => '=', 'value' => $params['brand']]; } 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 24/32] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=A6=96=E5=AD=97?= =?UTF-8?q?=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('提交失败'); From 665f46eb14cc626df96c64b89efb13d0697a5b0e Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Fri, 30 May 2025 15:35:28 +0800 Subject: [PATCH 25/32] =?UTF-8?q?=E5=93=81=E7=89=8C=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/console/controller/BrandController.php | 8 +++++++- app/console/controller/VehicleNewController.php | 11 ++++++++++- app/console/service/BrandService.php | 4 +--- app/console/service/VehicleNewService.php | 4 +--- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/console/controller/BrandController.php b/app/console/controller/BrandController.php index d246cff..d0bd426 100644 --- a/app/console/controller/BrandController.php +++ b/app/console/controller/BrandController.php @@ -107,7 +107,13 @@ class BrandController extends BaseController $params = parent::prepareParams($request, $scene); if ($scene === 'default') { - + $params['filters'] = []; + if(!empty($params['name'])){ + $params['filters'][] = ['field' => 'name', 'operator' => 'like', 'value' => '%'.$params['name'].'%']; + } + if($params['status'] != ''){ + $params['filters'][] = ['field' => 'status', 'operator' => '=', 'value' => $params['status']]; + } } return $params; diff --git a/app/console/controller/VehicleNewController.php b/app/console/controller/VehicleNewController.php index bcaecd5..6c57db6 100644 --- a/app/console/controller/VehicleNewController.php +++ b/app/console/controller/VehicleNewController.php @@ -120,7 +120,16 @@ class VehicleNewController extends BaseController $params = parent::prepareParams($request, $scene); if ($scene === 'default') { - + $params['filters'] = []; + if(!empty($params['brand'])){ + $params['filters'][] = ['field' => 'brand', 'operator' => '=', 'value' => $params['brand']]; + } + if(!empty($params['type'])){ + $params['filters'][] = ['field' => 'type', 'operator' => '=', 'value' => $params['type']]; + } + if(!empty($params['energy'])){ + $params['filters'][] = ['field' => 'energy', 'operator' => '=', 'value' => $params['energy']]; + } } return $params; diff --git a/app/console/service/BrandService.php b/app/console/service/BrandService.php index 494c434..6b6ce33 100644 --- a/app/console/service/BrandService.php +++ b/app/console/service/BrandService.php @@ -32,9 +32,7 @@ class BrandService extends BaseService return [ 'default' => function ($params) { return [ - 'filters' => [ - ['field' => 'status', 'operator' => '=', 'value' => '1'] - ], + 'filters' => $params['filters'], 'fields' => ['id', 'status', 'sort', 'toppic', 'descpic', 'logo', 'letter', 'is_hot', 'created_at', 'updated_at'], 'relations' => [ 'translation' => ['brand_id', 'name', 'desc','toppic_alt','descpic_alt','logo_alt'], diff --git a/app/console/service/VehicleNewService.php b/app/console/service/VehicleNewService.php index 9ea6dff..de76ab2 100644 --- a/app/console/service/VehicleNewService.php +++ b/app/console/service/VehicleNewService.php @@ -35,9 +35,7 @@ class VehicleNewService extends BaseService 'default' => function ($params) { $keyword = $params['keyword'] ?? ''; return [ - 'filters' => [ -// ['field' => '***', 'operator' => '=', 'value' => '***'] - ], + 'filters' => $params['filters'], 'fields' => ['id', 'vin', 'brand', 'cover', 'price', 'type', 'energy', 'model', 'video', 'views', 'created_at', 'updated_at'], 'relations' => [ 'translation' => ['vehicle_id', 'locale', 'name', 'condition_desc', 'location'], From b28f9d75301c39327a9747ea80d58f2b7ba7dbb4 Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Fri, 30 May 2025 15:50:57 +0800 Subject: [PATCH 26/32] =?UTF-8?q?=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/console/controller/BrandController.php | 8 +++++--- app/console/controller/VehicleNewController.php | 5 +++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/console/controller/BrandController.php b/app/console/controller/BrandController.php index d0bd426..ab88108 100644 --- a/app/console/controller/BrandController.php +++ b/app/console/controller/BrandController.php @@ -4,6 +4,7 @@ namespace app\console\controller; use app\console\model\BrandBannerModel; use app\console\model\BrandTraitModel; +use app\console\model\BrandTranslationModel; use support\Request; use support\Response; use app\console\model\BrandModel; @@ -108,12 +109,13 @@ class BrandController extends BaseController if ($scene === 'default') { $params['filters'] = []; - if(!empty($params['name'])){ - $params['filters'][] = ['field' => 'name', 'operator' => 'like', 'value' => '%'.$params['name'].'%']; - } if($params['status'] != ''){ $params['filters'][] = ['field' => 'status', 'operator' => '=', 'value' => $params['status']]; } + if(!empty($params['name'])){ + $id = BrandTranslationModel::where('name', 'like', '%'.$params['name'].'%')->pluck('id')->toArray(); + $params['filters'][] = ['field' => 'id', 'operator' => 'in', 'value' => $id]; + } } return $params; diff --git a/app/console/controller/VehicleNewController.php b/app/console/controller/VehicleNewController.php index 6c57db6..0156f8a 100644 --- a/app/console/controller/VehicleNewController.php +++ b/app/console/controller/VehicleNewController.php @@ -2,6 +2,7 @@ namespace app\console\controller; +use app\console\model\VehicleNewTranslationModel; use support\Request; use support\Response; use app\console\model\VehicleNewModel; @@ -130,6 +131,10 @@ class VehicleNewController extends BaseController if(!empty($params['energy'])){ $params['filters'][] = ['field' => 'energy', 'operator' => '=', 'value' => $params['energy']]; } + if(!empty($params['name_like'])){ + $id = VehicleNewTranslationModel::where('name', 'like', '%'.$params['name_like'].'%')->pluck('id')->toArray(); + $params['filters'][] = ['field' => 'id', 'operator' => 'in', 'value' => $id]; + } } return $params; From d16d5a420236a40f2b629a4fb964fd2395cf874f Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Fri, 30 May 2025 15:55:16 +0800 Subject: [PATCH 27/32] =?UTF-8?q?=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/console/controller/BrandController.php | 2 +- app/console/controller/VehicleNewController.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/console/controller/BrandController.php b/app/console/controller/BrandController.php index ab88108..1637be1 100644 --- a/app/console/controller/BrandController.php +++ b/app/console/controller/BrandController.php @@ -113,7 +113,7 @@ class BrandController extends BaseController $params['filters'][] = ['field' => 'status', 'operator' => '=', 'value' => $params['status']]; } if(!empty($params['name'])){ - $id = BrandTranslationModel::where('name', 'like', '%'.$params['name'].'%')->pluck('id')->toArray(); + $id = BrandTranslationModel::where('name', 'like', '%'.$params['name'].'%')->pluck('brand_id')->toArray(); $params['filters'][] = ['field' => 'id', 'operator' => 'in', 'value' => $id]; } } diff --git a/app/console/controller/VehicleNewController.php b/app/console/controller/VehicleNewController.php index 0156f8a..c46ae08 100644 --- a/app/console/controller/VehicleNewController.php +++ b/app/console/controller/VehicleNewController.php @@ -132,7 +132,7 @@ class VehicleNewController extends BaseController $params['filters'][] = ['field' => 'energy', 'operator' => '=', 'value' => $params['energy']]; } if(!empty($params['name_like'])){ - $id = VehicleNewTranslationModel::where('name', 'like', '%'.$params['name_like'].'%')->pluck('id')->toArray(); + $id = VehicleNewTranslationModel::where('name', 'like', '%'.$params['name_like'].'%')->pluck('vehicle_id')->toArray(); $params['filters'][] = ['field' => 'id', 'operator' => 'in', 'value' => $id]; } } From 923e0495d00a5b0f540ccf9e497e30943d6ec729 Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Fri, 30 May 2025 16:29:08 +0800 Subject: [PATCH 28/32] 1 --- app/console/controller/BrandController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/console/controller/BrandController.php b/app/console/controller/BrandController.php index 1637be1..b8bce33 100644 --- a/app/console/controller/BrandController.php +++ b/app/console/controller/BrandController.php @@ -109,7 +109,7 @@ class BrandController extends BaseController if ($scene === 'default') { $params['filters'] = []; - if($params['status'] != ''){ + if(isset($params['status']) && $params['status'] != ''){ $params['filters'][] = ['field' => 'status', 'operator' => '=', 'value' => $params['status']]; } if(!empty($params['name'])){ From 4c4e1a70cfee55771859abedc4f287ac3672a0cc Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Fri, 30 May 2025 16:47:06 +0800 Subject: [PATCH 29/32] 1 --- app/console/service/BrandService.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/console/service/BrandService.php b/app/console/service/BrandService.php index 6b6ce33..ebdc61f 100644 --- a/app/console/service/BrandService.php +++ b/app/console/service/BrandService.php @@ -11,6 +11,7 @@ use Illuminate\Database\Eloquent\Model; use support\exception\BusinessException; use support\Db; use app\mzl\modules\translation\service\TranslationService; +use support\Log; class BrandService extends BaseService { @@ -166,6 +167,7 @@ class BrandService extends BaseService Db::beginTransaction(); try { $info = $this->update($id, $params); + log::info($info); if (!$info) { throw new BusinessException('提交失败'); } From 9e1cc5a804734e0b36bebb25152fac1c34c7938a Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Fri, 30 May 2025 16:58:03 +0800 Subject: [PATCH 30/32] 1 --- app/console/model/BrandTranslationModel.php | 2 +- app/console/service/BrandService.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/console/model/BrandTranslationModel.php b/app/console/model/BrandTranslationModel.php index 199958b..ffbd70a 100644 --- a/app/console/model/BrandTranslationModel.php +++ b/app/console/model/BrandTranslationModel.php @@ -69,7 +69,7 @@ class BrandTranslationModel extends Model static::saved(function ($model) { // 业务逻辑 if($model->locale == 'en'){ - BrandModel::updateOrCreate(['id' => $model->id],['letter' => mb_substr($model->name, 0, 1, 'UTF-8')]); + BrandModel::updateOrCreate(['id' => $model->brand_id],['letter' => mb_substr($model->name, 0, 1, 'UTF-8')]); } }); } diff --git a/app/console/service/BrandService.php b/app/console/service/BrandService.php index ebdc61f..40b7090 100644 --- a/app/console/service/BrandService.php +++ b/app/console/service/BrandService.php @@ -167,7 +167,6 @@ class BrandService extends BaseService Db::beginTransaction(); try { $info = $this->update($id, $params); - log::info($info); if (!$info) { throw new BusinessException('提交失败'); } From 459530fd269424a36a70448be5c1d5b8e393ee0f Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Tue, 3 Jun 2025 13:06:13 +0800 Subject: [PATCH 31/32] 1 --- app/apis/controller/BrandController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/apis/controller/BrandController.php b/app/apis/controller/BrandController.php index 116ce5f..aa3ee6e 100644 --- a/app/apis/controller/BrandController.php +++ b/app/apis/controller/BrandController.php @@ -135,7 +135,7 @@ class BrandController extends BaseController public function letterAll(Request $request, string $scene = 'letter'): Response { try { - return parent::index($request, $scene); + return parent::all($request, $scene); } catch (\Throwable $th) { return $this->errorResponse($th->getMessage()); } From 8b94fde0a2372464353ac386aa24b7b1bfaa844e Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Tue, 3 Jun 2025 13:24:31 +0800 Subject: [PATCH 32/32] 1 --- app/apis/controller/BrandController.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/apis/controller/BrandController.php b/app/apis/controller/BrandController.php index aa3ee6e..0376ac6 100644 --- a/app/apis/controller/BrandController.php +++ b/app/apis/controller/BrandController.php @@ -4,6 +4,7 @@ namespace app\apis\controller; use app\apis\model\BrandBannerModel; use app\apis\model\BrandTraitModel; +use app\apis\model\BrandTranslationModel; use support\Request; use support\Response; use app\apis\model\BrandModel; @@ -58,6 +59,10 @@ class BrandController extends BaseController 'created_at' => date('Y-m-d H:i:s', $item['created_at']), 'updated_at' => date('Y-m-d H:i:s', $item['updated_at']), ]; + if($scene === 'letter'){ + $brand = BrandTranslationModel::where(['brand_id' => $item['id'],'locale' => 'en'])->first(); + $result['name'] = isset($brand['name'])?$brand['name']:$result['name']; + } if ($item['toppic']) { $result['toppic_full'] = (new \app\mzl\modules\upload\service\OssService())->generatePrivateUrl($item['toppic']); }