Category.php 912 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\common\model\article;
  10. use think\Cache;
  11. use app\common\model\BaseModel;
  12. /**
  13. * 文章分类模型
  14. * Class Category
  15. * @package app\common\model
  16. */
  17. class Category extends BaseModel
  18. {
  19. protected $name = 'article_category';
  20. /**
  21. * 所有分类
  22. * @return mixed
  23. */
  24. public static function getALL()
  25. {
  26. $model = new static;
  27. if (!Cache::get('article_category_' . $model::$wxapp_id)) {
  28. $data = $model->order(['sort' => 'asc', 'create_time' => 'asc'])->select();
  29. $all = !empty($data) ? $data->toArray() : [];
  30. Cache::tag('cache')->set('article_category_' . $model::$wxapp_id, $all);
  31. }
  32. return Cache::get('article_category_' . $model::$wxapp_id);
  33. }
  34. }