1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-23 11:58:41 +08:00
xiaochong0302 c0e38d68fd 精简auth
2020-04-07 19:32:00 +08:00

147 lines
2.1 KiB
PHP

<?php
namespace App\Models;
use App\Caches\Category as CategoryCache;
use App\Caches\CategoryList as CategoryListCache;
use App\Caches\CategoryTreeList as CategoryTreeListCache;
use Phalcon\Mvc\Model\Behavior\SoftDelete;
class Category extends Model
{
/**
* 主键编号
*
* @var int
*/
public $id;
/**
* 上级编号
*
* @var int
*/
public $parent_id;
/**
* 名称
*
* @var string
*/
public $name;
/**
* 优先级
*
* @var int
*/
public $priority;
/**
* 层级
*
* @var int
*/
public $level;
/**
* 路径
*
* @var string
*/
public $path;
/**
* 发布标识
*
* @var int
*/
public $published;
/**
* 删除标识
*
* @var int
*/
public $deleted;
/**
* 节点数
*
* @var int
*/
public $child_count;
/**
* 课程数
*
* @var int
*/
public $course_count;
/**
* 创建时间
*
* @var int
*/
public $create_time;
/**
* 更新时间
*
* @var int
*/
public $update_time;
public function getSource()
{
return 'kg_category';
}
public function initialize()
{
parent::initialize();
$this->addBehavior(
new SoftDelete([
'field' => 'deleted',
'value' => 1,
])
);
}
public function beforeCreate()
{
$this->create_time = time();
}
public function beforeUpdate()
{
$this->update_time = time();
}
public function afterCreate()
{
$this->rebuildCache();
}
public function afterUpdate()
{
$this->rebuildCache();
}
public function rebuildCache()
{
$itemCache = new CategoryCache();
$itemCache->rebuild($this->id);
$listCache = new CategoryListCache();
$listCache->rebuild();
$treeListCache = new CategoryTreeListCache();
$treeListCache->rebuild();
}
}