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.
56 lines
1.6 KiB
56 lines
1.6 KiB
<?php
|
|
|
|
namespace App\Admin\Extensions\Grid;
|
|
use App\Models\AdminSetting;
|
|
use App\Models\MiniProgramTemplateList;
|
|
use Dcat\Admin\Grid\RowAction;
|
|
use EasyWeChat\Factory;
|
|
use Illuminate\Http\Request;
|
|
|
|
/**
|
|
* 上传(注册)小程序
|
|
* Class UploadMiniProgram
|
|
* @package App\Admin\Extensions\Grid
|
|
*/
|
|
class PullTemplateList extends RowAction
|
|
{
|
|
protected $title = '更新列表';
|
|
|
|
protected function html()
|
|
{
|
|
$this->appendHtmlAttribute('class', 'btn btn-primary');
|
|
$this->defaultHtmlAttribute('href', 'javascript:;');
|
|
|
|
return "<a {$this->formatHtmlAttributes()}>{$this->title}</a>";
|
|
}
|
|
|
|
public function handle(Request $request)
|
|
{
|
|
try {
|
|
$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'],
|
|
];
|
|
|
|
$openPlatform = Factory::openPlatform($config);
|
|
$codeTemplate = $openPlatform['code_template'];
|
|
$list = $codeTemplate->list();
|
|
|
|
MiniProgramTemplateList::insertOrIgnore($list['template_list']);
|
|
//删除不存在的数据
|
|
MiniProgramTemplateList::whereNotIn('template_id', array_column($list['template_list'], 'template_id'))->delete();
|
|
|
|
return $this->response()->success("操作成功")->refresh();
|
|
} catch (\Exception $e) {
|
|
return $this->response()->error($e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function confirm()
|
|
{
|
|
return ['此操作将数据与腾讯服务器数据同步,是否继续?', ''];
|
|
}
|
|
}
|