接口开发

This commit is contained in:
2025-02-25 16:57:59 +08:00
parent 76ccd57fbc
commit 32ba6262cc
48 changed files with 2468 additions and 466 deletions

View File

@ -0,0 +1,7 @@
package memberbalancechangesource
const (
CASH_BACK = "cash_back" // 会员返现
WITH_DRAW = "whith_draw" // 会员提现
)

View File

@ -0,0 +1,10 @@
package memberrenwallogstatus
const (
//待支付
PENDING = "pending"
//已支付
PAID = "paid"
//已过期
EXPIRED = "expired"
)

View File

@ -0,0 +1,16 @@
package memberwithdrawallogstatus
const (
//提现成功
SUCCESS = "success"
//提现失败
FAILED = "failed"
//审核中
PENDING = "pending"
//审核同构
APPROVED = "approved"
//审核拒绝
REJECTED = "rejected"
//已取消
CANCELED = "cancel"
)

View File

@ -56,3 +56,10 @@ const (
ListenAveLastSymbol = "listen_ave_last_symbol" // 监听最新交易对
AveRequestToken = "ave_request_token" // AVE请求token
)
// 用户下单
const (
MemberShipPre = "member_ship_pre:%v" //用户开通会员预下单 单价缓存{payable_amount}
MemberHash = "member_hash:%v" //用户开通会员hash缓存 {hash}
OrderAmount = "order_amount:%v" //用户下单金额缓存 {amount}
)

View File

@ -0,0 +1,8 @@
package sysconfigkey
const (
//用户返利等级2
MEMBER_INVITATION_RATE2 = "member_invitation_rate2"
//用户返利等级1
MEMBER_INVITATION_RATE1 = "member_invitation_rate1"
)

View File

