Cat.php 831 B

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