From 18de7a139d61cf797f3ef1fb733a5dbb8a29ac35 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Wed, 26 Aug 2020 10:21:27 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E9=80=80=E6=AC=BE--=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=88=A0=E9=99=A4=E7=89=B9=E4=BB=B7=E5=95=86=E5=93=81?= =?UTF-8?q?=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/NotifyPayRefundController.php | 19 +++++++++++++------ app/Service/CouponService.php | 2 +- app/Service/OrderService.php | 18 +++++++++--------- app/Service/WxRefundService.php | 17 +++++++++++++++-- config/autoload/dependencies.php | 1 + config/routes.php | 1 + 6 files changed, 40 insertions(+), 18 deletions(-) diff --git a/app/Controller/NotifyPayRefundController.php b/app/Controller/NotifyPayRefundController.php index 18176c6..24c12b1 100644 --- a/app/Controller/NotifyPayRefundController.php +++ b/app/Controller/NotifyPayRefundController.php @@ -14,6 +14,7 @@ use Hyperf\Guzzle\CoroutineHandler; use Hyperf\Di\Annotation\Inject; use Hyperf\HttpMessage\Stream\SwooleStream; use Symfony\Component\HttpFoundation\Request; +use App\Service\PurchaseLimitServiceInterface; class NotifyPayRefundController extends BaseController { @@ -32,6 +33,12 @@ class NotifyPayRefundController extends BaseController */ protected $orderService; + /** + * @Inject + * @var PurchaseLimitServiceInterface + */ + protected $purchaseLimitService; + /** * 微信退款回调 */ @@ -73,12 +80,12 @@ class NotifyPayRefundController extends BaseController ->where('global_order_id',$message['out_trade_no']) ->where('state',OrderMain::ORDER_STATE_REFUNDED) ->first(); - + // 退款返还优惠券 $this->couponService->orderRefundCoupon($message['out_trade_no']); // 删除特价商品缓存 - $this->orderService->clearTodayGoodPurchase($orderMain->user_id,1); + $this->purchaseLimitService->delSsdbPurchaseRecord($orderMain->id); // 添加用户的流水 if(!empty($orderMain)){ @@ -94,9 +101,9 @@ class NotifyPayRefundController extends BaseController } }); - 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())); } } \ No newline at end of file diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index 5efe903..d6a2d9f 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -19,7 +19,7 @@ use Hyperf\Redis\Redis; class CouponService implements CouponServiceInterface { - /** + /** * @Inject * @var Log */ diff --git a/app/Service/OrderService.php b/app/Service/OrderService.php index 8bb7dec..57aadf3 100644 --- a/app/Service/OrderService.php +++ b/app/Service/OrderService.php @@ -776,23 +776,23 @@ class OrderService implements OrderServiceInterface if($orderMain->pay_type == OrderMain::ORDER_PAY_WX){ // 微信支付 微信退款 - if($this->wxRefundService->wxPayRefund($global_order_id)){ + if(!$this->wxRefundService->wxPayRefund($global_order_id)){ Db::rollBack(); return false; }; }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 false; + // }; // 返还优惠券 - $this->couponService->orderRefundCoupon($global_order_id); + // $this->couponService->orderRefundCoupon($global_order_id); // 删除特价商品缓存 - $this->orderService->clearTodayGoodPurchase($orderMain->user_id,1); + // $this->orderService->clearTodayGoodPurchase($orderMain->user_id,1); // 添加用户流水 - $this->financialService->userByOLOrderRefund($orderMain->user_id, $orderMain->global_order_id, $orderMain->money); + // $this->financialService->userByOLOrderRefund($orderMain->user_id, $orderMain->global_order_id, $orderMain->money); } Db::commit(); @@ -855,6 +855,6 @@ class OrderService implements OrderServiceInterface public function clearTodayGoodPurchase($userId, $goodId) { $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); - return $ssdb->exec('hdel', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$userId, $goodId); + return $ssdb->exec('del', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$userId, $goodId); } } \ No newline at end of file diff --git a/app/Service/WxRefundService.php b/app/Service/WxRefundService.php index bcd4a9c..4ab53e2 100644 --- a/app/Service/WxRefundService.php +++ b/app/Service/WxRefundService.php @@ -6,9 +6,16 @@ use App\Model\OrderMain; use EasyWeChat\Factory; use Hyperf\DbConnection\Db; use App\Constants\ErrorCode; +use App\Commons\Log; class WxRefundService implements WxRefundServiceInterface { + /** + * @Inject + * @var Log + */ + protected $log; + /** * 微信支付退款 */ @@ -28,13 +35,19 @@ class WxRefundService implements WxRefundServiceInterface if(empty($orderMain)){ return false; }; + $options = [ + 'refund_desc' => '', + '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->money * 100, + $options ); - + + $this->log->event('wx_pay_refund',$result); return $result; } diff --git a/config/autoload/dependencies.php b/config/autoload/dependencies.php index 31e22ac..6eacba0 100644 --- a/config/autoload/dependencies.php +++ b/config/autoload/dependencies.php @@ -32,4 +32,5 @@ return [ \App\Service\FinancialRecordServiceInterface::class => \App\Service\FinancialRecordService::class, \App\Service\SeparateAccountsServiceInterface::class => \App\Service\SeparateAccountsService::class, \App\Service\ShopCarServiceInterface::class => \App\Service\ShopCarService::class, + \App\Service\WxRefundServiceInterface::class => \App\Service\WxRefundService::class, ]; diff --git a/config/routes.php b/config/routes.php index 2d0ef16..2a208a7 100644 --- a/config/routes.php +++ b/config/routes.php @@ -69,4 +69,5 @@ Router::addGroup('/v1/',function (){ Router::addGroup('/wechat/',function () { Router::post('notify/wxminionline', 'App\Controller\NotifyController@wxminiOnline'); Router::post('notify/wxminioffline', 'App\Controller\NotifyController@wxminiOffline'); + Router::post('notify/wxpayrefund', 'App\Controller\NotifyPayRefundController@wxPayRefund'); }); \ No newline at end of file