Browse Source

社区服务点分账短信

master
weigang 5 years ago
parent
commit
153e0235bd
  1. 29
      app/Model/AdminUser.php
  2. 29
      app/Model/CsInfo.php
  3. 17
      app/Service/FinancialRecordService.php
  4. 68
      app/Service/SmsAliService.php
  5. 9
      app/Service/SmsServiceInterface.php
  6. 3
      composer.json
  7. 1
      config/autoload/dependencies.php
  8. 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\Store;
use App\Model\UserBalance;
use App\Model\Users;
use Hyperf\Di\Annotation\Inject;
class FinancialRecordService implements FinancialRecordServiceInterface
{
/**
* @Inject
* @var SmsServiceInterface
*/
protected $smsAliService;
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->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);
}

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

3
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",

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

7
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', ''),
]
];
Loading…
Cancel
Save