修改打印机
This commit is contained in:
@@ -71,7 +71,7 @@ func (p *Print) GetPrinters(c *gin.Context) {
|
||||
}
|
||||
|
||||
controllers.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = printServer.GetPrinters(param.AppID, param.PrintNo, param.Name, param.Status, param.IsOnline, param.Offset, param.PageSize)
|
||||
retVal, err = printServer.GetPrinters(param.AppID, param.PrintNo, param.Name, param.Status, param.IsOnline, param.Offset, param.PageSize, tokenInfo.User.UserID)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
@@ -138,9 +138,9 @@ func (p *Print) UpdatePrinter(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// TestPrint 更新打印机 POST
|
||||
// @Title 查询打印机
|
||||
// @Description 查询打印机
|
||||
// TestPrint 测试打印 POST
|
||||
// @Title 测试打印
|
||||
// @Description 测试打印
|
||||
// @Param token cookie string true "用户登录token"
|
||||
// @Param data body app_model.UpdatePrintReq true "请求参数"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
|
||||
@@ -40,7 +40,7 @@ func GetPrinters(db *sqlx.DB, appID int, printNo string, status, statusNeq, flow
|
||||
return printers, err
|
||||
}
|
||||
|
||||
func GetPrintersPage(db *sqlx.DB, appID int, printNo, name string, status, isOnline, offset, pageSize int) (page *model.PagedInfo, err error) {
|
||||
func GetPrintersPage(db *sqlx.DB, appID int, printNo, name string, status, isOnline, offset, pageSize int, userId string) (page *model.PagedInfo, err error) {
|
||||
var (
|
||||
printers []*model.Printer
|
||||
count int
|
||||
@@ -76,6 +76,10 @@ func GetPrintersPage(db *sqlx.DB, appID int, printNo, name string, status, isOnl
|
||||
sqlOhter += " AND is_online = ?"
|
||||
sqlParams = append(sqlParams, isOnline)
|
||||
}
|
||||
if userId != "" {
|
||||
sqlOhter += " AND user_id = ?"
|
||||
sqlParams = append(sqlParams, userId)
|
||||
}
|
||||
//查总数
|
||||
row := db.DB.QueryRow(sqlCount+sqlOhter, sqlParams...)
|
||||
if err = row.Scan(&count); err != nil {
|
||||
|
||||
@@ -188,20 +188,22 @@ type Printer struct {
|
||||
Volume int `json:"volume"` //音量,1-5 ,对应打印机2-10
|
||||
FlowFlag int `json:"flow_flag" db:"flow_flag"` //是否超流量了,1表示超了
|
||||
OfflineCount int `json:"-" db:"offline_count"` //掉线次数
|
||||
UserId string `json:"user_id" db:"user_id"` //打印机所属用户
|
||||
}
|
||||
|
||||
type PrintMsg struct {
|
||||
ID int `json:"id" db:"id"`
|
||||
CreatedAt *time.Time `json:"created_at" db:"created_at"`
|
||||
UpdatedAt *time.Time `json:"updated_at" db:"updated_at"`
|
||||
LastOperator string `json:"last_operator" db:"last_operator"`
|
||||
DeletedAt *time.Time `json:"deleted_at" db:"deleted_at"`
|
||||
MsgID string `json:"msg_id" db:"msg_id"` //消息ID
|
||||
PrintNo string `json:"print_no" db:"print_no"` //打印机编号
|
||||
OrderNo string `json:"order_no" db:"order_no"` //订单序号
|
||||
Content string `json:"content"` //订单内容
|
||||
Status int `json:"status"` //打印状态
|
||||
Comment string `json:"comment"` //失败原因
|
||||
ID int `json:"id" db:"id"`
|
||||
CreatedAt *time.Time `json:"created_at" db:"created_at"`
|
||||
UpdatedAt *time.Time `json:"updated_at" db:"updated_at"`
|
||||
LastOperator string `json:"last_operator" db:"last_operator"`
|
||||
DeletedAt *time.Time `json:"deleted_at" db:"deleted_at"`
|
||||
MsgID string `json:"msg_id" db:"msg_id"` //消息ID
|
||||
PrintNo string `json:"print_no" db:"print_no"` //打印机编号
|
||||
OrderNo string `json:"order_no" db:"order_no"` //订单序号
|
||||
Content string `json:"content"` //订单内容
|
||||
Status int `json:"status"` //打印状态
|
||||
Comment string `json:"comment"` //失败原因
|
||||
ContentEncryption string `orm:"type(text)" json:"content_encryption"` //订单类容进制文件
|
||||
}
|
||||
|
||||
//流量支出
|
||||
|
||||
@@ -7,10 +7,16 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/gopay-main/wechat"
|
||||
"git.rosy.net.cn/jx-print/dao"
|
||||
"git.rosy.net.cn/jx-print/globals"
|
||||
"git.rosy.net.cn/jx-print/model"
|
||||
wxLogin "git.rosy.net.cn/jx-print/model/app_model"
|
||||
"git.rosy.net.cn/jx-print/services/api"
|
||||
"github.com/gin-gonic/gin"
|
||||
"reflect"
|
||||
"time"
|
||||
)
|
||||
|
||||
type UserLogin struct {
|
||||
@@ -18,100 +24,94 @@ type UserLogin struct {
|
||||
|
||||
// WxLogin 授权登录
|
||||
func (u *UserLogin) WxLogin(ctx *gin.Context, code, phone string) (*model.User, error) {
|
||||
//// 生成openId
|
||||
//openObj, err := wechat.GetOauth2AccessToken(ctx, wxLogin.WeChatAPPID, wxLogin.WeChatAPPSecret, code)
|
||||
//if err != nil {
|
||||
// return nil, err
|
||||
//}
|
||||
//
|
||||
//if openObj.Errcode != 0 {
|
||||
// return nil, errors.New(openObj.Errmsg)
|
||||
//}
|
||||
//
|
||||
//// 检查用户是否存在
|
||||
//users, err := dao.GetUsers(globals.GetDB(), "", "", phone, "")
|
||||
//if err != nil {
|
||||
// return nil, err
|
||||
//}
|
||||
//if len(users) > 1 {
|
||||
// return nil, errors.New("数据异常,用户电话不唯一,联系管理员")
|
||||
//}
|
||||
//
|
||||
//// 获取用户信息,是否注册
|
||||
//userInfo, err := wechat.GetOauth2UserInfo(ctx, openObj.AccessToken, openObj.Openid)
|
||||
//if err != nil {
|
||||
// return nil, err
|
||||
//}
|
||||
//
|
||||
//var userObj *model.User
|
||||
//timeNow := time.Now()
|
||||
//switch len(users) {
|
||||
//case 0:
|
||||
// // 用户不存在,创建并返回用户
|
||||
// userBase := &model.User{
|
||||
// CreatedAt: &timeNow,
|
||||
// UpdatedAt: &timeNow,
|
||||
// LastOperator: "系统新增",
|
||||
// DeletedAt: &utils.DefaultTimeValue,
|
||||
// UserID: utils.GetUUID(),
|
||||
// Password: "",
|
||||
// Name: userInfo.Nickname,
|
||||
// Mobile: phone,
|
||||
// Email: "",
|
||||
// Avatar: userInfo.Headimgurl,
|
||||
// Status: 1,
|
||||
// Type: 1,
|
||||
// Company: "",
|
||||
// CityCode: 0,
|
||||
// DistrictCode: 0,
|
||||
// Address: "",
|
||||
// IDCardNo: "",
|
||||
// Remark: "",
|
||||
// LastLoginAt: &timeNow,
|
||||
// LastLoginIP: ctx.ClientIP(),
|
||||
// LastLoginType: model.OrderOriginWxMini,
|
||||
// OpenId: userInfo.Openid,
|
||||
// UnionId: userInfo.Unionid,
|
||||
// }
|
||||
// if err := dao.CreateUserWx(userBase); err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// userObj = userBase
|
||||
//case 1:
|
||||
// // 用户使用电话号码登录,未使用微信登录
|
||||
// if users[0].OpenId == "" {
|
||||
// users[0].Name = userInfo.Nickname
|
||||
// users[0].Avatar = userInfo.Headimgurl
|
||||
// users[0].OpenId = userInfo.Openid
|
||||
// users[0].UnionId = userInfo.Unionid
|
||||
// }
|
||||
// // 用户存在,判断用户
|
||||
// users[0].UpdatedAt = &timeNow
|
||||
// users[0].LastOperator = users[0].Name
|
||||
// users[0].LastLoginIP = ctx.ClientIP()
|
||||
// if err := dao.UpdateUserWx(users[0], []string{"updated_at", "last_operator", "last_login_ip", "name", "avatar", "open_id", "union_id"}); err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// userObj = users[0]
|
||||
//}
|
||||
//
|
||||
//return userObj, err
|
||||
return nil, nil
|
||||
// 生成openId
|
||||
openObj, err := api.WeixinMiniAPI.SNSRetrieveToken(code)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 检查用户是否存在
|
||||
users, err := dao.GetUsers(globals.GetDB(), "", "", phone, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(users) > 1 {
|
||||
return nil, errors.New("数据异常,用户电话不唯一,联系管理员")
|
||||
}
|
||||
|
||||
// 获取用户信息,是否注册
|
||||
userInfo, err := wechat.GetOauth2UserInfo(ctx, openObj.AccessToken, openObj.OpenID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var userObj *model.User
|
||||
timeNow := time.Now()
|
||||
switch len(users) {
|
||||
case 0:
|
||||
// 用户不存在,创建并返回用户
|
||||
userBase := &model.User{
|
||||
CreatedAt: &timeNow,
|
||||
UpdatedAt: &timeNow,
|
||||
LastOperator: "系统新增",
|
||||
DeletedAt: &utils.DefaultTimeValue,
|
||||
UserID: utils.GetUUID(),
|
||||
Password: "",
|
||||
Name: userInfo.Nickname,
|
||||
Mobile: phone,
|
||||
Email: "",
|
||||
Avatar: userInfo.Headimgurl,
|
||||
Status: 1,
|
||||
Type: 1,
|
||||
Company: "",
|
||||
CityCode: 0,
|
||||
DistrictCode: 0,
|
||||
Address: "",
|
||||
IDCardNo: "",
|
||||
Remark: "",
|
||||
LastLoginAt: &timeNow,
|
||||
LastLoginIP: ctx.ClientIP(),
|
||||
LastLoginType: model.OrderOriginWxMini,
|
||||
OpenId: userInfo.Openid,
|
||||
UnionId: userInfo.Unionid,
|
||||
}
|
||||
if err := dao.CreateUserWx(userBase); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
userObj = userBase
|
||||
case 1:
|
||||
// 用户使用电话号码登录,未使用微信登录
|
||||
if users[0].OpenId == "" {
|
||||
users[0].Name = userInfo.Nickname
|
||||
users[0].Avatar = userInfo.Headimgurl
|
||||
users[0].OpenId = userInfo.Openid
|
||||
users[0].UnionId = userInfo.Unionid
|
||||
}
|
||||
// 用户存在,判断用户
|
||||
users[0].UpdatedAt = &timeNow
|
||||
users[0].LastOperator = users[0].Name
|
||||
users[0].LastLoginIP = ctx.ClientIP()
|
||||
if err := dao.UpdateUserWx(users[0], []string{"updated_at", "last_operator", "last_login_ip", "name", "avatar", "open_id", "union_id"}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
userObj = users[0]
|
||||
}
|
||||
|
||||
return userObj, err
|
||||
}
|
||||
|
||||
// GetUserPhoneNum 解密用户手机号
|
||||
func (u *UserLogin) GetUserPhoneNum(param *wxLogin.WeChatPhoneNumberParam) (string, error) {
|
||||
//sessionInfo, err := api.WeixinMiniAPI.SNSCode2Session(param.Code)
|
||||
//if err != nil {
|
||||
// return "", err
|
||||
//}
|
||||
//
|
||||
//weChatLogin := new(wechat.UserPhone)
|
||||
//if err := DecryptOpenDataToStruct(param.EncryptedData, param.IV, sessionInfo.SessionKey, weChatLogin); err != nil {
|
||||
// return "", err
|
||||
//}
|
||||
//return weChatLogin.PhoneNumber, nil
|
||||
return "", nil
|
||||
sessionInfo, err := api.WeixinMiniAPI.SNSCode2Session(param.Code)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
weChatLogin := new(wechat.UserPhone)
|
||||
if err := DecryptOpenDataToStruct(param.EncryptedData, param.IV, sessionInfo.SessionKey, weChatLogin); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return weChatLogin.PhoneNumber, nil
|
||||
}
|
||||
|
||||
// DecryptOpenDataToStruct 解密开放数据到结构体
|
||||
@@ -148,11 +148,24 @@ func DecryptOpenDataToStruct(encryptedData, iv, sessionKey string, beanPtr inter
|
||||
blockMode = cipher.NewCBCDecrypter(block, ivKey)
|
||||
plainText = make([]byte, len(cipherText))
|
||||
blockMode.CryptBlocks(plainText, cipherText)
|
||||
//if len(plainText) > 0 {
|
||||
// plainText = xaes.PKCS7UnPadding(plainText)
|
||||
//}
|
||||
if len(plainText) > 0 {
|
||||
plainText = PKCS7UnPadding(plainText)
|
||||
}
|
||||
if err = json.Unmarshal(plainText, beanPtr); err != nil {
|
||||
return fmt.Errorf("json.Marshal(%s):%w", string(plainText), err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 解密填充模式(去除补全码) PKCS7UnPadding
|
||||
// 解密时,需要在最后面去掉加密时添加的填充byte
|
||||
func PKCS7UnPadding(origData []byte) (bs []byte) {
|
||||
length := len(origData)
|
||||
unPaddingNumber := int(origData[length-1]) // 找到Byte数组最后的填充byte 数字
|
||||
if unPaddingNumber <= 16 {
|
||||
bs = origData[:(length - unPaddingNumber)] // 只截取返回有效数字内的byte数组
|
||||
} else {
|
||||
bs = origData
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ func AddPrinters(tokenInfo *model.TokenInfo, appID int, printInfo []*model.Print
|
||||
continue
|
||||
}
|
||||
printers, _ := dao.GetPrinters(db, appID, v.PrintNo, 0, 0, 0)
|
||||
if len(printers) > 0 {
|
||||
errs = append(errs, fmt.Errorf("此打印机已被其他应用绑定!print_no :%s 。", v.PrintNo))
|
||||
if len(printers) != 0 && printers[0].UserId != "system" {
|
||||
errs = append(errs, fmt.Errorf("打印机已经被绑定!print_no :%s 。", v.PrintNo))
|
||||
continue
|
||||
}
|
||||
printer := &model.Printer{
|
||||
@@ -45,9 +45,16 @@ func AddPrinters(tokenInfo *model.TokenInfo, appID int, printInfo []*model.Print
|
||||
IsOnline: model.PrinterOffline,
|
||||
Sound: "sounda",
|
||||
Volume: 4,
|
||||
UserId: tokenInfo.User.UserID,
|
||||
}
|
||||
if err = dao.Insert(db, printer); err != nil {
|
||||
errs = append(errs, err)
|
||||
if len(printers) > 0 {
|
||||
if err = dao.Update(db, printer, "UserId"); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
} else {
|
||||
if err = dao.Insert(db, printer); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(errs) > 0 {
|
||||
@@ -56,8 +63,8 @@ func AddPrinters(tokenInfo *model.TokenInfo, appID int, printInfo []*model.Print
|
||||
return err
|
||||
}
|
||||
|
||||
func GetPrinters(appID int, printNo, name string, status, isOnline, offset, pageSize int) (page *model.PagedInfo, err error) {
|
||||
return dao.GetPrintersPage(globals.GetDB(), appID, printNo, name, status, isOnline, offset, pageSize)
|
||||
func GetPrinters(appID int, printNo, name string, status, isOnline, offset, pageSize int, userId string) (page *model.PagedInfo, err error) {
|
||||
return dao.GetPrintersPage(globals.GetDB(), appID, printNo, name, status, isOnline, offset, pageSize, userId)
|
||||
}
|
||||
|
||||
func DelPrinters(appID int, tokenInfo *model.TokenInfo, printNos []string) (err error) {
|
||||
@@ -82,6 +89,10 @@ func DelPrinters(appID int, tokenInfo *model.TokenInfo, printNos []string) (err
|
||||
errs = append(errs, fmt.Errorf("未在该应用下查到此打印机!app_id: %d, print_no: %s", appID, v))
|
||||
continue
|
||||
}
|
||||
if printers[0].UserId != tokenInfo.User.UserID {
|
||||
errs = append(errs, fmt.Errorf("该打印机不属于此用户 :%s 。", v))
|
||||
continue
|
||||
}
|
||||
|
||||
printer := printers[0]
|
||||
printer.DeletedAt = &now
|
||||
|
||||
@@ -56,6 +56,7 @@ func AddPrinters(c *gin.Context, tokenInfo *model.TokenInfo, appID int, printInf
|
||||
IsOnline: model.PrinterOffline,
|
||||
Sound: sounda,
|
||||
Volume: 4,
|
||||
UserId: "system",
|
||||
}
|
||||
if err = dao.Insert(db, printer); err != nil {
|
||||
errs = append(errs, err)
|
||||
|
||||
Reference in New Issue
Block a user