冲突修改

This commit is contained in:
苏尹岚
2019-12-02 11:14:20 +08:00
11 changed files with 111 additions and 37 deletions

View File

@@ -23,7 +23,9 @@ const (
DefActSkuStock = 200 // 缺省活动库存
maxDiscount4SkuSecKill = 80
maxDiscount4Sku = 98
minDiscount4SkuDirectDown = 0
minDiscount4SkuDirectDownMTWM = 30
)
type ActOrderRuleParam struct {
@@ -179,7 +181,7 @@ func ActStoreSkuParam2Model(ctx *jxcontext.Context, db *dao.DaoDB, act *model.Ac
if actSkuMap.ActualActPrice <= 0 {
actSkuMap.ActualActPrice = 1
}
if err2 = checkDiscountValidation(act.Type, float64(actSkuMap.ActualActPrice)*100/float64(actSkuMap.VendorPrice)); err2 != nil {
if err2 = checkDiscountValidation(vendorIDs, act.Type, float64(actSkuMap.ActualActPrice)*100/float64(actSkuMap.VendorPrice)); err2 != nil {
v.ErrMsg = err2.Error()
v.ActualActPrice = actSkuMap.ActualActPrice
v.VendorPrice = actSkuMap.VendorPrice
@@ -303,14 +305,16 @@ func AddActStoreSkuBind(ctx *jxcontext.Context, db *dao.DaoDB, actID int, actSto
return err
}
func checkDiscountValidation(actType int, pricePercentage float64) (err error) {
func checkDiscountValidation(vendorIDs []int, actType int, pricePercentage float64) (err error) {
pricePercentageMin := int(math.Floor(pricePercentage))
pricePercentageMax := int(math.Ceil(pricePercentage))
if actType == model.ActSkuDirectDown && (pricePercentageMin < minDiscount4SkuDirectDown || pricePercentageMax > 99) {
if pricePercentageMin < minDiscount4SkuDirectDown {
err = fmt.Errorf("%s活动折扣必须大于:%d", model.ActTypeName[actType], minDiscount4SkuDirectDown)
} else if pricePercentageMax > 99 {
err = fmt.Errorf("%s活动必须折扣", model.ActTypeName[actType])
} else if pricePercentageMax > maxDiscount4Sku {
err = fmt.Errorf("%s活动必须至少有%d折扣", model.ActTypeName[actType], maxDiscount4Sku)
} else if len(vendorIDs) > 0 && vendorIDs[0] == model.VendorIDMTWM && pricePercentageMin < minDiscount4SkuDirectDownMTWM {
err = fmt.Errorf("美团平台%s活动折扣必须大于:%d", model.ActTypeName[actType], minDiscount4SkuDirectDownMTWM)
}
} else if actType == model.ActSkuSecKill && pricePercentageMax > maxDiscount4SkuSecKill {
err = fmt.Errorf("%s活动折扣必须小于:%d", model.ActTypeName[actType], maxDiscount4SkuSecKill)
@@ -333,7 +337,7 @@ func checkActValidation(act *model.Act, vendorIDs []int) (err error) {
if act.Type == model.ActSkuDirectDown || act.Type == model.ActSkuSecKill {
if act.PricePercentage == 0 {
errList.AddErr(fmt.Errorf("必须指定缺省活动折扣"))
} else if err = checkDiscountValidation(act.Type, float64(act.PricePercentage)); err != nil {
} else if err = checkDiscountValidation(vendorIDs, act.Type, float64(act.PricePercentage)); err != nil {
errList.AddErr(err)
} else if act.Type == model.ActSkuSecKill && vendorIDMap[model.VendorIDMTWM] == 1 {
errList.AddErr(fmt.Errorf("%s平台不支持%s活动", model.VendorChineseNames[model.VendorIDMTWM], model.ActTypeName[model.ActSkuSecKill]))
@@ -668,7 +672,7 @@ func DeleteActStoreSkuBind(ctx *jxcontext.Context, db *dao.DaoDB, actID int, act
originSyncStatus |= act.SyncStatus
isDeleteAll := true
isDeleteAtLeastOne := false
if actStoreSkuParam != nil {
if true { //actStoreSkuParam != nil {
actStoreSkuMap := partner.SplitActStoreSku(actStoreSkuMap[vendorID])
for storeID := range actStoreSkuMap {
for _, actStoreSku := range actStoreSkuMap[storeID] {
@@ -954,7 +958,7 @@ func ForceUpdateVendorPrice(ctx *jxcontext.Context, vendorID int, actType int, s
if err = dao.GetEntity(db, storeSkuBind, model.FieldStoreID, model.FieldSkuID, model.FieldDeletedAt); err == nil {
vendorPrice := int(v.VendorPrice)
if vendorPrice != 0 {
if err2 := checkDiscountValidation(actType, float64(v.ActPrice)*100/float64(v.VendorPrice)); err2 != nil {
if err2 := checkDiscountValidation([]int{vendorID}, actType, float64(v.ActPrice)*100/float64(v.VendorPrice)); err2 != nil {
v.ErrMsg = err2.Error()
v.ActualActPrice = v.ActPrice
wrongSkuList = append(wrongSkuList, v)
@@ -962,7 +966,7 @@ func ForceUpdateVendorPrice(ctx *jxcontext.Context, vendorID int, actType int, s
}
} else {
vendorPrice = dao.GetStoreSkuBindVendorPrice(storeSkuBind, vendorID)
if checkDiscountValidation(actType, float64(v.ActPrice)*100/float64(vendorPrice)) != nil {
if checkDiscountValidation([]int{vendorID}, actType, float64(v.ActPrice)*100/float64(vendorPrice)) != nil {
if actType == model.ActSkuSecKill {
vendorPrice = int(v.ActPrice)*100/maxDiscount4SkuSecKill + 10
} else if actType == model.ActSkuDirectDown {

View File

@@ -178,7 +178,7 @@ const (
maxStoreNameBind = 3000 // 最大门店SkuName bind个数
maxStoreNameBind2 = 10000 // 最大门店乘SkuName个数
AutoSaleAtStr = "20:25:00"
AutoSaleAtStr = "22:00:00"
)
var (

View File

@@ -949,3 +949,31 @@ func UpdateOrdersWithoutJxStoreID(db *DaoDB, fromDate, toDate time.Time) (count
}
return ExecuteSQL(db, sql, sqlParams)
}
func GetMyOrderCountInfo(db *DaoDB, userID string, fromDate, toDate time.Time, statuss []int) (countInfo []*model.GoodsOrderCountInfo, err error) {
if utils.IsTimeZero(fromDate) {
return nil, fmt.Errorf("必须指定开始日期")
}
if utils.IsTimeZero(toDate) {
toDate = fromDate
}
sql := `
SELECT t1.lock_status, t1.status, COUNT(*) count
FROM goods_order t1
WHERE t1.user_id = ? AND t1.vendor_id = ?
AND t1.order_created_at >= ? AND t1.order_created_at <= ?
`
sqlParams := []interface{}{
userID,
model.VendorIDJX,
fromDate, toDate,
}
if len(statuss) > 0 {
sql += " AND t1.status IN (" + GenQuestionMarks(len(statuss)) + ")"
sqlParams = append(sqlParams, statuss)
}
sql += " GROUP BY 1,2"
err = GetRows(db, &countInfo, sql, sqlParams...)
return countInfo, err
}

View File

@@ -66,9 +66,11 @@ func ActStoreSku2ActStoreSkuMap(actStoreSku *model.ActStoreSku2) (actStoreSkuMap
return actStoreSkuMap
}
func Act2Update(act *model.Act2, syncStatus int) (item *dao.KVUpdateItem) {
func Act2Update(ctx *jxcontext.Context, act *model.Act2, syncStatus int) (item *dao.KVUpdateItem) {
kvs := map[string]interface{}{
model.FieldSyncStatus: 0,
model.FieldUpdatedAt: time.Now(),
model.FieldLastOperator: ctx.GetUserName(),
}
if syncStatus == model.SyncFlagDeletedMask {
kvs[model.FieldDeletedAt] = time.Now()
@@ -82,10 +84,12 @@ func Act2Update(act *model.Act2, syncStatus int) (item *dao.KVUpdateItem) {
return item
}
func ActStoreSku2Update(actStoreSkuList []*model.ActStoreSku2, syncStatus int) (items []*dao.KVUpdateItem) {
func ActStoreSku2Update(ctx *jxcontext.Context, actStoreSkuList []*model.ActStoreSku2, syncStatus int) (items []*dao.KVUpdateItem) {
for _, v := range actStoreSkuList {
kvs := map[string]interface{}{
model.FieldSyncStatus: 0,
model.FieldUpdatedAt: time.Now(),
model.FieldLastOperator: ctx.GetUserName(),
}
if syncStatus == model.SyncFlagDeletedMask {
kvs[model.FieldDeletedAt] = time.Now()

View File

@@ -299,34 +299,34 @@ func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITa
err = func() (err error) {
if model.IsSyncStatusDelete(act.SyncStatus) {
canceledList, err2 := cancelSkuAct(ctx, nil, vendorActInfoMap)
updateItems = append(updateItems, partner.ActStoreSku2Update(canceledList, model.SyncFlagModifiedMask)...)
updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, canceledList, model.SyncFlagModifiedMask)...)
if err = err2; err == nil {
updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagModifiedMask))
updateItems = append(updateItems, partner.Act2Update(ctx, act, model.SyncFlagModifiedMask))
}
} else if model.IsSyncStatusNew(act.SyncStatus) {
createdList, err2 := createSkuAct(ctx, nil, act, actStoreSkuList4Create)
updateItems = append(updateItems, partner.ActStoreSku2Update(createdList, model.SyncFlagNewMask)...)
updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, createdList, model.SyncFlagNewMask)...)
if err = err2; err == nil {
updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagNewMask))
updateItems = append(updateItems, partner.Act2Update(ctx, act, model.SyncFlagNewMask))
}
} else if model.IsSyncStatusUpdate(act.SyncStatus) {
// globals.SugarLogger.Debug(utils.Format4Output(updateItems, false))
if len(actStoreSkuList4Create) > 0 {
addedList, err2 := addSkuActSkus(ctx, nil, act, actStoreSkuList4Create, vendorActIDMap)
updateItems = append(updateItems, partner.ActStoreSku2Update(addedList, model.SyncFlagNewMask)...)
updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, addedList, model.SyncFlagNewMask)...)
if err = err2; err != nil {
return err
}
}
if len(deleteActInfoMap) > 0 {
deletedList, err2 := deleteSkuActSkus(ctx, nil, deleteActInfoMap, vendorActInfoMap)
updateItems = append(updateItems, partner.ActStoreSku2Update(deletedList, model.SyncFlagDeletedMask)...)
updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, deletedList, model.SyncFlagDeletedMask)...)
if err = err2; err != nil {
return err
}
}
if err == nil {
updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagModifiedMask))
updateItems = append(updateItems, partner.Act2Update(ctx, act, model.SyncFlagModifiedMask))
}
}
return err

View File

@@ -262,9 +262,9 @@ func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITa
}
}
for _, actStoreSkuList := range vendorActInfoMap {
updateItems = append(updateItems, partner.ActStoreSku2Update(actStoreSkuList, model.SyncFlagModifiedMask)...)
updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, actStoreSkuList, model.SyncFlagModifiedMask)...)
}
updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagModifiedMask))
updateItems = append(updateItems, partner.Act2Update(ctx, act, model.SyncFlagModifiedMask))
} else if model.IsSyncStatusNew(act.SyncStatus) {
if act.VendorActID, err = createSkuAct(ctx, act, actStoreSkuList4Create); err != nil {
if act.VendorActID != "" {
@@ -273,15 +273,15 @@ func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITa
}
return err
}
updateItems = append(updateItems, partner.ActStoreSku2Update(actStoreSkuList4Create, model.SyncFlagNewMask)...)
updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagNewMask))
updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, actStoreSkuList4Create, model.SyncFlagNewMask)...)
updateItems = append(updateItems, partner.Act2Update(ctx, act, model.SyncFlagNewMask))
} else if model.IsSyncStatusUpdate(act.SyncStatus) {
// globals.SugarLogger.Debug(utils.Format4Output(updateItems, false))
if len(actStoreSkuList4Create) > 0 {
if _, err = createSkuAct(ctx, act, actStoreSkuList4Create); err != nil {
return err
}
updateItems = append(updateItems, partner.ActStoreSku2Update(actStoreSkuList4Create, model.SyncFlagNewMask)...)
updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, actStoreSkuList4Create, model.SyncFlagNewMask)...)
}
for vendorActID := range deleteActInfoMap {
if vendorActID != "" {
@@ -295,10 +295,10 @@ func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITa
return err
}
}
updateItems = append(updateItems, partner.ActStoreSku2Update(deleteActInfoMap[vendorActID], model.SyncFlagDeletedMask)...)
updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, deleteActInfoMap[vendorActID], model.SyncFlagDeletedMask)...)
}
if err == nil {
updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagModifiedMask))
updateItems = append(updateItems, partner.Act2Update(ctx, act, model.SyncFlagModifiedMask))
}
}
return err

