80 lines
2.0 KiB
PHP
80 lines
2.0 KiB
PHP
<?php
|
||
|
||
namespace app\models\cms;
|
||
|
||
use Yii;
|
||
|
||
/**
|
||
* This is the model class for table "{{%cms_post_meta}}".
|
||
*
|
||
* @property int $id ID
|
||
* @property int $cx_mch_id 平台商户ID
|
||
* @property int $type 类型:0=分类
|
||
* @property int $post_id 文章ID
|
||
* @property string|null $key KEY
|
||
* @property string|null $value VALUE
|
||
* @property int $created_at 添加时间
|
||
* @property int $updated_at 更新时间
|
||
* @property int $is_delete 是否删除:0=否,1=是
|
||
* @property int $deleted_at 删除时间
|
||
*/
|
||
class PostMeta extends \yii\db\ActiveRecord
|
||
{
|
||
const TYPE_CAT = 0;
|
||
|
||
/**
|
||
* {@inheritdoc}
|
||
*/
|
||
public static function tableName()
|
||
{
|
||
return '{{%cms_post_meta}}';
|
||
}
|
||
|
||
/**
|
||
* {@inheritdoc}
|
||
*/
|
||
public function rules()
|
||
{
|
||
return [
|
||
[['key', 'value'], 'trim'],
|
||
[['cx_mch_id', 'type', 'post_id', 'created_at', 'updated_at', 'is_delete', 'deleted_at'], 'integer'],
|
||
[['post_id'], 'required'],
|
||
[['key'], 'string', 'max' => 50],
|
||
[['value'], 'string', 'max' => 256],
|
||
];
|
||
}
|
||
|
||
/**
|
||
* {@inheritdoc}
|
||
*/
|
||
public function attributeLabels()
|
||
{
|
||
return [
|
||
'id' => 'ID',
|
||
'cx_mch_id' => '平台商户ID',
|
||
'type' => '类型:0=分类',
|
||
'post_id' => '文章ID',
|
||
'key' => 'KEY',
|
||
'value' => 'VALUE',
|
||
'created_at' => '添加时间',
|
||
'updated_at' => '更新时间',
|
||
'is_delete' => '是否删除:0=否,1=是',
|
||
'deleted_at' => '删除时间',
|
||
];
|
||
}
|
||
|
||
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();
|
||
return true;
|
||
} else {
|
||
return false;
|
||
}
|
||
}
|
||
}
|