|
|
@@ -9,9 +9,31 @@ class SmsClass extends BaseClass
|
|
|
{
|
|
|
public static $baseFile = '\biz\message\models\Sms';
|
|
|
|
|
|
+ //每个用户一天可以申请的短信条数
|
|
|
+ const SMS_LIMIT = 15;
|
|
|
+
|
|
|
public static $smsType = [
|
|
|
//申请会员
|
|
|
'applyMember' => ['id' => 0, 'sign' => 'applyMember'],
|
|
|
];
|
|
|
-
|
|
|
+
|
|
|
+ //用户今天还有没触发短信的机会 shish 2020.3.3
|
|
|
+ public static function getRightToSend($userId)
|
|
|
+ {
|
|
|
+ $ip = httpUtil::ip();
|
|
|
+ $statusKey = 'SMS_STATUS_' . $userId . '_' . $ip;
|
|
|
+ $hasSend = Yii::$app->redis->executeCommand('GET', [$statusKey]);
|
|
|
+ if (!empty($hasSend)) {
|
|
|
+ util::fail('请60秒后再操作');
|
|
|
+ }
|
|
|
+ $todayKey = 'SMS_NUM_' . date("Ymd") . '_' . $userId . '_' . $ip;
|
|
|
+ $num = Yii::$app->redis->executeCommand('GET', [$todayKey]);
|
|
|
+ $num = is_numeric($num) ? $num : 0;
|
|
|
+ if ($num > self::SMS_LIMIT) {
|
|
|
+ util::fail('您今天已经申请了'.self::SMS_LIMIT.'条短信,请明天再试');
|
|
|
+ }
|
|
|
+ Yii::$app->redis->executeCommand('SETEX', [$statusKey, 60, 'hasSend']);
|
|
|
+ Yii::$app->redis->executeCommand('SETEX', [$todayKey, 86400, ++$num]);
|
|
|
+ }
|
|
|
+
|
|
|
}
|