@ -93,7 +93,7 @@ func UserRegister(orm *gorm.DB, registerInfo sysmodel.FrontedUserRegisterReq) (i
Password: registerInfo.Password,
Salt: inttostring.GenerateRandomString(6),
Email: registerInfo.Email,
InviteCode: inttostring.NewInvite().Encode(int(time.Now().Unix())),
InviteCode: inttostring.NewNumberInvite().Encode(int(time.Now().Unix())),
Loginip: registerInfo.IP,
Mobile: registerInfo.Phone,
Area: registerInfo.PhoneAreaCode,
@ -484,205 +484,222 @@ func GenerateToken(uid, source int, nickname, phone, email, ip, deviceID string)
return jwtToken, expire, statuscode.OK
}
// // 用户多端互踢
//
//// 用户多端互踢
//func wsLoginKick(devId string, userId int) {
// if devId == "" {
// return
// }
// // 校验是否存在已经其他端登录
// key := fmt.Sprintf("user-%v", userId)
// // 读取原存储的设备号
// preDevId, _ := helper.DefaultRedis.HGetField(rediskey.UserLoginWsClient, key)
// // 将本次登录的设备号存储
// _ = helper.DefaultRedis.HSetField(rediskey.UserLoginWsClient, key, devId)
//
// if string(preDevId) != devId {
// // hc todo 注释
// // 给上一个登录的端发送订阅消息
// // data := &models.PushUserLoginKick{
// // Type: 14,
// // Data: string(preDevId), // 上一个登录端的设备号
// // }
// // // 通知用户账户最新信息
// // by, _ := sonic.Marshal(data)
// // log.Info("通知用户其他端已登录", zap.String("key", key), zap.ByteString("by", by))
// // kafkahelper.SendKafkaMsg(kafkatopic.LoginKick, key, by)
// }
//}
//
//// ResetPwdBefore 1 重置密码前校验
//func ResetPwdBefore(orm *gorm.DB, resetPwd sysmodel.ResetPwdReq) (user models.AdUser, code int) {
// var err error
//
// if resetPwd.RetrieveType == 1 {
// user, err = aduserdb.GetUserByPhone(orm, resetPwd.PhoneAreaCode, resetPwd.Phone)
// if err != nil {
// return user, statuscode.ServerError
// func wsLoginKick(devId string, userId int) {
// if devId == "" {
// return
// }
// } else if resetPwd.RetrieveType == 2 {
// user, err = aduserdb.GetUserByEmail(orm, resetPwd.Email) //GetUser("useremail", resetPwd.Email)
// if err != nil {
// return user, statuscode.ServerError
// // 校验是否存在已经其他端登录
// key := fmt.Sprintf("user-%v", userId)
// // 读取原存储的设备号
// preDevId, _ := helper.DefaultRedis.HGetField(rediskey.UserLoginWsClient, key)
// // 将本次登录的设备号存储
// _ = helper.DefaultRedis.HSetField(rediskey.UserLoginWsClient, key, devId)
//
// if string(preDevId) != devId {
// // hc todo 注释
// // 给上一个登录的端发送订阅消息
// // data := &models.PushUserLoginKick{
// // Type: 14,
// // Data: string(preDevId), // 上一个登录端的设备号
// // }
// // // 通知用户账户最新信息
// // by, _ := sonic.Marshal(data)
// // log.Info("通知用户其他端已登录", zap.String("key", key), zap.ByteString("by", by))
// // kafkahelper.SendKafkaMsg(kafkatopic.LoginKick, key, by)
// }
// }
//
// if user.Id == 0 {
// return user, statuscode.TheAccountIsNotRegistered
// // ResetPwdBefore 1 重置密码前校验
//
// func ResetPwdBefore(orm *gorm.DB, resetPwd sysmodel.ResetPwdReq) (user models.AdUser, code int) {
// var err error
//
// if resetPwd.RetrieveType == 1 {
// user, err = aduserdb.GetUserByPhone(orm, resetPwd.PhoneAreaCode, resetPwd.Phone)
// if err != nil {
// return user, statuscode.ServerError
// }
// } else if resetPwd.RetrieveType == 2 {
// user, err = aduserdb.GetUserByEmail(orm, resetPwd.Email) //GetUser("useremail", resetPwd.Email)
// if err != nil {
// return user, statuscode.ServerError
// }
// }
//
// if user.Id == 0 {
// return user, statuscode.TheAccountIsNotRegistered
// }
//
// return user, statuscode.OK
// }
//
// return user, statuscode.OK
//}
// // ResetPwdCheck 2 重置密码安全验证
//
//// ResetPwdCheck 2 重置密码安全验证
//func ResetPwdCheck(orm *gorm.DB, rpc sysmodel.ResetPwdCheck) (string, int) {
// var (
// user models.AdUser
// err error
// )
// func ResetPwdCheck(orm *gorm.DB, rpc sysmodel.ResetPwdCheck) (string, int) {
// var (
// user models.AdUser
// err error
// )
//
// if rpc.RetrieveType == 1 {
// user, err = aduserdb.GetUserByPhone(orm, rpc.PhoneAreaCode, rpc.Phone)
// if rpc.RetrieveType == 1 {
// user, err = aduserdb.GetUserByPhone(orm, rpc.PhoneAreaCode, rpc.Phone)
// if err != nil {
// return "", statuscode.ServerError
// }
// } else if rpc.RetrieveType == 2 {
// user, err = aduserdb.GetUserByEmail(orm, rpc.Email) //GetUser("useremail", rpc.Email)
// if err != nil {
// return "", statuscode.ServerError
// }
// }
//
// if user.Id == 0 {
// return "", statuscode.TheAccountIsNotRegistered
// }
//
// // 获取用户验证器开启状态
// authSwitch, err := aduserdb.GetUserAuthSwitch(orm, user.Id)
// if err != nil {
// return "", statuscode.ServerError
// }
// } else if rpc.RetrieveType == 2 {
// user, err = aduserdb.GetUserByEmail(orm, rpc.Email) //GetUser("useremail", rpc.Email)
// if err != nil {
// return "", statuscode.ServerError
// // 验证器校验
// validator := sysmodel.Authenticator{
// UserID: user.Id,
// PhoneAuth: authSwitch.PhoneAuth,
// EmailAuth: authSwitch.EmailAuth,
// GoogleAuth: authSwitch.GoogleAuth,
// Phone: user.Phone,
// Email: user.UserEmail,
// GoogleSecret: authSwitch.GoogleSecret,
// SmsCaptcha: rpc.SmsCaptcha,
// EmailCaptcha: rpc.EmailCaptcha,
// GoogleCaptcha: rpc.GoogleCaptcha,
// BusinessType: businesstype.ResetPass,
// }
//
// if code := AuthenticatorVerify(orm, validator); code != statuscode.OK {
// return "", code
// }
//
// // 校验验证码通过,生成下一步操作的凭证
// cre := sysmodel.Credential{
// BusinessType: int(businesstype.ResetPass),
// UserID: user.Id,
// Phone: user.Phone,
// Email: user.UserEmail,
// Time: time.Now().Unix(),
// Rand: rand.NewSource(time.Now().UnixNano()).Int63(),
// }
// creJ, _ := sonic.Marshal(cre)
// credentials := aeshelper.Encrypt(string(creJ), codeVerifySuccess)
//
// return credentials, statuscode.OK
// }
//
// if user.Id == 0 {
// return "", statuscode.TheAccountIsNotRegistered
// // ResetPwd 3 重置密码
//
// func ResetPwd(orm *gorm.DB, user models.AdUser, resetPwd sysmodel.ResetPwdReq) int {
// // 校验凭证
// cre := sysmodel.Credential{
// BusinessType: int(businesstype.ResetPass),
// UserID: user.Id,
// Phone: user.Phone,
// Email: user.UserEmail,
// Time: time.Now().Unix(),
// }
// if !CheckCredentials(cre, resetPwd.Credentials) {
// log.Error("business credentials error")
// return statuscode.BusinessCredentialsError
// }
//
// // 更新密码
// if err := aduserdb.UpdateUserPwd(orm, resetPwd.UserID, resetPwd.Password); err != nil {
// return statuscode.ServerError
// }
//
// return statuscode.OK
// }
//
// // 获取用户验证器开启状态
// authSwitch, err := aduserdb.GetUserAuthSwitch(orm, user.Id)
// if err != nil {
// return "", statuscode.ServerError
// }
// // 验证器校验
// validator := sysmodel.Authenticator{
// UserID: user.Id,
// PhoneAuth: authSwitch.PhoneAuth,
// EmailAuth: authSwitch.EmailAuth,
// GoogleAuth: authSwitch.GoogleAuth,
// Phone: user.Phone,
// Email: user.UserEmail,
// GoogleSecret: authSwitch.GoogleSecret,
// SmsCaptcha: rpc.SmsCaptcha,
// EmailCaptcha: rpc.EmailCaptcha,
// GoogleCaptcha: rpc.GoogleCaptcha,
// BusinessType: businesstype.ResetPass,
// // ChangePwdBefore 修改密码前校验
// func ChangePwdBefore(orm *gorm.DB, params sysmodel.UserChangePwdReq) (user models.AdUser, code int) {
//
// user, err := aduserdb.GetUserById(orm, params.UserId) //"id", params.UserId)
//
// if err != nil {
// return user, statuscode.ServerError
// }
// if user.UserPassword != params.OldPassword {
// return user, statuscode.OriginalPasswordError
// }
//
// return user, statuscode.OK
// }
//
// if code := AuthenticatorVerify(orm, validator); code != statuscode.OK {
// return "", code
// // ChangePwd 修改密码
//
// func ChangePwd(orm *gorm.DB, params sysmodel.UserChangePwdReq, user models.AdUser) int {
// // 获取用户验证器开关状态
// authSwitch, err := GetUserAuthSwitch(orm, user.Id)
// if err != nil {
// return statuscode.ServerError
// }
//
// // 验证器验证
// auth := sysmodel.Authenticator{
// UserID: params.UserId,
// PhoneAuth: authSwitch.PhoneAuth,
// EmailAuth: authSwitch.EmailAuth,
// GoogleAuth: authSwitch.GoogleAuth,
// Phone: user.Phone,
// Email: user.UserEmail,
// GoogleSecret: authSwitch.GoogleSecret,
// SmsCaptcha: params.SmsCaptcha,
// EmailCaptcha: params.EmailCaptcha,
// GoogleCaptcha: params.GoogleCaptcha,
// BusinessType: businesstype.ChangePassword,
// }
// if code := AuthenticatorVerify(orm, auth); code != statuscode.OK {
// return code
// }
//
// // 更新密码
// if err = aduserdb.UpdateUserPwd(orm, params.UserId, params.NewPassword); err != nil {
// return statuscode.ServerError
// }
//
// return statuscode.OK
// }
//
// // 校验验证码通过,生成下一步操作的凭证
// cre := sysmodel.Credential{
// BusinessType: int(businesstype.ResetPass),
// UserID: user.Id,
// Phone: user.Phone,
// Email: user.UserEmail,
// Time: time.Now().Unix(),
// Rand: rand.NewSource(time.Now().UnixNano()).Int63(),
// // GetUserRealName 获取用户真实姓名
//
// func GetUserRealName(orm *gorm.DB, uid int) string {
// buyerIdent, err := aduserdb.GetIdentification(orm, uid)
// if err != nil {
// return ""
// }
// realName := buyerIdent.Name
//
// if buyerIdent.CountryId == 40 || buyerIdent.CountryId == 73 ||
// buyerIdent.CountryId == 115 || buyerIdent.CountryId == 179 {
// realName = buyerIdent.Name // 中国大陆,港澳台
// } else {
// // 名字-中间名-姓
// realName = buyerIdent.Name + " " + buyerIdent.MiddleName + " " + buyerIdent.Surname
// }
//
// return realName
// }
// creJ, _ := sonic.Marshal(cre)
// credentials := aeshelper.Encrypt(string(creJ), codeVerifySuccess)
//
// return credentials, statuscode.OK
//}
//
//// ResetPwd 3 重置密码
//func ResetPwd(orm *gorm.DB, user models.AdUser, resetPwd sysmodel.ResetPwdReq) int {
// // 校验凭证
// cre := sysmodel.Credential{
// BusinessType: int(businesstype.ResetPass),
// UserID: user.Id,
// Phone: user.Phone,
// Email: user.UserEmail,
// Time: time.Now().Unix(),
// }
// if !CheckCredentials(cre, resetPwd.Credentials) {
// log.Error("business credentials error")
// return statuscode.BusinessCredentialsError
// }
//
// // 更新密码
// if err := aduserdb.UpdateUserPwd(orm, resetPwd.UserID, resetPwd.Password); err != nil {
// return statuscode.ServerError
// }
//
// return statuscode.OK
//}
//
//// ChangePwdBefore 修改密码前校验
//func ChangePwdBefore(orm *gorm.DB, params sysmodel.UserChangePwdReq) (user models.AdUser, code int) {
//
// user, err := aduserdb.GetUserById(orm, params.UserId) //"id", params.UserId)
//
// if err != nil {
// return user, statuscode.ServerError
// }
// if user.UserPassword != params.OldPassword {
// return user, statuscode.OriginalPasswordError
// }
//
// return user, statuscode.OK
//}
//
//// ChangePwd 修改密码
//func ChangePwd(orm *gorm.DB, params sysmodel.UserChangePwdReq, user models.AdUser) int {
// // 获取用户验证器开关状态
// authSwitch, err := GetUserAuthSwitch(orm, user.Id)
// if err != nil {
// return statuscode.ServerError
// }
//
// // 验证器验证
// auth := sysmodel.Authenticator{
// UserID: params.UserId,
// PhoneAuth: authSwitch.PhoneAuth,
// EmailAuth: authSwitch.EmailAuth,
// GoogleAuth: authSwitch.GoogleAuth,
// Phone: user.Phone,
// Email: user.UserEmail,
// GoogleSecret: authSwitch.GoogleSecret,
// SmsCaptcha: params.SmsCaptcha,
// EmailCaptcha: params.EmailCaptcha,
// GoogleCaptcha: params.GoogleCaptcha,
// BusinessType: businesstype.ChangePassword,
// }
// if code := AuthenticatorVerify(orm, auth); code != statuscode.OK {
// return code
// }
//
// // 更新密码
// if err = aduserdb.UpdateUserPwd(orm, params.UserId, params.NewPassword); err != nil {
// return statuscode.ServerError
// }
//
// return statuscode.OK
//}
//
//// GetUserRealName 获取用户真实姓名
//func GetUserRealName(orm *gorm.DB, uid int) string {
// buyerIdent, err := aduserdb.GetIdentification(orm, uid)
// if err != nil {
// return ""
// }
// realName := buyerIdent.Name
//
// if buyerIdent.CountryId == 40 || buyerIdent.CountryId == 73 ||
// buyerIdent.CountryId == 115 || buyerIdent.CountryId == 179 {
// realName = buyerIdent.Name // 中国大陆,港澳台
// } else {
// // 名字-中间名-姓
// realName = buyerIdent.Name + " " + buyerIdent.MiddleName + " " + buyerIdent.Surname
// }
//
// return realName
//}
// 退出登录
func Logout(userId, source int) error {
key := fmt.Sprintf(rediskey.AppLoginUserToken, userId)
if source == 3 {
key = fmt.Sprintf(rediskey.PCLoginUserToken, userId)
}
err := helper.DefaultRedis.DeleteString(key)
return err
}

View File

@ -0,0 +1,11 @@
package statuscode
//============用户模块===============
const (
InsufficientFunds = 110000 + iota // 提现可用余额不足
BelowMinimum // 提现金额低于最低限额
NetworkNotExist // 网络不存在
NetworkUnAvailable // 网络不可用
CanNotCancel // 无法取消
RenwalConfigDisabled // 续费配置不可用
)