Browse Source

缓存

develop
李可松 5 years ago
parent
commit
a689eedc9f
  1. 28
      app/Admin/Repositories/MiniProgramDraft.php
  2. 28
      app/Admin/Repositories/MiniProgramList.php
  3. 28
      app/Admin/Repositories/MiniProgramTemplate.php

28
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(

28
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(

28
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(

Loading…
Cancel
Save