SystemFaqLogic.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace app\admin\logic;
  3. use app\common\model\SystemFaq;
  4. use app\admin\model\dao\SystemFaq as SystemFaqDao;
  5. use think\facade\Cache;
  6. class SystemFaqLogic
  7. {
  8. private static $CACHE_ID_KEY = "cache:system_faq:id:";
  9. private static $CACHE_LIST_KEY = "cache:system_faq:list";
  10. public static function getList($page, $limit, $where, $sort)
  11. {
  12. $count = (new SystemFaq())
  13. ->where($where)
  14. ->count();
  15. $list = (new SystemFaq())
  16. ->where($where)
  17. ->page($page, $limit)
  18. ->order($sort)
  19. ->select();
  20. foreach ($list as &$v) {
  21. if ($v->parent_id == 0) {
  22. $v->parent_id = '最上级';
  23. } else {
  24. $self = SystemFaqLogic::getTitleById($v->parent_id);
  25. $v->parent_id = $self;
  26. }
  27. }
  28. return [$count, $list];
  29. }
  30. private static function getTitleById($parent_id)
  31. {
  32. $key = self::$CACHE_ID_KEY . $parent_id;
  33. if (Cache::has($key)) {
  34. return Cache::get($key);
  35. }
  36. $name = SystemFaqDao::getTitleById($parent_id);
  37. Cache::set($key, $name, 10 * 60);
  38. return $name;
  39. }
  40. public static function delTitleCache($parent_id)
  41. {
  42. $key = self::$CACHE_ID_KEY . $parent_id;
  43. Cache::delete($key);
  44. }
  45. public static function getTopList()
  46. {
  47. $key = self::$CACHE_LIST_KEY;
  48. if (Cache::has($key)) {
  49. return Cache::get($key);
  50. }
  51. $list = SystemFaqDao::getTopArrList();
  52. array_push($list, ['id' => 0, 'title' => '最上级']);
  53. Cache::set($key, $list, 10 * 60);
  54. return $list;
  55. }
  56. public static function delCache()
  57. {
  58. $key = self::$CACHE_LIST_KEY;
  59. Cache::delete($key);
  60. }
  61. }