From a2252e64877c1e334311a1173010cb0a04287814 Mon Sep 17 00:00:00 2001 From: gazebo Date: Mon, 28 Oct 2019 13:44:06 +0800 Subject: [PATCH 01/31] =?UTF-8?q?updateOrderOtherInfo=E4=B8=AD=E4=B8=8D?= =?UTF-8?q?=E7=89=B9=E6=AE=8A=E5=A4=84=E7=90=86VendorIDJX?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxcallback/orderman/order.go | 40 ++++++++------------------- business/model/dao/store.go | 16 ++++------- 2 files changed, 17 insertions(+), 39 deletions(-) diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index 8f7bee87c..b9dcf5fd7 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -385,37 +385,19 @@ func (c *OrderManager) updateOrderOtherInfo(order *model.GoodsOrder, db *dao.Dao globals.SugarLogger.Debugf("updateOrderOtherInfo orderID:%s, VendorStoreID:%s", order.VendorOrderID, order.VendorStoreID) payPercentage := 0 - if order.VendorID != model.VendorIDJX { - storeDetail, err := dao.GetStoreDetailByVendorStoreID(db, order.VendorStoreID, order.VendorID) - if err != nil { - if !dao.IsNoRowsError(err) { - globals.SugarLogger.Warnf("updateOrderOtherInfo GetStoreDetailByVendorStoreID orderID:%s, VendorStoreID:%s, error:%v", order.VendorOrderID, order.VendorStoreID, err) - return err - } - if time.Now().Sub(order.OrderCreatedAt) < 1*time.Hour { - globals.SugarLogger.Infof("updateOrderOtherInfo [运营]订单在京西与平台都找不到京西门店信息,订单:%s,平台门店ID:%s,平台:%s", order.VendorOrderID, order.VendorStoreID, model.VendorChineseNames[order.VendorID]) - } - err = nil - } else { - order.JxStoreID = storeDetail.Store.ID - payPercentage = storeDetail.PayPercentage + storeDetail, err := dao.GetStoreDetailByVendorStoreID(db, order.VendorStoreID, order.VendorID) + if err != nil { + if !dao.IsNoRowsError(err) { + globals.SugarLogger.Warnf("updateOrderOtherInfo GetStoreDetailByVendorStoreID orderID:%s, VendorStoreID:%s, error:%v", order.VendorOrderID, order.VendorStoreID, err) + return err } + if time.Now().Sub(order.OrderCreatedAt) < 1*time.Hour { + globals.SugarLogger.Infof("updateOrderOtherInfo [运营]订单在京西与平台都找不到京西门店信息,订单:%s,平台门店ID:%s,平台:%s", order.VendorOrderID, order.VendorStoreID, model.VendorChineseNames[order.VendorID]) + } + err = nil } else { - store := &model.Store{} - store.ID = order.StoreID - if err = dao.GetEntity(dao.GetDB(), store); err != nil { - if !dao.IsNoRowsError(err) { - globals.SugarLogger.Warnf("updateOrderOtherInfo GetEntity orderID:%s, VendorStoreID:%s, error:%v", order.VendorOrderID, order.VendorStoreID, err) - return err - } - if time.Now().Sub(order.OrderCreatedAt) < 1*time.Hour { - globals.SugarLogger.Infof("updateOrderOtherInfo b, [运营]订单在京西与平台都找不到京西门店信息,订单:%s,平台门店ID:%s,平台:%s", order.VendorOrderID, order.VendorStoreID, model.VendorChineseNames[order.VendorID]) - } - err = nil - } else { - payPercentage = store.PayPercentage - } - order.JxStoreID = order.StoreID + order.JxStoreID = storeDetail.Store.ID + payPercentage = storeDetail.PayPercentage } if err = c.updateOrderSkuOtherInfo(order, db, payPercentage); err == nil { jxutils.RefreshOrderSkuRelated(order) diff --git a/business/model/dao/store.go b/business/model/dao/store.go index 7aae7ec61..f6d45fc59 100644 --- a/business/model/dao/store.go +++ b/business/model/dao/store.go @@ -101,6 +101,10 @@ func getStoreDetail(db *DaoDB, storeID, vendorID int, vendorStoreID string) (sto if err = GetRow(db, storeDetail, sql, sqlParams...); err == nil { storeDetail.PricePercentagePackObj = PricePercentagePack2Obj(storeDetail.PricePercentagePackStr) storeDetail.FreightDeductionPackObj = FreightDeductionPack2Obj(storeDetail.FreightDeductionPackStr) + if vendorID == model.VendorIDJX { + storeDetail.VendorStatus = storeDetail.Status + storeDetail.PricePercentage = 100 + } return storeDetail, nil } return nil, err @@ -114,16 +118,8 @@ func GetStoreDetailByVendorStoreID(db *DaoDB, vendorStoreID string, vendorID int if vendorID != model.VendorIDJX { return getStoreDetail(db, 0, vendorID, vendorStoreID) } - store := &model.Store{} - store.ID = int(utils.Str2Int64WithDefault(vendorStoreID, 0)) - if err = GetEntity(db, store); err == nil { - // todo 还要补全其它参数 - storeDetail = &StoreDetail{ - Store: *store, - VendorStoreID: vendorStoreID, - VendorStatus: store.Status, - PricePercentage: 100, - } + if storeDetail, err = getStoreDetail(db, int(utils.Str2Int64WithDefault(vendorStoreID, 0)), vendorID, ""); err == nil { + storeDetail.VendorStoreID = vendorStoreID } return storeDetail, err } From 8281dfb19dc36be7daf6918e92fac693c97ec26a Mon Sep 17 00:00:00 2001 From: gazebo Date: Mon, 28 Oct 2019 16:19:48 +0800 Subject: [PATCH 02/31] debug CompareJxAndVendor --- business/jxstore/cms/store_sku_check.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/business/jxstore/cms/store_sku_check.go b/business/jxstore/cms/store_sku_check.go index 3cce02e21..c41e4f1ff 100644 --- a/business/jxstore/cms/store_sku_check.go +++ b/business/jxstore/cms/store_sku_check.go @@ -283,14 +283,22 @@ func CompareJxAndVendor(vendorID int, storeIDStr, vendorStoreID, storeName strin } } for skuID, vendorSkuInfo := range filterVendorSkuInfoMap { - skuIDStr := utils.Int2Str(skuID) - vendorSkuDetailName := vendorSkuInfo.SkuList[0].SkuName - vendorSkuSaleStatusName := GetSkuSaleStatusName(vendorSkuInfo.SkuList[0].Status) + if vendorSkuInfo != nil { + if len(vendorSkuInfo.SkuList) > 0 { + skuIDStr := utils.Int2Str(skuID) + vendorSkuDetailName := vendorSkuInfo.SkuList[0].SkuName + vendorSkuSaleStatusName := GetSkuSaleStatusName(vendorSkuInfo.SkuList[0].Status) - jxSkuInfo := filterJxSkuInfoMap[skuID] - if jxSkuInfo == nil { - outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, "", "", "", "", vendorSkuDetailName, "", vendorSkuSaleStatusName} - diffData.AppendData(vendorID, outPutData) + jxSkuInfo := filterJxSkuInfoMap[skuID] + if jxSkuInfo == nil { + outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, "", "", "", "", vendorSkuDetailName, "", vendorSkuSaleStatusName} + diffData.AppendData(vendorID, outPutData) + } + } else { + globals.SugarLogger.Warnf("CompareJxAndVendor vendorSkuInfo.SkuList:%d is nil", skuID) + } + } else { + globals.SugarLogger.Warnf("CompareJxAndVendor skuID:%d is nil", skuID) } } } From 04e65edebdad352d628fcc2b3bfe6f17276e7455 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 29 Oct 2019 09:42:49 +0800 Subject: [PATCH 03/31] =?UTF-8?q?GetOrders=E5=92=8CGetAfsOrders=E6=94=AF?= =?UTF-8?q?=E6=8C=81Post?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/jx_order.go | 4 ++-- routers/commentsRouter_controllers.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/controllers/jx_order.go b/controllers/jx_order.go index b28ab30b9..703b4571c 100644 --- a/controllers/jx_order.go +++ b/controllers/jx_order.go @@ -283,7 +283,7 @@ func (c *OrderController) ExportMTWaybills() { // @Param pageSize query int false "结果页大小(缺省为50,-1表示全部)" // @Success 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult -// @router /GetOrders [get] +// @router /GetOrders [get,post] func (c *OrderController) GetOrders() { c.callGetOrders(func(params *tOrderGetOrdersParams) (retVal interface{}, errCode string, err error) { var skuIDs []int @@ -335,7 +335,7 @@ func (c *OrderController) ExportOrders() { // @Param pageSize query int false "结果页大小(缺省为50,-1表示全部)" // @Success 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult -// @router /GetAfsOrders [get] +// @router /GetAfsOrders [get,post] func (c *OrderController) GetAfsOrders() { c.callGetAfsOrders(func(params *tOrderGetAfsOrdersParams) (retVal interface{}, errCode string, err error) { timeList, err := jxutils.BatchStr2Time(params.FromTime, params.ToTime) diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index 9345a8936..157c07787 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -796,7 +796,7 @@ func init() { beego.ControllerComments{ Method: "GetAfsOrders", Router: `/GetAfsOrders`, - AllowHTTPMethods: []string{"get"}, + AllowHTTPMethods: []string{"get","post"}, MethodParams: param.Make(), Filters: nil, Params: nil}) @@ -841,7 +841,7 @@ func init() { beego.ControllerComments{ Method: "GetOrders", Router: `/GetOrders`, - AllowHTTPMethods: []string{"get"}, + AllowHTTPMethods: []string{"get","post"}, MethodParams: param.Make(), Filters: nil, Params: nil}) From 378edfd3c98937badefdc470e483f6cb22f138aa Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 29 Oct 2019 11:38:39 +0800 Subject: [PATCH 04/31] =?UTF-8?q?=E8=85=BE=E8=AE=AF=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/wxpay_callback.go | 26 ++++++++++++++++++++++++++ routers/router.go | 1 + 2 files changed, 27 insertions(+) create mode 100644 controllers/wxpay_callback.go diff --git a/controllers/wxpay_callback.go b/controllers/wxpay_callback.go new file mode 100644 index 000000000..3de328fc0 --- /dev/null +++ b/controllers/wxpay_callback.go @@ -0,0 +1,26 @@ +package controllers + +import ( + "net/http" + + "git.rosy.net.cn/baseapi/platformapi/wxpay" + "github.com/astaxie/beego" +) + +type WXPayController struct { + beego.Controller +} + +func (c *WXPayController) Msg() { + if c.Ctx.Input.Method() == http.MethodPost { + var callbackResponse *wxpay.CallbackResponse + + if callbackResponse == nil { + callbackResponse = wxpay.SuccessResponse + } + c.Data["xml"] = callbackResponse + c.ServeXML() + } else { + c.Abort("404") + } +} diff --git a/routers/router.go b/routers/router.go index 9e0979e45..ab384579f 100644 --- a/routers/router.go +++ b/routers/router.go @@ -133,6 +133,7 @@ func init() { beego.AutoRouter(&controllers.WeimobController{}) beego.AutoRouter(&controllers.WeixinController{}) beego.AutoRouter(&controllers.DingDingController{}) + beego.AutoRouter(&controllers.WXPayController{}) // 如下都是用于检测存活的空接口 beego.Any("/", func(ctx *beecontext.Context) { From 84bd8d0b32a86e318b40488fd879783af330e759 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 29 Oct 2019 17:28:49 +0800 Subject: [PATCH 05/31] =?UTF-8?q?=E4=BC=98=E5=8C=96mtwm.ListOrders?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/partner/purchase/mtwm/order.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/business/partner/purchase/mtwm/order.go b/business/partner/purchase/mtwm/order.go index 6a8209a0d..271f43d54 100644 --- a/business/partner/purchase/mtwm/order.go +++ b/business/partner/purchase/mtwm/order.go @@ -579,7 +579,7 @@ func (c *PurchaseHandler) ListOrders(ctx *jxcontext.Context, parentTask tasksch. orderIDs = append(orderIDs, utils.Int64ToStr(v)) } } - if err = err2; err != nil || len(tmpOrderIDs) == 0 { + if err = err2; err != nil || len(tmpOrderIDs) < mtwmapi.MaxGap4GetOrderIdByDaySeq { err = nil break } From db1e81902f89a514071edf675039e5dffe8b1c66 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 29 Oct 2019 17:30:49 +0800 Subject: [PATCH 06/31] =?UTF-8?q?=E4=BF=AE=E5=A4=8DGetOrderConsigneeNumber?= =?UTF-8?q?=E4=B8=8EGetOrderCourierNumber=E4=B8=AD=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E5=AE=9E=E9=99=85=E4=BD=BF=E7=94=A8offset=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/partner/purchase/mtwm/order.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/business/partner/purchase/mtwm/order.go b/business/partner/purchase/mtwm/order.go index 271f43d54..d27769f5f 100644 --- a/business/partner/purchase/mtwm/order.go +++ b/business/partner/purchase/mtwm/order.go @@ -609,7 +609,7 @@ func (c *PurchaseHandler) ListOrders(ctx *jxcontext.Context, parentTask tasksch. func (p *PurchaseHandler) GetOrderConsigneeNumber(ctx *jxcontext.Context, storeID int, vendorStoreID string) (numberList []*partner.OrderPhoneNumberInfo, err error) { offset := 0 for { - result, err2 := api.MtwmAPI.OrderBatchPullPhoneNumber(vendorStoreID, 0, mtwmapi.MaxBatchPullPhoneNumberLimit) + result, err2 := api.MtwmAPI.OrderBatchPullPhoneNumber(vendorStoreID, offset, mtwmapi.MaxBatchPullPhoneNumberLimit) if err = err2; err == nil { for _, v := range result { v2 := &partner.OrderPhoneNumberInfo{ @@ -635,7 +635,7 @@ func (p *PurchaseHandler) GetOrderConsigneeNumber(ctx *jxcontext.Context, storeI func (p *PurchaseHandler) GetOrderCourierNumber(ctx *jxcontext.Context, storeID int, vendorStoreID string) (numberList []*partner.OrderPhoneNumberInfo, err error) { offset := 0 for { - result, err2 := api.MtwmAPI.OrderGetRiderInfoPhoneNumber(vendorStoreID, 0, mtwmapi.MaxBatchPullPhoneNumberLimit) + result, err2 := api.MtwmAPI.OrderGetRiderInfoPhoneNumber(vendorStoreID, offset, mtwmapi.MaxBatchPullPhoneNumberLimit) if err = err2; err == nil { for _, v := range result { numberList = append(numberList, &partner.OrderPhoneNumberInfo{ From bed22236009c0d6150f8f964078f472e1b4bca50 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 29 Oct 2019 17:54:15 +0800 Subject: [PATCH 07/31] =?UTF-8?q?OrderManager.OnOrderStatusChanged?= =?UTF-8?q?=E4=B8=AD=20=E6=9C=89=E4=BA=9B=E5=B9=B3=E5=8F=B0=EF=BC=88?= =?UTF-8?q?=E6=AF=94=E5=A6=82=E7=BE=8E=E5=9B=A2=E5=A4=96=E5=8D=96=EF=BC=89?= =?UTF-8?q?=EF=BC=8C=E5=9C=A8=E6=96=B0=E8=AE=A2=E5=8D=95=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E6=88=90=E5=8A=9F=E8=BF=94=E5=9B=9E=EF=BC=8C?= =?UTF-8?q?=E4=BD=86=E5=9C=A8=E9=87=8D=E5=8F=91=E8=AE=A2=E5=8D=95=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E5=89=8D=EF=BC=8C=E8=AE=A2=E5=8D=95=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=EF=BC=8C=E5=88=99=E4=B8=8D=E4=BC=9A=E5=86=8D?= =?UTF-8?q?=E9=87=8D=E5=8F=91=E6=96=B0=E8=AE=A2=E5=8D=95=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=EF=BC=8C=E7=89=B9=E6=AE=8A=E5=A4=84=E7=90=86=E4=B8=80=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxcallback/orderman/order.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index b9dcf5fd7..b1c52f003 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -11,6 +11,7 @@ import ( "git.rosy.net.cn/jx-callback/business/jxutils" "git.rosy.net.cn/jx-callback/business/model" "git.rosy.net.cn/jx-callback/business/model/dao" + "git.rosy.net.cn/jx-callback/business/partner" "git.rosy.net.cn/jx-callback/globals" "github.com/astaxie/beego/orm" ) @@ -151,6 +152,17 @@ func (c *OrderManager) OnOrderAdjust(order *model.GoodsOrder, orderStatus *model } func (c *OrderManager) OnOrderStatusChanged(orderStatus *model.OrderStatus) (err error) { + // 有些平台(比如美团外卖),在新订单事件没有成功返回,但在重发订单消息前,订单状态转换,则不会再重发新订单事件,特殊处理一下 + if orderStatus.Status == model.OrderStatusAccepted { + if _, err2 := c.LoadOrder(orderStatus.VendorOrderID, orderStatus.VendorID); err2 == ErrCanNotFindOrder { + if handler := partner.GetPurchaseOrderHandlerFromVendorID(orderStatus.VendorID); handler != nil { + if order, err2 := handler.GetOrder(orderStatus.VendorOrderID); err2 == nil { + c.OnOrderNew(order, orderStatus) + } + } + } + } + db := dao.GetDB() dao.Begin(db) defer func() { From 086c4199f21369791faebedca4601f5d40c34e50 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 29 Oct 2019 18:25:45 +0800 Subject: [PATCH 08/31] =?UTF-8?q?=E4=BC=98=E5=8C=96mtwm.ListOrders?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/partner/purchase/mtwm/order.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/business/partner/purchase/mtwm/order.go b/business/partner/purchase/mtwm/order.go index d27769f5f..cdf04c24c 100644 --- a/business/partner/purchase/mtwm/order.go +++ b/business/partner/purchase/mtwm/order.go @@ -3,6 +3,7 @@ package mtwm import ( "errors" "fmt" + "math" "net/url" "regexp" "strings" @@ -571,19 +572,29 @@ func (c *PurchaseHandler) ListOrders(ctx *jxcontext.Context, parentTask tasksch. vendorStoreID := batchItemList[0].(string) var orderIDs []string seqStart := 1 + i := 0 for { - seqEnd := seqStart + mtwmapi.MaxGap4GetOrderIdByDaySeq - 1 - tmpOrderIDs, err2 := api.MtwmAPI.GetOrderIdByDaySeq(vendorStoreID, queryDate, seqStart, seqEnd) + batchSize := int(math.Min(math.Pow(2, float64(i)), float64(mtwmapi.MaxGap4GetOrderIdByDaySeq))) + seqEnd := seqStart + batchSize - 1 + var tmpOrderIDs []int64 + if seqStart == seqEnd { + if vendorOderID, err2 := api.MtwmAPI.GetOrderIdByDaySeqSingle(vendorStoreID, queryDate, seqStart); err2 == nil { + tmpOrderIDs = []int64{vendorOderID} + } + } else { + tmpOrderIDs, err = api.MtwmAPI.GetOrderIdByDaySeq(vendorStoreID, queryDate, seqStart, seqEnd) + } if len(tmpOrderIDs) > 0 { for _, v := range tmpOrderIDs { orderIDs = append(orderIDs, utils.Int64ToStr(v)) } } - if err = err2; err != nil || len(tmpOrderIDs) < mtwmapi.MaxGap4GetOrderIdByDaySeq { + if err != nil || len(tmpOrderIDs) < batchSize { err = nil break } seqStart = seqEnd + 1 + i++ } retVal = orderIDs return retVal, nil From 01f77b8c8c3038824a88af4dd4f72b07b64a1385 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 29 Oct 2019 18:40:06 +0800 Subject: [PATCH 09/31] up --- business/partner/purchase/mtwm/order.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/business/partner/purchase/mtwm/order.go b/business/partner/purchase/mtwm/order.go index cdf04c24c..82ee31b6b 100644 --- a/business/partner/purchase/mtwm/order.go +++ b/business/partner/purchase/mtwm/order.go @@ -574,7 +574,7 @@ func (c *PurchaseHandler) ListOrders(ctx *jxcontext.Context, parentTask tasksch. seqStart := 1 i := 0 for { - batchSize := int(math.Min(math.Pow(2, float64(i)), float64(mtwmapi.MaxGap4GetOrderIdByDaySeq))) + batchSize := int(math.Min(math.Pow(2, float64(i*3)), float64(mtwmapi.MaxGap4GetOrderIdByDaySeq))) seqEnd := seqStart + batchSize - 1 var tmpOrderIDs []int64 if seqStart == seqEnd { From 5fa1fa38a817e5a15c3daf5e66cc3234466fde33 Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 30 Oct 2019 08:45:03 +0800 Subject: [PATCH 10/31] =?UTF-8?q?=E7=BE=8E=E5=9B=A2=E5=A4=96=E5=8D=96?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=95=86=E5=93=81=E5=9F=BA=E7=A1=80=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E6=97=B6=EF=BC=8C=E6=94=B9=E7=94=A8=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/partner/purchase/mtwm/store_sku2.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/business/partner/purchase/mtwm/store_sku2.go b/business/partner/purchase/mtwm/store_sku2.go index 1aa7f132f..a6220d317 100644 --- a/business/partner/purchase/mtwm/store_sku2.go +++ b/business/partner/purchase/mtwm/store_sku2.go @@ -37,8 +37,10 @@ func (p *PurchaseHandler) GetStoreSkusBatchSize(funcID int) (batchSize int) { batchSize = mtwmapi.MaxStoreSkuBatchSize case partner.FuncDeleteStoreSkus: batchSize = 1 // 可考虑用批量操作 - case partner.FuncCreateStoreSkus, partner.FuncUpdateStoreSkus: + case partner.FuncCreateStoreSkus: batchSize = 1 // 可考虑用批量操作 + case partner.FuncUpdateStoreSkus: + batchSize = mtwmapi.MaxStoreSkuBatchSize case partner.FuncGetStoreSkusFullInfo: batchSize = 1 } From 069db73f7b73b74fff3246bb9d819658e354911c Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 30 Oct 2019 10:53:10 +0800 Subject: [PATCH 11/31] =?UTF-8?q?=E5=88=B7=E6=96=B0=E5=BE=AE=E7=9B=9Ftoken?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 5d61ec564..dfd8d3d20 100644 --- a/main.go +++ b/main.go @@ -122,10 +122,10 @@ func main() { // globals.SugarLogger.Errorf("RefreshElmToken failed with error:%s", err) // return // } - // if err := tasks.RefreshWeimobToken(); err != nil { - // globals.SugarLogger.Errorf("RefreshWeimobToken failed with error:%s", err) - // return - // } + if err := tasks.RefreshWeimobToken(); err != nil { + globals.SugarLogger.Errorf("RefreshWeimobToken failed with error:%s", err) + return + } if err := tasks.RefreshYilianyunToken(); err != nil { globals.SugarLogger.Errorf("RefreshYilianyunToken failed with error:%s", err) return From 1c4bf23561193c62c3d878dcc77e1d42658fd861 Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 30 Oct 2019 11:38:34 +0800 Subject: [PATCH 12/31] =?UTF-8?q?prod=E5=90=AF=E7=94=A8=E5=BE=AE=E7=9B=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf/app.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/conf/app.conf b/conf/app.conf index 362ab482a..2f344db9f 100644 --- a/conf/app.conf +++ b/conf/app.conf @@ -155,6 +155,7 @@ enableEbaiStoreWrite = true enableMtwmStoreWrite = true enableWscStoreWrite = true +disableWeimob = false weimobCallbackURL = "http://callback.jxc4.com/weimob" dingdingAgentID = 239461075 From 6d307d9150757ee8e1b2f945376338ed1c0ebefb Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 30 Oct 2019 16:19:26 +0800 Subject: [PATCH 13/31] RefreshYilianyunToken --- business/jxutils/eventhub/eventhub.go | 4 +- .../eventhub/syseventhub/syseventhub.go | 38 ++++- business/jxutils/tasks/configrefresh.go | 161 ++++++++---------- controllers/sys.go | 21 ++- globals/globals.go | 2 + main.go | 4 - routers/commentsRouter_controllers.go | 9 + 7 files changed, 135 insertions(+), 104 deletions(-) diff --git a/business/jxutils/eventhub/eventhub.go b/business/jxutils/eventhub/eventhub.go index 422f3057c..3a4ca25f7 100644 --- a/business/jxutils/eventhub/eventhub.go +++ b/business/jxutils/eventhub/eventhub.go @@ -43,7 +43,6 @@ type EventInfo struct { type tRegisterInfo struct { notifyChan chan *EventInfo - eventCategory string eventTypeList []string criteria interface{} } @@ -177,8 +176,7 @@ func (e *EventHub) registerConsumer(eventCategory string, eventTypeList []string realEventTypeList[index] = composeEventType(eventCategory, eventType) } info := &tRegisterInfo{ - eventCategory: eventCategory, - eventTypeList: eventTypeList, + eventTypeList: realEventTypeList, notifyChan: make(chan *EventInfo, 1), criteria: criteria, } diff --git a/business/jxutils/eventhub/syseventhub/syseventhub.go b/business/jxutils/eventhub/syseventhub/syseventhub.go index 5ef2c63de..6e892522a 100644 --- a/business/jxutils/eventhub/syseventhub/syseventhub.go +++ b/business/jxutils/eventhub/syseventhub/syseventhub.go @@ -13,7 +13,8 @@ import ( const ( EventCategory = "sys" - EventTypeWXToken = "wxtoken" + EventTypeWXToken = "wxtoken" + EventTypeYLYToken = "ylytoken" ) type Hub struct { @@ -23,7 +24,7 @@ type Hub struct { type Criteria struct { } -type WXTokenInfo struct { +type TokenInfo struct { IsNew bool `json:"isNew"` Token string `json:"token"` } @@ -55,22 +56,43 @@ func (h *Hub) OnNewWXToken(token string) { }) } -func (h *Hub) GetWXToken(oldToken string, waitTime time.Duration) (tokenInfo *WXTokenInfo) { - token := api.WeixinAPI.CBGetToken() +func (h *Hub) OnNewYLYToken(token string) { + h.eventHub.PostNewEvent(EventCategory, &eventhub.EventInfo{ + Type: EventTypeYLYToken, + Data: token, + }) +} + +func (h *Hub) GetToken(tokenType, oldToken string, waitTime time.Duration) (tokenInfo *TokenInfo) { + var token string + switch tokenType { + case EventTypeWXToken: + token = api.WeixinAPI.CBGetToken() + case EventTypeYLYToken: + token = api.YilianyunAPI.GetToken() + } if token != oldToken { - tokenInfo = &WXTokenInfo{ + tokenInfo = &TokenInfo{ IsNew: false, Token: token, } } else { - eventInfo, err := h.eventHub.GetEvent(EventCategory, []string{EventTypeWXToken}, nil, waitTime) + eventInfo, err := h.eventHub.GetEvent(EventCategory, []string{tokenType}, nil, waitTime) if err == nil && eventInfo != nil { - tokenInfo = &WXTokenInfo{ + tokenInfo = &TokenInfo{ IsNew: true, Token: eventInfo.Data.(string), } } } - globals.SugarLogger.Debugf("GetWXToken tokenInfo:%s", utils.Format4Output(tokenInfo, true)) + globals.SugarLogger.Debugf("GetToken tokenInfo:%s", utils.Format4Output(tokenInfo, true)) return tokenInfo } + +func (h *Hub) GetWXToken(oldToken string, waitTime time.Duration) (tokenInfo *TokenInfo) { + return h.GetToken(EventTypeWXToken, oldToken, waitTime) +} + +func (h *Hub) GetYLYToken(oldToken string, waitTime time.Duration) (tokenInfo *TokenInfo) { + return h.GetToken(EventTypeYLYToken, oldToken, waitTime) +} diff --git a/business/jxutils/tasks/configrefresh.go b/business/jxutils/tasks/configrefresh.go index 7297ddf1d..ce071d76f 100644 --- a/business/jxutils/tasks/configrefresh.go +++ b/business/jxutils/tasks/configrefresh.go @@ -26,7 +26,6 @@ import ( const ( weixinTokenExpires = 7200 * time.Second dingdingTokenExpires = 7200 * time.Second - elmTokenExpires = 20 * 24 * 3600 * time.Second weimobTokenExpires = 7200 * time.Second yilianyunTokenExpires = 30 * 24 * 3600 * time.Second @@ -35,16 +34,6 @@ const ( minRefreshGap = 1 * time.Second ) -type ElmTokenForCompatible struct { - Error string `json:"error"` - ErrorDescription string `json:"error_description"` - AccessToken string `json:"accessToken"` - TokenType string `json:"tokenType"` - Expires int `json:"expires"` - RefreshToken string `json:"refreshToken"` - Success bool `json:"success"` -} - type CallResult struct { Code string `json:"code"` Desc string `json:"desc"` @@ -151,39 +140,10 @@ func RefreshWeixinToken() (err error) { return err } -func RefreshElmToken() (err error) { - if api.ElmAPI != nil { - err = RefreshConfig("eleme", elmTokenExpires, func() (string, string) { - if globals.IsProductEnv() { - if tokenInfo, err := api.ElmAPI.RefreshTokenIndividual(); err == nil { - tokenInfo2 := &ElmTokenForCompatible{ - Error: "", - ErrorDescription: "", - AccessToken: tokenInfo.AccessToken, - TokenType: tokenInfo.TokenType, - Expires: tokenInfo.ExpiresIn, - RefreshToken: "", - Success: true, - } - return string(utils.MustMarshal(tokenInfo2)), "" - } - } - return "", "" - }, func(value string) { - var tokenInfo ElmTokenForCompatible - err := utils.UnmarshalUseNumber([]byte(value), &tokenInfo) - if err == nil { - api.ElmAPI.SetToken(tokenInfo.AccessToken) - } - }) - } - return err -} - func RefreshWeimobToken() (err error) { if api.WeimobAPI != nil { err = RefreshConfig("weimob", weimobTokenExpires, func() (string, string) { - if globals.IsProductEnv() { + if globals.IsMainProductEnv() { if tokenInfo, err := api.WeimobAPI.RefreshTokenByRefreshToken(); err == nil { return string(utils.MustMarshal(tokenInfo)), utils.Time2Str(time.Now().Add((time.Duration(tokenInfo.ExpiresIn) - weimobTokenExpires/time.Second) * time.Second)) } @@ -230,62 +190,37 @@ func SaveWeimobToken(token *weimobapi.TokenInfo) (err error) { } func RefreshYilianyunToken() (err error) { - return RefreshConfig("yilianyun", yilianyunTokenExpires, func() (string, string) { + return RefreshConfig("yilianyun", yilianyunTokenExpires, func() (token string, expireTimeStr string) { globals.SugarLogger.Debugf("RefreshYilianyunToken RunMode:%s", beego.BConfig.RunMode) - if globals.IsProductEnv() { - if globals.IsMainProductEnv() { // 只有京西菜市刷新易联云key - if tokenInfo, err := api.YilianyunAPI.RetrieveToken(); err == nil { - return string(utils.MustMarshal(tokenInfo)), "" - } else { - globals.SugarLogger.Errorf("RefreshYilianyunToken RefreshToken failed with error:%v", err) - } + if globals.IsMainProductEnv() { // 只有京西菜市刷新易联云key + if tokenInfo, err := api.YilianyunAPI.RetrieveToken(); err == nil { + token = string(utils.MustMarshal(tokenInfo)) + } else { + globals.SugarLogger.Errorf("RefreshYilianyunToken RefreshToken failed with error:%v", err) + } + } else { + if tokenInfo := getYLYTokenFromRemote(api.YilianyunAPI.GetToken()); tokenInfo != nil { + expireTimeStr = utils.Time2Str(time.Now().Add(-yilianyunTokenExpires)) + token = tokenInfo.Token } } - return "", "" + return token, expireTimeStr }, func(value string) { + token := value var tokenInfo *yilianyunapi.TokenInfo - err := utils.UnmarshalUseNumber([]byte(value), &tokenInfo) - if err == nil { - api.YilianyunAPI.SetToken(tokenInfo.AccessToken) + if err := utils.TryUnmarshalUseNumber([]byte(value), &tokenInfo); err == nil { + token = tokenInfo.AccessToken } + syseventhub.SysEventHub.OnNewYLYToken(token) + api.YilianyunAPI.SetToken(token) }) } -func getWXTokenFromRemote(oldToken string) (tokenInfo *syseventhub.WXTokenInfo) { +func getWXTokenFromRemote(oldToken string) (tokenInfo *syseventhub.TokenInfo) { if IsGetWXTokenFromRemote() { - for { - waitSecond := 5 * 60 - globals.SugarLogger.Debugf("getWXTokenFromProd1") - response, err := http.Get(fmt.Sprintf("%s?accessKey=%s&oldToken=%s&waitSecond=%d", globals.GetWeixinTokenURL, globals.GetWeixinTokenKey, oldToken, waitSecond)) - globals.SugarLogger.Debugf("getWXTokenFromProd2 error:%v", err) - if err == nil { - defer response.Body.Close() - if response.StatusCode == http.StatusOK { - data, err2 := ioutil.ReadAll(response.Body) - if err = err2; err == nil { - var result CallResult - if err = utils.UnmarshalUseNumber(data, &result); err == nil { - if result.Code == "0" { - if result.Data != "" { - if err = utils.UnmarshalUseNumber([]byte(result.Data), &tokenInfo); err == nil && tokenInfo != nil { - globals.SugarLogger.Debugf("getWXTokenFromProd:%s", utils.Format4Output(tokenInfo, false)) - break - } - } - } else { - err = fmt.Errorf("return code is:%s", result.Code) - } - } - } - } else { - err = platformapi.ErrHTTPCodeIsNot200 - } - } - globals.SugarLogger.Infof("getWXTokenFromProd failed with error:%v", err) - if err != nil { - time.Sleep(errRefreshGap) - } - } + tokenInfo = PollingRemotEvent(globals.GetWeixinTokenURL, 0, map[string]interface{}{ + "oldToken": oldToken, + }) } return tokenInfo } @@ -293,3 +228,55 @@ func getWXTokenFromRemote(oldToken string) (tokenInfo *syseventhub.WXTokenInfo) func IsGetWXTokenFromRemote() bool { return !globals.IsMainProductEnv() && globals.GetWeixinTokenKey != "" && globals.GetWeixinTokenURL != "" } + +func PollingRemotEvent(remoteURL string, waitSecond int, params map[string]interface{}) (tokenInfo *syseventhub.TokenInfo) { + if waitSecond == 0 { + waitSecond = 5 * 60 + } + params2 := utils.MergeMaps(params, map[string]interface{}{ + "accessKey": globals.GetWeixinTokenKey, + "waitSecond": waitSecond, + }) + for { + globals.SugarLogger.Debugf("PollingRemotEvent") + response, err := http.Get(utils.GenerateGetURL(remoteURL, "", params2)) + globals.SugarLogger.Debugf("PollingRemotEvent2 error:%v", err) + if err == nil { + defer response.Body.Close() + if response.StatusCode == http.StatusOK { + data, err2 := ioutil.ReadAll(response.Body) + if err = err2; err == nil { + var result CallResult + if err = utils.UnmarshalUseNumber(data, &result); err == nil { + if result.Code == "0" { + if result.Data != "" { + if err = utils.UnmarshalUseNumber([]byte(result.Data), &tokenInfo); err == nil && tokenInfo != nil { + globals.SugarLogger.Debugf("PollingRemotEvent %s:%s", remoteURL, utils.Format4Output(tokenInfo, false)) + break + } + } + } else { + err = fmt.Errorf("return code is:%s", result.Code) + } + } + } + } else { + err = platformapi.ErrHTTPCodeIsNot200 + } + } + globals.SugarLogger.Infof("PollingRemotEvent failed with error:%v", err) + if err != nil { + time.Sleep(errRefreshGap) + } + } + return tokenInfo +} + +func getYLYTokenFromRemote(oldToken string) (tokenInfo *syseventhub.TokenInfo) { + if !globals.IsMainProductEnv() && globals.GetWeixinTokenKey != "" && globals.GetYLYTokenURL != "" { + tokenInfo = PollingRemotEvent(globals.GetYLYTokenURL, 0, map[string]interface{}{ + "oldToken": oldToken, + }) + } + return tokenInfo +} diff --git a/controllers/sys.go b/controllers/sys.go index 96d67fdc6..26ad57cce 100644 --- a/controllers/sys.go +++ b/controllers/sys.go @@ -20,8 +20,8 @@ type SysController struct { beego.Controller } -// @Title 得到京西门店信息 -// @Description 得到京西门店信息,如下条件之间是与的关系 +// @Title 得到微信token +// @Description 得到微信token // @Param accessKey query string true "假token" // @Param oldToken query string false "之前的token" // @Param waitSecond query int false "等待秒数" @@ -37,6 +37,23 @@ func (c *SysController) GetWXToken() { }) } +// @Title 得到易联云token +// @Description 得到易联云token +// @Param accessKey query string true "假token" +// @Param oldToken query string false "之前的token" +// @Param waitSecond query int false "等待秒数" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /GetYLYToken [get] +func (c *SysController) GetYLYToken() { + c.callGetYLYToken(func(params *tSysGetYLYTokenParams) (retVal interface{}, errCode string, err error) { + if params.AccessKey == globals.GetWeixinTokenKey { + retVal = syseventhub.SysEventHub.GetYLYToken(params.OldToken, time.Duration(params.WaitSecond)*time.Second) + } + return retVal, "", err + }) +} + // @Title 得到饿百RTF转换内容 // @Description 得到饿百RTF转换内容 // @Param imgListStr query string true "逗号分隔的图片列表可以是转义后的" diff --git a/globals/globals.go b/globals/globals.go index bb99b38ca..3bd30d243 100644 --- a/globals/globals.go +++ b/globals/globals.go @@ -40,6 +40,7 @@ var ( GetWeixinTokenURL string GetWeixinTokenKey string + GetYLYTokenURL string StoreName string @@ -82,6 +83,7 @@ func Init() { WxBackstageHost = beego.AppConfig.DefaultString("wxBackstageHost", "") GetWeixinTokenURL = beego.AppConfig.DefaultString("getWeixinTokenURL", "") + GetYLYTokenURL = beego.AppConfig.DefaultString("getYLYTokenURL", "") GetWeixinTokenKey = beego.AppConfig.DefaultString("getWeixinTokenKey", "") StoreName = beego.AppConfig.DefaultString("storeName", "京西菜市") diff --git a/main.go b/main.go index dfd8d3d20..4088c347f 100644 --- a/main.go +++ b/main.go @@ -118,10 +118,6 @@ func main() { globals.SugarLogger.Errorf("RefreshWeixinToken failed with error:%s", err) return } - // if err := tasks.RefreshElmToken(); err != nil { - // globals.SugarLogger.Errorf("RefreshElmToken failed with error:%s", err) - // return - // } if err := tasks.RefreshWeimobToken(); err != nil { globals.SugarLogger.Errorf("RefreshWeimobToken failed with error:%s", err) return diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index 157c07787..6cec894c6 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -1647,6 +1647,15 @@ func init() { Filters: nil, Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SysController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SysController"], + beego.ControllerComments{ + Method: "GetYLYToken", + Router: `/GetYLYToken`, + AllowHTTPMethods: []string{"get"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:TaskController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:TaskController"], beego.ControllerComments{ Method: "CancelTask", From 07d374a02e9c02688bd606db963c48779ea810e8 Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 30 Oct 2019 16:35:05 +0800 Subject: [PATCH 14/31] =?UTF-8?q?=E6=9E=9C=E5=9B=AD=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96=E6=98=93=E8=81=94=E4=BA=91key=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxutils/tasks/configrefresh.go | 8 ++++---- conf/app.conf | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/business/jxutils/tasks/configrefresh.go b/business/jxutils/tasks/configrefresh.go index ce071d76f..d675a6919 100644 --- a/business/jxutils/tasks/configrefresh.go +++ b/business/jxutils/tasks/configrefresh.go @@ -238,9 +238,9 @@ func PollingRemotEvent(remoteURL string, waitSecond int, params map[string]inter "waitSecond": waitSecond, }) for { - globals.SugarLogger.Debugf("PollingRemotEvent") + globals.SugarLogger.Debugf("PollingRemotEvent %s", remoteURL) response, err := http.Get(utils.GenerateGetURL(remoteURL, "", params2)) - globals.SugarLogger.Debugf("PollingRemotEvent2 error:%v", err) + globals.SugarLogger.Debugf("PollingRemotEvent2 %s error:%v", remoteURL, err) if err == nil { defer response.Body.Close() if response.StatusCode == http.StatusOK { @@ -256,7 +256,7 @@ func PollingRemotEvent(remoteURL string, waitSecond int, params map[string]inter } } } else { - err = fmt.Errorf("return code is:%s", result.Code) + err = fmt.Errorf("PollingRemotEvent %s return code is:%s", remoteURL, result.Code) } } } @@ -264,7 +264,7 @@ func PollingRemotEvent(remoteURL string, waitSecond int, params map[string]inter err = platformapi.ErrHTTPCodeIsNot200 } } - globals.SugarLogger.Infof("PollingRemotEvent failed with error:%v", err) + globals.SugarLogger.Infof("PollingRemotEvent %s failed with error:%v", remoteURL, err) if err != nil { time.Sleep(errRefreshGap) } diff --git a/conf/app.conf b/conf/app.conf index 2f344db9f..c5a5e8de9 100644 --- a/conf/app.conf +++ b/conf/app.conf @@ -119,6 +119,7 @@ weixinToken = "17_roSCZgkCxhRnyFVtei0KdfHwdGP8PmLzJFhCieka4_X4_d-lgfaTxF6oIS6FE5 dbConnectStr = "root:WebServer@1@tcp(127.0.0.1:3306)/jxd_dev_0?charset=utf8mb4&loc=Local&parseTime=true" getWeixinTokenURL = "http://beta.jxc4.com/v2/sys/GetWXToken" +getYLYTokenURL = "http://beta.jxc4.com/v2/sys/GetYLYToken" [prod] EnableDocs = false @@ -215,6 +216,8 @@ dingdingQRCodeSecret = "N9dyC9qB84sauQPs4_JYrILMsG5Krqm9-PSSVJ8t9hb87rrHiFUirISx dingdingCallbackURL = "http://callback-jxgy.jxc4.com/dingding/msg" getWeixinTokenURL = "http://www.jxc4.com/v2/sys/GetWXToken" +getYLYTokenURL = "http://www.jxc4.com/v2/sys/GetYLYToken" + storeName = "京西果园" [test] From fd9b2972cec4bfe91b442761a412dde7048d65ed Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 30 Oct 2019 16:39:43 +0800 Subject: [PATCH 15/31] =?UTF-8?q?GetOrderSkuInfo=E4=B8=AD=E8=BF=94?= =?UTF-8?q?=E5=9B=9EnameID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxcallback/orderman/orderman_ext.go | 25 ++++++++++---------- business/model/api.go | 1 + 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/business/jxcallback/orderman/orderman_ext.go b/business/jxcallback/orderman/orderman_ext.go index ad5aca131..cc7eb3abf 100644 --- a/business/jxcallback/orderman/orderman_ext.go +++ b/business/jxcallback/orderman/orderman_ext.go @@ -96,7 +96,7 @@ func (c *OrderManager) GetOrderSkuInfo(ctx *jxcontext.Context, vendorOrderID str IF(t1.shop_price = 0, t1.sale_price, t1.shop_price) shop_price, t1.sale_price, t1.earning_price, - CAST(IF(t1.earning_price <> 0, t1.earning_price, IF(t1.shop_price <> 0 && t1.shop_price < t1.sale_price, t1.shop_price, t1.sale_price) * IF(t5.pay_percentage > 0, t5.pay_percentage, %d) / 100) AS SIGNED) real_earning_price, + CAST(IF(t1.earning_price <> 0, t1.earning_price, IF(t1.shop_price <> 0 && t1.shop_price < t1.sale_price, t1.shop_price, t1.sale_price) * IF(t5.pay_percentage > 0, t5.pay_percentage, ?) / 100) AS SIGNED) real_earning_price, t1.weight, t1.sku_type, t1.promotion_type, @@ -105,18 +105,17 @@ func (c *OrderManager) GetOrderSkuInfo(ctx *jxcontext.Context, vendorOrderID str t1.store_sub_name, t1.vendor_price, %s full_sku_name, - `, model.DefaultEarningPricePercentage, fullSkuNameSQL) - db := dao.GetDB() - err = dao.GetRows(db, &skus, sql+` - t3.img image - FROM order_sku t1 - LEFT JOIN goods_order t6 ON t6.vendor_order_id = t1.vendor_order_id AND t6.vendor_id = t1.vendor_id - LEFT JOIN store t5 ON t5.id = IF(t6.jx_store_id <> 0, t6.jx_store_id, t6.store_id) - LEFT JOIN sku t2 ON IF(t1.jx_sku_id != 0, t1.jx_sku_id, t1.sku_id) = t2.id/* AND t2.deleted_at = ?*/ - LEFT JOIN sku_name t3 ON t2.name_id = t3.id/* AND t3.deleted_at = ?*/ - WHERE t1.vendor_order_id = ? AND t1.vendor_id = ? - ORDER BY t1.sku_name - `, /*, utils.DefaultTimeValue, utils.DefaultTimeValue*/ vendorOrderID, vendorID) + t2.name_id, + t3.img image + FROM order_sku t1 + LEFT JOIN goods_order t6 ON t6.vendor_order_id = t1.vendor_order_id AND t6.vendor_id = t1.vendor_id + LEFT JOIN store t5 ON t5.id = IF(t6.jx_store_id <> 0, t6.jx_store_id, t6.store_id) + LEFT JOIN sku t2 ON IF(t1.jx_sku_id != 0, t1.jx_sku_id, t1.sku_id) = t2.id/* AND t2.deleted_at = ?*/ + LEFT JOIN sku_name t3 ON t2.name_id = t3.id/* AND t3.deleted_at = ?*/ + WHERE t1.vendor_order_id = ? AND t1.vendor_id = ? + ORDER BY t1.sku_name + `, fullSkuNameSQL) + err = dao.GetRows(dao.GetDB(), &skus, sql /*, utils.DefaultTimeValue, utils.DefaultTimeValue*/, model.DefaultEarningPricePercentage, vendorOrderID, vendorID) if err != nil { globals.SugarLogger.Infof("GetOrderSkuInfo orderID:%s vendorID:%d failed with error:%v", vendorOrderID, vendorID, err) return nil, err diff --git a/business/model/api.go b/business/model/api.go index 1a3396774..e6c6a6796 100644 --- a/business/model/api.go +++ b/business/model/api.go @@ -36,6 +36,7 @@ type GoodsOrderExt struct { type OrderSkuExt struct { OrderSku + NameID int `orm:"column(name_id)" json:"nameID"` FullSkuName string `json:"fullSkuName"` Image string `json:"image"` RealEarningPrice int64 `json:"realEarningPrice"` // 实际单品结算给门店老板钱 From 3bd84cff45115af5f3dc2aa6ea48e66d81d85af4 Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 30 Oct 2019 17:35:35 +0800 Subject: [PATCH 16/31] =?UTF-8?q?SyncSkus=E4=B8=AD=E7=9A=84=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E7=AD=96=E7=95=A5=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index 22f9b97f0..d7d03b007 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -232,7 +232,7 @@ func (v *VendorSync) SyncSku(ctx *jxcontext.Context, db *dao.DaoDB, nameID, skuI func (v *VendorSync) SyncSkus(ctx *jxcontext.Context, db *dao.DaoDB, nameIDs []int, skuIDs []int, isAsync, isContinueWhenError bool, userName string) (hint string, err error) { globals.SugarLogger.Debugf("SyncSku trackInfo:%s, nameIDs:%v, skuIDs:%v, userName:%s", ctx.GetTrackInfo(), nameIDs, skuIDs, userName) - isManagedIt := len(nameIDs) > 1 || len(nameIDs) == 0 || len(skuIDs) > 1 || len(skuIDs) == 0 + isManagedIt := !(len(nameIDs) > 0 && len(nameIDs) <= 2 || len(skuIDs) > 0 && len(skuIDs) < 8) return v.LoopMultiStoresVendors(ctx, db, fmt.Sprintf("同步商品信息, nameIDs:%v, skuIDs:%v", nameIDs, skuIDs), isAsync, isManagedIt, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) { var resultList []interface{} From 48d6d5487bb85877486e18e56c3e571aa5c9b9a1 Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 30 Oct 2019 18:00:35 +0800 Subject: [PATCH 17/31] =?UTF-8?q?=E4=BF=AE=E5=A4=8DGetPossibleVendorIDFrom?= =?UTF-8?q?VendorOrderID=E4=B8=AD=E8=AF=AF=E5=88=A4=E6=96=AD=E4=BA=AC?= =?UTF-8?q?=E4=B8=9C=E6=96=B0=E8=AE=A2=E5=8D=95=E5=8F=B7=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxutils/jxutils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/business/jxutils/jxutils.go b/business/jxutils/jxutils.go index 763b78730..549df3cda 100644 --- a/business/jxutils/jxutils.go +++ b/business/jxutils/jxutils.go @@ -144,7 +144,7 @@ func GetPossibleVendorIDFromVendorOrderID(vendorOrderID string) (vendorID int) { // 改造点: // 1、订单号位数变化,由原有15位数增加1位数调整为16位数,对接商家需检查是否有对订单号位数做长度校验。 // 2、第一位数字发生变化,由原来9开头调整为当年年份后两位数如:2020年订单开头为20; - if orderIDLen == len("925265130002541") || orderIDLen == len("1925265130002541")+1 { + if orderIDLen == len("925265130002541") || orderIDLen == len("1925265130002541") { vendorID = model.VendorIDJD } else if orderIDLen == len("3022716176275221584") { // vendorID = model.VendorIDELM From bd0694ca32baaa270328ed3d015b32981e0b261a Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 31 Oct 2019 09:30:37 +0800 Subject: [PATCH 18/31] =?UTF-8?q?=E6=AF=8F=E6=99=9A=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E6=97=B6=EF=BC=8C=E6=8E=92=E9=99=A4=E7=A6=81?= =?UTF-8?q?=E7=94=A8=E9=97=A8=E5=BA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync.go | 50 ++++++++++------------------------- business/jxstore/misc/misc.go | 6 ++--- controllers/cms_sync.go | 2 +- 3 files changed, 18 insertions(+), 40 deletions(-) diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index d7d03b007..750931e3e 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -358,7 +358,7 @@ func (v *VendorSync) SyncStoresCategory(ctx *jxcontext.Context, db *dao.DaoDB, v } // -func (v *VendorSync) SyncStoresSkus2(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs []int, storeIDs, skuIDs, excludeSkuIDs []int, setSyncStatus int, isAsync, isContinueWhenError bool) (hint string, err error) { +func (v *VendorSync) SyncStoresSkus2(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs []int, storeIDs []int, syncDisabled bool, skuIDs, excludeSkuIDs []int, setSyncStatus int, isAsync, isContinueWhenError bool) (hint string, err error) { globals.SugarLogger.Debug("SyncStoresSkus2") isManageIt := len(storeIDs) != 1 || len(skuIDs) == 0 || len(skuIDs) > 8 task, hint, err := v.LoopStoresMap2(ctx, db, fmt.Sprintf("同步门店商品信息:%v", storeIDs), isAsync, isManageIt, vendorIDs, storeIDs, @@ -373,11 +373,13 @@ func (v *VendorSync) SyncStoresSkus2(ctx *jxcontext.Context, db *dao.DaoDB, vend tasksch.NewParallelConfig().SetParallelCount(parallelCount).SetIsContinueWhenError(isContinueWhenError), ctx, func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { storeMap := batchItemList[0].(*model.StoreMap) - if setSyncStatus != 0 { - dao.SetStoreSkuSyncStatus(db, storeMap.VendorID, []int{storeMap.StoreID}, skuIDs, setSyncStatus) - } - if _, err = v.proxySyncStoreSku(ctx, task, storeMap, nil, skuIDs, excludeSkuIDs, false, isContinueWhenError); err != nil { - globals.SugarLogger.Debugf("SyncStoresSkus2 failed2 store:%d failed with error:%v", storeMap.StoreID, err) + if syncDisabled || storeMap.Status > model.StoreStatusDisabled { + if setSyncStatus != 0 { + dao.SetStoreSkuSyncStatus(db, storeMap.VendorID, []int{storeMap.StoreID}, skuIDs, setSyncStatus) + } + if _, err = v.proxySyncStoreSku(ctx, task, storeMap, nil, skuIDs, excludeSkuIDs, false, isContinueWhenError); err != nil { + globals.SugarLogger.Debugf("SyncStoresSkus2 failed2 store:%d failed with error:%v", storeMap.StoreID, err) + } } return nil, err }, loopMapInfo.StoreMapList) @@ -387,18 +389,6 @@ func (v *VendorSync) SyncStoresSkus2(ctx *jxcontext.Context, db *dao.DaoDB, vend return nil, partner.AddVendorInfo2Err(err, loopMapInfo.VendorID) }, isContinueWhenError) if task != nil { - // if vendorErr := partner.IsErrChangePriceFailed(task.GetOriginalErr()); vendorErr != nil { - // platformList := make([]string, len(task.GetDetailErrList())) - // for k, v := range task.GetDetailErrList() { - // if vendorErr := partner.IsErrVendorError(v); vendorErr != nil { - // platformList[k] = model.VendorChineseNames[vendorErr.VendorID()] - // } else { - // platformList[k] = "未知" - // } - // } - // err = fmt.Errorf("同步价格失败\n失败平台:%s", strings.Join(platformList, ",")) - // } else { - // } err = makeSyncError(err) } return hint, err @@ -409,36 +399,22 @@ func (v *VendorSync) SyncStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, vendo if isForce { setSyncStatus = model.SyncFlagStoreSkuModifiedMask } - return v.SyncStoresSkus2(ctx, db, vendorIDs, storeIDs, skuIDs, nil, setSyncStatus, isAsync, isContinueWhenError) + return v.SyncStoresSkus2(ctx, db, vendorIDs, storeIDs, true, skuIDs, nil, setSyncStatus, isAsync, isContinueWhenError) } -// func isUseOldSyncLogic(storeMap *model.StoreMap) bool { -// return false -// return globals.IsProductEnv() && storeMap.StoreID != 102652 // 绿城四季鲜店 -// } - func (v *VendorSync) proxySyncStoreCategory(ctx *jxcontext.Context, parentTask tasksch.ITask, storeMap *model.StoreMap, nameIDs, skuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) { - // if isUseOldSyncLogic(storeMap) { - // return v.GetStoreHandler(storeMap.VendorID).(partner.ISingleStoreHandler).SyncStoreCategory(ctx, parentTask, storeMap.StoreID, isAsync) - // } return SyncStorCategories(ctx, parentTask, storeMap.VendorID, storeMap.StoreID, storeMap.VendorStoreID, nil, skuIDs, isAsync, isContinueWhenError) } func (v *VendorSync) proxySyncStoreSku(ctx *jxcontext.Context, parentTask tasksch.ITask, storeMap *model.StoreMap, nameIDs, skuIDs, excludeSkuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) { - // if isUseOldSyncLogic(storeMap) { - // return v.GetStoreHandler(storeMap.VendorID).SyncStoreSkus(ctx, parentTask, storeMap.StoreID, skuIDs, isAsync, isContinueWhenError) - // } return SyncStoreSkuNew(ctx, parentTask, storeMap.VendorID, storeMap.StoreID, storeMap.VendorStoreID, nil, skuIDs, excludeSkuIDs, isAsync, isContinueWhenError) } func (v *VendorSync) proxyFullSyncStoreSku(ctx *jxcontext.Context, parentTask tasksch.ITask, storeMap *model.StoreMap, isAsync, isContinueWhenError bool) (hint string, err error) { - // if isUseOldSyncLogic(storeMap) { - // return v.GetStoreHandler(storeMap.VendorID).FullSyncStoreSkus(ctx, parentTask, storeMap.StoreID, isAsync, isContinueWhenError) - // } return FullSyncStoreSkuNew(ctx, parentTask, storeMap.VendorID, storeMap.StoreID, storeMap.VendorStoreID, isAsync, isContinueWhenError) } -func (v *VendorSync) FullSyncStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs []int, storeIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) { +func (v *VendorSync) FullSyncStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs []int, storeIDs []int, syncDisabled, isAsync, isContinueWhenError bool) (hint string, err error) { globals.SugarLogger.Debug("FullSyncStoresSkus") hint, err = v.LoopStoresMap(ctx, db, fmt.Sprintf("初始化门店商品信息:%v", storeIDs), isAsync, true, vendorIDs, storeIDs, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) { @@ -452,8 +428,10 @@ func (v *VendorSync) FullSyncStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, v tasksch.NewParallelConfig().SetParallelCount(parallelCount).SetIsContinueWhenError(isContinueWhenError), ctx, func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { storeMap := batchItemList[0].(*model.StoreMap) - if _, err = v.proxyFullSyncStoreSku(ctx, task, storeMap, false, isContinueWhenError); err != nil { - globals.SugarLogger.Debugf("FullSyncStoresSkus failed2 store:%d failed with error:%v", storeMap.StoreID, err) + if syncDisabled || storeMap.Status > model.StoreStatusDisabled { + if _, err = v.proxyFullSyncStoreSku(ctx, task, storeMap, false, isContinueWhenError); err != nil { + globals.SugarLogger.Debugf("FullSyncStoresSkus failed2 store:%d failed with error:%v", storeMap.StoreID, err) + } } return nil, err }, loopMapInfo.StoreMapList) diff --git a/business/jxstore/misc/misc.go b/business/jxstore/misc/misc.go index 8f62f7f92..807ba34a5 100644 --- a/business/jxstore/misc/misc.go +++ b/business/jxstore/misc/misc.go @@ -124,12 +124,12 @@ func doDailyWork() { globals.SugarLogger.Debug("doDailyWork") cms.SyncStoresCourierInfo(jxcontext.AdminCtx, nil, false, true) netprinter.RebindAllPrinters(jxcontext.AdminCtx, false, true) - // cms.CurVendorSync.FullSyncStoresSkus(jxcontext.AdminCtx, dao.GetDB(), []int{model.VendorIDJD}, nil, true, true) + // cms.CurVendorSync.FullSyncStoresSkus(jxcontext.AdminCtx, dao.GetDB(), []int{model.VendorIDJD}, nil, false, true, true) - cms.CurVendorSync.SyncStoresSkus2(jxcontext.AdminCtx, dao.GetDB(), []int{model.VendorIDJD}, nil, nil, []int{27379}, model.SyncFlagSaleMask|model.SyncFlagPriceMask, true, true) + cms.CurVendorSync.SyncStoresSkus2(jxcontext.AdminCtx, dao.GetDB(), []int{model.VendorIDJD}, nil, false, nil, []int{27379}, model.SyncFlagSaleMask|model.SyncFlagPriceMask, true, true) SaveImportantTaskID(TaskNameSyncStoreSku, SpecialTaskID) - taskID, _ := cms.CurVendorSync.SyncStoresSkus2(jxcontext.AdminCtx, dao.GetDB(), []int{model.VendorIDEBAI, model.VendorIDMTWM}, nil, nil, nil, model.SyncFlagSaleMask|model.SyncFlagPriceMask, true, true) + taskID, _ := cms.CurVendorSync.SyncStoresSkus2(jxcontext.AdminCtx, dao.GetDB(), []int{model.VendorIDEBAI, model.VendorIDMTWM}, nil, false, nil, nil, model.SyncFlagSaleMask|model.SyncFlagPriceMask, true, true) SaveImportantTaskID(TaskNameSyncStoreSku, taskID) InitEx() diff --git a/controllers/cms_sync.go b/controllers/cms_sync.go index 079ae7e04..687264cb2 100644 --- a/controllers/cms_sync.go +++ b/controllers/cms_sync.go @@ -115,7 +115,7 @@ func (c *SyncController) FullSyncStoresSkus() { if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs, params.VendorIDs, &vendorIDs); err != nil { return retVal, "", err } - retVal, err = cms.CurVendorSync.FullSyncStoresSkus(params.Ctx, db, vendorIDs, storeIDs, params.IsAsync, params.IsContinueWhenError) + retVal, err = cms.CurVendorSync.FullSyncStoresSkus(params.Ctx, db, vendorIDs, storeIDs, true, params.IsAsync, params.IsContinueWhenError) return retVal, "", err }) } From e587723cf5810d5b745d0962b77b4c9608f175ca Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 31 Oct 2019 11:10:59 +0800 Subject: [PATCH 19/31] +GetWeimobToken --- .../eventhub/syseventhub/syseventhub.go | 22 +++++- business/jxutils/tasks/configrefresh.go | 68 +++++++++++-------- conf/app.conf | 5 +- controllers/sys.go | 17 +++++ globals/globals.go | 2 + routers/commentsRouter_controllers.go | 9 +++ 6 files changed, 91 insertions(+), 32 deletions(-) diff --git a/business/jxutils/eventhub/syseventhub/syseventhub.go b/business/jxutils/eventhub/syseventhub/syseventhub.go index 6e892522a..528c76973 100644 --- a/business/jxutils/eventhub/syseventhub/syseventhub.go +++ b/business/jxutils/eventhub/syseventhub/syseventhub.go @@ -13,8 +13,9 @@ import ( const ( EventCategory = "sys" - EventTypeWXToken = "wxtoken" - EventTypeYLYToken = "ylytoken" + EventTypeWXToken = "wxToken" + EventTypeYLYToken = "ylyToken" + EventTypeWeimobToken = "weimobToken" ) type Hub struct { @@ -63,6 +64,13 @@ func (h *Hub) OnNewYLYToken(token string) { }) } +func (h *Hub) OnNewWeimobToken(token string) { + h.eventHub.PostNewEvent(EventCategory, &eventhub.EventInfo{ + Type: EventTypeWeimobToken, + Data: token, + }) +} + func (h *Hub) GetToken(tokenType, oldToken string, waitTime time.Duration) (tokenInfo *TokenInfo) { var token string switch tokenType { @@ -70,6 +78,10 @@ func (h *Hub) GetToken(tokenType, oldToken string, waitTime time.Duration) (toke token = api.WeixinAPI.CBGetToken() case EventTypeYLYToken: token = api.YilianyunAPI.GetToken() + case EventTypeWeimobToken: + if weimobToken := api.WeimobAPI.GetToken(); weimobToken != nil { + token = string(utils.MustMarshal(weimobToken)) + } } if token != oldToken { tokenInfo = &TokenInfo{ @@ -85,7 +97,7 @@ func (h *Hub) GetToken(tokenType, oldToken string, waitTime time.Duration) (toke } } } - globals.SugarLogger.Debugf("GetToken tokenInfo:%s", utils.Format4Output(tokenInfo, true)) + globals.SugarLogger.Debugf("GetToken tokenType:%s tokenInfo:%s", tokenType, utils.Format4Output(tokenInfo, true)) return tokenInfo } @@ -96,3 +108,7 @@ func (h *Hub) GetWXToken(oldToken string, waitTime time.Duration) (tokenInfo *To func (h *Hub) GetYLYToken(oldToken string, waitTime time.Duration) (tokenInfo *TokenInfo) { return h.GetToken(EventTypeYLYToken, oldToken, waitTime) } + +func (h *Hub) GetWeimobToken(oldToken string, waitTime time.Duration) (tokenInfo *TokenInfo) { + return h.GetToken(EventTypeWeimobToken, oldToken, waitTime) +} diff --git a/business/jxutils/tasks/configrefresh.go b/business/jxutils/tasks/configrefresh.go index d675a6919..3f66b89b2 100644 --- a/business/jxutils/tasks/configrefresh.go +++ b/business/jxutils/tasks/configrefresh.go @@ -115,19 +115,17 @@ func RefreshWeixinToken() (err error) { if api.WeixinAPI != nil { err = RefreshConfig("wechat", weixinTokenExpires, func() (token string, expireTimeStr string) { globals.SugarLogger.Debugf("RefreshWeixinToken RunMode:%s", beego.BConfig.RunMode) - if globals.IsProductEnv() || beego.BConfig.RunMode == "alpha" { - if globals.IsMainProductEnv() { - if tokenInfo, err := api.WeixinAPI.CBRetrieveToken(); err == nil { - globals.SugarLogger.Debugf("RefreshWeixinToken tokenInfo:%s", utils.Format4Output(tokenInfo, true)) - token = tokenInfo.AccessToken - } else { - globals.SugarLogger.Errorf("RefreshWeixinToken RefreshToken failed with error:%v", err) - } + if globals.IsMainProductEnv() { + if tokenInfo, err := api.WeixinAPI.CBRetrieveToken(); err == nil { + globals.SugarLogger.Debugf("RefreshWeixinToken tokenInfo:%s", utils.Format4Output(tokenInfo, true)) + token = tokenInfo.AccessToken } else { - if tokenInfo := getWXTokenFromRemote(api.WeixinAPI.CBGetToken()); tokenInfo != nil { - expireTimeStr = utils.Time2Str(time.Now().Add(-weixinTokenExpires)) - token = tokenInfo.Token - } + globals.SugarLogger.Errorf("RefreshWeixinToken RefreshToken failed with error:%v", err) + } + } else { + if tokenInfo := getWXTokenFromRemote(api.WeixinAPI.CBGetToken()); tokenInfo != nil { + expireTimeStr = utils.Time2Str(time.Now().Add(-weixinTokenExpires)) + token = tokenInfo.Token } } return token, expireTimeStr @@ -142,17 +140,28 @@ func RefreshWeixinToken() (err error) { func RefreshWeimobToken() (err error) { if api.WeimobAPI != nil { - err = RefreshConfig("weimob", weimobTokenExpires, func() (string, string) { + err = RefreshConfig("weimob", weimobTokenExpires, func() (token string, expireTimeStr string) { + globals.SugarLogger.Debugf("RefreshWeimobToken RunMode:%s", beego.BConfig.RunMode) if globals.IsMainProductEnv() { if tokenInfo, err := api.WeimobAPI.RefreshTokenByRefreshToken(); err == nil { return string(utils.MustMarshal(tokenInfo)), utils.Time2Str(time.Now().Add((time.Duration(tokenInfo.ExpiresIn) - weimobTokenExpires/time.Second) * time.Second)) } + } else { + curToken := "" + if tokenInfo := api.WeimobAPI.GetToken(); tokenInfo != nil { + curToken = string(utils.MustMarshal(tokenInfo)) + } + if tokenInfo := getWeimobTokenFromRemote(curToken); tokenInfo != nil { + expireTimeStr = utils.Time2Str(time.Now().Add(-weimobTokenExpires)) + token = tokenInfo.Token + } } - return "", "" + return token, expireTimeStr }, func(value string) { var tokenInfo *weimobapi.TokenInfo err := utils.UnmarshalUseNumber([]byte(value), &tokenInfo) if err == nil { + syseventhub.SysEventHub.OnNewWeimobToken(string(utils.MustMarshal(tokenInfo))) api.WeimobAPI.SetToken(tokenInfo) } }) @@ -216,19 +225,6 @@ func RefreshYilianyunToken() (err error) { }) } -func getWXTokenFromRemote(oldToken string) (tokenInfo *syseventhub.TokenInfo) { - if IsGetWXTokenFromRemote() { - tokenInfo = PollingRemotEvent(globals.GetWeixinTokenURL, 0, map[string]interface{}{ - "oldToken": oldToken, - }) - } - return tokenInfo -} - -func IsGetWXTokenFromRemote() bool { - return !globals.IsMainProductEnv() && globals.GetWeixinTokenKey != "" && globals.GetWeixinTokenURL != "" -} - func PollingRemotEvent(remoteURL string, waitSecond int, params map[string]interface{}) (tokenInfo *syseventhub.TokenInfo) { if waitSecond == 0 { waitSecond = 5 * 60 @@ -272,6 +268,15 @@ func PollingRemotEvent(remoteURL string, waitSecond int, params map[string]inter return tokenInfo } +func getWXTokenFromRemote(oldToken string) (tokenInfo *syseventhub.TokenInfo) { + if !globals.IsMainProductEnv() && globals.GetWeixinTokenKey != "" && globals.GetWeixinTokenURL != "" { + tokenInfo = PollingRemotEvent(globals.GetWeixinTokenURL, 0, map[string]interface{}{ + "oldToken": oldToken, + }) + } + return tokenInfo +} + func getYLYTokenFromRemote(oldToken string) (tokenInfo *syseventhub.TokenInfo) { if !globals.IsMainProductEnv() && globals.GetWeixinTokenKey != "" && globals.GetYLYTokenURL != "" { tokenInfo = PollingRemotEvent(globals.GetYLYTokenURL, 0, map[string]interface{}{ @@ -280,3 +285,12 @@ func getYLYTokenFromRemote(oldToken string) (tokenInfo *syseventhub.TokenInfo) { } return tokenInfo } + +func getWeimobTokenFromRemote(oldToken string) (tokenInfo *syseventhub.TokenInfo) { + if !globals.IsMainProductEnv() && globals.GetWeixinTokenKey != "" && globals.GetWeimobTokenURL != "" { + tokenInfo = PollingRemotEvent(globals.GetWeimobTokenURL, 0, map[string]interface{}{ + "oldToken": oldToken, + }) + } + return tokenInfo +} diff --git a/conf/app.conf b/conf/app.conf index c5a5e8de9..692e5d9b2 100644 --- a/conf/app.conf +++ b/conf/app.conf @@ -118,8 +118,8 @@ weixinToken = "17_roSCZgkCxhRnyFVtei0KdfHwdGP8PmLzJFhCieka4_X4_d-lgfaTxF6oIS6FE5 dbConnectStr = "root:WebServer@1@tcp(127.0.0.1:3306)/jxd_dev_0?charset=utf8mb4&loc=Local&parseTime=true" -getWeixinTokenURL = "http://beta.jxc4.com/v2/sys/GetWXToken" -getYLYTokenURL = "http://beta.jxc4.com/v2/sys/GetYLYToken" +getWeixinTokenURL = "http://www.jxc4.com/v2/sys/GetWXToken" +getYLYTokenURL = "http://www.jxc4.com/v2/sys/GetYLYToken" [prod] EnableDocs = false @@ -311,5 +311,6 @@ weixinMiniAppID2 = "wx4b5930c13f8b1170" weixinMiniSecret2 = "2a57228a716ce991a52739f0ff41111d" getWeixinTokenURL = "http://www.jxc4.com/v2/sys/GetWXToken" +getWeimobTokenURL = "http://www.jxc4.com/v2/sys/GetWeimobToken" dbConnectStr = "root:WebServer@1@tcp(127.0.0.1:3306)/jxd_dev_0?charset=utf8mb4&loc=Local&parseTime=true" diff --git a/controllers/sys.go b/controllers/sys.go index 26ad57cce..4e4b66a0e 100644 --- a/controllers/sys.go +++ b/controllers/sys.go @@ -54,6 +54,23 @@ func (c *SysController) GetYLYToken() { }) } +// @Title 得到微盟token +// @Description 得到微盟token +// @Param accessKey query string true "假token" +// @Param oldToken query string false "之前的token" +// @Param waitSecond query int false "等待秒数" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /GetWeimobToken [get] +func (c *SysController) GetWeimobToken() { + c.callGetWeimobToken(func(params *tSysGetWeimobTokenParams) (retVal interface{}, errCode string, err error) { + if params.AccessKey == globals.GetWeixinTokenKey { + retVal = syseventhub.SysEventHub.GetWeimobToken(params.OldToken, time.Duration(params.WaitSecond)*time.Second) + } + return retVal, "", err + }) +} + // @Title 得到饿百RTF转换内容 // @Description 得到饿百RTF转换内容 // @Param imgListStr query string true "逗号分隔的图片列表可以是转义后的" diff --git a/globals/globals.go b/globals/globals.go index 3bd30d243..e615981b0 100644 --- a/globals/globals.go +++ b/globals/globals.go @@ -41,6 +41,7 @@ var ( GetWeixinTokenURL string GetWeixinTokenKey string GetYLYTokenURL string + GetWeimobTokenURL string StoreName string @@ -84,6 +85,7 @@ func Init() { GetWeixinTokenURL = beego.AppConfig.DefaultString("getWeixinTokenURL", "") GetYLYTokenURL = beego.AppConfig.DefaultString("getYLYTokenURL", "") + GetWeimobTokenURL = beego.AppConfig.DefaultString("getWeimobTokenURL", "") GetWeixinTokenKey = beego.AppConfig.DefaultString("getWeixinTokenKey", "") StoreName = beego.AppConfig.DefaultString("storeName", "京西菜市") diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index 6cec894c6..fad661d86 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -1647,6 +1647,15 @@ func init() { Filters: nil, Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SysController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SysController"], + beego.ControllerComments{ + Method: "GetWeimobToken", + Router: `/GetWeimobToken`, + AllowHTTPMethods: []string{"get"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SysController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SysController"], beego.ControllerComments{ Method: "GetYLYToken", From af4444648eea9d2eb6c91038e73f24048f843287 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 31 Oct 2019 11:13:30 +0800 Subject: [PATCH 20/31] =?UTF-8?q?+weimob=5Forder.go=EF=BC=8C=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E5=BE=AE=E7=9B=9F=E9=9B=86=E4=B8=AD=E4=BE=9B=E8=B4=A7?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E8=87=AA=E5=8A=A8=E5=85=B3=E6=B3=A8=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=9B=B8=E5=BA=94=E7=9A=84=E9=97=A8=E5=BA=97?= =?UTF-8?q?=E5=95=86=E5=93=81=E4=BB=B7=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/cs/weimob_order.go | 68 ++++++++++++++++++++++++++++++++++ controllers/weimob_callback.go | 10 +++-- 2 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 business/cs/weimob_order.go diff --git a/business/cs/weimob_order.go b/business/cs/weimob_order.go new file mode 100644 index 000000000..e5d89e979 --- /dev/null +++ b/business/cs/weimob_order.go @@ -0,0 +1,68 @@ +package cs + +import ( + "git.rosy.net.cn/baseapi/platformapi/weimobapi" + "git.rosy.net.cn/baseapi/utils" + "git.rosy.net.cn/jx-callback/business/jxstore/cms" + "git.rosy.net.cn/jx-callback/business/jxutils" + "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" + "git.rosy.net.cn/jx-callback/business/model" + "git.rosy.net.cn/jx-callback/business/model/dao" + "git.rosy.net.cn/jx-callback/globals" + "git.rosy.net.cn/jx-callback/globals/api" +) + +const ( + minCSOrderPayment = 0 // 供货订单的最小金额 + maxUnitPrice = 3000 // 为防止误填单价,限制单价最高 +) + +func OnCallbackMsg(msg *weimobapi.CallbackMsg) (response *weimobapi.CallbackResponse) { + orderID := utils.Int64ToStr(msg.OrderNo) + jxutils.CallMsgHandler(func() { + response = onOrderMsg(msg) + }, jxutils.ComposeUniversalOrderID(orderID, model.VendorIDWSC)) + return response +} + +func onOrderMsg(msg *weimobapi.CallbackMsg) (response *weimobapi.CallbackResponse) { + if msg.Event == weimobapi.MsgEventOrderStatusChange { + if orderDetail, err := api.WeimobAPI.QueryOrderDetail2(msg.OrderNo, false); err == nil { + if orderDetail.OrderStatus == weimobapi.OrderStatusFinished && orderDetail.PaymentAmount >= minCSOrderPayment { + changeStoreSkusByOrder(orderDetail) + } + } + } + return response +} + +func changeStoreSkusByOrder(order *weimobapi.OrderDetail) { + receiverMobile := order.DeliveryDetail.LogisticsDeliveryDetail.ReceiverMobile + storeList, err := dao.GetStoreList(dao.GetDB(), nil, []string{receiverMobile}, "") + if err != nil { + if len(storeList) == 1 { + var skuBindInfos []*cms.StoreSkuBindInfo + storeID := storeList[0].ID + for _, v := range order.ItemList { + nameID := int(utils.Str2Int64WithDefault(v.SkuCode, 0)) + unitPrice := v.OriginalPrice + if nameID > 0 && (unitPrice > 0 && unitPrice < maxUnitPrice) { + skuBindInfos = append(skuBindInfos, &cms.StoreSkuBindInfo{ + StoreID: storeID, + NameID: nameID, + UnitPrice: int(jxutils.StandardPrice2Int(unitPrice)), + IsFocus: 1, + IsSale: 1, + }) + } else { + globals.SugarLogger.Infof("[运营],微商城订单:%s,商品:%s没有设置正确的SkuName编码或单价,当前商家编码:%s,市场价:%s", order.OrderNo, v.SkuNum, v.SkuCode, jxutils.IntPrice2StandardString(jxutils.StandardPrice2Int(unitPrice))) + } + } + if len(skuBindInfos) > 0 { + cms.UpdateStoreSkus(jxcontext.NewWithUserName(nil, utils.LimitStringLen(utils.Int64ToStr(order.OrderNo), 32), nil, nil), storeID, skuBindInfos, true, true) + } + } else { + globals.SugarLogger.Infof("[运营],微商城订单:%s,手机:%s找不到唯一一个京西门店%d", order.OrderNo, receiverMobile, len(storeList)) + } + } +} diff --git a/controllers/weimob_callback.go b/controllers/weimob_callback.go index 8e8123ad7..7989ae264 100644 --- a/controllers/weimob_callback.go +++ b/controllers/weimob_callback.go @@ -3,6 +3,7 @@ package controllers import ( "git.rosy.net.cn/baseapi/platformapi/weimobapi" "git.rosy.net.cn/jx-callback/business/jxutils/tasks" + "git.rosy.net.cn/jx-callback/business/cs" "git.rosy.net.cn/jx-callback/globals" "git.rosy.net.cn/jx-callback/globals/api" "github.com/astaxie/beego" @@ -15,10 +16,11 @@ type WeimobController struct { func (c *WeimobController) onCallbackMsg() { if true { //c.Ctx.Input.Method() == http.MethodPost { callbackResponse := weimobapi.SuccessResponse - // msg, callbackResponse := api.WeimobAPI.GetCallbackMsg(c.Ctx.Input.RequestBody) - // if callbackResponse == nil { - // callbackResponse = wsc.OnCallbackMsg(msg) - // } + msg, callbackResponse := api.WeimobAPI.GetCallbackMsg(c.Ctx.Input.RequestBody) + if callbackResponse == nil { + // callbackResponse = wsc.OnCallbackMsg(msg) + callbackResponse = cs.OnCallbackMsg(msg) + } c.Data["json"] = callbackResponse c.ServeJSON() } else { From 5dc67bcd9ed8e8b24ef1c2fff45419af82c9d7ff Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 31 Oct 2019 11:25:45 +0800 Subject: [PATCH 21/31] disableWeimob = false for beta --- conf/app.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/conf/app.conf b/conf/app.conf index 692e5d9b2..608ab9764 100644 --- a/conf/app.conf +++ b/conf/app.conf @@ -310,6 +310,7 @@ weixinSecret = "6bbbed1443cc062c20a015a64c07a531" weixinMiniAppID2 = "wx4b5930c13f8b1170" weixinMiniSecret2 = "2a57228a716ce991a52739f0ff41111d" +disableWeimob = false getWeixinTokenURL = "http://www.jxc4.com/v2/sys/GetWXToken" getWeimobTokenURL = "http://www.jxc4.com/v2/sys/GetWeimobToken" From ae58b41ac64039a7f1d4d8dc9076f31053ed57d5 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 31 Oct 2019 14:06:14 +0800 Subject: [PATCH 22/31] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BE=AE=E7=9B=9F?= =?UTF-8?q?=E5=9B=9E=E8=B0=83=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/cs/weimob_order.go | 4 ++++ controllers/weimob_callback.go | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/business/cs/weimob_order.go b/business/cs/weimob_order.go index e5d89e979..8d088336b 100644 --- a/business/cs/weimob_order.go +++ b/business/cs/weimob_order.go @@ -26,11 +26,14 @@ func OnCallbackMsg(msg *weimobapi.CallbackMsg) (response *weimobapi.CallbackResp } func onOrderMsg(msg *weimobapi.CallbackMsg) (response *weimobapi.CallbackResponse) { + globals.SugarLogger.Debugf("onOrderMsg:%s", utils.Format4Output(msg, true)) if msg.Event == weimobapi.MsgEventOrderStatusChange { if orderDetail, err := api.WeimobAPI.QueryOrderDetail2(msg.OrderNo, false); err == nil { if orderDetail.OrderStatus == weimobapi.OrderStatusFinished && orderDetail.PaymentAmount >= minCSOrderPayment { changeStoreSkusByOrder(orderDetail) } + } else { + response = weimobapi.Err2CallbackResponse(err, "") } } return response @@ -43,6 +46,7 @@ func changeStoreSkusByOrder(order *weimobapi.OrderDetail) { if len(storeList) == 1 { var skuBindInfos []*cms.StoreSkuBindInfo storeID := storeList[0].ID + globals.SugarLogger.Debugf("changeStoreSkusByOrder storeID:%d", storeID) for _, v := range order.ItemList { nameID := int(utils.Str2Int64WithDefault(v.SkuCode, 0)) unitPrice := v.OriginalPrice diff --git a/controllers/weimob_callback.go b/controllers/weimob_callback.go index 7989ae264..ff3c8b5b5 100644 --- a/controllers/weimob_callback.go +++ b/controllers/weimob_callback.go @@ -2,8 +2,8 @@ package controllers import ( "git.rosy.net.cn/baseapi/platformapi/weimobapi" - "git.rosy.net.cn/jx-callback/business/jxutils/tasks" "git.rosy.net.cn/jx-callback/business/cs" + "git.rosy.net.cn/jx-callback/business/jxutils/tasks" "git.rosy.net.cn/jx-callback/globals" "git.rosy.net.cn/jx-callback/globals/api" "github.com/astaxie/beego" @@ -15,12 +15,14 @@ type WeimobController struct { func (c *WeimobController) onCallbackMsg() { if true { //c.Ctx.Input.Method() == http.MethodPost { - callbackResponse := weimobapi.SuccessResponse msg, callbackResponse := api.WeimobAPI.GetCallbackMsg(c.Ctx.Input.RequestBody) if callbackResponse == nil { // callbackResponse = wsc.OnCallbackMsg(msg) callbackResponse = cs.OnCallbackMsg(msg) } + if callbackResponse == nil { + callbackResponse = weimobapi.SuccessResponse + } c.Data["json"] = callbackResponse c.ServeJSON() } else { From a2c3107ee06c2023b93b10bc68b050779a853479 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 31 Oct 2019 14:20:50 +0800 Subject: [PATCH 23/31] up --- business/cs/weimob_order.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/business/cs/weimob_order.go b/business/cs/weimob_order.go index 8d088336b..cdcb2e0ec 100644 --- a/business/cs/weimob_order.go +++ b/business/cs/weimob_order.go @@ -13,8 +13,8 @@ import ( ) const ( - minCSOrderPayment = 0 // 供货订单的最小金额 - maxUnitPrice = 3000 // 为防止误填单价,限制单价最高 + minCSOrderPayment = 0 // 供货订单的最小金额(单位为元) + maxUnitPrice = 3000 // 为防止误填单价,限制单价最高(单位为分) ) func OnCallbackMsg(msg *weimobapi.CallbackMsg) (response *weimobapi.CallbackResponse) { @@ -33,6 +33,7 @@ func onOrderMsg(msg *weimobapi.CallbackMsg) (response *weimobapi.CallbackRespons changeStoreSkusByOrder(orderDetail) } } else { + globals.SugarLogger.Debugf("onOrderMsg order:%s failed with err:%v", msg.OrderNo, err) response = weimobapi.Err2CallbackResponse(err, "") } } @@ -40,6 +41,7 @@ func onOrderMsg(msg *weimobapi.CallbackMsg) (response *weimobapi.CallbackRespons } func changeStoreSkusByOrder(order *weimobapi.OrderDetail) { + globals.SugarLogger.Debugf("changeStoreSkusByOrder order:%s", utils.Format4Output(order, true)) receiverMobile := order.DeliveryDetail.LogisticsDeliveryDetail.ReceiverMobile storeList, err := dao.GetStoreList(dao.GetDB(), nil, []string{receiverMobile}, "") if err != nil { @@ -64,9 +66,13 @@ func changeStoreSkusByOrder(order *weimobapi.OrderDetail) { } if len(skuBindInfos) > 0 { cms.UpdateStoreSkus(jxcontext.NewWithUserName(nil, utils.LimitStringLen(utils.Int64ToStr(order.OrderNo), 32), nil, nil), storeID, skuBindInfos, true, true) + } else { + globals.SugarLogger.Debugf("changeStoreSkusByOrder storeID:%d is empty", storeID) } } else { globals.SugarLogger.Infof("[运营],微商城订单:%s,手机:%s找不到唯一一个京西门店%d", order.OrderNo, receiverMobile, len(storeList)) } + } else { + globals.SugarLogger.Warnf("changeStoreSkusByOrder receiverMobile:%s failed with err:%v", receiverMobile, err) } } From 77ae01854fcc4e3ed9f5abb284d75842b4692fc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 31 Oct 2019 14:54:58 +0800 Subject: [PATCH 24/31] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/report/report.go | 2 +- business/model/dao/report.go | 39 ++++++++++++++++++------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/business/jxstore/report/report.go b/business/jxstore/report/report.go index 1258a6f21..78e13bd99 100644 --- a/business/jxstore/report/report.go +++ b/business/jxstore/report/report.go @@ -33,7 +33,7 @@ func GetStatisticsReportForOrders(ctx *jxcontext.Context, storeIDs []int, fromDa if StatisticsForOrdersExistsStore == nil { continue } - StatisticsForOrdersExists, err = dao.GetStatisticsForOrdersExist(db, id) + StatisticsForOrdersExists, err = dao.GetStatisticsForOrdersExist(db, id, fromDateParm, toDateParm) //若该门店存在此查询条件范围内的订单 if StatisticsForOrdersExists != nil { storeIDsExist = append(storeIDsExist, id) diff --git a/business/model/dao/report.go b/business/model/dao/report.go index 17617df38..b25e425ff 100644 --- a/business/model/dao/report.go +++ b/business/model/dao/report.go @@ -14,20 +14,20 @@ type StatisticsForOrdersExists struct { type StatisticsReportForOrdersList struct { StatisticsForOrdersExists - OrderCounts int `orm:"column(orderCounts)" json:"orderCounts"` //订单数 - SalePrice int `orm:"column(salePrice)" json:"salePrice"` //GMV(售卖价) - ActualPayPrice int `orm:"column(actualPayPrice)" json:"actualPayPrice"` //实付 - ShopPrice int `orm:"column(shopPrice)" json:"shopPrice"` //京西 - DiscountMoney int `orm:"column(discountMoney)" json:"discountMoney"` //优惠 - DesiredFee int `orm:"column(desiredFee)" json:"desiredFee"` //配送费 - DistanceFreightMoney int `orm:"column(distanceFreightMoney)" json:"distanceFreightMoney"` //远距离 - WaybillTipMoney int `orm:"column(waybillTipMoney)" json:"waybillTipMoney"` // - TotalShopMoney int `orm:"column(totalShopMoney)" json:"totalShopMoney"` - PmSubsidyMoney int `orm:"column(pmSubsidyMoney)" json:"pmSubsidyMoney"` - EarningPrice int `orm:"column(earningPrice)" json:"earningPrice"` - TotalGrossProfit int `orm:"column(totalGrossProfit)" json:"totalGrossProfit"` - ComGrossProfit float32 `orm:"column(comGrossProfit)" json:"comGrossProfit"` - CityManagerGrossProfit float32 `orm:"column(cityManagerGrossProfit)" json:"cityManagerGrossProfit"` + OrderCounts int `orm:"column(orderCounts)" json:"orderCounts"` //订单数 + SalePrice int `orm:"column(salePrice)" json:"salePrice"` //GMV(售卖价) + ActualPayPrice int `orm:"column(actualPayPrice)" json:"actualPayPrice"` //实付 + ShopPrice int `orm:"column(shopPrice)" json:"shopPrice"` //京西 + DiscountMoney int `orm:"column(discountMoney)" json:"discountMoney"` //优惠 + DesiredFee int `orm:"column(desiredFee)" json:"desiredFee"` //配送费 + DistanceFreightMoney int `orm:"column(distanceFreightMoney)" json:"distanceFreightMoney"` //远距离 + WaybillTipMoney int `orm:"column(waybillTipMoney)" json:"waybillTipMoney"` //小费 + TotalShopMoney int `orm:"column(totalShopMoney)" json:"totalShopMoney"` //平台结算 + PmSubsidyMoney int `orm:"column(pmSubsidyMoney)" json:"pmSubsidyMoney"` //平台补贴 + EarningPrice int `orm:"column(earningPrice)" json:"earningPrice"` //门店收益(预计收益) + TotalGrossProfit int `orm:"column(totalGrossProfit)" json:"totalGrossProfit"` //总毛利 + ComGrossProfit float32 `orm:"column(comGrossProfit)" json:"comGrossProfit"` //公司毛利 + CityManagerGrossProfit float32 `orm:"column(cityManagerGrossProfit)" json:"cityManagerGrossProfit"` //城市经理毛利 } //是否存在这个门店 @@ -47,15 +47,22 @@ func IsStoreExist(db *DaoDB, storeID int) (StatisticsForOrdersExists *Statistics } //查询条件内是否存在订单 -func GetStatisticsForOrdersExist(db *DaoDB, storeID int) (StatisticsForOrdersExists *StatisticsForOrdersExists, err error) { +func GetStatisticsForOrdersExist(db *DaoDB, storeID int, fromDate time.Time, toDate time.Time) (StatisticsForOrdersExists *StatisticsForOrdersExists, err error) { sql := ` SELECT store_id FROM goods_order a LEFT JOIN waybill b ON IF(a.waybill_vendor_id = -1,a.vendor_order_id,a.vendor_waybill_id) = b.vendor_waybill_id WHERE a.store_id = ? - GROUP BY a.store_id ` sqlParams := []interface{}{} sqlParams = append(sqlParams, storeID) + if !utils.IsTimeZero(fromDate) && !utils.IsTimeZero(toDate) { + sql += `AND a.order_created_at BETWEEN ? and ? + ` + sqlParams = append(sqlParams, fromDate, toDate) + } + sql += ` + GROUP BY a.store_id + ` if err = GetRow(db, &StatisticsForOrdersExists, sql, sqlParams...); err == nil { return StatisticsForOrdersExists, nil From 4f8ded015340f619ceec5026d9e7348f712db1f9 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 31 Oct 2019 15:05:55 +0800 Subject: [PATCH 25/31] =?UTF-8?q?=E5=BE=AE=E7=9B=9F=E4=B8=AD=EF=BC=8C?= =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E6=B6=88=E6=81=AF=E4=B8=AD=E7=9A=84orderStat?= =?UTF-8?q?us=E5=85=88=E5=88=A4=E6=96=AD=E8=AE=A2=E5=8D=95=E7=8A=B6?= =?UTF-8?q?=E6=80=81=EF=BC=8C=E9=81=BF=E5=85=8D=E4=B8=8D=E5=BF=85=E8=A6=81?= =?UTF-8?q?=E7=9A=84QueryOrderDetail2=E7=9A=84=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/cs/weimob_order.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/business/cs/weimob_order.go b/business/cs/weimob_order.go index cdcb2e0ec..32189ab8b 100644 --- a/business/cs/weimob_order.go +++ b/business/cs/weimob_order.go @@ -28,13 +28,15 @@ func OnCallbackMsg(msg *weimobapi.CallbackMsg) (response *weimobapi.CallbackResp func onOrderMsg(msg *weimobapi.CallbackMsg) (response *weimobapi.CallbackResponse) { globals.SugarLogger.Debugf("onOrderMsg:%s", utils.Format4Output(msg, true)) if msg.Event == weimobapi.MsgEventOrderStatusChange { - if orderDetail, err := api.WeimobAPI.QueryOrderDetail2(msg.OrderNo, false); err == nil { - if orderDetail.OrderStatus == weimobapi.OrderStatusFinished && orderDetail.PaymentAmount >= minCSOrderPayment { - changeStoreSkusByOrder(orderDetail) + if utils.ForceInterface2Int64(msg.MsgBody["orderStatus"]) == weimobapi.MsgOrderStatusFinished { + if orderDetail, err := api.WeimobAPI.QueryOrderDetail2(msg.OrderNo, false); err == nil { + if orderDetail.OrderStatus == weimobapi.OrderStatusFinished && orderDetail.PaymentAmount >= minCSOrderPayment { + changeStoreSkusByOrder(orderDetail) + } + } else { + globals.SugarLogger.Debugf("onOrderMsg order:%s failed with err:%v", msg.OrderNo, err) + response = weimobapi.Err2CallbackResponse(err, "") } - } else { - globals.SugarLogger.Debugf("onOrderMsg order:%s failed with err:%v", msg.OrderNo, err) - response = weimobapi.Err2CallbackResponse(err, "") } } return response @@ -43,8 +45,7 @@ func onOrderMsg(msg *weimobapi.CallbackMsg) (response *weimobapi.CallbackRespons func changeStoreSkusByOrder(order *weimobapi.OrderDetail) { globals.SugarLogger.Debugf("changeStoreSkusByOrder order:%s", utils.Format4Output(order, true)) receiverMobile := order.DeliveryDetail.LogisticsDeliveryDetail.ReceiverMobile - storeList, err := dao.GetStoreList(dao.GetDB(), nil, []string{receiverMobile}, "") - if err != nil { + if storeList, err := dao.GetStoreList(dao.GetDB(), nil, []string{receiverMobile}, ""); err == nil { if len(storeList) == 1 { var skuBindInfos []*cms.StoreSkuBindInfo storeID := storeList[0].ID From 36a505fb32040e953164e5bd7fd1e7b52891a4a7 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 31 Oct 2019 15:49:17 +0800 Subject: [PATCH 26/31] =?UTF-8?q?=E5=8F=AA=E6=9C=89=E5=BA=93=E4=B8=AD?= =?UTF-8?q?=E5=8F=AF=E5=94=AE=E7=9A=84=E5=95=86=E5=93=81=E6=89=8D=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E5=85=B3=E6=B3=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index cc69d738d..25d9e9bf1 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -123,12 +123,14 @@ type StoreSkuBindInfo struct { type tStoreSkuBindAndSpec struct { model.StoreSkuBind - Name string - SpecQuality float32 - SpecUnit string - SkuNamePrice int - SkuNameUnit string - RealSkuID int `orm:"column(real_sku_id)"` + SkuStatus int + SkuNameStatus int + Name string + SpecQuality float32 + SpecUnit string + SkuNamePrice int + SkuNameUnit string + RealSkuID int `orm:"column(real_sku_id)"` } type SkuSaleInfo struct { @@ -924,12 +926,12 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs sql := ` SELECT t2.*, - t1.id real_sku_id, t1.spec_quality, t1.spec_unit,` + t1.id real_sku_id, t1.status sku_status, t1.spec_quality, t1.spec_unit,` if needGetExistingUnitPrice { sql += " IF(t5.unit_price > 0, t5.unit_price, t3.price) sku_name_price," } sql += ` - t3.unit sku_name_unit, t3.name + t3.unit sku_name_unit, t3.name, t3.status sku_name_status FROM sku t1 JOIN store ts ON ts.id = ? AND ts.deleted_at = ? LEFT JOIN store_sku_bind t2 ON t2.sku_id = t1.id AND t2.store_id = ts.id AND t2.deleted_at = ? @@ -982,7 +984,7 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs // globals.SugarLogger.Debug(utils.Format4Output(inSkuBind, false)) var skuBind *model.StoreSkuBind if v.ID == 0 { - if skuBindInfo.IsFocus == 1 { + if skuBindInfo.IsFocus == 1 && v.SkuNameStatus == model.SkuStatusNormal && v.SkuStatus == model.SkuStatusNormal { skuBind = &model.StoreSkuBind{ StoreID: storeID, SkuID: v.RealSkuID, From 85f3c9009e6f583dc9bb6f590518ee52c0756eca Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 31 Oct 2019 16:38:36 +0800 Subject: [PATCH 27/31] =?UTF-8?q?=E5=BE=AE=E5=95=86=E5=9F=8E=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E8=87=AA=E5=8A=A8=E4=BF=AE=E6=94=B9=E9=97=A8=E5=BA=97?= =?UTF-8?q?=E4=BB=B7=E6=A0=BC=E6=97=B6=EF=BC=8C=E7=94=B5=E8=AF=9D=E5=8F=B7?= =?UTF-8?q?=E7=A0=81=E5=8C=B9=E9=85=8D=E6=97=B6=EF=BC=8C=E4=B9=9F=E8=A6=81?= =?UTF-8?q?=E6=9F=A5=E5=88=86=E7=BB=84=20=E5=A4=9A=E4=BA=8E=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E9=97=A8=E5=BA=97=E5=8C=B9=E9=85=8D=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E5=8F=AA=E5=A4=84=E7=90=86=E7=AC=AC=E4=B8=80=E4=B8=AA=EF=BC=8C?= =?UTF-8?q?=E4=B8=94=E4=B8=8D=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/cs/weimob_order.go | 29 +++++++++++++++++++++++++++-- business/cs/weimob_order_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 business/cs/weimob_order_test.go diff --git a/business/cs/weimob_order.go b/business/cs/weimob_order.go index 32189ab8b..c5f0a0ac2 100644 --- a/business/cs/weimob_order.go +++ b/business/cs/weimob_order.go @@ -3,6 +3,7 @@ package cs import ( "git.rosy.net.cn/baseapi/platformapi/weimobapi" "git.rosy.net.cn/baseapi/utils" + "git.rosy.net.cn/jx-callback/business/authz/autils" "git.rosy.net.cn/jx-callback/business/jxstore/cms" "git.rosy.net.cn/jx-callback/business/jxutils" "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" @@ -45,8 +46,8 @@ func onOrderMsg(msg *weimobapi.CallbackMsg) (response *weimobapi.CallbackRespons func changeStoreSkusByOrder(order *weimobapi.OrderDetail) { globals.SugarLogger.Debugf("changeStoreSkusByOrder order:%s", utils.Format4Output(order, true)) receiverMobile := order.DeliveryDetail.LogisticsDeliveryDetail.ReceiverMobile - if storeList, err := dao.GetStoreList(dao.GetDB(), nil, []string{receiverMobile}, ""); err == nil { - if len(storeList) == 1 { + if storeList, err := GetStoreList4Mobile(dao.GetDB(), []string{receiverMobile}); err == nil { + if len(storeList) >= 1 { var skuBindInfos []*cms.StoreSkuBindInfo storeID := storeList[0].ID globals.SugarLogger.Debugf("changeStoreSkusByOrder storeID:%d", storeID) @@ -77,3 +78,27 @@ func changeStoreSkusByOrder(order *weimobapi.OrderDetail) { globals.SugarLogger.Warnf("changeStoreSkusByOrder receiverMobile:%s failed with err:%v", receiverMobile, err) } } + +func GetStoreList4Mobile(db *dao.DaoDB, mobileList []string) (storeList []*model.Store, err error) { + sql := ` + SELECT t1.* + FROM store t1 + WHERE t1.deleted_at = ?` + sqlParams := []interface{}{ + utils.DefaultTimeValue, + } + if len(mobileList) > 0 { + questionMarks := dao.GenQuestionMarks(len(mobileList)) + sql += " AND (t1.tel1 IN (" + questionMarks + ") OR t1.tel2 IN (" + questionMarks + `) + OR (SELECT + COUNT(*) + FROM casbin_rule t2 + JOIN user t3 ON t3.user_id = t2.v0 AND t3.mobile IN (` + questionMarks + `) + WHERE t2.v1 = CONCAT(?, t1.id) + ) > 0) + ` + sqlParams = append(sqlParams, mobileList, mobileList, mobileList, autils.NewStoreBossRole(-1).GetFullName()) + } + err = dao.GetRows(db, &storeList, sql, sqlParams...) + return storeList, err +} diff --git a/business/cs/weimob_order_test.go b/business/cs/weimob_order_test.go new file mode 100644 index 000000000..4e91a3fa6 --- /dev/null +++ b/business/cs/weimob_order_test.go @@ -0,0 +1,24 @@ +package cs + +import ( + "testing" + + "git.rosy.net.cn/baseapi/utils" + "git.rosy.net.cn/jx-callback/business/model/dao" + "git.rosy.net.cn/jx-callback/globals/api2" + "git.rosy.net.cn/jx-callback/globals/testinit" +) + +func init() { + testinit.Init() + api2.Init() +} + +func TestGetStoreList4Mobile(t *testing.T) { + storeList, err := GetStoreList4Mobile(dao.GetDB(), []string{"18180948107"}) + if err != nil { + t.Fatal(err) + } + t.Log(utils.Format4Output(storeList, false)) + t.Log(len(storeList)) +} From e1945255932c9751b870848812f9652f7baa8dfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 31 Oct 2019 16:47:07 +0800 Subject: [PATCH 28/31] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/report/report.go | 50 +---------- business/model/dao/report.go | 144 ++++++++++++++---------------- controllers/jx_report.go | 15 ++++ 3 files changed, 84 insertions(+), 125 deletions(-) diff --git a/business/jxstore/report/report.go b/business/jxstore/report/report.go index 78e13bd99..94a5bd5ff 100644 --- a/business/jxstore/report/report.go +++ b/business/jxstore/report/report.go @@ -10,16 +10,7 @@ import ( "git.rosy.net.cn/jx-callback/business/model/dao" ) -var ( - storeIDsExist []int - storeIDsNotExist []int - StatisticsForOrdersExists *dao.StatisticsForOrdersExists - StatisticsForOrdersExistsStore *dao.StatisticsForOrdersExists -) - func GetStatisticsReportForOrders(ctx *jxcontext.Context, storeIDs []int, fromDate string, toDate string) (statisticsReportForOrdersList []*dao.StatisticsReportForOrdersList, err error) { - storeIDsExist = storeIDsExist[0:0] - storeIDsNotExist = storeIDsNotExist[0:0] db := dao.GetDB() fromDateParm := utils.Str2Time(fromDate) toDateParm := utils.Str2Time(toDate) @@ -27,45 +18,6 @@ func GetStatisticsReportForOrders(ctx *jxcontext.Context, storeIDs []int, fromDa if math.Ceil(toDateParm.Sub(fromDateParm).Hours()/24) > 92 { return nil, errors.New(fmt.Sprintf("查询间隔时间不允许大于3个月!: 时间范围:[%v] 至 [%v]", fromDate, toDate)) } - //若入参中,不存在的店则不显示,存在的店但无订单的显示0 - for _, id := range storeIDs { - StatisticsForOrdersExistsStore, err = dao.IsStoreExist(db, id) - if StatisticsForOrdersExistsStore == nil { - continue - } - StatisticsForOrdersExists, err = dao.GetStatisticsForOrdersExist(db, id, fromDateParm, toDateParm) - //若该门店存在此查询条件范围内的订单 - if StatisticsForOrdersExists != nil { - storeIDsExist = append(storeIDsExist, id) - } else { - storeIDsNotExist = append(storeIDsNotExist, id) - } - } - statisticsReportForOrdersList, err = dao.GetStatisticsReportForOrders(db, storeIDsExist, fromDateParm, toDateParm) - if storeIDsNotExist != nil { - for _, v := range storeIDsNotExist { - tempStruct1 := &dao.StatisticsForOrdersExists{ - StoreID: v, - } - tempStruct2 := &dao.StatisticsReportForOrdersList{ - StatisticsForOrdersExists: *tempStruct1, - OrderCounts: 0, - SalePrice: 0, - ActualPayPrice: 0, - ShopPrice: 0, - DiscountMoney: 0, - DesiredFee: 0, - DistanceFreightMoney: 0, - WaybillTipMoney: 0, - TotalShopMoney: 0, - PmSubsidyMoney: 0, - EarningPrice: 0, - TotalGrossProfit: 0, - ComGrossProfit: 0, - CityManagerGrossProfit: 0, - } - statisticsReportForOrdersList = append(statisticsReportForOrdersList, tempStruct2) - } - } + statisticsReportForOrdersList, err = dao.GetStatisticsReportForOrders(db, storeIDs, fromDateParm, toDateParm) return statisticsReportForOrdersList, err } diff --git a/business/model/dao/report.go b/business/model/dao/report.go index b25e425ff..2fe33a08f 100644 --- a/business/model/dao/report.go +++ b/business/model/dao/report.go @@ -9,65 +9,29 @@ import ( ) type StatisticsForOrdersExists struct { - StoreID int `orm:"column(storeID)" json:"storeID"` + StoreID int `orm:"column(store_id)" json:"storeId"` } type StatisticsReportForOrdersList struct { StatisticsForOrdersExists - OrderCounts int `orm:"column(orderCounts)" json:"orderCounts"` //订单数 - SalePrice int `orm:"column(salePrice)" json:"salePrice"` //GMV(售卖价) - ActualPayPrice int `orm:"column(actualPayPrice)" json:"actualPayPrice"` //实付 - ShopPrice int `orm:"column(shopPrice)" json:"shopPrice"` //京西 - DiscountMoney int `orm:"column(discountMoney)" json:"discountMoney"` //优惠 - DesiredFee int `orm:"column(desiredFee)" json:"desiredFee"` //配送费 - DistanceFreightMoney int `orm:"column(distanceFreightMoney)" json:"distanceFreightMoney"` //远距离 - WaybillTipMoney int `orm:"column(waybillTipMoney)" json:"waybillTipMoney"` //小费 - TotalShopMoney int `orm:"column(totalShopMoney)" json:"totalShopMoney"` //平台结算 - PmSubsidyMoney int `orm:"column(pmSubsidyMoney)" json:"pmSubsidyMoney"` //平台补贴 - EarningPrice int `orm:"column(earningPrice)" json:"earningPrice"` //门店收益(预计收益) - TotalGrossProfit int `orm:"column(totalGrossProfit)" json:"totalGrossProfit"` //总毛利 - ComGrossProfit float32 `orm:"column(comGrossProfit)" json:"comGrossProfit"` //公司毛利 - CityManagerGrossProfit float32 `orm:"column(cityManagerGrossProfit)" json:"cityManagerGrossProfit"` //城市经理毛利 -} - -//是否存在这个门店 -func IsStoreExist(db *DaoDB, storeID int) (StatisticsForOrdersExists *StatisticsForOrdersExists, err error) { - sql := ` - SELECT * - FROM store - WHERE id = ? - ` - sqlParams := []interface{}{} - sqlParams = append(sqlParams, storeID) - - if err = GetRow(db, &StatisticsForOrdersExists, sql, sqlParams...); err == nil { - return StatisticsForOrdersExists, nil - } - return nil, err -} - -//查询条件内是否存在订单 -func GetStatisticsForOrdersExist(db *DaoDB, storeID int, fromDate time.Time, toDate time.Time) (StatisticsForOrdersExists *StatisticsForOrdersExists, err error) { - sql := ` - SELECT store_id - FROM goods_order a LEFT JOIN waybill b ON IF(a.waybill_vendor_id = -1,a.vendor_order_id,a.vendor_waybill_id) = b.vendor_waybill_id - WHERE a.store_id = ? - ` - sqlParams := []interface{}{} - sqlParams = append(sqlParams, storeID) - if !utils.IsTimeZero(fromDate) && !utils.IsTimeZero(toDate) { - sql += `AND a.order_created_at BETWEEN ? and ? - ` - sqlParams = append(sqlParams, fromDate, toDate) - } - sql += ` - GROUP BY a.store_id - ` - - if err = GetRow(db, &StatisticsForOrdersExists, sql, sqlParams...); err == nil { - return StatisticsForOrdersExists, nil - } - return nil, err + StoreName string `json:"name"` //门店名 + OrderCounts int `json:"orderCounts"` //订单数 + SalePrice int `json:"salePrice"` //GMV(售卖价) + ActualPayPrice int `json:"actualPayPrice"` //实付 + ShopPrice int `json:"shopPrice"` //京西 + DiscountMoney int `json:"discountMoney"` //优惠 + DesiredFee int `json:"desiredFee"` //配送费 + DistanceFreightMoney int `json:"distanceFreightMoney"` //远距离 + WaybillTipMoney int `json:"waybillTipMoney"` //小费 + TotalShopMoney int `json:"totalShopMoney"` //平台结算 + PmSubsidyMoney int `json:"pmSubsidyMoney"` //平台补贴 + EarningPrice int `json:"earningPrice"` //门店收益(预计收益) + TotalGrossProfit int `json:"totalGrossProfit"` //总毛利 + ComGrossProfit float32 `json:"comGrossProfit"` //公司毛利 + CityManagerGrossProfit float32 `json:"cityManagerGrossProfit"` //城市经理毛利 + MarketManName string `json:"marketManName"` //市场负责人 + OperatorName string `json:"operatorName"` //运营负责人 + OperatorName2 string `json:"operatorName2"` } //查询统计订单信息 @@ -75,26 +39,49 @@ func GetStatisticsReportForOrders(db *DaoDB, storeIDs []int, fromDate time.Time, //排除已取消的订单 status := strconv.Itoa(model.OrderStatusCanceled) sql := ` - SELECT s.*, - if(c.jx_brand_fee_factor = 0 AND c.market_add_fee_factor = 0,totalGrossProfit,(totalGrossProfit*c.jx_brand_fee_factor)/(c.jx_brand_fee_factor+market_add_fee_factor)) comGrossProfit, - if(c.jx_brand_fee_factor = 0 AND c.market_add_fee_factor = 0,0,(totalGrossProfit*c.market_add_fee_factor)/(c.jx_brand_fee_factor+market_add_fee_factor)) cityManagerGrossProfit - FROM store c,( - SELECT - a.store_id storeID, - count(*) orderCounts, - sum(sale_price) salePrice, - sum(actual_pay_price) actualPayPrice, - sum(shop_price) shopPrice, - sum(discount_money) discountMoney, - sum(desired_fee) desiredFee, - sum(distance_freight_money) distanceFreightMoney, - sum(waybill_tip_money) waybillTipMoney, - sum(total_shop_money) totalShopMoney, - sum(pm_subsidy_money) pmSubsidyMoney, - sum(earning_price) EarningPrice, - sum(total_shop_money-earning_price-desired_fee-distance_freight_money-waybill_tip_money-80) totalGrossProfit - FROM goods_order a LEFT JOIN waybill b on if(a.waybill_vendor_id = -1,a.vendor_order_id,a.vendor_waybill_id) = b.vendor_waybill_id - WHERE a.status != ` + status + ` + SELECT + c.id store_id, + c.name store_name, + s.orderCounts order_counts, + s.salePrice sale_price, + s.actualPayPrice actual_pay_price, + s.shopPrice shop_price, + s.discountMoney discount_money, + s.desiredFee desired_fee, + s.distanceFreightMoney distance_freight_money, + s.waybillTipMoney waybill_tip_money, + s.totalShopMoney total_shop_money, + s.pmSubsidyMoney pm_subsidy_money, + s.EarningPrice earning_price, + s.totalGrossProfit total_gross_profit, + IF(c.jx_brand_fee_factor = 0 AND c.market_add_fee_factor = 0,totalGrossProfit,(totalGrossProfit*c.jx_brand_fee_factor)/(c.jx_brand_fee_factor+market_add_fee_factor)) com_grossProfit, + IF(c.jx_brand_fee_factor = 0 AND c.market_add_fee_factor = 0,0,(totalGrossProfit*c.market_add_fee_factor)/(c.jx_brand_fee_factor+market_add_fee_factor)) city_manager_gross_profit, + IF(mm.name <> '', mm.name, mm.user_id2) market_man_name, + IF(om.name <> '', om.name, om.user_id2) operator_name, + IF(om2.name <> '', om2.name, om2.user_id2) operator_name2 + FROM store c + LEFT JOIN user mm ON mm.mobile <> '' AND mm.mobile = c.market_man_phone + LEFT JOIN user om ON om.mobile <> '' AND om.mobile = c.operator_phone + LEFT JOIN user om2 ON om2.mobile <> '' AND om2.mobile = c.operator_phone2 + LEFT JOIN + ( + SELECT + a.store_id storeID, + COUNT(*) orderCounts, + SUM(sale_price) salePrice, + SUM(actual_pay_price) actualPayPrice, + SUM(shop_price) shopPrice, + SUM(discount_money) discountMoney, + SUM(desired_fee) desiredFee, + SUM(distance_freight_money) distanceFreightMoney, + SUM(waybill_tip_money) waybillTipMoney, + SUM(total_shop_money) totalShopMoney, + SUM(pm_subsidy_money) pmSubsidyMoney, + SUM(earning_price) EarningPrice, + SUM(total_shop_money-earning_price-desired_fee-distance_freight_money-waybill_tip_money-80) totalGrossProfit + FROM goods_order a + LEFT JOIN waybill b ON IF(a.waybill_vendor_id = -1,a.vendor_order_id,a.vendor_waybill_id) = b.vendor_waybill_id + WHERE a.status != ` + status + ` ` sqlParams := []interface{}{} if !utils.IsTimeZero(fromDate) && !utils.IsTimeZero(toDate) { @@ -110,8 +97,13 @@ func GetStatisticsReportForOrders(db *DaoDB, storeIDs []int, fromDate time.Time, sql += ` GROUP BY a.store_id )s - WHERE s.storeID = c.id + ON s.storeID = c.id ` + if len(storeIDs) > 0 { + sql += `WHERE c.id IN (` + GenQuestionMarks(len(storeIDs)) + `) + ` + sqlParams = append(sqlParams, storeIDs) + } if err = GetRows(db, &statisticsReportForOrdersList, sql, sqlParams...); err == nil { return statisticsReportForOrdersList, nil } diff --git a/controllers/jx_report.go b/controllers/jx_report.go index 9450f576e..db0886210 100644 --- a/controllers/jx_report.go +++ b/controllers/jx_report.go @@ -29,3 +29,18 @@ func (c *ReportController) StatisticsReportForOrders() { return retVal, "", err }) } + +// @Title 查询售后单统计信息 +// @Description 根据门店idlist和时间范围查询 +// @Param token header string true "认证token" +// @Param storeIDs formData string true "京西门店ID列表[1,2,3]" +// @Param fromDate formData string true "开始日期(包含),格式(2006-01-02 00:00:00)" +// @Param toDate formData string true "结束日期(包含),格式(2006-01-02 00:00:00)" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /StatisticsReportForAfsOrders [post] +func (c *ReportController) StatisticsReportForAfsOrders() { + c.callStatisticsReportForAfsOrders(func(params *tReportStatisticsReportForAfsOrdersParams) (retVal interface{}, errCode string, err error) { + return retVal, "", err + }) +} From 7df7ba6242dd681b7bc79846a9b5fee790dddb99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 31 Oct 2019 17:31:40 +0800 Subject: [PATCH 29/31] =?UTF-8?q?=E5=94=AE=E5=90=8E=E5=8D=95=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + business/jxstore/report/report.go | 12 +++++ business/model/dao/report.go | 80 ++++++++++++++++++++++++++++++- controllers/jx_report.go | 4 ++ 4 files changed, 95 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 093f63d3f..14f76dcee 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ param_parser.go *.o *.exe *.exe~ +.vscode diff --git a/business/jxstore/report/report.go b/business/jxstore/report/report.go index 94a5bd5ff..0538ea1ab 100644 --- a/business/jxstore/report/report.go +++ b/business/jxstore/report/report.go @@ -21,3 +21,15 @@ func GetStatisticsReportForOrders(ctx *jxcontext.Context, storeIDs []int, fromDa statisticsReportForOrdersList, err = dao.GetStatisticsReportForOrders(db, storeIDs, fromDateParm, toDateParm) return statisticsReportForOrdersList, err } + +func GetStatisticsReportForAfsOrders(ctx *jxcontext.Context, storeIDs []int, fromDate string, toDate string) (statisticsReportForOrdersList []*dao.StatisticsReportForOrdersList, err error) { + db := dao.GetDB() + fromDateParm := utils.Str2Time(fromDate) + toDateParm := utils.Str2Time(toDate) + //若时间间隔大于3个月则不允许查询 + if math.Ceil(toDateParm.Sub(fromDateParm).Hours()/24) > 92 { + return nil, errors.New(fmt.Sprintf("查询间隔时间不允许大于3个月!: 时间范围:[%v] 至 [%v]", fromDate, toDate)) + } + statisticsReportForOrdersList, err = dao.GetGetStatisticsReportForAfsOrders(db, storeIDs, fromDateParm, toDateParm) + return statisticsReportForOrdersList, err +} diff --git a/business/model/dao/report.go b/business/model/dao/report.go index 2fe33a08f..1fdf80e60 100644 --- a/business/model/dao/report.go +++ b/business/model/dao/report.go @@ -85,12 +85,88 @@ func GetStatisticsReportForOrders(db *DaoDB, storeIDs []int, fromDate time.Time, ` sqlParams := []interface{}{} if !utils.IsTimeZero(fromDate) && !utils.IsTimeZero(toDate) { - sql += `AND a.order_created_at BETWEEN ? and ? + sql += `AND a.order_created_at BETWEEN ? AND ? ` sqlParams = append(sqlParams, fromDate, toDate) } if len(storeIDs) > 0 { - sql += `AND a.store_id in(` + GenQuestionMarks(len(storeIDs)) + `) + sql += `AND a.store_id IN(` + GenQuestionMarks(len(storeIDs)) + `) + ` + sqlParams = append(sqlParams, storeIDs) + } + sql += ` + GROUP BY a.store_id + )s + ON s.storeID = c.id + ` + if len(storeIDs) > 0 { + sql += `WHERE c.id IN (` + GenQuestionMarks(len(storeIDs)) + `) + ` + sqlParams = append(sqlParams, storeIDs) + } + if err = GetRows(db, &statisticsReportForOrdersList, sql, sqlParams...); err == nil { + return statisticsReportForOrdersList, nil + } + return nil, err +} + +//查询统计售后单信息 +func GetGetStatisticsReportForAfsOrders(db *DaoDB, storeIDs []int, fromDate time.Time, toDate time.Time) (statisticsReportForOrdersList []*StatisticsReportForOrdersList, err error) { + //排除已取消的订单 + status := strconv.Itoa(model.OrderStatusCanceled) + sql := ` + SELECT + c.id store_id, + c.name store_name, + s.orderCounts order_counts, + s.salePrice sale_price, + s.actualPayPrice actual_pay_price, + s.shopPrice shop_price, + s.discountMoney discount_money, + s.desiredFee desired_fee, + s.distanceFreightMoney distance_freight_money, + s.waybillTipMoney waybill_tip_money, + s.totalShopMoney total_shop_money, + s.pmSubsidyMoney pm_subsidy_money, + s.EarningPrice earning_price, + s.totalGrossProfit total_gross_profit, + IF(c.jx_brand_fee_factor = 0 AND c.market_add_fee_factor = 0,totalGrossProfit,(totalGrossProfit*c.jx_brand_fee_factor)/(c.jx_brand_fee_factor+market_add_fee_factor)) com_grossProfit, + IF(c.jx_brand_fee_factor = 0 AND c.market_add_fee_factor = 0,0,(totalGrossProfit*c.market_add_fee_factor)/(c.jx_brand_fee_factor+market_add_fee_factor)) city_manager_gross_profit, + IF(mm.name <> '', mm.name, mm.user_id2) market_man_name, + IF(om.name <> '', om.name, om.user_id2) operator_name, + IF(om2.name <> '', om2.name, om2.user_id2) operator_name2 + FROM store c + LEFT JOIN user mm ON mm.mobile <> '' AND mm.mobile = c.market_man_phone + LEFT JOIN user om ON om.mobile <> '' AND om.mobile = c.operator_phone + LEFT JOIN user om2 ON om2.mobile <> '' AND om2.mobile = c.operator_phone2 + LEFT JOIN + ( + SELECT + a.store_id storeID, + COUNT(*) orderCounts, + SUM(sale_price) salePrice, + SUM(actual_pay_price) actualPayPrice, + SUM(shop_price) shopPrice, + SUM(discount_money) discountMoney, + SUM(afs_freight_money) desiredFee, + SUM(distance_freight_money) distanceFreightMoney, + SUM(waybill_tip_money) waybillTipMoney, + SUM(total_shop_money) totalShopMoney, + SUM(b.pm_subsidy_money) pmSubsidyMoney, + SUM(earning_price) EarningPrice, + SUM(total_shop_money-earning_price-afs_freight_money-distance_freight_money-waybill_tip_money-80) totalGrossProfit + FROM goods_order a,afs_order b + WHERE a.vendor_order_id = b.vendor_order_id + AND a.status != ` + status + ` + ` + sqlParams := []interface{}{} + if !utils.IsTimeZero(fromDate) && !utils.IsTimeZero(toDate) { + sql += `AND a.order_created_at BETWEEN ? AND ? + ` + sqlParams = append(sqlParams, fromDate, toDate) + } + if len(storeIDs) > 0 { + sql += `AND a.store_id IN(` + GenQuestionMarks(len(storeIDs)) + `) ` sqlParams = append(sqlParams, storeIDs) } diff --git a/controllers/jx_report.go b/controllers/jx_report.go index db0886210..f839a14cc 100644 --- a/controllers/jx_report.go +++ b/controllers/jx_report.go @@ -41,6 +41,10 @@ func (c *ReportController) StatisticsReportForOrders() { // @router /StatisticsReportForAfsOrders [post] func (c *ReportController) StatisticsReportForAfsOrders() { c.callStatisticsReportForAfsOrders(func(params *tReportStatisticsReportForAfsOrdersParams) (retVal interface{}, errCode string, err error) { + var storeIDList []int + if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDList); err == nil { + retVal, err = report.GetStatisticsReportForAfsOrders(params.Ctx, storeIDList, params.FromDate, params.ToDate) + } return retVal, "", err }) } From 4a740c11ea0c1cfe7e041feff8ff71a5e2d3c221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 31 Oct 2019 17:33:15 +0800 Subject: [PATCH 30/31] .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 14f76dcee..2cfdc1b7e 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ param_parser.go *.exe *.exe~ .vscode +app.conf \ No newline at end of file From 4963b6875875ce46b129326ccd894ffc36710e35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 31 Oct 2019 17:43:50 +0800 Subject: [PATCH 31/31] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 - routers/commentsRouter_controllers.go | 28 ++++++++++++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 2cfdc1b7e..14f76dcee 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,3 @@ param_parser.go *.exe *.exe~ .vscode -app.conf \ No newline at end of file diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index 5dca35224..c8a8106c4 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -972,6 +972,24 @@ func init() { Filters: nil, Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ReportController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ReportController"], + beego.ControllerComments{ + Method: "StatisticsReportForAfsOrders", + Router: `/StatisticsReportForAfsOrders`, + AllowHTTPMethods: []string{"post"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ReportController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ReportController"], + beego.ControllerComments{ + Method: "StatisticsReportForOrders", + Router: `/StatisticsReportForOrders`, + AllowHTTPMethods: []string{"post"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SkuController"], beego.ControllerComments{ Method: "AddCategory", @@ -1952,13 +1970,5 @@ func init() { MethodParams: param.Make(), Filters: nil, Params: nil}) - - beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ReportController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ReportController"], - beego.ControllerComments{ - Method: "StatisticsReportForOrders", - Router: `/StatisticsReportForOrders`, - AllowHTTPMethods: []string{"post"}, - MethodParams: param.Make(), - Filters: nil, - Params: nil}) + }