This commit is contained in:
苏尹岚
2021-03-10 17:42:43 +08:00
parent a76e30bc35
commit acacc3b2de

View File

@@ -414,7 +414,13 @@ func GetStoreManageState(ctx *jxcontext.Context, storeIDs []int, vendorID int, f
dayCount = int(fromTimeT.Sub(toTimeT).Hours())/24 + 1 //查的几天 dayCount = int(fromTimeT.Sub(toTimeT).Hours())/24 + 1 //查的几天
getStoreManageStateResult []*GetStoreManageStateResult getStoreManageStateResult []*GetStoreManageStateResult
storeIDsPage []int storeIDsPage []int
storeMapMaps map[int]*model.StoreMap
) )
storeMapMaps = make(map[int]*model.StoreMap)
storeMaps, err := dao.GetStoresMapList(db, []int{vendorID}, nil, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", "", "")
for _, v := range storeMaps {
storeMapMaps[v.StoreID] = v
}
//权限 //权限
if permission.IsRoled(ctx) { if permission.IsRoled(ctx) {
if storeIDsMap, err := permission.GetUserStoresResultMap(ctx.GetUserID()); err == nil { if storeIDsMap, err := permission.GetUserStoresResultMap(ctx.GetUserID()); err == nil {
@@ -427,13 +433,11 @@ func GetStoreManageState(ctx *jxcontext.Context, storeIDs []int, vendorID int, f
} }
} else { } else {
for k, _ := range storeIDsMap { for k, _ := range storeIDsMap {
storeDetail, _ := dao.GetStoreDetail(db, k, vendorID, "") if storeMapMaps[k] != nil {
if storeDetail == nil || storeDetail.VendorStoreID == "" || storeDetail.VendorOrgCode == "" {
continue
}
storeIDs2 = append(storeIDs2, k) storeIDs2 = append(storeIDs2, k)
} }
} }
}
storeIDs = nil storeIDs = nil
storeIDs = storeIDs2 storeIDs = storeIDs2
} }
@@ -443,12 +447,13 @@ func GetStoreManageState(ctx *jxcontext.Context, storeIDs []int, vendorID int, f
index2 = len(storeIDs) - 1 index2 = len(storeIDs) - 1
} }
storeIDsPage = storeIDs[offset*pageSize : index2] storeIDsPage = storeIDs[offset*pageSize : index2]
task := tasksch.NewParallelTask("GetStoreManageState", tasksch.NewParallelConfig().SetParallelCount(20).SetIsContinueWhenError(true), ctx, for _, v := range storeIDsPage {
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { // task := tasksch.NewParallelTask("GetStoreManageState", tasksch.NewParallelConfig().SetParallelCount(20).SetIsContinueWhenError(true), ctx,
v := batchItemList[0].(int) // func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
// v := batchItemList[0].(int)
storeDetail, _ := dao.GetStoreDetail(db, v, vendorID, "") storeDetail, _ := dao.GetStoreDetail(db, v, vendorID, "")
if storeDetail == nil || storeDetail.VendorStoreID == "" || storeDetail.VendorOrgCode == "" { if storeDetail == nil || storeDetail.VendorStoreID == "" || storeDetail.VendorOrgCode == "" {
return retVal, err continue
} }
result := &GetStoreManageStateResult{ result := &GetStoreManageStateResult{
StoreID: v, StoreID: v,
@@ -460,14 +465,14 @@ func GetStoreManageState(ctx *jxcontext.Context, storeIDs []int, vendorID int, f
if result.CoverArea == 0 { if result.CoverArea == 0 {
handler := partner.GetPurchasePlatformFromVendorID(vendorID) handler := partner.GetPurchasePlatformFromVendorID(vendorID)
if store, err := handler.ReadStore(ctx, storeDetail.VendorOrgCode, storeDetail.VendorStoreID); err == nil { if store, err := handler.ReadStore(ctx, storeDetail.VendorOrgCode, storeDetail.VendorStoreID); err == nil {
if storeMaps, err := dao.GetStoresMapList(db, []int{vendorID}, []int{v}, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", "", ""); len(storeMaps) > 0 && err == nil { if storeMapMaps[v] != nil {
if vendorID == model.VendorIDJD && store.DeliveryRangeType != model.DeliveryRangeTypePolygon { if vendorID == model.VendorIDJD && store.DeliveryRangeType != model.DeliveryRangeTypePolygon {
storeMaps[0].CoverArea = math.Pi * utils.Str2Float64WithDefault(store.DeliveryRange, 0) * utils.Str2Float64WithDefault(store.DeliveryRange, 0) / float64(10000) storeMapMaps[v].CoverArea = math.Pi * utils.Str2Float64WithDefault(store.DeliveryRange, 0) * utils.Str2Float64WithDefault(store.DeliveryRange, 0) / float64(10000)
} else { } else {
storeMaps[0].CoverArea = CalculateCoverArea(strings.Split(store.DeliveryRange, ";"), vendorID) storeMapMaps[v].CoverArea = CalculateCoverArea(strings.Split(store.DeliveryRange, ";"), vendorID)
} }
dao.UpdateEntity(db, storeMaps[0], "CoverArea") dao.UpdateEntity(db, storeMapMaps[v], "CoverArea")
result.CoverArea = storeMaps[0].CoverArea result.CoverArea = storeMapMaps[v].CoverArea
} }
} }
} }
@@ -492,7 +497,7 @@ func GetStoreManageState(ctx *jxcontext.Context, storeIDs []int, vendorID int, f
result.ActAmple = ample result.ActAmple = ample
//订单 //订单
refuseOrderCount := 0 refuseOrderCount := 0
orderList, err := dao.QueryOrdersForManageState(db, v, vendorID, model.OrderStatusCanceled, fromTimeT, toTimeT) orderList, _ := dao.QueryOrdersForManageState(db, v, vendorID, model.OrderStatusCanceled, fromTimeT, toTimeT)
for _, v := range orderList { for _, v := range orderList {
if v.BindID == 0 { if v.BindID == 0 {
refuseOrderCount++ refuseOrderCount++
@@ -506,14 +511,15 @@ func GetStoreManageState(ctx *jxcontext.Context, storeIDs []int, vendorID int, f
result.StoreScore = scoreResult.AvgPoiScore result.StoreScore = scoreResult.AvgPoiScore
} }
} }
retVal = []*GetStoreManageStateResult{result} // retVal = []*GetStoreManageStateResult{result}
// getStoreManageStateResult = append(getStoreManageStateResult, result) // getStoreManageStateResult = append(getStoreManageStateResult, result)
return retVal, err // return retVal, err
}, storeIDsPage) // }, storeIDsPage)
tasksch.HandleTask(task, nil, true).Run() // tasksch.HandleTask(task, nil, true).Run()
result, _ := task.GetResult(0) // result, _ := task.GetResult(0)
for _, v := range result { // for _, v := range result {
getStoreManageStateResult = append(getStoreManageStateResult, v.(*GetStoreManageStateResult)) // getStoreManageStateResult = append(getStoreManageStateResult, v.(*GetStoreManageStateResult))
// }
} }
return &model.PagedInfo{ return &model.PagedInfo{
TotalCount: len(storeIDs), TotalCount: len(storeIDs),