diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index 5cec26237..2be8b30a2 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -613,18 +613,36 @@ func (c *OrderManager) UpdateOrderFields(order *model.GoodsOrder, fieldList []st return err } -func (c *OrderManager) RefreshHistoryOrdersEarningPrice(ctx *jxcontext.Context, vendorOrderID string, actIDs, vendorIDs []int, storeID int, fromDate, toDate string, isAsync, isContinueWhenError bool) (hint string, err error) { +func (c *OrderManager) RefreshHistoryOrdersEarningPrice(ctx *jxcontext.Context, vendorOrderID string, actID int, vendorIDs []int, storeID int, fromDate, toDate string, isAsync, isContinueWhenError bool) (hint string, err error) { + var ( + orderList []*model.GoodsOrder + fromDateParam time.Time + toDateParam time.Time + ) db := dao.GetDB() - fromDateParam := utils.Str2Time(fromDate) - toDateParam := utils.Str2Time(toDate) - //若时间间隔大于10天则不允许查询 - if math.Ceil(toDateParam.Sub(fromDateParam).Hours()/24) > 10 { - return "", errors.New(fmt.Sprintf("查询间隔时间不允许大于10天!时间范围:[%v] 至 [%v]", fromDate, toDate)) + if actID > 0 { + actList, _ := dao.QueryActs(db, actID, 0, math.MaxInt32, 0, "", 0, nil, nil, nil, 0, 0, 0, time.Time{}, time.Time{}, time.Time{}, time.Time{}) + if len(actList.Data) > 0 { + orderList, _ = dao.QueryOrders(db, vendorOrderID, actID, vendorIDs, storeID, actList.Data[0].BeginAt, actList.Data[0].EndAt) + } else { + return "", errors.New(fmt.Sprintf("未查询到相关结算活动,活动ID:[%d]", actID)) + } + } else { + if fromDate != "" && toDate != "" { + fromDateParam = utils.Str2Time(fromDate) + toDateParam = utils.Str2Time(toDate) + //若未传入活动ID,且时间间隔大于10天则不允许查询 + 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, actID, vendorIDs, storeID, fromDateParam, toDateParam) + } else { + return "", errors.New(fmt.Sprintf("若不按活动查询则间隔时间必须完整!时间范围:[%v] 至 [%v]", fromDate, toDate)) + } } - // orderList, _ := dao.QueryOrders(db, vendorOrderID, vendorIDs, storeID, fromDateParam, toDateParam) - orderList, _ := dao.QueryOrders(db, vendorOrderID, actIDs, vendorIDs, storeID, fromDateParam, toDateParam) if len(orderList) <= 0 { - return "", errors.New(fmt.Sprintf("未查询到订单!,vendorOrderID : %s, 时间范围:[%v] 至 [%v]", vendorOrderID, fromDate, toDate)) + return "", errors.New(fmt.Sprintf("未查询到订单!,vendorOrderID : %s, actID : %d, 时间范围:[%v] 至 [%v]", vendorOrderID, actID, fromDate, toDate)) } task := tasksch.NewParallelTask("刷新历史订单结算价", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx, func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { diff --git a/business/jxcallback/orderman/orderman_ext.go b/business/jxcallback/orderman/orderman_ext.go index 9bef94868..b41cef313 100644 --- a/business/jxcallback/orderman/orderman_ext.go +++ b/business/jxcallback/orderman/orderman_ext.go @@ -1169,7 +1169,7 @@ func (c *OrderManager) AmendMissingOrders(ctx *jxcontext.Context, vendorIDs []in if err = err2; err != nil && !isContinueWhenError { return "", err } - localOrders, err2 := dao.QueryOrders(db, "", []int{}, vendorIDs, storeID, fromDate, toDate.Add(24*time.Hour-time.Second)) + localOrders, err2 := dao.QueryOrders(db, "", 0, vendorIDs, storeID, fromDate, toDate.Add(24*time.Hour-time.Second)) if err = err2; err != nil { return "", err } diff --git a/business/jxstore/act/act.go b/business/jxstore/act/act.go index 85c1d6e6f..f0b127d25 100644 --- a/business/jxstore/act/act.go +++ b/business/jxstore/act/act.go @@ -104,7 +104,7 @@ func ActStoreSkuParam2Model(ctx *jxcontext.Context, db *dao.DaoDB, act *model.Ac } } - storeSkuList, err2 := dao.GetStoresSkusInfo(db, storeIDs, skuIDs) + storeSkuList, err2 := dao.GetStoresSkusInfo(db, storeIDs, skuIDs, false) if err = err2; err != nil { return nil, nil, nil, err } diff --git a/business/model/dao/dao_order.go b/business/model/dao/dao_order.go index f5395e136..59a065a16 100644 --- a/business/model/dao/dao_order.go +++ b/business/model/dao/dao_order.go @@ -38,7 +38,7 @@ type OrderSkuWithActualPayPrice struct { type tGoodsAndOrder struct { model.GoodsOrder - OrderSkuID int64 `orm:"column(order_sku_id)" json:"id"` + OrderSkuID int64 `orm:"column(order_sku_id)" json:"orderSkuID"` StoreSubID int `orm:"column(store_sub_id)" json:"storeSubID"` // 当前这个字段被当成结算活动ID用 StoreSubName string `orm:"size(64)" json:"storeSubName"` // 当前这个字段被用作vendorActType Count int `json:"count"` @@ -55,14 +55,17 @@ type tGoodsAndOrder struct { PromotionType int `json:"promotionType"` // todo 当前是用于记录京东的PromotionType(生成jxorder用),没有做转换 } -func QueryOrders(db *DaoDB, vendorOrderID string, actIDs, vendorIDs []int, storeID int, fromDate, toDate time.Time) (orderList []*model.GoodsOrder, err error) { +//actID指结算活动的id +func QueryOrders(db *DaoDB, vendorOrderID string, actID int, vendorIDs []int, storeID int, fromDate, toDate time.Time) (orderList []*model.GoodsOrder, err error) { sqlParams := []interface{}{} var ( orderNewList []*tGoodsAndOrder orderNewMap map[string][]*model.OrderSku ) sql := ` - SELECT a.*,b.id order_sku_id, b.store_sub_id, b.store_sub_name, b.count, b.vendor_sku_id, b.sku_id, b.jx_sku_id, b.sku_name, b.shop_price sku_shop_price, b.vendor_price sku_vendor_price, b.sale_price sku_sale_price, b.earning_price sku_earning_price, b.weight, b.sku_type, b.promotion_type + SELECT a.*, + b.id order_sku_id, b.store_sub_id, b.store_sub_name, b.count, b.vendor_sku_id, b.sku_id, b.jx_sku_id, b.sku_name, b.shop_price sku_shop_price, + b.vendor_price sku_vendor_price, b.sale_price sku_sale_price, b.earning_price sku_earning_price, b.weight, b.sku_type, b.promotion_type FROM goods_order a JOIN order_sku b ON a.vendor_order_id = b.vendor_order_id WHERE 1=1 @@ -83,20 +86,23 @@ func QueryOrders(db *DaoDB, vendorOrderID string, actIDs, vendorIDs []int, store sql += " AND a.order_created_at BETWEEN ? and ?" sqlParams = append(sqlParams, fromDate, toDate) } - if len(actIDs) > 0 { + if actID > 0 { sql += ` - AND a.vendor_order_id IN - (SELECT b.vendor_order_id + AND a.vendor_order_id IN + ( SELECT DISTINCT t4.vendor_order_id FROM act t1 JOIN act_store_sku t2 ON t2.act_id = t1.id - JOIN order_sku b ON b.sku_id = t2.sku_id + JOIN order_sku t3 ON t3.sku_id = t2.sku_id + JOIN goods_order t4 ON t4.vendor_order_id = t3.vendor_order_id + AND t4.vendor_id = t3.vendor_id + AND t2.store_id = IF(t4.jx_store_id <> 0, t4.jx_store_id, t4.store_id) + AND t4.order_created_at BETWEEN t1.begin_at AND t1.end_at WHERE t1.status = 1 - AND t1.id IN (` + GenQuestionMarks(len(actIDs)) + `) - AND t2.store_id = a.store_id - AND a.order_created_at BETWEEN t1.begin_at AND t1.end_at + AND t1.type = ? + AND t1.id = ? ) ` - sqlParams = append(sqlParams, actIDs) + sqlParams = append(sqlParams, model.ActSkuFake, actID) } err = GetRows(db, &orderNewList, sql, sqlParams...) if len(orderNewList) > 0 { diff --git a/controllers/jx_order.go b/controllers/jx_order.go index ec3aac94a..4fe21002f 100644 --- a/controllers/jx_order.go +++ b/controllers/jx_order.go @@ -744,11 +744,11 @@ func (c *OrderController) AmendMissingOrders() { // @Title 同步刷新历史订单的结算价按订单 // @Description 同步刷新历史订单的结算价按订单 // @Param token header string true "认证token" -// @Param fromTime formData string true "订单起始时间 (yyyy-mm-dd hh:ms:ss)" -// @Param toTime formData string true "订单结束时间 (yyyy-mm-dd hh:ms:ss)" +// @Param fromTime formData string false "订单起始时间 (yyyy-mm-dd hh:ms:ss)" +// @Param toTime formData string false "订单结束时间 (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 actID formData int false "活动ID" // @Param storeID formData int false "门店ID" // @Param isAsync formData bool false "是否异步操作" // @Param isContinueWhenError formData bool false "单个失败是否继续,缺省true" @@ -757,9 +757,9 @@ func (c *OrderController) AmendMissingOrders() { // @router /RefreshHistoryOrdersEarningPrice [post] func (c *OrderController) RefreshHistoryOrdersEarningPrice() { c.callRefreshHistoryOrdersEarningPrice(func(params *tOrderRefreshHistoryOrdersEarningPriceParams) (retVal interface{}, errCode string, err error) { - 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) + var vendorIDList []int + if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDList); err == nil { + retVal, err = orderman.FixedOrderManager.RefreshHistoryOrdersEarningPrice(params.Ctx, params.VendorOrderID, params.ActID, vendorIDList, params.StoreID, params.FromTime, params.ToTime, params.IsAsync, params.IsContinueWhenError) } return retVal, "", err })