WIN-2308041133\Administrator před 1 týdnem
rodič
revize
5cfad81dec

+ 22 - 1
app/admin/controller/store/StoreProduct.php

@@ -3,6 +3,7 @@
 namespace app\admin\controller\store;
 
 use app\admin\controller\AuthController;
+use app\models\store\StoreProductLevel;
 use app\models\system\Tree;
 use app\admin\model\store\{
     StoreDescription,
@@ -267,6 +268,15 @@ class StoreProduct extends AuthController
             }
             $data['productInfo'] = $productInfo;
         }
+        $level_radio = [
+            ['level_name' => '青源客', 'ratio' => 1.5],
+            ['level_name' => '青润使', 'ratio' => 2.0],
+            ['level_name' => '青金团', 'ratio' => 3.0],
+            ['level_name' => '青玉团', 'ratio' => 4.0],
+            ['level_name' => '青谷团', 'ratio' => 5.0]
+        ];
+        $data['level_radio'] = $level_radio;
+        $data['level_set'] = 1;
         return JsonService::successful($data);
     }
 
@@ -309,7 +319,9 @@ class StoreProduct extends AuthController
             ['attrs', []],
             ['activity', []],
             ['store_type', 1],
-            ['mer_id',0]
+            ['mer_id',0],
+            ['level_set', 0],
+            ['level_radio', []],
         ], $this->request, false, true);
 //        $admin_id=$this->adminId;
 //        $mer_id = SystemAdmin::where('id',$admin_id)->value('mer_id');
@@ -318,6 +330,10 @@ class StoreProduct extends AuthController
             $data['is_pick']=SystemStore::where('id',$data['mer_id'])->value('is_pick');
 //            var_dump($data);die();
 //        }