View File

@@ -102,6 +102,7 @@ func init() {
func GetMyOrders(ctx *jxcontext.Context, fromDateStr, toDateStr string, params map[string]interface{}, offset, pageSize int) (pagedInfo *model.PagedInfo, err error) {
db := dao.GetDB()
params["vendorIDs"] = string(utils.MustMarshal([]int{model.VendorIDJX}))
tmpOrderList, totalCount, err := dao.GetOrders(db, nil, false, false, fromDateStr, toDateStr, false, nil, false, ctx.GetUserID(), params, offset, pageSize)
if err == nil {
pagedInfo = &model.PagedInfo{
@@ -133,6 +134,11 @@ func GetMyOrders(ctx *jxcontext.Context, fromDateStr, toDateStr string, params m
return pagedInfo, err
}
func GetMyOrderCountInfo(ctx *jxcontext.Context, fromDate, toDate time.Time, statuss []int) (countInfo []*model.GoodsOrderCountInfo, err error) {
countInfo, err = dao.GetMyOrderCountInfo(dao.GetDB(), ctx.GetUserID(), fromDate, toDate, statuss)
return countInfo, err
}
func CreateOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, addressID int64, createType int) (outJxOrder *JxOrderInfo, err error) {
outJxOrder, deliveryAddress, err := generateOrder(ctx, jxOrder, addressID)
if err != nil {

View File

@@ -163,34 +163,34 @@ func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITa
err = func() (err error) {
if model.IsSyncStatusDelete(act.SyncStatus) {
canceledList, err2 := cancelSkuAct(ctx, nil, actStoreSkuList)
updateItems = append(updateItems, partner.ActStoreSku2Update(canceledList, model.SyncFlagModifiedMask)...)
updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, canceledList, model.SyncFlagModifiedMask)...)
if err = err2; err == nil {
updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagModifiedMask))
updateItems = append(updateItems, partner.Act2Update(ctx, act, model.SyncFlagModifiedMask))
}
} else if model.IsSyncStatusNew(act.SyncStatus) {
createdList, err2 := createSkuAct(ctx, nil, act, actStoreSkuList4Create)
updateItems = append(updateItems, partner.ActStoreSku2Update(createdList, model.SyncFlagNewMask)...)
updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, createdList, model.SyncFlagNewMask)...)
if err = err2; err == nil {
updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagNewMask))
updateItems = append(updateItems, partner.Act2Update(ctx, act, model.SyncFlagNewMask))
}
} else if model.IsSyncStatusUpdate(act.SyncStatus) {
// globals.SugarLogger.Debug(utils.Format4Output(updateItems, false))
if len(actStoreSkuList4Create) > 0 {
addedList, err2 := createSkuAct(ctx, nil, act, actStoreSkuList4Create)
updateItems = append(updateItems, partner.ActStoreSku2Update(addedList, model.SyncFlagNewMask)...)
updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, addedList, model.SyncFlagNewMask)...)
if err = err2; err != nil {
return err
}
}
if len(actStoreSkuList4Delete) > 0 {
deletedList, err2 := cancelSkuAct(ctx, nil, actStoreSkuList4Delete)
updateItems = append(updateItems, partner.ActStoreSku2Update(deletedList, model.SyncFlagDeletedMask)...)
updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, deletedList, model.SyncFlagDeletedMask)...)
if err = err2; err != nil {
return err
}
}
if err == nil {
updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagModifiedMask))
updateItems = append(updateItems, partner.Act2Update(ctx, act, model.SyncFlagModifiedMask))
}
}
return err

