作者 赵彬吉

update

@@ -43,7 +43,7 @@ class ProductController extends BaseController @@ -43,7 +43,7 @@ class ProductController extends BaseController
43 $map[] = ['status', $this->param['status']]; 43 $map[] = ['status', $this->param['status']];
44 } 44 }
45 $sort = ['id' => 'desc']; 45 $sort = ['id' => 'desc'];
46 - $data = $logic->getList($map, $sort, ['id', 'title', 'thumb', 'category_id', 'keywords', 'status', 'created_uid', 'created_at', 'updated_at']); 46 + $data = $logic->getList($map, $sort, ['id', 'title', 'thumb', 'category_id', 'keyword_id', 'status', 'created_uid', 'created_at', 'updated_at']);
47 return $this->success($data); 47 return $this->success($data);
48 } 48 }
49 49
@@ -54,8 +54,8 @@ class ProductController extends BaseController @@ -54,8 +54,8 @@ class ProductController extends BaseController
54 'id.required' => 'ID不能为空' 54 'id.required' => 'ID不能为空'
55 ]); 55 ]);
56 $data = $logic->getInfo($this->param['id']); 56 $data = $logic->getInfo($this->param['id']);
57 - return $this->success(Arr::twoKeepKeys($data, ['id', 'title', 'gallery', 'attrs', 'category_id', 'keywords', 'intro', 'content',  
58 - 'describe', 'seo_mate', 'related_product_id', 'status', 'category_id_text', 'status_text', 'created_uid', 'created_uid_text'])); 57 + return $this->success(Arr::twoKeepKeys($data, ['id', 'title', 'gallery', 'attrs', 'category_id', 'keyword_id', 'attr_id', 'describe_id', 'intro', 'content',
  58 + 'describe', 'seo_mate', 'related_product_id', 'status', 'category_id_text', 'keyword_id_text', 'status_text', 'created_uid', 'created_uid_text']));
