|
@@ -419,7 +419,7 @@ class AccountService
|
|
|
*/
|
|
|
public function setLocation($coachId, $latitude, $longitude, $type = TechnicianLocationType::COMMON->value, array $locationInfo = [])
|
|
|
{
|
|
|
- // 使用事务确保据一致性
|
|
|
+ // 使用事务确保��一致性
|
|
|
return DB::transaction(function () use ($coachId, $latitude, $longitude, $type, $locationInfo) {
|
|
|
// 验证经纬度的有效性(-90≤纬度≤90,-180≤经度≤180)
|
|
|
$this->validateCoordinates($latitude, $longitude);
|
|
@@ -1283,4 +1283,46 @@ class AccountService
|
|
|
];
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送验证码
|
|
|
+ *
|
|
|
+ * 业务流程:
|
|
|
+ * 1. 检查手机号是否已被使用
|
|
|
+ * 2. 生成验证码
|
|
|
+ * 3. 保存到 Redis
|
|
|
+ * 4. 发送验证码
|
|
|
+ *
|
|
|
+ * @param array $data 包含:
|
|
|
+ * - mobile: string 手机号
|
|
|
+ * - type: string 验证码类型
|
|
|
+ * @return array 返回结果
|
|
|
+ */
|
|
|
+ public function sendVerifyCode(array $data): array
|
|
|
+ {
|
|
|
+ // 检查手机号是否已被使用
|
|
|
+ $exists = MemberUser::where('mobile', $data['mobile'])
|
|
|
+ ->whereHas('coach')
|
|
|
+ ->exists();
|
|
|
+ abort_if($exists, 422, '该手机号已被使用');
|
|
|
+
|
|
|
+ // 生成6位随机验证码
|
|
|
+ $code = str_pad(random_int(0, 999999), 6, '0', STR_PAD_LEFT);
|
|
|
+
|
|
|
+ // 验证码有效期(5分钟)
|
|
|
+ $expireTime = 300;
|
|
|
+
|
|
|
+ // 缓存键
|
|
|
+ $cacheKey = "sms_code:{$data['type']}:{$data['mobile']}";
|
|
|
+
|
|
|
+ // 保存到Redis,设置5分钟过期
|
|
|
+ Redis::setex($cacheKey, $expireTime, $code);
|
|
|
+
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'code' => $code,
|
|
|
+ 'mobile' => substr_replace($data['mobile'], '****', 3, 4),
|
|
|
+ 'expire_time' => $expireTime
|
|
|
+ ];
|
|
|
+ }
|
|
|
}
|