Compare commits
77 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e5a03fa1cc | |||
| d184290e10 | |||
| 381fcb826a | |||
| 74ac6d3036 | |||
| 08cd3f3386 | |||
| 24298a7cd6 | |||
| ec12268247 | |||
| 24954f3fda | |||
| e2d5bbb34d | |||
| 770a8c3300 | |||
| d6db775b9b | |||
| d4c1755b3d | |||
| aa766b01e1 | |||
| 3099ce466b | |||
| f4d47faeaa | |||
| fe29a80e18 | |||
| 2107d56486 | |||
| 37167f8c28 | |||
| af17182605 | |||
| 61219df3d0 | |||
| 2360df3bf6 | |||
| e7eecd9b2b | |||
| 47dae69c62 | |||
| 5d0dbbc4ac | |||
| 1a1aa7e3aa | |||
| 8cf546100d | |||
| 8a1f7b7347 | |||
| b5765a25de | |||
| 5d9ee7098a | |||
| a94224c81e | |||
| 32cfaf8e9a | |||
| 72b296540a | |||
| 034d2a84f0 | |||
| dc1889fd12 | |||
| 79d3e59fce | |||
| ba53d10b47 | |||
| 413ea96a27 | |||
| 50f69c5efa | |||
| ad84e0d4ea | |||
| 8233a88bc7 | |||
| 1d9fbdb3a2 | |||
| 294f0b62c7 | |||
| dbca53f7d8 | |||
| af46fb9f46 | |||
| 9410d36145 | |||
| a136473171 | |||
| 2dbf422805 | |||
| 6cf0831c3e | |||
| 1fde0ad4eb | |||
| 26d3d7d115 | |||
| af63d438e1 | |||
| d8eb7efff2 | |||
| e927e22050 | |||
| 7dff3c5e3b | |||
| b09a83033a | |||
| ee8544a0bc | |||
| 0c5e2ed785 | |||
| 5ed23ecee7 | |||
| d0bf1e9833 | |||
| c762034dca | |||
| 26028a892c | |||
| 43a3d4037f | |||
| f87cf4574e | |||
| 04f690a56f | |||
| 0c6d3bea2a | |||
| 23a96ae7a7 | |||
| 3cb8c01bf1 | |||
| 0955e8c9d8 | |||
| 0125469e85 | |||
| 93ee1c3d47 | |||
| 3041e51234 | |||
| 72a47b4061 | |||
| 6d196fbc4d | |||
| 2a0bfc92cb | |||
| fee2241317 | |||
| 1e74a72d55 | |||
| c930f1f303 |
@@ -44,19 +44,12 @@ class AdpController extends BaseController
|
||||
if ($scene === 'default') {
|
||||
$item['title'] = isset($item['translation']) ? $item['translation']['title'] : '';
|
||||
unset($item['translation']);
|
||||
$ad = AdModel::with('translation')->where(['adp_id' => $item['id'], 'status' => 1])->limit(8)->get();
|
||||
foreach ($ad as $k => $v) {
|
||||
$v['type_txt'] = $v['type'] == 1?'新车' : ($v['type'] == 2?'二手车' : '');
|
||||
$v['alt'] = isset($v['translation']) ? $v['translation']['alt'] : '';
|
||||
$v['title'] = isset($v['translation']) ? $v['translation']['title'] : '';
|
||||
if(!empty($v['img'])){
|
||||
$v['full_img'] = (new \app\mzl\modules\upload\service\OssService())->generatePrivateUrl($v['img']);
|
||||
}else{
|
||||
$v['full_img'] = '';
|
||||
}
|
||||
unset($v['translation']);
|
||||
$item['ad'][$k] = $v;
|
||||
}
|
||||
$ad = AdModel::with('translation')->where(['adp_id' => $item['id'], 'type' => 1, 'status' => 1])->limit(8)->get()->toArray();
|
||||
$ad = $this->getService()->ad_arrange($ad);
|
||||
$item['new_ad'] = $ad;
|
||||
$ad = AdModel::with('translation')->where(['adp_id' => $item['id'], 'type' => 2, 'status' => 1])->limit(8)->get()->toArray();
|
||||
$ad = $this->getService()->ad_arrange($ad);
|
||||
$item['used_ad'] = $ad;
|
||||
}
|
||||
|
||||
return $item;
|
||||
|
||||
@@ -5,6 +5,8 @@ namespace app\apis\controller;
|
||||
use app\apis\model\BrandBannerModel;
|
||||
use app\apis\model\BrandTraitModel;
|
||||
use app\apis\model\BrandTranslationModel;
|
||||
use app\apis\model\VehicleNewModel;
|
||||
use app\apis\service\VehicleNewService;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use app\apis\model\BrandModel;
|
||||
@@ -88,6 +90,13 @@ class BrandController extends BaseController
|
||||
unset($v['translation']);
|
||||
$result['trait'][$k] = $v;
|
||||
}
|
||||
if($scene === 'hot'){
|
||||
$vehicles = VehicleNewModel::where(['brand'=>$item['id']])->limit(8)->get();
|
||||
foreach ($vehicles as &$v) {
|
||||
$v['cover_full'] = (new \app\mzl\modules\upload\service\OssService())->generatePrivateUrl($v['cover']);
|
||||
}
|
||||
$result['vehicle'] = $vehicles;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
return $item;
|
||||
@@ -103,12 +112,12 @@ class BrandController extends BaseController
|
||||
{
|
||||
$params = parent::prepareParams($request, $scene);
|
||||
|
||||
if ($scene === 'default' || $scene === 'letter') {
|
||||
if ($scene === 'default' || $scene === 'letter' || $scene === 'hot') {
|
||||
$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){
|
||||
if(isset($params['is_hot']) && $params['is_hot'] == 1 || $scene === 'hot'){
|
||||
$params['filters'][] = ['field' => 'is_hot', 'operator' => '=', 'value' => 1];
|
||||
}
|
||||
}
|
||||
@@ -146,6 +155,21 @@ class BrandController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*
|
||||
* @param Request $request 请求对象
|
||||
* @return Response 响应对象
|
||||
*/
|
||||
public function hot(Request $request, string $scene = 'hot'): Response
|
||||
{
|
||||
try {
|
||||
return parent::all($request, $scene);
|
||||
} catch (\Throwable $th) {
|
||||
return $this->errorResponse($th->getMessage().$th->getFile().$th->getLine());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace app\apis\controller;
|
||||
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use app\apis\model\VehicleNewAttributeValuesModel;
|
||||
use app\apis\service\VehicleNewAttributeValuesService;
|
||||
use app\apis\validate\VehicleNewAttributeValuesValidator;
|
||||
use app\mzl\common\controller\BaseController;
|
||||
|
||||
class VehicleNewAttributeValuesController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 不需要验证token的接口
|
||||
* @var array
|
||||
*/
|
||||
protected $noNeedJwt = [];
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected mixed $validator = VehicleNewAttributeValuesValidator::class;
|
||||
|
||||
/**
|
||||
* 返回业务 Service 实例
|
||||
*/
|
||||
protected function getService()
|
||||
{
|
||||
return new VehicleNewAttributeValuesService(new VehicleNewAttributeValuesModel());
|
||||
}
|
||||
|
||||
/**
|
||||
* 额外字段处理 (根据场景处理)
|
||||
* @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\VehicleNewAttributeValuesTranslationModel;
|
||||
use app\apis\service\VehicleNewAttributeValuesTranslationService;
|
||||
use app\apis\validate\VehicleNewAttributeValuesTranslationValidator;
|
||||
use app\mzl\common\controller\BaseController;
|
||||
|
||||
class VehicleNewAttributeValuesTranslationController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 不需要验证token的接口
|
||||
* @var array
|
||||
*/
|
||||
protected $noNeedJwt = [];
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected mixed $validator = VehicleNewAttributeValuesTranslationValidator::class;
|
||||
|
||||
/**
|
||||
* 返回业务 Service 实例
|
||||
*/
|
||||
protected function getService()
|
||||
{
|
||||
return new VehicleNewAttributeValuesTranslationService(new VehicleNewAttributeValuesTranslationModel());
|
||||
}
|
||||
|
||||
/**
|
||||
* 额外字段处理 (根据场景处理)
|
||||
* @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\VehicleNewAttributesModel;
|
||||
use app\apis\service\VehicleNewAttributesService;
|
||||
use app\apis\validate\VehicleNewAttributesValidator;
|
||||
use app\mzl\common\controller\BaseController;
|
||||
|
||||
class VehicleNewAttributesController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 不需要验证token的接口
|
||||
* @var array
|
||||
*/
|
||||
protected $noNeedJwt = [];
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected mixed $validator = VehicleNewAttributesValidator::class;
|
||||
|
||||
/**
|
||||
* 返回业务 Service 实例
|
||||
*/
|
||||
protected function getService()
|
||||
{
|
||||
return new VehicleNewAttributesService(new VehicleNewAttributesModel());
|
||||
}
|
||||
|
||||
/**
|
||||
* 额外字段处理 (根据场景处理)
|
||||
* @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\VehicleNewAttributesTranslationModel;
|
||||
use app\apis\service\VehicleNewAttributesTranslationService;
|
||||
use app\apis\validate\VehicleNewAttributesTranslationValidator;
|
||||
use app\mzl\common\controller\BaseController;
|
||||
|
||||
class VehicleNewAttributesTranslationController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 不需要验证token的接口
|
||||
* @var array
|
||||
*/
|
||||
protected $noNeedJwt = [];
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected mixed $validator = VehicleNewAttributesTranslationValidator::class;
|
||||
|
||||
/**
|
||||
* 返回业务 Service 实例
|
||||
*/
|
||||
protected function getService()
|
||||
{
|
||||
return new VehicleNewAttributesTranslationService(new VehicleNewAttributesTranslationModel());
|
||||
}
|
||||
|
||||
/**
|
||||
* 额外字段处理 (根据场景处理)
|
||||
* @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,8 @@
|
||||
|
||||
namespace app\apis\controller;
|
||||
|
||||
use app\apis\model\VehicleNewAttributesTranslationModel;
|
||||
use app\apis\model\VehicleNewAttributeValuesTranslationModel;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use app\apis\model\VehicleNewModel;
|
||||
@@ -104,6 +106,30 @@ class VehicleNewController extends BaseController
|
||||
$contentRes['content'] = isset($content['translation']) ? $content['translation']['content']:'';
|
||||
$result['content'][] = $contentRes;
|
||||
}
|
||||
|
||||
if(empty($item['sku'])){
|
||||
$result['sku'] = [];
|
||||
return $result;
|
||||
}
|
||||
foreach ($item['sku'] as &$sku) {
|
||||
$i=0;
|
||||
$skuAttributes = $sku['skuAttributes'];
|
||||
foreach ($skuAttributes as $key => &$skuAttribute){
|
||||
$attribute = VehicleNewAttributesTranslationModel::where(['attributes_id' => $skuAttribute['attribute']['id'],'locale'=>locale()])->first();
|
||||
$value = VehicleNewAttributeValuesTranslationModel::where(['values_id' => $skuAttribute['value']['id'],'locale'=>locale()])->first();
|
||||
|
||||
//$skuAttribute['attribute']['attribute_name'] = $attribute['attribute_name'] ;
|
||||
//$skuAttribute['value']['value_name'] = $value['value_name'];
|
||||
$sku['skuAttributes'][$key]['attribute_name'] = $attribute['attribute_name'];
|
||||
$sku['skuAttributes'][$key]['value_name'] = $value['value_name'];
|
||||
$sku['skuAttributes'][$key]['color_code'] =$sku['skuAttributes'][$key]['value']['color_code'];
|
||||
$sku['skuAttributes'][$key]['img_full'] = (!empty($skuAttribute['img']))?(new \app\mzl\modules\upload\service\OssService())->generatePrivateUrl($skuAttribute['img']):'';
|
||||
|
||||
}
|
||||
$sku['name'] = isset($sku['translation']) ? $sku['translation']['name']:'';
|
||||
unset($sku['translation']);
|
||||
$result['sku'][] = $sku;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace app\apis\controller;
|
||||
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use app\apis\model\VehicleNewSkuAttributesModel;
|
||||
use app\apis\service\VehicleNewSkuAttributesService;
|
||||
use app\apis\validate\VehicleNewSkuAttributesValidator;
|
||||
use app\mzl\common\controller\BaseController;
|
||||
|
||||
class VehicleNewSkuAttributesController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 不需要验证token的接口
|
||||
* @var array
|
||||
*/
|
||||
protected $noNeedJwt = [];
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected mixed $validator = VehicleNewSkuAttributesValidator::class;
|
||||
|
||||
/**
|
||||
* 返回业务 Service 实例
|
||||
*/
|
||||
protected function getService()
|
||||
{
|
||||
return new VehicleNewSkuAttributesService(new VehicleNewSkuAttributesModel());
|
||||
}
|
||||
|
||||
/**
|
||||
* 额外字段处理 (根据场景处理)
|
||||
* @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,98 @@
|
||||
<?php
|
||||
|
||||
namespace app\apis\controller;
|
||||
|
||||
use app\apis\model\VehicleNewAttributesTranslationModel;
|
||||
use app\apis\model\VehicleNewAttributeValuesTranslationModel;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use app\apis\model\VehicleNewSkusModel;
|
||||
use app\apis\service\VehicleNewSkusService;
|
||||
use app\apis\validate\VehicleNewSkusValidator;
|
||||
use app\mzl\common\controller\BaseController;
|
||||
|
||||
class VehicleNewSkusController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 不需要验证token的接口
|
||||
* @var array
|
||||
*/
|
||||
protected $noNeedJwt = [];
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected mixed $validator = VehicleNewSkusValidator::class;
|
||||
|
||||
/**
|
||||
* 返回业务 Service 实例
|
||||
*/
|
||||
protected function getService()
|
||||
{
|
||||
return new VehicleNewSkusService(new VehicleNewSkusModel());
|
||||
}
|
||||
|
||||
/**
|
||||
* 额外字段处理 (根据场景处理)
|
||||
* @param array $item
|
||||
* @param string $scene
|
||||
* @return array
|
||||
*/
|
||||
protected function postProcessItem(array $item, string $scene): array
|
||||
{
|
||||
if ($scene === 'default' || $scene === 'show') {
|
||||
foreach ($item['skuAttributes'] as &$skuAttribute){
|
||||
$attribute = VehicleNewAttributesTranslationModel::where(['attributes_id' => $skuAttribute['attribute']['id'],'locale'=>locale()])->first();
|
||||
$value = VehicleNewAttributeValuesTranslationModel::where(['values_id' => $skuAttribute['value']['id'],'locale'=>locale()])->first();
|
||||
|
||||
$skuAttribute['attribute']['attribute_name'] = $attribute['attribute_name'] ;
|
||||
$skuAttribute['value']['value_name'] = $value['value_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());
|
||||
}
|
||||
}
|
||||
|
||||
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\VehicleNewSkusTranslationModel;
|
||||
use app\apis\service\VehicleNewSkusTranslationService;
|
||||
use app\apis\validate\VehicleNewSkusTranslationValidator;
|
||||
use app\mzl\common\controller\BaseController;
|
||||
|
||||
class VehicleNewSkusTranslationController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 不需要验证token的接口
|
||||
* @var array
|
||||
*/
|
||||
protected $noNeedJwt = [];
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected mixed $validator = VehicleNewSkusTranslationValidator::class;
|
||||
|
||||
/**
|
||||
* 返回业务 Service 实例
|
||||
*/
|
||||
protected function getService()
|
||||
{
|
||||
return new VehicleNewSkusTranslationService(new VehicleNewSkusTranslationModel());
|
||||
}
|
||||
|
||||
/**
|
||||
* 额外字段处理 (根据场景处理)
|
||||
* @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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,4 +77,20 @@ class AdpModel extends Model
|
||||
{
|
||||
return $this->hasMany(AdModel::class, 'adp_id','id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 广告
|
||||
*/
|
||||
public function new_ad()
|
||||
{
|
||||
return $this->hasMany(AdModel::class, 'adp_id','id')->where(['type' => 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 广告
|
||||
*/
|
||||
public function used_ad()
|
||||
{
|
||||
return $this->hasMany(AdModel::class, 'adp_id','id')->where(['type' => 2]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace app\apis\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
/**
|
||||
* VehicleNewAttributeValuesModel
|
||||
*/
|
||||
class VehicleNewAttributeValuesModel 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_attribute_values';
|
||||
|
||||
/**
|
||||
* 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', 'attribute_id', 'color_code', 'price_modifier', 'sort_order', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
/**
|
||||
* 单条翻译
|
||||
*/
|
||||
public function translation()
|
||||
{
|
||||
return $this->hasOne(VehicleNewAttributeValuesTranslationModel::class, 'values_id')->where('locale', locale());
|
||||
}
|
||||
|
||||
/**
|
||||
* 多条翻译
|
||||
*/
|
||||
public function translations()
|
||||
{
|
||||
return $this->hasMany(VehicleNewAttributeValuesTranslationModel::class, 'values_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace app\apis\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
/**
|
||||
* VehicleNewAttributeValuesTranslationModel
|
||||
*/
|
||||
class VehicleNewAttributeValuesTranslationModel 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_attribute_values_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', 'values_id', 'locale', 'value_name', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace app\apis\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
/**
|
||||
* VehicleNewAttributesModel
|
||||
*/
|
||||
class VehicleNewAttributesModel 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_attributes';
|
||||
|
||||
/**
|
||||
* 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', 'category_id', 'is_required', 'input_type', 'is_img', 'status', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
/**
|
||||
* 单条翻译
|
||||
*/
|
||||
public function translation()
|
||||
{
|
||||
return $this->hasOne(VehicleNewAttributesTranslationModel::class, 'attributes_id','id')->where('locale', locale());
|
||||
}
|
||||
|
||||
/**
|
||||
* 多条翻译
|
||||
*/
|
||||
public function translations()
|
||||
{
|
||||
return $this->hasMany(VehicleNewAttributesTranslationModel::class, 'attributes_id');
|
||||
}
|
||||
|
||||
public function value()
|
||||
{
|
||||
return $this->hasMany(VehicleNewAttributeValuesModel::class, 'attribute_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace app\apis\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
/**
|
||||
* VehicleNewAttributesTranslationModel
|
||||
*/
|
||||
class VehicleNewAttributesTranslationModel 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_attributes_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', 'attributes_id', 'locale', 'attribute_name', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
}
|
||||
@@ -118,4 +118,9 @@ class VehicleNewModel extends Model
|
||||
{
|
||||
return $this->hasMany(VehicleNewContentModel::class, 'vehicle_id', 'id');
|
||||
}
|
||||
|
||||
public function sku()
|
||||
{
|
||||
return $this->hasMany(VehicleNewSkusModel::class, 'vehicle_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace app\apis\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
/**
|
||||
* VehicleNewSkuAttributesModel
|
||||
*/
|
||||
class VehicleNewSkuAttributesModel 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_sku_attributes';
|
||||
|
||||
/**
|
||||
* 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', 'sku_id', 'attribute_id', 'value_id', 'img', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
public function attribute()
|
||||
{
|
||||
return $this->belongsTo(VehicleNewAttributesModel::class, 'attribute_id', 'id');
|
||||
}
|
||||
|
||||
public function value()
|
||||
{
|
||||
return $this->belongsTo(VehicleNewAttributeValuesModel::class, 'value_id', 'id');
|
||||
}
|
||||
|
||||
public function skuAttributes()
|
||||
{
|
||||
return $this->belongsTo(VehicleNewSkusModel::class, 'sku_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace app\apis\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
/**
|
||||
* VehicleNewSkusModel
|
||||
*/
|
||||
class VehicleNewSkusModel 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_skus';
|
||||
|
||||
/**
|
||||
* 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', 'sku_code', 'stock', 'price', 'status', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
|
||||
public function skuAttributes()
|
||||
{
|
||||
return $this->hasMany(VehicleNewSkuAttributesModel::class, 'sku_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 单条翻译
|
||||
*/
|
||||
public function translation()
|
||||
{
|
||||
return $this->hasOne(VehicleNewSkusTranslationModel::class, 'sku_id')->where('locale', locale());
|
||||
}
|
||||
|
||||
/**
|
||||
* 多条翻译
|
||||
*/
|
||||
public function translations()
|
||||
{
|
||||
return $this->hasMany(VehicleNewSkusTranslationModel::class, 'sku_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace app\apis\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
/**
|
||||
* VehicleNewSkusTranslationModel
|
||||
*/
|
||||
class VehicleNewSkusTranslationModel 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_skus_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', 'sku_id', 'locale', 'name', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
}
|
||||
@@ -31,8 +31,10 @@ class AdpService extends BaseService
|
||||
'fields' => ['id', 'new_url', 'used_url', 'status', 'sort', 'creater', 'created_at', 'updated_at'],
|
||||
'relations' => [
|
||||
'translation' => ['adp_id', 'title'],
|
||||
'ad' => ['id', 'type', 'img', 'price', 'status', 'sort', 'creater', 'created_at', 'updated_at'],
|
||||
'ad.translation' => ['ad_id', 'alt', 'title'],
|
||||
// 'new_ad' => ['id', 'type', 'img', 'price', 'status', 'sort', 'creater', 'created_at', 'updated_at'],
|
||||
// 'new_ad.translation' => ['ad_id', 'alt', 'title'],
|
||||
// 'used_ad' => ['id', 'type', 'img', 'price', 'status', 'sort', 'creater', 'created_at', 'updated_at'],
|
||||
// 'used_ad.translation' => ['ad_id', 'alt', 'title'],
|
||||
],
|
||||
'sorts' => [
|
||||
['field' => 'sort', 'direction' => 'desc'],
|
||||
@@ -46,4 +48,20 @@ class AdpService extends BaseService
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
public function ad_arrange(array $ad): array{
|
||||
foreach ($ad as $k => &$v) {
|
||||
$v['type_txt'] = $v['type'] == 1?'新车' : ($v['type'] == 2?'二手车' : '');
|
||||
$v['alt'] = isset($v['translation']) ? $v['translation']['alt'] : '';
|
||||
$v['title'] = isset($v['translation']) ? $v['translation']['title'] : '';
|
||||
if(!empty($v['img'])){
|
||||
$v['full_img'] = (new \app\mzl\modules\upload\service\OssService())->generatePrivateUrl($v['img']);
|
||||
}else{
|
||||
$v['full_img'] = '';
|
||||
}
|
||||
unset($v['translation']);
|
||||
$item['ad'][$k] = $v;
|
||||
}
|
||||
return $ad;
|
||||
}
|
||||
}
|
||||
@@ -61,6 +61,22 @@ class BrandService extends BaseService
|
||||
],
|
||||
];
|
||||
},
|
||||
'hot' => 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' => [
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace app\apis\service;
|
||||
|
||||
use app\apis\model\VehicleNewAttributeValuesModel;
|
||||
use app\mzl\common\services\BaseService;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class VehicleNewAttributeValuesService extends BaseService
|
||||
{
|
||||
/**
|
||||
* 定义模型
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getModel(): string
|
||||
{
|
||||
return VehicleNewAttributeValuesModel::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\VehicleNewAttributeValuesTranslationModel;
|
||||
use app\mzl\common\services\BaseService;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class VehicleNewAttributeValuesTranslationService extends BaseService
|
||||
{
|
||||
/**
|
||||
* 定义模型
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getModel(): string
|
||||
{
|
||||
return VehicleNewAttributeValuesTranslationModel::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\VehicleNewAttributesModel;
|
||||
use app\mzl\common\services\BaseService;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class VehicleNewAttributesService extends BaseService
|
||||
{
|
||||
/**
|
||||
* 定义模型
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getModel(): string
|
||||
{
|
||||
return VehicleNewAttributesModel::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\VehicleNewAttributesTranslationModel;
|
||||
use app\mzl\common\services\BaseService;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class VehicleNewAttributesTranslationService extends BaseService
|
||||
{
|
||||
/**
|
||||
* 定义模型
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getModel(): string
|
||||
{
|
||||
return VehicleNewAttributesTranslationModel::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,
|
||||
// ]
|
||||
// ];
|
||||
// }
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -78,6 +78,11 @@ class VehicleNewService extends BaseService
|
||||
'types.translation' => ['type_id', 'name'],
|
||||
'energy.translation' => ['energy_id', 'name'],
|
||||
'models.translation' => ['model_id', 'name'],
|
||||
'sku' => [],
|
||||
'sku.skuAttributes' => ['id','sku_id','attribute_id','value_id','img',],
|
||||
'sku.skuAttributes.attribute' => ['id', 'input_type', 'is_img', 'status'],
|
||||
'sku.skuAttributes.value' => ['id','color_code'],
|
||||
'sku.translation' => ['sku_id', 'name', 'locale'],
|
||||
],
|
||||
'sorts' => [
|
||||
['field' => 'id', 'direction' => 'desc']
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace app\apis\service;
|
||||
|
||||
use app\apis\model\VehicleNewSkuAttributesModel;
|
||||
use app\mzl\common\services\BaseService;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class VehicleNewSkuAttributesService extends BaseService
|
||||
{
|
||||
/**
|
||||
* 定义模型
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getModel(): string
|
||||
{
|
||||
return VehicleNewSkuAttributesModel::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,93 @@
|
||||
<?php
|
||||
|
||||
namespace app\apis\service;
|
||||
|
||||
use app\apis\model\VehicleNewSkusModel;
|
||||
use app\mzl\common\services\BaseService;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class VehicleNewSkusService extends BaseService
|
||||
{
|
||||
/**
|
||||
* 定义模型
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getModel(): string
|
||||
{
|
||||
return VehicleNewSkusModel::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* 多场景配置
|
||||
*/
|
||||
public function queryScenes(): array
|
||||
{
|
||||
return [
|
||||
'default' => function ($params) {
|
||||
return [
|
||||
'filters' => [
|
||||
['field' => 'status', 'operator' => '=', 'value' => '1'],
|
||||
],
|
||||
'fields' => ['id','status'],
|
||||
'relations' => [
|
||||
'skuAttributes' => [],
|
||||
'skuAttributes.attribute' => ['id', 'input_type', 'is_img', 'status'],
|
||||
'skuAttributes.value' => ['id','color_code'],
|
||||
],
|
||||
'sorts' => [
|
||||
['field' => 'created_at', 'direction' => 'desc']
|
||||
],
|
||||
'pagination' => [
|
||||
'page' => $params['page'] ?? 1,
|
||||
'per_page' => $params['per_page'] ?? 10,
|
||||
]
|
||||
];
|
||||
},
|
||||
'show' => function ($params) {
|
||||
return [
|
||||
'filters' => [
|
||||
['field'=>'id', 'operator'=>'=', 'value'=> $params['id']],
|
||||
],
|
||||
'fields' => ['id', 'status'],
|
||||
'relations' => [
|
||||
'skuAttributes' => [],
|
||||
'skuAttributes.attribute' => ['id', 'input_type', 'is_img', 'status'],
|
||||
'skuAttributes.attribute.translation' => ['attribute_name'],
|
||||
'skuAttributes.value' => ['id','color_code'],
|
||||
],
|
||||
];
|
||||
},
|
||||
// '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\VehicleNewSkusTranslationModel;
|
||||
use app\mzl\common\services\BaseService;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class VehicleNewSkusTranslationService extends BaseService
|
||||
{
|
||||
/**
|
||||
* 定义模型
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getModel(): string
|
||||
{
|
||||
return VehicleNewSkusTranslationModel::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 VehicleNewAttributeValuesTranslationValidator extends Validate
|
||||
{
|
||||
// 规则
|
||||
protected $rule = [
|
||||
|
||||
];
|
||||
|
||||
// 提示
|
||||
protected $message = [
|
||||
|
||||
];
|
||||
|
||||
// 场景
|
||||
protected $scene = [
|
||||
'store' => [
|
||||
|
||||
],
|
||||
|
||||
'update' => [
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\apis\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class VehicleNewAttributeValuesValidator extends Validate
|
||||
{
|
||||
// 规则
|
||||
protected $rule = [
|
||||
|
||||
];
|
||||
|
||||
// 提示
|
||||
protected $message = [
|
||||
|
||||
];
|
||||
|
||||
// 场景
|
||||
protected $scene = [
|
||||
'store' => [
|
||||
|
||||
],
|
||||
|
||||
'update' => [
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\apis\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class VehicleNewAttributesTranslationValidator extends Validate
|
||||
{
|
||||
// 规则
|
||||
protected $rule = [
|
||||
|
||||
];
|
||||
|
||||
// 提示
|
||||
protected $message = [
|
||||
|
||||
];
|
||||
|
||||
// 场景
|
||||
protected $scene = [
|
||||
'store' => [
|
||||
|
||||
],
|
||||
|
||||
'update' => [
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\apis\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class VehicleNewAttributesValidator extends Validate
|
||||
{
|
||||
// 规则
|
||||
protected $rule = [
|
||||
|
||||
];
|
||||
|
||||
// 提示
|
||||
protected $message = [
|
||||
|
||||
];
|
||||
|
||||
// 场景
|
||||
protected $scene = [
|
||||
'store' => [
|
||||
|
||||
],
|
||||
|
||||
'update' => [
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\apis\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class VehicleNewSkuAttributesValidator extends Validate
|
||||
{
|
||||
// 规则
|
||||
protected $rule = [
|
||||
|
||||
];
|
||||
|
||||
// 提示
|
||||
protected $message = [
|
||||
|
||||
];
|
||||
|
||||
// 场景
|
||||
protected $scene = [
|
||||
'store' => [
|
||||
|
||||
],
|
||||
|
||||
'update' => [
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\apis\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class VehicleNewSkusTranslationValidator extends Validate
|
||||
{
|
||||
// 规则
|
||||
protected $rule = [
|
||||
|
||||
];
|
||||
|
||||
// 提示
|
||||
protected $message = [
|
||||
|
||||
];
|
||||
|
||||
// 场景
|
||||
protected $scene = [
|
||||
'store' => [
|
||||
|
||||
],
|
||||
|
||||
'update' => [
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\apis\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class VehicleNewSkusValidator extends Validate
|
||||
{
|
||||
// 规则
|
||||
protected $rule = [
|
||||
|
||||
];
|
||||
|
||||
// 提示
|
||||
protected $message = [
|
||||
|
||||
];
|
||||
|
||||
// 场景
|
||||
protected $scene = [
|
||||
'store' => [
|
||||
|
||||
],
|
||||
|
||||
'update' => [
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -130,9 +130,6 @@ class BrandController extends BaseController
|
||||
*/
|
||||
public function index(Request $request, string $scene = 'default'): Response
|
||||
{
|
||||
// $Brand = BrandModel::with('banner')->with('trait')->where('id',314)->first()->toArray();
|
||||
// var_dump($Brand);
|
||||
// return json($Brand);
|
||||
try {
|
||||
return parent::index($request, $scene);
|
||||
} catch (\Throwable $th) {
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\controller;
|
||||
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use app\console\model\VehicleNewAttributeCategoriesModel;
|
||||
use app\console\service\VehicleNewAttributeCategoriesService;
|
||||
use app\console\validate\VehicleNewAttributeCategoriesValidator;
|
||||
use app\mzl\common\controller\BaseController;
|
||||
|
||||
class VehicleNewAttributeCategoriesController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 不需要验证token的接口
|
||||
* @var array
|
||||
*/
|
||||
protected $noNeedJwt = [];
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected mixed $validator = VehicleNewAttributeCategoriesValidator::class;
|
||||
|
||||
/**
|
||||
* 返回业务 Service 实例
|
||||
*/
|
||||
protected function getService()
|
||||
{
|
||||
return new VehicleNewAttributeCategoriesService(new VehicleNewAttributeCategoriesModel());
|
||||
}
|
||||
|
||||
/**
|
||||
* 额外字段处理 (根据场景处理)
|
||||
* @param array $item
|
||||
* @param string $scene
|
||||
* @return array
|
||||
*/
|
||||
protected function postProcessItem(array $item, string $scene): array
|
||||
{
|
||||
if ($scene === 'default' || $scene === 'show' || $scene === 'preset') {
|
||||
$result = [
|
||||
'id' => $item['id'],
|
||||
'sort_order' => $item['sort_order'],
|
||||
'category_name' => isset($item['translation']) ? $item['translation']['category_name'] : '',
|
||||
];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数预处理 (根据场景处理)
|
||||
* @param Request $request
|
||||
* @param string $scene
|
||||
* @return array
|
||||
*/
|
||||
protected function prepareParams(Request $request, string $scene): array
|
||||
{
|
||||
$params = parent::prepareParams($request, $scene);
|
||||
|
||||
if ($scene === 'default') {
|
||||
|
||||
}
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*
|
||||
* @param Request $request 请求对象
|
||||
* @return Response 响应对象
|
||||
*/
|
||||
public function index(Request $request, string $scene = 'default'): Response
|
||||
{
|
||||
try {
|
||||
return parent::index($request, $scene);
|
||||
} catch (\Throwable $th) {
|
||||
return $this->errorResponse($th->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function presets(Request $request, string $scene = 'preset'): Response
|
||||
{
|
||||
try {
|
||||
return parent::all($request, $scene);
|
||||
} catch (\Throwable $th) {
|
||||
return $this->errorResponse($th->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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().$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().$th->getLine().$th->getFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\controller;
|
||||
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use app\console\model\VehicleNewAttributeCategoriesTranslationModel;
|
||||
use app\console\service\VehicleNewAttributeCategoriesTranslationService;
|
||||
use app\console\validate\VehicleNewAttributeCategoriesTranslationValidator;
|
||||
use app\mzl\common\controller\BaseController;
|
||||
|
||||
class VehicleNewAttributeCategoriesTranslationController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 不需要验证token的接口
|
||||
* @var array
|
||||
*/
|
||||
protected $noNeedJwt = [];
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected mixed $validator = VehicleNewAttributeCategoriesTranslationValidator::class;
|
||||
|
||||
/**
|
||||
* 返回业务 Service 实例
|
||||
*/
|
||||
protected function getService()
|
||||
{
|
||||
return new VehicleNewAttributeCategoriesTranslationService(new VehicleNewAttributeCategoriesTranslationModel());
|
||||
}
|
||||
|
||||
/**
|
||||
* 额外字段处理 (根据场景处理)
|
||||
* @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,103 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\controller;
|
||||
|
||||
use app\console\model\VehicleNewAttributeValuesTranslationModel;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use app\console\model\VehicleNewAttributeValuesModel;
|
||||
use app\console\service\VehicleNewAttributeValuesService;
|
||||
use app\console\validate\VehicleNewAttributeValuesValidator;
|
||||
use app\mzl\common\controller\BaseController;
|
||||
|
||||
class VehicleNewAttributeValuesController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 不需要验证token的接口
|
||||
* @var array
|
||||
*/
|
||||
protected $noNeedJwt = [];
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected mixed $validator = VehicleNewAttributeValuesValidator::class;
|
||||
|
||||
/**
|
||||
* 返回业务 Service 实例
|
||||
*/
|
||||
protected function getService()
|
||||
{
|
||||
return new VehicleNewAttributeValuesService(new VehicleNewAttributeValuesModel());
|
||||
}
|
||||
|
||||
/**
|
||||
* 额外字段处理 (根据场景处理)
|
||||
* @param array $item
|
||||
* @param string $scene
|
||||
* @return array
|
||||
*/
|
||||
protected function postProcessItem(array $item, string $scene): array
|
||||
{
|
||||
|
||||
if ($scene === 'default') {
|
||||
|
||||
}
|
||||
|
||||
if ($scene === 'preset') {
|
||||
$result = [
|
||||
'id' => $item['id'],
|
||||
'color_code' => $item['color_code'],
|
||||
// 'value_name' => isset($item['translation']) ? $item['translation']['value_name'] : '1',
|
||||
];
|
||||
$translation = VehicleNewAttributeValuesTranslationModel::where(['values_id' => $item['id'],'locale'=>locale()])->first();
|
||||
$result['value_name'] = $translation->value_name;
|
||||
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') {
|
||||
|
||||
}
|
||||
if ($scene === 'preset') {
|
||||
$params['filters'][] = ['field' => 'attribute_id', 'operator' => '=', 'value' => $params['id']];
|
||||
}
|
||||
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 presets(Request $request, string $scene = 'preset'): Response
|
||||
{
|
||||
try {
|
||||
return parent::all($request, $scene);
|
||||
} catch (\Throwable $th) {
|
||||
return $this->errorResponse($th->getMessage().$th->getFile().$th->getLine());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\controller;
|
||||
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use app\console\model\VehicleNewAttributeValuesTranslationModel;
|
||||
use app\console\service\VehicleNewAttributeValuesTranslationService;
|
||||
use app\console\validate\VehicleNewAttributeValuesTranslationValidator;
|
||||
use app\mzl\common\controller\BaseController;
|
||||
|
||||
class VehicleNewAttributeValuesTranslationController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 不需要验证token的接口
|
||||
* @var array
|
||||
*/
|
||||
protected $noNeedJwt = [];
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected mixed $validator = VehicleNewAttributeValuesTranslationValidator::class;
|
||||
|
||||
/**
|
||||
* 返回业务 Service 实例
|
||||
*/
|
||||
protected function getService()
|
||||
{
|
||||
return new VehicleNewAttributeValuesTranslationService(new VehicleNewAttributeValuesTranslationModel());
|
||||
}
|
||||
|
||||
/**
|
||||
* 额外字段处理 (根据场景处理)
|
||||
* @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,151 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\controller;
|
||||
|
||||
use app\console\model\VehicleNewAttributeCategoriesTranslationModel;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use app\console\model\VehicleNewAttributesModel;
|
||||
use app\console\service\VehicleNewAttributesService;
|
||||
use app\console\validate\VehicleNewAttributesValidator;
|
||||
use app\mzl\common\controller\BaseController;
|
||||
|
||||
class VehicleNewAttributesController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 不需要验证token的接口
|
||||
* @var array
|
||||
*/
|
||||
protected $noNeedJwt = [];
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected mixed $validator = VehicleNewAttributesValidator::class;
|
||||
|
||||
/**
|
||||
* 返回业务 Service 实例
|
||||
*/
|
||||
protected function getService()
|
||||
{
|
||||
return new VehicleNewAttributesService(new VehicleNewAttributesModel());
|
||||
}
|
||||
|
||||
/**
|
||||
* 额外字段处理 (根据场景处理)
|
||||
* @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'],
|
||||
'status' => $item['status'],
|
||||
'category_id' => $item['category_id'],
|
||||
'input_type' => $item['input_type'],
|
||||
'is_img' => $item['is_img'],
|
||||
'attribute_name' => isset($item['translation']) ? $item['translation']['attribute_name'] : '',
|
||||
];
|
||||
|
||||
if(!empty($item['category_id'])){
|
||||
$category = VehicleNewAttributeCategoriesTranslationModel::where(['categories_id'=>$item['category_id']])->first();
|
||||
$result['category_name'] = $category['category_name'];
|
||||
}
|
||||
|
||||
foreach ($item['value'] as $value) {
|
||||
$valueRes['id'] = $value['id'];
|
||||
$valueRes['attribute_id'] = $value['attribute_id'];
|
||||
$valueRes['color_code'] = $value['color_code'];
|
||||
$valueRes['value_name'] = isset($value['translation']) ? $value['translation']['value_name']:'';
|
||||
$result['value'][] = $valueRes;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
if ($scene === 'preset') {
|
||||
return [
|
||||
'id' => $item['id'],
|
||||
'is_img' => $item['is_img'],
|
||||
'attribute_name' => isset($item['translation']) ? $item['translation']['attribute_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 {
|
||||
return $this->getService()->add($request->all())
|
||||
? $this->successResponse()
|
||||
: $this->errorResponse();
|
||||
} catch (\Throwable $th) {
|
||||
return $this->errorResponse($th->getMessage().$th->getLine().$th->getFile());
|
||||
}
|
||||
}
|
||||
|
||||
public function presets(Request $request, string $scene = 'preset'): Response
|
||||
{
|
||||
try {
|
||||
return parent::all($request, $scene);
|
||||
} 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().$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().$th->getLine().$th->getFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\controller;
|
||||
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use app\console\model\VehicleNewAttributesTranslationModel;
|
||||
use app\console\service\VehicleNewAttributesTranslationService;
|
||||
use app\console\validate\VehicleNewAttributesTranslationValidator;
|
||||
use app\mzl\common\controller\BaseController;
|
||||
|
||||
class VehicleNewAttributesTranslationController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 不需要验证token的接口
|
||||
* @var array
|
||||
*/
|
||||
protected $noNeedJwt = [];
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected mixed $validator = VehicleNewAttributesTranslationValidator::class;
|
||||
|
||||
/**
|
||||
* 返回业务 Service 实例
|
||||
*/
|
||||
protected function getService()
|
||||
{
|
||||
return new VehicleNewAttributesTranslationService(new VehicleNewAttributesTranslationModel());
|
||||
}
|
||||
|
||||
/**
|
||||
* 额外字段处理 (根据场景处理)
|
||||
* @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,87 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\controller;
|
||||
|
||||
use app\console\model\VehicleNewAttributesTranslationModel;
|
||||
use app\console\model\VehicleNewAttributeValuesTranslationModel;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use app\console\model\VehicleNewSkuAttributesModel;
|
||||
use app\console\service\VehicleNewSkuAttributesService;
|
||||
use app\console\validate\VehicleNewSkuAttributesValidator;
|
||||
use app\mzl\common\controller\BaseController;
|
||||
|
||||
class VehicleNewSkuAttributesController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 不需要验证token的接口
|
||||
* @var array
|
||||
*/
|
||||
protected $noNeedJwt = [];
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected mixed $validator = VehicleNewSkuAttributesValidator::class;
|
||||
|
||||
/**
|
||||
* 返回业务 Service 实例
|
||||
*/
|
||||
protected function getService()
|
||||
{
|
||||
return new VehicleNewSkuAttributesService(new VehicleNewSkuAttributesModel());
|
||||
}
|
||||
|
||||
/**
|
||||
* 额外字段处理 (根据场景处理)
|
||||
* @param array $item
|
||||
* @param string $scene
|
||||
* @return array
|
||||
*/
|
||||
protected function postProcessItem(array $item, string $scene): array
|
||||
{
|
||||
|
||||
if ($scene === 'default' || $scene === 'show') {
|
||||
$attribute = VehicleNewAttributesTranslationModel::where(['attributes_id' => $item['attribute']['id'],'locale'=>locale()])->first();
|
||||
$value = VehicleNewAttributeValuesTranslationModel::where(['values_id' => $item['value']['id'],'locale'=>locale()])->first();
|
||||
|
||||
$item['attribute']['attribute_name'] = $attribute['attribute_name'] ;
|
||||
$item['value']['value_name'] = $value['value_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->getLine().$th->getFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\controller;
|
||||
|
||||
use app\console\model\VehicleNewAttributesTranslationModel;
|
||||
use app\console\model\VehicleNewAttributeValuesTranslationModel;
|
||||
use app\console\model\VehicleNewSkuAttributesModel;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use app\console\model\VehicleNewSkusModel;
|
||||
use app\console\service\VehicleNewSkusService;
|
||||
use app\console\validate\VehicleNewSkusValidator;
|
||||
use app\mzl\common\controller\BaseController;
|
||||
|
||||
class VehicleNewSkusController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 不需要验证token的接口
|
||||
* @var array
|
||||
*/
|
||||
protected $noNeedJwt = [];
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected mixed $validator = VehicleNewSkusValidator::class;
|
||||
|
||||
/**
|
||||
* 返回业务 Service 实例
|
||||
*/
|
||||
protected function getService()
|
||||
{
|
||||
return new VehicleNewSkusService(new VehicleNewSkusModel());
|
||||
}
|
||||
|
||||
/**
|
||||
* 额外字段处理 (根据场景处理)
|
||||
* @param array $item
|
||||
* @param string $scene
|
||||
* @return array
|
||||
*/
|
||||
protected function postProcessItem(array $item, string $scene): array
|
||||
{
|
||||
|
||||
if ($scene === 'default' || $scene === 'show') {
|
||||
foreach ($item['skuAttributes'] as &$skuAttribute){
|
||||
$attribute = VehicleNewAttributesTranslationModel::where(['attributes_id' => $skuAttribute['attribute']['id'],'locale'=>locale()])->first();
|
||||
$value = VehicleNewAttributeValuesTranslationModel::where(['values_id' => $skuAttribute['value']['id'],'locale'=>locale()])->first();
|
||||
|
||||
$skuAttribute['attribute']['attribute_name'] = $attribute['attribute_name'] ;
|
||||
$skuAttribute['value']['value_name'] = $value['value_name'];
|
||||
$skuAttribute['img_full'] = (!empty($skuAttribute['img']))?(new \app\mzl\modules\upload\service\OssService())->generatePrivateUrl($skuAttribute['img']):'';
|
||||
|
||||
}
|
||||
$item['name'] = isset($item['translation']) ? $item['translation']['name'] : '';
|
||||
unset($item['translation']);
|
||||
}
|
||||
|
||||
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'][] = ['field' => 'status', 'operator' => '=', 'value' => '1'];
|
||||
$params['filters'][] = ['field' => 'vehicle_id', 'operator' => '=', 'value' => $params['id']];
|
||||
}
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*
|
||||
* @param Request $request 请求对象
|
||||
* @return Response 响应对象
|
||||
*/
|
||||
public function index(Request $request, string $scene = 'default'): Response
|
||||
{
|
||||
try {
|
||||
if(empty($request->get('id'))){
|
||||
return $this->errorResponse('id is not null');
|
||||
}
|
||||
return parent::index($request, $scene);
|
||||
} catch (\Throwable $th) {
|
||||
return $this->errorResponse($th->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
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\VehicleNewSkusTranslationModel;
|
||||
use app\console\service\VehicleNewSkusTranslationService;
|
||||
use app\console\validate\VehicleNewSkusTranslationValidator;
|
||||
use app\mzl\common\controller\BaseController;
|
||||
|
||||
class VehicleNewSkusTranslationController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 不需要验证token的接口
|
||||
* @var array
|
||||
*/
|
||||
protected $noNeedJwt = [];
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected mixed $validator = VehicleNewSkusTranslationValidator::class;
|
||||
|
||||
/**
|
||||
* 返回业务 Service 实例
|
||||
*/
|
||||
protected function getService()
|
||||
{
|
||||
return new VehicleNewSkusTranslationService(new VehicleNewSkusTranslationModel());
|
||||
}
|
||||
|
||||
/**
|
||||
* 额外字段处理 (根据场景处理)
|
||||
* @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,78 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
/**
|
||||
* VehicleNewAttributeCategoriesModel
|
||||
*/
|
||||
class VehicleNewAttributeCategoriesModel 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_attribute_categories';
|
||||
|
||||
/**
|
||||
* 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', 'category_name', 'sort_order', 'created_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
|
||||
/**
|
||||
* 单条翻译
|
||||
*/
|
||||
public function translation()
|
||||
{
|
||||
return $this->hasOne(VehicleNewAttributeCategoriesTranslationModel::class, 'categories_id')->where('locale', locale());
|
||||
}
|
||||
|
||||
/**
|
||||
* 多条翻译
|
||||
*/
|
||||
public function translations()
|
||||
{
|
||||
return $this->hasMany(VehicleNewAttributeCategoriesTranslationModel::class, 'categories_id');
|
||||
}
|
||||
|
||||
public function attribute()
|
||||
{
|
||||
return $this->hasMany(VehicleNewAttributesModel::class, 'category_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
/**
|
||||
* VehicleNewAttributeCategoriesTranslationModel
|
||||
*/
|
||||
class VehicleNewAttributeCategoriesTranslationModel 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_attribute_categories_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', 'categories_id', 'locale', 'category_name', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
/**
|
||||
* VehicleNewAttributeValuesModel
|
||||
*/
|
||||
class VehicleNewAttributeValuesModel 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_attribute_values';
|
||||
|
||||
/**
|
||||
* 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', 'attribute_id', 'value_name', 'color_code', 'price_modifier', 'sort_order', 'created_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
/**
|
||||
* 单条翻译
|
||||
*/
|
||||
public function translation()
|
||||
{
|
||||
return $this->hasOne(VehicleNewAttributeValuesTranslationModel::class, 'values_id')->where('locale', locale());
|
||||
}
|
||||
|
||||
/**
|
||||
* 多条翻译
|
||||
*/
|
||||
public function translations()
|
||||
{
|
||||
return $this->hasMany(VehicleNewAttributeValuesTranslationModel::class, 'values_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
/**
|
||||
* VehicleNewAttributeValuesTranslationModel
|
||||
*/
|
||||
class VehicleNewAttributeValuesTranslationModel 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_attribute_values_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', 'values_id', 'locale', 'value_name', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
/**
|
||||
* VehicleNewAttributesModel
|
||||
*/
|
||||
class VehicleNewAttributesModel 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_attributes';
|
||||
|
||||
/**
|
||||
* 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', 'category_id', 'attribute_name', 'is_required', 'input_type', 'is_img', 'status', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
/**
|
||||
* 单条翻译
|
||||
*/
|
||||
public function translation()
|
||||
{
|
||||
return $this->hasOne(VehicleNewAttributesTranslationModel::class, 'attributes_id','id')->where('locale', locale());
|
||||
}
|
||||
|
||||
/**
|
||||
* 多条翻译
|
||||
*/
|
||||
public function translations()
|
||||
{
|
||||
return $this->hasMany(VehicleNewAttributesTranslationModel::class, 'attributes_id');
|
||||
}
|
||||
|
||||
public function value()
|
||||
{
|
||||
return $this->hasMany(VehicleNewAttributeValuesModel::class, 'attribute_id', 'id');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
/**
|
||||
* VehicleNewAttributesTranslationModel
|
||||
*/
|
||||
class VehicleNewAttributesTranslationModel 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_attributes_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', 'attributes_id', 'locale', 'attribute_name', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
/**
|
||||
* VehicleNewSkuAttributesModel
|
||||
*/
|
||||
class VehicleNewSkuAttributesModel 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_sku_attributes';
|
||||
|
||||
/**
|
||||
* 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', 'sku_id', 'attribute_id', 'value_id', 'img', 'created_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
public function attribute()
|
||||
{
|
||||
return $this->belongsTo(VehicleNewAttributesModel::class, 'attribute_id', 'id');
|
||||
}
|
||||
|
||||
public function value()
|
||||
{
|
||||
return $this->belongsTo(VehicleNewAttributeValuesModel::class, 'value_id', 'id');
|
||||
}
|
||||
|
||||
public function skuAttributes()
|
||||
{
|
||||
return $this->belongsTo(VehicleNewSkusModel::class, 'sku_id', 'id');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
/**
|
||||
* VehicleNewSkusModel
|
||||
*/
|
||||
class VehicleNewSkusModel 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_skus';
|
||||
|
||||
/**
|
||||
* 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', 'sku_code', 'stock', 'price', 'status', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
public function skuAttributes()
|
||||
{
|
||||
return $this->hasMany(VehicleNewSkuAttributesModel::class, 'sku_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 单条翻译
|
||||
*/
|
||||
public function translation()
|
||||
{
|
||||
return $this->hasOne(VehicleNewSkusTranslationModel::class, 'sku_id')->where('locale', locale());
|
||||
}
|
||||
|
||||
/**
|
||||
* 多条翻译
|
||||
*/
|
||||
public function translations()
|
||||
{
|
||||
return $this->hasMany(VehicleNewSkusTranslationModel::class, 'sku_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
/**
|
||||
* VehicleNewSkusTranslationModel
|
||||
*/
|
||||
class VehicleNewSkusTranslationModel 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_skus_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', 'sku_id', 'locale', 'name', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\service;
|
||||
|
||||
use app\console\model\VehicleNewAttributeCategoriesModel;
|
||||
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 VehicleNewAttributeCategoriesService extends BaseService
|
||||
{
|
||||
/**
|
||||
* 定义模型
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getModel(): string
|
||||
{
|
||||
return VehicleNewAttributeCategoriesModel::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* 多场景配置
|
||||
*/
|
||||
public function queryScenes(): array
|
||||
{
|
||||
return [
|
||||
'default' => function ($params) {
|
||||
return [
|
||||
'filters' => [
|
||||
],
|
||||
'fields' => ['id','sort_order'],
|
||||
'relations' => [
|
||||
'translation' => ['categories_id', 'locale', 'category_name'],
|
||||
'attribute' => ['id','status'],
|
||||
'attribute.translation' => ['attributes_id', 'locale', 'attribute_name'],
|
||||
],
|
||||
'sorts' => [
|
||||
['field' => 'created_at', 'direction' => 'desc']
|
||||
],
|
||||
'pagination' => [
|
||||
'page' => $params['page'] ?? 1,
|
||||
'per_page' => $params['per_page'] ?? 10,
|
||||
]
|
||||
];
|
||||
},
|
||||
'preset' => function ($params) {
|
||||
return [
|
||||
'filters' => [
|
||||
],
|
||||
'fields' => ['id','sort_order'],
|
||||
'relations' => [
|
||||
'translation' => ['categories_id', 'locale', 'category_name'],
|
||||
'attribute' => ['id','status'],
|
||||
'attribute.translation' => ['attributes_id', 'locale', 'attribute_name'],
|
||||
],
|
||||
'sorts' => [
|
||||
['field' => 'created_at', 'direction' => 'desc']
|
||||
],
|
||||
];
|
||||
},
|
||||
'show' => function ($params) {
|
||||
return [
|
||||
'filters' => [
|
||||
['field'=>'id', 'operator'=>'=', 'value'=> $params['id']],
|
||||
],
|
||||
'fields' => ['id', 'status'],
|
||||
'relations' => [
|
||||
'translation' => ['categories_id', 'locale', 'category_name'],
|
||||
'attribute' => ['id','status'],
|
||||
'attribute.translation' => ['attributes_id', 'locale', 'attribute_name'],
|
||||
],
|
||||
];
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
// 声明需要多语言翻译
|
||||
protected array $translatable = [
|
||||
'category_name',
|
||||
];
|
||||
|
||||
public function add(array $params)
|
||||
{
|
||||
$sourceLocale = locale();
|
||||
$sourceFields = $this->extractSourceFields($params);
|
||||
|
||||
if (empty($sourceFields)) {
|
||||
throw new \InvalidArgumentException("请传递至少一条 {$sourceLocale} 语言的翻译字段");
|
||||
};
|
||||
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
$info = $this->create($params);
|
||||
if (!$info) {
|
||||
throw new BusinessException('提交失败');
|
||||
}
|
||||
|
||||
// 异步翻译并写入 hs_vehicle_data_translation 表
|
||||
(new TranslationService())->queueTranslations(
|
||||
'vehicleNewAttributeCategories',
|
||||
$info->id,
|
||||
$sourceLocale,
|
||||
$sourceFields
|
||||
);
|
||||
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollBack();
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
|
||||
public function edit(array $params, int $id)
|
||||
{
|
||||
$sourceLocale = locale();
|
||||
var_dump($params);
|
||||
$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(
|
||||
'vehicleNewAttributeCategories',
|
||||
$id,
|
||||
$sourceLocale,
|
||||
$sourceFields
|
||||
);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollBack();
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\service;
|
||||
|
||||
use app\console\model\VehicleNewAttributeCategoriesTranslationModel;
|
||||
use app\mzl\common\services\BaseService;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class VehicleNewAttributeCategoriesTranslationService extends BaseService
|
||||
{
|
||||
/**
|
||||
* 定义模型
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getModel(): string
|
||||
{
|
||||
return VehicleNewAttributeCategoriesTranslationModel::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,76 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\service;
|
||||
|
||||
use app\console\model\VehicleNewAttributeValuesModel;
|
||||
use app\mzl\common\services\BaseService;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class VehicleNewAttributeValuesService extends BaseService
|
||||
{
|
||||
/**
|
||||
* 定义模型
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getModel(): string
|
||||
{
|
||||
return VehicleNewAttributeValuesModel::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* 多场景配置
|
||||
*/
|
||||
public function queryScenes(): array
|
||||
{
|
||||
return [
|
||||
'preset' => function ($params) {
|
||||
return [
|
||||
'filters' => $params['filters'],
|
||||
'fields' => ['id', 'color_code'],
|
||||
'relations' => [
|
||||
'translation' => ['id', 'locale', 'value_name'],
|
||||
],
|
||||
'sorts' => [
|
||||
['field' => 'created_at', 'direction' => 'desc']
|
||||
],
|
||||
];
|
||||
},
|
||||
// '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 = [
|
||||
'value_name',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\service;
|
||||
|
||||
use app\console\model\VehicleNewAttributeValuesTranslationModel;
|
||||
use app\mzl\common\services\BaseService;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class VehicleNewAttributeValuesTranslationService extends BaseService
|
||||
{
|
||||
/**
|
||||
* 定义模型
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getModel(): string
|
||||
{
|
||||
return VehicleNewAttributeValuesTranslationModel::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,207 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\service;
|
||||
|
||||
use app\console\model\VehicleNewAttributesModel;
|
||||
use app\console\model\VehicleNewAttributeValuesModel;
|
||||
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 VehicleNewAttributesService extends BaseService
|
||||
{
|
||||
/**
|
||||
* 定义模型
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getModel(): string
|
||||
{
|
||||
return VehicleNewAttributesModel::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* 多场景配置
|
||||
*/
|
||||
public function queryScenes(): array
|
||||
{
|
||||
return [
|
||||
'default' => function ($params) {
|
||||
return [
|
||||
'filters' => [
|
||||
],
|
||||
'fields' => ['id','status', 'input_type', 'category_id', 'is_img'],
|
||||
'relations' => [
|
||||
'translation' => ['attributes_id', 'locale', 'attribute_name'],
|
||||
'value' => ['id', 'attribute_id', 'color_code', 'sort_order'],
|
||||
'value.translation' => ['id', 'values_id', 'locale', 'value_name'],
|
||||
],
|
||||
'sorts' => [
|
||||
['field' => 'created_at', 'direction' => 'desc']
|
||||
],
|
||||
'pagination' => [
|
||||
'page' => $params['page'] ?? 1,
|
||||
'per_page' => $params['per_page'] ?? 10,
|
||||
]
|
||||
];
|
||||
},
|
||||
'preset' => function ($params) {
|
||||
return [
|
||||
'filters' => [
|
||||
],
|
||||
'fields' => ['id','is_img','status'],
|
||||
'relations' => [
|
||||
'translation' => ['attributes_id', 'locale', 'attribute_name'],
|
||||
'value' => ['id', 'attribute_id', 'color_code', 'sort_order'],
|
||||
'value.translation' => ['id', 'values_id', 'locale', 'value_name'],
|
||||
],
|
||||
'sorts' => [
|
||||
['field' => 'created_at', 'direction' => 'desc']
|
||||
],
|
||||
];
|
||||
},
|
||||
'show' => function ($params) {
|
||||
return [
|
||||
'filters' => [
|
||||
['field'=>'id', 'operator'=>'=', 'value'=> $params['id']],
|
||||
],
|
||||
'fields' => ['id', 'status', 'input_type', 'category_id', 'is_img'],
|
||||
'relations' => [
|
||||
'translation' => ['attributes_id', 'locale', 'attribute_name'],
|
||||
'value' => ['id', 'attribute_id', 'color_code', 'sort_order'],
|
||||
'value.translation' => ['id', 'values_id', 'locale', 'value_name'],
|
||||
],
|
||||
];
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
// 声明需要多语言翻译
|
||||
protected array $translatable = [
|
||||
'attribute_name',
|
||||
];
|
||||
|
||||
public function add(array $params)
|
||||
{
|
||||
$sourceLocale = locale();
|
||||
$sourceFields = $this->extractSourceFields($params);
|
||||
|
||||
if (empty($sourceFields)) {
|
||||
throw new \InvalidArgumentException("请传递至少一条 {$sourceLocale} 语言的翻译字段");
|
||||
};
|
||||
|
||||
$values = $params['value'];
|
||||
unset($params['value']);
|
||||
$VehicleNewAttributeValuesService = new VehicleNewAttributeValuesService(new VehicleNewAttributeValuesModel());
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
$info = $this->create($params);
|
||||
if (!$info) {
|
||||
throw new BusinessException('提交失败');
|
||||
}
|
||||
|
||||
// 异步翻译并写入 hs_vehicle_data_translation 表
|
||||
(new TranslationService())->queueTranslations(
|
||||
'vehicleNewAttributes',
|
||||
$info->id,
|
||||
$sourceLocale,
|
||||
$sourceFields
|
||||
);
|
||||
|
||||
$valuesId = [];
|
||||
foreach ($values as $value) {
|
||||
$askedsourceFields = $VehicleNewAttributeValuesService->extractSourceFields($value);
|
||||
$value['attribute_id'] = $info->id;
|
||||
$value_res = $VehicleNewAttributeValuesService->create($value);
|
||||
if (!$value_res) {
|
||||
throw new BusinessException('提交失败');
|
||||
}
|
||||
(new TranslationService())->queueTranslations(
|
||||
'vehicleNewAttributeValues',
|
||||
$value_res->id,
|
||||
$sourceLocale,
|
||||
$askedsourceFields
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
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} 语言的翻译字段");
|
||||
};
|
||||
|
||||
$values = $params['value'];
|
||||
unset($params['value']);
|
||||
$VehicleNewAttributeValuesService = new VehicleNewAttributeValuesService(new VehicleNewAttributeValuesModel());
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
$info = $this->update($id, $params);
|
||||
if (!$info) {
|
||||
throw new BusinessException('提交失败');
|
||||
}
|
||||
|
||||
// 异步翻译并写入 hs_vehicle_data_translation 表
|
||||
(new TranslationService())->queueTranslations(
|
||||
'vehicleNewAttributes',
|
||||
$id,
|
||||
$sourceLocale,
|
||||
$sourceFields
|
||||
);
|
||||
|
||||
|
||||
$valuesId = [];
|
||||
foreach ($values as $value) {
|
||||
$valuesourceFields = $VehicleNewAttributeValuesService->extractSourceFields($value);
|
||||
$value['attribute_id'] = $id;
|
||||
|
||||
if(!empty($value['id'])){
|
||||
$valueId = $value['id'];
|
||||
$valuesId[] = $valueId;
|
||||
$value_res = $VehicleNewAttributeValuesService->update($valueId, $value);
|
||||
if (!$value_res) {
|
||||
throw new BusinessException('提交失败:属性值');
|
||||
}
|
||||
} else {
|
||||
unset($value['id']);
|
||||
$value_res = $VehicleNewAttributeValuesService->create($value);
|
||||
if (!$value_res) {
|
||||
throw new BusinessException('提交失败:属性值');
|
||||
}
|
||||
$valueId = $value_res->id;
|
||||
$valuesId[] = $valueId;
|
||||
}
|
||||
|
||||
(new TranslationService())->queueTranslations(
|
||||
'vehicleNewAttributeValues',
|
||||
$valueId,
|
||||
$sourceLocale,
|
||||
$valuesourceFields
|
||||
);
|
||||
}
|
||||
VehicleNewAttributeValuesModel::whereNotIn('id', $valuesId)->where('attribute_id',$id)->delete();
|
||||
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollBack();
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\service;
|
||||
|
||||
use app\console\model\VehicleNewAttributesTranslationModel;
|
||||
use app\mzl\common\services\BaseService;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class VehicleNewAttributesTranslationService extends BaseService
|
||||
{
|
||||
/**
|
||||
* 定义模型
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getModel(): string
|
||||
{
|
||||
return VehicleNewAttributesTranslationModel::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,
|
||||
// ]
|
||||
// ];
|
||||
// }
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,8 @@ use app\console\model\VehicleNewAskedTranslationModel;
|
||||
use app\console\model\VehicleNewContentModel;
|
||||
use app\console\model\VehicleNewContentTranslationModel;
|
||||
use app\console\model\VehicleNewModel;
|
||||
use app\console\model\VehicleNewSkuAttributesModel;
|
||||
use app\console\model\VehicleNewSkusModel;
|
||||
use app\console\model\VehicleNewTraitModel;
|
||||
use app\console\model\VehicleNewTraitTranslationModel;
|
||||
use app\console\model\VehicleNewTranslationModel;
|
||||
@@ -125,11 +127,15 @@ class VehicleNewService extends BaseService
|
||||
unset($params['album']);
|
||||
$contents = $params['content'];
|
||||
unset($params['content']);
|
||||
$skus = $params['sku'];
|
||||
unset($params['sku']);
|
||||
|
||||
$VehicleNewAskedService = new VehicleNewAskedService(new VehicleNewAskedModel());
|
||||
$VehicleNewTraitService = new VehicleNewTraitService(new VehicleNewTraitModel());
|
||||
$VehicleNewAlbumService = new VehicleNewAlbumService(new VehicleNewAlbumModel());
|
||||
$VehicleNewContentService = new VehicleNewContentService(new VehicleNewContentModel());
|
||||
$VehicleNewSkusService = new VehicleNewSkusService(new VehicleNewSkusModel());
|
||||
$VehicleNewSkuAttributesService = new VehicleNewSkuAttributesService(new VehicleNewSkuAttributesModel());
|
||||
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
@@ -212,6 +218,26 @@ class VehicleNewService extends BaseService
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($skus as $sku) {
|
||||
$sku['vehicle_id'] = $info->id;
|
||||
$sku_code = sprintf("%05d", $info->id);
|
||||
$sku['sku_code'] = rand(100,999).$sku_code[0].' '.substr($sku_code,1).' '.sprintf("%04d", $sku['skuAttributes'][0]['attribute_id']).' '.sprintf("%04d", $sku['skuAttributes'][0]['value_id']);
|
||||
|
||||
$sku_res = $VehicleNewSkusService->create($sku);
|
||||
if (!$sku_res) {
|
||||
throw new BusinessException('提交失败');
|
||||
}
|
||||
|
||||
$skuAttributes = $sku['skuAttributes'];
|
||||
foreach ($skuAttributes as $skuAttribute) {
|
||||
$skuAttribute['sku_id'] = $sku_res->id;
|
||||
$skuAttribute_res = $VehicleNewSkuAttributesService->create($skuAttribute);
|
||||
if (!$skuAttribute_res) {
|
||||
throw new BusinessException('提交失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $th) {
|
||||
@@ -237,27 +263,15 @@ class VehicleNewService extends BaseService
|
||||
unset($params['album']);
|
||||
$contents = $params['content'];
|
||||
unset($params['content']);
|
||||
$skus = $params['sku']??[];
|
||||
unset($params['sku']);
|
||||
|
||||
$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 ?? '';
|
||||
// }
|
||||
// }
|
||||
$VehicleNewSkusService = new VehicleNewSkusService(new VehicleNewSkusModel());
|
||||
$VehicleNewSkuAttributesService = new VehicleNewSkuAttributesService(new VehicleNewSkuAttributesModel());
|
||||
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
@@ -441,30 +455,64 @@ class VehicleNewService extends BaseService
|
||||
);
|
||||
}
|
||||
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('提交失败');
|
||||
// }
|
||||
$skusId = [];
|
||||
foreach ($skus as $sku) {
|
||||
if(!empty($sku['id'])){
|
||||
$skuId =$sku['id'];
|
||||
$skusId[] =$skuId;
|
||||
$skuAttributes = $sku['skuAttributes'];
|
||||
unset($sku['skuAttributes']);
|
||||
$sku_res = $VehicleNewSkusService->update($skuId,$sku);
|
||||
if (!$sku_res) {
|
||||
throw new BusinessException('提交失败5');
|
||||
}
|
||||
$skuAttributeIds = [];
|
||||
foreach ($skuAttributes as $skuAttribute) {
|
||||
if(!empty($skuAttribute['id'])){
|
||||
$skuAttributeId = $skuAttribute['id'];
|
||||
$skuAttributeIds[] =$skuAttributeId;
|
||||
$skuAttribute['sku_id'] = $skuId;
|
||||
$skuAttribute_res = $VehicleNewSkuAttributesService->update($skuAttributeId, $skuAttribute);
|
||||
var_dump($skuAttribute_res);
|
||||
if (!$skuAttribute_res) {
|
||||
throw new BusinessException('提交失败4');
|
||||
}
|
||||
}else{
|
||||
$skuAttribute['sku_id'] = $sku_res->id;
|
||||
$skuAttribute_res = $VehicleNewSkuAttributesService->create($skuAttribute);
|
||||
$skuAttributeIds[] =$skuAttribute_res->id;
|
||||
if (!$skuAttribute_res) {
|
||||
throw new BusinessException('提交失败3');
|
||||
}
|
||||
}
|
||||
}
|
||||
VehicleNewSkuAttributesModel::whereNotIn('id', $skuAttributeIds)->where('sku_id',$skuId)->delete();
|
||||
}else{
|
||||
$sku['vehicle_id'] = $id;
|
||||
$sku_code = sprintf("%05d", $id);
|
||||
$sku['sku_code'] = rand(100,999).$sku_code[0].' '.substr($sku_code,1).' '.sprintf("%04d", $sku['skuAttributes'][0]['attribute_id']).' '.sprintf("%04d", $sku['skuAttributes'][0]['value_id']);
|
||||
|
||||
// if (isset($params['draft_id']) && $params['draft_id']) {
|
||||
// if (!DraftsModel::where('id', $params['draft_id'])->delete()) {
|
||||
// throw new BusinessException('草稿移除失败');
|
||||
// }
|
||||
// }
|
||||
$skuAttributes = $sku['skuAttributes'];
|
||||
unset($sku['skuAttributes']);
|
||||
|
||||
$sku_res = $VehicleNewSkusService->create($sku);
|
||||
$skusId[] =$sku_res->id;
|
||||
if (!$sku_res) {
|
||||
throw new BusinessException('提交失败2');
|
||||
}
|
||||
|
||||
// $skuAttributes = $sku['skuAttributes'];
|
||||
foreach ($skuAttributes as $skuAttribute) {
|
||||
$skuAttribute['sku_id'] = $sku_res->id;
|
||||
$skuAttribute_res = $VehicleNewSkuAttributesService->create($skuAttribute);
|
||||
if (!$skuAttribute_res) {
|
||||
throw new BusinessException('提交失败1');
|
||||
}
|
||||
}
|
||||
}
|
||||
VehicleNewSkusModel::whereNotIn('id', $skusId)->where('vehicle_id',$id)->delete();
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\service;
|
||||
|
||||
use app\console\model\VehicleNewSkuAttributesModel;
|
||||
use app\mzl\common\services\BaseService;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class VehicleNewSkuAttributesService extends BaseService
|
||||
{
|
||||
/**
|
||||
* 定义模型
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getModel(): string
|
||||
{
|
||||
return VehicleNewSkuAttributesModel::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* 多场景配置
|
||||
*/
|
||||
public function queryScenes(): array
|
||||
{
|
||||
return [
|
||||
'default' => function ($params) {
|
||||
return [
|
||||
'filters' => [
|
||||
['field' => 'id', 'operator' => '=', 'value' => '7']
|
||||
],
|
||||
'fields' => ['id','attribute_id','value_id','img'],
|
||||
'relations' => [
|
||||
'attribute' => ['id', 'input_type', 'is_img', 'status'],
|
||||
'attribute.translation' => ['attribute_name'],
|
||||
'value' => ['id','color_code'],
|
||||
'value.translation' => ['value_name'],
|
||||
],
|
||||
'sorts' => [
|
||||
['field' => 'created_at', 'direction' => 'desc']
|
||||
],
|
||||
'pagination' => [
|
||||
'page' => $params['page'] ?? 1,
|
||||
'per_page' => $params['per_page'] ?? 10,
|
||||
]
|
||||
];
|
||||
},
|
||||
// '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\console\service;
|
||||
|
||||
use app\console\model\VehicleNewSkusTranslationModel;
|
||||
use app\mzl\common\services\BaseService;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class VehicleNewSkusTranslationService extends BaseService
|
||||
{
|
||||
/**
|
||||
* 定义模型
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getModel(): string
|
||||
{
|
||||
return VehicleNewSkusTranslationModel::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\console\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class VehicleNewAttributeCategoriesTranslationValidator extends Validate
|
||||
{
|
||||
// 规则
|
||||
protected $rule = [
|
||||
|
||||
];
|
||||
|
||||
// 提示
|
||||
protected $message = [
|
||||
|
||||
];
|
||||
|
||||
// 场景
|
||||
protected $scene = [
|
||||
'store' => [
|
||||
|
||||
],
|
||||
|
||||
'update' => [
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class VehicleNewAttributeCategoriesValidator extends Validate
|
||||
{
|
||||
// 规则
|
||||
protected $rule = [
|
||||
|
||||
];
|
||||
|
||||
// 提示
|
||||
protected $message = [
|
||||
|
||||
];
|
||||
|
||||
// 场景
|
||||
protected $scene = [
|
||||
'store' => [
|
||||
|
||||
],
|
||||
|
||||
'update' => [
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class VehicleNewAttributeValuesTranslationValidator extends Validate
|
||||
{
|
||||
// 规则
|
||||
protected $rule = [
|
||||
|
||||
];
|
||||
|
||||
// 提示
|
||||
protected $message = [
|
||||
|
||||
];
|
||||
|
||||
// 场景
|
||||
protected $scene = [
|
||||
'store' => [
|
||||
|
||||
],
|
||||
|
||||
'update' => [
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class VehicleNewAttributeValuesValidator extends Validate
|
||||
{
|
||||
// 规则
|
||||
protected $rule = [
|
||||
|
||||
];
|
||||
|
||||
// 提示
|
||||
protected $message = [
|
||||
|
||||
];
|
||||
|
||||
// 场景
|
||||
protected $scene = [
|
||||
'store' => [
|
||||
|
||||
],
|
||||
|
||||
'update' => [
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class VehicleNewAttributesTranslationValidator extends Validate
|
||||
{
|
||||
// 规则
|
||||
protected $rule = [
|
||||
|
||||
];
|
||||
|
||||
// 提示
|
||||
protected $message = [
|
||||
|
||||
];
|
||||
|
||||
// 场景
|
||||
protected $scene = [
|
||||
'store' => [
|
||||
|
||||
],
|
||||
|
||||
'update' => [
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class VehicleNewAttributesValidator extends Validate
|
||||
{
|
||||
// 规则
|
||||
protected $rule = [
|
||||
|
||||
];
|
||||
|
||||
// 提示
|
||||
protected $message = [
|
||||
|
||||
];
|
||||
|
||||
// 场景
|
||||
protected $scene = [
|
||||
'store' => [
|
||||
|
||||
],
|
||||
|
||||
'update' => [
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class VehicleNewSkuAttributesValidator extends Validate
|
||||
{
|
||||
// 规则
|
||||
protected $rule = [
|
||||
|
||||
];
|
||||
|
||||
// 提示
|
||||
protected $message = [
|
||||
|
||||
];
|
||||
|
||||
// 场景
|
||||
protected $scene = [
|
||||
'store' => [
|
||||
|
||||
],
|
||||
|
||||
'update' => [
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class VehicleNewSkusTranslationValidator extends Validate
|
||||
{
|
||||
// 规则
|
||||
protected $rule = [
|
||||
|
||||
];
|
||||
|
||||
// 提示
|
||||
protected $message = [
|
||||
|
||||
];
|
||||
|
||||
// 场景
|
||||
protected $scene = [
|
||||
'store' => [
|
||||
|
||||
],
|
||||
|
||||
'update' => [
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class VehicleNewSkusValidator extends Validate
|
||||
{
|
||||
// 规则
|
||||
protected $rule = [
|
||||
|
||||
];
|
||||
|
||||
// 提示
|
||||
protected $message = [
|
||||
|
||||
];
|
||||
|
||||
// 场景
|
||||
protected $scene = [
|
||||
'store' => [
|
||||
|
||||
],
|
||||
|
||||
'update' => [
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -71,6 +71,22 @@ return [
|
||||
'translation_model' => \app\console\model\AdTranslationModel::class,
|
||||
'foreign_key' => 'ad_id',
|
||||
],
|
||||
'vehicleNewAttributes' => [
|
||||
'translation_model' => \app\console\model\VehicleNewAttributesTranslationModel::class,
|
||||
'foreign_key' => 'attributes_id',
|
||||
],
|
||||
'vehicleNewAttributeValues' => [
|
||||
'translation_model' => \app\console\model\VehicleNewAttributeValuesTranslationModel::class,
|
||||
'foreign_key' => 'values_id',
|
||||
],
|
||||
'vehicleNewAttributeCategories' => [
|
||||
'translation_model' => \app\console\model\VehicleNewAttributeCategoriesTranslationModel::class,
|
||||
'foreign_key' => 'categories_id',
|
||||
],
|
||||
'vehicleNewSku' => [
|
||||
'translation_model' => \app\console\model\VehicleNewSkusTranslationModel::class,
|
||||
'foreign_key' => 'sku_id',
|
||||
],
|
||||
],
|
||||
|
||||
// 默认支持的目标语种列表
|
||||
|
||||
@@ -44,11 +44,16 @@ Route::group('/apis', function() {
|
||||
Route::any('/agt/privacy', [\app\apis\controller\AgreementController::class, 'one']);
|
||||
// 品牌按字母查询
|
||||
Route::any('/brand/letterAll', [\app\apis\controller\BrandController::class, 'letterAll']);
|
||||
//查询热门品牌
|
||||
Route::any('/brand/hot', [\app\apis\controller\BrandController::class, 'hot']);
|
||||
// 品牌详情
|
||||
Route::any('/brand/detail/{id}', [\app\apis\controller\BrandController::class, 'detail']);
|
||||
// 新车管理
|
||||
Route::any('/vehicle/new/list', [\app\apis\controller\VehicleNewController::class, 'index']);
|
||||
Route::any('/vehicle/new/{id}/detail', [\app\apis\controller\VehicleNewController::class, 'detail']);
|
||||
//新车属性
|
||||
Route::any('/vehicle/new/sku/{id}/detail', [\app\apis\controller\VehicleNewSkusController::class, 'detail']);
|
||||
Route::any('/vehicle/new/sku/list', [\app\apis\controller\VehicleNewSkusController::class, 'index']);
|
||||
// 能源列表
|
||||
Route::any('/energy/preset', [\app\console\controller\EnergyController::class, 'presets']);
|
||||
|
||||
@@ -197,6 +202,31 @@ Route::group('/console', function() {
|
||||
Route::any('/vehicle/new/{id}/delete', [\app\console\controller\VehicleNewController::class, 'destroy']);
|
||||
Route::any('/vehicle/new/{id}/detail', [\app\console\controller\VehicleNewController::class, 'detail']);
|
||||
|
||||
//新车sku
|
||||
Route::any('/vehicle/new/sku/list', [\app\console\controller\VehicleNewSkusController::class, 'index']);
|
||||
Route::any('/vehicle/new/sku/attributes/list', [\app\console\controller\VehicleNewSkuAttributesController::class, 'index']);
|
||||
Route::any('/vehicle/new/sku/add', [\app\console\controller\VehicleNewSkusController::class, 'add']);
|
||||
Route::any('/vehicle/new/sku/{id}/update', [\app\console\controller\VehicleNewSkusController::class, 'edit']);
|
||||
Route::any('/vehicle/new/sku/{id}/delete', [\app\console\controller\VehicleNewSkusController::class, 'destroy']);
|
||||
Route::any('/vehicle/new/sku/{id}/detail', [\app\console\controller\VehicleNewSkusController::class, 'detail']);
|
||||
|
||||
//新车属性
|
||||
Route::any('/vehicle/new/attributes/list', [\app\console\controller\VehicleNewAttributesController::class, 'index']);
|
||||
Route::any('/vehicle/new/attributes/preset', [\app\console\controller\VehicleNewAttributesController::class, 'presets']);
|
||||
Route::any('/vehicle/new/attributes/add', [\app\console\controller\VehicleNewAttributesController::class, 'add']);
|
||||
Route::any('/vehicle/new/attributes/{id}/update', [\app\console\controller\VehicleNewAttributesController::class, 'edit']);
|
||||
Route::any('/vehicle/new/attributes/{id}/delete', [\app\console\controller\VehicleNewAttributesController::class, 'destroy']);
|
||||
Route::any('/vehicle/new/attributes/{id}/detail', [\app\console\controller\VehicleNewAttributesController::class, 'detail']);
|
||||
Route::any('/vehicle/new/values/preset', [\app\console\controller\VehicleNewAttributeValuesController::class, 'presets']);
|
||||
|
||||
//新车属性分类
|
||||
Route::any('/vehicle/new/categories/list', [\app\console\controller\VehicleNewAttributeCategoriesController::class, 'index']);
|
||||
Route::any('/vehicle/new/categories/preset', [\app\console\controller\VehicleNewAttributeCategoriesController::class, 'presets']);
|
||||
Route::any('/vehicle/new/categories/add', [\app\console\controller\VehicleNewAttributeCategoriesController::class, 'add']);
|
||||
Route::any('/vehicle/new/categories/{id}/update', [\app\console\controller\VehicleNewAttributeCategoriesController::class, 'edit']);
|
||||
Route::any('/vehicle/new/categories/{id}/delete', [\app\console\controller\VehicleNewAttributeCategoriesController::class, 'destroy']);
|
||||
Route::any('/vehicle/new/categories/{id}/detail', [\app\console\controller\VehicleNewAttributeCategoriesController::class, 'detail']);
|
||||
|
||||
// 上传
|
||||
Route::any('/upload/image', [\app\mzl\modules\upload\controller\UploadController::class, 'uploadImage']);
|
||||
Route::any('/upload/image/proxy', [\app\mzl\modules\upload\controller\UploadController::class, 'proxy']);
|
||||
|
||||
Reference in New Issue
Block a user