|
|
@@ -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;
|