作者 liyuhang

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

@@ -47,38 +47,6 @@ class ProductController extends BaseController @@ -47,38 +47,6 @@ class ProductController extends BaseController
47 47
48 public function save(ProductRequest $request, ProductLogic $logic) 48 public function save(ProductRequest $request, ProductLogic $logic)
49 { 49 {
50 - //验证图片集格式  
51 - foreach ($this->param['gallery'] as $v){  
52 - if(empty($v['url'])){  
53 - throw new BsideGlobalException(Code::SYSTEM_ERROR, '图片链接不能为空');  
54 - }  
55 - }  
56 - //验证产品参数  
57 - foreach ($this->param['attrs'] as $v){  
58 - if(empty($v['key'])){  
59 - throw new BsideGlobalException(Code::SYSTEM_ERROR, '产品属性名不能为空');  
60 - }  
61 - if(empty($v['value'])){  
62 - throw new BsideGlobalException(Code::SYSTEM_ERROR, '产品属性值不能为空');  
63 - }  
64 - }  
65 - //验证seo_mate参数  
66 - if(empty($this->param['seo_mate']['title'])){  
67 - throw new BsideGlobalException(Code::SYSTEM_ERROR, 'SEO标题不能为空');  
68 - }  
69 - if(empty($this->param['seo_mate']['description'])){  
70 - throw new BsideGlobalException(Code::SYSTEM_ERROR, 'SEO描述不能为空');  
71 - }  
72 - if(empty($this->param['seo_mate']['keyword'])){  
73 - throw new BsideGlobalException(Code::SYSTEM_ERROR, 'SEO关键词不能为空');  
74 - }  
75 -  
76 - //关联产品 最多16个  
77 - $this->param['related_product_id'] = array_filter(Arr::splitFilterToArray($this->param['related_product_id']), 'intval');  
78 - if(count($this->param['related_product_id']) > 16){  
79 - throw new BsideGlobalException(Code::SYSTEM_ERROR, '关联产品不能超过16个');  
80 - }  
81 -  
82 //封面取第一个图片 50 //封面取第一个图片
83 $this->param['thumb'] = $this->param['gallery'][0] ?? ''; 51 $this->param['thumb'] = $this->param['gallery'][0] ?? '';
84 52
@@ -2,6 +2,9 @@ @@ -2,6 +2,9 @@
2 2
3 namespace App\Http\Requests\Bside\product; 3 namespace App\Http\Requests\Bside\product;
4 4
  5 +use App\Enums\Common\Code;
  6 +use App\Exceptions\BsideGlobalException;
  7 +use App\Helper\Arr;
5 use App\Models\Product\Product; 8 use App\Models\Product\Product;
6 use Illuminate\Foundation\Http\FormRequest; 9 use Illuminate\Foundation\Http\FormRequest;
7 use Illuminate\Validation\Rule; 10 use Illuminate\Validation\Rule;
@@ -32,18 +35,48 @@ class ProductRequest extends FormRequest @@ -32,18 +35,48 @@ class ProductRequest extends FormRequest
32 public function rules() 35 public function rules()
33 { 36 {
34 return [ 37 return [
35 - 'title'=>'required|max:200',  
36 - 'route'=>'required|max:100',  
37 - 'gallery'=>'required|array',  
38 - 'attrs'=>'required|array',  
39 - 'category_id'=>'required',  
40 - 'keywords'=>'required',  
41 - 'intro'=>'required|max:500',  
42 - 'content'=>'required',  
43 - 'describe'=>'required|array',  
44 - 'seo_mate'=>'required|array',  
45 - 'related_product_id'=>'required',  
46 - 'status'=>['required', Rule::in(array_keys(Product::statusMap()))], 38 + 'title' => 'required|max:200',
  39 + 'route' => 'required|max:100',
  40 + 'gallery' => ['required', 'array', function ($attribute, $value, $fail) {
  41 + foreach ($value as $v) {
  42 + if (empty($v['url'])) {
  43 + $fail('图片链接不能为空');
  44 + }
  45 + }
  46 + }],
  47 + 'attrs' => ['required', 'array', function ($attribute, $value, $fail) {
  48 + foreach ($value as $v) {
  49 + if (empty($v['key'])) {
  50 + $fail('产品属性名不能为空');
  51 + }
  52 + if (empty($v['value'])) {
  53 + $fail('产品属性值不能为空');
  54 + }
  55 + }
  56 + }],
  57 + 'category_id' => 'required',
  58 + 'keywords' => 'required',
  59 + 'intro' => 'required|max:500',
  60 + 'content' => 'required',
  61 + 'describe' => 'required|array',
  62 + 'seo_mate' => ['required', 'array', function ($attribute, $value, $fail) {
  63 + if(empty($value['title'])){
  64 + $fail('SEO标题不能为空');
  65 + }
  66 + if(empty($value['description'])){
  67 + $fail('SEO描述不能为空');
  68 + }
  69 + if(empty($value['keyword'])){
  70 + $fail('SEO关键词不能为空');
  71 + }
  72 + }],
  73 + 'related_product_id' => ['required', function ($attribute, $value, $fail) {
  74 + $value = array_filter(Arr::splitFilterToArray($value), 'intval');
  75 + if(count($value) > 16){
  76 + $fail('关联产品不能超过16个');
  77 + }
  78 + }],
  79 + 'status' => ['required', Rule::in(array_keys(Product::statusMap()))],
47 ]; 80 ];
48 } 81 }
49 82