121 lines
3.3 KiB
PHP
121 lines
3.3 KiB
PHP
<?php
|
||
|
||
namespace app\models;
|
||
|
||
use Yii;
|
||
use app\models\Model;
|
||
|
||
/**
|
||
* This is the model class for table "{{%faq}}".
|
||
*
|
||
* @property int $id ID
|
||
* @property int $cx_mch_id 平台商户ID
|
||
* @property string $title 标题
|
||
* @property string $content 内容
|
||
* @property int $created_at 添加时间
|
||
* @property int $updated_at 更新时间
|
||
* @property int $is_delete 是否删除
|
||
* @property int $deleted_at 删除时间
|
||
* @property int $status 状态:0=草稿,1=已发布,2=回收站
|
||
* @property int $published_at 发布时间
|
||
* @property int $sort 排序:默认100,升序
|
||
* @property int $is_hot 是否热门:0=否,1=是
|
||
*/
|
||
class Faq extends \yii\db\ActiveRecord
|
||
{
|
||
const STATUS_DRAFT = 0;
|
||
const STATUS_PUBLISHED = 1;
|
||
const STATUS_TRASH = 2;
|
||
|
||
|
||
/**
|
||
* {@inheritdoc}
|
||
*/
|
||
public static function tableName()
|
||
{
|
||
return '{{%faq}}';
|
||
}
|
||
|
||
/**
|
||
* {@inheritdoc}
|
||
*/
|
||
public function rules()
|
||
{
|
||
return [
|
||
[['title', 'content', ], 'trim'],
|
||
[['cx_mch_id', 'created_at', 'updated_at', 'is_delete', 'deleted_at', 'status', 'published_at', 'sort', 'is_hot'], 'integer'],
|
||
[['title', 'content'], 'required'],
|
||
[['content'], 'string'],
|
||
[['title'], 'string', 'max' => 256],
|
||
];
|
||
}
|
||
|
||
/**
|
||
* {@inheritdoc}
|
||
*/
|
||
public function attributeLabels()
|
||
{
|
||
return [
|
||
'id' => 'ID',
|
||
'cx_mch_id' => '平台商户ID',
|
||
'title' => '标题',
|
||
'content' => '内容',
|
||
'created_at' => '添加时间',
|
||
'updated_at' => '更新时间',
|
||
'is_delete' => '是否删除',
|
||
'deleted_at' => '删除时间',
|
||
'status' => '状态:0=草稿,1=已发布,2=回收站',
|
||
'published_at' => '发布时间',
|
||
'sort' => '排序:默认100,升序',
|
||
'is_hot' => '是否热门:0=否,1=是',
|
||
];
|
||
}
|
||
|
||
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->title = Model::htmlTagFilter($this->title);
|
||
$this->content = Model::htmlTagFilter($this->content);
|
||
}
|
||
|
||
|
||
public static function statusLabels()
|
||
{
|
||
return [
|
||
'0' => '草稿',
|
||
'1' => '已发布',
|
||
'2' => '回收站',
|
||
];
|
||
}
|
||
|
||
public static function getStatus($status)
|
||
{
|
||
$labels = self::statusLabels();
|
||
return isset($labels[$status]) ? $labels[$status] : "未知";
|
||
}
|
||
|
||
public static function getViewedNum($faq_id, $cx_mch_id = 0)
|
||
{
|
||
return FaqMeta::getViewedNum($faq_id, $cx_mch_id);
|
||
}
|
||
|
||
public static function setViewedNum($faq_id, $cx_mch_id = 0)
|
||
{
|
||
return FaqMeta::setViewedNum($faq_id, $cx_mch_id);
|
||
}
|
||
}
|