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
|
||||
}
|
||||
|
||||
@@ -520,6 +520,7 @@ func RefreshOrderSkuRelated(order *model.GoodsOrder) *model.GoodsOrder {
|
||||
order.VendorPrice = 0
|
||||
order.ShopPrice = 0
|
||||
order.Weight = 0
|
||||
order.EarningPrice = 0
|
||||
for _, sku := range order.Skus {
|
||||
if sku.SkuID > math.MaxInt32 {
|
||||
sku.SkuID = 0
|
||||
@@ -532,6 +533,7 @@ func RefreshOrderSkuRelated(order *model.GoodsOrder) *model.GoodsOrder {
|
||||
order.SalePrice += sku.SalePrice * int64(sku.Count)
|
||||
order.VendorPrice += sku.VendorPrice * int64(sku.Count)
|
||||
order.ShopPrice += sku.ShopPrice * int64(sku.Count)
|
||||
order.EarningPrice += sku.EarningPrice * int64(sku.Count)
|
||||
order.Weight += sku.Weight * sku.Count
|
||||
}
|
||||
return order
|
||||
|
||||
@@ -36,7 +36,7 @@ type OrderSkuWithActualPayPrice struct {
|
||||
PayPercentage int `json:"payPercentage"`
|
||||
}
|
||||
|
||||
func QueryOrders(db *DaoDB, vendorIDs []int, storeID int, orderCreatedAtBegin, orderCreatedAtEnd time.Time) (orderList []*model.GoodsOrder, err error) {
|
||||
func QueryOrders(db *DaoDB, vendorOrderID string, vendorIDs []int, storeID int, orderCreatedAtBegin, orderCreatedAtEnd time.Time) (orderList []*model.GoodsOrder, err error) {
|
||||
sql := `
|
||||
SELECT t1.*
|
||||
FROM goods_order t1
|
||||
@@ -44,6 +44,10 @@ func QueryOrders(db *DaoDB, vendorIDs []int, storeID int, orderCreatedAtBegin, o
|
||||
sqlParams := []interface{}{
|
||||
orderCreatedAtBegin,
|
||||
}
|
||||
if vendorOrderID != "" {
|
||||
sql += " AND t1.vendor_order_id = ?"
|
||||
sqlParams = append(sqlParams, vendorOrderID)
|
||||
}
|
||||
if len(vendorIDs) > 0 {
|
||||
sql += " AND t1.vendor_id IN (" + GenQuestionMarks(len(vendorIDs)) + ")"
|
||||
sqlParams = append(sqlParams, vendorIDs)
|
||||
|
||||
@@ -741,6 +741,29 @@ func (c *OrderController) AmendMissingOrders() {
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 同步刷新历史订单的结算价按订单
|
||||
// @Description 同步刷新历史订单的结算价按订单
|
||||
// @Param token header string true "认证token"
|
||||
// @Param fromDate formData string true "订单起始日期"
|
||||
// @Param toDate formData string true "订单结束日期"
|
||||
// @Param vendorOrderID formData string false "订单号"
|
||||
// @Param vendorIDs formData int false "平台ID列表[0,1,3]"
|
||||
// @Param storeID formData int false "门店ID"
|
||||
// @Param isAsync formData bool true "是否异步操作"
|
||||
// @Param isContinueWhenError formData bool false "单个失败是否继续,缺省true"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /RefreshHistoryOrdersEarningPrice [post]
|
||||
func (c *OrderController) RefreshHistoryOrdersEarningPrice() {
|
||||
c.callRefreshHistoryOrdersEarningPrice(func(params *tOrderRefreshHistoryOrdersEarningPriceParams) (retVal interface{}, errCode string, err error) {
|
||||
var vendorIDList []int
|
||||
if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDList); err == nil {
|
||||
err = orderman.FixedOrderManager.RefreshHistoryOrdersEarningPrice(params.Ctx, params.VendorOrderID, vendorIDList, params.StoreID, params.FromDate, params.ToDate, params.IsAsync, params.IsContinueWhenError)
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 商家主动发起部分退款售后
|
||||
// @Description 商家主动发起部分退款售后
|
||||
// @Param token header string true "认证token"
|
||||
|
||||
@@ -918,6 +918,15 @@ func init() {
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"],
|
||||
beego.ControllerComments{
|
||||
Method: "RefreshHistoryOrdersEarningPrice",
|
||||
Router: `/RefreshHistoryOrdersEarningPrice`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"],
|
||||
beego.ControllerComments{
|
||||
Method: "RefreshOrderFinancial",
|
||||
|
||||
Reference in New Issue
Block a user