diff --git a/WeChatApplet/Services/Impl/FrameworkService.cs b/WeChatApplet/Services/Impl/FrameworkService.cs
index 6a627b8..3b5ed9d 100644
--- a/WeChatApplet/Services/Impl/FrameworkService.cs
+++ b/WeChatApplet/Services/Impl/FrameworkService.cs
@@ -1,4 +1,5 @@
using AutoMapper;
+using Microsoft.EntityFrameworkCore;
using YD_WeChatApplet.Api.Services.Interface;
using YD_WeChatApplet.Api.SmartSportsEntitys;
using YD_WeChatApplet.Api.Utilities;
@@ -25,11 +26,22 @@ namespace YD_WeChatApplet.Api.Services.Impl
///
public async Task ScanCodeLogin(string code)
{
- var entity = new Ai_ScanCodeLogin()
+ var schoolCode = UserLoginContext.Current.SchoolCode;
+ var teacherId = UserLoginContext.Current.UserId;
+
+ // 先检查是否已存在相同的记录
+ var exist = await _sportsContext.Ai_ScanCodeLogin
+ .AnyAsync(x => x.Code == code && x.SchoolCode == schoolCode && x.TeacherId == teacherId);
+
+ if (exist)
+ return true; // 已存在,认为成功
+
+ // 不存在则添加
+ var entity = new Ai_ScanCodeLogin
{
Code = code,
- SchoolCode = UserLoginContext.Current.SchoolCode,
- TeacherId = UserLoginContext.Current.UserId,
+ SchoolCode = schoolCode,
+ TeacherId = teacherId,
TeacherPhoneNo = UserLoginContext.Current.PhoneNo,
CreateDate = DateTime.Now
};
@@ -37,5 +49,6 @@ namespace YD_WeChatApplet.Api.Services.Impl
await _sportsContext.AddAsync(entity);
return await _sportsContext.SaveChangesAsync() > 0;
}
+
}
}