Browse Source

Merge branch 'purchase_limit' of http://120.24.33.109:11081/hyzjshwo/lanzu_api_hyperf into purchase_limit

master
Lemon 5 years ago
parent
commit
8d85cc27d6
  1. 29
      app/Model/AdminUser.php
  2. 29
      app/Model/CsInfo.php
  3. 17
      app/Service/FinancialRecordService.php
  4. 1
      app/Service/OrderService.php
  5. 68
      app/Service/SmsAliService.php
  6. 9
      app/Service/SmsServiceInterface.php
  7. 57
      app/Service/WxRefundService.php
  8. 3
      composer.json
  9. 1
      config/autoload/dependencies.php
  10. 7
      config/config.php

29
app/Model/AdminUser.php

@ -0,0 +1,29 @@
<?php
declare (strict_types=1);
namespace App\Model;
use Hyperf\DbConnection\Model\Model;
/**
*/
class AdminUser extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'admin_users';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [];
}

29
app/Model/CsInfo.php

@ -0,0 +1,29 @@
<?php
declare (strict_types=1);
namespace App\Model;
use Hyperf\DbConnection\Model\Model;
/**
*/
class CsInfo extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'lanzu_cs_info';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [];
}

17
app/Service/FinancialRecordService.php

@ -5,11 +5,16 @@ namespace App\Service;
use App\Model\FinancialRecord; use App\Model\FinancialRecord;
use App\Model\Store; use App\Model\Store;
use App\Model\UserBalance; use App\Model\UserBalance;
use App\Model\Users;
use Hyperf\Di\Annotation\Inject;
class FinancialRecordService implements FinancialRecordServiceInterface class FinancialRecordService implements FinancialRecordServiceInterface
{ {
/**
* @Inject
* @var SmsServiceInterface
*/
protected $smsAliService;
public function ledgerAccounts($source_id, $money, $source_type, $money_type, $desc, $comment='') public function ledgerAccounts($source_id, $money, $source_type, $money_type, $desc, $comment='')
{ {
@ -77,6 +82,10 @@ class FinancialRecordService implements FinancialRecordServiceInterface
]); ]);
$balance->balance = bcadd($balance->balance, $money, 2); $balance->balance = bcadd($balance->balance, $money, 2);
$balance->save(); $balance->save();
// 发送短信
$this->smsAliService->sendForCommunityFinancial($user_id, $money);
} }
/** /**
@ -101,6 +110,9 @@ class FinancialRecordService implements FinancialRecordServiceInterface
]); ]);
$balance->balance = bcadd($balance->balance, $money, 2); $balance->balance = bcadd($balance->balance, $money, 2);
$balance->save(); $balance->save();
// 发送短信
$this->smsAliService->sendForCommunityFinancial($user_id, $money);
} }
/** /**
@ -125,6 +137,9 @@ class FinancialRecordService implements FinancialRecordServiceInterface
]); ]);
$balance->balance = bcadd($balance->balance, $money,2); $balance->balance = bcadd($balance->balance, $money,2);
$balance->save(); $balance->save();
// 发送短信
$this->smsAliService->sendForCommunityFinancial($user_id, $money);
} }

1
app/Service/OrderService.php

@ -803,7 +803,6 @@ class OrderService implements OrderServiceInterface
// 微信支付 微信退款 // 微信支付 微信退款
$refundRes = $this->wxRefundService->wxPayRefund($orderMain->global_order_id); $refundRes = $this->wxRefundService->wxPayRefund($orderMain->global_order_id);
var_dump($refundRes);
if( if(
empty($refundRes) empty($refundRes)
|| !$refundRes || !$refundRes

68
app/Service/SmsAliService.php

@ -0,0 +1,68 @@
<?php
namespace App\Service;
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
use App\Commons\Log;
use App\Model\CsInfo;
use App\Model\Market;
use Hyperf\Di\Annotation\Inject;
class SmsAliService implements SmsServiceInterface
{
const TEMPLATE_COMMUNITY_FINANCIAL = 'SMS_200690862';
/**
* @Inject
* @var Log
*/
protected $log;
public function send($phone, $template, $templateParams, $signName='懒族生活')
{
$alisms = config('alisms');
AlibabaCloud::accessKeyClient($alisms['app_key'], $alisms['app_secret'])
->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));
}
}

9
app/Service/SmsServiceInterface.php

@ -0,0 +1,9 @@
<?php
namespace App\Service;
interface SmsServiceInterface
{
public function send($phone, $template, $templateParams);
public function sendForCommunityFinancial($userId, $money);
}

57
app/Service/WxRefundService.php

@ -9,6 +9,8 @@ use App\Commons\Log;
use App\Constants\LogLabel; use App\Constants\LogLabel;
use Hyperf\Di\Annotation\Inject; use Hyperf\Di\Annotation\Inject;
use Hyperf\Guzzle\CoroutineHandler; use Hyperf\Guzzle\CoroutineHandler;
use Hyperf\Database\Exception\QueryException;
use App\Exception\BusinessException;
class WxRefundService implements WxRefundServiceInterface class WxRefundService implements WxRefundServiceInterface
{ {
@ -23,33 +25,42 @@ class WxRefundService implements WxRefundServiceInterface
*/ */
public function wxPayRefund($global_order_id) public function wxPayRefund($global_order_id)
{ {
$config = config('wxpay');
$app = Factory::payment($config);
$app['guzzle_handler'] = CoroutineHandler::class;
// 查询订单
$orderMain = OrderMain::query()
->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('global_order_id',$global_order_id)
->where('pay_type',OrderMain::ORDER_PAY_WX) ->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); $this->log->event(LogLabel::WX_PAY_REFUND,$result);
return $result; return $result;
} }

3
composer.json

@ -40,7 +40,8 @@
"hyperf/json-rpc": "^2.0", "hyperf/json-rpc": "^2.0",
"hyperf/rpc-server": "^2.0", "hyperf/rpc-server": "^2.0",
"hyperf/rpc-client": "^2.0", "hyperf/rpc-client": "^2.0",
"hyperf/consul": "^2.0"
"hyperf/consul": "^2.0",
"alibabacloud/client": "^1.5"
}, },
"require-dev": { "require-dev": {
"swoole/ide-helper": "^4.5", "swoole/ide-helper": "^4.5",

1
config/autoload/dependencies.php

@ -33,4 +33,5 @@ return [
\App\Service\SeparateAccountsServiceInterface::class => \App\Service\SeparateAccountsService::class, \App\Service\SeparateAccountsServiceInterface::class => \App\Service\SeparateAccountsService::class,
\App\Service\ShopCarServiceInterface::class => \App\Service\ShopCarService::class, \App\Service\ShopCarServiceInterface::class => \App\Service\ShopCarService::class,
\App\Service\WxRefundServiceInterface::class => \App\Service\WxRefundService::class, \App\Service\WxRefundServiceInterface::class => \App\Service\WxRefundService::class,
\App\Service\SmsServiceInterface::class => \App\Service\SmsAliService::class,
]; ];

7
config/config.php

@ -40,5 +40,12 @@ return [
'wxtempmsg' => [ 'wxtempmsg' => [
'app_id' => env('APP_ID',''), 'app_id' => env('APP_ID',''),
'secret' => env('APP_SECRET',''), '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', ''),
] ]
]; ];
Loading…
Cancel
Save