This commit is contained in:
suyl
2021-07-07 18:59:57 +08:00
parent ee1f00ab29
commit 21737e5cd9
5 changed files with 70 additions and 4 deletions

View File

@@ -2,10 +2,13 @@ package services
import (
"fmt"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-print/dao"
"git.rosy.net.cn/jx-print/globals"
"git.rosy.net.cn/jx-print/model"
putils "git.rosy.net.cn/jx-print/utils"
"github.com/gin-gonic/gin"
"time"
)
func GetApps(c *gin.Context, user *model.User) (apps []*model.Apps, err error) {
@@ -15,5 +18,40 @@ func GetApps(c *gin.Context, user *model.User) (apps []*model.Apps, err error) {
if user.UserID == "" {
return nil, fmt.Errorf("账号信息有误,请重新登录!")
}
return dao.GetApps(globals.GetDB(), user.UserID)
return dao.GetApps(globals.GetDB(), user.UserID, "")
}
func AddApp(c *gin.Context, code, name, mobile, userID string) (err error) {
var (
db = globals.GetDB()
now = time.Now()
)
if rcode, ok := putils.GetKet(mobile).(string); !ok {
putils.DelKey(mobile)
return err
} else if code != rcode {
putils.DelKey(mobile)
return fmt.Errorf("验证码错误!")
}
putils.DelKey(mobile)
if apps, _ := dao.GetApps(db, userID, ""); len(apps) > 2 {
return fmt.Errorf("同一个账号最多只能建3个app")
}
if apps, _ := dao.GetApps(db, "", mobile); len(apps) > 0 {
return fmt.Errorf("同一个手机号只能建1个app")
}
apps := &model.Apps{
CreatedAt: &now,
UpdatedAt: &now,
DeletedAt: &utils.DefaultTimeValue,
Name: name,
Type: 0,
Status: 1,
AppKey: putils.RandStringBytes(16),
UserID: userID,
Mobile: mobile,
}
err = dao.Insert(db, apps)
return err
}