Browse Source

订单退款--修改删除特价商品缓存

master
liangyuyan 6 years ago
parent
commit
18de7a139d
  1. 19
      app/Controller/NotifyPayRefundController.php
  2. 2
      app/Service/CouponService.php
  3. 18
      app/Service/OrderService.php
  4. 17
      app/Service/WxRefundService.php
  5. 1
      config/autoload/dependencies.php
  6. 1
      config/routes.php

19
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()));
}
}

2
app/Service/CouponService.php

@ -19,7 +19,7 @@ use Hyperf\Redis\Redis;
class CouponService implements CouponServiceInterface
{
/**
/**
* @Inject
* @var Log
*/

18
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);
}
}

17
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;
}

1
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,
];

1
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');
});
Loading…
Cancel
Save