修改打印模板
This commit is contained in:
120
controllers/app/print_temp.go
Normal file
120
controllers/app/print_temp.go
Normal file
@@ -0,0 +1,120 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-print/controllers/controller"
|
||||
"git.rosy.net.cn/jx-print/model"
|
||||
tempModel "git.rosy.net.cn/jx-print/model/app_model"
|
||||
printServer "git.rosy.net.cn/jx-print/services/print_server/app_server"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// AddOrUpdateTemp 模板添加 POST
|
||||
// @Title 模板添加
|
||||
// @Description 模板添加
|
||||
// @Param token cookie string true "用户登录token"
|
||||
// @Param data body app_model.AddTemp true "请求参数"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /addOrUpdateTemp [post]
|
||||
func (p *Print) AddOrUpdateTemp(c *gin.Context) {
|
||||
var (
|
||||
err error
|
||||
tokenInfo *model.TokenInfo
|
||||
param = tempModel.AddTemp{}
|
||||
tempServer = printServer.TempServer{}
|
||||
)
|
||||
if err = c.ShouldBind(¶m); err != nil {
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
param.UserId = tokenInfo.User.UserID
|
||||
|
||||
controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
err = tempServer.AddOrUpdateTemp(¶m)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteTemp 删除用户自定义模板
|
||||
// @Title 删除用户自定义模板
|
||||
// @Description 删除用户自定义模板
|
||||
// @Param token cookie string true "用户登录token"
|
||||
// @Param data body app_model.DeleteTemp true "请求参数"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /deleteTemp [delete]
|
||||
func (p *Print) DeleteTemp(c *gin.Context) {
|
||||
var (
|
||||
err error
|
||||
tokenInfo *model.TokenInfo
|
||||
param = tempModel.DeleteTemp{}
|
||||
tempServer = printServer.TempServer{}
|
||||
)
|
||||
if err = c.ShouldBind(¶m); err != nil {
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
err = tempServer.DeleteTemp(param.ID, tokenInfo.User.UserID)
|
||||
return "", "", err
|
||||
})
|
||||
}
|
||||
|
||||
// GetUserTempList 获取用户模板,模板不足时填充系统模板
|
||||
// @Title 获取用户模板
|
||||
// @Description 获取用户模板
|
||||
// @Param token cookie string true "用户登录token"
|
||||
// @Param data body app_model.DeleteTemp true "请求参数"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /getUserTempList [get]
|
||||
func (p *Print) GetUserTempList(c *gin.Context) {
|
||||
var (
|
||||
err error
|
||||
tokenInfo *model.TokenInfo
|
||||
param = tempModel.DeleteTemp{}
|
||||
tempServer = printServer.TempServer{}
|
||||
)
|
||||
if err = c.ShouldBind(¶m); err != nil {
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = tempServer.QueryTempList(tokenInfo.User.UserID)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// SwitchTemp 切换模板打印模板
|
||||
// @Title 切换模板
|
||||
// @Description 切换模板
|
||||
// @Param token cookie string true "用户登录token"
|
||||
// @Param data body app_model.DeleteTemp true "请求参数"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /switchTemp [get]
|
||||
func (p *Print) SwitchTemp(c *gin.Context) {
|
||||
var (
|
||||
err error
|
||||
tokenInfo *model.TokenInfo
|
||||
param = tempModel.DeleteTemp{}
|
||||
tempServer = printServer.TempServer{}
|
||||
)
|
||||
if err = c.ShouldBind(¶m); err != nil {
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
err = tempServer.SwitchTemp(tokenInfo.User.UserID, param.ID)
|
||||
return "", "", err
|
||||
})
|
||||
}
|
||||
85
controllers/app/wx_login.go
Normal file
85
controllers/app/wx_login.go
Normal file
@@ -0,0 +1,85 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-print/controllers/controller"
|
||||
"git.rosy.net.cn/jx-print/model"
|
||||
"git.rosy.net.cn/jx-print/model/app_model"
|
||||
"git.rosy.net.cn/jx-print/services/print_server/app_server"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Auth2Controller struct{}
|
||||
|
||||
var Auth2ControllerController = new(Auth2Controller)
|
||||
|
||||
// Login 登录接口
|
||||
// @Title 登录接口
|
||||
// @Description 登录接口(微信与公众号登录不能直接调用此接口)
|
||||
// @Param data body app_model.WxLoginReq true "请求参数"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /Login [post]
|
||||
func (a *Auth2Controller) Login(c *gin.Context) {
|
||||
// 参数绑定
|
||||
var (
|
||||
err error
|
||||
params *app_model.WxLoginReq
|
||||
service = app_server.UserLogin{}
|
||||
)
|
||||
|
||||
if err = c.ShouldBind(¶ms); err != nil {
|
||||
c.JSON(http.StatusOK, &model.CallBack{
|
||||
Code: model.ErrCodeNormal,
|
||||
Desc: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
user, err := service.WxLogin(c, params.Code, params.Phone)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
// 获取token
|
||||
token, err := controller.SetToken(user)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
return map[string]interface{}{"token": token, "user": user}, "", nil
|
||||
})
|
||||
}
|
||||
|
||||
// GetUserPhoneByWeChat 获取用户电话号码
|
||||
// @Title 获取用户电话号码
|
||||
// @Description 获取用户电话号码
|
||||
// @Param data body app_model.WeChatPhoneNumberParam true "请求参数"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /GetUserPhone [post]
|
||||
func (a *Auth2Controller) GetUserPhoneByWeChat(c *gin.Context) {
|
||||
// 参数绑定
|
||||
var (
|
||||
err error
|
||||
params *app_model.WeChatPhoneNumberParam
|
||||
service = app_server.UserLogin{}
|
||||
)
|
||||
|
||||
if err = c.ShouldBind(¶ms); err != nil {
|
||||
c.JSON(http.StatusOK, &model.CallBack{
|
||||
Code: model.ErrCodeNormal,
|
||||
Desc: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
phone, err := service.GetUserPhoneNum(params)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
return map[string]interface{}{"phone": phone}, "", nil
|
||||
})
|
||||
}
|
||||
208
controllers/app/wx_print.go
Normal file
208
controllers/app/wx_print.go
Normal file
@@ -0,0 +1,208 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-print/controllers/controller"
|
||||
"git.rosy.net.cn/jx-print/model"
|
||||
print "git.rosy.net.cn/jx-print/model/app_model"
|
||||
"git.rosy.net.cn/jx-print/putils"
|
||||
printServer "git.rosy.net.cn/jx-print/services/print_server/app_server"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Print struct{}
|
||||
|
||||
var PrintController = new(Print)
|
||||
|
||||
// AddPrinters 添加打印机 POST
|
||||
// @Title 添加打印机
|
||||
// @Description 添加打印机
|
||||
// @Param token cookie string true "用户登录token"
|
||||
// @Param data body app_model.AddPrintReq true "请求参数"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /addPrinters [post]
|
||||
func (p *Print) AddPrinters(c *gin.Context) {
|
||||
var (
|
||||
err error
|
||||
tokenInfo *model.TokenInfo
|
||||
param = print.AddPrintReq{}
|
||||
printInfo []*model.PrintInfo
|
||||
)
|
||||
|
||||
if err = c.ShouldBind(¶m); err != nil {
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
if err = putils.UnmarshalUseNumber([]byte(param.Prints), &printInfo); err != nil {
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
err = printServer.AddPrinters(tokenInfo, param.AppID, printInfo)
|
||||
return retVal, "", err
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// GetPrinters 查询打印机 GET
|
||||
// @Title 查询打印机
|
||||
// @Description 查询打印机
|
||||
// @Param token cookie string true "用户登录token"
|
||||
// @Param data body app_model.QueryPrintReq true "请求参数"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /getPrinters [get]
|
||||
func (p *Print) GetPrinters(c *gin.Context) {
|
||||
var (
|
||||
err error
|
||||
tokenInfo *model.TokenInfo
|
||||
param = print.QueryPrintReq{}
|
||||
)
|
||||
if err = c.ShouldBind(¶m); err != nil {
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
|
||||
controller.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, tokenInfo.User.UserID)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// DelPrinters 删除打印机 POST
|
||||
// @Title 删除打印机
|
||||
// @Description 删除打印机
|
||||
// @Param token cookie string true "用户登录token"
|
||||
// @Param data body app_model.QueryPrintReq true "请求参数"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /delPrinters [post]
|
||||
func (p *Print) DelPrinters(c *gin.Context) {
|
||||
var (
|
||||
err error
|
||||
tokenInfo *model.TokenInfo
|
||||
param = print.DeletePrintReq{}
|
||||
printNos []string
|
||||
)
|
||||
if err = c.ShouldBind(¶m); err != nil {
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
if err = putils.UnmarshalUseNumber([]byte(param.PrintNos), &printNos); err != nil {
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
err = printServer.DelPrinters(param.AppID, tokenInfo, printNos)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// UpdatePrinter 更新打印机 POST
|
||||
// @Title 查询打印机
|
||||
// @Description 查询打印机
|
||||
// @Param token cookie string true "用户登录token"
|
||||
// @Param data body app_model.UpdatePrintReq true "请求参数"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /updatePrinter [post]
|
||||
func (p *Print) UpdatePrinter(c *gin.Context) {
|
||||
var (
|
||||
err error
|
||||
tokenInfo *model.TokenInfo
|
||||
param = print.UpdatePrintReq{}
|
||||
)
|
||||
if err = c.ShouldBind(¶m); err != nil {
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
if !controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
err = printServer.UpdatePrinter(param.AppID, tokenInfo, param.PrintNo, param.Name, param.Sound, param.Volume)
|
||||
return retVal, "", err
|
||||
}) {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// TestPrint 更新打印机 POST
|
||||
// @Title 查询打印机
|
||||
// @Description 查询打印机
|
||||
// @Param token cookie string true "用户登录token"
|
||||
// @Param data body app_model.UpdatePrintReq true "请求参数"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /testPrinter [post]
|
||||
func (p *Print) TestPrint(c *gin.Context) {
|
||||
var (
|
||||
err error
|
||||
tokenInfo *model.TokenInfo
|
||||
param = print.TestPrintReq{}
|
||||
)
|
||||
if err = c.ShouldBind(¶m); err != nil {
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = printServer.TestPrint(param.AppID, tokenInfo, param.PrintNo, param.OrderNo, param.Content)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// GetPrintMessages 获取打印机消息 POST
|
||||
// @Title 获取打印机消息
|
||||
// @Description 获取打印机消息
|
||||
// @Param token cookie string true "用户登录token"
|
||||
// @Param data body app_model.UpdatePrintReq true "请求参数"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /getPrintMessages [get]
|
||||
func (p *Print) GetPrintMessages(c *gin.Context) {
|
||||
var (
|
||||
err error
|
||||
tokenInfo *model.TokenInfo
|
||||
param = print.GetPrintMsg{}
|
||||
)
|
||||
if err = c.ShouldBind(¶m); err != nil {
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
|
||||
controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = printServer.GetPrintMessages(param.AppID, tokenInfo, param.PrintNo, param.MsgID, param.BeginAt, param.EndAt, param.Offset, param.PageSize)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// StatPrinterReport 查询打印统计(首页) GET
|
||||
func (p *Print) StatPrinterReport(c *gin.Context) {
|
||||
var (
|
||||
tokenInfo *model.TokenInfo
|
||||
)
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = printServer.GetPrinterReport(tokenInfo)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-print/controllers/controller"
|
||||
"git.rosy.net.cn/jx-print/globals"
|
||||
"git.rosy.net.cn/jx-print/model"
|
||||
"git.rosy.net.cn/jx-print/services/print_server"
|
||||
@@ -13,10 +14,10 @@ func GetApps(c *gin.Context) {
|
||||
var (
|
||||
tokenInfo *model.TokenInfo
|
||||
)
|
||||
if tokenInfo = checkToken(c); tokenInfo == nil {
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
if !callFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
if !controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = print_server.GetApps(c, tokenInfo.User.UserID)
|
||||
return retVal, "", err
|
||||
}) {
|
||||
@@ -39,17 +40,17 @@ func AddApp(c *gin.Context) {
|
||||
param = &AddAppParam{}
|
||||
)
|
||||
if err = c.ShouldBind(¶m); err != nil {
|
||||
c.JSON(http.StatusOK, &CallBack{
|
||||
c.JSON(http.StatusOK, &model.CallBack{
|
||||
Code: model.ErrCodeNormal,
|
||||
Desc: err.Error(),
|
||||
})
|
||||
globals.SugarLogger.Debugf("End API :%s error:%v:", c.Request.URL, err)
|
||||
return
|
||||
}
|
||||
if tokenInfo = checkToken(c); tokenInfo == nil {
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
if !callFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
if !controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
err = print_server.AddApp(c, param.Code, param.Name, param.Mobile, tokenInfo.User.UserID)
|
||||
return retVal, "", err
|
||||
}) {
|
||||
@@ -68,17 +69,17 @@ func DelApp(c *gin.Context) {
|
||||
}{}
|
||||
)
|
||||
if err = c.ShouldBind(¶m); err != nil {
|
||||
c.JSON(http.StatusOK, &CallBack{
|
||||
c.JSON(http.StatusOK, &model.CallBack{
|
||||
Code: model.ErrCodeNormal,
|
||||
Desc: err.Error(),
|
||||
})
|
||||
globals.SugarLogger.Debugf("End API :%s error:%v:", c.Request.URL, err)
|
||||
return
|
||||
}
|
||||
if tokenInfo = checkToken(c); tokenInfo == nil {
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
if !callFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
if !controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
err = print_server.DelApp(c, param.AppID, tokenInfo.User.UserID)
|
||||
return retVal, "", err
|
||||
}) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-print/globals"
|
||||
"git.rosy.net.cn/jx-print/model"
|
||||
"git.rosy.net.cn/jx-print/services/api"
|
||||
"git.rosy.net.cn/jx-print/services/print_server"
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -16,7 +17,7 @@ type CallbackController struct {
|
||||
func (t *CallbackController) Msg(c *gin.Context) {
|
||||
data, _ := ioutil.ReadAll(c.Request.Body)
|
||||
globals.SugarLogger.Debugf("callback msg : %v , user-agent :%s", string(data), c.Request.UserAgent())
|
||||
c.JSON(200, &CallBack{})
|
||||
c.JSON(200, &model.CallBack{})
|
||||
}
|
||||
|
||||
func (t *CallbackController) TlPayCallback(c *gin.Context) {
|
||||
@@ -27,5 +28,5 @@ func (t *CallbackController) TlPayCallback(c *gin.Context) {
|
||||
globals.SugarLogger.Debugf("tonglianapi callback callbackResponse:%s", utils.Format4Output(call, true))
|
||||
print_server.PayTLCallback(call)
|
||||
}
|
||||
c.JSON(200, &CallBack{})
|
||||
c.JSON(200, &model.CallBack{})
|
||||
}
|
||||
|
||||
@@ -1,29 +1,26 @@
|
||||
package controllers
|
||||
package controller
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-print/globals"
|
||||
"git.rosy.net.cn/jx-print/model"
|
||||
wxConst "git.rosy.net.cn/jx-print/model/app_model"
|
||||
"git.rosy.net.cn/jx-print/putils"
|
||||
"git.rosy.net.cn/jx-print/services/print_server"
|
||||
"github.com/dchest/captcha"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type CallBack struct {
|
||||
Data string `json:"data"`
|
||||
Code string `json:"code"`
|
||||
Desc string `json:"desc"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
globals.SugarLogger.Debugf("test init ...")
|
||||
}
|
||||
|
||||
func checkToken(c *gin.Context) (tokenInfo *model.TokenInfo) {
|
||||
func CheckToken(c *gin.Context) (tokenInfo *model.TokenInfo) {
|
||||
var (
|
||||
cookie *http.Cookie
|
||||
err error
|
||||
@@ -33,9 +30,9 @@ func checkToken(c *gin.Context) (tokenInfo *model.TokenInfo) {
|
||||
tokenInfo = &model.TokenInfo{}
|
||||
//验证token
|
||||
//v2下的接口需要验证,v1不需要
|
||||
if !strings.Contains(c.Request.URL.String(), "v1") {
|
||||
if !strings.Contains(c.Request.URL.String(), "v1") || !strings.Contains(c.Request.URL.String(), "app_no") {
|
||||
if cookie, err = c.Request.Cookie("token"); err != nil {
|
||||
c.JSON(http.StatusOK, &CallBack{
|
||||
c.JSON(http.StatusOK, &model.CallBack{
|
||||
Desc: err.Error(),
|
||||
Code: model.ErrCodeNormal,
|
||||
})
|
||||
@@ -46,7 +43,7 @@ func checkToken(c *gin.Context) (tokenInfo *model.TokenInfo) {
|
||||
globals.SugarLogger.Debugf("checkToken token: %v", tokenInfo.Token)
|
||||
if tokenMap = putils.GetKey(tokenInfo.Token).(map[string]interface{}); tokenMap == nil {
|
||||
err = fmt.Errorf("token过期或无效,请重新登录!")
|
||||
c.JSON(http.StatusOK, &CallBack{
|
||||
c.JSON(http.StatusOK, &model.CallBack{
|
||||
Desc: err.Error(),
|
||||
Code: model.ErrCodeToken,
|
||||
})
|
||||
@@ -57,7 +54,7 @@ func checkToken(c *gin.Context) (tokenInfo *model.TokenInfo) {
|
||||
tokenInfo.User = user
|
||||
} else {
|
||||
err = fmt.Errorf("token错误,请重新登录!")
|
||||
c.JSON(http.StatusOK, &CallBack{
|
||||
c.JSON(http.StatusOK, &model.CallBack{
|
||||
Desc: err.Error(),
|
||||
Code: model.ErrCodeToken,
|
||||
})
|
||||
@@ -68,10 +65,10 @@ func checkToken(c *gin.Context) (tokenInfo *model.TokenInfo) {
|
||||
return tokenInfo
|
||||
}
|
||||
|
||||
func callFunc(c *gin.Context, worker func() (retVal interface{}, errCode string, err error)) bool {
|
||||
func CallFunc(c *gin.Context, worker func() (retVal interface{}, errCode string, err error)) bool {
|
||||
var (
|
||||
err error
|
||||
callBack = &CallBack{
|
||||
callBack = &model.CallBack{
|
||||
Code: model.ErrCodeNormal,
|
||||
}
|
||||
result interface{}
|
||||
@@ -104,7 +101,7 @@ func callFunc(c *gin.Context, worker func() (retVal interface{}, errCode string,
|
||||
return false
|
||||
}
|
||||
|
||||
func captchaVerify(c *gin.Context, code string) bool {
|
||||
func CaptchaVerify(c *gin.Context, code string) bool {
|
||||
verifyCode := putils.GetKey(c.ClientIP() + model.SessionKey)
|
||||
if verifyCode == nil {
|
||||
return true
|
||||
@@ -116,8 +113,8 @@ func captchaVerify(c *gin.Context, code string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func buildErrJson(c *gin.Context, err error) {
|
||||
c.JSON(http.StatusOK, &CallBack{
|
||||
func BuildErrJson(c *gin.Context, err error) {
|
||||
c.JSON(http.StatusOK, &model.CallBack{
|
||||
Code: model.ErrCodeNormal,
|
||||
Desc: err.Error(),
|
||||
})
|
||||
@@ -133,13 +130,30 @@ func GetConfig(c *gin.Context) {
|
||||
}{}
|
||||
)
|
||||
if err = c.ShouldBind(¶m); err != nil {
|
||||
buildErrJson(c, err)
|
||||
BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
if !callFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
if !CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = print_server.GetConfig(c, param.Type, param.Key)
|
||||
return retVal, "", err
|
||||
}) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func SetToken(user *model.User) (token string, err error) {
|
||||
token = createToken(user)
|
||||
err = putils.SetKey(token, user, putils.DefTokenDuration)
|
||||
return token, err
|
||||
}
|
||||
|
||||
func createToken(user *model.User) (token string) {
|
||||
return strings.Join([]string{
|
||||
wxConst.TokenHeader,
|
||||
wxConst.TokenVer,
|
||||
user.UserID,
|
||||
time.Now().Format("20060102-150405"),
|
||||
utils.GetUUID(),
|
||||
user.Name,
|
||||
}, wxConst.TokenTypeSep)
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-print/controllers/controller"
|
||||
"git.rosy.net.cn/jx-print/model"
|
||||
"git.rosy.net.cn/jx-print/services/print_server"
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -18,13 +19,13 @@ func CreateOrder(c *gin.Context) {
|
||||
}{}
|
||||
)
|
||||
if err = c.ShouldBind(¶m); err != nil {
|
||||
buildErrJson(c, err)
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
if tokenInfo = checkToken(c); tokenInfo == nil {
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
if !callFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
if !controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = print_server.CreateOrder(tokenInfo, param.OrderType, param.Origin, param.ThingID, param.TypeID)
|
||||
return retVal, "", err
|
||||
}) {
|
||||
@@ -43,13 +44,13 @@ func Pay(c *gin.Context) {
|
||||
}{}
|
||||
)
|
||||
if err = c.ShouldBind(¶m); err != nil {
|
||||
buildErrJson(c, err)
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
if tokenInfo = checkToken(c); tokenInfo == nil {
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
if !callFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
if !controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = print_server.Pay(tokenInfo, param.OrderID, param.PayType, param.VendorPayType)
|
||||
return retVal, "", err
|
||||
}) {
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-print/controllers/controller"
|
||||
"git.rosy.net.cn/jx-print/model"
|
||||
"git.rosy.net.cn/jx-print/putils"
|
||||
"git.rosy.net.cn/jx-print/services/print_server"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
//添加打印机 POST
|
||||
// AddPrinters 添加打印机 POST
|
||||
func AddPrinters(c *gin.Context) {
|
||||
var (
|
||||
err error
|
||||
@@ -19,17 +20,17 @@ func AddPrinters(c *gin.Context) {
|
||||
printInfos []*model.PrintInfo
|
||||
)
|
||||
if err = c.ShouldBind(¶m); err != nil {
|
||||
buildErrJson(c, err)
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
if tokenInfo = checkToken(c); tokenInfo == nil {
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
if err = putils.UnmarshalUseNumber([]byte(param.Prints), &printInfos); err != nil {
|
||||
buildErrJson(c, err)
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
if !callFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
if !controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
err = print_server.AddPrinters(c, tokenInfo, param.AppID, printInfos)
|
||||
return retVal, "", err
|
||||
}) {
|
||||
@@ -54,13 +55,13 @@ func GetPrinters(c *gin.Context) {
|
||||
}{}
|
||||
)
|
||||
if err = c.ShouldBind(¶m); err != nil {
|
||||
buildErrJson(c, err)
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
if tokenInfo = checkToken(c); tokenInfo == nil {
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
if !callFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
if !controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = print_server.GetPrinters(c, param.AppID, param.PrintNo, param.Name, param.Status, param.IsOnline, param.Offset, param.PageSize)
|
||||
return retVal, "", err
|
||||
}) {
|
||||
@@ -81,17 +82,17 @@ func DelPrinters(c *gin.Context) {
|
||||
printNos []string
|
||||
)
|
||||
if err = c.ShouldBind(¶m); err != nil {
|
||||
buildErrJson(c, err)
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
if tokenInfo = checkToken(c); tokenInfo == nil {
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
if err = putils.UnmarshalUseNumber([]byte(param.PrintNos), &printNos); err != nil {
|
||||
buildErrJson(c, err)
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
if !callFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
if !controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
err = print_server.DelPrinters(c, param.AppID, tokenInfo, printNos)
|
||||
return retVal, "", err
|
||||
}) {
|
||||
@@ -114,13 +115,13 @@ func UpdatePrinter(c *gin.Context) {
|
||||
}{}
|
||||
)
|
||||
if err = c.ShouldBind(¶m); err != nil {
|
||||
buildErrJson(c, err)
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
if tokenInfo = checkToken(c); tokenInfo == nil {
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
if !callFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
if !controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
err = print_server.UpdatePrinter(c, param.AppID, tokenInfo, param.PrintNo, param.Name, param.Sound, param.Volume)
|
||||
return retVal, "", err
|
||||
}) {
|
||||
@@ -142,13 +143,13 @@ func TestPrint(c *gin.Context) {
|
||||
}{}
|
||||
)
|
||||
if err = c.ShouldBind(¶m); err != nil {
|
||||
buildErrJson(c, err)
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
if tokenInfo = checkToken(c); tokenInfo == nil {
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
if !callFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
if !controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = print_server.TestPrint(c, param.AppID, tokenInfo, param.PrintNo, param.OrderNo, param.Content)
|
||||
return retVal, "", err
|
||||
}) {
|
||||
@@ -173,13 +174,13 @@ func GetPrintMessages(c *gin.Context) {
|
||||
}{}
|
||||
)
|
||||
if err = c.ShouldBind(¶m); err != nil {
|
||||
buildErrJson(c, err)
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
if tokenInfo = checkToken(c); tokenInfo == nil {
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
if !callFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
if !controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = print_server.GetPrintMessages(c, param.AppID, tokenInfo, param.PrintNo, param.MsgID, param.BeginAt, param.EndAt, param.Offset, param.PageSize)
|
||||
return retVal, "", err
|
||||
}) {
|
||||
@@ -193,10 +194,10 @@ func GetPrinterReport(c *gin.Context) {
|
||||
var (
|
||||
tokenInfo *model.TokenInfo
|
||||
)
|
||||
if tokenInfo = checkToken(c); tokenInfo == nil {
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
if !callFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
if !controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = print_server.GetPrinterReport(c, tokenInfo)
|
||||
return retVal, "", err
|
||||
}) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-print/controllers/controller"
|
||||
"git.rosy.net.cn/jx-print/model"
|
||||
"git.rosy.net.cn/jx-print/services/print_server"
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -22,13 +23,13 @@ func GetCardsInfo(c *gin.Context) {
|
||||
}{}
|
||||
)
|
||||
if err = c.ShouldBind(¶m); err != nil {
|
||||
buildErrJson(c, err)
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
if tokenInfo = checkToken(c); tokenInfo == nil {
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
if !callFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
if !controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = print_server.GetCardsInfo(tokenInfo, param.AppID, param.PrintNo, param.CardStatus, param.IccID, param.BeginDate, param.EndDate, param.Offset, param.PageSize)
|
||||
return retVal, "", err
|
||||
}) {
|
||||
@@ -52,13 +53,13 @@ func GetChargeInfo(c *gin.Context) {
|
||||
}{}
|
||||
)
|
||||
if err = c.ShouldBind(¶m); err != nil {
|
||||
buildErrJson(c, err)
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
if tokenInfo = checkToken(c); tokenInfo == nil {
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
if !callFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
if !controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = print_server.GetChargeInfo(tokenInfo, param.AppID, param.PrintNo, param.IccID, param.BeginDate, param.EndDate, param.Offset, param.PageSize)
|
||||
return retVal, "", err
|
||||
}) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"git.rosy.net.cn/jx-print/controllers/controller"
|
||||
"git.rosy.net.cn/jx-print/globals"
|
||||
"git.rosy.net.cn/jx-print/model"
|
||||
"git.rosy.net.cn/jx-print/putils"
|
||||
@@ -28,22 +29,22 @@ func RegisterUser(c *gin.Context) {
|
||||
user = &UserParam{}
|
||||
)
|
||||
if err = c.ShouldBind(&user); err != nil {
|
||||
c.JSON(http.StatusOK, &CallBack{
|
||||
c.JSON(http.StatusOK, &model.CallBack{
|
||||
Code: model.ErrCodeNormal,
|
||||
Desc: err.Error(),
|
||||
})
|
||||
globals.SugarLogger.Debugf("API :%s error:%v:", c.Request.URL, err)
|
||||
return
|
||||
}
|
||||
if !captchaVerify(c, user.Code) {
|
||||
c.JSON(http.StatusOK, &CallBack{
|
||||
if !controller.CaptchaVerify(c, user.Code) {
|
||||
c.JSON(http.StatusOK, &model.CallBack{
|
||||
Code: model.ErrCodeNormal,
|
||||
Desc: "验证码错误!",
|
||||
})
|
||||
globals.SugarLogger.Debugf("End API :%s error:%v:", c.Request.URL, err)
|
||||
return
|
||||
}
|
||||
if !callFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
if !controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
err = print_server.RegisterUser(c, user.Name, user.Password)
|
||||
return retVal, "", err
|
||||
}) {
|
||||
@@ -59,22 +60,22 @@ func Login(c *gin.Context) {
|
||||
user = &UserParam{}
|
||||
)
|
||||
if err = c.ShouldBind(&user); err != nil {
|
||||
c.JSON(http.StatusOK, &CallBack{
|
||||
c.JSON(http.StatusOK, &model.CallBack{
|
||||
Code: model.ErrCodeNormal,
|
||||
Desc: err.Error(),
|
||||
})
|
||||
globals.SugarLogger.Debugf("End API :%s error:%v:", c.Request.URL, err)
|
||||
return
|
||||
}
|
||||
if !captchaVerify(c, user.Code) {
|
||||
c.JSON(http.StatusOK, &CallBack{
|
||||
if !controller.CaptchaVerify(c, user.Code) {
|
||||
c.JSON(http.StatusOK, &model.CallBack{
|
||||
Code: model.ErrCodeNormal,
|
||||
Desc: "验证码错误!",
|
||||
})
|
||||
globals.SugarLogger.Debugf("End API :%s error:%v:", c.Request.URL, err)
|
||||
return
|
||||
}
|
||||
if !callFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
if !controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = print_server.Login(c, user.Name, user.Password)
|
||||
return retVal, "", err
|
||||
}) {
|
||||
@@ -88,11 +89,11 @@ func GetTokenInfo(c *gin.Context) {
|
||||
var (
|
||||
tokenInfo *model.TokenInfo
|
||||
)
|
||||
if tokenInfo = checkToken(c); tokenInfo == nil {
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
data, _ := json.Marshal(tokenInfo)
|
||||
c.JSON(http.StatusOK, &CallBack{
|
||||
c.JSON(http.StatusOK, &model.CallBack{
|
||||
Code: model.ErrCodeSuccess,
|
||||
Data: string(data),
|
||||
})
|
||||
@@ -104,10 +105,10 @@ func Logout(c *gin.Context) {
|
||||
var (
|
||||
tokenInfo *model.TokenInfo
|
||||
)
|
||||
if tokenInfo = checkToken(c); tokenInfo == nil {
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
if !callFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
if !controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
err = print_server.Logout(c, tokenInfo.Token)
|
||||
return retVal, "", err
|
||||
}) {
|
||||
@@ -125,17 +126,17 @@ func UpdateUser(c *gin.Context) {
|
||||
}{}
|
||||
)
|
||||
if err = c.ShouldBind(&user); err != nil {
|
||||
c.JSON(http.StatusOK, &CallBack{
|
||||
c.JSON(http.StatusOK, &model.CallBack{
|
||||
Code: model.ErrCodeNormal,
|
||||
Desc: err.Error(),
|
||||
})
|
||||
globals.SugarLogger.Debugf("End API :%s error:%v:", c.Request.URL, err)
|
||||
return
|
||||
}
|
||||
if tokenInfo := checkToken(c); tokenInfo == nil {
|
||||
if tokenInfo := controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
if !callFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
if !controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
err = print_server.UpdateUser(c, user.Payload)
|
||||
return retVal, "", err
|
||||
}) {
|
||||
@@ -146,7 +147,7 @@ func UpdateUser(c *gin.Context) {
|
||||
|
||||
//获取菜单,文档 GET
|
||||
func GetMenus(c *gin.Context) {
|
||||
if !callFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
if !controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = print_server.GetMenus(c)
|
||||
return retVal, "", err
|
||||
}) {
|
||||
@@ -164,14 +165,14 @@ func GetMenuDetail(c *gin.Context) {
|
||||
}{}
|
||||
)
|
||||
if err = c.ShouldBind(&user); err != nil {
|
||||
c.JSON(http.StatusOK, &CallBack{
|
||||
c.JSON(http.StatusOK, &model.CallBack{
|
||||
Code: model.ErrCodeNormal,
|
||||
Desc: err.Error(),
|
||||
})
|
||||
globals.SugarLogger.Debugf("End API :%s error:%v:", c.Request.URL, err)
|
||||
return
|
||||
}
|
||||
if !callFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
if !controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = print_server.GetMenuDetail(c, user.ID)
|
||||
return retVal, "", err
|
||||
}) {
|
||||
|
||||
Reference in New Issue
Block a user