Browse Source

增加审核撤回功能

master
李可松 4 years ago
parent
commit
ee4812ea75
  1. 3
      app/Admin/Controllers/AgentController.php
  2. 66
      app/Admin/Extensions/Grid/MiniProgramAuditStatus.php
  3. 2
      app/Admin/Extensions/Grid/MiniProgramUpload.php

3
app/Admin/Controllers/AgentController.php

@ -78,7 +78,8 @@ class AgentController extends AdminController
} else if ($is_success === 0 && $template_id === $last_template_id) {
$column->append("已发布(模板:{$template_id})");
} else if (in_array($is_success, [-1, 2, 4])) { //如果状态是-1未检查过,或2审核中,或4审核延后,则显示审核状态按钮
$column->append((new MiniProgramAuditStatus(null, 1))->setKey($this->id));
$column->append((new MiniProgramAuditStatus(null, 1))->setKey($this->id))->append(' ');
$column->append((new MiniProgramAuditStatus(null, 2))->setKey($this->id));
} else {
$column->append((new MiniProgramUpload(null, 1))->setKey($this->id));
$statusArr = [0 => '审核成功', 1 => '审核被拒绝', 2 => '审核中', 3 => '已撤回', 4 => '审核延后'];

66
app/Admin/Extensions/Grid/MiniProgramAuditStatus.php

@ -23,8 +23,8 @@ class MiniProgramAuditStatus extends RowAction
public function __construct($title = null, $action = 1)
{
parent::__construct($title);
$this->action = $action; //$action:1=通过;2=拒绝
$this->title = $action == 1 ? '审核状态' : '拒绝';
$this->action = $action;
$this->title = $action == 1 ? '审核状态' : '审核撤销';
}
protected function html()
@ -36,14 +36,18 @@ class MiniProgramAuditStatus extends RowAction
return "<a {$this->formatHtmlAttributes()}>{$this->title}</a>";
}
public function handle(Request $request)
public function handle()
{
return $this->action == 1 ? $this->auditStatus() : $this->undoAudit();
}
private function auditStatus()
{
$agent = Agent::find($this->getKey());
if (empty($agent->appid)) {
return $this->response()->error('该代理商未注册过小程序,请先注册');
}
// $template_id = MiniProgramTemplate::max('template_id');
$log = MiniProgramUploadLog::where(['agent_id' => $agent->id])->orderBy('id', 'desc')->first();
if (!$log) {
return $this->response()->error('该代理商未上传及发布过最新版本的小程序');
@ -95,6 +99,60 @@ class MiniProgramAuditStatus extends RowAction
}
}
private function undoAudit()
{
$agent = Agent::find($this->getKey());
if (empty($agent->appid)) {
return $this->response()->error('该代理商未注册过小程序,请先注册');
}
$log = MiniProgramUploadLog::where(['agent_id' => $agent->id])->orderBy('id', 'desc')->first();
if (!$log) {
return $this->response()->error('该代理商未上传及发布过最新版本的小程序');
} else if (!$log->audit_id) {
return $this->response()->error('未找到审核记录audit_id');
}
try {
$openPlatform = new OpenPlatform();
$refreshToken = $openPlatform->refreshToken($agent->appid);
if (!$refreshToken) {
return $this->response()->error('获取refresh_token失败');
}
/** @var Client $code */
$code = $openPlatform->code($agent->appid, $refreshToken);
if (!$code) {
return $this->response()->error('获取code失败');
}
$res = $code->withdrawAudit();
if (isset($res['errcode'], $res['errmsg']) && $res['errcode'] == 0 && $res['errmsg'] == 'ok') {
//保存审核状态为已撤回
$log->is_success = 3;
$log->save();
return $this->response()->success("撤回最后审核单成功")->refresh();
} else if (isset($res['errcode']) && $res['errcode'] != 0) {
$error = [
-1 => '腾讯内部系统错误',
87013 => '撤回次数达到上限(每天5次,每个月 10 次)',
];
return $this->response()->error(isset($error[$res['errcode']]) ? $error[$res['errcode']] : ($res['errmsg'] ?? join(',', $res)));
} else {
return $this->response()->error($res['errmsg'] ?? join(',', $res));
}
} catch (InvalidConfigException | GuzzleException | \Exception $e) {
return $this->response()->error($e->getMessage());
}
}
public function confirm()
{
if ($this->action == 2) {
return ['撤回次数每天最多5次,每个月最多10次,是否继续?', ''];
}
}
public function parameters()
{
return ['action' => $this->action];

2
app/Admin/Extensions/Grid/MiniProgramUpload.php

@ -135,7 +135,7 @@ class MiniProgramUpload extends RowAction
//注:uploadAll在小程序模板列表页使用
private function uploadAll()
{
return true;
}
public function confirm()

Loading…
Cancel
Save