From d40a281b2e70afbc987def59475ac3e0c1d17f04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 8 Sep 2020 15:24:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B4=BB=E5=8A=A8=E5=88=A0=E9=99=A4=E7=9B=B4?= =?UTF-8?q?=E9=99=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxcallback/orderman/order.go | 6 +- business/jxstore/act/act.go | 2 + business/jxstore/cms/store_sku.go | 176 ++++++++++++++++++++++++++ 3 files changed, 181 insertions(+), 3 deletions(-) diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index 598adf926..47f3a9dcb 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -1317,15 +1317,15 @@ func setJdsOrderSeq(order *model.GoodsOrder) (err error) { type tCount struct { Count int `json:"count"` } - var count = &tCount{} + var counts []*tCount sql := ` SELECT count(*) count FROM goods_order WHERE store_id = ? AND order_create_at >= ? AND order_create_at <= ? AND vendor_id = ? ` sqlParams := []interface{}{ order.StoreID, utils.Time2Date(time.Now()), utils.Time2Date(time.Now().AddDate(0, 0, 1)), order.VendorID, } - err = dao.GetRow(dao.GetDB(), &count, sql, sqlParams) - order.OrderSeq = count.Count + 1 + err = dao.GetRows(dao.GetDB(), &counts, sql, sqlParams) + order.OrderSeq = counts[0].Count + 1 return err } diff --git a/business/jxstore/act/act.go b/business/jxstore/act/act.go index fcc8e98d6..f28c60e9f 100644 --- a/business/jxstore/act/act.go +++ b/business/jxstore/act/act.go @@ -1682,3 +1682,5 @@ func checkPriceDefendOrderByPrice(db *dao.DaoDB, storeID, skuID, stock, jxPrice } return stock } + + diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index 7ba20c673..0d6ed6567 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -206,6 +206,14 @@ type MatterStock struct { Stock int `json:"stock"` } +type ActStoreSkuParam struct { + model.ActStoreSku + + ActualActPrice int64 `json:"actualActPrice,omitempty"` // 单品级活动用,创建活动时商品的活动价格 + VendorPrice int64 `json:"vendorPrice,omitempty"` // 创建活动时的平台价格 + ErrMsg string `json:"errMsg,omitempty"` +} + const ( maxStoreNameBind = 10000 // 最大门店SkuName bind个数 maxStoreNameBind2 = 10000 // 最大门店乘SkuName个数 @@ -1285,6 +1293,9 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs skuBind.JxPrice = jxPrice updateFieldMap["UnitPrice"] = 1 updateFieldMap["JxPrice"] = 1 + + //TODO 2020-09-08 如果改价时商品在做直降,要取消这个商品的直降,再通过改价比例修改活动价,再上这个直降 + // checkActDirectDown(ctx, skuBind, beforeMsg) } } if skuBindInfo.StatusSaleBegin != 0 && skuBindInfo.StatusSaleEnd != 0 { @@ -1350,6 +1361,47 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs return skuIDs, err } +// func checkActDirectDown(ctx *jxcontext.Context, skuBind *model.StoreSkuBind, beforeSkuBind tStoreSkuBindAndSpec) (err error) { +// var ( +// originPrice = beforeSkuBind.Price +// price = skuBind.Price +// db = dao.GetDB() +// pageSize = 9999 +// // percent = price / originPrice +// ) +// if paged, _ := dao.QueryActs(db, 0, 0, pageSize, -1, "", -1, []int{model.ActStatusCreated}, []int{model.ActSkuDirectDown}, nil, skuBind.StoreID, []int{skuBind.SkuID}, 0, utils.ZeroTimeValue, utils.ZeroTimeValue, time.Now().AddDate(0, -2, 0), time.Now()); len(paged.Data) > 0 { +// for _, act := range paged.Data { +// if _, actStoreSkus, err := dao.GetActStoreSkuVendorList(db, act.ID, nil, []int{skuBind.StoreID}, []int{skuBind.SkuID}, "", 0, pageSize); err == nil && len(actStoreSkus) > 0 { +// var ( +// handler = partner.GetPurchasePlatformFromVendorID(actStoreSkus[0].VendorID).(partner.IPurchasePlatformActHandler) +// actStoreSkuParam []*ActStoreSkuParam +// ) +// for _, actStoreSku := range actStoreSkus { +// aa := &ActStoreSkuParam{ +// ActStoreSku: model.ActStoreSku{ +// StoreID: skuBind.StoreID, +// SkuID: actStoreSku.SkuID, +// ActID: act.ID, +// }, +// } +// actStoreSkuParam = append(actStoreSkuParam, aa) +// } +// DeleteActStoreSkuBind(ctx, db, act.ID, actStoreSkuParam) +// actMap, err := dao.GetActVendorInfo(db, act.ID, []int{actStoreSkus[0].VendorID}) +// if err != nil { +// return err +// } +// actStoreSkuMap, err := dao.GetActStoreSkuVendorInfo(db, act.ID, nil, nil, nil) +// if err != nil { +// return err +// } +// handler.SyncAct(ctx, nil, actMap[actStoreSkus[0].VendorID], nil, actStoreSkuMap[actStoreSkus[0].VendorID]) +// } +// } +// } +// return err +// } + func getSkuSaleStatus(inSkuBind *StoreSkuBindSkuInfo, skuNameBindInfo *StoreSkuBindInfo) int { tempSale := 0 if inSkuBind != nil { @@ -4940,3 +4992,127 @@ func GetSpecialtyStoreSkus(ctx *jxcontext.Context, storeIDs, vendorIDs []int) (e } return err } + +func checkActUpdate(actID int, actMap map[int]*model.Act2) (err error) { + if len(actMap) == 0 { + return fmt.Errorf("活动%d不存在或已被取消", actID) + } + errList := errlist.New() + for vendorID, act := range actMap { + if vendorID == model.VendorIDEBAI && act.CreateType != model.ActCreateTypeAPI { + errList.AddErr(fmt.Errorf("饿百平台不支持修改或取消网页活动")) + } + } + return errList.GetErrListAsOne() +} + +func DeleteActStoreSkuBind(ctx *jxcontext.Context, db *dao.DaoDB, actID int, actStoreSkuParam []*ActStoreSkuParam) (originSyncStatus int8, err error) { + actMap, err := dao.GetActVendorInfo(db, actID, nil) + if err != nil { + return 0, err + } + if err = checkActUpdate(actID, actMap); err != nil { + return 0, err + } + + actStoreSkuMap, err := dao.GetActStoreSkuVendorInfo(db, actID, nil, nil, nil) + if err != nil { + return 0, err + } + act := actMap[partner.GetVendorIDsFromActMap(actMap)[0]] + if act.Status != model.ActStatusCreated || time.Now().Sub(act.EndAt) > 0 { + return 0, fmt.Errorf("当前活动状态:%s,不能进行此操作,或已过期", model.ActStatusName[act.Status]) + } + + dao.Begin(db) + defer func() { + if r := recover(); r != nil || err != nil { + dao.Rollback(db) + if r != nil { + panic(r) + } + } + }() + actStoreSkuParamMap := make(map[int64]*ActStoreSkuParam) + for _, v := range actStoreSkuParam { + actStoreSkuParamMap[jxutils.Combine2Int(v.StoreID, v.SkuID)] = v + if _, err = dao.DeleteEntityLogically(db, &model.ActStoreSku{}, nil, ctx.GetUserName(), + map[string]interface{}{ + model.FieldActID: actID, + model.FieldStoreID: v.StoreID, + model.FieldSkuID: v.SkuID, + }); err != nil { + return 0, err + } + } + + isNeedCancelAct := true + for vendorID, act := range actMap { + originSyncStatus |= act.SyncStatus + isDeleteAll := true + isDeleteAtLeastOne := false + if true { //actStoreSkuParam != nil { + actStoreSkuMap := partner.SplitActStoreSku(actStoreSkuMap[vendorID]) + for storeID := range actStoreSkuMap { + for _, actStoreSku := range actStoreSkuMap[storeID] { + if actStoreSkuParam == nil || actStoreSkuParamMap[jxutils.Combine2Int(actStoreSku.StoreID, actStoreSku.SkuID)] != nil { + if act.Type == model.ActSkuFake { + _, err = dao.DeleteEntityLogically(db, &model.ActStoreSkuMap{}, nil, ctx.GetUserName(), + map[string]interface{}{ + model.FieldActID: actID, + model.FieldStoreID: actStoreSku.StoreID, + model.FieldSkuID: actStoreSku.SkuID, + }) + } else { + _, err = dao.UpdateEntityLogically(db, partner.ActStoreSku2ActStoreSkuMap(actStoreSku), + map[string]interface{}{ + model.FieldSyncStatus: actStoreSku.SyncStatus | model.SyncFlagDeletedMask, + }, ctx.GetUserName(), nil) + } + if err != nil { + return 0, err + } + isDeleteAtLeastOne = true + } else { + isNeedCancelAct = false + isDeleteAll = false + } + } + } + } else { + isDeleteAll = true + isDeleteAtLeastOne = true + } + if isDeleteAll || isDeleteAtLeastOne { + syncStatus := int8(model.SyncFlagModifiedMask) + if isDeleteAll { + syncStatus = model.SyncFlagDeletedMask + } + syncStatus |= act.SyncStatus + if act.Type != model.ActSkuFake && vendorID != model.VendorIDJX { + if _, err = dao.UpdateEntityLogically(db, partner.Act2ActMap(act), + map[string]interface{}{ + model.FieldSyncStatus: syncStatus, + }, ctx.GetUserName(), nil); err != nil { + return 0, err + } + } + } + if isDeleteAll != isNeedCancelAct { + globals.SugarLogger.Warnf("deleteActStoreBind, actID:%d isDeleteAll:%t != isNeedCancelAct:%t", act.ID, isDeleteAll, isNeedCancelAct) + } + } + + if isNeedCancelAct { + act := &model.Act{} + act.ID = actID + if _, err = dao.UpdateEntityLogically(db, act, + map[string]interface{}{ + model.FieldStatus: model.ActStatusCanceled, + }, ctx.GetUserName(), nil); err != nil { + return 0, err + } + } + dao.Commit(db) + return originSyncStatus, err +}