Merge branch 'feature/vehicle_new_sku' into develop
This commit is contained in:
@@ -126,6 +126,8 @@ class VehicleNewController extends BaseController
|
||||
$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\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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,4 +59,20 @@ class VehicleNewSkusModel extends Model
|
||||
{
|
||||
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 = [];
|
||||
}
|
||||
@@ -82,6 +82,7 @@ class VehicleNewService extends BaseService
|
||||
'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\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 VehicleNewSkusTranslationValidator extends Validate
|
||||
{
|
||||
// 规则
|
||||
protected $rule = [
|
||||
|
||||
];
|
||||
|
||||
// 提示
|
||||
protected $message = [
|
||||
|
||||
];
|
||||
|
||||
// 场景
|
||||
protected $scene = [
|
||||
'store' => [
|
||||
|
||||
],
|
||||
|
||||
'update' => [
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -166,7 +166,7 @@ class VehicleNewSkusService extends BaseService
|
||||
$skuAttributesId[] = $skuAttributeId;
|
||||
}
|
||||
}
|
||||
VehicleNewSkuAttributesModel::whereNotIn('id', $skuAttributesId)->where('attribute_id',$id)->delete();
|
||||
VehicleNewSkuAttributesModel::whereNotIn('id', $skuAttributesId)->where('sku_id',$id)->delete();
|
||||
|
||||
|
||||
Db::commit();
|
||||
|
||||
Reference in New Issue
Block a user