Browse Source

Merge branch 'phoenix' of http://120.24.33.109:11081/hyzjshwo/lanzu_api_hyperf into phoenix

master
Lemon 5 years ago
parent
commit
63c0dc10f0
  1. 96
      app/JsonRpc/OrderService.php
  2. 8
      app/Service/v3/Implementations/PaymentService.php

96
app/JsonRpc/OrderService.php

@ -69,7 +69,12 @@ class OrderService implements OrderServiceInterface
Db::rollBack();
$this->log->event(LogLabel::ORDER_COMPLETE_LOG, ['jsonrpc_order_service_exception_onlineComplete' => $e->getMessage(), 'params' => json([$global_order_id, $user_id])]);
throw new ErrorCodeException(ErrorCode::ORDER_COMPLETE_FAIL);
return [
"status" => 200,
"code" => $e->getCode() ?? ErrorCode::ORDER_COMPLETE_FAIL,
"result" => [],
"message" => $e->getMessage()
];
}
}
@ -82,33 +87,22 @@ class OrderService implements OrderServiceInterface
*/
public function onlineRefund($global_order_id, $user_id)
{
Db::beginTransaction();
try {
$result = $this->orderOnlineService->doRefund($global_order_id, $user_id);
Db::commit();
if ($result['return_code'] == 'SUCCESS' && isset($result['result_code']) && $result['result_code'] == "SUCCESS") {
$this->orderOnlineService->doRefund($global_order_id, $user_id);
return [
"status" => 200,
"code" => 0,
"result" => [],
"message" => '处理成功'
];
} else {
} catch (\Exception $e) {
return [
"status" => 200,
"code" => -1,
"code" => $e->getCode(),
"result" => [],
"message" => $result['err_code_des']
"message" => $e->getMessage()
];
}
} catch (\Exception $e) {
Db::rollBack();
$this->log->event(LogLabel::ORDER_REFUND_LOG, ['jsonrpc_order_service_exception_onlineRefund' => $e->getMessage(), 'params' => json([$global_order_id, $user_id])]);
throw new ErrorCodeException(ErrorCode::ORDER_REFUND_FAIL);
}
}
@ -130,6 +124,9 @@ class OrderService implements OrderServiceInterface
public function onlineSingleRefund($user_id, $note, $global_order_id, $order_child_id=null, $order_goods_id=null)
{
Db::beginTransaction();
try {
$params = [
'user_id' => $user_id,
'note' => $note,
@ -189,19 +186,20 @@ class OrderService implements OrderServiceInterface
}
var_dump('ordergoods', $orderGoods);
$totalAmount = $orderMain->total_money; // 订单可退款金额,总订单金额不含配送费和服务费
$preRefundAmount = 0; // 预退款金额
$refundAmount = 0; // 实际退款金额
$refundType = 'Main'; // 退款类型, Main整单 Sub子单 Goods单品
$refundType = 'main'; // 退款类型, Main整单 Sub子单 Goods单品
if ($orderGoods) { // 1. 如果订单商品存在则说明要退单品
$preRefundAmount = bcmul($orderGoods->price, $orderGoods->number, 2);
$refundType = 'Goods';
$refundType = 'goods';
} elseif ($orderChild) { // 2. 否则如果存在子订单说明退子订单
$preRefundAmount = $orderChild->money;
$refundType = 'Sub';
$refundType = 'sub';
} else { // 3. 再则如果存在主订单说明退主订单
$preRefundAmount = $orderMain->total_money;
$refundType = 'Main';
$refundType = 'main';
}
// 占订单金额的比例
@ -219,6 +217,8 @@ class OrderService implements OrderServiceInterface
throw new ErrorCodeException(ErrorCode::ORDER_REFUND_FAIL);
}
var_dump($orderMain->money, $preRefundAmount, $refundAmount);
// 开始退款
$config = config('wxpay');
$app = Factory::payment($config);
@ -229,14 +229,14 @@ class OrderService implements OrderServiceInterface
bcmul($orderMain->money, 100, 0),
bcmul($refundAmount, 100, 0),
[
'refund_desc' => '订单协商退款['.$refundType.']',
'refund_desc' => '订单协商退款[' . $refundType . ']',
'notify_url' => config('wechat.notify_url.refund_single'),
]
);
if ($result['return_code'] == 'FAIL') {
$this->log->event(LogLabel::ORDER_REFUND_LOG, [
'jsonrpc_order_service_exception_onlineSingleRefund' => $result['return_msg'].'[微信退款失败]',
'jsonrpc_order_service_exception_onlineSingleRefund' => $result['return_msg'] . '[微信退款失败]',
'params' => json_encode($result)
]);
throw new ErrorCodeException(ErrorCode::ORDER_REFUND_FAIL);
@ -244,18 +244,66 @@ class OrderService implements OrderServiceInterface
if ($result['result_code'] == 'FAIL') {
$this->log->event(LogLabel::ORDER_REFUND_LOG, [
'jsonrpc_order_service_exception_onlineSingleRefund' => $result['err_code_des'].'[微信退款失败]'.$result['err_code'],
'jsonrpc_order_service_exception_onlineSingleRefund' => $result['err_code_des'] . '[微信退款失败]' . $result['err_code'],
'params' => json_encode($result)
]);
throw new ErrorCodeException(ErrorCode::ORDER_REFUND_FAIL);
}
// 退款申请成功,查询退款状态
// 退款申请成功,查询退款状态,此处暂时无法传递和记录单品退的信息,所以直接查询退款状态处理,不做回调
$refundResult = $app->refund->queryByRefundId($result['refund_id']);
$this->log->event(LogLabel::ORDER_REFUND_LOG, [
'jsonrpc_order_service_exception_onlineSingleRefund' => '[微信退款查询]',
'params' => json_encode($refundResult)
]);
// 退款成功
if (
!($refundResult['return_code'] == 'SUCCESS'
&& isset($refundResult['result_code'])
&& $refundResult['result_code'] == 'SUCCESS')
) {
throw new ErrorCodeException(ErrorCode::ORDER_REFUND_FAIL);
}
$currentTime = time();
// 处理订单状态
$orderMain->state = OrderState::REFUNDED;
$orderMain->total_refund_note = $note;
$orderMain->refund_time = $currentTime;
$orderMain->save();
if ($refundType == 'sub') {
$orderChild->status = 3;
$orderChild->refund_note = $note;
$orderChild->refund_time = $currentTime;
$orderChild->save();
}
if ($refundType == 'goods') {
$orderGoods->status = 3;
$orderGoods->refund_note = $note;
$orderGoods->refund_time = $currentTime;
$orderGoods->save();
}
Db::commit();
return [
"status" => 200,
"code" => 0,
"result" => [],
"message" => '处理成功'
];
} catch (\Exception $e) {
Db::rollBack();
return [
"status" => 200,
"code" => $e->getCode(),
"result" => [],
"message" => '[退款失败]'.$e->getMessage()
];
}
}
}

8
app/Service/v3/Implementations/PaymentService.php

@ -127,6 +127,14 @@ class PaymentService implements PaymentServiceInterface
'notify_url' => config('wechat.notify_url.refund'),
]
);
if ($result['return_code'] == 'SUCCESS' && isset($result['result_code']) && $result['result_code'] == "SUCCESS") {
return true;
} else {
throw new ErrorCodeException(ErrorCode::PAYMENT_FAIL);
}
return $result;
} catch (\Exception $e) {
$this->log->event(LogLabel::ORDER_PAYMENT_LOG, ['payment_do_exception_msg' => $e->getMessage()]);

Loading…
Cancel
Save