|
|
@ -47,6 +47,13 @@ class Goods extends \yii\db\ActiveRecord |
|
|
|
//是否删除is_delete
|
|
|
|
const IS_DELETE_NO = 0;//未删除
|
|
|
|
const IS_DELETE_YES = 1;//已删除
|
|
|
|
//该商品是否开放销售is_sale
|
|
|
|
const IS_SALE_NO = 0;//否
|
|
|
|
const IS_SALE_YES = 1;//是
|
|
|
|
public static $isSale = [ |
|
|
|
self::IS_SALE_NO => '否', |
|
|
|
self::IS_SALE_YES => '是' |
|
|
|
]; |
|
|
|
/** |
|
|
|
* {@inheritdoc} |
|
|
|
*/ |
|
|
@ -63,6 +70,7 @@ class Goods extends \yii\db\ActiveRecord |
|
|
|
return [ |
|
|
|
[['pid', 'cat_id', 'brand_id', 'shop_cat_id', 'supplier_id', 'weight', 'length', 'width', 'height', 'diameter', 'sold_count', 'limit_count', 'stock', 'stock_warn', 'market_price', 'price', 'image', 'model_id', 'is_sale', 'sort_order', 'bouns_points', 'experience_points', 'is_delete', 'express_template'], 'integer'], |
|
|
|
[['cat_id', 'brand_id', 'shop_cat_id', 'name', 'sn'], 'required'], |
|
|
|
[['sn'], 'checkExist'], |
|
|
|
[['description'], 'string'], |
|
|
|
[['name'], 'string', 'max' => 120], |
|
|
|
[['sn'], 'string', 'max' => 60], |
|
|
@ -72,6 +80,25 @@ class Goods extends \yii\db\ActiveRecord |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param $attribute |
|
|
|
* @param $params |
|
|
|
* 验证商品编号唯一 |
|
|
|
*/ |
|
|
|
public function checkExist($attribute, $params) |
|
|
|
{ |
|
|
|
$goods = self::find()->where([$attribute => $this->$attribute, 'is_delete' => 0])->one(); |
|
|
|
if ($this->isNewRecord) { |
|
|
|
if ($goods) { |
|
|
|
$this->addError($attribute, "该商品编号已经存在"); |
|
|
|
} |
|
|
|
} else { |
|
|
|
if ($goods && $goods->id != $this->id) { |
|
|
|
$this->addError($attribute, "该商品编号已经存在"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* {@inheritdoc} |
|
|
|
*/ |
|
|
@ -103,7 +130,7 @@ class Goods extends \yii\db\ActiveRecord |
|
|
|
'description' => '详细介绍', |
|
|
|
'image' => '图片id', |
|
|
|
'model_id' => '模型id', |
|
|
|
'is_sale' => '该商品是否开放销售,1为是,0为否', |
|
|
|
'is_sale' => '该商品是否开放销售', |
|
|
|
'sort_order' => '排序', |
|
|
|
'bouns_points' => '奖励积分', |
|
|
|
'experience_points' => '经验值', |
|
|
@ -135,4 +162,17 @@ class Goods extends \yii\db\ActiveRecord |
|
|
|
], |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param bool $insert |
|
|
|
* @return bool |
|
|
|
* 自动填入参数 |
|
|
|
*/ |
|
|
|
public function beforeSave($insert) |
|
|
|
{ |
|
|
|
if (!$this->sn) { |
|
|
|
$this->sn = time() . rand(1111, 9999); |
|
|
|
} |
|
|
|
return parent::beforeSave($insert); // TODO: Change the autogenerated stub
|
|
|
|
} |
|
|
|
} |