From c8de6e1c625cc596515e78a4baf9e8a5b14e5027 Mon Sep 17 00:00:00 2001 From: "Mr. Shuixiang" Date: Sat, 17 Oct 2020 01:33:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E7=8E=B0=E5=A4=B1=E8=B4=A5=E9=83=A8?= =?UTF-8?q?=E5=88=86=E6=83=85=E5=86=B5=E7=9A=84=E7=9F=AD=E4=BF=A1=E6=8F=90?= =?UTF-8?q?=E9=86=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/v3/Implementations/PaymentService.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/Service/v3/Implementations/PaymentService.php b/app/Service/v3/Implementations/PaymentService.php index c982f4b..a00e7e3 100644 --- a/app/Service/v3/Implementations/PaymentService.php +++ b/app/Service/v3/Implementations/PaymentService.php @@ -169,6 +169,10 @@ class PaymentService implements PaymentServiceInterface $app = Factory::payment($config); $app['guzzle_handler'] = CoroutineHandler::class; + // 特殊原因如资金不够等,发短信给老板或者老总 + $redis = ApplicationContext::getContainer()->get(Redis::class); + $refuseReasonForSpecialKey = 'send_withdraw_refuse_reson_'.date('Ymd'); + $result = $app->transfer->toBalance([ 'partner_trade_no' => $tradeNo, // 商户订单号,需保持唯一性(只能是字母或者数字,不能包含有符号) 'openid' => $openId, @@ -192,9 +196,12 @@ class PaymentService implements PaymentServiceInterface // 如果是商户余额不足等原因,要发送短信给老总 $arr = ['NOTENOUGH','AMOUNT_LIMIT','NO_AUTH']; if (in_array($result['err_code'], $arr)) { - $redis = ApplicationContext::getContainer()->get(Redis::class); - if (!$redis->exists('send_withdraw_refuse_reson_'.date('Ymd'))) { - $this->smsAliSendService->doWithdrawFail($result['err_code'], $result['err_code_des']); + + if (!$redis->exists($refuseReasonForSpecialKey)) { // 当天如果没发过就发 + $res = $this->smsAliSendService->doWithdrawFail($result['err_code'], $result['err_code_des']); + if (isset($res['Code']) && $res['Code'] == 'OK') { + $redis->set($refuseReasonForSpecialKey, $result['err_code'].'/'.$result['err_code_des']); + } } } @@ -223,6 +230,8 @@ class PaymentService implements PaymentServiceInterface throw new ErrorCodeException(ErrorCode::WITHDRAW_PAYMENT_FAIL); } + // 一旦有提现成功的,说明没有特殊原因影响,可能临时解除了,比如临时充钱了,去除标志防止再次缺钱的发生 + $redis->del($refuseReasonForSpecialKey); return true; }