From 57f699d16ceec633bcebdf0fd2d45e64ed2be72d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Mon, 19 Dec 2022 11:14:00 +0800 Subject: [PATCH] 1 --- business/jxstore/cms/store.go | 4 ++++ business/jxstore/misc/misc.go | 10 ++++++---- business/model/dao/store.go | 11 +++++++++-- business/model/dao/thing_map.go | 5 +++-- .../partner/purchase/tiktok_store/order.go | 3 --- .../purchase/tiktok_store/store_sku2_utils.go | 2 +- controllers/cms_store.go | 19 ++++++++++++++++++- routers/commentsRouter_controllers.go | 10 ++++++++++ 8 files changed, 51 insertions(+), 13 deletions(-) diff --git a/business/jxstore/cms/store.go b/business/jxstore/cms/store.go index be4b99061..9e581d0da 100644 --- a/business/jxstore/cms/store.go +++ b/business/jxstore/cms/store.go @@ -6095,3 +6095,7 @@ func BatchCreateFreeShipTemplate(relInfo map[string][]tiktok_store.RelInfo, ship func GetVendorStoreBind(vendorStoreId string, vendorId int) (int, error) { return dao.GetCodeAndIDByMeiTuan(vendorStoreId, vendorId) } + +func BindJxPrintToStore(storeId int64, printSn, printKey string) error { + return dao.BindJXPrintToStore(storeId, printSn, printKey) +} diff --git a/business/jxstore/misc/misc.go b/business/jxstore/misc/misc.go index e52a2333f..716a39dad 100644 --- a/business/jxstore/misc/misc.go +++ b/business/jxstore/misc/misc.go @@ -249,10 +249,10 @@ func Init() { cms.RefreshTiktokShopToken(jxcontext.AdminCtx) }, 60*time.Second, 30*time.Minute) - // 更新门店商品 - //ScheduleTimerFuncByInterval(func() { - // syncStoreSkuTiktok() - //}, 60*time.Second, 1*time.Minute) + // 抖音更新门店商品 + ScheduleTimerFuncByInterval(func() { + syncStoreSkuTiktok() + }, 60*time.Second, 1*time.Minute) // 定时任务刷新当前订单的物流信息 ScheduleTimerFunc("RefreshMaterialLogistics", func() { @@ -574,6 +574,7 @@ func syncStoreSku() { } func syncStoreSkuTiktok() { + globals.SugarLogger.Debugf("==========syncStoreSkuTiktok=") syncFlag := 0 | model.SyncFlagSaleMask task := tasksch.NewParallelTask("同步京西商品到抖音平台,方案二使用", nil, jxcontext.AdminCtx, func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { @@ -593,6 +594,7 @@ func syncStoreSkuTiktok() { errList.AddErr(err) SaveImportantTaskID(TaskNameSyncStoreSku, SpecialTaskID) } + globals.SugarLogger.Debugf("===============syncStoreSkuTiktok ,errList %s", utils.Format4Output(errList, false)) err = errList.GetErrListAsOne() return retVal, err }, []int{0, 1}) diff --git a/business/model/dao/store.go b/business/model/dao/store.go index c40f9cfac..a376eab42 100644 --- a/business/model/dao/store.go +++ b/business/model/dao/store.go @@ -1631,8 +1631,15 @@ func InsertIntoFreightTemplate(storeID int, vendorStoreID string, templateID, wa return err } -//只获取美团平台的京西storeID +// GetCodeAndIDByMeiTuan 只获取美团平台的京西storeID func GetCodeAndIDByMeiTuan(vendorStoreID string, vendorId int) (storeID int, err error) { - err = GetRow(GetDB(), &storeID, "SELECT s.store_id FROM store_map s WHERE s.vendor_store_id = ? AND s.vendor_id = ? ", vendorStoreID, vendorId) + err = GetRow(GetDB(), &storeID, "SELECT s.store_id FROM store_map s WHERE s.vendor_store_id = ? AND s.vendor_id = ? AND deleted_at = ?", vendorStoreID, vendorId, utils.DefaultTimeValue) return storeID, err } + +// BindJXPrintToStore 更新绑定门店的京西打印机 PrinterFontSize printer_sn printer_key printer_vendor_id printer_font_size +func BindJXPrintToStore(storeId int64, printSn, printKey string) error { + sql := ` UPDATE store SET printer_sn = ? , printer_key = ? , printer_vendor_id = ? , printer_font_size = ? WHERE id = ?` + _, err := ExecuteSQL(GetDB(), sql, []interface{}{printSn, printKey, model.VendorIDJxprint, model.NO, storeId}) + return err +} diff --git a/business/model/dao/thing_map.go b/business/model/dao/thing_map.go index bc51fa0b8..82fb4959a 100644 --- a/business/model/dao/thing_map.go +++ b/business/model/dao/thing_map.go @@ -43,15 +43,16 @@ func CreateThingMap(thingId int64, vendorThingID, appOrgCode, err string, thingT } // GetThingToTiktokMapList 抖店获取同步类型 -func GetThingToTiktokMapList(db *DaoDB, vendorId int, thingId int64) (cats []*model.ThingMap, err error) { +func GetThingToTiktokMapList(db *DaoDB, vendorId int, thingId int64, vendorOrgCode string) (cats []*model.ThingMap, err error) { sql := ` SELECT t1.* FROM thing_map t1 - WHERE t1.thing_id = ? AND t1.vendor_id = ? AND t1.deleted_at = ? + WHERE t1.thing_id = ? AND t1.vendor_id = ? AND vendor_org_code = ? AND t1.deleted_at = ? ` sqlParams := []interface{}{ thingId, vendorId, + vendorOrgCode, utils.DefaultTimeValue, } diff --git a/business/partner/purchase/tiktok_store/order.go b/business/partner/purchase/tiktok_store/order.go index 7edebbf5f..6db0a85c0 100644 --- a/business/partner/purchase/tiktok_store/order.go +++ b/business/partner/purchase/tiktok_store/order.go @@ -589,9 +589,6 @@ func (c *PurchaseHandler) Swtich2SelfDeliver(order *model.GoodsOrder, userName s AddressId: 0, StoreId: utils.Str2Int64(order.VendorStoreID), }) - if err != nil { - return err - } return err } diff --git a/business/partner/purchase/tiktok_store/store_sku2_utils.go b/business/partner/purchase/tiktok_store/store_sku2_utils.go index 210a665ef..1b4c76b73 100644 --- a/business/partner/purchase/tiktok_store/store_sku2_utils.go +++ b/business/partner/purchase/tiktok_store/store_sku2_utils.go @@ -215,7 +215,7 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI // 根据本地商品id获取线上商品是否存在,存在则只创建子商品 // 获取本地存储映射关系,获取本地主商品id是否存在 - localThing, err := dao.GetThingToTiktokMapList(db, model.VendorIDDD, int64(storeSku.SkuID)) + localThing, err := dao.GetThingToTiktokMapList(db, model.VendorIDDD, int64(storeSku.SkuID), storeDetail.VendorOrgCode) if len(localThing) == 0 { mainOrderDetail, err := api.GetSkuDetailLocalID("", utils.Int2Str(storeSku.SkuID)) if err != nil || mainOrderDetail == nil || mainOrderDetail.ProductIdStr == "" { diff --git a/controllers/cms_store.go b/controllers/cms_store.go index 26482fe84..6022cfaff 100644 --- a/controllers/cms_store.go +++ b/controllers/cms_store.go @@ -1544,7 +1544,7 @@ func (c *StoreController) CreateFreeShipTemplates() { }) } -// @Title 打印机获取授权账号再京西菜市的绑定关系 +// @Title 打印机获取授权账号再京西菜市的绑定关系(其实就是根据平台门店id获取绑定门店id) // @Description 打印机获取授权账号再京西菜市的绑定关系 // @Param token header string true "认证token" // @Param vendorStoreId formData string true "平台账号id" @@ -1558,3 +1558,20 @@ func (c *StoreController) PrintCheckAccountAuthorization() { return retVal, "", err }) } + +// @Title 门店存在时,绑定打印机账号信息 +// @Description 门店存在时,绑定打印机账号信息 +// @Param token header string true "认证token" +// @Param storeId formData int64 true "京西门店id" +// @Param printSn formData string true "打印机编号" +// @Param printKey formData string true "打印机秘钥" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /BindJxPrinter [post] +func (c *StoreController) BindJxPrinter() { + c.callBindJxPrinter(func(params *tStoreBindJxPrinterParams) (interface{}, string, error) { + err := cms.BindJxPrintToStore(int64(params.StoreId), params.PrintSn, params.PrintKey) + return nil, "", err + }) + +} diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index cb47fa3b8..58042c6c5 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -3000,6 +3000,16 @@ func init() { Filters: nil, Params: nil}) + // 绑定京西打印机到京西菜市 + web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"], + web.ControllerComments{ + Method: "BindJxPrinter", + Router: `/BindJxPrinter`, + AllowHTTPMethods: []string{"post"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"], web.ControllerComments{ Method: "BackUpStoreSkuBind",