根据skuid批量关注
This commit is contained in:
@@ -72,6 +72,12 @@ type StoreSkuBindInfo struct {
|
||||
Skus []*StoreSkuBindSkuInfo `json:"skus,omitempty"`
|
||||
}
|
||||
|
||||
type tStoreSkuBindInfo struct {
|
||||
NameID int `json:"nameID"`
|
||||
UnitPrice int `json:"unitPrice"` // 对于是份的SKU就是单价(每斤价格),其它则为总价
|
||||
IsFocused bool `json:"isFocused"` //是否关注过
|
||||
}
|
||||
|
||||
type tStoreSkuBindAndSpec struct {
|
||||
model.StoreSkuBind
|
||||
SkuStatus int
|
||||
@@ -154,6 +160,11 @@ type DataLock struct {
|
||||
locker sync.RWMutex
|
||||
}
|
||||
|
||||
type tUpdateStoresSkus struct {
|
||||
StoreID int
|
||||
SkuBindInfos []*StoreSkuBindInfo
|
||||
}
|
||||
|
||||
const (
|
||||
maxStoreNameBind = 10000 // 最大门店SkuName bind个数
|
||||
maxStoreNameBind2 = 10000 // 最大门店乘SkuName个数
|
||||
@@ -2753,22 +2764,20 @@ func FocusStoreSkusByExcel(ctx *jxcontext.Context, files []*multipart.FileHeader
|
||||
|
||||
func FocusStoreSkusByExcelBin(ctx *jxcontext.Context, reader io.Reader, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
var (
|
||||
skuMap = make(map[int]int)
|
||||
skuNameMap = make(map[int]int)
|
||||
skuBindInfos []*StoreSkuBindInfo
|
||||
db = dao.GetDB()
|
||||
storeIDs []int
|
||||
skuIDs []int
|
||||
skuMap = make(map[int]int)
|
||||
db = dao.GetDB()
|
||||
skuIDs []int
|
||||
result1 []interface{}
|
||||
)
|
||||
sheetParam := &SheetParam{
|
||||
OutSkuIDCol: 1,
|
||||
SkuPriceCol: 3,
|
||||
SkuRow: 1,
|
||||
}
|
||||
// xlsx, err := excelize.OpenFile("111.xlsx")
|
||||
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
switch step {
|
||||
case 0:
|
||||
// xlsx, err := excelize.OpenFile("111.xlsx")
|
||||
xlsx, err := excelize.OpenReader(reader)
|
||||
if err != nil {
|
||||
return result, err
|
||||
@@ -2785,43 +2794,72 @@ func FocusStoreSkusByExcelBin(ctx *jxcontext.Context, reader io.Reader, isAsync,
|
||||
skuIDs = append(skuIDs, k)
|
||||
}
|
||||
skuList, err := dao.GetSkus(db, skuIDs, nil, nil, nil)
|
||||
storeList, err := dao.GetStoreList(db, nil, nil, "")
|
||||
if err != nil && len(skuList) == 0 {
|
||||
return result, err
|
||||
}
|
||||
for _, v := range skuList {
|
||||
taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
store := batchItemList[0].(*model.Store)
|
||||
var (
|
||||
price int
|
||||
specQuality float64
|
||||
skuBindInfos []*StoreSkuBindInfo
|
||||
skuNameMap = make(map[int]int)
|
||||
skuInfoMap = make(map[int][]*StoreSkuBindSkuInfo)
|
||||
)
|
||||
if v.Unit == model.SpecialUnit {
|
||||
if v.SpecUnit == model.SpecUnitNames[1] || v.SpecUnit == model.SpecUnitNames[2] {
|
||||
specQuality = float64(v.SpecQuality) * 1000
|
||||
for _, v := range skuList {
|
||||
var (
|
||||
price int
|
||||
specQuality float64
|
||||
)
|
||||
focusList, _ := dao.GetStoreSkuBindByNameID(db, store.ID, v.NameID, model.StoreSkuBindStatusNormal)
|
||||
//有关注过
|
||||
if len(focusList) > 0 {
|
||||
price = 0
|
||||
skuInfoMap[v.NameID] = append(skuInfoMap[v.NameID], &StoreSkuBindSkuInfo{
|
||||
SkuID: v.ID,
|
||||
IsSale: 1,
|
||||
})
|
||||
skuNameMap[v.NameID] = price
|
||||
} else {
|
||||
specQuality = float64(v.SpecQuality)
|
||||
if v.Unit == model.SpecialUnit {
|
||||
if v.SpecUnit == model.SpecUnitNames[1] || v.SpecUnit == model.SpecUnitNames[2] {
|
||||
specQuality = float64(v.SpecQuality) * 1000
|
||||
} else {
|
||||
specQuality = float64(v.SpecQuality)
|
||||
}
|
||||
price = int(utils.Float64TwoInt64(utils.Int2Float64(model.SpecialSpecQuality) / specQuality * utils.Int2Float64(skuMap[v.ID])))
|
||||
} else {
|
||||
price = skuMap[v.ID]
|
||||
}
|
||||
if skuNameMap[v.NameID] < price {
|
||||
skuNameMap[v.NameID] = price
|
||||
}
|
||||
}
|
||||
price = int(utils.Float64TwoInt64(utils.Int2Float64(model.SpecialSpecQuality) / specQuality * utils.Int2Float64(skuMap[v.ID])))
|
||||
} else {
|
||||
price = skuMap[v.ID]
|
||||
}
|
||||
if skuNameMap[v.NameID] < price {
|
||||
skuNameMap[v.NameID] = price
|
||||
for k, v := range skuNameMap {
|
||||
skuBindInfo := &StoreSkuBindInfo{
|
||||
NameID: k,
|
||||
UnitPrice: v,
|
||||
IsFocus: 1,
|
||||
IsSale: 1,
|
||||
Skus: skuInfoMap[k],
|
||||
}
|
||||
skuBindInfos = append(skuBindInfos, skuBindInfo)
|
||||
}
|
||||
}
|
||||
for k, v := range skuNameMap {
|
||||
skuBindInfo := &StoreSkuBindInfo{
|
||||
NameID: k,
|
||||
UnitPrice: v,
|
||||
IsFocus: 1,
|
||||
IsSale: 1,
|
||||
tUpdate := &tUpdateStoresSkus{
|
||||
StoreID: store.ID,
|
||||
SkuBindInfos: skuBindInfos,
|
||||
}
|
||||
skuBindInfos = append(skuBindInfos, skuBindInfo)
|
||||
}
|
||||
storeList, err := dao.GetStoreList(db, nil, nil, "")
|
||||
for _, v := range storeList {
|
||||
storeIDs = append(storeIDs, v.ID)
|
||||
retVal = []*tUpdateStoresSkus{tUpdate}
|
||||
return retVal, err
|
||||
}
|
||||
taskParallel := tasksch.NewParallelTask("根据skuID关注商品", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx, taskFunc, storeList)
|
||||
tasksch.HandleTask(taskParallel, task, true).Run()
|
||||
result1, _ = taskParallel.GetResult(0)
|
||||
case 2:
|
||||
UpdateStoresSkus(ctx, storeIDs, skuBindInfos, false, isAsync, isContinueWhenError)
|
||||
for _, v := range result1 {
|
||||
tUpdate := v.(*tUpdateStoresSkus)
|
||||
UpdateStoresSkus(ctx, []int{tUpdate.StoreID}, tUpdate.SkuBindInfos, false, isAsync, isContinueWhenError)
|
||||
}
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
@@ -2854,9 +2892,9 @@ func GetCellForFocusStoreSkus(db *dao.DaoDB, rowNum int, row []string, sheetPara
|
||||
|
||||
func FocusStoreSkusBySku(ctx *jxcontext.Context, skuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
var (
|
||||
skuBindInfos []*StoreSkuBindInfo
|
||||
skuNameMap = make(map[int][]*StoreSkuBindSkuInfo)
|
||||
storeIDs []int
|
||||
skuNameMap = make(map[int][]*StoreSkuBindSkuInfo)
|
||||
storeIDs []int
|
||||
result1 []interface{}
|
||||
)
|
||||
db := dao.GetDB()
|
||||
skuList, err := dao.GetSkus(db, skuIDs, nil, nil, nil)
|
||||
@@ -2876,26 +2914,40 @@ func FocusStoreSkusBySku(ctx *jxcontext.Context, skuIDs []int, isAsync, isContin
|
||||
case 1:
|
||||
taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
store := batchItemList[0].(*model.Store)
|
||||
var skuBindInfos []*StoreSkuBindInfo
|
||||
for k, v := range skuNameMap {
|
||||
midPrice, _ := dao.GetMidPriceByNameID(db, store.CityCode, k, utils.Time2Date(time.Now().AddDate(0, 0, -1)))
|
||||
var price int
|
||||
focusList, _ := dao.GetStoreSkuBindByNameID(db, store.ID, k, model.StoreSkuBindStatusNormal)
|
||||
//有关注过
|
||||
if len(focusList) > 0 {
|
||||
price = 0
|
||||
} else {
|
||||
midPrice, _ := dao.GetMidPriceByNameID(db, store.CityCode, k, utils.Time2Date(time.Now().AddDate(0, 0, -1)))
|
||||
price = midPrice
|
||||
}
|
||||
skuBindInfo := &StoreSkuBindInfo{
|
||||
NameID: k,
|
||||
UnitPrice: midPrice,
|
||||
UnitPrice: price,
|
||||
IsFocus: 1,
|
||||
Skus: v,
|
||||
}
|
||||
retVal = []*StoreSkuBindInfo{skuBindInfo}
|
||||
skuBindInfos = append(skuBindInfos, skuBindInfo)
|
||||
}
|
||||
tUpdate := &tUpdateStoresSkus{
|
||||
StoreID: store.ID,
|
||||
SkuBindInfos: skuBindInfos,
|
||||
}
|
||||
retVal = []*tUpdateStoresSkus{tUpdate}
|
||||
return retVal, err
|
||||
}
|
||||
taskParallel := tasksch.NewParallelTask("根据skuID部分关注商品", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx, taskFunc, storeList)
|
||||
tasksch.HandleTask(taskParallel, task, true).Run()
|
||||
result1, _ := taskParallel.GetResult(0)
|
||||
for _, v := range result1 {
|
||||
skuBindInfos = append(skuBindInfos, v.(*StoreSkuBindInfo))
|
||||
}
|
||||
result1, _ = taskParallel.GetResult(0)
|
||||
case 2:
|
||||
UpdateStoresSkus(ctx, storeIDs, skuBindInfos, false, isAsync, isContinueWhenError)
|
||||
for _, v := range result1 {
|
||||
tUpdate := v.(*tUpdateStoresSkus)
|
||||
UpdateStoresSkus(ctx, []int{tUpdate.StoreID}, tUpdate.SkuBindInfos, false, isAsync, isContinueWhenError)
|
||||
}
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
@@ -1345,6 +1345,28 @@ func GetDeletedStoreSkuBind(db *DaoDB, storeID, skuID int) (storeSkuBind *model.
|
||||
return storeSkuBind
|
||||
}
|
||||
|
||||
func GetStoreSkuBindByNameID(db *DaoDB, storeID, nameID, status int) (storeSkuBind []*model.StoreSkuBind, err error) {
|
||||
sql := `
|
||||
SELECT c.*
|
||||
FROM sku a
|
||||
JOIN store_sku_bind c ON c.sku_id = a.id
|
||||
WHERE c.store_id = ?
|
||||
AND a.name_id = ?
|
||||
AND c.deleted_at = ?
|
||||
AND a.deleted_at = ?
|
||||
AND c.status = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
storeID,
|
||||
nameID,
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
status,
|
||||
}
|
||||
err = GetRows(db, &storeSkuBind, sql, sqlParams...)
|
||||
return storeSkuBind, err
|
||||
}
|
||||
|
||||
func GetMidPriceByNameID(db *DaoDB, cityCode, skuNameID int, snapDate time.Time) (midPrice int, err error) {
|
||||
var (
|
||||
sku []*model.SkuAndName
|
||||
|
||||
@@ -359,7 +359,7 @@ type OrderSupplementFee struct {
|
||||
|
||||
func (v *OrderSupplementFee) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"StoreID", "VendorOrderID", "SupplementTime", "VendorID", "BillID"},
|
||||
[]string{"StoreID", "VendorOrderID", "SupplementTime"},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user