105 lines
3.3 KiB
PHP
105 lines
3.3 KiB
PHP
<?php
|
||
|
||
namespace app\models;
|
||
|
||
use Yii;
|
||
use app\models\Model;
|
||
|
||
/**
|
||
* This is the model class for table "{{%goods_hub}}".
|
||
*
|
||
* @property int $id ID
|
||
* @property int $cx_mch_id 平台商户ID
|
||
* @property string $name 商品名称
|
||
* @property string|null $subtitle 副标题
|
||
* @property float $original_price 原价
|
||
* @property float $cost_price 成本价
|
||
* @property string $detail 商品详情,图文
|
||
* @property string $cover_pic 商品缩略图
|
||
* @property string|null $pic_urls 商品轮播图
|
||
* @property string|null $video_url 商品视频
|
||
* @property string $unit 单位
|
||
* @property int $created_at 添加时间
|
||
* @property int $updated_at 更新时间
|
||
* @property int $deleted_at 删除时间
|
||
* @property int $is_delete 是否删除,0=否,1=是
|
||
* @property int $type 商品类型:0=实体商品
|
||
*/
|
||
class GoodsHub extends \yii\db\ActiveRecord
|
||
{
|
||
/**
|
||
* {@inheritdoc}
|
||
*/
|
||
public static function tableName()
|
||
{
|
||
return '{{%goods_hub}}';
|
||
}
|
||
|
||
/**
|
||
* {@inheritdoc}
|
||
*/
|
||
public function rules()
|
||
{
|
||
return [
|
||
[['detail', 'pic_urls', 'name', 'subtitle', 'cover_pic', 'video_url', 'unit'], 'trim'],
|
||
[['cx_mch_id', 'created_at', 'updated_at', 'deleted_at', 'is_delete', 'type'], 'integer'],
|
||
[['name', 'detail', 'cover_pic'], 'required'],
|
||
[['original_price', 'cost_price'], 'number'],
|
||
[['detail', 'pic_urls'], 'string'],
|
||
[['name', 'subtitle', 'cover_pic', 'video_url', 'unit'], 'string', 'max' => 255],
|
||
];
|
||
}
|
||
|
||
/**
|
||
* {@inheritdoc}
|
||
*/
|
||
public function attributeLabels()
|
||
{
|
||
return [
|
||
'id' => 'ID',
|
||
'cx_mch_id' => '平台商户ID',
|
||
'name' => '商品名称',
|
||
'subtitle' => '副标题',
|
||
'original_price' => '原价',
|
||
'cost_price' => '成本价',
|
||
'detail' => '商品详情,图文',
|
||
'cover_pic' => '商品缩略图',
|
||
'pic_urls' => '商品轮播图',
|
||
'video_url' => '商品视频',
|
||
'unit' => '单位',
|
||
'created_at' => '添加时间',
|
||
'updated_at' => '更新时间',
|
||
'deleted_at' => '删除时间',
|
||
'is_delete' => '是否删除,0=否,1=是',
|
||
'type' => '商品类型:0=实体商品 ',
|
||
];
|
||
}
|
||
|
||
|
||
public function beforeSave($insert) {
|
||
if(parent::beforeSave($insert)){
|
||
if($this->isNewRecord){
|
||
$this->created_at = time();
|
||
}
|
||
$this->updated_at = time();
|
||
if($this->is_delete == 1)
|
||
$this->deleted_at = time();
|
||
$this->htmlTagFilter();
|
||
return true;
|
||
} else {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public function htmlTagFilter()
|
||
{
|
||
$this->name = Model::htmlTagFilter($this->name);
|
||
$this->subtitle = Model::htmlTagFilter($this->subtitle);
|
||
$this->detail = Model::htmlTagFilter($this->detail);
|
||
$this->cover_pic = Model::htmlTagFilter($this->cover_pic);
|
||
$this->video_url = Model::htmlTagFilter($this->video_url);
|
||
$this->unit = Model::htmlTagFilter($this->unit);
|
||
}
|
||
|
||
}
|