+        $level_set = $data['level_set'];
+        $level_radio = $data['level_radio'];
+        unset($data['level_set']);
+        unset($data['level_radio']);
         foreach ($data['activity'] as $k => $v) {
             if ($v == '秒杀') {
                 $data['activity'][$k] = 1;
@@ -380,6 +396,10 @@ class StoreProduct extends AuthController
             }
 
             $attr_res = StoreProductAttr::createProductAttr($attr, $detail, $id);
+            if ($level_set>0){
+                StoreProductLevel::where('product_id',$id)->where('type',1)->delete();
+//                未完待续
+            }
             if ($attr_res) {
                 ProductModel::commitTrans();
                 return Json::success('修改成功!');
@@ -391,6 +411,7 @@ class StoreProduct extends AuthController
             $data['add_time'] = time();
             $data['code_path'] = '';
             $res = ProductModel::create($data);
+            $id = $res['id'];
             $description = $data['description'];
             StoreDescription::saveDescription($description, $res['id']);
             $cateData = [];

+ 105 - 1
app/admin/view/store/store_product/create.php

@@ -721,6 +721,51 @@
                                             </div>
                                         </div>
                                     </div>
+                                    <!-- 在这里添加等级返利设置 -->
+                                    <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
+                                        <div class="grid-demo grid-demo-bg1">
+                                            <div class="layui-form-item">
+                                                <label class="layui-form-label">等级返利设置</label>
+                                                <div class="layui-input-block">
+                                                    <input type="radio" name="level_set" lay-filter="level_set" value="1"
+                                                           title="开启"
+                                                           :checked="formData.level_set == 1 ? true : false">
+                                                    <input type="radio" name="level_set" lay-filter="level_set" value="0"
+                                                           title="关闭"
+                                                           :checked="formData.level_set == 0 ? true : false">
+                                                </div>
+                                            </div>
+                                        </div>
+                                    </div>
+
+                                    <div class="layui-col-xs12 layui-col-sm12 layui-col-md12" v-if="formData.level_set == 1">
+                                        <div class="grid-demo grid-demo-bg1">
+                                            <div class="layui-form-item">
+                                                <label class="layui-form-label">等级返利比例(%)</label>
+                                                <div class="layui-input-block">
+                                                    <table class="layui-table">
+                                                        <thead>
+                                                        <tr>
+                                                            <th width="20%">等级名称</th>
+                                                            <th width="20%">返利比例(%)</th>
+                                                        </tr>
+                                                        </thead>
+                                                        <tbody>
+                                                        <tr v-for="(item, index) in level_radio" :key="index">
+                                                            <td>{{ item.level_name }}</td>
+                                                            <td>
+                                                                <input type="number" v-model="item.ratio" class="layui-input"
+                                                                       placeholder="请输入返利比例" step="0.01" min="0" max="100">
+                                                            </td>
+                                                        </tr>
+                                                        </tbody>
+                                                    </table>
+                                                    <span class="info">设置每个等级对应的返利百分比</span>
+                                                </div>
+                                            </div>
+                                        </div>
+                                    </div>
+
                                     <div class="layui-col-xs12 layui-col-sm4 layui-col-md4">
                                         <div class="grid-demo grid-demo-bg1">
                                             <div class="layui-form-item">
@@ -1048,6 +1093,7 @@
             upload: {
                 videoIng: false
             },
+
             formData: {
                 cate_id: [],
                 temp_id: 0,
@@ -1128,7 +1174,19 @@
             activity: {'秒杀': '#1E9FFF', '砍价': '#189688', '拼团': '#FEB900'},
             attr: [],//临时属性
             newRule: false,//是否添加新规则
-            radioRule: ['store_type', 'is_sub', 'is_show', 'is_hot', 'is_benefit', 'is_new', 'is_good', 'is_best','is_wholesale', 'spec_type'],//radio 当选规则
+            // ... 其他已有数据保持不变
+            level_set: 0,
+            level_radio: [
+                { level_name: '青源客', ratio: '' },
+                { level_name: '青润使', ratio: '' },
+                { level_name: '青金团', ratio: '' },
+                { level_name: '青玉团', ratio: '' },
+                { level_name: '青谷团', ratio: '' }
+            ],
+            // 添加level_set到radioRule数组中
+            radioRule: ['store_type', 'is_sub', 'is_show', 'is_hot', 'is_benefit', 'is_new', 'is_good', 'is_best','is_wholesale', 'spec_type', 'level_set'],
+            // ... 其他数据保持不变
+            // radioRule: ['store_type', 'is_sub', 'is_show', 'is_hot', 'is_benefit', 'is_new', 'is_good', 'is_best','is_wholesale', 'spec_type'],//radio 当选规则
             rule: { //多图选择规则
                 slider_image: {
                     maxLength: 5
@@ -1165,6 +1223,10 @@
             //         this.formData.attr.pic = n;
             //     }
             // }
+            // ... 其他watch保持不变
+            'formData.level_set': function(n) {
+                // 处理level_set变化
+            },
         },
         methods: {
             back: function () {
@@ -1274,6 +1336,29 @@
                     a: 'get_product_info',
                     q: {id: that.id}
                 })).then(function (res) {
+                    // ... 原有的数据处理代码保持不变
+
+                    var productInfo = res.data.productInfo || {};
+                    if (productInfo.id && that.id) {
+                        that.$set(that, 'formData', productInfo);
+                        // 处理等级返利数据
+                        if (productInfo.level_radio && productInfo.level_radio.length > 0) {
+                            that.$set(that, 'level_radio', productInfo.level_radio);
+                            that.formData.level_set = 1;
+                        } else {
+                            // 如果没有数据,重置为初始值
+                            that.$set(that, 'level_radio', [
+                                { level_name: '青源客', ratio: '' },
+                                { level_name: '青润使', ratio: '' },
+                                { level_name: '青金团', ratio: '' },
+                                { level_name: '青玉团', ratio: '' },
+                                { level_name: '青谷团', ratio: '' }
+                            ]);
+                            that.formData.level_set = 0;
+                        }
+                        that.generate();
+                    }
+                    // ... 后续代码保持不变
                     that.$set(that, 'cateList', res.data.cateList);
                     that.$set(that, 'tempList', res.data.tempList);
                     that.$set(that, 'merList', res.data.merList);
@@ -1624,6 +1709,25 @@
             },
             handleSubmit: function () {
                 var that = this, cate_id = $('input[name="cate_id"]').val();
+                // ... 原有的验证代码保持不变
+
+                // 处理等级返利数据
+                if (that.formData.level_set == 1) {
+                    // 验证等级返利数据
+                    for (var i = 0; i < that.level_radio.length; i++) {
+                        var ratio = parseFloat(that.level_radio[i].ratio);
+                        if (isNaN(ratio) || ratio < 0 || ratio > 100) {
+                            return that.showMsg('请正确填写等级返利比例(0-100之间)');
+                        }
+                    }
+                    // 将level_radio赋值给formData
+                    that.formData.level_radio = that.level_radio;
+                } else {
+                    // 关闭时清空数据
+                    that.formData.level_radio = [];
+                }
+
+                // ... 后续原有的提交代码保持不变
                 if (cate_id != '') {
                     this.formData.cate_id = cate_id.split(',');
                 }