88 lines
2.4 KiB
PHP
88 lines
2.4 KiB
PHP
<?php
|
||
|
||
namespace app\models;
|
||
|
||
use Yii;
|
||
use app\models\integral\mall\IntegralMallGoodsAttr;
|
||
use app\models\Model;
|
||
|
||
/**
|
||
* This is the model class for table "{{%goods_attr}}".
|
||
*
|
||
* @property int $id ID
|
||
* @property int $cx_mch_id 平台商户ID
|
||
* @property int $goods_id
|
||
* @property string $sign_id 规格ID标识,规格:规格值
|
||
* @property int $stock 库存
|
||
* @property float $price 价格
|
||
* @property string|null $serial_no 货号
|
||
* @property int $weight 重量(克)
|
||
* @property string|null $cover_pic 规格图片
|
||
* @property int $is_delete 是否删除,0=否,1=是
|
||
*/
|
||
class GoodsAttr extends \yii\db\ActiveRecord
|
||
{
|
||
/**
|
||
* {@inheritdoc}
|
||
*/
|
||
public static function tableName()
|
||
{
|
||
return '{{%goods_attr}}';
|
||
}
|
||
|
||
/**
|
||
* {@inheritdoc}
|
||
*/
|
||
public function rules()
|
||
{
|
||
return [
|
||
[['sign_id', 'serial_no', 'cover_pic'], 'trim'],
|
||
[['cx_mch_id', 'goods_id', 'stock', 'weight', 'is_delete'], 'integer'],
|
||
[['goods_id'], 'required'],
|
||
[['price'], 'number'],
|
||
[['sign_id', 'serial_no', 'cover_pic'], 'string', 'max' => 255],
|
||
];
|
||
}
|
||
|
||
/**
|
||
* {@inheritdoc}
|
||
*/
|
||
public function attributeLabels()
|
||
{
|
||
return [
|
||
'id' => 'ID',
|
||
'cx_mch_id' => '平台商户ID',
|
||
'goods_idgoods_id' => '商品ID',
|
||
'sign_id' => '规格ID标识,规格:规格值',
|
||
'stock' => '库存',
|
||
'price' => '价格',
|
||
'serial_no' => '货号',
|
||
'weight' => '重量(克)',
|
||
'cover_pic' => '规格图片',
|
||
'is_delete' => '是否删除,0=否,1=是',
|
||
];
|
||
}
|
||
|
||
public function beforeSave($insert) {
|
||
if(parent::beforeSave($insert)){
|
||
$this->htmlTagFilter();
|
||
return true;
|
||
} else {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public function htmlTagFilter()
|
||
{
|
||
$this->serial_no = Model::htmlTagFilter($this->serial_no);
|
||
$this->cover_pic = Model::htmlTagFilter($this->cover_pic);
|
||
}
|
||
|
||
|
||
//获取积分商品
|
||
public function getIntegralMallGoodsAttr()
|
||
{
|
||
return $this->hasOne(IntegralMallGoodsAttr::className(), ['goods_attr_id' => 'id'])->where(['is_delete' => 0]);
|
||
}
|
||
}
|