59 } 59 }
60 60
61 public function save(ProductRequest $request, ProductLogic $logic) 61 public function save(ProductRequest $request, ProductLogic $logic)
@@ -30,12 +30,7 @@ class ProductLogic extends BaseLogic @@ -30,12 +30,7 @@ class ProductLogic extends BaseLogic
30 { 30 {
31 $data = parent::getList($map, $sort, $columns, $limit); 31 $data = parent::getList($map, $sort, $columns, $limit);
32 foreach ($data['list'] as &$v){ 32 foreach ($data['list'] as &$v){
33 - foreach ($v['category_id'] as $category_id){  
34 - $v['category_id_text'][] =(new CategoryLogic())->getCacheInfo($category_id)['title']??'';  
35 - }  
36 - $v['category_id_text'] = Arr::arrToSet($v['category_id_text'], 'trim');  
37 - $v['status_text'] = Product::statusMap()[$v['status']] ?? '';  
38 - $v['created_uid_text'] = (new UserLogic())->getCacheInfo($v['created_uid'])['name'] ?? ''; 33 + $v = $this->formatData($v);
39 } 34 }
40 return $this->success($data); 35 return $this->success($data);
41 } 36 }
@@ -43,13 +38,22 @@ class ProductLogic extends BaseLogic @@ -43,13 +38,22 @@ class ProductLogic extends BaseLogic
43 public function getInfo($id) 38 public function getInfo($id)
44 { 39 {
45 $info = parent::getInfo($id); 40 $info = parent::getInfo($id);
  41 + $info = $this->formatData($info);
  42 + return $this->success($info);
  43 + }
  44 +
  45 + public function formatData($info){
46 foreach ($info['category_id'] as $category_id) { 46 foreach ($info['category_id'] as $category_id) {
47 $info['category_id_text'][] = (new CategoryLogic())->getCacheInfo($category_id)['title'] ?? ''; 47 $info['category_id_text'][] = (new CategoryLogic())->getCacheInfo($category_id)['title'] ?? '';
48 } 48 }
  49 + foreach ($info['keyword_id'] as $keyword_id){
  50 + $info['keyword_id_text'][] =(new KeywordLogic())->getCacheInfo($keyword_id)['title']??'';
  51 + }
49 $info['category_id_text'] = Arr::arrToSet($info['category_id_text'], 'trim'); 52 $info['category_id_text'] = Arr::arrToSet($info['category_id_text'], 'trim');
  53 + $info['keyword_id_text'] = Arr::arrToSet($info['keyword_id_text'], 'trim');
50 $info['status_text'] = Product::statusMap()[$info['status']] ?? ''; 54 $info['status_text'] = Product::statusMap()[$info['status']] ?? '';
51 $info['created_uid_text'] = (new UserLogic())->getCacheInfo($info['created_uid'])['name'] ?? ''; 55 $info['created_uid_text'] = (new UserLogic())->getCacheInfo($info['created_uid'])['name'] ?? '';
52 - return $this->success($info); 56 + return $info;
53 } 57 }
54 58
55 public function save($param){ 59 public function save($param){
@@ -48,7 +48,7 @@ class ProductRequest extends FormRequest @@ -48,7 +48,7 @@ class ProductRequest extends FormRequest
48 } 48 }
49 } 49 }
50 }], 50 }],
51 - 'attrs' => ['required', 'array', function ($attribute, $value, $fail) { 51 + 'attrs' => ['array', function ($attribute, $value, $fail) {
52 foreach ($value as $v) { 52 foreach ($value as $v) {
53 if (empty($v['key'])) { 53 if (empty($v['key'])) {
54 $fail('产品属性名不能为空'); 54 $fail('产品属性名不能为空');
@@ -59,11 +59,9 @@ class ProductRequest extends FormRequest @@ -59,11 +59,9 @@ class ProductRequest extends FormRequest
59 } 59 }
60 }], 60 }],
61 'category_id' => 'required', 61 'category_id' => 'required',
62 - 'keywords' => 'required',  
63 'intro' => 'required|max:500', 62 'intro' => 'required|max:500',
64 'content' => 'required', 63 'content' => 'required',
65 - 'describe' => 'required|array',  
66 - 'seo_mate' => ['required', 'array', function ($attribute, $value, $fail) { 64 + 'seo_mate' => ['array', function ($attribute, $value, $fail) {
67 if(empty($value['title'])){ 65 if(empty($value['title'])){
68 $fail('SEO标题不能为空'); 66 $fail('SEO标题不能为空');
69 } 67 }
@@ -74,7 +72,7 @@ class ProductRequest extends FormRequest @@ -74,7 +72,7 @@ class ProductRequest extends FormRequest
74 $fail('SEO关键词不能为空'); 72 $fail('SEO关键词不能为空');
75 } 73 }
76 }], 74 }],
77 - 'related_product_id' => ['required', function ($attribute, $value, $fail) { 75 + 'related_product_id' => [function ($attribute, $value, $fail) {
78 $value = array_filter(Arr::splitFilterToArray($value), 'intval'); 76 $value = array_filter(Arr::splitFilterToArray($value), 'intval');
79 if(count($value) > 16){ 77 if(count($value) > 16){
80 $fail('关联产品不能超过16个'); 78 $fail('关联产品不能超过16个');
@@ -85,12 +85,28 @@ class Product extends Base @@ -85,12 +85,28 @@ class Product extends Base
85 return Arr::setToArr($value); 85 return Arr::setToArr($value);
86 } 86 }
87 87
88 - public function setKeywordsAttribute($value){  
89 - $this->attributes['keywords'] = Arr::arrToSet($value, 'trim'); 88 + public function setAttrIdAttribute($value){
  89 + $this->attributes['attr_id'] = Arr::arrToSet($value);
90 } 90 }
91 91
92 - public function getKeywordsAttribute($value){  
93 - return Arr::setToArr($value, 'trim'); 92 + public function getAttrIdAttribute($value){
  93 + return Arr::setToArr($value);
  94 + }
  95 +
  96 + public function setDescribeIdAttribute($value){
  97 + $this->attributes['describe_id'] = Arr::arrToSet($value);
  98 + }
  99 +
  100 + public function getDescribeIdAttribute($value){
  101 + return Arr::setToArr($value);
  102 + }
  103 +
  104 + public function setKeywordIdAttribute($value){
  105 + $this->attributes['keyword_id'] = Arr::arrToSet($value);
  106 + }
  107 +
  108 + public function getKeywordIdAttribute($value){
  109 + return Arr::setToArr($value);
94 } 110 }
95 111
96 public function setRelatedProductIdAttribute($value){ 112 public function setRelatedProductIdAttribute($value){