delapp get menu
This commit is contained in:
@@ -11,14 +11,11 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func GetApps(c *gin.Context, user *model.User) (apps []*model.Apps, err error) {
|
||||
if user == nil {
|
||||
return nil, fmt.Errorf("未获取到账号信息!")
|
||||
}
|
||||
if user.UserID == "" {
|
||||
func GetApps(c *gin.Context, userID string) (apps []*model.Apps, err error) {
|
||||
if userID == "" {
|
||||
return nil, fmt.Errorf("账号信息有误,请重新登录!")
|
||||
}
|
||||
return dao.GetApps(globals.GetDB(), user.UserID, "")
|
||||
return dao.GetApps(globals.GetDB(), 0, userID, "")
|
||||
}
|
||||
|
||||
func AddApp(c *gin.Context, code, name, mobile, userID string) (err error) {
|
||||
@@ -35,10 +32,10 @@ func AddApp(c *gin.Context, code, name, mobile, userID string) (err error) {
|
||||
}
|
||||
putils.DelKey(mobile)
|
||||
|
||||
if apps, _ := dao.GetApps(db, userID, ""); len(apps) > 2 {
|
||||
if apps, _ := dao.GetApps(db, 0, userID, ""); len(apps) > 2 {
|
||||
return fmt.Errorf("同一个账号最多只能建3个app!")
|
||||
}
|
||||
if apps, _ := dao.GetApps(db, "", mobile); len(apps) > 0 {
|
||||
if apps, _ := dao.GetApps(db, 0, "", mobile); len(apps) > 0 {
|
||||
return fmt.Errorf("同一个手机号只能建1个app!")
|
||||
}
|
||||
apps := &model.Apps{
|
||||
@@ -55,3 +52,23 @@ func AddApp(c *gin.Context, code, name, mobile, userID string) (err error) {
|
||||
err = dao.Insert(db, apps)
|
||||
return err
|
||||
}
|
||||
|
||||
func DelApp(c *gin.Context, appID int, userID string) (err error) {
|
||||
var (
|
||||
db = globals.GetDB()
|
||||
now = time.Now()
|
||||
)
|
||||
if appID == 0 {
|
||||
return fmt.Errorf("参数错误!appID :%v", appID)
|
||||
}
|
||||
if apps, err2 := dao.GetApps(db, appID, userID, ""); err2 != nil {
|
||||
return err2
|
||||
} else if len(apps) == 0 {
|
||||
return fmt.Errorf("未查询到此应用!app_id :%d, user_id: %s", appID, userID)
|
||||
} else {
|
||||
app := apps[0]
|
||||
app.DeletedAt = &now
|
||||
err = dao.Update(db, app, model.FieldDeletedAt)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user