1
This commit is contained in:
31
business/dao/print_bind_store.go
Normal file
31
business/dao/print_bind_store.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"time"
|
||||
)
|
||||
|
||||
// QueryPrintBindStore 查询绑定门店
|
||||
func QueryPrintBindStore(printNo string) ([]*model.PrintBindStore, error) {
|
||||
var data []*model.PrintBindStore
|
||||
if err := GetRows(GetDB(), &data, `SELECT * FROM print_bind_store WHERE print_no = ?`, []interface{}{printNo}...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// BindStoreList 绑定门店信息
|
||||
func BindStoreList(req *model.AddPrinterParam) error {
|
||||
param := &model.PrintBindStore{
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
StoreID: req.StoreId,
|
||||
StoreName: req.StoreName,
|
||||
StoreVendor: 9, // 绑定平台,全平台
|
||||
PrintNo: req.PrintNo,
|
||||
UserId: "system", // 所属用户
|
||||
StoreStatus: 1, // 门店开启
|
||||
BindStatus: 1, // 绑定状态
|
||||
}
|
||||
return CreateEntity(GetDB(), param)
|
||||
}
|
||||
@@ -51,7 +51,29 @@ func AddPrinter(appID int, printers []*model.AddPrinterParam) (err error) {
|
||||
}
|
||||
for _, v := range printers {
|
||||
if printers2, _ := dao.GetPrinters(db, appID, v.PrintNo, 0, 0); len(printers2) > 0 {
|
||||
errs = append(errs, fmt.Errorf("此应用已经绑定了该打印机!print_no : %v ", v.PrintNo))
|
||||
// 代表打印机已经在小程序注册了,查询打印机授权门店
|
||||
bindStoreList, err := dao.QueryPrintBindStore(v.PrintNo)
|
||||
if err != nil {
|
||||
errs = append(errs, fmt.Errorf("QueryPrintBindStore err : %v ", err))
|
||||
continue
|
||||
}
|
||||
if len(bindStoreList) >= 5 {
|
||||
errs = append(errs, fmt.Errorf("当前打印机绑定门店数据超过五个,无法继续绑定"))
|
||||
continue
|
||||
}
|
||||
have := false
|
||||
for _, bsl := range bindStoreList {
|
||||
if bsl.StoreID == v.StoreId {
|
||||
have = true
|
||||
}
|
||||
}
|
||||
if !have {
|
||||
if err := dao.BindStoreList(printers[0]); err != nil {
|
||||
errs = append(errs, fmt.Errorf("BindStoreList err : %v ", err))
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
//验证
|
||||
@@ -76,7 +98,7 @@ func AddPrinter(appID int, printers []*model.AddPrinterParam) (err error) {
|
||||
}
|
||||
|
||||
// 创建打印机
|
||||
if err := InitPrint(printer); err != nil {
|
||||
if err := InitPrint(printer, v); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -86,7 +108,7 @@ func AddPrinter(appID int, printers []*model.AddPrinterParam) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func InitPrint(printer *model.Printer) error {
|
||||
func InitPrint(printer *model.Printer, printParam *model.AddPrinterParam) error {
|
||||
txDb, _ := dao.Begin(dao.GetDB())
|
||||
// 创建打印机
|
||||
dao.WrapAddIDCULDEntity(printer, "")
|
||||
@@ -135,6 +157,13 @@ func InitPrint(printer *model.Printer) error {
|
||||
txDb.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
// 初始化绑定信息
|
||||
if err := dao.BindStoreList(printParam); err != nil {
|
||||
txDb.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
defer txDb.Commit()
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -15,9 +15,11 @@ const (
|
||||
)
|
||||
|
||||
type AddPrinterParam struct {
|
||||
PrintNo string `json:"print_no"` //打印机编号
|
||||
Name string `json:"name"` //打印机备注名
|
||||
SIM string `json:"sim"` //sim卡号
|
||||
PrintNo string `json:"print_no"` //打印机编号
|
||||
Name string `json:"name"` //打印机备注名
|
||||
SIM string `json:"sim"` //sim卡号-电话号码,接受验证的电话
|
||||
StoreId int64 `json:"store_id"` // 门店id
|
||||
StoreName string `json:"store_name"` // 门店名称
|
||||
}
|
||||
|
||||
type Printer struct {
|
||||
|
||||
Reference in New Issue
Block a user