- 新增充值退款数据库表结构及相关枚举字段 - 新增充值退款服务层核心逻辑(创建、审核、退款、回调处理) - 新增充值退款后台管理页面及操作入口 - 新增充值退款前端页面及样式调整 - 新增充值退款相关测试用例 - 新增充值退款策略校验及网关处理逻辑
32 行
2.2 KiB
PHP
32 行
2.2 KiB
PHP
<?php
|
|
define('APP_PATH', __DIR__ . '/../server/application/');
|
|
require __DIR__ . '/../server/thinkphp/base.php';
|
|
\think\App::initCommon();
|
|
use app\common\library\RechargeRefundService as Service;
|
|
use think\Db;
|
|
Db::startTrans();
|
|
try {
|
|
Db::name('user')->where('id',1)->update(['money'=>'70.00']);
|
|
$pay = Db::name('pay_order')->insertGetId(['out_trade_no'=>'TEST'.bin2hex(random_bytes(10)), 'order_id'=>0,'order_no'=>'','user_id'=>1,'scene'=>'recharge','openid'=>'TEST','amount'=>'100.00','status'=>'paid']);
|
|
$r = Service::create($pay, '30.00', '退款测试', 1);
|
|
Service::begin($r['id'], 1, '同意');
|
|
$data = ['out_refund_no'=>$r['refund_no'],'refund_id'=>'WXTEST','refund_status'=>'SUCCESS','amount'=>['refund'=>3000,'total'=>10000]];
|
|
Service::applyResult($r['refund_no'], $data);
|
|
Service::applyResult($r['refund_no'], $data);
|
|
$bad = $data; $bad['amount']['refund'] = 1;
|
|
try { Service::applyResult($r['refund_no'], $bad); throw new RuntimeException('终态接受不一致金额'); } catch (InvalidArgumentException $e) {}
|
|
if ((float)Db::name('user')->where('id',1)->value('money') !== 40.0) throw new RuntimeException('退款成功后余额错误');
|
|
if ((float)Db::name('pay_order')->where('id',$pay)->value('refund_amount') !== 30.0) throw new RuntimeException('退款重复入账');
|
|
$r2 = Service::create($pay, '20.00', '退款测试', 1);
|
|
Service::begin($r2['id'], 1, '同意');
|
|
Service::applyResult($r2['refund_no'], ['out_refund_no'=>$r2['refund_no'],'refund_id'=>'WXTEST2','refund_status'=>'ABNORMAL']);
|
|
if ((float)Db::name('user')->where('id',1)->value('money') !== 20.0) throw new RuntimeException('异常退款不得释放余额');
|
|
try { Service::create($pay, '1.00', '重复退款', 1); throw new RuntimeException('异常退款期间允许新申请'); } catch (InvalidArgumentException $e) {}
|
|
$closed = ['out_refund_no'=>$r2['refund_no'],'refund_id'=>'WXTEST2','refund_status'=>'CLOSED'];
|
|
Service::applyResult($r2['refund_no'], $closed);
|
|
Service::applyResult($r2['refund_no'], $closed);
|
|
if ((float)Db::name('user')->where('id',1)->value('money') !== 40.0) throw new RuntimeException('关闭退款未正确释放余额');
|
|
echo "Recharge refund callback passed\n";
|
|
} finally { Db::rollback(); }
|
|
|