feat:增加用户资产和会员状态
This commit is contained in:
@ -1,12 +1,14 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
model3 "SciencesServer/app/api/enterprise/model"
|
||||
"SciencesServer/app/api/enterprise/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/handle"
|
||||
"SciencesServer/config"
|
||||
"SciencesServer/serve/orm"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Login struct{ local string }
|
||||
@ -58,32 +60,47 @@ func loginForSmsCaptcha(params *LoginParams, local string) (*InstanceLoginParams
|
||||
}
|
||||
var isExist bool
|
||||
// 查询账号信息
|
||||
mUserInstance := model3.NewUserInstance()
|
||||
mUserInstance := model.NewUserInstance()
|
||||
|
||||
if isExist, err = model2.FirstField(mUserInstance.UserInstance, []string{"id", "uuid", "avatar", "name", "mobile", "status"},
|
||||
if isExist, err = model2.FirstField(mUserInstance.UserInstance, []string{"id", "uuid", "avatar", "name", "mobile",
|
||||
"is_vip", "vip_deadline", "status"},
|
||||
model2.NewWhere("mobile", params.Captcha.Mobile)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mUserIdentity := model3.NewUserIdentity()
|
||||
mUserIdentity := model.NewUserIdentity()
|
||||
// 用户资产信息
|
||||
mUserAssets := new(model.UserAssets)
|
||||
|
||||
if isExist {
|
||||
// 查询该区域下最后一次选中的信息
|
||||
if err = mUserIdentity.LastChooseInfo(mUserInstance.UUID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if mUserAssets, err = model.NewUserAssets().Assets(mUserInstance.UUID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
goto RETURNS
|
||||
}
|
||||
mUserInstance.Name = params.Captcha.Mobile
|
||||
mUserInstance.Mobile = params.Captcha.Mobile
|
||||
mUserInstance.Password = utils.GetRandomString(12)
|
||||
if err = orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
mUserInstance.Name = params.Captcha.Mobile
|
||||
mUserInstance.Mobile = params.Captcha.Mobile
|
||||
mUserInstance.Password = utils.GetRandomString(12)
|
||||
|
||||
if err = model2.Create(mUserInstance.UserInstance); err != nil {
|
||||
if err = model2.Create(mUserInstance.UserInstance, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
mUserAssets.UID = mUserInstance.UUID
|
||||
|
||||
return model2.Create(mUserAssets.UserAssets, tx)
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
RETURNS:
|
||||
return &InstanceLoginParams{
|
||||
UID: mUserInstance.UUID,
|
||||
Avatar: mUserInstance.GetAvatarAttribute(config.SettingInfo.Domain), Name: mUserInstance.Name, Mobile: mUserInstance.Mobile,
|
||||
Vip: mUserInstance.VipStatus(), VipDeadline: mUserInstance.VipDeadline, Currency: mUserAssets.Currency,
|
||||
Identity: mUserInstance.Identity, SelectIdentity: mUserIdentity.Identity,
|
||||
Status: mUserInstance.Status,
|
||||
}, nil
|
||||
@ -94,9 +111,10 @@ func loginForPassword(params *LoginParams, local string) (*InstanceLoginParams,
|
||||
if !utils.ValidateMobile(params.Password.Account) {
|
||||
return nil, errors.New("操作错误,手机号码格式异常")
|
||||
}
|
||||
mUserInstance := model3.NewUserInstance()
|
||||
mUserInstance := model.NewUserInstance()
|
||||
|
||||
isExist, err := model2.FirstField(mUserInstance.UserInstance, []string{"id", "uuid", "name", "avatar", "mobile", "password", "salt", "status"},
|
||||
isExist, err := model2.FirstField(mUserInstance.UserInstance, []string{"id", "uuid", "name", "avatar", "mobile",
|
||||
"is_vip", "vip_deadline", "password", "salt", "status"},
|
||||
model2.NewWhere("mobile", params.Password.Account))
|
||||
|
||||
if err != nil {
|
||||
@ -107,8 +125,14 @@ func loginForPassword(params *LoginParams, local string) (*InstanceLoginParams,
|
||||
if !mUserInstance.ValidatePassword(params.Password.Password) {
|
||||
return nil, errors.New("操作错误,账户或密码错误")
|
||||
}
|
||||
// 用户资产信息
|
||||
mUserAssets := new(model.UserAssets)
|
||||
|
||||
if mUserAssets, err = model.NewUserAssets().Assets(mUserInstance.UUID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 最后一次选中的身份信息
|
||||
mUserIdentity := model3.NewUserIdentity()
|
||||
mUserIdentity := model.NewUserIdentity()
|
||||
|
||||
if err = mUserIdentity.LastChooseInfo(mUserInstance.UUID); err != nil {
|
||||
return nil, err
|
||||
@ -116,6 +140,7 @@ func loginForPassword(params *LoginParams, local string) (*InstanceLoginParams,
|
||||
return &InstanceLoginParams{
|
||||
UID: mUserInstance.UUID,
|
||||
Avatar: mUserInstance.GetAvatarAttribute(config.SettingInfo.Domain), Name: mUserInstance.Name, Mobile: mUserInstance.Mobile,
|
||||
Vip: mUserInstance.VipStatus(), VipDeadline: mUserInstance.VipDeadline, Currency: mUserAssets.Currency,
|
||||
Identity: mUserInstance.Identity, SelectIdentity: mUserIdentity.Identity,
|
||||
Status: mUserInstance.Status,
|
||||
}, nil
|
||||
|
Reference in New Issue
Block a user