فهرست منبع

商品列表,添加和编辑商品

zxiansheng 3 سال پیش
والد
کامیت
878c1ed37c

+ 20 - 4
backendApi/modules/v1/models/lists/shop/GoodsList.php

@@ -45,10 +45,26 @@ class GoodsList extends \common\libs\dataList\DataList implements DataListInterf
                     'header' => '商品编号',
                     'headerOther' => ['width' => '200'],
                 ],
-                'TYPE' => [
-                    'header' => '商品来源',
-                    'value' => function($row){
-                        return ShopGoods::GOODS_TYPE[$row['TYPE']]['name'];
+                // 'TYPE' => [
+                //     'header' => '商品来源',
+                //     'value' => function($row){
+                //         return ShopGoods::GOODS_TYPE[$row['TYPE']]['name'];
+                //     },
+                //     'headerOther' => ['width' => '150'],
+                // ],
+                'SELL_DISCOUNT' => [
+                    'header' => '商品折扣',
+                    'value' => function($row) {
+                        $discount = 0;
+                        if ($row['TYPE'] == 1) {
+                            $discount = '0.5';
+                        } else if($row['TYPE'] == 2) {
+                            $discount = '0.6';
+                        } else {
+                            $discount = $row['SELL_DISCOUNT'];
+                        }
+
+                        return $discount;
                     },
                     'headerOther' => ['width' => '150'],
                 ],

+ 7 - 3
backendEle/src/views/shop/goods-add.vue

@@ -6,16 +6,19 @@
                 <el-form-item label="商品名称">
                     <el-input v-model="form.goodsName"></el-input>
                 </el-form-item>
-                <el-form-item label="商品来源">
+                <!-- <el-form-item label="商品来源">
                     <el-select v-model="form.type" placeholder="请选择商品来源">
                         <el-option v-for="(item,index) in goodsType" :key="index" :label="item.name"
                                    :value="index"></el-option>
                     </el-select>
+                </el-form-item> -->
+                <el-form-item label="会员折扣">
+                    <el-input v-model="form.sellDiscount"></el-input>
                 </el-form-item>
                 <el-form-item label="商品类型">
                     <el-checkbox  v-for="(value,key) in GiftTypeArr" v-model="form.giftType[key-1]" :key="key" >{{value.name}}</el-checkbox>
                 </el-form-item>
-                <el-form-item label="出售方式">
+                <el-form-item label="复消购买方式">
                     <el-checkbox  v-for="(value,key) in sellType" v-model="form.sellType[key-1]" :key="key" >{{value.name}}</el-checkbox>
                 </el-form-item>
 
@@ -105,6 +108,7 @@
                     discount:'',
                     cover:'',
                     textarea:'',
+                    sellDiscount:'',
                 },
                 submitButtonStat: false,
                 goodsType:[],
@@ -185,6 +189,7 @@
 
                 let postData = {
                     goodsName: this.form.goodsName,
+                    sellDiscount: this.form.sellDiscount,
                     discount: this.form.type.discount,
                     type: this.form.type,
                     giftType: sen_gift,
@@ -199,7 +204,6 @@
                     content: this.form.content,
                     sort: this.form.sort,
                     cover: this.form.cover,
-
                 }
 
                 return network.postData(path, postData).then(response => {

+ 7 - 2
backendEle/src/views/shop/index.vue

@@ -70,16 +70,19 @@
                     <el-form-item label="商品名称">
                         <el-input v-model="form.goodsName"></el-input>
                     </el-form-item>
-                    <el-form-item label="商品来源">
+                    <!-- <el-form-item label="商品来源">
                         <el-select v-model="form.type">
                             <el-option v-for="(item,index) in goodsType" :key="index" :label="item.name"
                                        :value="index"></el-option>
                         </el-select>
+                    </el-form-item> -->
+                    <el-form-item label="会员折扣">
+                        <el-input v-model="form.sellDiscount"></el-input>
                     </el-form-item>
                     <el-form-item label="商品类型">
                         <el-checkbox  v-for="(value,index) in GiftTypeArr" v-model="value.checked" :key="index" >{{value.name}}</el-checkbox>
                     </el-form-item>
-                    <el-form-item label="出售方式">
+                    <el-form-item label="复消购买方式">
                          <el-checkbox  v-for="(value,index) in sell_type" v-model="value.checked" :key="index" >{{value.name}}</el-checkbox>
                     </el-form-item>
 
@@ -197,6 +200,7 @@
                     discount:'',
                     cover:'',
                     textarea:'',
+                    sellDiscount:'',
                 },
                 submitButtonStat: false,
                 goodsType:[],
@@ -272,6 +276,7 @@
                     vueObj.sell_type=sellType;
 
                     vueObj.form.goodsName=response.goodsInfo.GOODS_NAME
+                    vueObj.form.sellDiscount=response.goodsInfo.SELL_DISCOUNT
                     vueObj.form.goodsNo=response.goodsInfo.GOODS_NO
                     vueObj.form.type=response.goodsInfo.TYPE
                     vueObj.form.unit=response.goodsInfo.UNIT

+ 4 - 3
common/models/ShopGoods.php

@@ -83,8 +83,8 @@ class ShopGoods extends \common\components\ActiveRecord
     public function rules()
     {
         return [
-            [['GOODS_NAME', 'CATE_ID', 'TYPE','GIFT_TYPE', 'SELL_TYPE', 'GOODS_NO', 'SELL_PRICE','MARKET_PRICE','PRICE_PV','STORE_NUMS'], 'required'],
-            [['TYPE','STORE_NUMS'], 'integer'],
+            [['SELL_DISCOUNT','GOODS_NAME', 'CATE_ID','GIFT_TYPE', 'SELL_TYPE', 'GOODS_NO', 'SELL_PRICE','MARKET_PRICE','PRICE_PV','STORE_NUMS'], 'required'],
+            [['STORE_NUMS'], 'integer'],
             [['SELL_PRICE','MARKET_PRICE','PRICE_PV','POINT'], 'number'],
             [['ID','CATE_ID', 'GOODS_NO','SELL_TYPE','GIFT_TYPE'], 'string', 'max' => 32],
             [['UNIT'], 'string', 'max' => 16],
@@ -104,7 +104,8 @@ class ShopGoods extends \common\components\ActiveRecord
             'ID' => 'ID',
             'GOODS_NAME' => '商品名称',
             'CATE_ID' => '所属分类ID',
-            'TYPE' => '商品来源',
+            // 'TYPE' => '商品来源',
+            'SELL_DISCOUNT' => '会员折扣',
             'GIFT_TYPE' => '商品类型',
             'SELL_TYPE' => '出售方式',
             'GOODS_NO' => '商品编号',

+ 18 - 7
common/models/forms/ShopGoodsForm.php

@@ -17,6 +17,7 @@ class ShopGoodsForm extends Model
     public $id;
     public $goodsName;
     public $type;
+    public $sellDiscount;
     public $giftType;
     public $sellType;
     public $goodsNo;
@@ -46,14 +47,15 @@ class ShopGoodsForm extends Model
     public function rules()
     {
         return [
-            [['id','type','giftType','sellType','goodsNo', 'goodsName', 'unit', 'sellPrice', 'marketPrice', 'pricePv', 'storeNums', 'content', 'sort','status','cover'], 'trim'],
-            [['goodsName','type','giftType','sellType','goodsNo', 'storeNums','sellPrice','marketPrice','pricePv', 'sort','status','cover'], 'required'],
+            [['id','sellDiscount','giftType','sellType','goodsNo', 'goodsName', 'unit', 'sellPrice', 'marketPrice', 'pricePv', 'storeNums', 'content', 'sort','status','cover'], 'trim'],
+            [['goodsName','sellDiscount','giftType','sellType','goodsNo', 'storeNums','sellPrice','marketPrice','pricePv', 'sort','status','cover'], 'required'],
             [['id'], 'required', 'on'=>'edit'],
             [['id'], 'exist', 'targetClass'=>ShopGoods::class, 'targetAttribute'=>'ID'],
             [['sellPrice','marketPrice','pricePv'], 'price'],
             [['id'], 'initModel'],
             [['selectedIds'], 'isSelected'],
             [['sort'], 'isSort'],
+            [['sellDiscount'], 'isDiscount']
         ];
     }
 
@@ -63,7 +65,7 @@ class ShopGoodsForm extends Model
             'selectedIds' => '商品ID',
             'id' => '产品ID',
             'goodsName' => '商品名称',
-            'type' => '商品来源',
+            'sellDiscount' => '会员折扣',
             'giftType' => '商品类型',
             'sellType' => '出售方式',
             'goodsNo' => '产品编号',
@@ -87,8 +89,8 @@ class ShopGoodsForm extends Model
     {
         $parentScenarios =  parent::scenarios();
         $customScenarios = [
-            'add' => ['goodsName','type','giftType', 'sellType','goodsNo','unit','sellPrice','marketPrice','pricePv','storeNums', 'content','sort','cover'],
-            'edit' => ['id','goodsName','type','giftType', 'sellType','goodsNo','unit','sellPrice','marketPrice','pricePv', 'storeNums', 'content','sort','cover'],
+            'add' => ['goodsName','sellDiscount','giftType', 'sellType','goodsNo','unit','sellPrice','marketPrice','pricePv','storeNums', 'content','sort','cover'],
+            'edit' => ['id','goodsName','sellDiscount','giftType', 'sellType','goodsNo','unit','sellPrice','marketPrice','pricePv', 'storeNums', 'content','sort','cover'],
             'changeStatus' => ['selectedIds', 'status'],
         ];
         return array_merge($parentScenarios, $customScenarios);
@@ -126,6 +128,13 @@ class ShopGoodsForm extends Model
         }
     }
 
+    // 折扣为0-1
+    public function isDiscount($attributes) {
+        if ($this->sellDiscount < 0 || $this->sellDiscount > 1 || !is_numeric($this->sellDiscount)) {
+            $this->addError($attributes, '折扣请填写0-1之间的数');
+        }
+    }
+
     /**
      * 添加
      * @return ShopGoods|null
@@ -140,7 +149,8 @@ class ShopGoodsForm extends Model
             // 添加商品
             $shopGoods = new ShopGoods();
             $shopGoods->GOODS_NAME = $this->goodsName;
-            $shopGoods->TYPE = $this->type;
+            //$shopGoods->TYPE = $this->type;
+            $shopGoods->SELL_DISCOUNT = $this->sellDiscount;
             $shopGoods->GIFT_TYPE = implode(',',$this->giftType);
             $shopGoods->SELL_TYPE = implode(',',$this->sellType);
             $shopGoods->GOODS_NO = $this->goodsNo;
@@ -182,7 +192,8 @@ class ShopGoodsForm extends Model
         try {
             $model = $this->_model;
             $model->GOODS_NAME = $this->goodsName;
-            $model->TYPE = $this->type;
+            // $model->TYPE = $this->type;
+            $model->SELL_DISCOUNT = $this->sellDiscount;
             $model->GIFT_TYPE = implode(',',$this->giftType);
             $model->SELL_TYPE = implode(',',$this->sellType);
             $model->GOODS_NO = $this->goodsNo;