| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- namespace app\admin\logic;
- use app\common\model\SystemFaq;
- use app\admin\model\dao\SystemFaq as SystemFaqDao;
- use think\facade\Cache;
- class SystemFaqLogic
- {
- private static $CACHE_ID_KEY = "cache:system_faq:id:";
- private static $CACHE_LIST_KEY = "cache:system_faq:list";
- public static function getList($page, $limit, $where, $sort)
- {
- $count = (new SystemFaq())
- ->where($where)
- ->count();
- $list = (new SystemFaq())
- ->where($where)
- ->page($page, $limit)
- ->order($sort)
- ->select();
- foreach ($list as &$v) {
- if ($v->parent_id == 0) {
- $v->parent_id = '最上级';
- } else {
- $self = SystemFaqLogic::getTitleById($v->parent_id);
- $v->parent_id = $self;
- }
- }
- return [$count, $list];
- }
- private static function getTitleById($parent_id)
- {
- $key = self::$CACHE_ID_KEY . $parent_id;
- if (Cache::has($key)) {
- return Cache::get($key);
- }
- $name = SystemFaqDao::getTitleById($parent_id);
- Cache::set($key, $name, 10 * 60);
- return $name;
- }
- public static function delTitleCache($parent_id)
- {
- $key = self::$CACHE_ID_KEY . $parent_id;
- Cache::delete($key);
- }
- public static function getTopList()
- {
- $key = self::$CACHE_LIST_KEY;
- if (Cache::has($key)) {
- return Cache::get($key);
- }
- $list = SystemFaqDao::getTopArrList();
- array_push($list, ['id' => 0, 'title' => '最上级']);
- Cache::set($key, $list, 10 * 60);
- return $list;
- }
- public static function delCache()
- {
- $key = self::$CACHE_LIST_KEY;
- Cache::delete($key);
- }
- }
|