Cat.php 749 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace app\youzan\logic;
  3. use app\youzan\model\YzCat;
  4. use think\facade\Cache;
  5. use think\facade\Db;
  6. //分类处理层
  7. class Cat
  8. {
  9. private static $cache_key = 'yz_cat_list_pid_';
  10. //获取分类列表
  11. public static function getYzCatList(int $parent_cid = 0)
  12. {
  13. $key = self::$cache_key . (string)$parent_cid;
  14. $rs = Cache::get($key);
  15. if (empty($rs)) {
  16. $rs = YzCat::field('id,yz_cat_id,yz_cat_name,parent_cid')
  17. ->where('status', YzCat::$status_normal)
  18. ->where('parent_cid', $parent_cid)
  19. ->order('id')
  20. ->select()
  21. ->toArray();
  22. Cache::set($key, $rs, 3600);
  23. }
  24. return $rs;
  25. }
  26. }