海南旅游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.4 KiB

  1. <?php
  2. namespace App\Admin\Repositories;
  3. use App\Models\AdminSetting;
  4. use Dcat\Admin\Grid;
  5. use Dcat\Admin\Repositories\Repository;
  6. use EasyWeChat\Factory;
  7. use GuzzleHttp\Exception\GuzzleException;
  8. use Illuminate\Pagination\LengthAwarePaginator;
  9. /**
  10. * 小程序草稿箱
  11. * Class MiniProgramDraft
  12. * @package App\Admin\Repositories
  13. */
  14. class MiniProgramList extends Repository
  15. {
  16. public function getPrimaryKeyColumn()
  17. {
  18. return '';
  19. }
  20. /**
  21. * 查询表格数据
  22. *
  23. * @param Grid\Model $model
  24. * @return LengthAwarePaginator
  25. * @throws GuzzleException
  26. */
  27. public function get(Grid\Model $model): LengthAwarePaginator
  28. {
  29. $setting = AdminSetting::val(['service_appid', 'service_appsecret', 'service_token', 'service_aeskey']);
  30. $config = [
  31. 'app_id' => $setting['service_appid'],
  32. 'secret' => $setting['service_appsecret'],
  33. 'token' => $setting['service_token'],
  34. 'aes_key' => $setting['service_aeskey'],
  35. ];
  36. $openPlatform = Factory::openPlatform($config);
  37. $codeTemplate = $openPlatform['code_template'];
  38. if (empty($codeTemplate) || (!$list = $openPlatform->getAuthorizers())) {
  39. $data['total'] = 0;
  40. $data['subjects'] = [];
  41. } else {
  42. $data['total'] = count($list['list']);
  43. $data['subjects'] = $list['list'] ?? [];
  44. }
  45. return $model->makePaginator(
  46. $data['total'] ?? 0, // 传入总记录数
  47. $data['subjects'] ?? [] // 传入数据二维数组
  48. );
  49. }
  50. }