141 lines
4.6 KiB
Go
141 lines
4.6 KiB
Go
package app
|
|
|
|
import (
|
|
"git.rosy.net.cn/baseapi/utils"
|
|
"git.rosy.net.cn/jx-print/controllers"
|
|
"git.rosy.net.cn/jx-print/globals"
|
|
"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"
|
|
"net/http"
|
|
)
|
|
|
|
type PrinterBindStore struct {
|
|
}
|
|
|
|
var PrinterBindStoreController = new(PrinterBindStore)
|
|
|
|
// AddPrinterBindStore 记录授权成功的门店信息
|
|
// @Title 记录授权成功的门店信息
|
|
// @Description 记录授权成功的门店信息
|
|
// @Param token cookie string true "用户登录token"
|
|
// @Param data body app_model.AddBindStore true "请求参数"
|
|
// @Success 200 {object} controllers.CallResult
|
|
// @Failure 200 {object} controllers.CallResult
|
|
// @router /bindingStore [post]
|
|
func (p *PrinterBindStore) AddPrinterBindStore(c *gin.Context) {
|
|
var (
|
|
err error
|
|
tokenInfo *model.TokenInfo
|
|
param = &tempModel.AddBindStore{}
|
|
bindServer = printServer.PrintBindStore{}
|
|
)
|
|
if err = c.ShouldBind(¶m); err != nil {
|
|
controllers.BuildErrJson(c, err)
|
|
return
|
|
}
|
|
if tokenInfo = controllers.CheckToken(c); tokenInfo == nil {
|
|
return
|
|
}
|
|
|
|
controllers.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
|
err = bindServer.AddStoreBind(tokenInfo.User.UserID, param)
|
|
return retVal, "", err
|
|
})
|
|
}
|
|
|
|
// UpdatePrinterUnBindStore 解除打印机账号绑定关系
|
|
// @Title 解除打印机账号绑定关系
|
|
// @Description 解除打印机账号绑定关系
|
|
// @Param token cookie string true "用户登录token"
|
|
// @Param data body app_model.RelieveBind true "请求参数"
|
|
// @Success 200 {object} controllers.CallResult
|
|
// @Failure 200 {object} controllers.CallResult
|
|
// @router /bindingStore [post]
|
|
func (p *PrinterBindStore) UpdatePrinterUnBindStore(c *gin.Context) {
|
|
var (
|
|
err error
|
|
tokenInfo *model.TokenInfo
|
|
param = &tempModel.RelieveBind{}
|
|
bindServer = printServer.PrintBindStore{}
|
|
)
|
|
if err = c.ShouldBind(¶m); err != nil {
|
|
controllers.BuildErrJson(c, err)
|
|
return
|
|
}
|
|
if tokenInfo = controllers.CheckToken(c); tokenInfo == nil {
|
|
return
|
|
}
|
|
|
|
// 解除用户和打印机绑定关系,
|
|
|
|
controllers.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
|
err = bindServer.RelievePrintBindStore(tokenInfo.User.UserID, param.PrintNo)
|
|
return retVal, "", err
|
|
})
|
|
}
|
|
|
|
// CheckStoreBindStatus 检查用户是否可以取消门店打印机绑定
|
|
// @Title 检查用户是否可以取消门店打印机绑定
|
|
// @Description 检查用户是否可以取消门店打印机绑定
|
|
// @Param token cookie string true "用户登录token"
|
|
// @Param data body app_model.RelieveStore true "请求参数"
|
|
// @Success 200 {object} controllers.CallResult
|
|
// @Failure 200 {object} controllers.CallResult
|
|
// @router /checkBindingStore [post]
|
|
func (p *PrinterBindStore) CheckStoreBindStatus(c *gin.Context) {
|
|
var (
|
|
err error
|
|
tokenInfo *model.TokenInfo
|
|
param = &tempModel.RelieveStore{}
|
|
bindServer = printServer.PrintBindStore{}
|
|
)
|
|
if err = c.ShouldBind(¶m); err != nil {
|
|
controllers.BuildErrJson(c, err)
|
|
return
|
|
}
|
|
if tokenInfo = controllers.CheckToken(c); tokenInfo == nil {
|
|
return
|
|
}
|
|
|
|
controllers.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
|
have, err := bindServer.QueryStoreAndUser(param)
|
|
return map[string]bool{"bind": have}, "", err
|
|
})
|
|
}
|
|
|
|
// LoseStoreAuthorize 失去授权回调
|
|
// @Title 失去授权回调
|
|
// @Description 失去授权回调
|
|
// @Param token cookie string true "用户登录token"
|
|
// @Param data body app_model.RelieveStore true "请求参数"
|
|
// @Success 200 {object} controllers.CallResult
|
|
// @Failure 200 {object} controllers.CallResult
|
|
// @router /loseAuthorize [post]
|
|
func (p *PrinterBindStore) LoseStoreAuthorize(c *gin.Context) {
|
|
if c.Request.Method == http.MethodPost {
|
|
var (
|
|
bindServer = printServer.PrintBindStore{}
|
|
)
|
|
storeId, err := bindServer.AnalysisStore(c.Request)
|
|
if err != nil {
|
|
globals.SugarLogger.Errorf("京西菜市门店失去授权回调错误:%v", err)
|
|
c.JSON(http.StatusNotFound, "")
|
|
}
|
|
|
|
if storeId == "" {
|
|
globals.SugarLogger.Errorf("京西菜市门店失去授权回调错误,门店id不能小于等于0:%v", err)
|
|
c.JSON(http.StatusNotFound, "")
|
|
}
|
|
if err := bindServer.LoseAuthorize(utils.Str2Int64(storeId)); err != nil {
|
|
globals.SugarLogger.Errorf("通联支付,回调函数错误处理异常:%v", err)
|
|
c.JSON(http.StatusNotFound, "")
|
|
}
|
|
|
|
c.JSON(http.StatusOK, "")
|
|
} else {
|
|
c.JSON(http.StatusNotFound, "")
|
|
}
|
|
}
|