Commit 40de9a0b authored by 万继龙's avatar 万继龙

Merge branch 'develop' into 'test'

Develop

See merge request bp/pay!12
parents 08e4f4c9 69c9bde1
......@@ -19,13 +19,12 @@ class RefundException extends BaseException
5 => '已核销计算订单不支持退款!',
6 => '退款处理完成,请勿重复申请',
7 => '退款处理中请稍等',
6 => '该退款单核对ping++状态为未支付,请稍后重试!',
8 => '退款消息类型匹配失败,请管理员关注!',
9 => 'ping++退款消息格式错误,请管理员关注!',
10 => 'ping++退单状态异常,请管理员关注!',
11 => 'ping++退单缺少matadata!',
13 => '仅支持自己操作订单退款!',
12 => 'ping++未支付订单不允许退款。',
13 => 'ping++存在多次支付场景,请联系管理员确认。',
];
}
......@@ -47,7 +47,7 @@ class PingxxService
$royalty_users = [];
$ret = OrderRefund::create(
$refundData['charge'],
$refundData['id'],
[
'charge' => $refundData['charge'], //在该订单中,需要退款的 charge 对象 ID,默认全部退款。
'charge_amount' => $refundData['charge_amount'], //charge 退款金额,默认为全额退款。必须和 charge 参数同时使用。单位:分。
......@@ -64,7 +64,8 @@ class PingxxService
// 捕获报错信息
if ($e->getHttpStatus() != null) {
return json_encode($e->getHttpBody(), true);
return json_decode($e->getHttpBody(), true);
} else {
return [
......@@ -92,7 +93,7 @@ class PingxxService
} catch (\Pingpp\Error\Base $e) {
// 捕获报错信息
if ($e->getHttpStatus() != null) {
return json_encode($e->getHttpBody(), true);
return json_decode($e->getHttpBody(), true);
} else {
return [
......@@ -199,7 +200,7 @@ class PingxxService
} catch (\Pingpp\Error\Base $e) {
// 捕获报错信息
if ($e->getHttpStatus() != null) {
return json_encode($e->getHttpBody(), true);
return json_decode($e->getHttpBody(), true);
} else {
return [
......
......@@ -4,6 +4,7 @@
namespace App\Services\refund;
use Api\PhpServices\Idgen\Idgen;
use Api\PhpUtils\Log\FileLog;
use App\Exception\BaseException;
use App\Models\Dictionary;
use App\Models\order\mysql\PayOrder;
......@@ -15,7 +16,6 @@ use App\Services\order\OrderService;
use App\Services\pingxx\PingxxService;
use Helpers\Strategy;
use Helpers\Logger;
use App\Exception\custom\RefundException;
use Yaf\Application;
......@@ -23,8 +23,6 @@ use Yaf\Application;
class RefundService
{
private $refund_order = [];
/**
* @param $order_item_id
* @param $user_id
......@@ -42,7 +40,7 @@ class RefundService
throw new RefundException(['cus' => 2]);
}
if(empty($ret['result']['user_id'] != $user_id)) {
if(empty($ret['result']['user_id']) || $ret['result']['user_id'] != $user_id) {
throw new RefundException(['cus' => 3]);
}
......@@ -57,9 +55,30 @@ class RefundService
$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 = [
'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'],
'metadata' => [
'app_id'=>'merchant-c',
......@@ -193,10 +212,11 @@ class RefundService
$pay_order = PayOrder::getMaster('*', ['order_id'=>$where['order_id']]);
// 总共手续费
$wx_tip = PayOrderClearing::getMaster('*', [
$wx_clear = PayOrderClearing::getMaster('*', [
'order_id'=>$where['order_id'],
'pay_order_id'=>$pay_order['pay_order_id'],
'pay_type'=>Dictionary::PAY_TYPE_IN]
'pay_type'=>406 //三方渠道手续费
]
);
// 计算已退金额、已退手续费
......@@ -210,7 +230,12 @@ class RefundService
$cleared_tip += $r['refund_wx_tip'];
}
$wx_tip = Strategy::getWxTip($order_item['payment'], $pay_order['pay_amount'], $cleared_amount, $wx_tip['pay_amount'], $cleared_tip);
$wx_total_tip = 0;
if($wx_clear) {
$wx_total_tip = $wx_clear['pay_amount'];
}
$wx_tip = Strategy::getWxTip($order_item['payment'], $pay_order['pay_amount'], $cleared_amount, $wx_total_tip, $cleared_tip);
$edit = [
'refund_order_status'=>Dictionary::REFUND_ORDER_STATUS_SEND,
......@@ -221,7 +246,6 @@ class RefundService
if(!$ret) {
throw new RefundException(['cus' => 0]);
}
//重新获取
$refund_order = RefundOrder::getMaster('*', ['refund_order_id'=>$refund_order['refund_order_id']]);
$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