WIN-2308041133\Administrator há 1 mês atrás
pai
commit
b5892adc57

+ 34 - 9
app/admin/view/store/store_product/create.php

@@ -428,13 +428,16 @@
                                                 </div>
                                                 <div class="layui-form-item rules">
                                                     <label class="layui-form-label"></label>
-                                                    <button type="button"
-                                                            class="layui-btn layui-btn-primary layui-btn-sm"
-                                                            v-for="(val,inx) in item.detail">
-                                                        {{val}}
-                                                        <i class="layui-icon layui-icon-close"
-                                                           @click="deleteValue(item,inx)"></i>
-                                                    </button>
+                                                        <button type="button"
+                                                                :class="{'layui-btn-primary': !(item.specialDetail && item.specialDetail[val]), 'layui-btn-danger': (item.specialDetail && item.specialDetail[val])}"
+                                                                class="layui-btn layui-btn-sm"
+                                                                v-for="(val,inx) in item.detail"
+                                                                @click="toggleSpecial(item, val)">
+                                                            {{val}}
+                                                            <span v-if="item.specialDetail && item.specialDetail[val]" style="margin-left:2px;font-size:10px">特供</span>
+                                                            <i class="layui-icon layui-icon-close"
+                                                               @click.stop="deleteValue(item,inx)"></i>
+                                                        </button>
                                                     <div class="rules rulesBox">
                                                         <div class="rules-btn-sm">
                                                             <input type="text" v-model="item.detailValue" name="title"
@@ -1166,7 +1169,8 @@
                     //     value: '',
                     //     detailValue:'',
                     //     attrHidden:false,
-                    //     detail:[]
+                    //     detail:[],
+                    //     specialDetail:{} //{value: true} 标记特供规格值
                     // }
                 ],
                 activity: ['秒杀', '砍价', '拼团'],
@@ -1484,6 +1488,20 @@
                 }
                 item.detail.push(item.detailValue);
                 item.detailValue = '';
+                if (!item.specialDetail) this.$set(item, 'specialDetail', {});
+            },
+            /**
+             * 切换规格值特供状态
+             * @param item 规格对象
+             * @param val 规格值
+             */
+            toggleSpecial: function (item, val) {
+                if (!item.specialDetail) this.$set(item, 'specialDetail', {});
+                if (item.specialDetail[val]) {
+                    this.$set(item.specialDetail, val, false);
+                } else {
+                    this.$set(item.specialDetail, val, true);
+                }
             },
             /**
              * 删除某个属性值
@@ -1492,7 +1510,12 @@
              * */
             deleteValue: function (item, inx) {
                 if (item.detail.length > 1) {
+                    var oldVal = item.detail[inx];
                     item.detail.splice(inx, 1);
+                    // 清理该值的特供标记
+                    if (item.specialDetail && item.specialDetail[oldVal]) {
+                        this.$delete(item.specialDetail, oldVal);
+                    }
                 } else {
                     return this.showMsg('请设置至少一个属性');
                 }
@@ -1548,7 +1571,8 @@
                         value: this.formDynamic.attrsName,
                         detailValue: '',
                         attrHidden: false,
-                        detail: [this.formDynamic.attrsVal]
+                        detail: [this.formDynamic.attrsVal],
+                        specialDetail: {}
                     });
                     this.formDynamic.attrsName = '';
                     this.formDynamic.attrsVal = '';
@@ -2004,6 +2028,7 @@
                     if (rule) {
                         this.ruleBool = true;
                         var rule_value = rule.rule_value.map(function (item) {
+                            item.specialDetail = item.specialDetail || {};
                             return item;
                         });
                         this.$set(this.formData, 'items', rule_value);

+ 39 - 0
app/api/controller/store/StoreProductController.php

@@ -141,6 +141,45 @@ class StoreProductController
         $storeInfo['userCollect'] = StoreProductRelation::isProductRelation($id, $uid, 'collect');
         $storeInfo['userLike'] = StoreProductRelation::isProductRelation($id, $uid, 'like');
         list($productAttr, $productValue) = StoreProductAttr::getProductAttrDetail($id, $uid, $type);
+
+        // 特供规格过滤:非经销商用户隐藏特供规格值
+        $isDealer = $uid ? (User::where('uid', $uid)->value('dealer') > 0) : false;
+        if (!$isDealer) {
+            // 收集所有特供规格值
+            $specialValues = [];
+            foreach ($productAttr as $attrGroup) {
+                foreach ($attrGroup['attr_value'] as $av) {
+                    if (!empty($av['is_special'])) {
+                        $specialValues[] = $av['attr'];
+                    }
+                }
+            }
+            // 过滤 productValue:移除包含特供值的SKU
+            if (!empty($specialValues)) {
+                foreach ($productValue as $suk => $value) {
+                    foreach ($specialValues as $sv) {
+                        if (in_array($sv, explode(',', $suk))) {
+                            unset($productValue[$suk]);
+                            break;
+                        }
+                    }
+                }
+                // 过滤 productAttr:移除特供规格值
+                foreach ($productAttr as $k => $attrGroup) {
+                    $newAttrValues = [];
+                    $newAttrValue = [];
+                    foreach ($attrGroup['attr_value'] as $av) {
+                        if (empty($av['is_special'])) {
+                            $newAttrValues[] = $av['attr'];
+                            $newAttrValue[] = $av;
+                        }
+                    }
+                    $productAttr[$k]['attr_values'] = $newAttrValues;
+                    $productAttr[$k]['attr_value'] = $newAttrValue;
+                }
+            }
+        }
+
         StoreVisit::setView($uid, $id, $storeInfo['cate_id'], 'viwe');
         $data['storeInfo'] = StoreProduct::setLevelPrice($storeInfo, $uid, true);
         $data['similarity'] = StoreProduct::cateIdBySimilarityProduct($storeInfo['cate_id'], 'id,store_name,image,price,sales,ficti', 4);

+ 20 - 0
app/models/store/StoreProductAttr.php

@@ -58,12 +58,32 @@ class StoreProductAttr extends BaseModel
             }
             $values[$value['suk']] = $value;
         }
+
+        // 读取特供规格标记
+        $specialValueMap = [];
+        $resultData = Db::name('StoreProductAttrResult')->where('product_id', $productId)->where('type', $type_id)->value('result');
+        if ($resultData) {
+            $resultJson = json_decode($resultData, true);
+            if (isset($resultJson['attr']) && is_array($resultJson['attr'])) {
+                foreach ($resultJson['attr'] as $attrItem) {
+                    if (isset($attrItem['specialDetail']) && is_array($attrItem['specialDetail'])) {
+                        foreach ($attrItem['specialDetail'] as $specVal => $isSpecial) {
+                            if ($isSpecial) {
+                                $specialValueMap[trim($specVal)] = true;
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
         foreach ($attrDetail as $k=>$v){
             $attr = $v['attr_values'];
 //            unset($productAttr[$k]['attr_values']);
             foreach ($attr as $kk=>$vv){
                 $attrDetail[$k]['attr_value'][$kk]['attr'] =  $vv;
                 $attrDetail[$k]['attr_value'][$kk]['check'] =  false;
+                $attrDetail[$k]['attr_value'][$kk]['is_special'] = isset($specialValueMap[$vv]);
             }
         }
         return [$attrDetail,$values];