新增按订单刷新历史订单结算价
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"
|
||||
@@ -605,3 +610,47 @@ func (c *OrderManager) UpdateOrderFields(order *model.GoodsOrder, fieldList []st
|
||||
}, "UpdateOrderFields orderID:%s failed with error:%v", order.VendorOrderID, err)
|
||||
return err
|
||||
}
|
||||
|
||||
func RefreshHistoryOrdersEarningPrice(ctx *jxcontext.Context, fromDate string, toDate string, isAsync, isContinueWhenError bool) (err error) {
|
||||
db := dao.GetDB()
|
||||
fromDateParm := utils.Str2Time(fromDate)
|
||||
toDateParm := utils.Str2Time(toDate)
|
||||
//若时间间隔大于10天则不允许查询
|
||||
if math.Ceil(toDateParm.Sub(fromDateParm).Hours()/24) > 10 {
|
||||
return errors.New(fmt.Sprintf("查询间隔时间不允许大于10天!: 时间范围:[%v] 至 [%v]", fromDate, toDate))
|
||||
}
|
||||
actStoreSkuList, err := dao.GetEffectiveActStoreSkuInfo(db, 0, []int{}, []int{}, []int{}, 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) {
|
||||
if actStoreSkuMap := jxutils.NewActStoreSkuMap(actStoreSkuList, false); actStoreSkuMap != nil {
|
||||
v := batchItemList[0].(*model.ActStoreSku2)
|
||||
num, err := dao.UpdateOrderSkuEariningPrice(db, v, 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, v.StoreID, v.SkuID, v.VendorID, v.EarningPrice, v.ActID))
|
||||
}
|
||||
}
|
||||
return retVal, err
|
||||
}, actStoreSkuList)
|
||||
tasksch.HandleTask(task1, task, true).Run()
|
||||
case 1:
|
||||
num2, err2 := dao.UpdateGoodOrderEaringPrice(db, fromDateParm, toDateParm)
|
||||
if err2 != nil && !isContinueWhenError {
|
||||
return "", err2
|
||||
} else {
|
||||
globals.SugarLogger.Debug(fmt.Sprintf("更新goods_order , 行数:%d, 时间: %v 至 %v", num2, fromDateParm, toDateParm))
|
||||
}
|
||||
}
|
||||
return result, err
|
||||
}, 2)
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
if !isAsync {
|
||||
_, err = task.GetResult(0)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -589,3 +589,52 @@ func GetRiskOrderCount(db *DaoDB, dayNum int, includeToday bool) (storeOrderList
|
||||
|
||||
return storeOrderList, GetRows(db, &storeOrderList, sql, sqlParams)
|
||||
}
|
||||
|
||||
func UpdateOrderSkuEariningPrice(db *DaoDB, actStoreSku2 *model.ActStoreSku2, fromDateParm, toDateParm time.Time) (num int64, err error) {
|
||||
sql := `
|
||||
UPDATE order_sku t1
|
||||
JOIN goods_order tt1 ON tt1.vendor_order_id = t1.vendor_order_id
|
||||
AND tt1.vendor_id = ?
|
||||
AND t1.sku_id = ?
|
||||
AND tt1.jx_store_id = ?
|
||||
AND tt1.order_created_at BETWEEN ? and ?
|
||||
SET t1.earning_price = ?,t1.store_sub_id = ?
|
||||
WHERE t1.store_sub_id = 0
|
||||
AND t1.earning_price <> 0
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
actStoreSku2.VendorID,
|
||||
actStoreSku2.SkuID,
|
||||
actStoreSku2.StoreID,
|
||||
fromDateParm,
|
||||
toDateParm,
|
||||
actStoreSku2.EarningPrice,
|
||||
actStoreSku2.ActID,
|
||||
}
|
||||
return ExecuteSQL(db, sql, sqlParams...)
|
||||
}
|
||||
|
||||
func UpdateGoodOrderEaringPrice(db *DaoDB, fromDateParm, toDateParm time.Time) (num int64, err error) {
|
||||
sql := `
|
||||
UPDATE goods_order t1
|
||||
JOIN(
|
||||
SELECT
|
||||
IF(t0.jx_store_id > 0, t0.jx_store_id, t0.store_id) store_id,
|
||||
t0.vendor_id,
|
||||
t0.vendor_order_id,
|
||||
CAST(SUM(t1.count * IF(t1.earning_price <> 0, t1.earning_price, IF(t1.shop_price <> 0 && t1.shop_price < t1.sale_price, t1.shop_price, t1.sale_price) * IF(t5.pay_percentage > 0, t5.pay_percentage, 70) / 100)) AS SIGNED) earning_price
|
||||
FROM goods_order t0
|
||||
JOIN order_sku t1 ON t1.vendor_order_id = t0.vendor_order_id AND t1.vendor_id = t0.vendor_id
|
||||
LEFT JOIN store t5 ON t5.id = IF(t0.jx_store_id <> 0, t0.jx_store_id, t0.store_id)
|
||||
WHERE t0.order_created_at BETWEEN ? AND ?
|
||||
GROUP BY 1,2,3
|
||||
) t2 ON t2.vendor_order_id = t1.vendor_order_id AND t2.vendor_id = t1.vendor_id
|
||||
SET t1.earning_price = t2.earning_price
|
||||
WHERE t1.earning_price <> t2.earning_price
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
fromDateParm,
|
||||
toDateParm,
|
||||
}
|
||||
return ExecuteSQL(db, sql, sqlParams...)
|
||||
}
|
||||
|
||||
@@ -741,6 +741,23 @@ func (c *OrderController) AmendMissingOrders() {
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 同步刷新历史订单的结算价按订单
|
||||
// @Description 同步刷新历史订单的结算价按订单
|
||||
// @Param token header string true "认证token"
|
||||
// @Param fromDate formData string true "订单起始日期"
|
||||
// @Param toDate formData string true "订单结束日期"
|
||||
// @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) {
|
||||
err = orderman.RefreshHistoryOrdersEarningPrice(params.Ctx, 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