刷新历史订单结算价修改
This commit is contained in:
@@ -613,18 +613,36 @@ func (c *OrderManager) UpdateOrderFields(order *model.GoodsOrder, fieldList []st
|
|||||||
return err
|
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()
|
db := dao.GetDB()
|
||||||
fromDateParam := utils.Str2Time(fromDate)
|
if actID > 0 {
|
||||||
toDateParam := utils.Str2Time(toDate)
|
actList, _ := dao.QueryActs(db, actID, 0, math.MaxInt32, 0, "", 0, nil, nil, nil, 0, 0, 0, time.Time{}, time.Time{}, time.Time{}, time.Time{})
|
||||||
//若时间间隔大于10天则不允许查询
|
if len(actList.Data) > 0 {
|
||||||
if math.Ceil(toDateParam.Sub(fromDateParam).Hours()/24) > 10 {
|
orderList, _ = dao.QueryOrders(db, vendorOrderID, actID, vendorIDs, storeID, actList.Data[0].BeginAt, actList.Data[0].EndAt)
|
||||||
return "", errors.New(fmt.Sprintf("查询间隔时间不允许大于10天!时间范围:[%v] 至 [%v]", fromDate, toDate))
|
} 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 {
|
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,
|
task := tasksch.NewParallelTask("刷新历史订单结算价", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||||
|
|||||||
@@ -1169,7 +1169,7 @@ func (c *OrderManager) AmendMissingOrders(ctx *jxcontext.Context, vendorIDs []in
|
|||||||
if err = err2; err != nil && !isContinueWhenError {
|
if err = err2; err != nil && !isContinueWhenError {
|
||||||
return "", err
|
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 {
|
if err = err2; err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
if err = err2; err != nil {
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ type OrderSkuWithActualPayPrice struct {
|
|||||||
|
|
||||||
type tGoodsAndOrder struct {
|
type tGoodsAndOrder struct {
|
||||||
model.GoodsOrder
|
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用
|
StoreSubID int `orm:"column(store_sub_id)" json:"storeSubID"` // 当前这个字段被当成结算活动ID用
|
||||||
StoreSubName string `orm:"size(64)" json:"storeSubName"` // 当前这个字段被用作vendorActType
|
StoreSubName string `orm:"size(64)" json:"storeSubName"` // 当前这个字段被用作vendorActType
|
||||||
Count int `json:"count"`
|
Count int `json:"count"`
|
||||||
@@ -55,14 +55,17 @@ type tGoodsAndOrder struct {
|
|||||||
PromotionType int `json:"promotionType"` // todo 当前是用于记录京东的PromotionType(生成jxorder用),没有做转换
|
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{}{}
|
sqlParams := []interface{}{}
|
||||||
var (
|
var (
|
||||||
orderNewList []*tGoodsAndOrder
|
orderNewList []*tGoodsAndOrder
|
||||||
orderNewMap map[string][]*model.OrderSku
|
orderNewMap map[string][]*model.OrderSku
|
||||||
)
|
)
|
||||||
sql := `
|
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
|
FROM goods_order a
|
||||||
JOIN order_sku b ON a.vendor_order_id = b.vendor_order_id
|
JOIN order_sku b ON a.vendor_order_id = b.vendor_order_id
|
||||||
WHERE 1=1
|
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 ?"
|
sql += " AND a.order_created_at BETWEEN ? and ?"
|
||||||
sqlParams = append(sqlParams, fromDate, toDate)
|
sqlParams = append(sqlParams, fromDate, toDate)
|
||||||
}
|
}
|
||||||
if len(actIDs) > 0 {
|
if actID > 0 {
|
||||||
sql += `
|
sql += `
|
||||||
AND a.vendor_order_id IN
|
AND a.vendor_order_id IN
|
||||||
(SELECT b.vendor_order_id
|
( SELECT DISTINCT t4.vendor_order_id
|
||||||
FROM act t1
|
FROM act t1
|
||||||
JOIN act_store_sku t2 ON t2.act_id = t1.id
|
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
|
WHERE t1.status = 1
|
||||||
AND t1.id IN (` + GenQuestionMarks(len(actIDs)) + `)
|
AND t1.type = ?
|
||||||
AND t2.store_id = a.store_id
|
AND t1.id = ?
|
||||||
AND a.order_created_at BETWEEN t1.begin_at AND t1.end_at
|
|
||||||
)
|
)
|
||||||
`
|
`
|
||||||
sqlParams = append(sqlParams, actIDs)
|
sqlParams = append(sqlParams, model.ActSkuFake, actID)
|
||||||
}
|
}
|
||||||
err = GetRows(db, &orderNewList, sql, sqlParams...)
|
err = GetRows(db, &orderNewList, sql, sqlParams...)
|
||||||
if len(orderNewList) > 0 {
|
if len(orderNewList) > 0 {
|
||||||
|
|||||||
@@ -744,11 +744,11 @@ func (c *OrderController) AmendMissingOrders() {
|
|||||||
// @Title 同步刷新历史订单的结算价按订单
|
// @Title 同步刷新历史订单的结算价按订单
|
||||||
// @Description 同步刷新历史订单的结算价按订单
|
// @Description 同步刷新历史订单的结算价按订单
|
||||||
// @Param token header string true "认证token"
|
// @Param token header string true "认证token"
|
||||||
// @Param fromTime formData string true "订单起始时间 (yyyy-mm-dd hh:ms:ss)"
|
// @Param fromTime formData string false "订单起始时间 (yyyy-mm-dd hh:ms:ss)"
|
||||||
// @Param toTime formData string true "订单结束时间 (yyyy-mm-dd hh:ms:ss)"
|
// @Param toTime formData string false "订单结束时间 (yyyy-mm-dd hh:ms:ss)"
|
||||||
// @Param vendorOrderID formData string false "订单号"
|
// @Param vendorOrderID formData string false "订单号"
|
||||||
// @Param vendorIDs formData string false "平台ID列表[0,1,3]"
|
// @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 storeID formData int false "门店ID"
|
||||||
// @Param isAsync formData bool false "是否异步操作"
|
// @Param isAsync formData bool false "是否异步操作"
|
||||||
// @Param isContinueWhenError formData bool false "单个失败是否继续,缺省true"
|
// @Param isContinueWhenError formData bool false "单个失败是否继续,缺省true"
|
||||||
@@ -757,9 +757,9 @@ func (c *OrderController) AmendMissingOrders() {
|
|||||||
// @router /RefreshHistoryOrdersEarningPrice [post]
|
// @router /RefreshHistoryOrdersEarningPrice [post]
|
||||||
func (c *OrderController) RefreshHistoryOrdersEarningPrice() {
|
func (c *OrderController) RefreshHistoryOrdersEarningPrice() {
|
||||||
c.callRefreshHistoryOrdersEarningPrice(func(params *tOrderRefreshHistoryOrdersEarningPriceParams) (retVal interface{}, errCode string, err error) {
|
c.callRefreshHistoryOrdersEarningPrice(func(params *tOrderRefreshHistoryOrdersEarningPriceParams) (retVal interface{}, errCode string, err error) {
|
||||||
var vendorIDList, actIDList []int
|
var vendorIDList []int
|
||||||
if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDList, params.ActIDs, &actIDList); err == nil {
|
if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDList); err == nil {
|
||||||
retVal, err = orderman.FixedOrderManager.RefreshHistoryOrdersEarningPrice(params.Ctx, params.VendorOrderID, actIDList, vendorIDList, params.StoreID, params.FromTime, params.ToTime, params.IsAsync, params.IsContinueWhenError)
|
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
|
return retVal, "", err
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user