diff --git a/app/Model/AdminUser.php b/app/Model/AdminUser.php new file mode 100644 index 0000000..d2ed2b6 --- /dev/null +++ b/app/Model/AdminUser.php @@ -0,0 +1,29 @@ +balance = bcadd($balance->balance, $money, 2); $balance->save(); + + // 发送短信 + $this->smsAliService->sendForCommunityFinancial($user_id, $money); + } /** @@ -101,6 +110,9 @@ class FinancialRecordService implements FinancialRecordServiceInterface ]); $balance->balance = bcadd($balance->balance, $money, 2); $balance->save(); + + // 发送短信 + $this->smsAliService->sendForCommunityFinancial($user_id, $money); } /** @@ -125,6 +137,9 @@ class FinancialRecordService implements FinancialRecordServiceInterface ]); $balance->balance = bcadd($balance->balance, $money,2); $balance->save(); + + // 发送短信 + $this->smsAliService->sendForCommunityFinancial($user_id, $money); } diff --git a/app/Service/OrderService.php b/app/Service/OrderService.php index a02634e..215772f 100644 --- a/app/Service/OrderService.php +++ b/app/Service/OrderService.php @@ -803,7 +803,6 @@ class OrderService implements OrderServiceInterface // 微信支付 微信退款 $refundRes = $this->wxRefundService->wxPayRefund($orderMain->global_order_id); - var_dump($refundRes); if( empty($refundRes) || !$refundRes diff --git a/app/Service/SmsAliService.php b/app/Service/SmsAliService.php new file mode 100644 index 0000000..9c709f6 --- /dev/null +++ b/app/Service/SmsAliService.php @@ -0,0 +1,68 @@ +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(['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/SmsServiceInterface.php b/app/Service/SmsServiceInterface.php new file mode 100644 index 0000000..7f69282 --- /dev/null +++ b/app/Service/SmsServiceInterface.php @@ -0,0 +1,9 @@ +select('id','global_order_id','order_num','money','state') + try{ + $config = config('wxpay'); + $app = Factory::payment($config); + $app['guzzle_handler'] = CoroutineHandler::class; + + // 查询订单 + $orderMain = OrderMain::query() + ->select(['id','global_order_id','order_num','money','state']) ->where('global_order_id',$global_order_id) ->where('pay_type',OrderMain::ORDER_PAY_WX) - ->where(Db::raw('refund_time is null')) - ->first()->toArray(); + ->whereRaw('refund_time is null') + ->first(); - if(empty($orderMain)){ - return false; - }; + 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, - $options - ); + $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, + $options + ); + } catch (QueryException $e) { + $this->log->event(LogLabel::WX_PAY_REFUND,$e->getMessage()); + return false; + } catch (BusinessException $e){ + $this->log->event(LogLabel::WX_PAY_REFUND,$e->getMessage()); + return false; + } + $this->log->event(LogLabel::WX_PAY_REFUND,$result); return $result; } diff --git a/composer.json b/composer.json index 4cfe0dd..e47d9a0 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,8 @@ "hyperf/json-rpc": "^2.0", "hyperf/rpc-server": "^2.0", "hyperf/rpc-client": "^2.0", - "hyperf/consul": "^2.0" + "hyperf/consul": "^2.0", + "alibabacloud/client": "^1.5" }, "require-dev": { "swoole/ide-helper": "^4.5", diff --git a/config/autoload/dependencies.php b/config/autoload/dependencies.php index 6eacba0..dc8ce2c 100644 --- a/config/autoload/dependencies.php +++ b/config/autoload/dependencies.php @@ -33,4 +33,5 @@ return [ \App\Service\SeparateAccountsServiceInterface::class => \App\Service\SeparateAccountsService::class, \App\Service\ShopCarServiceInterface::class => \App\Service\ShopCarService::class, \App\Service\WxRefundServiceInterface::class => \App\Service\WxRefundService::class, + \App\Service\SmsServiceInterface::class => \App\Service\SmsAliService::class, ]; diff --git a/config/config.php b/config/config.php index ba75ad6..d416f7f 100644 --- a/config/config.php +++ b/config/config.php @@ -40,5 +40,12 @@ return [ 'wxtempmsg' => [ 'app_id' => env('APP_ID',''), 'secret' => env('APP_SECRET',''), + ], + 'alisms' => [ + 'app_key' => env('ALI_SMS_APP_KEY', ''), + 'app_secret' => env('ALI_SMS_APP_SECRET', ''), + 'regionid' => env('ALI_SMS_REGION_ID', ''), + 'product' => env('ALI_SMS_PRODUCT', ''), + 'host' => env('ALI_SMS_HOST', ''), ] ];