Merge remote-tracking branch 'origin/mark' into jdshop

This commit is contained in:
苏尹岚
2021-03-25 18:23:44 +08:00
58 changed files with 2075 additions and 550 deletions

View File

@@ -138,7 +138,7 @@ func (c *OrderManager) OnOrderAdjust(order *model.GoodsOrder, orderStatus *model
// }, "OnAdjustOrder delete order_sku, orderID:%s", order.VendorOrderID)
order.AdjustCount = adjustCount + 1
//扣点的订单需要修改订单的totalshopmoney
if err == nil && order.OrderPayPercentage < 100 {
if err == nil && order.OrderPayPercentage < 50 && order.OrderPayPercentage > 0 {
order2, _ := partner.GetPurchaseOrderHandlerFromVendorID(order.VendorID).GetOrder(order.VendorOrgCode, order.VendorOrderID, order.VendorStoreID)
order.TotalShopMoney = order2.TotalShopMoney
}
@@ -345,14 +345,12 @@ func (c *OrderManager) SaveOrder(order *model.GoodsOrder, isAdjust bool, db *dao
} else {
globals.SugarLogger.Warnf("saveOrder create order:%v, error:%v", order, err)
}
if err == nil {
dao.Commit(db)
}
//修改商品库存
if err == nil {
utils.CallFuncAsync(func() {
err = ModifyOrderSkusStock(db, order, false)
})
err = ModifyOrderSkusStock(db, order, false)
}
if err == nil {
dao.Commit(db)
}
return isDuplicated, err
}
@@ -384,7 +382,7 @@ func ModifyOrderSkusStock(db *dao.DaoDB, order *model.GoodsOrder, isAdd bool) (e
if len(storeSkus2) > 0 {
storeSku3 := storeSkus2[0]
storeSku3.Stock = storeSku3.Stock + sku.Count
dao.UpdateEntity(db, storeSku3, "Stock")
db.Db.Update(storeSku3, "Stock")
}
}
realStock := checkPriceDefendOrderByStock(db, jxutils.GetSaleStoreIDFromOrder(order), sku.SkuID, stock, storeSku.JxPrice)
@@ -393,9 +391,9 @@ func ModifyOrderSkusStock(db *dao.DaoDB, order *model.GoodsOrder, isAdd bool) (e
}
}
storeSku.Stock = stock
dao.UpdateEntity(db, storeSku, "Stock")
db.Db.Update(storeSku, "Stock")
if order.VendorID != model.VendorIDJX {
dao.SetStoreSkuSyncStatus(db, order.VendorID, []int{jxutils.GetSaleStoreIDFromOrder(order)}, []int{sku.SkuID}, model.SyncFlagStockMask)
// dao.SetStoreSkuSyncStatus(db, order.VendorID, []int{jxutils.GetSaleStoreIDFromOrder(order)}, []int{sku.SkuID}, model.SyncFlagStockMask)
}
}
return err
@@ -545,35 +543,25 @@ func (c *OrderManager) updateOrderSkuOtherInfo(order *model.GoodsOrder, db *dao.
//TODO 京东美团的订单,做活动的商品之前就会拆分出来,所以只做更新,饿百暂时不管, 2020-05-07
//TODO 不根据商品是否拆分直接根据该商品做了活动并且他的vendorPrice 和 salePrice 相等,就按新规则结算, 2020-05-11
//TODO 现在不判断商品做没做活动只要vendorPrice和salePrice不等就默认为做了活动不做活动的商品就按新规则结算2020-05-18
if order.VendorID == model.VendorIDJD || order.VendorID == model.VendorIDMTWM {
for _, v := range orderSkus {
if v.EarningPrice > 0 {
// var storeID int
// if order.StoreID == 0 {
// storeID = order.JxStoreID
// } else {
// storeID = order.StoreID
// }
// result, err := dao.GetEffectiveActStoreSkuInfo2(db, 0, []int{order.VendorID}, []int{model.ActSkuSecKill, model.ActSkuDirectDown}, []int{storeID}, []int{v.SkuID}, order.OrderCreatedAt, order.OrderCreatedAt)
// if (len(result) > 0 && err == nil) || v.IsVendorAct == model.YES {
if v.VendorPrice == v.SalePrice {
var earningPrice = 0
if v.ShopPrice < v.SalePrice {
if v.ShopPrice == 0 {
earningPrice = int(utils.Float64TwoInt64(math.Round(utils.Int2Float64(int(v.SalePrice)) * utils.Int2Float64(storePayPercentage) / 100)))
} else {
earningPrice = int(utils.Float64TwoInt64(math.Round(utils.Int2Float64(int(v.ShopPrice)) * utils.Int2Float64(storePayPercentage) / 100)))
}
} else {
earningPrice = int(utils.Float64TwoInt64(math.Round(utils.Int2Float64(int(v.SalePrice)) * utils.Int2Float64(storePayPercentage) / 100)))
}
v.EarningPrice = int64(earningPrice)
// v.StoreSubID = 0
}
// }
}
}
}
// if order.VendorID == model.VendorIDJD || order.VendorID == model.VendorIDMTWM {
// for _, v := range orderSkus {
// if v.EarningPrice > 0 {
// if v.VendorPrice == v.SalePrice {
// var earningPrice = 0
// if v.ShopPrice < v.SalePrice {
// if v.ShopPrice == 0 {
// earningPrice = int(utils.Float64TwoInt64(math.Round(utils.Int2Float64(int(v.SalePrice)) * utils.Int2Float64(storePayPercentage) / 100)))
// } else {
// earningPrice = int(utils.Float64TwoInt64(math.Round(utils.Int2Float64(int(v.ShopPrice)) * utils.Int2Float64(storePayPercentage) / 100)))
// }
// } else {
// earningPrice = int(utils.Float64TwoInt64(math.Round(utils.Int2Float64(int(v.SalePrice)) * utils.Int2Float64(storePayPercentage) / 100)))
// }
// v.EarningPrice = int64(earningPrice)
// }
// }
// }
// }
}
return nil
}
@@ -1941,8 +1929,8 @@ func UpdateOrderInfo(ctx *jxcontext.Context, vendorOrderID string, vendorID int,
func RefreshOrderSkuInfo(ctx *jxcontext.Context, vendorOrderID string, vendorID, skuID int) (num int64, err error) {
var (
db = dao.GetDB()
shopPrice int64
db = dao.GetDB()
shopPrice, earningPrice int64
)
order, err := partner.CurOrderManager.LoadOrder(vendorOrderID, vendorID)
if order.EarningType != model.EarningTypeQuote {
@@ -1954,8 +1942,11 @@ func RefreshOrderSkuInfo(ctx *jxcontext.Context, vendorOrderID string, vendorID,
return fmt.Errorf("未找到此门店商品!")
}
storeSku := storeSkus[0]
if v.ShopPrice == v.EarningPrice {
v.EarningPrice = int64(math.Round(float64(storeSku.Price) * float64(order.OrderPayPercentage) / 100))
}
v.ShopPrice = int64(storeSku.Price)
dao.UpdateEntity(db, v, "ShopPrice")
dao.UpdateEntity(db, v, "ShopPrice", "EarningPrice")
return err
}
dao.Begin(db)
@@ -1981,9 +1972,11 @@ func RefreshOrderSkuInfo(ctx *jxcontext.Context, vendorOrderID string, vendorID,
}
for _, v := range order.Skus {
shopPrice += v.ShopPrice * int64(v.Count)
earningPrice += v.EarningPrice * int64(v.Count)
}
order.ShopPrice = shopPrice
num, err = dao.UpdateEntity(db, order, "ShopPrice")
order.EarningPrice = earningPrice
num, err = dao.UpdateEntity(db, order, "ShopPrice", "EarningPrice")
dao.Commit(db)
return num, err
}

View File

@@ -12,10 +12,9 @@ import (
"github.com/astaxie/beego"
"git.rosy.net.cn/jx-callback/globals/api"
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
"git.rosy.net.cn/baseapi/platformapi/jdapi"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/business/jxutils/excel"
@@ -74,7 +73,14 @@ func (c *OrderManager) GetStoreOrderCountInfo(ctx *jxcontext.Context, storeID, l
} else if lastHours == 0 && lastMinutes == 0 {
lastHours = defLastHours
}
//权限
if permission.IsRoled(ctx) {
if storeIDsMap, err := permission.GetUserStoresResultMap(ctx.GetUserID()); err == nil {
if storeIDsMap[storeID] == 0 {
storeID = -1
}
}
}
db := dao.GetDB()
sql := `
SELECT t1.lock_status, t1.status, COUNT(*) count
@@ -301,6 +307,9 @@ func (c *OrderManager) GetOrders(ctx *jxcontext.Context, isIncludeFake bool, fro
}
}
}
if len(storeIDs2) == 0 {
storeIDs2 = append(storeIDs2, -1)
}
} else {
for k, _ := range storeIDsMap {
storeIDs2 = append(storeIDs2, k)
@@ -345,6 +354,9 @@ func (c *OrderManager) ExportOrders(ctx *jxcontext.Context, fromDateStr, toDateS
}
}
}
if len(storeIDs2) == 0 {
storeIDs2 = append(storeIDs2, -1)
}
} else {
for k, _ := range storeIDsMap {
storeIDs2 = append(storeIDs2, k)
@@ -385,12 +397,18 @@ func (c *OrderManager) ExportOrders(ctx *jxcontext.Context, fromDateStr, toDateS
}, ",")
} else {
if v.EarningType == model.EarningTypeQuote {
earningPrice := 0
if v.SkuEarningPrice != 0 {
earningPrice = v.SkuEarningPrice
} else {
earningPrice = v.SkuShopPrice
}
skuStr = strings.Join([]string{
utils.Int2Str(v.SkuID),
utils.Int2Str(v.SkuCount2),
utils.Int2Str(v.SkuEarningPrice),
utils.Int2Str(v.SkuSalePrice),
utils.Int2Str(v.SkuShopPrice),
utils.Int2Str(v.SkuSalePrice),
utils.Int2Str(earningPrice),
}, ",")
} else {
skuStr = strings.Join([]string{
@@ -759,7 +777,7 @@ func (c *OrderManager) GetStoresOrderSaleInfoNew(ctx *jxcontext.Context, storeID
//成都菜市
if beego.BConfig.RunMode == "prod" || beego.BConfig.RunMode == "beta" {
if v.EarningType == model.EarningTypeQuote {
saleInfo.RealEarningPrice += v.ShopPrice * int64(v.Count)
saleInfo.RealEarningPrice += v.EarningPrice * int64(v.Count)
}
} else {
if v.OrderPayPercentage == 100 {
@@ -900,6 +918,9 @@ func (c *OrderManager) GetAfsOrders(ctx *jxcontext.Context, keyword, afsOrderID,
storeIDs2 = append(storeIDs2, v)
}
}
if len(storeIDs2) == 0 {
storeIDs2 = append(storeIDs2, -1)
}
} else {
for k, _ := range storeIDsMap {
storeIDs2 = append(storeIDs2, k)
@@ -1399,9 +1420,16 @@ func GetMatterStoreOrderCount(ctx *jxcontext.Context, storeID int) (result *Orde
func RefreshJdShopOrdersEarningPrice(ctx *jxcontext.Context, orderStartTime, orderEndTime string) (err error) {
var (
db = dao.GetDB()
db = dao.GetDB()
appOrgCode string
)
results, err := api.JdAPI.GetJdShopOrders(utils.Str2Time(orderStartTime).Format("20060102"), utils.Str2Time(orderEndTime).Format("20060102"), globals.JdOrgCode, globals.JdLoginName)
if beego.BConfig.RunMode == "jxgy" {
appOrgCode = "339032"
} else {
appOrgCode = "320406"
}
jdapi := partner.CurAPIManager.GetAPI(model.VendorIDJD, appOrgCode).(*jdapi.API)
results, err := jdapi.GetJdShopOrders(utils.Str2Time(orderStartTime).Format("20060102"), utils.Str2Time(orderEndTime).Format("20060102"), globals.JdOrgCode, globals.JdLoginName)
if err != nil {
return err
}
@@ -1414,12 +1442,12 @@ func RefreshJdShopOrdersEarningPrice(ctx *jxcontext.Context, orderStartTime, ord
stores, _ := dao.GetStoreList(db, []int{jxutils.GetSaleStoreIDFromOrder(order)}, nil, nil, nil, nil, "")
if len(stores) > 0 {
store := stores[0]
if order.NewEarningPrice == 0 {
jxutils.RefreshOrderEarningPrice2(order, store.PayPercentage)
}
if order.TotalShopMoney == 0 {
order.TotalShopMoney = utils.Float64TwoInt64(v.DueAmount * 100)
}
if order.NewEarningPrice == 0 {
jxutils.RefreshOrderEarningPrice2(order, store.PayPercentage)
}
dao.UpdateEntity(db, order, "TotalShopMoney", "NewEarningPrice")
}
}