2025-12-08 17:37:34 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\common\service;
|
|
|
|
|
|
2025-12-11 16:11:38 +08:00
|
|
|
use app\common\logic\PostCategoryLogic;
|
|
|
|
|
use app\common\logic\SkuAttributeLogic;
|
2025-12-08 17:37:34 +08:00
|
|
|
use app\common\validate\SkuAttributeValidate;
|
|
|
|
|
use app\common\traits\crud\CrudServiceTrait;
|
|
|
|
|
use app\common\model\SkuAttribute;
|
2025-12-09 15:33:21 +08:00
|
|
|
use support\Request;
|
2025-12-08 17:37:34 +08:00
|
|
|
|
|
|
|
|
class SkuAttributeService
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
use CrudServiceTrait;
|
|
|
|
|
|
2025-12-11 16:11:38 +08:00
|
|
|
protected $logic;
|
2025-12-08 17:37:34 +08:00
|
|
|
/**
|
|
|
|
|
* 指定当前要操作的模型
|
|
|
|
|
*/
|
|
|
|
|
protected string $modelClass = SkuAttribute::class;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 验证器
|
|
|
|
|
*/
|
|
|
|
|
protected $validator = SkuAttributeValidate::class;
|
|
|
|
|
|
2025-12-11 16:11:38 +08:00
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->logic = (new SkuAttributeLogic());
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-08 17:37:34 +08:00
|
|
|
/**
|
|
|
|
|
* 获取验证器
|
|
|
|
|
*/
|
|
|
|
|
public function getValidator()
|
|
|
|
|
{
|
|
|
|
|
return new $this->validator;
|
|
|
|
|
}
|
2025-12-09 15:33:21 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 构造 CrudUtil 查询配置
|
|
|
|
|
*/
|
|
|
|
|
protected function buildQueryConfig(Request $request, string $scene = 'default'): array
|
|
|
|
|
{
|
|
|
|
|
$p = $request->all();
|
|
|
|
|
|
|
|
|
|
$config = [];
|
|
|
|
|
$config['model'] = $this->modelClass;
|
|
|
|
|
switch ($scene) {
|
|
|
|
|
case 'default':
|
|
|
|
|
case 'index':
|
|
|
|
|
$config['order']['sort'] = 'desc';
|
|
|
|
|
$config['order']['id'] = 'desc';
|
|
|
|
|
break;
|
|
|
|
|
case 'show':
|
|
|
|
|
$config['where']['id'] = $p['id'];
|
|
|
|
|
break;
|
|
|
|
|
case 'store':
|
|
|
|
|
break;
|
|
|
|
|
case 'update':
|
|
|
|
|
case 'destroy':
|
|
|
|
|
$config['where']['id'] = $p['id'];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $config;
|
|
|
|
|
}
|
2025-12-11 16:11:38 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 添加前置处理
|
|
|
|
|
*/
|
|
|
|
|
public function beforeServiceStore($data, Request $request)
|
|
|
|
|
{
|
2025-12-11 16:26:00 +08:00
|
|
|
$options = [];
|
|
|
|
|
foreach ($data['options_json'] as $v){
|
|
|
|
|
$options[] = $v['value'];
|
|
|
|
|
}
|
|
|
|
|
$data['options_json'] = json_encode($options, JSON_UNESCAPED_UNICODE);
|
2025-12-11 16:11:38 +08:00
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 添加前置处理
|
|
|
|
|
*/
|
|
|
|
|
public function beforeServiceUpdate($data, Request $request)
|
|
|
|
|
{
|
2025-12-11 16:27:18 +08:00
|
|
|
$options = [];
|
2025-12-17 14:30:10 +08:00
|
|
|
if (!empty($data['options_json'])) {
|
|
|
|
|
foreach ($data['options_json'] as $v){
|
|
|
|
|
$options[] = $v['value'];
|
|
|
|
|
}
|
2025-12-11 16:27:18 +08:00
|
|
|
}
|
|
|
|
|
$data['options_json'] = json_encode($options, JSON_UNESCAPED_UNICODE);
|
2025-12-11 16:11:38 +08:00
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取系统list
|
|
|
|
|
*/
|
|
|
|
|
public function preset($params)
|
|
|
|
|
{
|
|
|
|
|
$where = [];
|
|
|
|
|
if(isset($params['category_id']) && $params['category_id']) {
|
|
|
|
|
$where['category_id'] = $params['category_id'];
|
|
|
|
|
}
|
|
|
|
|
$result = $this->logic->getList($where)->toArray();
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
2025-12-08 17:37:34 +08:00
|
|
|
}
|