diff --git a/app/Admin/Repositories/MiniProgramDraft.php b/app/Admin/Repositories/MiniProgramDraft.php index 2f5bf75..9da52c9 100644 --- a/app/Admin/Repositories/MiniProgramDraft.php +++ b/app/Admin/Repositories/MiniProgramDraft.php @@ -7,6 +7,7 @@ use Dcat\Admin\Repositories\Repository; use EasyWeChat\Factory; use GuzzleHttp\Exception\GuzzleException; use Illuminate\Pagination\LengthAwarePaginator; +use Illuminate\Support\Facades\Cache; /** * 小程序草稿箱 @@ -15,10 +16,7 @@ use Illuminate\Pagination\LengthAwarePaginator; */ class MiniProgramDraft extends Repository { - public function getPrimaryKeyColumn() - { - return 'draft_id'; - } + protected $keyName = 'draft_id'; /** * 查询表格数据 @@ -37,15 +35,21 @@ class MiniProgramDraft extends Repository 'aes_key' => $setting['service_aeskey'], ]; - $openPlatform = Factory::openPlatform($config); - $codeTemplate = $openPlatform['code_template']; - - if (empty($codeTemplate) || (!$list = $codeTemplate->getDrafts())) { - $data['total'] = 0; - $data['subjects'] = []; + $cache_key = 'mini_program:draft_list'; + if ($data['subjects'] = Cache::get($cache_key)) { + $data['total'] = count($data['subjects']); } else { - $data['total'] = count($list['draft_list']); - $data['subjects'] = $list['draft_list'] ?? []; + $openPlatform = Factory::openPlatform($config); + $codeTemplate = $openPlatform['code_template']; + + if (empty($codeTemplate) || (!$list = $codeTemplate->getDrafts())) { + $data['total'] = 0; + $data['subjects'] = []; + } else { + $data['total'] = count($list['draft_list']); + $data['subjects'] = $list['draft_list'] ?? []; + Cache::put($cache_key, $list['draft_list'], 120); + } } return $model->makePaginator( diff --git a/app/Admin/Repositories/MiniProgramList.php b/app/Admin/Repositories/MiniProgramList.php index cbb99d6..bb88508 100644 --- a/app/Admin/Repositories/MiniProgramList.php +++ b/app/Admin/Repositories/MiniProgramList.php @@ -7,6 +7,7 @@ use Dcat\Admin\Repositories\Repository; use EasyWeChat\Factory; use GuzzleHttp\Exception\GuzzleException; use Illuminate\Pagination\LengthAwarePaginator; +use Illuminate\Support\Facades\Cache; /** * 小程序草稿箱 @@ -15,10 +16,7 @@ use Illuminate\Pagination\LengthAwarePaginator; */ class MiniProgramList extends Repository { - public function getPrimaryKeyColumn() - { - return ''; - } + protected $keyName = 'id'; /** * 查询表格数据 @@ -37,15 +35,21 @@ class MiniProgramList extends Repository 'aes_key' => $setting['service_aeskey'], ]; - $openPlatform = Factory::openPlatform($config); - $codeTemplate = $openPlatform['code_template']; - - if (empty($codeTemplate) || (!$list = $openPlatform->getAuthorizers())) { - $data['total'] = 0; - $data['subjects'] = []; + $cache_key = 'mini_program:list'; + if ($data['subjects'] = Cache::get($cache_key)) { + $data['total'] = count($data['subjects']); } else { - $data['total'] = count($list['list']); - $data['subjects'] = $list['list'] ?? []; + $openPlatform = Factory::openPlatform($config); + $codeTemplate = $openPlatform['code_template']; + + if (empty($codeTemplate) || (!$list = $openPlatform->getAuthorizers())) { + $data['total'] = 0; + $data['subjects'] = []; + } else { + $data['total'] = count($list['list']); + $data['subjects'] = $list['list'] ?? []; + Cache::put($cache_key, $list['list'], 120); + } } return $model->makePaginator( diff --git a/app/Admin/Repositories/MiniProgramTemplate.php b/app/Admin/Repositories/MiniProgramTemplate.php index 8883848..b1651b5 100644 --- a/app/Admin/Repositories/MiniProgramTemplate.php +++ b/app/Admin/Repositories/MiniProgramTemplate.php @@ -7,6 +7,7 @@ use Dcat\Admin\Repositories\Repository; use EasyWeChat\Factory; use GuzzleHttp\Exception\GuzzleException; use Illuminate\Pagination\LengthAwarePaginator; +use Illuminate\Support\Facades\Cache; /** * 小程序模板 @@ -15,10 +16,7 @@ use Illuminate\Pagination\LengthAwarePaginator; */ class MiniProgramTemplate extends Repository { - public function getPrimaryKeyColumn() - { - return 'template_id'; - } + protected $keyName = 'template_id'; /** * 查询表格数据 @@ -37,15 +35,21 @@ class MiniProgramTemplate extends Repository 'aes_key' => $setting['service_aeskey'], ]; - $openPlatform = Factory::openPlatform($config); - $codeTemplate = $openPlatform['code_template']; - - if (empty($codeTemplate) || (!$list = $codeTemplate->list())) { - $data['total'] = 0; - $data['subjects'] = []; + $cache_key = 'mini_program:template_list'; + if ($data['subjects'] = Cache::get($cache_key)) { + $data['total'] = count($data['subjects']); } else { - $data['total'] = count($list['template_list']); - $data['subjects'] = $list['template_list'] ?? []; + $openPlatform = Factory::openPlatform($config); + $codeTemplate = $openPlatform['code_template']; + + if (empty($codeTemplate) || (!$list = $codeTemplate->list())) { + $data['total'] = 0; + $data['subjects'] = []; + } else { + $data['total'] = count($list['template_list']); + $data['subjects'] = $list['template_list'] ?? []; + Cache::put($cache_key, $list['template_list'], 120); + } } return $model->makePaginator(