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..0376ac6 100644 --- a/app/apis/controller/BrandController.php +++ b/app/apis/controller/BrandController.php @@ -2,6 +2,9 @@ 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; @@ -39,7 +42,54 @@ class BrandController extends BaseController */ protected function postProcessItem(array $item, string $scene): array { - + if ($scene === 'default' || $scene === 'letter' || $scene === 'hot' || $scene === 'show') { + $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($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']); + } + 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,10 +103,16 @@ 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 +130,36 @@ 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::all($request, $scene); + } catch (\Throwable $th) { + return $this->errorResponse($th->getMessage()); + } + } + + /** + * 详情 + * + * @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/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/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..b28b832 --- /dev/null +++ b/app/apis/controller/VehicleNewController.php @@ -0,0 +1,176 @@ + $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') { + $params['filters'] = []; + 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; + } + + /** + * 分页 + * + * @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()); + } + } + + 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/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/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/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/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..e2683e4 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,41 @@ 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'] + ], + ]; + }, + 'show' => function ($params) { + return [ + 'filters' => [ + ['field' => 'status', 'operator' => '=', 'value' => '1'], + ['field' => 'id', 'operator' => '=', 'value' => $params['id']], + ], + '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'] + ], + ]; + }, ]; } } \ 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/service/VehicleNewAlbumService.php b/app/apis/service/VehicleNewAlbumService.php new file mode 100644 index 0000000..eb3a9bd --- /dev/null +++ b/app/apis/service/VehicleNewAlbumService.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/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..c444c01 --- /dev/null +++ b/app/apis/service/VehicleNewService.php @@ -0,0 +1,110 @@ + function ($params) { + $keyword = $params['keyword'] ?? ''; + return [ + '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'], + '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, + ] + ]; + } + ]; + } + + 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 = [ + '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/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/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/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..b8bce33 100644 --- a/app/console/controller/BrandController.php +++ b/app/console/controller/BrandController.php @@ -2,6 +2,9 @@ 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; @@ -39,16 +42,49 @@ class BrandController extends BaseController */ protected function postProcessItem(array $item, string $scene): array { - if ($scene === 'default') { - return [ + $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']) + '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; } if ($scene === 'preset') { @@ -72,7 +108,14 @@ class BrandController extends BaseController $params = parent::prepareParams($request, $scene); if ($scene === 'default') { - + $params['filters'] = []; + if(isset($params['status']) && $params['status'] != ''){ + $params['filters'][] = ['field' => 'status', 'operator' => '=', 'value' => $params['status']]; + } + if(!empty($params['name'])){ + $id = BrandTranslationModel::where('name', 'like', '%'.$params['name'].'%')->pluck('brand_id')->toArray(); + $params['filters'][] = ['field' => 'id', 'operator' => 'in', 'value' => $id]; + } } return $params; @@ -86,6 +129,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 +154,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 +165,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/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..c46ae08 --- /dev/null +++ b/app/console/controller/VehicleNewController.php @@ -0,0 +1,189 @@ + $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') { + $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']]; + } + if(!empty($params['name_like'])){ + $id = VehicleNewTranslationModel::where('name', 'like', '%'.$params['name_like'].'%')->pluck('vehicle_id')->toArray(); + $params['filters'][] = ['field' => 'id', 'operator' => 'in', 'value' => $id]; + } + } + + return $params; + } + + public function add(Request $request): Response + { + try { + return $this->getService()->add($request->all()) + ? $this->successResponse() + : $this->errorResponse(); + } catch (\Throwable $th) { + return $this->errorResponse($th->getMessage().$th->getLine().$th->getFile()); + } + } + + 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()); + } + } + + /** + * 分页 + * + * @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->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()); + } + } +} \ 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/BrandBannerModel.php b/app/console/model/BrandBannerModel.php new file mode 100644 index 0000000..b2d1cf4 --- /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, '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/console/model/BrandBannerTranslationModel.php b/app/console/model/BrandBannerTranslationModel.php new file mode 100644 index 0000000..00df108 --- /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..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', 'created_at', 'updated_at']; + protected $fillable = ['id', 'status', 'sort', 'toppic', 'descpic', 'logo', 'letter', 'is_hot', '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..cf4c671 --- /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 = [ + 'title', 'content' + ]; +} \ 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..ffbd70a 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']; /** * 不允许自动填充模型字段 @@ -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->brand_id],['letter' => mb_substr($model->name, 0, 1, 'UTF-8')]); + } + }); + } } \ 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..f5853c2 --- /dev/null +++ b/app/console/model/VehicleNewAlbumModel.php @@ -0,0 +1,79 @@ +hasOne(VehicleNewAlbumTranslationModel::class, 'album_id')->where('locale', locale()); + } + + /** + * 多条翻译 + */ + public function translations() + { + return $this->hasMany(VehicleNewAlbumTranslationModel::class, 'album_id'); + } + + const VEHICLE_NEW_ALBUM_FIELDS = [ + 'pic', + ]; + const TRANS_FIELDS = [ + 'alt', + ]; +} \ 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..d02c1d0 --- /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) { + 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..40b7090 100644 --- a/app/console/service/BrandService.php +++ b/app/console/service/BrandService.php @@ -2,13 +2,16 @@ 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; use support\exception\BusinessException; use support\Db; use app\mzl\modules\translation\service\TranslationService; +use support\Log; class BrandService extends BaseService { @@ -30,12 +33,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'] @@ -65,12 +70,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 +104,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('提交失败'); + } + // 异步翻译并写入 hs_brand_banner_translation 表 + (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 +151,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 +179,73 @@ class BrandService extends BaseService $sourceFields ); + //品牌轮播图 + $bannersId = []; + foreach ($banners as $banner) { + $bannersourceFields = $BrandBannerService->extractSourceFields($banner); + $bannersourceFields['brand_id'] = $id; + $banner['brand_id'] = $id; + + 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( + 'brandBanner', + $bannerId, + $sourceLocale, + $bannersourceFields + ); + } + BrandBannerModel::whereNotIn('id', $bannersId)->where('brand_id',$id)->delete(); + + //品牌特性 + $traitsId = []; + foreach ($traits as $trait) { + $traitsourceFields = $BrandTraitService->extractSourceFields($trait); + $traitsourceFields['brand_id'] = $id; + $trait['brand_id'] = $id; + + 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( + 'brandTrait', + $traitId, + $sourceLocale, + $traitsourceFields + ); + } + BrandTraitModel::whereNotIn('id', $traitsId)->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/service/VehicleNewAlbumService.php b/app/console/service/VehicleNewAlbumService.php new file mode 100644 index 0000000..52ae634 --- /dev/null +++ b/app/console/service/VehicleNewAlbumService.php @@ -0,0 +1,64 @@ + 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..3d95f2b --- /dev/null +++ b/app/console/service/VehicleNewContentService.php @@ -0,0 +1,64 @@ + 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 = [ + 'content', + ]; +} \ 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..de76ab2 --- /dev/null +++ b/app/console/service/VehicleNewService.php @@ -0,0 +1,434 @@ + function ($params) { + $keyword = $params['keyword'] ?? ''; + return [ + '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'], + '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', + ]; + + 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 { + if(empty($params['model'])){ + $params['model'] = 0; + } + $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; + $album_res = $VehicleNewAlbumService->create($album); + if (!$album_res) { + throw new BusinessException('提交失败'); + } + (new TranslationService())->queueTranslations( + 'vehicleNewAlbum', + $album_res->id, + $sourceLocale, + $albumsourceFields + ); + } + + foreach ($contents as $content) { + $contentsourceFields = $VehicleNewContentService->extractSourceFields($content); + $content['vehicle_id'] = $info->id; + $content_res = $VehicleNewContentService->create($content); + if (!$content_res) { + throw new BusinessException('提交失败'); + } + + (new TranslationService())->queueTranslations( + 'vehicleNewContent', + $content_res->id, + $sourceLocale, + $contentsourceFields + ); + } + + Db::commit(); + return true; + } 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} 语言的翻译字段"); + }; + + $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 { + if(empty($params['model'])){ + $params['model'] = 0; + } + $info = $this->update($id, $params); + if (!$info) { + throw new BusinessException('提交失败'); + } + + // 异步翻译并写入 hs_vehicle_data_translation 表 + (new TranslationService())->queueTranslations( + 'vehicleNew', + $id, + $sourceLocale, + $sourceFields + ); + + $askedsId = []; + foreach ($askeds as $asked) { + $askedsourceFields = $VehicleNewAskedService->extractSourceFields($asked); + $asked['vehicle_id'] = $id; + if(!empty($asked['id'])){ + $askedId = $asked['id']; + $askedsId[] = $askedId; + $asked_res = $VehicleNewAskedService->update($askedId, $asked); + if (!$asked_res) { + throw new BusinessException('提交失败:常见问题2'); + } + } else { + unset($asked['id']); + $asked_res = $VehicleNewAskedService->create($asked); + if (!$asked_res) { + throw new BusinessException('提交失败:常见问题1'); + } + $askedId = $asked_res->id; + $askedsId[] = $askedId; + } + (new TranslationService())->queueTranslations( + 'vehicleNewAsked', + $askedId, + $sourceLocale, + $askedsourceFields + ); + } + VehicleNewAskedModel::whereNotIn('id', $askedsId)->where('vehicle_id',$id)->delete(); + + $traitsId = []; + foreach ($traits as $trait) { + $traitsourceFields = $VehicleNewTraitService->extractSourceFields($trait); + $trait['vehicle_id'] = $id; + if(!empty($trait['id'])){ + $traitId = $trait['id']; + $traitsId[] = $traitId; + $trait_res = $VehicleNewTraitService->update($traitId, $trait); + if (!$trait_res) { + throw new BusinessException('提交失败:车辆特性'); + } + } else { + unset($trait['id']); + $trait_res = $VehicleNewTraitService->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(); + + $albumsId = []; + 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('提交失败'); +// } + + if(!empty($album['id'])){ + $albumId =$album['id']; + $albumsId[] =$albumId; + $album_res = $VehicleNewAlbumService->update($albumId,$album); + if (!$album_res) { + throw new BusinessException('提交失败:车辆图册'); + } + } else { + unset($album['id']); + $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 + ); + } + VehicleNewAlbumModel::whereNotIn('id', $albumsId)->where('vehicle_id',$id)->delete(); + + $contentsId = []; + 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('提交失败'); +// } + + if(!empty($content['id'])){ + $contentId =$content['id']; + $contentsId[] =$contentId; + $content_res = $VehicleNewContentService->update($contentId,$content); + if (!$content_res) { + throw new BusinessException('提交失败:车辆介绍1'); + } + } else { + unset($content['id']); + $content_res = $VehicleNewContentService->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([ + // '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/app/console/service/VehicleNewTraitService.php b/app/console/service/VehicleNewTraitService.php new file mode 100644 index 0000000..46b38c2 --- /dev/null +++ b/app/console/service/VehicleNewTraitService.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/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/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/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 01b353a..751ccbc 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', @@ -30,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 f690160..d9244dd 100644 --- a/config/route.php +++ b/config/route.php @@ -36,10 +36,21 @@ 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']); // 隐私协议 Route::any('/agt/privacy', [\app\apis\controller\AgreementController::class, 'one']); + // 品牌按字母查询 + Route::any('/brand/letterAll', [\app\apis\controller\BrandController::class, 'letterAll']); + // 品牌详情 + Route::any('/brand/detail/{id}', [\app\apis\controller\BrandController::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']); }); // ====== ====== ====== 网站 ====== ====== ====== @@ -124,6 +135,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']); @@ -154,6 +177,13 @@ 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/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']); + // 上传 Route::any('/upload/image', [\app\mzl\modules\upload\controller\UploadController::class, 'uploadImage']);