<?php
namespace app\api\model\article;
use think\Cache;
use app\store\model\Article as ArticleModel;
use app\common\model\article\Category as CategoryModel;
class Category extends CategoryModel
{
public static function detail($category_id)
{
return static::get($category_id);
}
public function add($data)
{
$data['wxapp_id'] = self::$wxapp_id;
$this->deleteCache();
return $this->allowField(true)->save($data);
}
public function edit($data)
{
$this->deleteCache();
return $this->allowField(true)->save($data);
}
public function remove($category_id)
{
$articleCount = ArticleModel::getArticleTotal(['category_id' => $category_id]);
if ($articleCount > 0) {
$this->error = '该分类下存在' . $articleCount . '个文章,不允许删除';
return false;
}
$this->deleteCache();
return $this->delete();
}
private function deleteCache()
{
return Cache::rm('article_category_' . self::$wxapp_id);
}
}