|
@@ -19,18 +19,18 @@ type AppUser struct {
|
|
Nickname string `gorm:"type:varchar(50);" json:"nickname"` // 昵称
|
|
Nickname string `gorm:"type:varchar(50);" json:"nickname"` // 昵称
|
|
Password string `gorm:"type:varchar(50);" json:"password"` // 密码
|
|
Password string `gorm:"type:varchar(50);" json:"password"` // 密码
|
|
LastLoginTime utils.Time `gorm:"type:datetime;" json:"last_login_time"` // 最后登录时间
|
|
LastLoginTime utils.Time `gorm:"type:datetime;" json:"last_login_time"` // 最后登录时间
|
|
- State int `gorm:"type:int;" json:"state"` // 状态 0:正常 1:禁用
|
|
|
|
|
|
+ State int `gorm:"type:int;" json:"state"` // 状态 1:正常 2:禁用
|
|
AppID string `gorm:"type:varchar(50);" json:"app_id" validate:"required"` // 应用id
|
|
AppID string `gorm:"type:varchar(50);" json:"app_id" validate:"required"` // 应用id
|
|
RegistMethod int `gorm:"type:int;" json:"regist_method"` // 注册方式 1 短信登录 2 微信登录 3 系统添加
|
|
RegistMethod int `gorm:"type:int;" json:"regist_method"` // 注册方式 1 短信登录 2 微信登录 3 系统添加
|
|
}
|
|
}
|
|
|
|
|
|
type AppUserRegist struct {
|
|
type AppUserRegist struct {
|
|
Username string `gorm:"type:varchar(50);index:username_name,unique" json:"username" validate:"required" min:"3" max:"50"` // 用户名
|
|
Username string `gorm:"type:varchar(50);index:username_name,unique" json:"username" validate:"required" min:"3" max:"50"` // 用户名
|
|
- Phone string `gorm:"type:varchar(50);" json:"phone" validate:"required" min:"11" max:"11"` // 手机号
|
|
|
|
|
|
+ Phone string `gorm:"type:varchar(50);" json:"phone"` // 手机号
|
|
Nickname string `gorm:"type:varchar(50);" json:"nickname"` // 昵称
|
|
Nickname string `gorm:"type:varchar(50);" json:"nickname"` // 昵称
|
|
Password string `gorm:"type:varchar(50);" json:"password" validate:"required" min:"6" max:"20"` // 密码
|
|
Password string `gorm:"type:varchar(50);" json:"password" validate:"required" min:"6" max:"20"` // 密码
|
|
AppID string `gorm:"type:varchar(50);not null;unique" json:"app_id" validate:"required"` // 应用id
|
|
AppID string `gorm:"type:varchar(50);not null;unique" json:"app_id" validate:"required"` // 应用id
|
|
- Code string `json:"code" validate:"required" min:"6" max:"6"` // 验证码
|
|
|
|
|
|
+ Code string `json:"code"` // 验证码
|
|
RegistMethod int `gorm:"type:int;" json:"regist_method"` // 注册方式 1 短信登录 2 微信登录 3 系统添加
|
|
RegistMethod int `gorm:"type:int;" json:"regist_method"` // 注册方式 1 短信登录 2 微信登录 3 系统添加
|
|
}
|
|
}
|
|
type AppUserDel struct {
|
|
type AppUserDel struct {
|
|
@@ -38,6 +38,59 @@ type AppUserDel struct {
|
|
AppID string `json:"app_id" validate:"required"`
|
|
AppID string `json:"app_id" validate:"required"`
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// AccountLogin 账号登录
|
|
|
|
+func (a AppUser) AccountLogin(appUser AppUserRegist) (e.Rescode, string) {
|
|
|
|
+ //TODO implement me
|
|
|
|
+ tableName := "appUser_" + appUser.AppID
|
|
|
|
+ tx := global.DBLink.Table(tableName)
|
|
|
|
+ if tx.Error != nil {
|
|
|
|
+ if strings.Contains(tx.Error.Error(), "Error 1146 (42S02)") {
|
|
|
|
+ return e.NOTTABLE, ""
|
|
|
|
+ }
|
|
|
|
+ return e.LOGINFAIL, ""
|
|
|
|
+ }
|
|
|
|
+ md5 := utils.MD5(appUser.Password)
|
|
|
|
+ tx.Select("username", "id", "password", "nickname", "phone").
|
|
|
|
+ Where("username=? and password=?", appUser.Username, md5).
|
|
|
|
+ Where("state=?", 1).First(&a)
|
|
|
|
+ token, err := utils.CreateToken(a.ID, a.Username, "user")
|
|
|
|
+ token = "interior:" + token
|
|
|
|
+ if err != nil {
|
|
|
|
+ return e.TokenIsFaild, ""
|
|
|
|
+ }
|
|
|
|
+ if tx.RowsAffected > 0 {
|
|
|
|
+ global.DBLink.Table(tableName).Where("id=?", a.ID).Update("last_login_time", utils.Time(time.Now()))
|
|
|
|
+ return e.SUCCESS, token
|
|
|
|
+ }
|
|
|
|
+ return e.ThePasswordIsWrongOrThePhoneNumberIsIncorrect, ""
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// CodeLogin 验证码登录
|
|
|
|
+func (a AppUser) CodeLogin(appUser AppUserRegist) (e.Rescode, string) {
|
|
|
|
+ //TODO implement me
|
|
|
|
+ result, err := global.Rdb.Get(context.Background(), appUser.Phone).Result()
|
|
|
|
+ if err != nil {
|
|
|
|
+ return e.TheVerificationCodeWasNotSent, ""
|
|
|
|
+ }
|
|
|
|
+ if result != appUser.Code {
|
|
|
|
+ return e.CodeIsError, ""
|
|
|
|
+ }
|
|
|
|
+ tableName := "appUser_" + appUser.AppID
|
|
|
|
+ tx := global.DBLink.Table(tableName)
|
|
|
|
+ tx.Select("username", "id", "password", "nickname", "phone").
|
|
|
|
+ Where("phone=?", appUser.Phone).First(&a)
|
|
|
|
+ token, err := utils.CreateToken(a.ID, a.Username, "user")
|
|
|
|
+ token = "interior:" + token
|
|
|
|
+ if a.Phone != "" {
|
|
|
|
+ global.DBLink.Table(tableName).Where("id=?", a.ID).Update("last_login_time", utils.Time(time.Now()))
|
|
|
|
+ return e.SUCCESS, token
|
|
|
|
+ } else {
|
|
|
|
+ return e.NOTREGIST, ""
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// DeleteAppUserByID 删除用户
|
|
func (a AppUser) DeleteAppUserByID(id int, tableName string) e.Rescode {
|
|
func (a AppUser) DeleteAppUserByID(id int, tableName string) e.Rescode {
|
|
//TODO implement me
|
|
//TODO implement me
|
|
tx := global.DBLink.Table(tableName).Where("id=?", id).Delete(&a)
|
|
tx := global.DBLink.Table(tableName).Where("id=?", id).Delete(&a)
|
|
@@ -46,6 +99,8 @@ func (a AppUser) DeleteAppUserByID(id int, tableName string) e.Rescode {
|
|
}
|
|
}
|
|
return e.SUCCESS
|
|
return e.SUCCESS
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// UpdateAppUser 更新用户
|
|
func (a AppUser) UpdateAppUser(appUser AppUser, tabaleName string) e.Rescode {
|
|
func (a AppUser) UpdateAppUser(appUser AppUser, tabaleName string) e.Rescode {
|
|
//TODO implement me
|
|
//TODO implement me
|
|
tx := global.DBLink.Table(tabaleName).Updates(appUser)
|
|
tx := global.DBLink.Table(tabaleName).Updates(appUser)
|
|
@@ -55,7 +110,8 @@ func (a AppUser) UpdateAppUser(appUser AppUser, tabaleName string) e.Rescode {
|
|
return e.SUCCESS
|
|
return e.SUCCESS
|
|
}
|
|
}
|
|
|
|
|
|
-func (a AppUser) GetAppUserList(params unity.QueryPageParams, tableName string, queryCond string) (result []AppUser, total int64, err error) {
|
|
|
|
|
|
+// GetAppUserList 获取用户列表
|
|
|
|
+func (a AppUser) GetAppUserList(params unity.CapQueryPageParams, tableName string, queryCond string) (result []AppUser, total int64, err error) {
|
|
query := global.DBLink.Table(tableName)
|
|
query := global.DBLink.Table(tableName)
|
|
if params.Query != "%%" {
|
|
if params.Query != "%%" {
|
|
query = query.Where(queryCond, params.Query)
|
|
query = query.Where(queryCond, params.Query)
|