action = $action; $this->title = $action == 1 ? '上传小程序' : '上传给所有代理商'; } protected function html() { $class = 'btn btn-sm btn-primary'; $this->appendHtmlAttribute('class', $class); $this->defaultHtmlAttribute('href', 'javascript:;'); return "formatHtmlAttributes()}>{$this->title}"; } public function handle(Request $request) { return $request->action == 1 ? $this->uploadOne() : $this->uploadAll(); } //注:uploadOne在代理商列表页使用 private function uploadOne() { $template = MiniProgramTemplate::orderBy('template_id', 'desc')->first(); $agent = Agent::find($this->getKey()); if (empty($agent->appid)) { return $this->response()->error('该代理商未注册过小程序,请先注册'); } try { new UploadMiniProgram($agent, $template); return $this->response()->success("上传成功,并已提交审核")->refresh(); } catch (GuzzleException | \Exception $e) { return $this->response()->error($e->getMessage()); } } //注:uploadAll在小程序模板列表页使用 private function uploadAll() { //上传单个时,$this->getKey()是代理商ID,上传多个时,是小程序模板ID $template_id = $this->getKey(); $ids = Agent::whereNotNull('appid') ->where([ ['status', '=', UserStatus::NORMAL], ['appid', '<>', ''], ])->pluck('id'); foreach ($ids as $id) { BatchUploadMiniProgram::dispatch($template_id, $id); } return $this->response()->success('已经为所有已注册过小程序,且状态正常的代理商上传小程序。上传需要一定时间,请耐心等待'); } public function confirm() { if ($this->action == 1) { $last_template_id = MiniProgramTemplate::max('template_id'); return ["确定要上传模板ID为{$last_template_id}的小程序吗?", '']; } else { return ['上传确认', '确定要将此小程序模板上传给所有已审核的代理商吗?']; } } public function parameters() { return ['action' => $this->action]; } private function auditErrorCode(): array { return [ -1 => '系统繁忙', 86000 => '不是由第三方代小程序进行调用', 86001 => '不存在第三方的已经提交的代码', 85006 => '标签格式错误', 85007 => '页面路径错误', 85008 => '当前小程序没有已经审核通过的类目,请添加类目成功后重试', 85009 => '已经有正在审核的版本', 85010 => 'item_list 有项目为空', 85011 => '标题填写错误', 85023 => '审核列表填写的项目数不在 1-5 以内', 85077 => '小程序类目信息失效(类目中含有官方下架的类目,请重新选择类目)', 86002 => '小程序还未设置昵称、头像、简介。请先设置完后再重新提交', 85085 => '小程序提审数量已达本月上限,请点击查看《临时quota申请流程》', 85086 => '提交代码审核之前需提前上传代码', 85087 => '小程序已使用 api navigateToMiniProgram,请声明跳转 appid 列表后再次提交', 87006 => '小游戏不能提交', 86007 => '小程序禁止提交', 85051 => 'version_desc或者preview_info超限', 85092 => 'preview_info格式错误', 85093 => 'preview_info 视频或者图片个数超限', 85094 => '需提供审核机制说明信息', 86009 => '服务商新增小程序代码提审能力被限制', 86010 => '服务商迭代小程序代码提审能力被限制', 9400001 => '该开发小程序已开通小程序直播权限,不支持发布版本。如需发版,请解绑开发小程序后再操作。', 9402202 => '请勿频繁提交,待上一次操作完成后再提交', ]; } }