修改了手机号登陆

This commit is contained in:
2024-08-15 14:37:05 +08:00
parent 8ee4dec11d
commit adb565257d
12 changed files with 648 additions and 35 deletions
+189
View File
@@ -7,6 +7,8 @@ import (
"hepa-calc-api/api/dao"
"hepa-calc-api/api/model"
"hepa-calc-api/extend/aliyun"
"hepa-calc-api/extend/app"
"hepa-calc-api/utils"
"io"
"math/rand"
"net/http"
@@ -152,3 +154,190 @@ func (r *UserService) AddUserMemberBuyCount(tx *gorm.DB, userId int64) (bool, er
return true, nil
}
// HandleAppUserInfo 处理app用户数据
func (r *UserService) HandleAppUserInfo(tx *gorm.DB, user *model.User, userInfo *model.UserInfo) error {
appUserInfo, err := app.GetInfoByMobile(user.Mobile)
if err != nil {
return err
}
// 对比处理用户数据
userData := make(map[string]interface{}) // 用户数据
userInfoData := make(map[string]interface{}) // 用户详情数据
// 出生日期/年龄
if appUserInfo.Data.Birthday != "" {
if user.Birthday != nil {
birthday := time.Time(*user.Birthday).Format("2006-01-02 15:04:05")
if appUserInfo.Data.Birthday != birthday {
userData["birthday"] = appUserInfo.Data.Birthday
}
} else {
userData["birthday"] = appUserInfo.Data.Birthday
}
// 年龄
age, err := utils.CalculateAge(appUserInfo.Data.Birthday)
if err != nil {
return err
}
userData["age"] = age
}
// 是否怀孕 1无计划 2计划中 3已怀孕 4家有宝宝
if appUserInfo.Data.IsPregnant != nil {
if userInfo.IsPregnant != nil {
if *appUserInfo.Data.IsPregnant != *userInfo.IsPregnant {
userInfoData["is_pregnant"] = appUserInfo.Data.IsPregnant
}
} else {
userInfoData["is_pregnant"] = appUserInfo.Data.IsPregnant
}
// 预产期
if appUserInfo.Data.ExpectedDateOfChildbirth != "" {
userInfoData["expected_date"] = appUserInfo.Data.ExpectedDateOfChildbirth
}
}
// 性别
if appUserInfo.Data.Sex != nil {
if user.Sex != nil {
if *appUserInfo.Data.Sex != *user.Sex {
userData["sex"] = appUserInfo.Data.Sex
}
} else {
userData["sex"] = appUserInfo.Data.Sex
}
}
// 体重
if appUserInfo.Data.Weight != nil {
weight := fmt.Sprintf("%f", appUserInfo.Data.Weight)
if userInfo.Weight != "" {
if weight != userInfo.Weight {
userInfoData["weight"] = weight
}
} else {
userInfoData["weight"] = weight
}
}
// 省份 id
if appUserInfo.Data.ProvinceID != nil {
// 获取省份数据
if userInfo.ProvinceId != nil {
if *appUserInfo.Data.ProvinceID != *userInfo.ProvinceId {
userInfoData["province_id"] = appUserInfo.Data.ProvinceID
}
} else {
userInfoData["province_id"] = appUserInfo.Data.ProvinceID
}
}
// 城市 id
if appUserInfo.Data.CityID != nil {
// 获取城市数据
if userInfo.CityId != nil {
if *appUserInfo.Data.CityID != *userInfo.CityId {
userInfoData["city_id"] = appUserInfo.Data.CityID
}
} else {
userInfoData["city_id"] = appUserInfo.Data.CityID
}
}
// 市区 id
if appUserInfo.Data.CountyID != nil {
// 获取区县数据
if userInfo.CountyId != nil {
if *appUserInfo.Data.CountyID != *userInfo.CountyId {
userInfoData["county_id"] = appUserInfo.Data.CountyID
}
} else {
userInfoData["county_id"] = appUserInfo.Data.CountyID
}
}
// 家族病史
if appUserInfo.Data.IsHBV != nil {
// 有无 肝硬化或肝癌家族史 0无1有2未知
// 是否存在家族病史(0:未知 1:是 2:否)
// 转换双方状态
if *appUserInfo.Data.IsHBV == 0 {
*appUserInfo.Data.IsHBV = 2
} else if *appUserInfo.Data.IsHBV == 1 {
*appUserInfo.Data.IsHBV = 1
} else if *appUserInfo.Data.IsHBV == 2 {
*appUserInfo.Data.IsHBV = 0
}
if userInfo.IsFamilyHistory != nil {
if *appUserInfo.Data.IsHBV != *userInfo.IsFamilyHistory {
userInfoData["is_family_history"] = appUserInfo.Data.IsHBV
}
} else {
userInfoData["is_family_history"] = appUserInfo.Data.IsHBV
}
}
// 民族
if appUserInfo.Data.NationUUID != "" {
// 获取民族数据
var nationId int64
if userInfo.NationId != nil {
if nationId != *userInfo.NationId {
userInfoData["nation_id"] = nationId
}
} else {
userInfoData["nation_id"] = nationId
}
}
// 患者 uuid
if appUserInfo.Data.PatientUUID != "" {
if user.AppIden != "" {
if appUserInfo.Data.PatientUUID != user.AppIden {
userData["app_iden"] = appUserInfo.Data.PatientUUID
}
} else {
userData["app_iden"] = appUserInfo.Data.PatientUUID
}
}
// 姓名
if appUserInfo.Data.Name != "" {
if user.UserName != "" {
if appUserInfo.Data.Name != user.UserName {
userData["user_name"] = appUserInfo.Data.Name
}
} else {
userData["user_name"] = appUserInfo.Data.Name
}
}
// 修改用户数据
if len(userData) > 0 {
userDao := dao.UserDao{}
err := userDao.EditUserById(tx, user.UserId, userData)
if err != nil {
return err
}
}
// 修改用户详情数据
if len(userInfoData) > 0 {
userInfoDao := dao.UserInfoDao{}
err := userInfoDao.EditUserInfoById(tx, userInfo.UserInfoId, userInfoData)
if err != nil {
return err
}
}
return nil
}