刷新历史订单结算价
This commit is contained in:
@@ -349,7 +349,6 @@ func (c *OrderManager) updateOrderSkuOtherInfo(order *model.GoodsOrder, db *dao.
|
|||||||
skumapper[v.VendorSkuID] = v
|
skumapper[v.VendorSkuID] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
skuIDMap := make(map[int]int)
|
|
||||||
for _, v := range orderSkus {
|
for _, v := range orderSkus {
|
||||||
v.VendorOrderID = order.VendorOrderID
|
v.VendorOrderID = order.VendorOrderID
|
||||||
v.VendorID = order.VendorID
|
v.VendorID = order.VendorID
|
||||||
@@ -369,10 +368,6 @@ func (c *OrderManager) updateOrderSkuOtherInfo(order *model.GoodsOrder, db *dao.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
v.EarningPrice = jxutils.CaculateSkuEarningPrice(v.ShopPrice, v.SalePrice, storePayPercentage)
|
v.EarningPrice = jxutils.CaculateSkuEarningPrice(v.ShopPrice, v.SalePrice, storePayPercentage)
|
||||||
|
|
||||||
if skuID := jxutils.GetSkuIDFromOrderSku(v); skuID > 0 {
|
|
||||||
skuIDMap[skuID] = 1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
updateSingleOrderEarningPrice(order, db)
|
updateSingleOrderEarningPrice(order, db)
|
||||||
}
|
}
|
||||||
@@ -618,21 +613,19 @@ func (c *OrderManager) UpdateOrderFields(order *model.GoodsOrder, fieldList []st
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *OrderManager) RefreshHistoryOrdersEarningPrice(ctx *jxcontext.Context, fromDate string, toDate string, isAsync, isContinueWhenError bool, vendorOrderId int) (err error) {
|
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()
|
db := dao.GetDB()
|
||||||
fromDateParm := utils.Str2Time(fromDate)
|
fromDateParam := utils.Str2Time(fromDate)
|
||||||
toDateParm := utils.Str2Time(toDate)
|
toDateParam := utils.Str2Time(toDate)
|
||||||
//若时间间隔大于10天则不允许查询
|
//若时间间隔大于10天则不允许查询
|
||||||
if math.Ceil(toDateParm.Sub(fromDateParm).Hours()/24) > 10 {
|
if math.Ceil(toDateParam.Sub(fromDateParam).Hours()/24) > 10 {
|
||||||
return errors.New(fmt.Sprintf("查询间隔时间不允许大于10天!时间范围:[%v] 至 [%v]", fromDate, toDate))
|
return errors.New(fmt.Sprintf("查询间隔时间不允许大于10天!时间范围:[%v] 至 [%v]", fromDate, toDate))
|
||||||
}
|
}
|
||||||
|
orderList, _ := dao.QueryOrders(db, vendorOrderId, vendorIDs, storeId, fromDateParam, toDateParam)
|
||||||
orderList, _ := dao.QueryOrders(db, []int{}, 0, fromDateParm, toDateParm)
|
if len(orderList) <= 0 {
|
||||||
task := tasksch.NewSeqTask("按订单刷新历史订单结算价", ctx,
|
return errors.New(fmt.Sprintf("未查询到订单!,vendorOrderId : %s, 时间范围:[%v] 至 [%v]", vendorOrderId, fromDate, toDate))
|
||||||
func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
}
|
||||||
switch step {
|
task := tasksch.NewParallelTask("刷新历史订单结算价", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||||
case 0:
|
|
||||||
task1 := tasksch.NewParallelTask("更新order_sku", 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) {
|
||||||
v := batchItemList[0].(*model.GoodsOrder)
|
v := batchItemList[0].(*model.GoodsOrder)
|
||||||
db := dao.GetDB()
|
db := dao.GetDB()
|
||||||
@@ -648,33 +641,19 @@ func (c *OrderManager) RefreshHistoryOrdersEarningPrice(ctx *jxcontext.Context,
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
for _, value := range order.Skus {
|
for _, value := range order.Skus {
|
||||||
if _, err := dao.UpdateEntity(db, value); err != nil && !isContinueWhenError {
|
if _, err := dao.UpdateEntity(db, value, "EarningPrice", "StoreSubID"); err != nil {
|
||||||
if !dao.IsDuplicateError(err) {
|
|
||||||
globals.SugarLogger.Warnf("On RefreshHistoryOrdersEarningPrice order.VendorOrderID:%s err:%v", order.VendorOrderID, err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
dao.Rollback(db)
|
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jxutils.RefreshOrderSkuRelated(order)
|
jxutils.RefreshOrderSkuRelated(order)
|
||||||
if _, err2 := dao.UpdateEntity(db, order); err2 != nil && !isContinueWhenError {
|
if _, err2 := dao.UpdateEntity(db, order, "EarningPrice"); err2 != nil {
|
||||||
if !dao.IsDuplicateError(err) {
|
|
||||||
globals.SugarLogger.Warnf("On RefreshHistoryOrdersEarningPrice order.VendorOrderID:%s err:%v", order.VendorOrderID, err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
dao.Rollback(db)
|
|
||||||
return "", err2
|
return "", err2
|
||||||
}
|
}
|
||||||
dao.Commit(db)
|
dao.Commit(db)
|
||||||
c.SaveOrder(order, true, db)
|
|
||||||
return retVal, err
|
return retVal, err
|
||||||
}, orderList)
|
}, orderList)
|
||||||
tasksch.HandleTask(task1, task, true).Run()
|
|
||||||
}
|
|
||||||
return result, err
|
|
||||||
}, 1)
|
|
||||||
tasksch.HandleTask(task, nil, true).Run()
|
tasksch.HandleTask(task, nil, true).Run()
|
||||||
|
|
||||||
if !isAsync {
|
if !isAsync {
|
||||||
_, err = task.GetResult(0)
|
_, err = task.GetResult(0)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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, 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 {
|
if err = err2; err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ type OrderSkuWithActualPayPrice struct {
|
|||||||
PayPercentage int `json:"payPercentage"`
|
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 := `
|
sql := `
|
||||||
SELECT t1.*
|
SELECT t1.*
|
||||||
FROM goods_order t1
|
FROM goods_order t1
|
||||||
@@ -44,6 +44,10 @@ func QueryOrders(db *DaoDB, vendorIDs []int, storeID int, orderCreatedAtBegin, o
|
|||||||
sqlParams := []interface{}{
|
sqlParams := []interface{}{
|
||||||
orderCreatedAtBegin,
|
orderCreatedAtBegin,
|
||||||
}
|
}
|
||||||
|
if vendorOrderId != "" {
|
||||||
|
sql += " AND t1.vendor_order_id = ?"
|
||||||
|
sqlParams = append(sqlParams, vendorOrderId)
|
||||||
|
}
|
||||||
if len(vendorIDs) > 0 {
|
if len(vendorIDs) > 0 {
|
||||||
sql += " AND t1.vendor_id IN (" + GenQuestionMarks(len(vendorIDs)) + ")"
|
sql += " AND t1.vendor_id IN (" + GenQuestionMarks(len(vendorIDs)) + ")"
|
||||||
sqlParams = append(sqlParams, vendorIDs)
|
sqlParams = append(sqlParams, vendorIDs)
|
||||||
|
|||||||
@@ -746,15 +746,20 @@ func (c *OrderController) AmendMissingOrders() {
|
|||||||
// @Param token header string true "认证token"
|
// @Param token header string true "认证token"
|
||||||
// @Param fromDate formData string true "订单起始日期"
|
// @Param fromDate formData string true "订单起始日期"
|
||||||
// @Param toDate 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 isAsync formData bool true "是否异步操作"
|
||||||
// @Param isContinueWhenError formData bool false "单个失败是否继续,缺省true"
|
// @Param isContinueWhenError formData bool false "单个失败是否继续,缺省true"
|
||||||
// @Param vendorOrderId formData int false "订单号(测试用)"
|
|
||||||
// @Success 200 {object} controllers.CallResult
|
// @Success 200 {object} controllers.CallResult
|
||||||
// @Failure 200 {object} controllers.CallResult
|
// @Failure 200 {object} controllers.CallResult
|
||||||
// @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) {
|
||||||
err = orderman.FixedOrderManager.RefreshHistoryOrdersEarningPrice(params.Ctx, params.FromDate, params.ToDate, params.IsAsync, params.IsContinueWhenError, params.VendorOrderId)
|
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
|
return retVal, "", err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user