From 174aacd23195ee0472bc49624b4401750372cecd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Wed, 24 Aug 2022 10:40:42 +0800 Subject: [PATCH] 1 --- business/dao/print_bind_store.go | 31 ++++++++++++++++++++++++++++ business/jxstore/cms/print.go | 35 +++++++++++++++++++++++++++++--- business/model/print.go | 8 +++++--- 3 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 business/dao/print_bind_store.go diff --git a/business/dao/print_bind_store.go b/business/dao/print_bind_store.go new file mode 100644 index 000000000..37cc6cbb2 --- /dev/null +++ b/business/dao/print_bind_store.go @@ -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) +} diff --git a/business/jxstore/cms/print.go b/business/jxstore/cms/print.go index 2b9b5b376..9a79ef7ba 100644 --- a/business/jxstore/cms/print.go +++ b/business/jxstore/cms/print.go @@ -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 } diff --git a/business/model/print.go b/business/model/print.go index b24380cfc..50ea01cc1 100644 --- a/business/model/print.go +++ b/business/model/print.go @@ -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 {