- 新增充值退款数据库表结构及相关枚举字段 - 新增充值退款服务层核心逻辑(创建、审核、退款、回调处理) - 新增充值退款后台管理页面及操作入口 - 新增充值退款前端页面及样式调整 - 新增充值退款相关测试用例 - 新增充值退款策略校验及网关处理逻辑
34 行
2.2 KiB
PHP
34 行
2.2 KiB
PHP
<?php
|
|
namespace app\common\library {
|
|
class WxPayV3Service {
|
|
public static $calls = 0;
|
|
public function refund(array $params) {
|
|
self::$calls++;
|
|
if (self::$calls === 1) throw new \RuntimeException('TIMEOUT');
|
|
return ['out_refund_no'=>$params['out_refund_no'], 'refund_id'=>'WX-TEST', 'status'=>'SUCCESS', 'amount'=>['refund'=>(int)round((float)$params['refund_amount']*100), 'total'=>(int)round((float)$params['total_amount']*100)]];
|
|
}
|
|
public function queryRefundByOutRefundNo($no) { throw new \RuntimeException('RESOURCE_NOT_EXISTS'); }
|
|
public static function extractFailInfo($e) { return ['code'=>$e->getMessage(), 'reason'=>$e->getMessage()]; }
|
|
}
|
|
}
|
|
namespace {
|
|
define('APP_PATH', __DIR__ . '/../server/application/');
|
|
require __DIR__ . '/../server/thinkphp/base.php';
|
|
\think\App::initCommon();
|
|
\think\Db::startTrans();
|
|
try {
|
|
\think\Db::name('user')->where('id',1)->update(['money'=>'50.00']);
|
|
$id=\think\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=\app\common\library\RechargeRefundService::create($id,'20.00','客服退款',1);
|
|
\app\common\library\RechargeRefundService::begin($r['id'],1,'同意');
|
|
try { \app\common\library\RechargeRefundService::send($r['id']); throw new \Exception('Expected timeout'); }
|
|
catch (\RuntimeException $e) { if ($e->getMessage() !== 'TIMEOUT') throw $e; }
|
|
$row=\think\Db::name('recharge_refund')->where('id',$r['id'])->find();
|
|
if ($row['status'] !== 'unknown' || (float)\think\Db::name('user')->where('id',1)->value('money') !== 30.0) throw new \Exception('Timeout failed to preserve reservation');
|
|
\app\common\library\RechargeRefundService::send($r['id']);
|
|
$row=\think\Db::name('recharge_refund')->where('id',$r['id'])->find();
|
|
if ($row['status'] !== 'success' || (float)\think\Db::name('pay_order')->where('id',$id)->value('refund_amount') !== 20.0) throw new \Exception('Retry failed');
|
|
echo "Recharge gateway timeout and retry passed\n";
|
|
} finally { \think\Db::rollback(); }
|
|
}
|