打印机
This commit is contained in:
74
services/print_server/app.go
Normal file
74
services/print_server/app.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package print_server
|
||||
|
||||
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/putils"
|
||||
"github.com/gin-gonic/gin"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GetApps(c *gin.Context, userID string) (apps []*model.Apps, err error) {
|
||||
if userID == "" {
|
||||
return nil, fmt.Errorf("账号信息有误,请重新登录!")
|
||||
}
|
||||
return dao.GetApps(globals.GetDB(), 0, userID, "")
|
||||
}
|
||||
|
||||
func AddApp(c *gin.Context, code, name, mobile, userID string) (err error) {
|
||||
var (
|
||||
db = globals.GetDB()
|
||||
now = time.Now()
|
||||
)
|
||||
//if rcode := putils.GetKey(mobile); rcode == "" {
|
||||
// putils.DelKey(mobile)
|
||||
// return fmt.Errorf("验证码错误!")
|
||||
//} else if code != rcode {
|
||||
// putils.DelKey(mobile)
|
||||
// return fmt.Errorf("验证码错误!")
|
||||
//}
|
||||
//putils.DelKey(mobile)
|
||||
|
||||
if apps, _ := dao.GetApps(db, 0, userID, ""); len(apps) > 2 {
|
||||
return fmt.Errorf("同一个账号最多只能建3个app!")
|
||||
}
|
||||
if apps, _ := dao.GetApps(db, 0, "", 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
|
||||
}
|
||||
|
||||
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