You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
<?php
namespace App\Admin\Repositories;use App\Models\AdminSetting;use Dcat\Admin\Grid;use Dcat\Admin\Repositories\Repository;use EasyWeChat\Factory;use GuzzleHttp\Exception\GuzzleException;use Illuminate\Pagination\LengthAwarePaginator;use Illuminate\Support\Facades\Cache;
/** * 小程序模板 * Class MiniProgramDraft * @package App\Admin\Repositories */class MiniProgramTemplate extends Repository{ protected $keyName = 'template_id';
/** * 查询表格数据 * * @param Grid\Model $model * @return LengthAwarePaginator * @throws GuzzleException */ public function get(Grid\Model $model): LengthAwarePaginator { $setting = AdminSetting::val(['service_appid', 'service_appsecret', 'service_token', 'service_aeskey']); $config = [ 'app_id' => $setting['service_appid'], 'secret' => $setting['service_appsecret'], 'token' => $setting['service_token'], 'aes_key' => $setting['service_aeskey'], ];
$cache_key = 'mini_program:template_list'; if ($data['subjects'] = Cache::get($cache_key)) { $data['total'] = count($data['subjects']); } else { $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( $data['total'] ?? 0, // 传入总记录数
$data['subjects'] ?? [] // 传入数据二维数组
); }}
|