feat: 新增充值退款功能完整实现
- 新增充值退款数据库表结构及相关枚举字段 - 新增充值退款服务层核心逻辑(创建、审核、退款、回调处理) - 新增充值退款后台管理页面及操作入口 - 新增充值退款前端页面及样式调整 - 新增充值退款相关测试用例 - 新增充值退款策略校验及网关处理逻辑
这个提交包含在:
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\RechargeRefundService;
|
||||
use think\Db;
|
||||
|
||||
class RechargeRefund extends Backend
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$status = trim((string)$this->request->get('status', ''));
|
||||
$query = Db::name('recharge_refund')->alias('r')
|
||||
->join('pay_order p', 'p.id=r.pay_order_id', 'LEFT')
|
||||
->join('user u', 'u.id=r.user_id', 'LEFT')
|
||||
->field('r.*,p.out_trade_no,u.mobile,u.nickname');
|
||||
if ($status !== '') $query->where('r.status', $status);
|
||||
$list = $query->order('r.id desc')->paginate(20, false, ['query'=>$this->request->get()]);
|
||||
$this->view->assign('list', $list);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
public function create($ids = null)
|
||||
{
|
||||
$pay = Db::name('pay_order')->where('id', (int)$ids)->where('scene', 'recharge')->find();
|
||||
if (!$pay) $this->error('充值订单不存在');
|
||||
if ($this->request->isPost()) {
|
||||
$this->token();
|
||||
try { RechargeRefundService::create((int)$ids, $this->request->post('amount', ''), $this->request->post('reason', ''), $this->auth->id); }
|
||||
catch (\Throwable $e) { $this->error($e->getMessage()); }
|
||||
$this->success('退款申请已提交,余额已占用,等待审核');
|
||||
}
|
||||
$this->view->assign('pay', $pay);
|
||||
$this->view->assign('balance', Db::name('user')->where('id', (int)$pay['user_id'])->value('money'));
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
public function review($ids = null)
|
||||
{
|
||||
$row = Db::name('recharge_refund')->where('id', (int)$ids)->find();
|
||||
if (!$row) $this->error('退款申请不存在');
|
||||
if ($this->request->isPost()) {
|
||||
$this->token();
|
||||
$action = $this->request->post('action', '');
|
||||
try {
|
||||
if ($action === 'reject') {
|
||||
RechargeRefundService::reject((int)$ids, $this->auth->id, $this->request->post('note', ''));
|
||||
$this->success('已驳回并释放余额');
|
||||
}
|
||||
if ($action !== 'approve') throw new \InvalidArgumentException('无效操作');
|
||||
RechargeRefundService::begin((int)$ids, $this->auth->id, $this->request->post('note', ''));
|
||||
} catch (\think\exception\HttpResponseException $e) { throw $e; }
|
||||
catch (\Throwable $e) { $this->error($e->getMessage()); }
|
||||
try { RechargeRefundService::send((int)$ids); }
|
||||
catch (\Throwable $e) { $this->error('申请已审核,微信结果待核实,余额保持占用:' . $e->getMessage()); }
|
||||
$this->success('退款请求已处理,请查看退款状态');
|
||||
}
|
||||
$this->view->assign('row', $row);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
public function resolve($ids = null)
|
||||
{
|
||||
$row = Db::name('recharge_refund')->where('id', (int)$ids)->find();
|
||||
if (!$row) $this->error('退款申请不存在');
|
||||
if ($this->request->isPost()) {
|
||||
$this->token();
|
||||
try {
|
||||
if ($this->request->post('action', '') === 'retry') RechargeRefundService::send((int)$ids);
|
||||
else RechargeRefundService::sync((int)$ids);
|
||||
} catch (\Throwable $e) { $this->error('处理失败,余额保持占用:' . $e->getMessage()); }
|
||||
$this->success('处理完成,请查看退款状态');
|
||||
}
|
||||
$this->view->assign('row', $row);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户