+ CreateConsumerFromOrders
This commit is contained in:
@@ -190,7 +190,7 @@ func HandleOrder4Consignee(order *model.GoodsOrder) (err error) {
|
||||
if err == nil {
|
||||
vendorUserID = ""
|
||||
if user == nil {
|
||||
if user, err = dao.GetUserByID(db, "UserID", authInfo.UserID); err != nil {
|
||||
if user, err = dao.GetUserByID(db, "user_id", authInfo.UserID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -999,3 +999,99 @@ func RefreshMtpsWaybillFee(ctx *jxcontext.Context, isAsync, isContinueWhenError
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func CreateConsumerFromOrders(ctx *jxcontext.Context, vendorIDs []int, fromDate, toDate time.Time, isForce, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
if utils.IsTimeZero(fromDate) {
|
||||
return "", fmt.Errorf("fromDate必须指定")
|
||||
}
|
||||
if utils.IsTimeZero(toDate) {
|
||||
toDate = time.Now()
|
||||
}
|
||||
fromDate = utils.Time2Date(fromDate)
|
||||
toDate = utils.Time2Date(toDate)
|
||||
if len(vendorIDs) == 0 {
|
||||
vendorIDs = partner.GetPurchasePlatformVendorIDs()
|
||||
}
|
||||
var dateList []time.Time
|
||||
curDate := fromDate
|
||||
for {
|
||||
if toDate.Sub(curDate) < 0 {
|
||||
break
|
||||
}
|
||||
dateList = append(dateList, curDate)
|
||||
curDate = curDate.Add(24 * time.Hour)
|
||||
}
|
||||
|
||||
type GoodsOrderWithOriginal struct {
|
||||
model.GoodsOrder
|
||||
OriginalData string `orm:"type(text)" json:"-"`
|
||||
}
|
||||
|
||||
db := dao.GetDB()
|
||||
rootTask := tasksch.NewParallelTask("RefreshMtpsWaybillFee", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
curDate := batchItemList[0].(time.Time)
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM goods_order t1
|
||||
LEFT JOIN goods_order_original t2 ON t2.vendor_order_id = t1.vendor_order_id AND t2.vendor_id = t1.vendor_id
|
||||
WHERE t1.order_created_at >= ? AND t1.order_created_at < ?`
|
||||
sqlParams := []interface{}{
|
||||
curDate,
|
||||
curDate.Add(24 * time.Hour),
|
||||
}
|
||||
if len(vendorIDs) > 0 {
|
||||
sql += " AND t1.vendor_id IN (" + dao.GenQuestionMarks(len(vendorIDs)) + ")"
|
||||
sqlParams = append(sqlParams, vendorIDs)
|
||||
}
|
||||
if !isForce {
|
||||
sql += " AND t1.vendor_user_id = ''"
|
||||
}
|
||||
var orderList []*GoodsOrderWithOriginal
|
||||
if err = dao.GetRows(db, &orderList, sql, sqlParams...); err == nil {
|
||||
if len(orderList) > 0 {
|
||||
subTask := tasksch.NewParallelTask("RefreshMtpsWaybillFee", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
order := batchItemList[0].(*GoodsOrderWithOriginal)
|
||||
if isForce || order.VendorUserID == "" {
|
||||
if handler := partner.GetPurchasePlatformFromVendorID(order.VendorID); handler != nil {
|
||||
var order2 *model.GoodsOrder
|
||||
// globals.SugarLogger.Debugf("fuck:%s", order.OriginalData)
|
||||
if order.OriginalData != "" {
|
||||
var orderData map[string]interface{}
|
||||
if utils.UnmarshalUseNumber([]byte(order.OriginalData), &orderData) == nil {
|
||||
order2 = handler.Map2Order(orderData)
|
||||
if order2.VendorUserID == "" {
|
||||
order2 = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
if order2 == nil {
|
||||
order2, err = handler.GetOrder(order.VendorOrderID)
|
||||
}
|
||||
if order2 != nil {
|
||||
isNeedUpdateOrder := order.VendorUserID != order2.VendorUserID
|
||||
order.VendorUserID = order2.VendorUserID
|
||||
if isNeedUpdateOrder {
|
||||
dao.UpdateEntity(db, &order.GoodsOrder, "VendorUserID")
|
||||
}
|
||||
err = cms.HandleOrder4Consignee(&order.GoodsOrder)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
}, orderList)
|
||||
tasksch.HandleTask(subTask, task, true).Run()
|
||||
_, err = subTask.GetResult(0)
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
}, dateList)
|
||||
tasksch.HandleTask(rootTask, nil, true).Run()
|
||||
if !isAsync {
|
||||
_, err = rootTask.GetResult(0)
|
||||
} else {
|
||||
hint = rootTask.ID
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
@@ -316,3 +316,28 @@ func (c *TempOpController) CheckSkuDiffBetweenJxAndVendor() {
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 通过订单创建消费者用户
|
||||
// @Description 通过订单创建消费者用户
|
||||
// @Param token header string true "认证token"
|
||||
// @Param fromDate formData string true "开始日期"
|
||||
// @Param vendorIDs formData string false "运营商ID列表(京东0 美团1 饿百3)"
|
||||
// @Param toDate formData string false "结束日期(缺省不限制)"
|
||||
// @Param isForce formData bool false "是否强制"
|
||||
// @Param isAsync formData bool false "是否异步操作"
|
||||
// @Param isContinueWhenError formData bool false "单个同步失败是否继续,缺省false"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /CreateConsumerFromOrders [post]
|
||||
func (c *TempOpController) CreateConsumerFromOrders() {
|
||||
c.callCreateConsumerFromOrders(func(params *tTempopCreateConsumerFromOrdersParams) (retVal interface{}, errCode string, err error) {
|
||||
var vendorIDs []int
|
||||
timeList, err := jxutils.BatchStr2Time(params.FromDate, params.ToDate)
|
||||
if err == nil {
|
||||
if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDs); err == nil {
|
||||
retVal, err = tempop.CreateConsumerFromOrders(params.Ctx, vendorIDs, timeList[0], timeList[1], params.IsForce, params.IsAsync, params.IsContinueWhenError)
|
||||
}
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1647,6 +1647,15 @@ func init() {
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:TempOpController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:TempOpController"],
|
||||
beego.ControllerComments{
|
||||
Method: "CreateConsumerFromOrders",
|
||||
Router: `/CreateConsumerFromOrders`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:TempOpController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:TempOpController"],
|
||||
beego.ControllerComments{
|
||||
Method: "PrintMsg",
|
||||
|
||||
Reference in New Issue
Block a user