Merge branch 'mark' of e.coding.net:rosydev/jx-callback into mark
This commit is contained in:
@@ -1,14 +1,19 @@
|
||||
package orderman
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
|
||||
"git.rosy.net.cn/baseapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/scheduler"
|
||||
"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/business/partner"
|
||||
@@ -257,7 +262,7 @@ func (c *OrderManager) SaveOrder(order *model.GoodsOrder, isAdjust bool, db *dao
|
||||
order.VendorStatus = orderStatus.VendorStatus
|
||||
order.StatusTime = orderStatus.StatusTime
|
||||
|
||||
jxutils.RefreshOrderSkuRelated(order)
|
||||
// jxutils.RefreshOrderSkuRelated(order)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -344,7 +349,6 @@ func (c *OrderManager) updateOrderSkuOtherInfo(order *model.GoodsOrder, db *dao.
|
||||
skumapper[v.VendorSkuID] = v
|
||||
}
|
||||
|
||||
skuIDMap := make(map[int]int)
|
||||
for _, v := range orderSkus {
|
||||
v.VendorOrderID = order.VendorOrderID
|
||||
v.VendorID = order.VendorID
|
||||
@@ -364,33 +368,36 @@ func (c *OrderManager) updateOrderSkuOtherInfo(order *model.GoodsOrder, db *dao.
|
||||
}
|
||||
}
|
||||
v.EarningPrice = jxutils.CaculateSkuEarningPrice(v.ShopPrice, v.SalePrice, storePayPercentage)
|
||||
|
||||
if skuID := jxutils.GetSkuIDFromOrderSku(v); skuID > 0 {
|
||||
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) {
|
||||
@@ -413,22 +420,22 @@ func (c *OrderManager) updateOrderOtherInfo(order *model.GoodsOrder, db *dao.Dao
|
||||
}
|
||||
if err = c.updateOrderSkuOtherInfo(order, db, payPercentage); err == nil {
|
||||
jxutils.RefreshOrderSkuRelated(order)
|
||||
caculateOrderEarningPrice(order, payPercentage)
|
||||
// caculateOrderEarningPrice(order, payPercentage)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// 计算结算给门店的金额
|
||||
func caculateOrderEarningPrice(order *model.GoodsOrder, storePayPercentage int) {
|
||||
order.EarningPrice = 0
|
||||
for _, v := range order.Skus {
|
||||
skuEarningPrice := v.EarningPrice
|
||||
if skuEarningPrice == 0 {
|
||||
skuEarningPrice = jxutils.CaculateSkuEarningPrice(v.ShopPrice, v.SalePrice, storePayPercentage)
|
||||
}
|
||||
order.EarningPrice += skuEarningPrice * int64(v.Count)
|
||||
}
|
||||
}
|
||||
// func caculateOrderEarningPrice(order *model.GoodsOrder, storePayPercentage int) {
|
||||
// order.EarningPrice = 0
|
||||
// for _, v := range order.Skus {
|
||||
// skuEarningPrice := v.EarningPrice
|
||||
// if skuEarningPrice == 0 {
|
||||
// skuEarningPrice = jxutils.CaculateSkuEarningPrice(v.ShopPrice, v.SalePrice, storePayPercentage)
|
||||
// }
|
||||
// order.EarningPrice += skuEarningPrice * int64(v.Count)
|
||||
// }
|
||||
// }
|
||||
|
||||
func (c *OrderManager) addOrderStatus(orderStatus *model.OrderStatus, db *dao.DaoDB) (isDuplicated bool, order *model.GoodsOrder, err error) {
|
||||
globals.SugarLogger.Debugf("addOrderStatus refOrderID:%s, orderID:%s", orderStatus.RefVendorOrderID, orderStatus.VendorOrderID)
|
||||
@@ -605,3 +612,49 @@ func (c *OrderManager) UpdateOrderFields(order *model.GoodsOrder, fieldList []st
|
||||
}, "UpdateOrderFields orderID:%s failed with error:%v", order.VendorOrderID, err)
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *OrderManager) RefreshHistoryOrdersEarningPrice(ctx *jxcontext.Context, vendorOrderID string, vendorIDs []int, storeID int, fromDate string, toDate string, isAsync, isContinueWhenError bool) (err error) {
|
||||
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))
|
||||
}
|
||||
orderList, _ := dao.QueryOrders(db, vendorOrderID, vendorIDs, storeID, fromDateParam, toDateParam)
|
||||
if len(orderList) <= 0 {
|
||||
return errors.New(fmt.Sprintf("未查询到订单!,vendorOrderID : %s, 时间范围:[%v] 至 [%v]", vendorOrderID, fromDate, toDate))
|
||||
}
|
||||
task := tasksch.NewParallelTask("刷新历史订单结算价", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
v := batchItemList[0].(*model.GoodsOrder)
|
||||
db := dao.GetDB()
|
||||
order, _ := c.loadOrder(v.VendorOrderID, "", v.VendorID)
|
||||
updateSingleOrderEarningPrice(order, db)
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil || err != nil {
|
||||
dao.Rollback(db)
|
||||
if r != nil {
|
||||
panic(r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
for _, value := range order.Skus {
|
||||
if _, err = dao.UpdateEntity(db, value, "EarningPrice", "StoreSubID"); err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
jxutils.RefreshOrderSkuRelated(order)
|
||||
if _, err = dao.UpdateEntity(db, order, "EarningPrice"); err != nil {
|
||||
return "", err
|
||||
}
|
||||
dao.Commit(db)
|
||||
return retVal, err
|
||||
}, orderList)
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
if !isAsync {
|
||||
_, err = task.GetResult(0)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -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, vendorIDs, storeID, fromDate, toDate.Add(24*time.Hour-time.Second))
|
||||
localOrders, err2 := dao.QueryOrders(db, "", vendorIDs, storeID, fromDate, toDate.Add(24*time.Hour-time.Second))
|
||||
if err = err2; err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user