Merge branch 'feature/brand'
This commit is contained in:
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\controller;
|
||||||
|
|
||||||
|
use support\Request;
|
||||||
|
use support\Response;
|
||||||
|
use app\apis\model\BrandBannerModel;
|
||||||
|
use app\apis\service\BrandBannerService;
|
||||||
|
use app\apis\validate\BrandBannerValidator;
|
||||||
|
use app\mzl\common\controller\BaseController;
|
||||||
|
|
||||||
|
class BrandBannerController extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不需要验证token的接口
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $noNeedJwt = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证器
|
||||||
|
*/
|
||||||
|
protected mixed $validator = BrandBannerValidator::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回业务 Service 实例
|
||||||
|
*/
|
||||||
|
protected function getService()
|
||||||
|
{
|
||||||
|
return new BrandBannerService(new BrandBannerModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 额外字段处理 (根据场景处理)
|
||||||
|
* @param array $item
|
||||||
|
* @param string $scene
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function postProcessItem(array $item, string $scene): array
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($scene === 'default') {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\controller;
|
||||||
|
|
||||||
|
use support\Request;
|
||||||
|
use support\Response;
|
||||||
|
use app\apis\model\BrandBannerTranslationModel;
|
||||||
|
use app\apis\service\BrandBannerTranslationService;
|
||||||
|
use app\apis\validate\BrandBannerTranslationValidator;
|
||||||
|
use app\mzl\common\controller\BaseController;
|
||||||
|
|
||||||
|
class BrandBannerTranslationController extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不需要验证token的接口
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $noNeedJwt = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证器
|
||||||
|
*/
|
||||||
|
protected mixed $validator = BrandBannerTranslationValidator::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回业务 Service 实例
|
||||||
|
*/
|
||||||
|
protected function getService()
|
||||||
|
{
|
||||||
|
return new BrandBannerTranslationService(new BrandBannerTranslationModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 额外字段处理 (根据场景处理)
|
||||||
|
* @param array $item
|
||||||
|
* @param string $scene
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function postProcessItem(array $item, string $scene): array
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($scene === 'default') {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
namespace app\apis\controller;
|
namespace app\apis\controller;
|
||||||
|
|
||||||
|
use app\apis\model\BrandBannerModel;
|
||||||
|
use app\apis\model\BrandTraitModel;
|
||||||
|
use app\apis\model\BrandTranslationModel;
|
||||||
use support\Request;
|
use support\Request;
|
||||||
use support\Response;
|
use support\Response;
|
||||||
use app\apis\model\BrandModel;
|
use app\apis\model\BrandModel;
|
||||||
@@ -39,7 +42,54 @@ class BrandController extends BaseController
|
|||||||
*/
|
*/
|
||||||
protected function postProcessItem(array $item, string $scene): array
|
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;
|
return $item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,10 +103,16 @@ class BrandController extends BaseController
|
|||||||
{
|
{
|
||||||
$params = parent::prepareParams($request, $scene);
|
$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;
|
return $params;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,4 +130,36 @@ class BrandController extends BaseController
|
|||||||
return $this->errorResponse($th->getMessage());
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\controller;
|
||||||
|
|
||||||
|
use support\Request;
|
||||||
|
use support\Response;
|
||||||
|
use app\apis\model\BrandTraitModel;
|
||||||
|
use app\apis\service\BrandTraitService;
|
||||||
|
use app\apis\validate\BrandTraitValidator;
|
||||||
|
use app\mzl\common\controller\BaseController;
|
||||||
|
|
||||||
|
class BrandTraitController extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不需要验证token的接口
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $noNeedJwt = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证器
|
||||||
|
*/
|
||||||
|
protected mixed $validator = BrandTraitValidator::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回业务 Service 实例
|
||||||
|
*/
|
||||||
|
protected function getService()
|
||||||
|
{
|
||||||
|
return new BrandTraitService(new BrandTraitModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 额外字段处理 (根据场景处理)
|
||||||
|
* @param array $item
|
||||||
|
* @param string $scene
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function postProcessItem(array $item, string $scene): array
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($scene === 'default') {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\controller;
|
||||||
|
|
||||||
|
use support\Request;
|
||||||
|
use support\Response;
|
||||||
|
use app\apis\model\BrandTraitTranslationModel;
|
||||||
|
use app\apis\service\BrandTraitTranslationService;
|
||||||
|
use app\apis\validate\BrandTraitTranslationValidator;
|
||||||
|
use app\mzl\common\controller\BaseController;
|
||||||
|
|
||||||
|
class BrandTraitTranslationController extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不需要验证token的接口
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $noNeedJwt = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证器
|
||||||
|
*/
|
||||||
|
protected mixed $validator = BrandTraitTranslationValidator::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回业务 Service 实例
|
||||||
|
*/
|
||||||
|
protected function getService()
|
||||||
|
{
|
||||||
|
return new BrandTraitTranslationService(new BrandTraitTranslationModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 额外字段处理 (根据场景处理)
|
||||||
|
* @param array $item
|
||||||
|
* @param string $scene
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function postProcessItem(array $item, string $scene): array
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($scene === 'default') {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\controller;
|
||||||
|
|
||||||
|
use support\Request;
|
||||||
|
use support\Response;
|
||||||
|
use app\apis\model\VehicleNewAlbumModel;
|
||||||
|
use app\apis\service\VehicleNewAlbumService;
|
||||||
|
use app\apis\validate\VehicleNewAlbumValidator;
|
||||||
|
use app\mzl\common\controller\BaseController;
|
||||||
|
|
||||||
|
class VehicleNewAlbumController extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不需要验证token的接口
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $noNeedJwt = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证器
|
||||||
|
*/
|
||||||
|
protected mixed $validator = VehicleNewAlbumValidator::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回业务 Service 实例
|
||||||
|
*/
|
||||||
|
protected function getService()
|
||||||
|
{
|
||||||
|
return new VehicleNewAlbumService(new VehicleNewAlbumModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 额外字段处理 (根据场景处理)
|
||||||
|
* @param array $item
|
||||||
|
* @param string $scene
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function postProcessItem(array $item, string $scene): array
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($scene === 'default') {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\controller;
|
||||||
|
|
||||||
|
use support\Request;
|
||||||
|
use support\Response;
|
||||||
|
use app\apis\model\VehicleNewAlbumTranslationModel;
|
||||||
|
use app\apis\service\VehicleNewAlbumTranslationService;
|
||||||
|
use app\apis\validate\VehicleNewAlbumTranslationValidator;
|
||||||
|
use app\mzl\common\controller\BaseController;
|
||||||
|
|
||||||
|
class VehicleNewAlbumTranslationController extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不需要验证token的接口
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $noNeedJwt = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证器
|
||||||
|
*/
|
||||||
|
protected mixed $validator = VehicleNewAlbumTranslationValidator::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回业务 Service 实例
|
||||||
|
*/
|
||||||
|
protected function getService()
|
||||||
|
{
|
||||||
|
return new VehicleNewAlbumTranslationService(new VehicleNewAlbumTranslationModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 额外字段处理 (根据场景处理)
|
||||||
|
* @param array $item
|
||||||
|
* @param string $scene
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function postProcessItem(array $item, string $scene): array
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($scene === 'default') {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\controller;
|
||||||
|
|
||||||
|
use support\Request;
|
||||||
|
use support\Response;
|
||||||
|
use app\apis\model\VehicleNewAskedModel;
|
||||||
|
use app\apis\service\VehicleNewAskedService;
|
||||||
|
use app\apis\validate\VehicleNewAskedValidator;
|
||||||
|
use app\mzl\common\controller\BaseController;
|
||||||
|
|
||||||
|
class VehicleNewAskedController extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不需要验证token的接口
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $noNeedJwt = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证器
|
||||||
|
*/
|
||||||
|
protected mixed $validator = VehicleNewAskedValidator::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回业务 Service 实例
|
||||||
|
*/
|
||||||
|
protected function getService()
|
||||||
|
{
|
||||||
|
return new VehicleNewAskedService(new VehicleNewAskedModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 额外字段处理 (根据场景处理)
|
||||||
|
* @param array $item
|
||||||
|
* @param string $scene
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function postProcessItem(array $item, string $scene): array
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($scene === 'default') {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\controller;
|
||||||
|
|
||||||
|
use support\Request;
|
||||||
|
use support\Response;
|
||||||
|
use app\apis\model\VehicleNewAskedTranslationModel;
|
||||||
|
use app\apis\service\VehicleNewAskedTranslationService;
|
||||||
|
use app\apis\validate\VehicleNewAskedTranslationValidator;
|
||||||
|
use app\mzl\common\controller\BaseController;
|
||||||
|
|
||||||
|
class VehicleNewAskedTranslationController extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不需要验证token的接口
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $noNeedJwt = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证器
|
||||||
|
*/
|
||||||
|
protected mixed $validator = VehicleNewAskedTranslationValidator::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回业务 Service 实例
|
||||||
|
*/
|
||||||
|
protected function getService()
|
||||||
|
{
|
||||||
|
return new VehicleNewAskedTranslationService(new VehicleNewAskedTranslationModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 额外字段处理 (根据场景处理)
|
||||||
|
* @param array $item
|
||||||
|
* @param string $scene
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function postProcessItem(array $item, string $scene): array
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($scene === 'default') {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\controller;
|
||||||
|
|
||||||
|
use support\Request;
|
||||||
|
use support\Response;
|
||||||
|
use app\apis\model\VehicleNewContentModel;
|
||||||
|
use app\apis\service\VehicleNewContentService;
|
||||||
|
use app\apis\validate\VehicleNewContentValidator;
|
||||||
|
use app\mzl\common\controller\BaseController;
|
||||||
|
|
||||||
|
class VehicleNewContentController extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不需要验证token的接口
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $noNeedJwt = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证器
|
||||||
|
*/
|
||||||
|
protected mixed $validator = VehicleNewContentValidator::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回业务 Service 实例
|
||||||
|
*/
|
||||||
|
protected function getService()
|
||||||
|
{
|
||||||
|
return new VehicleNewContentService(new VehicleNewContentModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 额外字段处理 (根据场景处理)
|
||||||
|
* @param array $item
|
||||||
|
* @param string $scene
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function postProcessItem(array $item, string $scene): array
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($scene === 'default') {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\controller;
|
||||||
|
|
||||||
|
use support\Request;
|
||||||
|
use support\Response;
|
||||||
|
use app\apis\model\VehicleNewContentTranslationModel;
|
||||||
|
use app\apis\service\VehicleNewContentTranslationService;
|
||||||
|
use app\apis\validate\VehicleNewContentTranslationValidator;
|
||||||
|
use app\mzl\common\controller\BaseController;
|
||||||
|
|
||||||
|
class VehicleNewContentTranslationController extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不需要验证token的接口
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $noNeedJwt = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证器
|
||||||
|
*/
|
||||||
|
protected mixed $validator = VehicleNewContentTranslationValidator::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回业务 Service 实例
|
||||||
|
*/
|
||||||
|
protected function getService()
|
||||||
|
{
|
||||||
|
return new VehicleNewContentTranslationService(new VehicleNewContentTranslationModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 额外字段处理 (根据场景处理)
|
||||||
|
* @param array $item
|
||||||
|
* @param string $scene
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function postProcessItem(array $item, string $scene): array
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($scene === 'default') {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,176 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\controller;
|
||||||
|
|
||||||
|
use support\Request;
|
||||||
|
use support\Response;
|
||||||
|
use app\apis\model\VehicleNewModel;
|
||||||
|
use app\apis\service\VehicleNewService;
|
||||||
|
use app\apis\validate\VehicleNewValidator;
|
||||||
|
use app\mzl\common\controller\BaseController;
|
||||||
|
|
||||||
|
class VehicleNewController extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不需要验证token的接口
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $noNeedJwt = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证器
|
||||||
|
*/
|
||||||
|
protected mixed $validator = VehicleNewValidator::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回业务 Service 实例
|
||||||
|
*/
|
||||||
|
protected function getService()
|
||||||
|
{
|
||||||
|
return new VehicleNewService(new VehicleNewModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 额外字段处理 (根据场景处理)
|
||||||
|
* @param array $item
|
||||||
|
* @param string $scene
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function postProcessItem(array $item, string $scene): array
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($scene === 'default' || $scene === 'show') {
|
||||||
|
$result = [
|
||||||
|
'id' => $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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\controller;
|
||||||
|
|
||||||
|
use support\Request;
|
||||||
|
use support\Response;
|
||||||
|
use app\apis\model\VehicleNewTraitModel;
|
||||||
|
use app\apis\service\VehicleNewTraitService;
|
||||||
|
use app\apis\validate\VehicleNewTraitValidator;
|
||||||
|
use app\mzl\common\controller\BaseController;
|
||||||
|
|
||||||
|
class VehicleNewTraitController extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不需要验证token的接口
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $noNeedJwt = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证器
|
||||||
|
*/
|
||||||
|
protected mixed $validator = VehicleNewTraitValidator::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回业务 Service 实例
|
||||||
|
*/
|
||||||
|
protected function getService()
|
||||||
|
{
|
||||||
|
return new VehicleNewTraitService(new VehicleNewTraitModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 额外字段处理 (根据场景处理)
|
||||||
|
* @param array $item
|
||||||
|
* @param string $scene
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function postProcessItem(array $item, string $scene): array
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($scene === 'default') {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\controller;
|
||||||
|
|
||||||
|
use support\Request;
|
||||||
|
use support\Response;
|
||||||
|
use app\apis\model\VehicleNewTraitTranslationModel;
|
||||||
|
use app\apis\service\VehicleNewTraitTranslationService;
|
||||||
|
use app\apis\validate\VehicleNewTraitTranslationValidator;
|
||||||
|
use app\mzl\common\controller\BaseController;
|
||||||
|
|
||||||
|
class VehicleNewTraitTranslationController extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不需要验证token的接口
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $noNeedJwt = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证器
|
||||||
|
*/
|
||||||
|
protected mixed $validator = VehicleNewTraitTranslationValidator::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回业务 Service 实例
|
||||||
|
*/
|
||||||
|
protected function getService()
|
||||||
|
{
|
||||||
|
return new VehicleNewTraitTranslationService(new VehicleNewTraitTranslationModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 额外字段处理 (根据场景处理)
|
||||||
|
* @param array $item
|
||||||
|
* @param string $scene
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function postProcessItem(array $item, string $scene): array
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($scene === 'default') {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\controller;
|
||||||
|
|
||||||
|
use support\Request;
|
||||||
|
use support\Response;
|
||||||
|
use app\apis\model\VehicleNewTranslationModel;
|
||||||
|
use app\apis\service\VehicleNewTranslationService;
|
||||||
|
use app\apis\validate\VehicleNewTranslationValidator;
|
||||||
|
use app\mzl\common\controller\BaseController;
|
||||||
|
|
||||||
|
class VehicleNewTranslationController extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不需要验证token的接口
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $noNeedJwt = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证器
|
||||||
|
*/
|
||||||
|
protected mixed $validator = VehicleNewTranslationValidator::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回业务 Service 实例
|
||||||
|
*/
|
||||||
|
protected function getService()
|
||||||
|
{
|
||||||
|
return new VehicleNewTranslationService(new VehicleNewTranslationModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 额外字段处理 (根据场景处理)
|
||||||
|
* @param array $item
|
||||||
|
* @param string $scene
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function postProcessItem(array $item, string $scene): array
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($scene === 'default') {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\model;
|
||||||
|
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BrandBannerModel
|
||||||
|
*/
|
||||||
|
class BrandBannerModel extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The connection name for the model.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
protected $connection = 'mysql';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'hs_brand_banner';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the table.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the model should be timestamped.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型的数据字段的保存格式。
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $dateFormat = 'U';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'brand_id', 'pic', 'status', 'sort', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $guarded = [];
|
||||||
|
|
||||||
|
|
||||||
|
public function brand()
|
||||||
|
{
|
||||||
|
return $this->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'
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\model;
|
||||||
|
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BrandBannerTranslationModel
|
||||||
|
*/
|
||||||
|
class BrandBannerTranslationModel extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The connection name for the model.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
protected $connection = 'mysql';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'hs_brand_banner_translation';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the table.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the model should be timestamped.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型的数据字段的保存格式。
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $dateFormat = 'U';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'brand_id', 'banner_id', 'locale', 'alt', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $guarded = [];
|
||||||
|
|
||||||
|
public function brand()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(BrandModel::class, 'brand_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function banner()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(BrandBannerModel::class, 'banner_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -58,4 +58,13 @@ class BrandModel extends Model
|
|||||||
{
|
{
|
||||||
return $this->hasOne(BrandTranslationModel::class, 'brand_id')->where('locale', locale());
|
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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\model;
|
||||||
|
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BrandTraitModel
|
||||||
|
*/
|
||||||
|
class BrandTraitModel extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The connection name for the model.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
protected $connection = 'mysql';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'hs_brand_trait';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the table.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the model should be timestamped.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型的数据字段的保存格式。
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $dateFormat = 'U';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'brand_id', 'status', 'sort', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $guarded = [];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function brand()
|
||||||
|
{
|
||||||
|
return $this->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'
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\model;
|
||||||
|
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BrandTraitTranslationModel
|
||||||
|
*/
|
||||||
|
class BrandTraitTranslationModel extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The connection name for the model.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
protected $connection = 'mysql';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'hs_brand_trait_translation';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the table.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the model should be timestamped.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型的数据字段的保存格式。
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $dateFormat = 'U';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'brand_id', 'trait_id', 'locale', 'title', 'content', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $guarded = [];
|
||||||
|
|
||||||
|
|
||||||
|
public function brand()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(BrandModel::class, 'brand_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function brandTrait()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(BrandTraitModel::class, 'trait_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\model;
|
||||||
|
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VehicleNewAlbumModel
|
||||||
|
*/
|
||||||
|
class VehicleNewAlbumModel extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The connection name for the model.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
protected $connection = 'mysql';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'hs_vehicle_new_album';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the table.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the model should be timestamped.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型的数据字段的保存格式。
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $dateFormat = 'U';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'vehicle_id', 'pic', 'status', 'sort', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $guarded = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单条翻译
|
||||||
|
*/
|
||||||
|
public function translation()
|
||||||
|
{
|
||||||
|
return $this->hasOne(VehicleNewAlbumTranslationModel::class, 'album_id')->where('locale', locale());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 多条翻译
|
||||||
|
*/
|
||||||
|
public function translations()
|
||||||
|
{
|
||||||
|
return $this->hasMany(VehicleNewAlbumTranslationModel::class, 'album_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
const TRANS_FIELDS = [
|
||||||
|
'alt',
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\model;
|
||||||
|
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VehicleNewAlbumTranslationModel
|
||||||
|
*/
|
||||||
|
class VehicleNewAlbumTranslationModel extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The connection name for the model.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
protected $connection = 'mysql';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'hs_vehicle_new_album_translation';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the table.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the model should be timestamped.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型的数据字段的保存格式。
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $dateFormat = 'U';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'album_id', 'locale', 'alt', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $guarded = [];
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\model;
|
||||||
|
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VehicleNewAskedModel
|
||||||
|
*/
|
||||||
|
class VehicleNewAskedModel extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The connection name for the model.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
protected $connection = 'mysql';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'hs_vehicle_new_asked';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the table.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the model should be timestamped.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型的数据字段的保存格式。
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $dateFormat = 'U';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'vehicle_id', 'status', 'sort', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $guarded = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 相册字段
|
||||||
|
*/
|
||||||
|
const VEHICLE_NEW_ASKED_FIELDS = [
|
||||||
|
'title',
|
||||||
|
'content',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单条翻译
|
||||||
|
*/
|
||||||
|
public function translation()
|
||||||
|
{
|
||||||
|
return $this->hasOne(VehicleNewAskedTranslationModel::class, 'asked_id')->where('locale', locale());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 多条翻译
|
||||||
|
*/
|
||||||
|
public function translations()
|
||||||
|
{
|
||||||
|
return $this->hasMany(VehicleNewAskedTranslationModel::class, 'asked_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\model;
|
||||||
|
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VehicleNewAskedTranslationModel
|
||||||
|
*/
|
||||||
|
class VehicleNewAskedTranslationModel extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The connection name for the model.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
protected $connection = 'mysql';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'hs_vehicle_new_asked_translation';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the table.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the model should be timestamped.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型的数据字段的保存格式。
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $dateFormat = 'U';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'asked_id', 'locale', 'title', 'content', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $guarded = [];
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\model;
|
||||||
|
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VehicleNewContentModel
|
||||||
|
*/
|
||||||
|
class VehicleNewContentModel extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The connection name for the model.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
protected $connection = 'mysql';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'hs_vehicle_new_content';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the table.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the model should be timestamped.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型的数据字段的保存格式。
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $dateFormat = 'U';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'vehicle_id', 'status', 'sort', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $guarded = [];
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单条翻译
|
||||||
|
*/
|
||||||
|
public function translation()
|
||||||
|
{
|
||||||
|
return $this->hasOne(VehicleNewContentTranslationModel::class, 'content_id')->where('locale', locale());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 多条翻译
|
||||||
|
*/
|
||||||
|
public function translations()
|
||||||
|
{
|
||||||
|
return $this->hasMany(VehicleNewContentTranslationModel::class, 'content_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\model;
|
||||||
|
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VehicleNewContentTranslationModel
|
||||||
|
*/
|
||||||
|
class VehicleNewContentTranslationModel extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The connection name for the model.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
protected $connection = 'mysql';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'hs_vehicle_new_content_translation';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the table.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the model should be timestamped.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型的数据字段的保存格式。
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $dateFormat = 'U';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'content_id', 'locale', 'content', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $guarded = [];
|
||||||
|
}
|
||||||
@@ -0,0 +1,121 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\model;
|
||||||
|
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VehicleNewModel
|
||||||
|
*/
|
||||||
|
class VehicleNewModel extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The connection name for the model.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
protected $connection = 'mysql';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'hs_vehicle_new';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the table.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the model should be timestamped.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型的数据字段的保存格式。
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $dateFormat = 'U';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'vin', 'brand', 'cover', 'album', 'price', 'type', 'energy', 'model', 'video', 'views', 'created_at', 'updated_at', 'location'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $guarded = [];
|
||||||
|
|
||||||
|
const TRANS_FIELDS = [
|
||||||
|
'name', 'condition_desc'
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单条翻译
|
||||||
|
*/
|
||||||
|
public function translation()
|
||||||
|
{
|
||||||
|
return $this->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');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\model;
|
||||||
|
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VehicleNewTraitModel
|
||||||
|
*/
|
||||||
|
class VehicleNewTraitModel extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The connection name for the model.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
protected $connection = 'mysql';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'hs_vehicle_new_trait';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the table.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the model should be timestamped.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型的数据字段的保存格式。
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $dateFormat = 'U';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'vehicle_id', 'status', 'sort', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $guarded = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单条翻译
|
||||||
|
*/
|
||||||
|
public function translation()
|
||||||
|
{
|
||||||
|
return $this->hasOne(VehicleNewTraitTranslationModel::class, 'trait_id')->where('locale', locale());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 多条翻译
|
||||||
|
*/
|
||||||
|
public function translations()
|
||||||
|
{
|
||||||
|
return $this->hasMany(VehicleNewTraitTranslationModel::class, 'trait_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\model;
|
||||||
|
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VehicleNewTraitTranslationModel
|
||||||
|
*/
|
||||||
|
class VehicleNewTraitTranslationModel extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The connection name for the model.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
protected $connection = 'mysql';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'hs_vehicle_new_trait_translation';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the table.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the model should be timestamped.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型的数据字段的保存格式。
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $dateFormat = 'U';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'trait_id', 'locale', 'title', 'content', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $guarded = [];
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\model;
|
||||||
|
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VehicleNewTranslationModel
|
||||||
|
*/
|
||||||
|
class VehicleNewTranslationModel extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The connection name for the model.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
protected $connection = 'mysql';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'hs_vehicle_new_translation';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the table.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the model should be timestamped.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型的数据字段的保存格式。
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $dateFormat = 'U';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'vehicle_id', 'locale', 'name', 'condition_desc', 'location', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $guarded = [];
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\service;
|
||||||
|
|
||||||
|
use app\apis\model\BrandBannerModel;
|
||||||
|
use app\mzl\common\services\BaseService;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class BrandBannerService extends BaseService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 定义模型
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getModel(): string
|
||||||
|
{
|
||||||
|
return BrandBannerModel::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,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\service;
|
||||||
|
|
||||||
|
use app\apis\model\BrandBannerTranslationModel;
|
||||||
|
use app\mzl\common\services\BaseService;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class BrandBannerTranslationService extends BaseService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 定义模型
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getModel(): string
|
||||||
|
{
|
||||||
|
return BrandBannerTranslationModel::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,
|
||||||
|
// ]
|
||||||
|
// ];
|
||||||
|
// }
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,12 +27,14 @@ class BrandService extends BaseService
|
|||||||
return [
|
return [
|
||||||
'default' => function ($params) {
|
'default' => function ($params) {
|
||||||
return [
|
return [
|
||||||
'filters' => [
|
'filters' => $params['filters'],
|
||||||
['field' => 'status', 'operator' => '=', 'value' => '1']
|
'fields' => ['id', 'status', 'sort', 'toppic', 'descpic', 'logo', 'letter', 'is_hot', 'created_at', 'updated_at'],
|
||||||
],
|
|
||||||
'fields' => ['id', 'status', 'sort', 'created_at', 'updated_at'],
|
|
||||||
'relations' => [
|
'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' => [
|
'sorts' => [
|
||||||
['field' => 'id', 'direction' => 'desc']
|
['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']
|
||||||
|
],
|
||||||
|
];
|
||||||
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\service;
|
||||||
|
|
||||||
|
use app\apis\model\BrandTraitModel;
|
||||||
|
use app\mzl\common\services\BaseService;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class BrandTraitService extends BaseService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 定义模型
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getModel(): string
|
||||||
|
{
|
||||||
|
return BrandTraitModel::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,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\service;
|
||||||
|
|
||||||
|
use app\apis\model\BrandTraitTranslationModel;
|
||||||
|
use app\mzl\common\services\BaseService;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class BrandTraitTranslationService extends BaseService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 定义模型
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getModel(): string
|
||||||
|
{
|
||||||
|
return BrandTraitTranslationModel::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,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\service;
|
||||||
|
|
||||||
|
use app\apis\model\VehicleNewAlbumModel;
|
||||||
|
use app\mzl\common\services\BaseService;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class VehicleNewAlbumService extends BaseService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 定义模型
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getModel(): string
|
||||||
|
{
|
||||||
|
return VehicleNewAlbumModel::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,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\service;
|
||||||
|
|
||||||
|
use app\apis\model\VehicleNewAlbumTranslationModel;
|
||||||
|
use app\mzl\common\services\BaseService;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class VehicleNewAlbumTranslationService extends BaseService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 定义模型
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getModel(): string
|
||||||
|
{
|
||||||
|
return VehicleNewAlbumTranslationModel::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,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\service;
|
||||||
|
|
||||||
|
use app\apis\model\VehicleNewAskedModel;
|
||||||
|
use app\mzl\common\services\BaseService;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class VehicleNewAskedService extends BaseService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 定义模型
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getModel(): string
|
||||||
|
{
|
||||||
|
return VehicleNewAskedModel::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,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\service;
|
||||||
|
|
||||||
|
use app\apis\model\VehicleNewAskedTranslationModel;
|
||||||
|
use app\mzl\common\services\BaseService;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class VehicleNewAskedTranslationService extends BaseService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 定义模型
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getModel(): string
|
||||||
|
{
|
||||||
|
return VehicleNewAskedTranslationModel::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,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\service;
|
||||||
|
|
||||||
|
use app\apis\model\VehicleNewContentModel;
|
||||||
|
use app\mzl\common\services\BaseService;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class VehicleNewContentService extends BaseService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 定义模型
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getModel(): string
|
||||||
|
{
|
||||||
|
return VehicleNewContentModel::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,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\service;
|
||||||
|
|
||||||
|
use app\apis\model\VehicleNewContentTranslationModel;
|
||||||
|
use app\mzl\common\services\BaseService;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class VehicleNewContentTranslationService extends BaseService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 定义模型
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getModel(): string
|
||||||
|
{
|
||||||
|
return VehicleNewContentTranslationModel::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,110 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\service;
|
||||||
|
|
||||||
|
use app\apis\model\EnergyModel;
|
||||||
|
use app\apis\model\EnergyTranslationModel;
|
||||||
|
use app\apis\model\VehicleNewModel;
|
||||||
|
use app\mzl\common\services\BaseService;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class VehicleNewService extends BaseService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 定义模型
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getModel(): string
|
||||||
|
{
|
||||||
|
return VehicleNewModel::class;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 多场景配置
|
||||||
|
*/
|
||||||
|
public function queryScenes(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'default' => 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',
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\service;
|
||||||
|
|
||||||
|
use app\apis\model\VehicleNewTraitModel;
|
||||||
|
use app\mzl\common\services\BaseService;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class VehicleNewTraitService extends BaseService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 定义模型
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getModel(): string
|
||||||
|
{
|
||||||
|
return VehicleNewTraitModel::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,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\service;
|
||||||
|
|
||||||
|
use app\apis\model\VehicleNewTraitTranslationModel;
|
||||||
|
use app\mzl\common\services\BaseService;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class VehicleNewTraitTranslationService extends BaseService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 定义模型
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getModel(): string
|
||||||
|
{
|
||||||
|
return VehicleNewTraitTranslationModel::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,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\service;
|
||||||
|
|
||||||
|
use app\apis\model\VehicleNewTranslationModel;
|
||||||
|
use app\mzl\common\services\BaseService;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class VehicleNewTranslationService extends BaseService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 定义模型
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getModel(): string
|
||||||
|
{
|
||||||
|
return VehicleNewTranslationModel::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,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\validate;
|
||||||
|
|
||||||
|
use think\Validate;
|
||||||
|
|
||||||
|
class BrandBannerTranslationValidator extends Validate
|
||||||
|
{
|
||||||
|
// 规则
|
||||||
|
protected $rule = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
// 提示
|
||||||
|
protected $message = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
// 场景
|
||||||
|
protected $scene = [
|
||||||
|
'store' => [
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
|
'update' => [
|
||||||
|
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\validate;
|
||||||
|
|
||||||
|
use think\Validate;
|
||||||
|
|
||||||
|
class BrandBannerValidator extends Validate
|
||||||
|
{
|
||||||
|
// 规则
|
||||||
|
protected $rule = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
// 提示
|
||||||
|
protected $message = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
// 场景
|
||||||
|
protected $scene = [
|
||||||
|
'store' => [
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
|
'update' => [
|
||||||
|
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\validate;
|
||||||
|
|
||||||
|
use think\Validate;
|
||||||
|
|
||||||
|
class BrandTraitTranslationValidator extends Validate
|
||||||
|
{
|
||||||
|
// 规则
|
||||||
|
protected $rule = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
// 提示
|
||||||
|
protected $message = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
// 场景
|
||||||
|
protected $scene = [
|
||||||
|
'store' => [
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
|
'update' => [
|
||||||
|
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\validate;
|
||||||
|
|
||||||
|
use think\Validate;
|
||||||
|
|
||||||
|
class BrandTraitValidator extends Validate
|
||||||
|
{
|
||||||
|
// 规则
|
||||||
|
protected $rule = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
// 提示
|
||||||
|
protected $message = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
// 场景
|
||||||
|
protected $scene = [
|
||||||
|
'store' => [
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
|
'update' => [
|
||||||
|
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\validate;
|
||||||
|
|
||||||
|
use think\Validate;
|
||||||
|
|
||||||
|
class VehicleNewAlbumTranslationValidator extends Validate
|
||||||
|
{
|
||||||
|
// 规则
|
||||||
|
protected $rule = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
// 提示
|
||||||
|
protected $message = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
// 场景
|
||||||
|
protected $scene = [
|
||||||
|
'store' => [
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
|
'update' => [
|
||||||
|
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\validate;
|
||||||
|
|
||||||
|
use think\Validate;
|
||||||
|
|
||||||
|
class VehicleNewAlbumValidator extends Validate
|
||||||
|
{
|
||||||
|
// 规则
|
||||||
|
protected $rule = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
// 提示
|
||||||
|
protected $message = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
// 场景
|
||||||
|
protected $scene = [
|
||||||
|
'store' => [
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
|
'update' => [
|
||||||
|
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\validate;
|
||||||
|
|
||||||
|
use think\Validate;
|
||||||
|
|
||||||
|
class VehicleNewAskedTranslationValidator extends Validate
|
||||||
|
{
|
||||||
|
// 规则
|
||||||
|
protected $rule = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
// 提示
|
||||||
|
protected $message = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
// 场景
|
||||||
|
protected $scene = [
|
||||||
|
'store' => [
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
|
'update' => [
|
||||||
|
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\validate;
|
||||||
|
|
||||||
|
use think\Validate;
|
||||||
|
|
||||||
|
class VehicleNewAskedValidator extends Validate
|
||||||
|
{
|
||||||
|
// 规则
|
||||||
|
protected $rule = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
// 提示
|
||||||
|
protected $message = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
// 场景
|
||||||
|
protected $scene = [
|
||||||
|
'store' => [
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
|
'update' => [
|
||||||
|
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\validate;
|
||||||
|
|
||||||
|
use think\Validate;
|
||||||
|
|
||||||
|
class VehicleNewContentTranslationValidator extends Validate
|
||||||
|
{
|
||||||
|
// 规则
|
||||||
|
protected $rule = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
// 提示
|
||||||
|
protected $message = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
// 场景
|
||||||
|
protected $scene = [
|
||||||
|
'store' => [
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
|
'update' => [
|
||||||
|
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\validate;
|
||||||
|
|
||||||
|
use think\Validate;
|
||||||
|
|
||||||
|
class VehicleNewContentValidator extends Validate
|
||||||
|
{
|
||||||
|
// 规则
|
||||||
|
protected $rule = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
// 提示
|
||||||
|
protected $message = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
// 场景
|
||||||
|
protected $scene = [
|
||||||
|
'store' => [
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
|
'update' => [
|
||||||
|
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\validate;
|
||||||
|
|
||||||
|
use think\Validate;
|
||||||
|
|
||||||
|
class VehicleNewTraitTranslationValidator extends Validate
|
||||||
|
{
|
||||||
|
// 规则
|
||||||
|
protected $rule = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
// 提示
|
||||||
|
protected $message = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
// 场景
|
||||||
|
protected $scene = [
|
||||||
|
'store' => [
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
|
'update' => [
|
||||||
|
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\validate;
|
||||||
|
|
||||||
|
use think\Validate;
|
||||||
|
|
||||||
|
class VehicleNewTraitValidator extends Validate
|
||||||
|
{
|
||||||
|
// 规则
|
||||||
|
protected $rule = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
// 提示
|
||||||
|
protected $message = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
// 场景
|
||||||
|
protected $scene = [
|
||||||
|
'store' => [
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
|
'update' => [
|
||||||
|
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\validate;
|
||||||
|
|
||||||
|
use think\Validate;
|
||||||
|
|
||||||
|
class VehicleNewTranslationValidator extends Validate
|
||||||
|
{
|
||||||
|
// 规则
|
||||||
|
protected $rule = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
// 提示
|
||||||
|
protected $message = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
// 场景
|
||||||
|
protected $scene = [
|
||||||
|
'store' => [
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
|
'update' => [
|
||||||
|
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\apis\validate;
|
||||||
|
|
||||||
|
use think\Validate;
|
||||||
|
|
||||||
|
class VehicleNewValidator extends Validate
|
||||||
|
{
|
||||||
|
// 规则
|
||||||
|
protected $rule = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
// 提示
|
||||||
|
protected $message = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
// 场景
|
||||||
|
protected $scene = [
|
||||||
|
'store' => [
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
|
'update' => [
|
||||||
|
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -65,7 +65,9 @@ class LocationController extends BaseController
|
|||||||
$params = parent::prepareParams($request, $scene);
|
$params = parent::prepareParams($request, $scene);
|
||||||
|
|
||||||
if ($scene === 'default') {
|
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;
|
return $params;
|
||||||
|
|||||||
@@ -0,0 +1,119 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\controller;
|
||||||
|
|
||||||
|
use app\console\model\BrandBannerModel;
|
||||||
|
use app\console\service\BrandBannerService;
|
||||||
|
use app\console\validate\BrandBannerValidator;
|
||||||
|
use support\Request;
|
||||||
|
use support\Response;
|
||||||
|
use app\mzl\common\controller\BaseController;
|
||||||
|
|
||||||
|
class BrandBannerController extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不需要验证token的接口
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $noNeedJwt = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证器
|
||||||
|
*/
|
||||||
|
protected mixed $validator = BrandBannerValidator::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回业务 Service 实例
|
||||||
|
*/
|
||||||
|
protected function getService()
|
||||||
|
{
|
||||||
|
return new BrandBannerService(new BrandBannerModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 额外字段处理 (根据场景处理)
|
||||||
|
* @param array $item
|
||||||
|
* @param string $scene
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function postProcessItem(array $item, string $scene): array
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($scene === 'default') {
|
||||||
|
return [
|
||||||
|
'id' => $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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
namespace app\console\controller;
|
namespace app\console\controller;
|
||||||
|
|
||||||
|
use app\console\model\BrandBannerModel;
|
||||||
|
use app\console\model\BrandTraitModel;
|
||||||
|
use app\console\model\BrandTranslationModel;
|
||||||
use support\Request;
|
use support\Request;
|
||||||
use support\Response;
|
use support\Response;
|
||||||
use app\console\model\BrandModel;
|
use app\console\model\BrandModel;
|
||||||
@@ -39,16 +42,49 @@ class BrandController extends BaseController
|
|||||||
*/
|
*/
|
||||||
protected function postProcessItem(array $item, string $scene): array
|
protected function postProcessItem(array $item, string $scene): array
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($scene === 'default') {
|
if ($scene === 'default') {
|
||||||
return [
|
$result = [
|
||||||
'id' => $item['id'],
|
'id' => $item['id'],
|
||||||
'status' => $item['status'],
|
'status' => $item['status'],
|
||||||
'sort' => $item['sort'],
|
'sort' => $item['sort'],
|
||||||
|
'toppic' => $item['toppic'],
|
||||||
|
'descpic' => $item['descpic'],
|
||||||
|
'logo' => $item['logo'],
|
||||||
|
'is_hot' => $item['is_hot'],
|
||||||
'name' => isset($item['translation']) ? $item['translation']['name'] : '',
|
'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']),
|
'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') {
|
if ($scene === 'preset') {
|
||||||
@@ -72,7 +108,14 @@ class BrandController extends BaseController
|
|||||||
$params = parent::prepareParams($request, $scene);
|
$params = parent::prepareParams($request, $scene);
|
||||||
|
|
||||||
if ($scene === 'default') {
|
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;
|
return $params;
|
||||||
@@ -86,6 +129,9 @@ class BrandController extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function index(Request $request, string $scene = 'default'): Response
|
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 {
|
try {
|
||||||
return parent::index($request, $scene);
|
return parent::index($request, $scene);
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
@@ -108,8 +154,8 @@ class BrandController extends BaseController
|
|||||||
public function add(Request $request): Response
|
public function add(Request $request): Response
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return $this->getService()->add($request->all())
|
$id = $this->getService()->add($request->all());
|
||||||
? $this->successResponse()
|
return $id ? $this->successResponse(['id' => $id])
|
||||||
: $this->errorResponse();
|
: $this->errorResponse();
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
return $this->errorResponse($th->getMessage());
|
return $this->errorResponse($th->getMessage());
|
||||||
@@ -119,11 +165,12 @@ class BrandController extends BaseController
|
|||||||
public function edit(Request $request, int $id): Response
|
public function edit(Request $request, int $id): Response
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
$request->setPost('id',$id);
|
||||||
return $this->getService()->edit($request->all(), $id)
|
return $this->getService()->edit($request->all(), $id)
|
||||||
? $this->successResponse()
|
? $this->successResponse()
|
||||||
: $this->errorResponse();
|
: $this->errorResponse();
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
return $this->errorResponse($th->getMessage());
|
return $this->errorResponse($th->getMessage().$th->getFile().$th->getLine());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,112 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\controller;
|
||||||
|
|
||||||
|
use app\console\model\BrandTraitModel;
|
||||||
|
use app\console\service\BrandTraitService;
|
||||||
|
use app\console\validate\BrandTraitValidator;
|
||||||
|
use support\Request;
|
||||||
|
use support\Response;
|
||||||
|
use app\mzl\common\controller\BaseController;
|
||||||
|
|
||||||
|
class BrandTraitController extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不需要验证token的接口
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $noNeedJwt = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证器
|
||||||
|
*/
|
||||||
|
protected mixed $validator = BrandTraitValidator::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回业务 Service 实例
|
||||||
|
*/
|
||||||
|
protected function getService()
|
||||||
|
{
|
||||||
|
return new BrandTraitService(new BrandTraitModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 额外字段处理 (根据场景处理)
|
||||||
|
* @param array $item
|
||||||
|
* @param string $scene
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function postProcessItem(array $item, string $scene): array
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($scene === 'default') {
|
||||||
|
return [
|
||||||
|
'id' => $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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\controller;
|
||||||
|
|
||||||
|
use support\Request;
|
||||||
|
use support\Response;
|
||||||
|
use app\console\model\VehicleNewAlbumModel;
|
||||||
|
use app\console\service\VehicleNewAlbumService;
|
||||||
|
use app\console\validate\VehicleNewAlbumValidator;
|
||||||
|
use app\mzl\common\controller\BaseController;
|
||||||
|
|
||||||
|
class VehicleNewAlbumController extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不需要验证token的接口
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $noNeedJwt = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证器
|
||||||
|
*/
|
||||||
|
protected mixed $validator = VehicleNewAlbumValidator::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回业务 Service 实例
|
||||||
|
*/
|
||||||
|
protected function getService()
|
||||||
|
{
|
||||||
|
return new VehicleNewAlbumService(new VehicleNewAlbumModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 额外字段处理 (根据场景处理)
|
||||||
|
* @param array $item
|
||||||
|
* @param string $scene
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function postProcessItem(array $item, string $scene): array
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($scene === 'default') {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\controller;
|
||||||
|
|
||||||
|
use support\Request;
|
||||||
|
use support\Response;
|
||||||
|
use app\console\model\VehicleNewAlbumTranslationModel;
|
||||||
|
use app\console\service\VehicleNewAlbumTranslationService;
|
||||||
|
use app\console\validate\VehicleNewAlbumTranslationValidator;
|
||||||
|
use app\mzl\common\controller\BaseController;
|
||||||
|
|
||||||
|
class VehicleNewAlbumTranslationController extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不需要验证token的接口
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $noNeedJwt = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证器
|
||||||
|
*/
|
||||||
|
protected mixed $validator = VehicleNewAlbumTranslationValidator::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回业务 Service 实例
|
||||||
|
*/
|
||||||
|
protected function getService()
|
||||||
|
{
|
||||||
|
return new VehicleNewAlbumTranslationService(new VehicleNewAlbumTranslationModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 额外字段处理 (根据场景处理)
|
||||||
|
* @param array $item
|
||||||
|
* @param string $scene
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function postProcessItem(array $item, string $scene): array
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($scene === 'default') {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\controller;
|
||||||
|
|
||||||
|
use support\Request;
|
||||||
|
use support\Response;
|
||||||
|
use app\console\model\VehicleNewAskedModel;
|
||||||
|
use app\console\service\VehicleNewAskedService;
|
||||||
|
use app\console\validate\VehicleNewAskedValidator;
|
||||||
|
use app\mzl\common\controller\BaseController;
|
||||||
|
|
||||||
|
class VehicleNewAskedController extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不需要验证token的接口
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $noNeedJwt = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证器
|
||||||
|
*/
|
||||||
|
protected mixed $validator = VehicleNewAskedValidator::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回业务 Service 实例
|
||||||
|
*/
|
||||||
|
protected function getService()
|
||||||
|
{
|
||||||
|
return new VehicleNewAskedService(new VehicleNewAskedModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 额外字段处理 (根据场景处理)
|
||||||
|
* @param array $item
|
||||||
|
* @param string $scene
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function postProcessItem(array $item, string $scene): array
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($scene === 'default') {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\controller;
|
||||||
|
|
||||||
|
use support\Request;
|
||||||
|
use support\Response;
|
||||||
|
use app\console\model\VehicleNewAskedTranslationModel;
|
||||||
|
use app\console\service\VehicleNewAskedTranslationService;
|
||||||
|
use app\console\validate\VehicleNewAskedTranslationValidator;
|
||||||
|
use app\mzl\common\controller\BaseController;
|
||||||
|
|
||||||
|
class VehicleNewAskedTranslationController extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不需要验证token的接口
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $noNeedJwt = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证器
|
||||||
|
*/
|
||||||
|
protected mixed $validator = VehicleNewAskedTranslationValidator::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回业务 Service 实例
|
||||||
|
*/
|
||||||
|
protected function getService()
|
||||||
|
{
|
||||||
|
return new VehicleNewAskedTranslationService(new VehicleNewAskedTranslationModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 额外字段处理 (根据场景处理)
|
||||||
|
* @param array $item
|
||||||
|
* @param string $scene
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function postProcessItem(array $item, string $scene): array
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($scene === 'default') {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\controller;
|
||||||
|
|
||||||
|
use support\Request;
|
||||||
|
use support\Response;
|
||||||
|
use app\console\model\VehicleNewContentModel;
|
||||||
|
use app\console\service\VehicleNewContentService;
|
||||||
|
use app\console\validate\VehicleNewContentValidator;
|
||||||
|
use app\mzl\common\controller\BaseController;
|
||||||
|
|
||||||
|
class VehicleNewContentController extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不需要验证token的接口
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $noNeedJwt = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证器
|
||||||
|
*/
|
||||||
|
protected mixed $validator = VehicleNewContentValidator::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回业务 Service 实例
|
||||||
|
*/
|
||||||
|
protected function getService()
|
||||||
|
{
|
||||||
|
return new VehicleNewContentService(new VehicleNewContentModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 额外字段处理 (根据场景处理)
|
||||||
|
* @param array $item
|
||||||
|
* @param string $scene
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function postProcessItem(array $item, string $scene): array
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($scene === 'default') {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\controller;
|
||||||
|
|
||||||
|
use support\Request;
|
||||||
|
use support\Response;
|
||||||
|
use app\console\model\VehicleNewContentTranslationModel;
|
||||||
|
use app\console\service\VehicleNewContentTranslationService;
|
||||||
|
use app\console\validate\VehicleNewContentTranslationValidator;
|
||||||
|
use app\mzl\common\controller\BaseController;
|
||||||
|
|
||||||
|
class VehicleNewContentTranslationController extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不需要验证token的接口
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $noNeedJwt = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证器
|
||||||
|
*/
|
||||||
|
protected mixed $validator = VehicleNewContentTranslationValidator::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回业务 Service 实例
|
||||||
|
*/
|
||||||
|
protected function getService()
|
||||||
|
{
|
||||||
|
return new VehicleNewContentTranslationService(new VehicleNewContentTranslationModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 额外字段处理 (根据场景处理)
|
||||||
|
* @param array $item
|
||||||
|
* @param string $scene
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function postProcessItem(array $item, string $scene): array
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($scene === 'default') {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,189 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\controller;
|
||||||
|
|
||||||
|
use app\console\model\VehicleNewTranslationModel;
|
||||||
|
use support\Request;
|
||||||
|
use support\Response;
|
||||||
|
use app\console\model\VehicleNewModel;
|
||||||
|
use app\console\service\VehicleNewService;
|
||||||
|
use app\console\validate\VehicleNewValidator;
|
||||||
|
use app\mzl\common\controller\BaseController;
|
||||||
|
|
||||||
|
class VehicleNewController extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不需要验证token的接口
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $noNeedJwt = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证器
|
||||||
|
*/
|
||||||
|
protected mixed $validator = VehicleNewValidator::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回业务 Service 实例
|
||||||
|
*/
|
||||||
|
protected function getService()
|
||||||
|
{
|
||||||
|
return new VehicleNewService(new VehicleNewModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 额外字段处理 (根据场景处理)
|
||||||
|
* @param array $item
|
||||||
|
* @param string $scene
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function postProcessItem(array $item, string $scene): array
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($scene === 'default' || $scene === 'show') {
|
||||||
|
$result = [
|
||||||
|
'id' => $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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\controller;
|
||||||
|
|
||||||
|
use support\Request;
|
||||||
|
use support\Response;
|
||||||
|
use app\console\model\VehicleNewTraitModel;
|
||||||
|
use app\console\service\VehicleNewTraitService;
|
||||||
|
use app\console\validate\VehicleNewTraitValidator;
|
||||||
|
use app\mzl\common\controller\BaseController;
|
||||||
|
|
||||||
|
class VehicleNewTraitController extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不需要验证token的接口
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $noNeedJwt = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证器
|
||||||
|
*/
|
||||||
|
protected mixed $validator = VehicleNewTraitValidator::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回业务 Service 实例
|
||||||
|
*/
|
||||||
|
protected function getService()
|
||||||
|
{
|
||||||
|
return new VehicleNewTraitService(new VehicleNewTraitModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 额外字段处理 (根据场景处理)
|
||||||
|
* @param array $item
|
||||||
|
* @param string $scene
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function postProcessItem(array $item, string $scene): array
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($scene === 'default') {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\controller;
|
||||||
|
|
||||||
|
use support\Request;
|
||||||
|
use support\Response;
|
||||||
|
use app\console\model\VehicleNewTraitTranslationModel;
|
||||||
|
use app\console\service\VehicleNewTraitTranslationService;
|
||||||
|
use app\console\validate\VehicleNewTraitTranslationValidator;
|
||||||
|
use app\mzl\common\controller\BaseController;
|
||||||
|
|
||||||
|
class VehicleNewTraitTranslationController extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不需要验证token的接口
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $noNeedJwt = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证器
|
||||||
|
*/
|
||||||
|
protected mixed $validator = VehicleNewTraitTranslationValidator::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回业务 Service 实例
|
||||||
|
*/
|
||||||
|
protected function getService()
|
||||||
|
{
|
||||||
|
return new VehicleNewTraitTranslationService(new VehicleNewTraitTranslationModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 额外字段处理 (根据场景处理)
|
||||||
|
* @param array $item
|
||||||
|
* @param string $scene
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function postProcessItem(array $item, string $scene): array
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($scene === 'default') {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\controller;
|
||||||
|
|
||||||
|
use support\Request;
|
||||||
|
use support\Response;
|
||||||
|
use app\console\model\VehicleNewTranslationModel;
|
||||||
|
use app\console\service\VehicleNewTranslationService;
|
||||||
|
use app\console\validate\VehicleNewTranslationValidator;
|
||||||
|
use app\mzl\common\controller\BaseController;
|
||||||
|
|
||||||
|
class VehicleNewTranslationController extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不需要验证token的接口
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $noNeedJwt = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证器
|
||||||
|
*/
|
||||||
|
protected mixed $validator = VehicleNewTranslationValidator::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回业务 Service 实例
|
||||||
|
*/
|
||||||
|
protected function getService()
|
||||||
|
{
|
||||||
|
return new VehicleNewTranslationService(new VehicleNewTranslationModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 额外字段处理 (根据场景处理)
|
||||||
|
* @param array $item
|
||||||
|
* @param string $scene
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function postProcessItem(array $item, string $scene): array
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($scene === 'default') {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\model;
|
||||||
|
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VehicleDataModel
|
||||||
|
*/
|
||||||
|
class BrandBannerModel extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The connection name for the model.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
protected $connection = 'mysql';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'hs_brand_banner';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the table.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the model should be timestamped.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型的数据字段的保存格式。
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $dateFormat = 'U';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'brand_id', 'pic', 'status', 'sort', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $guarded = [];
|
||||||
|
|
||||||
|
|
||||||
|
public function brand()
|
||||||
|
{
|
||||||
|
return $this->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'
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\model;
|
||||||
|
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VehicleDataModel
|
||||||
|
*/
|
||||||
|
class BrandBannerTranslationModel extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The connection name for the model.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
protected $connection = 'mysql';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'hs_brand_banner_translation';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the table.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the model should be timestamped.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型的数据字段的保存格式。
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $dateFormat = 'U';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'brand_id', 'banner_id', 'alt', 'locale', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $guarded = [];
|
||||||
|
|
||||||
|
|
||||||
|
public function brand()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(BrandModel::class, 'brand_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function banner()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(BrandBannerModel::class, 'banner_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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');
|
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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\model;
|
||||||
|
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VehicleDataModel
|
||||||
|
*/
|
||||||
|
class BrandTraitModel extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The connection name for the model.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
protected $connection = 'mysql';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'hs_brand_trait';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the table.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the model should be timestamped.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型的数据字段的保存格式。
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $dateFormat = 'U';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'brand_id', 'status', 'sort', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $guarded = [];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function brand()
|
||||||
|
{
|
||||||
|
return $this->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'
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\model;
|
||||||
|
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VehicleDataModel
|
||||||
|
*/
|
||||||
|
class BrandTraitTranslationModel extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The connection name for the model.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
protected $connection = 'mysql';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'hs_brand_trait_translation';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the table.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the model should be timestamped.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型的数据字段的保存格式。
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $dateFormat = 'U';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'brand_id', 'trait_id', 'locale', 'title', 'content', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $guarded = [];
|
||||||
|
|
||||||
|
|
||||||
|
public function brand()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(BrandModel::class, 'brand_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function brandTrait()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(BrandTraitModel::class, 'trait_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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');
|
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')]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\model;
|
||||||
|
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VehicleNewAlbumModel
|
||||||
|
*/
|
||||||
|
class VehicleNewAlbumModel extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The connection name for the model.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
protected $connection = 'mysql';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'hs_vehicle_new_album';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the table.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the model should be timestamped.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型的数据字段的保存格式。
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $dateFormat = 'U';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'vehicle_id', 'pic', 'status', 'sort', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $guarded = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单条翻译
|
||||||
|
*/
|
||||||
|
public function translation()
|
||||||
|
{
|
||||||
|
return $this->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',
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\model;
|
||||||
|
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VehicleNewAlbumTranslationModel
|
||||||
|
*/
|
||||||
|
class VehicleNewAlbumTranslationModel extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The connection name for the model.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
protected $connection = 'mysql';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'hs_vehicle_new_album_translation';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the table.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the model should be timestamped.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型的数据字段的保存格式。
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $dateFormat = 'U';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'album_id', 'locale', 'alt', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $guarded = [];
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\model;
|
||||||
|
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VehicleNewAskedModel
|
||||||
|
*/
|
||||||
|
class VehicleNewAskedModel extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The connection name for the model.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
protected $connection = 'mysql';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'hs_vehicle_new_asked';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the table.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the model should be timestamped.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型的数据字段的保存格式。
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $dateFormat = 'U';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'vehicle_id', 'status', 'sort', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $guarded = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 相册字段
|
||||||
|
*/
|
||||||
|
const VEHICLE_NEW_ASKED_FIELDS = [
|
||||||
|
'title',
|
||||||
|
'content',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单条翻译
|
||||||
|
*/
|
||||||
|
public function translation()
|
||||||
|
{
|
||||||
|
return $this->hasOne(VehicleNewAskedTranslationModel::class, 'asked_id')->where('locale', locale());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 多条翻译
|
||||||
|
*/
|
||||||
|
public function translations()
|
||||||
|
{
|
||||||
|
return $this->hasMany(VehicleNewAskedTranslationModel::class, 'asked_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\model;
|
||||||
|
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VehicleNewAskedTranslationModel
|
||||||
|
*/
|
||||||
|
class VehicleNewAskedTranslationModel extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The connection name for the model.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
protected $connection = 'mysql';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'hs_vehicle_new_asked_translation';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the table.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the model should be timestamped.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型的数据字段的保存格式。
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $dateFormat = 'U';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'asked_id', 'locale', 'title', 'content', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $guarded = [];
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\model;
|
||||||
|
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VehicleNewContentModel
|
||||||
|
*/
|
||||||
|
class VehicleNewContentModel extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The connection name for the model.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
protected $connection = 'mysql';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'hs_vehicle_new_content';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the table.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the model should be timestamped.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型的数据字段的保存格式。
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $dateFormat = 'U';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'vehicle_id', 'status', 'sort', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $guarded = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单条翻译
|
||||||
|
*/
|
||||||
|
public function translation()
|
||||||
|
{
|
||||||
|
return $this->hasOne(VehicleNewContentTranslationModel::class, 'content_id')->where('locale', locale());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 多条翻译
|
||||||
|
*/
|
||||||
|
public function translations()
|
||||||
|
{
|
||||||
|
return $this->hasMany(VehicleNewContentTranslationModel::class, 'content_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\model;
|
||||||
|
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VehicleNewContentTranslationModel
|
||||||
|
*/
|
||||||
|
class VehicleNewContentTranslationModel extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The connection name for the model.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
protected $connection = 'mysql';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'hs_vehicle_new_content_translation';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the table.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the model should be timestamped.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型的数据字段的保存格式。
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $dateFormat = 'U';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'content_id', 'locale', 'content', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $guarded = [];
|
||||||
|
}
|
||||||
@@ -0,0 +1,121 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\model;
|
||||||
|
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VehicleNewModel
|
||||||
|
*/
|
||||||
|
class VehicleNewModel extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The connection name for the model.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
protected $connection = 'mysql';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'hs_vehicle_new';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the table.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the model should be timestamped.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型的数据字段的保存格式。
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $dateFormat = 'U';
|
||||||
|
|
||||||
|
/**x`
|
||||||
|
* 允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'vin', 'brand', 'cover', 'album', 'price', 'type', 'energy', 'model', 'video', 'views', 'created_at', 'updated_at', 'location'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $guarded = [];
|
||||||
|
|
||||||
|
const TRANS_FIELDS = [
|
||||||
|
'name', 'condition_desc'
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单条翻译
|
||||||
|
*/
|
||||||
|
public function translation()
|
||||||
|
{
|
||||||
|
return $this->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');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\model;
|
||||||
|
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VehicleNewTraitModel
|
||||||
|
*/
|
||||||
|
class VehicleNewTraitModel extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The connection name for the model.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
protected $connection = 'mysql';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'hs_vehicle_new_trait';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the table.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the model should be timestamped.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型的数据字段的保存格式。
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $dateFormat = 'U';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'vehicle_id', 'status', 'sort', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $guarded = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单条翻译
|
||||||
|
*/
|
||||||
|
public function translation()
|
||||||
|
{
|
||||||
|
return $this->hasOne(VehicleNewTraitTranslationModel::class, 'trait_id')->where('locale', locale());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 多条翻译
|
||||||
|
*/
|
||||||
|
public function translations()
|
||||||
|
{
|
||||||
|
return $this->hasMany(VehicleNewTraitTranslationModel::class, 'trait_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\model;
|
||||||
|
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VehicleNewTraitTranslationModel
|
||||||
|
*/
|
||||||
|
class VehicleNewTraitTranslationModel extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The connection name for the model.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
protected $connection = 'mysql';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'hs_vehicle_new_trait_translation';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the table.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the model should be timestamped.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型的数据字段的保存格式。
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $dateFormat = 'U';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'trait_id', 'locale', 'title', 'content', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $guarded = [];
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\model;
|
||||||
|
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VehicleNewTranslationModel
|
||||||
|
*/
|
||||||
|
class VehicleNewTranslationModel extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The connection name for the model.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
protected $connection = 'mysql';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'hs_vehicle_new_translation';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the table.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the model should be timestamped.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型的数据字段的保存格式。
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $dateFormat = 'U';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'vehicle_id', 'locale', 'name', 'condition_desc', 'location', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $guarded = [];
|
||||||
|
}
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\service;
|
||||||
|
|
||||||
|
use app\console\model\BrandBannerModel;
|
||||||
|
use app\mzl\common\services\BaseService;
|
||||||
|
use app\mzl\modules\translation\service\TranslationService;
|
||||||
|
use support\Db;
|
||||||
|
use support\exception\BusinessException;
|
||||||
|
|
||||||
|
class BrandBannerService extends BaseService
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定义模型
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getModel(): string
|
||||||
|
{
|
||||||
|
return BrandBannerModel::class;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 多场景配置
|
||||||
|
*/
|
||||||
|
public function queryScenes(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'default' => 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,13 +2,16 @@
|
|||||||
|
|
||||||
namespace app\console\service;
|
namespace app\console\service;
|
||||||
|
|
||||||
|
use app\console\model\BrandBannerModel;
|
||||||
use app\console\model\BrandModel;
|
use app\console\model\BrandModel;
|
||||||
|
use app\console\model\BrandTraitModel;
|
||||||
use app\mzl\common\services\BaseService;
|
use app\mzl\common\services\BaseService;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use support\exception\BusinessException;
|
use support\exception\BusinessException;
|
||||||
use support\Db;
|
use support\Db;
|
||||||
use app\mzl\modules\translation\service\TranslationService;
|
use app\mzl\modules\translation\service\TranslationService;
|
||||||
|
use support\Log;
|
||||||
|
|
||||||
class BrandService extends BaseService
|
class BrandService extends BaseService
|
||||||
{
|
{
|
||||||
@@ -30,12 +33,14 @@ class BrandService extends BaseService
|
|||||||
return [
|
return [
|
||||||
'default' => function ($params) {
|
'default' => function ($params) {
|
||||||
return [
|
return [
|
||||||
'filters' => [
|
'filters' => $params['filters'],
|
||||||
['field' => 'status', 'operator' => '=', 'value' => '1']
|
'fields' => ['id', 'status', 'sort', 'toppic', 'descpic', 'logo', 'letter', 'is_hot', 'created_at', 'updated_at'],
|
||||||
],
|
|
||||||
'fields' => ['id', 'status', 'sort', 'created_at', 'updated_at'],
|
|
||||||
'relations' => [
|
'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' => [
|
'sorts' => [
|
||||||
['field' => 'id', 'direction' => 'desc']
|
['field' => 'id', 'direction' => 'desc']
|
||||||
@@ -65,12 +70,20 @@ class BrandService extends BaseService
|
|||||||
|
|
||||||
|
|
||||||
protected array $translatable = [
|
protected array $translatable = [
|
||||||
'name'
|
'name', 'desc','toppic_alt','descpic_alt','logo_alt'
|
||||||
];
|
];
|
||||||
|
|
||||||
public function add(array $params)
|
public function add(array $params)
|
||||||
{
|
{
|
||||||
$sourceLocale = locale();
|
$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);
|
$sourceFields = $this->extractSourceFields($params);
|
||||||
if (empty($sourceFields)) {
|
if (empty($sourceFields)) {
|
||||||
throw new \InvalidArgumentException("请传递至少一条 {$sourceLocale} 语言的翻译字段");
|
throw new \InvalidArgumentException("请传递至少一条 {$sourceLocale} 语言的翻译字段");
|
||||||
@@ -91,8 +104,44 @@ class BrandService extends BaseService
|
|||||||
$sourceFields
|
$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();
|
Db::commit();
|
||||||
return true;
|
return $info->id;
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
Db::rollBack();
|
Db::rollBack();
|
||||||
throw $th;
|
throw $th;
|
||||||
@@ -102,6 +151,14 @@ class BrandService extends BaseService
|
|||||||
public function edit(array $params, int $id)
|
public function edit(array $params, int $id)
|
||||||
{
|
{
|
||||||
$sourceLocale = locale();
|
$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);
|
$sourceFields = $this->extractSourceFields($params);
|
||||||
if (empty($sourceFields)) {
|
if (empty($sourceFields)) {
|
||||||
throw new \InvalidArgumentException("请传递至少一条 {$sourceLocale} 语言的翻译字段");
|
throw new \InvalidArgumentException("请传递至少一条 {$sourceLocale} 语言的翻译字段");
|
||||||
@@ -122,6 +179,73 @@ class BrandService extends BaseService
|
|||||||
$sourceFields
|
$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();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
|
|||||||
@@ -0,0 +1,120 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\service;
|
||||||
|
|
||||||
|
use app\console\model\BrandTraitModel;
|
||||||
|
use app\mzl\common\services\BaseService;
|
||||||
|
use app\mzl\modules\translation\service\TranslationService;
|
||||||
|
use support\Db;
|
||||||
|
use support\exception\BusinessException;
|
||||||
|
|
||||||
|
class BrandTraitService extends BaseService
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定义模型
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getModel(): string
|
||||||
|
{
|
||||||
|
return BrandTraitModel::class;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 多场景配置
|
||||||
|
*/
|
||||||
|
public function queryScenes(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'default' => 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\service;
|
||||||
|
|
||||||
|
use app\console\model\VehicleNewAlbumModel;
|
||||||
|
use app\mzl\common\services\BaseService;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class VehicleNewAlbumService extends BaseService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 定义模型
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getModel(): string
|
||||||
|
{
|
||||||
|
return VehicleNewAlbumModel::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,
|
||||||
|
// ]
|
||||||
|
// ];
|
||||||
|
// }
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 声明需要多语言翻译
|
||||||
|
protected array $translatable = [
|
||||||
|
'alt',
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\service;
|
||||||
|
|
||||||
|
use app\console\model\VehicleNewAlbumTranslationModel;
|
||||||
|
use app\mzl\common\services\BaseService;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class VehicleNewAlbumTranslationService extends BaseService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 定义模型
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getModel(): string
|
||||||
|
{
|
||||||
|
return VehicleNewAlbumTranslationModel::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,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\service;
|
||||||
|
|
||||||
|
use app\console\model\VehicleNewAskedModel;
|
||||||
|
use app\mzl\common\services\BaseService;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class VehicleNewAskedService extends BaseService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 定义模型
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getModel(): string
|
||||||
|
{
|
||||||
|
return VehicleNewAskedModel::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,
|
||||||
|
// ]
|
||||||
|
// ];
|
||||||
|
// }
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 声明需要多语言翻译
|
||||||
|
protected array $translatable = [
|
||||||
|
'title',
|
||||||
|
'content',
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\service;
|
||||||
|
|
||||||
|
use app\console\model\VehicleNewAskedTranslationModel;
|
||||||
|
use app\mzl\common\services\BaseService;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class VehicleNewAskedTranslationService extends BaseService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 定义模型
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getModel(): string
|
||||||
|
{
|
||||||
|
return VehicleNewAskedTranslationModel::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,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\service;
|
||||||
|
|
||||||
|
use app\console\model\VehicleNewContentModel;
|
||||||
|
use app\mzl\common\services\BaseService;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class VehicleNewContentService extends BaseService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 定义模型
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getModel(): string
|
||||||
|
{
|
||||||
|
return VehicleNewContentModel::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,
|
||||||
|
// ]
|
||||||
|
// ];
|
||||||
|
// }
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 声明需要多语言翻译
|
||||||
|
protected array $translatable = [
|
||||||
|
'content',
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\service;
|
||||||
|
|
||||||
|
use app\console\model\VehicleNewContentTranslationModel;
|
||||||
|
use app\mzl\common\services\BaseService;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class VehicleNewContentTranslationService extends BaseService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 定义模型
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getModel(): string
|
||||||
|
{
|
||||||
|
return VehicleNewContentTranslationModel::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,434 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\service;
|
||||||
|
|
||||||
|
use app\console\model\VehicleNewAlbumModel;
|
||||||
|
use app\console\model\VehicleNewAskedModel;
|
||||||
|
use app\console\model\VehicleNewContentModel;
|
||||||
|
use app\console\model\VehicleNewModel;
|
||||||
|
use app\console\model\VehicleNewTraitModel;
|
||||||
|
use app\mzl\common\services\BaseService;
|
||||||
|
use app\mzl\modules\translation\service\TranslationService;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use support\Db;
|
||||||
|
use support\exception\BusinessException;
|
||||||
|
|
||||||
|
class VehicleNewService extends BaseService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 定义模型
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getModel(): string
|
||||||
|
{
|
||||||
|
return VehicleNewModel::class;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 多场景配置
|
||||||
|
*/
|
||||||
|
public function queryScenes(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'default' => 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\console\service;
|
||||||
|
|
||||||
|
use app\console\model\VehicleNewTraitModel;
|
||||||
|
use app\mzl\common\services\BaseService;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class VehicleNewTraitService extends BaseService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 定义模型
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getModel(): string
|
||||||
|
{
|
||||||
|
return VehicleNewTraitModel::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,
|
||||||
|
// ]
|
||||||
|
// ];
|
||||||
|
// }
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 声明需要多语言翻译
|
||||||
|
protected array $translatable = [
|
||||||
|
'title',
|
||||||
|
'content',
|
||||||
|
];
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user