View File

@@ -142,7 +142,7 @@ func (c *PurchaseHandler) onAfsOrderMsg(msg *mtwmapi.CallbackMsg) (retVal *mtwma
}
func (p *PurchaseHandler) createAfsOrder(orderData url.Values) (afsOrder *model.AfsOrder) {
afsOrder, err := partner.CurOrderManager.CreateAfsOrderFromOrder(orderData.Get("refund_id"), model.VendorIDMTWM)
afsOrder, err := partner.CurOrderManager.CreateAfsOrderFromOrder(orderData.Get("order_id"), model.VendorIDMTWM)
if err == nil {
afsOrder.AfsOrderID = orderData.Get("refund_id")
afsOrder.AfsCreatedAt = utils.Timestamp2Time(utils.Str2Int64(orderData.Get("timestamp")))

View File

@@ -2,6 +2,7 @@ package controllers
import (
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/business/partner/purchase/jx/localjx"
"github.com/astaxie/beego"
)
@@ -92,3 +93,25 @@ func (c *JxOrderController) GetMyOrders() {
return retVal, "", err
})
}
// @Title 查询自己的订单状态数量信息
// @Description 查询自己的订单状态数量信息
// @Param token header string true "认证token"
// @Param fromDate query string false "开始日期包含格式2006-01-02如果订单号为空此项必须要求"
// @Param toDate query string false "结束日期包含格式2006-01-02如果订单号为空此项必须要求"
// @Param statuss query string false "订单状态列表[1,2,3],缺省不限制"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetMyOrderCountInfo [get]
func (c *JxOrderController) GetMyOrderCountInfo() {
c.callGetMyOrderCountInfo(func(params *tJxorderGetMyOrderCountInfoParams) (retVal interface{}, errCode string, err error) {
timeList, err := jxutils.BatchStr2Time(params.FromDate, params.ToDate)
if err == nil {
var statuss []int
if err = jxutils.Strings2Objs(params.Statuss, &statuss); err == nil {
retVal, err = localjx.GetMyOrderCountInfo(params.Ctx, timeList[0], timeList[1], statuss)
}
}
return retVal, "", err
})
}

View File

@@ -610,6 +610,15 @@ func init() {
Filters: nil,
Params: nil})
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JxOrderController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JxOrderController"],
beego.ControllerComments{
Method: "GetMyOrderCountInfo",
Router: `/GetMyOrderCountInfo`,
AllowHTTPMethods: []string{"get"},
MethodParams: param.Make(),
Filters: nil,
Params: nil})
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JxOrderController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JxOrderController"],
beego.ControllerComments{
Method: "GetMyOrders",