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

129 lines
4.4 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <?php
  2. namespace App\Admin\Extensions\Grid;
  3. use App\Common\UserStatus;
  4. use App\Jobs\BatchUploadMiniProgram;
  5. use App\Models\Agent;
  6. use App\Models\MiniProgramTemplate;
  7. use App\Models\MiniProgramUploadLog;
  8. use App\Service\OpenPlatform;
  9. use App\Service\UploadMiniProgram;
  10. use Dcat\Admin\Grid\RowAction;
  11. use EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Code\Client;
  12. use GuzzleHttp\Exception\GuzzleException;
  13. use Illuminate\Http\Request;
  14. use Illuminate\Support\Facades\Redis;
  15. use Illuminate\Support\Facades\Storage;
  16. /**
  17. * 上传(注册)小程序
  18. * Class UploadMiniProgram
  19. * @package App\Admin\Extensions\Grid
  20. */
  21. class MiniProgramUpload extends RowAction
  22. {
  23. private $action;
  24. public function __construct($title = null, $action = 1)
  25. {
  26. parent::__construct($title);
  27. $this->action = $action;
  28. $this->title = $action == 1 ? '上传小程序' : '上传给所有代理商';
  29. }
  30. protected function html()
  31. {
  32. $class = 'btn btn-sm btn-primary';
  33. $this->appendHtmlAttribute('class', $class);
  34. $this->defaultHtmlAttribute('href', 'javascript:;');
  35. return "<a {$this->formatHtmlAttributes()}>{$this->title}</a>";
  36. }
  37. public function handle(Request $request)
  38. {
  39. return $request->action == 1 ? $this->uploadOne() : $this->uploadAll();
  40. }
  41. //注:uploadOne在代理商列表页使用
  42. private function uploadOne()
  43. {
  44. $template = MiniProgramTemplate::orderBy('template_id', 'desc')->first();
  45. $agent = Agent::find($this->getKey());
  46. if (empty($agent->appid)) {
  47. return $this->response()->error('该代理商未注册过小程序,请先注册');
  48. }
  49. try {
  50. new UploadMiniProgram($agent, $template);
  51. return $this->response()->success("上传成功,并已提交审核")->refresh();
  52. } catch (GuzzleException | \Exception $e) {
  53. return $this->response()->error($e->getMessage());
  54. }
  55. }
  56. //注:uploadAll在小程序模板列表页使用
  57. private function uploadAll()
  58. {
  59. //上传单个时,$this->getKey()是代理商ID,上传多个时,是小程序模板ID
  60. $template_id = $this->getKey();
  61. $ids = Agent::whereNotNull('appid')
  62. ->where([
  63. ['status', '=', UserStatus::NORMAL],
  64. ['appid', '<>', ''],
  65. ])->pluck('id');
  66. foreach ($ids as $id) {
  67. BatchUploadMiniProgram::dispatch($template_id, $id);
  68. }
  69. return $this->response()->success('已经为所有已注册过小程序,且状态正常的代理商上传小程序。上传需要一定时间,请耐心等待');
  70. }
  71. public function confirm()
  72. {
  73. if ($this->action == 1) {
  74. $last_template_id = MiniProgramTemplate::max('template_id');
  75. return ["确定要上传模板ID为{$last_template_id}的小程序吗?", ''];
  76. } else {
  77. return ['上传确认', '确定要将此小程序模板上传给所有已审核的代理商吗?'];
  78. }
  79. }
  80. public function parameters()
  81. {
  82. return ['action' => $this->action];
  83. }
  84. private function auditErrorCode(): array
  85. {
  86. return [
  87. -1 => '系统繁忙',
  88. 86000 => '不是由第三方代小程序进行调用',
  89. 86001 => '不存在第三方的已经提交的代码',
  90. 85006 => '标签格式错误',
  91. 85007 => '页面路径错误',
  92. 85008 => '当前小程序没有已经审核通过的类目,请添加类目成功后重试',
  93. 85009 => '已经有正在审核的版本',
  94. 85010 => 'item_list 有项目为空',
  95. 85011 => '标题填写错误',
  96. 85023 => '审核列表填写的项目数不在 1-5 以内',
  97. 85077 => '小程序类目信息失效(类目中含有官方下架的类目,请重新选择类目)',
  98. 86002 => '小程序还未设置昵称、头像、简介。请先设置完后再重新提交',
  99. 85085 => '小程序提审数量已达本月上限,请点击查看《临时quota申请流程》',
  100. 85086 => '提交代码审核之前需提前上传代码',
  101. 85087 => '小程序已使用 api navigateToMiniProgram,请声明跳转 appid 列表后再次提交',
  102. 87006 => '小游戏不能提交',
  103. 86007 => '小程序禁止提交',
  104. 85051 => 'version_desc或者preview_info超限',
  105. 85092 => 'preview_info格式错误',
  106. 85093 => 'preview_info 视频或者图片个数超限',
  107. 85094 => '需提供审核机制说明信息',
  108. 86009 => '服务商新增小程序代码提审能力被限制',
  109. 86010 => '服务商迭代小程序代码提审能力被限制',
  110. 9400001 => '该开发小程序已开通小程序直播权限,不支持发布版本。如需发版,请解绑开发小程序后再操作。',
  111. 9402202 => '请勿频繁提交,待上一次操作完成后再提交',
  112. ];
  113. }
  114. }