Browse Source

订单退款--修改4

master
liangyuyan 6 years ago
parent
commit
19852115e9
  1. 7
      app/Controller/NotifyPayRefundController.php
  2. 25
      app/JsonRpc/OrderService.php
  3. 82
      app/Service/OrderService.php
  4. 2
      app/Service/PurchaseLimitService.php
  5. 21
      app/Service/WxRefundService.php

7
app/Controller/NotifyPayRefundController.php

@ -1,12 +1,11 @@
<?php
/**
* 本回调用不到 20200826
*/
namespace App\Controller;
use App\Constants\LogLabel;
use App\Model\OrderMain;
use App\Service\OrderServiceInterface;
use App\Service\FinancialRecordServiceInterface;
use EasyWeChat\Factory;

25
app/JsonRpc/OrderService.php

@ -75,20 +75,17 @@ class OrderService implements OrderServiceInterface
"result" => [],
"message" => ''
];
try{
$res = $this->orderService->onlineRefund($global_order_id);
if($res){
$result['code'] = 0;
$result['result'] = $res;
$result['message'] = '退款成功';
}else{
$result['result'] = $res;
$result['message'] = '退款失败';
};
} catch (\Exception $e){
$result['message'] = $e->getMessage();
}
$res = $this->orderService->onlineRefund($global_order_id);
if($res['code'] > 0){
$result['result'] = $res;
$result['message'] = '退款失败';
}else{
$result['code'] = 0;
$result['result'] = $res;
$result['message'] = '退款成功';
};
return $result;
}
}

82
app/Service/OrderService.php

@ -761,14 +761,20 @@ class OrderService implements OrderServiceInterface
if (empty($orderMain)) {
Db::rollBack();
return '查询不到订单';
return [
'code' => 1,
'msg' =>'查询不到订单'
];
}
$orderMain->state = OrderMain::ORDER_STATE_REFUNDED;
if(!$orderMain->save()){
Db::rollBack();
return '更新主订单失败';
return [
'code' => 2,
'msg' =>'更新主订单失败'
];
};
// 子订单状态更新
@ -778,64 +784,68 @@ class OrderService implements OrderServiceInterface
->update(['state' => OrderMain::ORDER_STATE_REFUNDED]);
if(empty($upChild)){
Db::rollBack();
return '更新子订单失败';
return [
'code' => 3,
'msg' =>'更新子订单失败'
];
}
if($orderMain->pay_type == OrderMain::ORDER_PAY_WX){
$data = [
'global_order_id' => $global_order_id,
'money' => $orderMain->money
];
// 微信支付 微信退款
$refundRes = $this->wxRefundService->wxPayRefund($data);
$refundRes = $this->wxRefundService->wxPayRefund($orderMain->global_order_id);
var_dump($refundRes);
if(
empty($refundRes)
|| !$refundRes
|| !isset($refundRes['result_code'])
|| $refundRes['result_code'] != 'SUCCESS'
){
Db::rollBack();
return $refundRes;
};
/* --- 退款成功 --- */
$orderMain = $orderMain->fresh();
if(empty($orderMain->refund_time)){
// 添加退款时间
$orderMain->refund_time = time();
$orderMain->save();
// 退款返还优惠券
$this->couponService->orderRefundCoupons($orderMain->global_order_id);
// 删除特价商品缓存
$this->purchaseLimitService->delSsdbPurchaseRecord($orderMain->id);
// 添加用户的流水
$this->financialService->userByOLOrderRefund($orderMain->user_id, $orderMain->global_order_id, $orderMain->money);
}
}else if($orderMain->pay_type == OrderMain::ORDER_PAY_BALANCE){
// 余额支付 退款到用户余额
// if($this->userService->userWallet($orderMain->user_id,$orderMain->money,Users::WALLET_TYPE_INC)){
// Db::rollBack();
// return false;
// };
if($this->userService->userWallet($orderMain->user_id,$orderMain->money,Users::WALLET_TYPE_INC)){
Db::rollBack();
return [
'code' => 4,
'msg' =>'退款到用户余额失败'
];
};
}
// 返还优惠券
// $this->couponService->orderRefundCoupon($global_order_id);
/* --- 退款成功 --- */
$orderMain = $orderMain->fresh();
if(empty($orderMain->refund_time)){
// 添加退款时间
$orderMain->refund_time = time();
$orderMain->save();
// 退款返还优惠券
$this->couponService->orderRefundCoupons($orderMain->global_order_id);
// 删除特价商品缓存
// $this->orderService->clearTodayGoodPurchase($orderMain->user_id,1);
// 添加用户流水
// $this->financialService->userByOLOrderRefund($orderMain->user_id, $orderMain->global_order_id, $orderMain->money);
$this->purchaseLimitService->delSsdbPurchaseRecord($orderMain->global_order_id);
// 添加用户的流水
$this->financialService->userByOLOrderRefund($orderMain->user_id, $orderMain->global_order_id, $orderMain->money);
}
Db::commit();
return true;
return [
'code' => 0,
'msg' =>'退款成功'
];
} catch (\Exception $e) {
$this->log->event(LogLabel::ORDER_LOG, ['msg'=> '订单退款','exception' => $e->getMessage()]);
Db::rollBack();
return false;
return [
'code' => 5,
'msg' => $e->getMessage()
];
}
}

2
app/Service/PurchaseLimitService.php

@ -52,7 +52,9 @@ class PurchaseLimitService implements PurchaseLimitServiceInterface
$order_main = OrderMain::where('global_order_id',$global_order_id)
->select('id','user_id')
->first();
$order_id = $order_main->id;
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
$order = Order::query()
->where('order_main_id',$order_id)

21
app/Service/WxRefundService.php

@ -27,14 +27,13 @@ class WxRefundService implements WxRefundServiceInterface
$app = Factory::payment($config);
$app['guzzle_handler'] = CoroutineHandler::class;
$orderMain = $global_order_id;
// 查询订单
// $orderMain = OrderMain::query()
// ->select('id','global_order_id','order_num','money','state')
// ->where('global_order_id',$global_order_id)
// ->where('pay_type',OrderMain::ORDER_PAY_WX)
// ->where(Db::raw('refund_time is null'))
// ->first()->toArray();
$orderMain = OrderMain::query()
->select('id','global_order_id','order_num','money','state')
->where('global_order_id',$global_order_id)
->where('pay_type',OrderMain::ORDER_PAY_WX)
->where(Db::raw('refund_time is null'))
->first()->toArray();
if(empty($orderMain)){
return false;
@ -45,10 +44,10 @@ class WxRefundService implements WxRefundServiceInterface
// 'notify_url' => config('site_host') . '/wechat/notify/wxpayrefund'
];
$result = $app->refund->byOutTradeNumber(
$orderMain['global_order_id'],
$orderMain['global_order_id'],
$orderMain['money'] * 100,
$orderMain['money'] * 100,
$orderMain->global_order_id,
$orderMain->global_order_id,
$orderMain->money * 100,
$orderMain->money * 100,
$options
);
$this->log->event(LogLabel::WX_PAY_REFUND,$result);

Loading…
Cancel
Save