shish 6 rokov pred
rodič
commit
ad5117fbb1

+ 23 - 1
biz/message/classes/SmsClass.php

@@ -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]);
+	}
+
 }

+ 25 - 0
biz/message/services/SmsService.php

@@ -31,4 +31,29 @@ class SmsService extends BaseService
 		return $cacheCode;
 	}
 
+	//商家发短信 shish 2020.3.3
+	public static function merchantSend()
+	{
+		//要算钱的
+	}
+
+	//平台发短信 shish 2020.3.3
+	public static function platformSend()
+	{
+
+		/*
+		主要就更解决能不能发送的问题
+		
+		发送情况记录
+		
+		平台短信余额是否充足
+		商家短信余额是否充足
+		
+		有没ip限制
+		
+		最低部就是发送接口
+		 */
+
+	}
+
 }

+ 0 - 7
common/components/sms.php

@@ -32,13 +32,6 @@ class sms
 	const ACCOUNT = 'N2890342';
 	//短信服务密码
 	const PASSWORD = 'abc178c7';
-	//一个用户一天同个IP申请的短信条数
-	const LIMIT = 10;
-
-	public static function platformFreeSend()
-	{
-
-	}
 
 	//商家发短信 shish 2019.12.24
 	public static function merchantSend($mobile, $msg, $merchant)