|
|
@ -1,12 +1,11 @@ |
|
|
<?php |
|
|
<?php |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 本回调用不到 20200826 |
|
|
|
|
|
*/ |
|
|
namespace App\Controller; |
|
|
namespace App\Controller; |
|
|
|
|
|
|
|
|
use App\Constants\LogLabel; |
|
|
use App\Constants\LogLabel; |
|
|
|
|
|
|
|
|
use App\Model\OrderMain; |
|
|
use App\Model\OrderMain; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use App\Service\OrderServiceInterface; |
|
|
use App\Service\OrderServiceInterface; |
|
|
use App\Service\FinancialRecordServiceInterface; |
|
|
use App\Service\FinancialRecordServiceInterface; |
|
|
use EasyWeChat\Factory; |
|
|
use EasyWeChat\Factory; |
|
|
@ -15,6 +14,7 @@ use Hyperf\Di\Annotation\Inject; |
|
|
use Hyperf\HttpMessage\Stream\SwooleStream; |
|
|
use Hyperf\HttpMessage\Stream\SwooleStream; |
|
|
use Symfony\Component\HttpFoundation\Request; |
|
|
use Symfony\Component\HttpFoundation\Request; |
|
|
use App\Service\PurchaseLimitServiceInterface; |
|
|
use App\Service\PurchaseLimitServiceInterface; |
|
|
|
|
|
use Hyperf\DbConnection\Db; |
|
|
|
|
|
|
|
|
class NotifyPayRefundController extends BaseController |
|
|
class NotifyPayRefundController extends BaseController |
|
|
{ |
|
|
{ |
|
|
@ -44,6 +44,10 @@ class NotifyPayRefundController extends BaseController |
|
|
*/ |
|
|
*/ |
|
|
public function wxPayRefund() |
|
|
public function wxPayRefund() |
|
|
{ |
|
|
{ |
|
|
|
|
|
$this->log->event( |
|
|
|
|
|
LogLabel::WX_NOTIFY_REFUND, |
|
|
|
|
|
'进入回调' |
|
|
|
|
|
); |
|
|
$config = config('wxpay'); |
|
|
$config = config('wxpay'); |
|
|
$app = Factory::payment($config); |
|
|
$app = Factory::payment($config); |
|
|
$app['guzzle_handler'] = CoroutineHandler::class; |
|
|
$app['guzzle_handler'] = CoroutineHandler::class; |
|
|
@ -59,7 +63,10 @@ class NotifyPayRefundController extends BaseController |
|
|
|
|
|
|
|
|
/* 通知回调,进行业务处理 */ |
|
|
/* 通知回调,进行业务处理 */ |
|
|
$response = $app->handleRefundedNotify(function ($message, $fail) use ($app) { |
|
|
$response = $app->handleRefundedNotify(function ($message, $fail) use ($app) { |
|
|
|
|
|
|
|
|
|
|
|
$this->log->event( |
|
|
|
|
|
LogLabel::WX_NOTIFY_REFUND, |
|
|
|
|
|
$message |
|
|
|
|
|
); |
|
|
try { |
|
|
try { |
|
|
/* --- 退款失败 --- */ |
|
|
/* --- 退款失败 --- */ |
|
|
if ( |
|
|
if ( |
|
|
@ -69,41 +76,47 @@ class NotifyPayRefundController extends BaseController |
|
|
) { |
|
|
) { |
|
|
// 错误日志
|
|
|
// 错误日志
|
|
|
$this->log->event( |
|
|
$this->log->event( |
|
|
LogLabel::PAY_NOTIFY_REFUND, |
|
|
|
|
|
|
|
|
LogLabel::WX_NOTIFY_REFUND, |
|
|
$message |
|
|
$message |
|
|
); |
|
|
); |
|
|
$fail('Unknown error but FAIL'); |
|
|
$fail('Unknown error but FAIL'); |
|
|
|
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* --- 退款成功 --- */ |
|
|
/* --- 退款成功 --- */ |
|
|
$orderMain = OrderMain::select('id','global_order_id','money','user_id') |
|
|
$orderMain = OrderMain::select('id','global_order_id','money','user_id') |
|
|
->where('global_order_id',$message['out_trade_no']) |
|
|
->where('global_order_id',$message['out_trade_no']) |
|
|
->where('state',OrderMain::ORDER_STATE_REFUNDED) |
|
|
->where('state',OrderMain::ORDER_STATE_REFUNDED) |
|
|
|
|
|
->where(Db::raw('refund_time is null')) |
|
|
->first(); |
|
|
->first(); |
|
|
|
|
|
|
|
|
// 退款返还优惠券
|
|
|
|
|
|
$this->couponService->orderRefundCoupon($message['out_trade_no']); |
|
|
|
|
|
|
|
|
if(!empty($orderMain)){ |
|
|
|
|
|
// 添加退款时间
|
|
|
|
|
|
$orderMain->refund_time = time(); |
|
|
|
|
|
$orderMain->save(); |
|
|
|
|
|
|
|
|
|
|
|
// 退款返还优惠券
|
|
|
|
|
|
$this->couponService->orderRefundCoupons($orderMain->global_order_id); |
|
|
|
|
|
|
|
|
// 删除特价商品缓存
|
|
|
|
|
|
$this->purchaseLimitService->delSsdbPurchaseRecord($orderMain->id); |
|
|
|
|
|
|
|
|
// 删除特价商品缓存
|
|
|
|
|
|
$this->purchaseLimitService->delSsdbPurchaseRecord($orderMain->id); |
|
|
|
|
|
|
|
|
// 添加用户的流水
|
|
|
|
|
|
if(!empty($orderMain)){ |
|
|
|
|
|
|
|
|
// 添加用户的流水
|
|
|
$this->financialService->userByOLOrderRefund($orderMain->user_id, $orderMain->global_order_id, $orderMain->money); |
|
|
$this->financialService->userByOLOrderRefund($orderMain->user_id, $orderMain->global_order_id, $orderMain->money); |
|
|
} |
|
|
} |
|
|
} catch (\Exception $e) { |
|
|
} catch (\Exception $e) { |
|
|
|
|
|
|
|
|
$this->log->event( |
|
|
$this->log->event( |
|
|
LogLabel::PAY_NOTIFY_REFUND, |
|
|
|
|
|
|
|
|
LogLabel::WX_NOTIFY_REFUND, |
|
|
['exception_fail' => $e->getMessage()] |
|
|
['exception_fail' => $e->getMessage()] |
|
|
); |
|
|
); |
|
|
$fail('Exception'); |
|
|
$fail('Exception'); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
// return $this->response
|
|
|
|
|
|
// ->withHeader('Content-Type', 'text/xml')
|
|
|
|
|
|
// ->withStatus(200)
|
|
|
|
|
|
// ->withBody(new SwooleStream($response->getContent()));
|
|
|
|
|
|
|
|
|
return $this->response |
|
|
|
|
|
->withHeader('Content-Type', 'text/xml') |
|
|
|
|
|
->withStatus(200) |
|
|
|
|
|
->withBody(new SwooleStream($response->getContent())); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |