From 9c5c28273586d04e2cca8d6ab43be24264b50d78 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, 7 Nov 2019 10:55:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=B7=E6=96=B0=E5=8E=86=E5=8F=B2=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxcallback/orderman/order.go | 5 +-- business/model/dao/dao_order.go | 44 +++++++++++++++++++++++++++ controllers/jx_order.go | 9 +++--- 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index 36d4abbde..ab109290f 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -613,7 +613,7 @@ func (c *OrderManager) UpdateOrderFields(order *model.GoodsOrder, fieldList []st return err } -func (c *OrderManager) RefreshHistoryOrdersEarningPrice(ctx *jxcontext.Context, vendorOrderID string, vendorIDs []int, storeID int, fromDate string, toDate string, isAsync, isContinueWhenError bool) (hint string, err error) { +func (c *OrderManager) RefreshHistoryOrdersEarningPrice(ctx *jxcontext.Context, vendorOrderID string, actIDs []int, vendorIDs []int, storeID int, fromDate string, toDate string, isAsync, isContinueWhenError bool) (hint string, err error) { db := dao.GetDB() fromDateParam := utils.Str2Time(fromDate) toDateParam := utils.Str2Time(toDate) @@ -621,7 +621,8 @@ func (c *OrderManager) RefreshHistoryOrdersEarningPrice(ctx *jxcontext.Context, if math.Ceil(toDateParam.Sub(fromDateParam).Hours()/24) > 10 { return "", errors.New(fmt.Sprintf("查询间隔时间不允许大于10天!时间范围:[%v] 至 [%v]", fromDate, toDate)) } - orderList, _ := dao.QueryOrders(db, vendorOrderID, vendorIDs, storeID, fromDateParam, toDateParam) + // orderList, _ := dao.QueryOrders(db, vendorOrderID, vendorIDs, storeID, fromDateParam, toDateParam) + orderList, _ := dao.QueryOrdersFilterByAct(db, vendorOrderID, actIDs, vendorIDs, storeID, fromDateParam, toDateParam) if len(orderList) <= 0 { return "", errors.New(fmt.Sprintf("未查询到订单!,vendorOrderID : %s, 时间范围:[%v] 至 [%v]", vendorOrderID, fromDate, toDate)) } diff --git a/business/model/dao/dao_order.go b/business/model/dao/dao_order.go index d0b247ea2..f9b2945e2 100644 --- a/business/model/dao/dao_order.go +++ b/business/model/dao/dao_order.go @@ -593,3 +593,47 @@ func GetRiskOrderCount(db *DaoDB, dayNum int, includeToday bool) (storeOrderList return storeOrderList, GetRows(db, &storeOrderList, sql, sqlParams) } + +func QueryOrdersFilterByAct(db *DaoDB, vendorOrderID string, actIDs, vendorIDs []int, storeID int, fromDate, toDate time.Time) (orderList []*model.GoodsOrderExt, err error) { + sql := ` + SELECT a.vendor_order_id, a.vendor_id + FROM goods_order a + JOIN order_sku b ON a.vendor_order_id = b.vendor_order_id + JOIN (SELECT t1.begin_at,t1.end_at, t2.act_id,t2.store_id, t2.sku_id + FROM act t1 + JOIN act_store_sku t2 ON t2.act_id = t1.id + WHERE t1.status = 1 + ` + sqlParams := []interface{}{} + if len(actIDs) > 0 { + sql += " AND t1.id IN (" + GenQuestionMarks(len(actIDs)) + ")" + sqlParams = append(sqlParams, actIDs) + } + sql += ` + )s + ON s.store_id = a.store_id + AND s.sku_id = b.sku_id + AND a.order_created_at BETWEEN s.begin_at AND s.end_at + WHERE 1=1 + ` + if vendorOrderID != "" { + sql += " AND a.vendor_order_id = ?" + sqlParams = append(sqlParams, vendorOrderID) + } + if len(vendorIDs) > 0 { + sql += " AND a.vendor_id IN (" + GenQuestionMarks(len(vendorIDs)) + ")" + sqlParams = append(sqlParams, vendorIDs) + } + if storeID > 0 { + sql += " AND IF(a.jx_store_id <> 0, a.jx_store_id, a.store_id) = ?" + 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 1,2 + ` + return orderList, GetRows(db, &orderList, sql, sqlParams...) +} diff --git a/controllers/jx_order.go b/controllers/jx_order.go index cc0be95db..ec3aac94a 100644 --- a/controllers/jx_order.go +++ b/controllers/jx_order.go @@ -748,17 +748,18 @@ func (c *OrderController) AmendMissingOrders() { // @Param toTime formData string true "订单结束时间 (yyyy-mm-dd hh:ms:ss)" // @Param vendorOrderID formData string false "订单号" // @Param vendorIDs formData string false "平台ID列表[0,1,3]" +// @Param actIDs formData string false "活动ID列表[0,1,3]" // @Param storeID formData int false "门店ID" -// @Param isAsync formData bool true "是否异步操作" +// @Param isAsync formData bool false "是否异步操作" // @Param isContinueWhenError formData bool false "单个失败是否继续,缺省true" // @Success 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult // @router /RefreshHistoryOrdersEarningPrice [post] func (c *OrderController) RefreshHistoryOrdersEarningPrice() { c.callRefreshHistoryOrdersEarningPrice(func(params *tOrderRefreshHistoryOrdersEarningPriceParams) (retVal interface{}, errCode string, err error) { - var vendorIDList []int - if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDList); err == nil { - retVal, err = orderman.FixedOrderManager.RefreshHistoryOrdersEarningPrice(params.Ctx, params.VendorOrderID, vendorIDList, params.StoreID, params.FromTime, params.ToTime, params.IsAsync, params.IsContinueWhenError) + var vendorIDList, actIDList []int + if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDList, params.ActIDs, &actIDList); err == nil { + retVal, err = orderman.FixedOrderManager.RefreshHistoryOrdersEarningPrice(params.Ctx, params.VendorOrderID, actIDList, vendorIDList, params.StoreID, params.FromTime, params.ToTime, params.IsAsync, params.IsContinueWhenError) } return retVal, "", err })