海南旅游SAAS
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

4 years ago
  1. <?php
  2. namespace App\Admin\Extensions\Grid;
  3. use App\Models\AdminSetting;
  4. use App\Models\MiniProgramTemplateList;
  5. use Dcat\Admin\Grid\RowAction;
  6. use EasyWeChat\Factory;
  7. use Illuminate\Http\Request;
  8. /**
  9. * 上传(注册)小程序
  10. * Class UploadMiniProgram
  11. * @package App\Admin\Extensions\Grid
  12. */
  13. class PullTemplateList extends RowAction
  14. {
  15. protected $title = '更新列表';
  16. protected function html()
  17. {
  18. $this->appendHtmlAttribute('class', 'btn btn-primary');
  19. $this->defaultHtmlAttribute('href', 'javascript:;');
  20. return "<a {$this->formatHtmlAttributes()}>{$this->title}</a>";
  21. }
  22. public function handle(Request $request)
  23. {
  24. try {
  25. $setting = AdminSetting::val(['service_appid', 'service_appsecret', 'service_token', 'service_aeskey']);
  26. $config = [
  27. 'app_id' => $setting['service_appid'],
  28. 'secret' => $setting['service_appsecret'],
  29. 'token' => $setting['service_token'],
  30. 'aes_key' => $setting['service_aeskey'],
  31. ];
  32. $openPlatform = Factory::openPlatform($config);
  33. $codeTemplate = $openPlatform['code_template'];
  34. $list = $codeTemplate->list();
  35. MiniProgramTemplateList::insertOrIgnore($list['template_list']);
  36. //删除不存在的数据
  37. MiniProgramTemplateList::whereNotIn('template_id', array_column($list['template_list'], 'template_id'))->delete();
  38. return $this->response()->success("操作成功")->refresh();
  39. } catch (\Exception $e) {
  40. return $this->response()->error($e->getMessage());
  41. }
  42. }
  43. public function confirm()
  44. {
  45. return ['此操作将数据与腾讯服务器数据同步,是否继续?', ''];
  46. }
  47. }