feat:优化项目结构

This commit is contained in:
henry
2021-11-24 10:50:09 +08:00
parent f007168919
commit 0862142ef0
25 changed files with 306 additions and 203 deletions

View File

@ -4,17 +4,20 @@ import (
"SciencesServer/app/api/enterprise/model"
"SciencesServer/app/basic/config"
model2 "SciencesServer/app/common/model"
"SciencesServer/app/handle"
"SciencesServer/app/service"
"SciencesServer/app/session"
config2 "SciencesServer/config"
"SciencesServer/serve/orm"
"SciencesServer/utils"
"errors"
"gorm.io/gorm"
"time"
)
type Instance struct{ *service.SessionEnterprise }
type Instance struct{ *session.Enterprise }
type InstanceHandle func(enterprise *service.SessionEnterprise) *Instance
type InstanceHandle func(session *session.Enterprise) *Instance
type (
// InstanceInfo 基本信息
@ -58,6 +61,36 @@ func (c *Instance) Detail() (*InstanceDetailInfo, error) {
return resp, nil
}
// BindMobile 绑定手机号码
func (c *Instance) BindMobile(mobile, captcha string) error {
if !utils.ValidateMobile(mobile) {
return errors.New("操作错误,手机号码格式异常")
}
// 查询用户手机号码是否绑定
mUserInstance := model.NewUserInstance()
if _, err := model2.FirstField(mUserInstance.UserInstance, []string{"id", "uuid", "mobile"}, model2.NewWhere("uuid", c.UID)); err != nil {
return err
}
if mUserInstance.Mobile == mobile {
return nil
}
pass, err := handle.NewCaptcha().Validate(&handle.CaptchaSms{
Mobile: mobile, Captcha: captcha,
})
if err != nil {
return err
} else if !pass {
return errors.New("操作错误,验证码错误或已过期")
}
if err := model2.Updates(mUserInstance.UserInstance, map[string]interface{}{
"mobile": mobile, "updated_at": time.Now(),
}); err != nil {
return err
}
return nil
}
// SwitchIdentity 切换身份
func (c *Instance) SwitchIdentity(identity int) error {
if _, has := config.TenantUserIdentityData[identity]; !has {
@ -96,12 +129,12 @@ func (c *Instance) SwitchIdentity(identity int) error {
c.ManageUID = mUserManage.UUID
}
c.SelectIdentity = identity
service.Publish(config2.EventForAccountLoginProduce, config2.RedisKeyForAccount, c.UIDToString(), c.SessionEnterprise)
service.Publish(config2.EventForAccountLoginProduce, config2.RedisKeyForAccount, c.UIDToString(), c.Enterprise)
return nil
}
func NewInstance() InstanceHandle {
return func(enterprise *service.SessionEnterprise) *Instance {
return &Instance{SessionEnterprise: enterprise}
return func(session *session.Enterprise) *Instance {
return &Instance{Enterprise: session}
}
}