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