作者 liyuhang

Merge branch 'dev' of http://47.244.231.31:8099/zhl/globalso-v6 into dev

... ... @@ -47,38 +47,6 @@ class ProductController extends BaseController
public function save(ProductRequest $request, ProductLogic $logic)
{
//验证图片集格式
foreach ($this->param['gallery'] as $v){
if(empty($v['url'])){
throw new BsideGlobalException(Code::SYSTEM_ERROR, '图片链接不能为空');
}
}
//验证产品参数
foreach ($this->param['attrs'] as $v){
if(empty($v['key'])){
throw new BsideGlobalException(Code::SYSTEM_ERROR, '产品属性名不能为空');
}
if(empty($v['value'])){
throw new BsideGlobalException(Code::SYSTEM_ERROR, '产品属性值不能为空');
}
}
//验证seo_mate参数
if(empty($this->param['seo_mate']['title'])){
throw new BsideGlobalException(Code::SYSTEM_ERROR, 'SEO标题不能为空');
}
if(empty($this->param['seo_mate']['description'])){
throw new BsideGlobalException(Code::SYSTEM_ERROR, 'SEO描述不能为空');
}
if(empty($this->param['seo_mate']['keyword'])){
throw new BsideGlobalException(Code::SYSTEM_ERROR, 'SEO关键词不能为空');
}
//关联产品 最多16个
$this->param['related_product_id'] = array_filter(Arr::splitFilterToArray($this->param['related_product_id']), 'intval');
if(count($this->param['related_product_id']) > 16){
throw new BsideGlobalException(Code::SYSTEM_ERROR, '关联产品不能超过16个');
}
//封面取第一个图片
$this->param['thumb'] = $this->param['gallery'][0] ?? '';
... ...
... ... @@ -2,6 +2,9 @@
namespace App\Http\Requests\Bside\product;
use App\Enums\Common\Code;
use App\Exceptions\BsideGlobalException;
use App\Helper\Arr;
use App\Models\Product\Product;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
... ... @@ -32,18 +35,48 @@ class ProductRequest extends FormRequest
public function rules()
{
return [
'title'=>'required|max:200',
'route'=>'required|max:100',
'gallery'=>'required|array',
'attrs'=>'required|array',
'category_id'=>'required',
'keywords'=>'required',
'intro'=>'required|max:500',
'content'=>'required',
'describe'=>'required|array',
'seo_mate'=>'required|array',
'related_product_id'=>'required',
'status'=>['required', Rule::in(array_keys(Product::statusMap()))],
'title' => 'required|max:200',
'route' => 'required|max:100',
'gallery' => ['required', 'array', function ($attribute, $value, $fail) {
foreach ($value as $v) {
if (empty($v['url'])) {
$fail('图片链接不能为空');
}
}
}],
'attrs' => ['required', 'array', function ($attribute, $value, $fail) {
foreach ($value as $v) {
if (empty($v['key'])) {
$fail('产品属性名不能为空');
}
if (empty($v['value'])) {
$fail('产品属性值不能为空');
}
}
}],
'category_id' => 'required',
'keywords' => 'required',
'intro' => 'required|max:500',
'content' => 'required',
'describe' => 'required|array',
'seo_mate' => ['required', 'array', function ($attribute, $value, $fail) {
if(empty($value['title'])){
$fail('SEO标题不能为空');
}
if(empty($value['description'])){
$fail('SEO描述不能为空');
}
if(empty($value['keyword'])){
$fail('SEO关键词不能为空');
}
}],
'related_product_id' => ['required', function ($attribute, $value, $fail) {
$value = array_filter(Arr::splitFilterToArray($value), 'intval');
if(count($value) > 16){
$fail('关联产品不能超过16个');
}
}],
'status' => ['required', Rule::in(array_keys(Product::statusMap()))],
];
}
... ...