Initial commit

This commit is contained in:
18338781771
2025-05-14 13:19:23 +08:00
commit 1ab607f65a
313 changed files with 27595 additions and 0 deletions
+117
View File
@@ -0,0 +1,117 @@
<?php
namespace app\console\service;
use app\console\model\AgreementModel;
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;
class AgreementService extends BaseService
{
/**
* 定义模型
*
* @return string
*/
public function getModel(): string
{
return AgreementModel::class;
}
/**
* 多场景配置
*/
public function queryScenes(): array
{
return [
'default' => function ($params) {
return [
'filters' => [
['field' => 'status', 'operator' => '=', 'value' => '1']
],
'fields' => ['id', 'key', 'status', 'created_at', 'updated_at'],
'relations' => [
'translation' => ['agreement_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);
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(
'agreement',
$info->id,
$sourceLocale,
$sourceFields
);
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} 语言的翻译字段");
};
Db::beginTransaction();
try {
$info = $this->update($id, $params);
if (!$info) {
throw new BusinessException('提交失败');
}
// 异步翻译并写入 hs_vehicle_data_translation 表
(new TranslationService())->queueTranslations(
'agreement',
$id,
$sourceLocale,
$sourceFields
);
Db::commit();
return true;
} catch (\Throwable $th) {
Db::rollBack();
throw $th;
}
}
}
@@ -0,0 +1,59 @@
<?php
namespace app\console\service;
use app\console\model\AgreementTranslationModel;
use app\mzl\common\services\BaseService;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
class AgreementTranslationService extends BaseService
{
/**
* 定义模型
*
* @return string
*/
public function getModel(): string
{
return AgreementTranslationModel::class;
}
/**
* 多场景配置
*/
public function queryScenes(): array
{
return [
// 'default' => 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,
// ]
// ];
// }
];
}
}
+132
View File
@@ -0,0 +1,132 @@
<?php
namespace app\console\service;
use app\console\model\BrandModel;
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;
class BrandService extends BaseService
{
/**
* 定义模型
*
* @return string
*/
public function getModel(): string
{
return BrandModel::class;
}
/**
* 多场景配置
*/
public function queryScenes(): array
{
return [
'default' => function ($params) {
return [
'filters' => [
['field' => 'status', 'operator' => '=', 'value' => '1']
],
'fields' => ['id', 'status', 'sort', 'created_at', 'updated_at'],
'relations' => [
'translation' => ['brand_id', 'name']
],
'sorts' => [
['field' => 'id', 'direction' => 'desc']
],
'pagination' => [
'page' => $params['page'] ?? 1,
'per_page' => $params['per_page'] ?? 10,
]
];
},
'preset' => function ($params) {
return [
'filters' => [
['field' => 'status', 'operator' => '=', 'value' => '1']
],
'fields' => ['id'],
'relations' => [
'translation' => ['brand_id', 'name']
],
'sorts' => [
['field' => 'id', 'direction' => 'desc']
]
];
}
];
}
protected array $translatable = [
'name'
];
public function add(array $params)
{
$sourceLocale = locale();
$sourceFields = $this->extractSourceFields($params);
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(
'brand',
$info->id,
$sourceLocale,
$sourceFields
);
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} 语言的翻译字段");
};
Db::beginTransaction();
try {
$info = $this->update($id, $params);
if (!$info) {
throw new BusinessException('提交失败');
}
// 异步翻译并写入 hs_vehicle_data_translation 表
(new TranslationService())->queueTranslations(
'brand',
$id,
$sourceLocale,
$sourceFields
);
Db::commit();
return true;
} catch (\Throwable $th) {
Db::rollBack();
throw $th;
}
}
}
@@ -0,0 +1,59 @@
<?php
namespace app\console\service;
use app\console\model\BrandTranslationModel;
use app\mzl\common\services\BaseService;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
class BrandTranslationService extends BaseService
{
/**
* 定义模型
*
* @return string
*/
public function getModel(): string
{
return BrandTranslationModel::class;
}
/**
* 多场景配置
*/
public function queryScenes(): array
{
return [
// 'default' => 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,
// ]
// ];
// }
];
}
}
+59
View File
@@ -0,0 +1,59 @@
<?php
namespace app\console\service;
use app\console\model\DraftsModel;
use app\mzl\common\services\BaseService;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
class DraftsService extends BaseService
{
/**
* 定义模型
*
* @return string
*/
public function getModel(): string
{
return DraftsModel::class;
}
/**
* 多场景配置
*/
public function queryScenes(): array
{
return [
// 'default' => 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,
// ]
// ];
// }
];
}
}
+131
View File
@@ -0,0 +1,131 @@
<?php
namespace app\console\service;
use app\console\model\EnergyModel;
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;
class EnergyService extends BaseService
{
/**
* 定义模型
*
* @return string
*/
public function getModel(): string
{
return EnergyModel::class;
}
/**
* 多场景配置
*/
public function queryScenes(): array
{
return [
'default' => function ($params) {
return [
'filters' => [
['field' => 'status', 'operator' => '=', 'value' => '1']
],
'fields' => ['id', 'status', 'sort', 'created_at', 'updated_at'],
'relations' => [
'translation' => ['energy_id', 'name']
],
'sorts' => [
['field' => 'id', 'direction' => 'desc']
],
'pagination' => [
'page' => $params['page'] ?? 1,
'per_page' => $params['per_page'] ?? 10,
]
];
},
'preset' => function ($params) {
return [
'filters' => [
['field' => 'status', 'operator' => '=', 'value' => '1']
],
'fields' => ['id'],
'relations' => [
'translation' => ['energy_id', 'name']
],
'sorts' => [
['field' => 'id', 'direction' => 'desc']
]
];
}
];
}
protected array $translatable = [
'name'
];
public function add(array $params)
{
$sourceLocale = locale();
$sourceFields = $this->extractSourceFields($params);
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(
'energy',
$info->id,
$sourceLocale,
$sourceFields
);
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} 语言的翻译字段");
};
Db::beginTransaction();
try {
$info = $this->update($id, $params);
if (!$info) {
throw new BusinessException('提交失败');
}
// 异步翻译并写入 hs_vehicle_data_translation 表
(new TranslationService())->queueTranslations(
'energy',
$id,
$sourceLocale,
$sourceFields
);
Db::commit();
return true;
} catch (\Throwable $th) {
Db::rollBack();
throw $th;
}
}
}
@@ -0,0 +1,59 @@
<?php
namespace app\console\service;
use app\console\model\EnergyTranslationModel;
use app\mzl\common\services\BaseService;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
class EnergyTranslationService extends BaseService
{
/**
* 定义模型
*
* @return string
*/
public function getModel(): string
{
return EnergyTranslationModel::class;
}
/**
* 多场景配置
*/
public function queryScenes(): array
{
return [
// 'default' => 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,
// ]
// ];
// }
];
}
}
+131
View File
@@ -0,0 +1,131 @@
<?php
namespace app\console\service;
use app\console\model\LocationModel;
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;
class LocationService extends BaseService
{
/**
* 定义模型
*
* @return string
*/
public function getModel(): string
{
return LocationModel::class;
}
/**
* 多场景配置
*/
public function queryScenes(): array
{
return [
'default' => function ($params) {
return [
'filters' => [
['field' => 'status', 'operator' => '=', 'value' => '1']
],
'fields' => ['id', 'status', 'sort', 'created_at', 'updated_at'],
'relations' => [
'translation' => ['location_id', 'name']
],
'sorts' => [
['field' => 'id', 'direction' => 'desc']
],
'pagination' => [
'page' => $params['page'] ?? 1,
'per_page' => $params['per_page'] ?? 10,
]
];
},
'preset' => function ($params) {
return [
'filters' => [
['field' => 'status', 'operator' => '=', 'value' => '1']
],
'fields' => ['id'],
'relations' => [
'translation' => ['location_id', 'name']
],
'sorts' => [
['field' => 'id', 'direction' => 'desc']
]
];
}
];
}
protected array $translatable = [
'name'
];
public function add(array $params)
{
$sourceLocale = locale();
$sourceFields = $this->extractSourceFields($params);
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(
'location',
$info->id,
$sourceLocale,
$sourceFields
);
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} 语言的翻译字段");
};
Db::beginTransaction();
try {
$info = $this->update($id, $params);
if (!$info) {
throw new BusinessException('提交失败');
}
// 异步翻译并写入 hs_vehicle_data_translation 表
(new TranslationService())->queueTranslations(
'location',
$id,
$sourceLocale,
$sourceFields
);
Db::commit();
return true;
} catch (\Throwable $th) {
Db::rollBack();
throw $th;
}
}
}
@@ -0,0 +1,59 @@
<?php
namespace app\console\service;
use app\console\model\LocationTranslationModel;
use app\mzl\common\services\BaseService;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
class LocationTranslationService extends BaseService
{
/**
* 定义模型
*
* @return string
*/
public function getModel(): string
{
return LocationTranslationModel::class;
}
/**
* 多场景配置
*/
public function queryScenes(): array
{
return [
// 'default' => 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,
// ]
// ];
// }
];
}
}
+133
View File
@@ -0,0 +1,133 @@
<?php
namespace app\console\service;
use app\console\model\ModelModel;
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;
class ModelService extends BaseService
{
/**
* 定义模型
*
* @return string
*/
public function getModel(): string
{
return ModelModel::class;
}
/**
* 多场景配置
*/
public function queryScenes(): array
{
return [
'default' => function ($params) {
return [
'filters' => [
['field' => 'status', 'operator' => '=', 'value' => '1']
],
'fields' => ['id', 'brand_id', 'status', 'sort', 'created_at', 'updated_at'],
'relations' => [
'translation' => ['model_id', 'name'],
'brand.translation' => ['brand_id', 'name']
],
'sorts' => [
['field' => 'id', 'direction' => 'desc']
],
'pagination' => [
'page' => $params['page'] ?? 1,
'per_page' => $params['per_page'] ?? 10,
]
];
},
'preset' => function ($params) {
return [
'filters' => [
['field' => 'status', 'operator' => '=', 'value' => '1'],
['field' => 'brand_id', 'operator' => '=', 'value' => $params['brand_id']]
],
'fields' => ['id'],
'relations' => [
'translation' => ['model_id', 'name']
],
'sorts' => [
['field' => 'id', 'direction' => 'desc']
]
];
}
];
}
protected array $translatable = [
'name'
];
public function add(array $params)
{
$sourceLocale = locale();
$sourceFields = $this->extractSourceFields($params);
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(
'model',
$info->id,
$sourceLocale,
$sourceFields
);
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} 语言的翻译字段");
};
Db::beginTransaction();
try {
$info = $this->update($id, $params);
if (!$info) {
throw new BusinessException('提交失败');
}
// 异步翻译并写入 hs_vehicle_data_translation 表
(new TranslationService())->queueTranslations(
'model',
$id,
$sourceLocale,
$sourceFields
);
Db::commit();
return true;
} catch (\Throwable $th) {
Db::rollBack();
throw $th;
}
}
}
@@ -0,0 +1,59 @@
<?php
namespace app\console\service;
use app\console\model\ModelTranslationModel;
use app\mzl\common\services\BaseService;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
class ModelTranslationService extends BaseService
{
/**
* 定义模型
*
* @return string
*/
public function getModel(): string
{
return ModelTranslationModel::class;
}
/**
* 多场景配置
*/
public function queryScenes(): array
{
return [
// 'default' => 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,
// ]
// ];
// }
];
}
}
+131
View File
@@ -0,0 +1,131 @@
<?php
namespace app\console\service;
use app\console\model\TypesModel;
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;
class TypesService extends BaseService
{
/**
* 定义模型
*
* @return string
*/
public function getModel(): string
{
return TypesModel::class;
}
/**
* 多场景配置
*/
public function queryScenes(): array
{
return [
'default' => function ($params) {
return [
'filters' => [
['field' => 'status', 'operator' => '=', 'value' => '1']
],
'fields' => ['id', 'img', 'status', 'sort', 'created_at', 'updated_at'],
'relations' => [
'translation' => ['type_id', 'name']
],
'sorts' => [
['field' => 'id', 'direction' => 'desc']
],
'pagination' => [
'page' => $params['page'] ?? 1,
'per_page' => $params['per_page'] ?? 10,
]
];
},
'preset' => function ($params) {
return [
'filters' => [
['field' => 'status', 'operator' => '=', 'value' => '1']
],
'fields' => ['id'],
'relations' => [
'translation' => ['type_id', 'name']
],
'sorts' => [
['field' => 'id', 'direction' => 'desc']
]
];
}
];
}
protected array $translatable = [
'name'
];
public function add(array $params)
{
$sourceLocale = locale();
$sourceFields = $this->extractSourceFields($params);
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(
'type',
$info->id,
$sourceLocale,
$sourceFields
);
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} 语言的翻译字段");
};
Db::beginTransaction();
try {
$info = $this->update($id, $params);
if (!$info) {
throw new BusinessException('提交失败');
}
// 异步翻译并写入 hs_vehicle_data_translation 表
(new TranslationService())->queueTranslations(
'type',
$id,
$sourceLocale,
$sourceFields
);
Db::commit();
return true;
} catch (\Throwable $th) {
Db::rollBack();
throw $th;
}
}
}
@@ -0,0 +1,59 @@
<?php
namespace app\console\service;
use app\console\model\TypesTranslationModel;
use app\mzl\common\services\BaseService;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
class TypesTranslationService extends BaseService
{
/**
* 定义模型
*
* @return string
*/
public function getModel(): string
{
return TypesTranslationModel::class;
}
/**
* 多场景配置
*/
public function queryScenes(): array
{
return [
// 'default' => 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,
// ]
// ];
// }
];
}
}
+45
View File
@@ -0,0 +1,45 @@
<?php
namespace app\console\service;
use app\console\model\UsersModel;
use app\mzl\common\services\BaseService;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
class UsersService extends BaseService
{
/**
* 定义模型
*
* @return string
*/
public function getModel(): string
{
return UsersModel::class;
}
/**
* 多场景配置
*/
public function queryScenes(): array
{
return [
'default' => function ($params) {
return [
'filters' => [
// ['field' => '***', 'operator' => '=', 'value' => '***']
],
'fields' => ['id', 'user_sn', 'nickname', 'avatar', 'realname', 'phone', 'company', 'created_at', 'updated_at'],
'sorts' => [
['field' => 'id', 'direction' => 'desc']
],
'pagination' => [
'page' => $params['page'] ?? 1,
'per_page' => $params['per_page'] ?? 10,
]
];
}
];
}
}
@@ -0,0 +1,59 @@
<?php
namespace app\console\service;
use app\console\model\VehicleAlbumModel;
use app\mzl\common\services\BaseService;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
class VehicleAlbumService extends BaseService
{
/**
* 定义模型
*
* @return string
*/
public function getModel(): string
{
return VehicleAlbumModel::class;
}
/**
* 多场景配置
*/
public function queryScenes(): array
{
return [
// 'default' => 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,
// ]
// ];
// }
];
}
}
@@ -0,0 +1,80 @@
<?php
namespace app\console\service;
use app\console\model\VehicleApplyModel;
use app\mzl\common\services\BaseService;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use support\exception\BusinessException;
use app\apis\model\VehicleDataModel;
class VehicleApplyService extends BaseService
{
/**
* 定义模型
*
* @return string
*/
public function getModel(): string
{
return VehicleApplyModel::class;
}
/**
* 多场景配置
*/
public function queryScenes(): array
{
return [
'default' => function ($params) {
return [
'filters' => [
// ['field' => '***', 'operator' => '=', 'value' => '***']
],
'fields' => ['id', 'vehicle_data_id', 'apply_status', 'desc', 'created_at', 'updated_at'],
'relations' => [
'vehicleDataInfo.translation' => ['vehicle_id', 'name']
],
'sorts' => [
['field' => 'id', 'direction' => 'desc']
],
'pagination' => [
'page' => $params['page'] ?? 1,
'per_page' => $params['per_page'] ?? 10,
]
];
}
];
}
/**
* 操作审核
*/
public function doApply(array $data, int $id): bool
{
$info = $this->model->where('id', $id)->first();
if (!$info) {
throw new BusinessException('未找到待审核信息', 404);
}
$info->apply_status = $data['apply_status'];
$info->desc = $data['desc'];
$info->admin_id = 1;
$vDataInfo = VehicleDataModel::where('id', $info->vehicle_data_id)->first();
if (!$vDataInfo) {
throw new BusinessException('未找到审核信息关联的车辆信息', 404);
}
$vDataInfo->info_status = $data['apply_status'];
if (!$info->save() || !$vDataInfo->save()) {
throw new BusinessException('审核失败,请重试', 500);
}
return true;
}
}
+285
View File
@@ -0,0 +1,285 @@
<?php
namespace app\console\service;
use app\console\model\DraftsModel;
use app\console\model\VehicleApplyModel;
use app\apis\model\VehicleAlbumModel;
use app\console\model\VehicleDataModel;
use app\mzl\common\org\XunfeiFanyi;
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;
class VehicleDataService extends BaseService
{
/**
* 定义模型
*
* @return string
*/
public function getModel(): string
{
return VehicleDataModel::class;
}
/**
* 多场景配置
*/
public function queryScenes(): array
{
return [
'default' => function(array $params) {
return [
'filters' => $params['filters'],
'fields' => [
'id','vin','price','cover',
'type','energy','model','mileage','vehicle_age',
'views','is_hot','created_at','updated_at', 'brand', 'model', 'user_id', 'location'
],
'relations' => [
'translation' => ['vehicle_id', 'name','condition_desc'],
'brand.translation' => ['brand_id', 'name'],
'album' => [
'id', 'vehicle_data_id', 'front_45_degree',
'front_left_45_degree', 'front_left_headlight',
'front_view', 'lower_front', 'wheel_hub',
'front_right_seat', 'right_lower_side',
'rear_right_taillight', 'rear_right_45_degree',
'lower_rear', 'trunk', 'left_lower_side',
'rear_seats', 'center_console', 'control_panel',
'gear_shift', 'car_key', 'steering_wheel',
'dashboard', 'odometer_reading',
'front_left_door_panel', 'front_left_door_function_area',
'front_left_seat', 'interior_ceiling'
],
'user' => ['realname', 'nickname'],
'types.translation' => ['type_id', 'name'],
'energy.translation' => ['energy_id', 'name'],
'models.translation' => ['model_id', 'name'],
'user' => ['nickname'],
'location.translation' => ['location_id', 'name']
],
'sorts' => [
['field'=>'id','direction'=>'desc'],
],
'pagination' => [
'page' => $params['page'] ?? 1,
'per_page' => $params['per_page'] ?? 10,
],
];
},
'show' => function(array $params) {
return [
'filters' => [
['field'=>'id', 'operator'=>'=', 'value'=> $params['id']],
],
'fields' => [
'id','vin','price','cover',
'type','energy','model','mileage','vehicle_age',
'views','is_hot','created_at','updated_at', 'brand', 'model', 'user_id', 'location'
],
'relations' => [
'translation' => ['vehicle_id', 'name','condition_desc'],
'brand.translation' => ['brand_id', 'name'],
'album' => [
'id', 'vehicle_data_id', 'front_45_degree',
'front_left_45_degree', 'front_left_headlight',
'front_view', 'lower_front', 'wheel_hub',
'front_right_seat', 'right_lower_side',
'rear_right_taillight', 'rear_right_45_degree',
'lower_rear', 'trunk', 'left_lower_side',
'rear_seats', 'center_console', 'control_panel',
'gear_shift', 'car_key', 'steering_wheel',
'dashboard', 'odometer_reading',
'front_left_door_panel', 'front_left_door_function_area',
'front_left_seat', 'interior_ceiling'
],
'user' => ['realname', 'nickname'],
'types.translation' => ['type_id', 'name'],
'energy.translation' => ['energy_id', 'name'],
'models.translation' => ['model_id', 'name'],
'user' => ['nickname'],
'location.translation' => ['location_id', 'name']
],
'sorts' => [
['field'=>'id','direction'=>'desc'],
],
'pagination' => [
'page' => $params['page'] ?? 1,
'per_page' => $params['per_page'] ?? 10,
],
];
},
];
}
/**
* 操作销售状态
*/
public function doSaled(array $data, int $id): bool
{
$info = $this->model->where('id', $id)->first();
if (!$info) {
throw new BusinessException('未找到车辆信息', 404);
}
$info->is_saled = $data['is_saled'];
if (!$info->save()) {
throw new BusinessException('设置失败,请重试', 500);
}
return true;
}
// 声明需要多语言翻译
protected array $translatable = [
'name',
'condition_desc',
// 'location'
];
public function add(array $params)
{
$sourceLocale = locale();
$sourceFields = $this->extractSourceFields($params);
if (empty($sourceFields)) {
throw new \InvalidArgumentException("请传递至少一条 {$sourceLocale} 语言的翻译字段");
};
$albums = VehicleAlbumModel::VEHICLE_ALBUM_FIELDS;
foreach ($params as $ko => $vo) {
if (in_array($ko, $albums)) {
$album[$ko] = $vo ?? '';
} else {
if (in_array($ko, VehicleDataModel::TRANS_FIELDS)) {
$trans[$ko] = $vo ?? '';
} else {
$data[$ko] = $vo ?? '';
}
}
}
Db::beginTransaction();
try {
$data['info_status'] = 1;
$info = $this->create($data);
if (!$info) {
throw new BusinessException('提交失败');
}
// 异步翻译并写入 hs_vehicle_data_translation 表
(new TranslationService())->queueTranslations(
'vehicle',
$info->id,
$sourceLocale,
$sourceFields
);
$album['vehicle_data_id'] = $info->id;
$albumModel = new VehicleAlbumModel();
if (!$albumModel->create($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;
}
}
public function edit(array $params, int $id)
{
$sourceLocale = locale();
$sourceFields = $this->extractSourceFields($params);
if (empty($sourceFields)) {
throw new \InvalidArgumentException("请传递至少一条 {$sourceLocale} 语言的翻译字段");
};
$album = [];
$trans = [];
$albums = VehicleAlbumModel::VEHICLE_ALBUM_FIELDS;
foreach ($params as $ko => $vo) {
if (in_array($ko, $albums)) {
$album[$ko] = $vo ?? '';
} else {
if (in_array($ko, VehicleDataModel::TRANS_FIELDS)) {
$trans[$ko] = $vo ?? '';
} else {
$data[$ko] = $vo ?? '';
}
}
}
Db::beginTransaction();
try {
$info = $this->update($id, $params);
if (!$info) {
throw new BusinessException('提交失败');
}
// 异步翻译并写入 hs_vehicle_data_translation 表
(new TranslationService())->queueTranslations(
'vehicle',
$id,
$sourceLocale,
$sourceFields
);
if ($album) {
// $album['vehicle_data_id'] = $info->id;
$albumModel = new VehicleAlbumModel();
if (!$albumModel->updateOrCreate(
['vehicle_data_id' => $id],
$album
)) {
throw new BusinessException('提交失败');
}
}
// $applyModel = new VehicleApplyModel();
// if (!$applyModel->create([
// 'vehicle_data_id' => $info->id,
// 'desc' => '提交审核'
// ])) {
// throw new BusinessException('提交失败');
// }
// if (isset($params['draft_id']) && $params['draft_id']) {
// if (!DraftsModel::where('id', $params['draft_id'])->delete()) {
// throw new BusinessException('草稿移除失败');
// }
// }
Db::commit();
return true;
} catch (\Throwable $th) {
Db::rollBack();
throw $th;
}
}
}
@@ -0,0 +1,59 @@
<?php
namespace app\console\service;
use app\console\model\VehicleDataTranslationModel;
use app\mzl\common\services\BaseService;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
class VehicleDataTranslationService extends BaseService
{
/**
* 定义模型
*
* @return string
*/
public function getModel(): string
{
return VehicleDataTranslationModel::class;
}
/**
* 多场景配置
*/
public function queryScenes(): array
{
return [
// 'default' => 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,
// ]
// ];
// }
];
}
}