diff --git a/app/Constants/v3/ErrorCode.php b/app/Constants/v3/ErrorCode.php index 2529791..0c0a765 100644 --- a/app/Constants/v3/ErrorCode.php +++ b/app/Constants/v3/ErrorCode.php @@ -88,7 +88,7 @@ class ErrorCode extends AbstractConstants /************************************/ /** - * @Message("支付失败") + * @Message("提现支付失败") */ const PAYMENT_FAIL = 651; diff --git a/app/Constants/v3/SmsTemplateCode.php b/app/Constants/v3/SmsTemplateCode.php index e616f83..c8f6769 100644 --- a/app/Constants/v3/SmsTemplateCode.php +++ b/app/Constants/v3/SmsTemplateCode.php @@ -14,4 +14,9 @@ class SmsTemplateCode extends AbstractConstants * @Message("短信验证码") */ const ALI_VERIFY_CODE = 'SMS_201650612'; + + /** + * @Message("社区服务点奖励流水") + */ + const ALI_COMMUNITY_FINANCIAL = 'SMS_200690862'; } \ No newline at end of file diff --git a/app/Controller/v3/WithdrawController.php b/app/Controller/v3/WithdrawController.php index 660ce6f..689c4ae 100644 --- a/app/Controller/v3/WithdrawController.php +++ b/app/Controller/v3/WithdrawController.php @@ -194,7 +194,7 @@ class WithdrawController extends BaseController 'withdraw' => json_encode($withdraw), 'params' => json_encode(['balance' => $balance->balance, 'user_id' => $userId, 'store_id' => $storeId]), ]); - throw new ErrorCodeException(ErrorCode::STORE_WITHDRAW_FAIL, $e->getMessage()); + throw new ErrorCodeException(ErrorCode::STORE_WITHDRAW_FAIL); } } diff --git a/app/Service/v3/Implementations/FinancialRecordService.php b/app/Service/v3/Implementations/FinancialRecordService.php index be47556..d04d4a3 100644 --- a/app/Service/v3/Implementations/FinancialRecordService.php +++ b/app/Service/v3/Implementations/FinancialRecordService.php @@ -4,10 +4,9 @@ namespace App\Service\v3\Implementations; use App\Constants\v3\UserType; use App\Model\v3\FinancialRecord; -use App\Model\v3\Store; use App\Model\v3\UserBalance; use App\Service\v3\Interfaces\FinancialRecordServiceInterface; -use App\Service\v3\Interfaces\SmsServiceInterface; +use App\Service\v3\Interfaces\SmsSendServiceInterface; use Hyperf\Di\Annotation\Inject; class FinancialRecordService implements FinancialRecordServiceInterface @@ -15,9 +14,9 @@ class FinancialRecordService implements FinancialRecordServiceInterface /** * @Inject - * @var SmsServiceInterface + * @var SmsSendServiceInterface */ - protected $smsAliService; + protected $smsAliSendService; public function ledgerAccounts($source_id, $money, $source_type, $money_type, $desc, $comment='') { @@ -87,7 +86,7 @@ class FinancialRecordService implements FinancialRecordServiceInterface $balance->save(); // 发送短信 - $this->smsAliService->sendForCommunityFinancial($user_id, $money); + $this->smsAliSendService->doCommunityFinancial($user_id, $money); } @@ -115,7 +114,7 @@ class FinancialRecordService implements FinancialRecordServiceInterface $balance->save(); // 发送短信 - $this->smsAliService->sendForCommunityFinancial($user_id, $money); + $this->smsAliSendService->doCommunityFinancial($user_id, $money); } /** @@ -142,7 +141,7 @@ class FinancialRecordService implements FinancialRecordServiceInterface $balance->save(); // 发送短信 - $this->smsAliService->sendForCommunityFinancial($user_id, $money); + $this->smsAliSendService->doCommunityFinancial($user_id, $money); } diff --git a/app/Service/v3/Implementations/PaymentService.php b/app/Service/v3/Implementations/PaymentService.php index dff2b8d..f2e37e1 100644 --- a/app/Service/v3/Implementations/PaymentService.php +++ b/app/Service/v3/Implementations/PaymentService.php @@ -13,13 +13,17 @@ use App\Model\v3\OrderMain; use App\Model\v3\User; use App\Service\v3\Interfaces\GoodsActivityServiceInterface; use App\Service\v3\Interfaces\PaymentServiceInterface; +use App\Service\v3\Interfaces\SmsSendServiceInterface; use EasyWeChat\Factory; +use EasyWeChat\Kernel\Exceptions\InvalidArgumentException; use EasyWeChat\Kernel\Exceptions\InvalidConfigException; use EasyWeChat\Kernel\Support\Collection; use GuzzleHttp\Exception\GuzzleException; use Hyperf\DbConnection\Db; use Hyperf\Guzzle\CoroutineHandler; use Hyperf\Di\Annotation\Inject; +use Hyperf\Redis\Redis; +use Hyperf\Utils\ApplicationContext; use Psr\Http\Message\ResponseInterface; use function AlibabaCloud\Client\json; @@ -31,6 +35,11 @@ class PaymentService implements PaymentServiceInterface */ protected $log; + /** + * @var SmsSendServiceInterface + */ + protected $smsAliSendService; + public function do($globalOrderId, $money, $userId, $notifyUrl) { @@ -94,7 +103,7 @@ class PaymentService implements PaymentServiceInterface } /** - * 退款的整单,允许后台操作退款 + * 退款的整单,用户申请的退款 * @param $globalOrderId * @param $userId * @return array|bool|Collection|object|ResponseInterface|string @@ -147,7 +156,10 @@ class PaymentService implements PaymentServiceInterface * @param $userName * @param string $desc * @param string $checkName + * @return bool * @throws GuzzleException + * @throws InvalidConfigException + * @throws InvalidArgumentException */ public function payToWx($money, $tradeNo, $openId, $userName, $desc = '', $checkName = 'NO_CHECK') { @@ -179,7 +191,16 @@ class PaymentService implements PaymentServiceInterface 'result' => json_encode($result), 'desc' => $desc ]); - throw new ErrorCodeException(ErrorCode::PAYMENT_FAIL, $result['err_code_des']); + throw new ErrorCodeException(ErrorCode::PAYMENT_FAIL); + + // 如果是商户余额不足等原因,要发送短信给老总 + $arr = ['NOTENOUGH','AMOUNT_LIMIT']; + if (in_array($result['error_code'], $arr)) { + $redis = ApplicationContext::getContainer()->get(Redis::class); + if (!$redis->exists('send_withdraw_refuse_reson_'.date('Ymd'))) { + $this->smsAliSendService->doWithdrawFail($result['error_code'], $result['error_code_des']); + } + } } return true; diff --git a/app/Service/v3/Implementations/SmsAliSendService.php b/app/Service/v3/Implementations/SmsAliSendService.php index 81929d1..34bc7ea 100644 --- a/app/Service/v3/Implementations/SmsAliSendService.php +++ b/app/Service/v3/Implementations/SmsAliSendService.php @@ -7,6 +7,8 @@ use AlibabaCloud\Client\Exception\ClientException; use AlibabaCloud\Client\Exception\ServerException; use App\Constants\v3\ErrorCode; use App\Exception\ErrorCodeException; +use App\Model\v3\CsInfo; +use App\Model\v3\Market; use Exception; use App\Commons\Log; use App\Constants\v3\SmsTemplateCode; @@ -22,7 +24,7 @@ class SmsAliSendService implements SmsSendServiceInterface */ protected $log; - public function do($tel, $template, $templateParams) + public function do($tel, $template, $templateParams, $signName = '') { try { @@ -41,7 +43,7 @@ class SmsAliSendService implements SmsSendServiceInterface 'query' => [ 'RegionId' => $aliSms['regionid'], 'PhoneNumbers' => $tel, - 'SignName' => $aliSms['sign_name'], + 'SignName' => $signName ?: $aliSms['sign_name'], 'TemplateCode' => $template, 'TemplateParam' => $templateParams, ], @@ -86,4 +88,19 @@ class SmsAliSendService implements SmsSendServiceInterface // TODO: Implement removeVerifyCode() method. } + public function doCommunityFinancial($userId, $money) + { + $csInfo = CsInfo::query()->where(['admin_user_id' => $userId])->first(); + $market = Market::query()->where(['id' => $csInfo->market_id])->first(); + + $params = ['user_name' => $csInfo->name, 'market_name' => $market->name, 'money' => $money]; + return $this->do($csInfo->phone, SmsTemplateCode::ALI_COMMUNITY_FINANCIAL, json_encode($params)); + } + + public function doWithdrawFail($errorCode, $errorCodeDes) + { + $params = ['code' => $errorCode]; + return $this->do(18611745705, SmsTemplateCode::ALI_VERIFY_CODE, json_encode($params)); + } + } \ No newline at end of file diff --git a/app/Service/v3/Implementations/SmsAliService.php b/app/Service/v3/Implementations/SmsAliService.php deleted file mode 100644 index 5bcc7d6..0000000 --- a/app/Service/v3/Implementations/SmsAliService.php +++ /dev/null @@ -1,69 +0,0 @@ -regionId($alisms['regionid']) - ->asDefaultClient(); - - try { - $result = AlibabaCloud::rpc() - ->product($alisms['product']) - // ->scheme('https') // https | http - ->version('2017-05-25') - ->action('SendSms') - ->method('POST') - ->host($alisms['host']) - ->options([ - 'query' => [ - 'RegionId' => $alisms['regionid'], - 'PhoneNumbers' => $phone, - 'SignName' => $signName, - 'TemplateCode' => $template, - 'TemplateParam' => $templateParams, - ], - ]) - ->request(); - return $result->toArray(); - } catch (ClientException $e) { - $this->log->event('alisms', ['alisms_error_ClientException' => $e->getErrorMessage()]); - return false; - } catch (ServerException $e) { - $this->log->event('alisms', ['alisms_error_ServerException' => $e->getErrorMessage()]); - return false; - } - } - - public function sendForCommunityFinancial($userId, $money) - { - - $csInfo = CsInfo::query()->where(['admin_user_id' => $userId])->first(); - $market = Market::query()->where(['id' => $csInfo->market_id])->first(); - - $params = ['user_name' => $csInfo->name, 'market_name' => $market->name, 'money' => $money]; - return $this->send($csInfo->phone, self::TEMPLATE_COMMUNITY_FINANCIAL, json_encode($params)); - } -} \ No newline at end of file diff --git a/app/Service/v3/Interfaces/SmsSendServiceInterface.php b/app/Service/v3/Interfaces/SmsSendServiceInterface.php index d704721..d007aa0 100644 --- a/app/Service/v3/Interfaces/SmsSendServiceInterface.php +++ b/app/Service/v3/Interfaces/SmsSendServiceInterface.php @@ -4,10 +4,12 @@ namespace App\Service\v3\Interfaces; interface SmsSendServiceInterface { - public function do($tel, $template, $templateParams); + public function do($tel, $template, $templateParams, $signName = ''); public function check(); public function undo(); public function doVerifyCode($tel, $code); public function checkVerifyCode($tel, $code); public function undoVerifyCode($tel, $code); + public function doCommunityFinancial($userId, $money); + public function doWithdrawFail($errorCode, $errorCodeDes); } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/SmsServiceInterface.php b/app/Service/v3/Interfaces/SmsServiceInterface.php deleted file mode 100644 index a071c5e..0000000 --- a/app/Service/v3/Interfaces/SmsServiceInterface.php +++ /dev/null @@ -1,9 +0,0 @@ - \App\Service\v3\Implementations\SeparateAccountsService::class, \App\Service\v3\Interfaces\UserServiceInterface::class => \App\Service\v3\Implementations\UserService::class, \App\Service\v3\Interfaces\CouponRebateServiceInterface::class => \App\Service\v3\Implementations\CouponRebateService::class, - \App\Service\v3\Interfaces\SmsServiceInterface::class => \App\Service\v3\Implementations\SmsAliService::class, + \App\Service\v3\Interfaces\SmsSendServiceInterface::class => \App\Service\v3\Implementations\SmsAliSendService::class, \App\Service\v3\Interfaces\AttachmentServiceInterface::class => \App\Service\v3\Implementations\AttachmentService::class, \App\JsonRpc\PrintServiceInterface::class => \App\JsonRpc\FeieService::class, \App\JsonRpc\LocationServiceInterface::class => \App\JsonRpc\LocationService::class,