Commit 69c9bde1 authored by wanjilong's avatar wanjilong

add: 增加多次支付异常报警逻辑

parent 18043c63
...@@ -19,13 +19,12 @@ class RefundException extends BaseException ...@@ -19,13 +19,12 @@ class RefundException extends BaseException
5 => '已核销计算订单不支持退款!', 5 => '已核销计算订单不支持退款!',
6 => '退款处理完成,请勿重复申请', 6 => '退款处理完成,请勿重复申请',
7 => '退款处理中请稍等', 7 => '退款处理中请稍等',
6 => '该退款单核对ping++状态为未支付,请稍后重试!',
8 => '退款消息类型匹配失败,请管理员关注!', 8 => '退款消息类型匹配失败,请管理员关注!',
9 => 'ping++退款消息格式错误,请管理员关注!', 9 => 'ping++退款消息格式错误,请管理员关注!',
10 => 'ping++退单状态异常,请管理员关注!', 10 => 'ping++退单状态异常,请管理员关注!',
11 => 'ping++退单缺少matadata!', 11 => 'ping++退单缺少matadata!',
12 => 'ping++未支付订单不允许退款。',
13 => '仅支持自己操作订单退款!', 13 => 'ping++存在多次支付场景,请联系管理员确认。',
]; ];
} }
...@@ -47,7 +47,7 @@ class PingxxService ...@@ -47,7 +47,7 @@ class PingxxService
$royalty_users = []; $royalty_users = [];
$ret = OrderRefund::create( $ret = OrderRefund::create(
$refundData['charge'], $refundData['id'],
[ [
'charge' => $refundData['charge'], //在该订单中,需要退款的 charge 对象 ID,默认全部退款。 'charge' => $refundData['charge'], //在该订单中,需要退款的 charge 对象 ID,默认全部退款。
'charge_amount' => $refundData['charge_amount'], //charge 退款金额,默认为全额退款。必须和 charge 参数同时使用。单位:分。 'charge_amount' => $refundData['charge_amount'], //charge 退款金额,默认为全额退款。必须和 charge 参数同时使用。单位:分。
...@@ -64,7 +64,8 @@ class PingxxService ...@@ -64,7 +64,8 @@ class PingxxService
// 捕获报错信息 // 捕获报错信息
if ($e->getHttpStatus() != null) { if ($e->getHttpStatus() != null) {
return json_encode($e->getHttpBody(), true);
return json_decode($e->getHttpBody(), true);
} else { } else {
return [ return [
...@@ -92,7 +93,7 @@ class PingxxService ...@@ -92,7 +93,7 @@ class PingxxService
} catch (\Pingpp\Error\Base $e) { } catch (\Pingpp\Error\Base $e) {
// 捕获报错信息 // 捕获报错信息
if ($e->getHttpStatus() != null) { if ($e->getHttpStatus() != null) {
return json_encode($e->getHttpBody(), true); return json_decode($e->getHttpBody(), true);
} else { } else {
return [ return [
...@@ -199,7 +200,7 @@ class PingxxService ...@@ -199,7 +200,7 @@ class PingxxService
} catch (\Pingpp\Error\Base $e) { } catch (\Pingpp\Error\Base $e) {
// 捕获报错信息 // 捕获报错信息
if ($e->getHttpStatus() != null) { if ($e->getHttpStatus() != null) {
return json_encode($e->getHttpBody(), true); return json_decode($e->getHttpBody(), true);
} else { } else {
return [ return [
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
namespace App\Services\refund; namespace App\Services\refund;
use Api\PhpServices\Idgen\Idgen; use Api\PhpServices\Idgen\Idgen;
use Api\PhpUtils\Log\FileLog;
use App\Exception\BaseException; use App\Exception\BaseException;
use App\Models\Dictionary; use App\Models\Dictionary;
use App\Models\order\mysql\PayOrder; use App\Models\order\mysql\PayOrder;
...@@ -15,7 +16,6 @@ use App\Services\order\OrderService; ...@@ -15,7 +16,6 @@ use App\Services\order\OrderService;
use App\Services\pingxx\PingxxService; use App\Services\pingxx\PingxxService;
use Helpers\Strategy; use Helpers\Strategy;
use Helpers\Logger;
use App\Exception\custom\RefundException; use App\Exception\custom\RefundException;
use Yaf\Application; use Yaf\Application;
...@@ -23,8 +23,6 @@ use Yaf\Application; ...@@ -23,8 +23,6 @@ use Yaf\Application;
class RefundService class RefundService
{ {
private $refund_order = [];
/** /**
* @param $order_item_id * @param $order_item_id
* @param $user_id * @param $user_id
...@@ -57,9 +55,30 @@ class RefundService ...@@ -57,9 +55,30 @@ class RefundService
$data = $this->can_refund($where, $order_item); $data = $this->can_refund($where, $order_item);
/*
https://www.pingxx.com/api/%E8%AE%A2%E5%8D%95%20Refunds%20%E9%80%80%E6%AC%BE%E6%A6%82%E8%BF%B0.html
订单退款 paid = true, status = canceled, amount_paid > 0 则表明可以退款
amount_paid 大于 actual_amount 需要最后一单全退。
具体见ping++ 文档
*/
$pay = PingxxService::getInstance()->getOrder($data['pay_order']['third_order_id']);
if(empty($pay['paid']) || $pay['paid'] != true) {
throw new RefundException(['cus' => 12]);
}
// 存在多次支付的场景需要人工介入处理, 修复订单支付金额,退款金额
if($pay['amount_paid'] > $pay['actual_amount']) {
FileLog::error('pay-service: 订单存在多次支付成功,需人工处理。', json_encode($pay, JSON_UNESCAPED_UNICODE));
throw new RefundException(['cus' => 13]);
}
// 构造退款数据 // 构造退款数据
$refund = [ $refund = [
'charge'=>$data['pay_order']['third_order_id'], 'id'=>$pay['id'], //pingxx订单ID
'charge'=>$pay['charge'], //pingxx 支付订单ID
'refund_mode' => 'to_source', //默认返回
'charge_amount'=>$data['refund_order']['refund_amount'], 'charge_amount'=>$data['refund_order']['refund_amount'],
'metadata' => [ 'metadata' => [
'app_id'=>'merchant-c', 'app_id'=>'merchant-c',
...@@ -227,7 +246,6 @@ class RefundService ...@@ -227,7 +246,6 @@ class RefundService
if(!$ret) { if(!$ret) {
throw new RefundException(['cus' => 0]); throw new RefundException(['cus' => 0]);
} }
//重新获取 //重新获取
$refund_order = RefundOrder::getMaster('*', ['refund_order_id'=>$refund_order['refund_order_id']]); $refund_order = RefundOrder::getMaster('*', ['refund_order_id'=>$refund_order['refund_order_id']]);
$data = [ $data = [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment