订单结算价刷新
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -375,28 +374,35 @@ func (c *OrderManager) updateOrderSkuOtherInfo(order *model.GoodsOrder, db *dao.
|
||||
skuIDMap[skuID] = 1
|
||||
}
|
||||
}
|
||||
updateSingleOrderEarningPrice(order, db)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(skuIDMap) > 0 {
|
||||
actStoreSkuList, err := dao.GetEffectiveActStoreSkuInfo(db, 0, []int{order.VendorID}, []int{jxStoreID}, jxutils.IntMap2List(skuIDMap), order.OrderCreatedAt, order.OrderCreatedAt)
|
||||
if err != nil {
|
||||
globals.SugarLogger.Errorf("updateOrderSkuOtherInfo can not get sku promotion info for error:%v", err)
|
||||
return err
|
||||
}
|
||||
if actStoreSkuMap := jxutils.NewActStoreSkuMap(actStoreSkuList, false); actStoreSkuMap != nil {
|
||||
for _, v := range orderSkus {
|
||||
if skuID := jxutils.GetSkuIDFromOrderSku(v); skuID > 0 {
|
||||
if actStoreSku := actStoreSkuMap.GetActStoreSku(jxStoreID, skuID, order.VendorID); actStoreSku != nil {
|
||||
v.EarningPrice = actStoreSku.EarningPrice
|
||||
if true { //v.StoreSubName != "" { // 之前这里为什么要加判断?
|
||||
v.StoreSubID = actStoreSku.ActID
|
||||
}
|
||||
func updateSingleOrderEarningPrice(order *model.GoodsOrder, db *dao.DaoDB) {
|
||||
jxStoreID := jxutils.GetShowStoreIDFromOrder(order)
|
||||
skuIDMap := make(map[int]int)
|
||||
for _, v := range order.Skus {
|
||||
skuIDMap[v.SkuID] = 1
|
||||
}
|
||||
if len(skuIDMap) > 0 {
|
||||
actStoreSkuList, err := dao.GetEffectiveActStoreSkuInfo(db, 0, []int{order.VendorID}, []int{jxStoreID}, jxutils.IntMap2List(skuIDMap), order.OrderCreatedAt, order.OrderCreatedAt)
|
||||
if err != nil {
|
||||
globals.SugarLogger.Errorf("updateOrderSkuOtherInfo can not get sku promotion info for error:%v", err)
|
||||
}
|
||||
if actStoreSkuMap := jxutils.NewActStoreSkuMap(actStoreSkuList, false); actStoreSkuMap != nil {
|
||||
for _, v := range order.Skus {
|
||||
if skuID := jxutils.GetSkuIDFromOrderSku(v); skuID > 0 {
|
||||
if actStoreSku := actStoreSkuMap.GetActStoreSku(jxStoreID, skuID, order.VendorID); actStoreSku != nil {
|
||||
v.EarningPrice = actStoreSku.EarningPrice
|
||||
if true { //v.StoreSubName != "" { // 之前这里为什么要加判断?
|
||||
v.StoreSubID = actStoreSku.ActID
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *OrderManager) updateOrderOtherInfo(order *model.GoodsOrder, db *dao.DaoDB) (err error) {
|
||||
@@ -612,7 +618,7 @@ func (c *OrderManager) UpdateOrderFields(order *model.GoodsOrder, fieldList []st
|
||||
return err
|
||||
}
|
||||
|
||||
func RefreshHistoryOrdersEarningPrice(ctx *jxcontext.Context, fromDate string, toDate string, isAsync, isContinueWhenError bool, vendorOrderId string) (err error) {
|
||||
func (c *OrderManager) RefreshHistoryOrdersEarningPrice(ctx *jxcontext.Context, fromDate string, toDate string, isAsync, isContinueWhenError bool, vendorOrderId int) (err error) {
|
||||
db := dao.GetDB()
|
||||
fromDateParm := utils.Str2Time(fromDate)
|
||||
toDateParm := utils.Str2Time(toDate)
|
||||
@@ -620,35 +626,36 @@ func RefreshHistoryOrdersEarningPrice(ctx *jxcontext.Context, fromDate string, t
|
||||
if math.Ceil(toDateParm.Sub(fromDateParm).Hours()/24) > 10 {
|
||||
return errors.New(fmt.Sprintf("查询间隔时间不允许大于10天!时间范围:[%v] 至 [%v]", fromDate, toDate))
|
||||
}
|
||||
orderSkus, _ := dao.GetOrdersByCreateTime(db, fromDateParm, toDateParm, vendorOrderId)
|
||||
if len(orderSkus) == 0 {
|
||||
return errors.New(fmt.Sprintf("未查询到订单!时间范围:[%v] 至 [%v]", fromDate, toDate))
|
||||
}
|
||||
|
||||
orderList, _ := dao.QueryOrders(db, []int{vendorOrderId}, 0, fromDateParm, toDateParm)
|
||||
task := tasksch.NewSeqTask("按订单刷新历史订单结算价", ctx,
|
||||
func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
switch step {
|
||||
case 0:
|
||||
task1 := tasksch.NewParallelTask("更新order_sku", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
v := batchItemList[0].(*model.OrderSku)
|
||||
storeID, _ := strconv.Atoi(utils.Int64ToStr(v.ID))
|
||||
actStoreSkuList, err := dao.GetEffectiveActStoreSkuInfo(db, 0, []int{v.VendorID}, []int{storeID}, []int{v.SkuID}, fromDateParm, toDateParm)
|
||||
if err != nil {
|
||||
globals.SugarLogger.Errorf("updateOrderSkuOtherInfo can not get sku promotion info for error:%v", err)
|
||||
return "", err
|
||||
}
|
||||
if actStoreSkuMap := jxutils.NewActStoreSkuMap(actStoreSkuList, false); actStoreSkuMap != nil {
|
||||
for _, value := range actStoreSkuList {
|
||||
num, err := dao.UpdateOrderSkuEariningPrice(db, value, fromDateParm, toDateParm)
|
||||
if err != nil && !isContinueWhenError {
|
||||
return "", err
|
||||
} else {
|
||||
globals.SugarLogger.Debug(fmt.Sprintf("更新order_sku , 行数:%d, storeid :%d ,skuid : %d, vendoreid : %d, earningPrice : %v, store_sub_id : %d", num, value.StoreID, value.SkuID, value.VendorID, value.EarningPrice, value.ActID))
|
||||
v := batchItemList[0].(*model.GoodsOrder)
|
||||
order, _ := c.loadOrder(v.VendorOrderID, "", v.VendorID)
|
||||
updateSingleOrderEarningPrice(order, db)
|
||||
for _, orderSku := range order.Skus {
|
||||
actStoreSkuList, err := dao.GetEffectiveActStoreSkuInfo(db, 0, []int{v.VendorID}, []int{v.StoreID}, []int{orderSku.SkuID}, v.OrderCreatedAt, v.OrderCreatedAt)
|
||||
if err != nil {
|
||||
globals.SugarLogger.Errorf("updateOrderSkuOtherInfo can not get sku promotion info for error:%v", err)
|
||||
return "", err
|
||||
}
|
||||
if actStoreSkuMap := jxutils.NewActStoreSkuMap(actStoreSkuList, false); actStoreSkuMap != nil {
|
||||
for _, value := range actStoreSkuList {
|
||||
num, err := dao.UpdateOrderSkuEariningPrice(db, value, fromDateParm, toDateParm)
|
||||
if err != nil && !isContinueWhenError {
|
||||
return "", err
|
||||
} else {
|
||||
globals.SugarLogger.Debug(fmt.Sprintf("更新order_sku , 行数:%d, storeid :%d ,skuid : %d, vendoreid : %d, earningPrice : %v, store_sub_id : %d", num, value.StoreID, value.SkuID, value.VendorID, value.EarningPrice, value.ActID))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return retVal, err
|
||||
}, orderSkus)
|
||||
}, orderList)
|
||||
tasksch.HandleTask(task1, task, true).Run()
|
||||
case 1:
|
||||
num2, err2 := dao.UpdateGoodOrderEaringPrice(db, fromDateParm, toDateParm)
|
||||
|
||||
Reference in New Issue
Block a user