aa
This commit is contained in:
@@ -414,7 +414,13 @@ func GetStoreManageState(ctx *jxcontext.Context, storeIDs []int, vendorID int, f
|
||||
dayCount = int(fromTimeT.Sub(toTimeT).Hours())/24 + 1 //查的几天
|
||||
getStoreManageStateResult []*GetStoreManageStateResult
|
||||
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 storeIDsMap, err := permission.GetUserStoresResultMap(ctx.GetUserID()); err == nil {
|
||||
@@ -427,11 +433,9 @@ func GetStoreManageState(ctx *jxcontext.Context, storeIDs []int, vendorID int, f
|
||||
}
|
||||
} else {
|
||||
for k, _ := range storeIDsMap {
|
||||
storeDetail, _ := dao.GetStoreDetail(db, k, vendorID, "")
|
||||
if storeDetail == nil || storeDetail.VendorStoreID == "" || storeDetail.VendorOrgCode == "" {
|
||||
continue
|
||||
if storeMapMaps[k] != nil {
|
||||
storeIDs2 = append(storeIDs2, k)
|
||||
}
|
||||
storeIDs2 = append(storeIDs2, k)
|
||||
}
|
||||
}
|
||||
storeIDs = nil
|
||||
@@ -443,77 +447,79 @@ func GetStoreManageState(ctx *jxcontext.Context, storeIDs []int, vendorID int, f
|
||||
index2 = len(storeIDs) - 1
|
||||
}
|
||||
storeIDsPage = storeIDs[offset*pageSize : index2]
|
||||
task := tasksch.NewParallelTask("GetStoreManageState", tasksch.NewParallelConfig().SetParallelCount(20).SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
v := batchItemList[0].(int)
|
||||
storeDetail, _ := dao.GetStoreDetail(db, v, vendorID, "")
|
||||
if storeDetail == nil || storeDetail.VendorStoreID == "" || storeDetail.VendorOrgCode == "" {
|
||||
return retVal, err
|
||||
}
|
||||
result := &GetStoreManageStateResult{
|
||||
StoreID: v,
|
||||
StoreName: storeDetail.Name,
|
||||
MarketScale: storeDetail.MarketScale,
|
||||
CoverArea: storeDetail.CoverArea,
|
||||
}
|
||||
//覆盖范围
|
||||
if result.CoverArea == 0 {
|
||||
handler := partner.GetPurchasePlatformFromVendorID(vendorID)
|
||||
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 vendorID == model.VendorIDJD && store.DeliveryRangeType != model.DeliveryRangeTypePolygon {
|
||||
storeMaps[0].CoverArea = math.Pi * utils.Str2Float64WithDefault(store.DeliveryRange, 0) * utils.Str2Float64WithDefault(store.DeliveryRange, 0) / float64(10000)
|
||||
} else {
|
||||
storeMaps[0].CoverArea = CalculateCoverArea(strings.Split(store.DeliveryRange, ";"), vendorID)
|
||||
}
|
||||
dao.UpdateEntity(db, storeMaps[0], "CoverArea")
|
||||
result.CoverArea = storeMaps[0].CoverArea
|
||||
}
|
||||
}
|
||||
}
|
||||
//营业时长
|
||||
optime := jxutils.JxOperationTime2TimeByDate(storeDetail.CloseTime1, time.Now()).Sub(jxutils.JxOperationTime2TimeByDate(storeDetail.OpenTime1, time.Now())).Hours()
|
||||
if storeDetail.CloseTime2 != 0 && storeDetail.OpenTime2 != 0 {
|
||||
optime += jxutils.JxOperationTime2TimeByDate(storeDetail.CloseTime2, time.Now()).Sub(jxutils.JxOperationTime2TimeByDate(storeDetail.OpenTime2, time.Now())).Hours()
|
||||
}
|
||||
result.OpenTime = optime * float64(dayCount)
|
||||
//商品数
|
||||
highSkuCount := 0
|
||||
storeSkus, _ := dao.GetStoresSkusForManageState(db, v, model.StoreSkuBindStatusNormal)
|
||||
for _, v := range storeSkus {
|
||||
if v.UnitPrice > v.MidUnitPrice {
|
||||
highSkuCount++
|
||||
}
|
||||
}
|
||||
result.SkuCount, result.HighSkuCount = len(storeSkus), highSkuCount
|
||||
//活动丰富度
|
||||
for _, v := range storeIDsPage {
|
||||
// task := tasksch.NewParallelTask("GetStoreManageState", tasksch.NewParallelConfig().SetParallelCount(20).SetIsContinueWhenError(true), ctx,
|
||||
// func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
// v := batchItemList[0].(int)
|
||||
storeDetail, _ := dao.GetStoreDetail(db, v, vendorID, "")
|
||||
if storeDetail == nil || storeDetail.VendorStoreID == "" || storeDetail.VendorOrgCode == "" {
|
||||
continue
|
||||
}
|
||||
result := &GetStoreManageStateResult{
|
||||
StoreID: v,
|
||||
StoreName: storeDetail.Name,
|
||||
MarketScale: storeDetail.MarketScale,
|
||||
CoverArea: storeDetail.CoverArea,
|
||||
}
|
||||
//覆盖范围
|
||||
if result.CoverArea == 0 {
|
||||
handler := partner.GetPurchasePlatformFromVendorID(vendorID)
|
||||
ample, _ := handler.GetActAmple(ctx, storeDetail.VendorStoreID, storeDetail.VendorStoreID)
|
||||
result.ActAmple = ample
|
||||
//订单
|
||||
refuseOrderCount := 0
|
||||
orderList, err := dao.QueryOrdersForManageState(db, v, vendorID, model.OrderStatusCanceled, fromTimeT, toTimeT)
|
||||
for _, v := range orderList {
|
||||
if v.BindID == 0 {
|
||||
refuseOrderCount++
|
||||
if store, err := handler.ReadStore(ctx, storeDetail.VendorOrgCode, storeDetail.VendorStoreID); err == nil {
|
||||
if storeMapMaps[v] != nil {
|
||||
if vendorID == model.VendorIDJD && store.DeliveryRangeType != model.DeliveryRangeTypePolygon {
|
||||
storeMapMaps[v].CoverArea = math.Pi * utils.Str2Float64WithDefault(store.DeliveryRange, 0) * utils.Str2Float64WithDefault(store.DeliveryRange, 0) / float64(10000)
|
||||
} else {
|
||||
storeMapMaps[v].CoverArea = CalculateCoverArea(strings.Split(store.DeliveryRange, ";"), vendorID)
|
||||
}
|
||||
dao.UpdateEntity(db, storeMapMaps[v], "CoverArea")
|
||||
result.CoverArea = storeMapMaps[v].CoverArea
|
||||
}
|
||||
}
|
||||
result.NullOrderCount, result.RefuseOrderCount = len(orderList), refuseOrderCount
|
||||
//评分(美团)
|
||||
if vendorID == model.VendorIDMTWM {
|
||||
mtapi := partner.CurAPIManager.GetAPI(model.VendorIDMTWM, storeDetail.VendorOrgCode).(*mtwmapi.API)
|
||||
if scoreResult, err := mtapi.CommentScore(storeDetail.VendorStoreID); err == nil {
|
||||
result.StoreScore = scoreResult.AvgPoiScore
|
||||
}
|
||||
}
|
||||
//营业时长
|
||||
optime := jxutils.JxOperationTime2TimeByDate(storeDetail.CloseTime1, time.Now()).Sub(jxutils.JxOperationTime2TimeByDate(storeDetail.OpenTime1, time.Now())).Hours()
|
||||
if storeDetail.CloseTime2 != 0 && storeDetail.OpenTime2 != 0 {
|
||||
optime += jxutils.JxOperationTime2TimeByDate(storeDetail.CloseTime2, time.Now()).Sub(jxutils.JxOperationTime2TimeByDate(storeDetail.OpenTime2, time.Now())).Hours()
|
||||
}
|
||||
result.OpenTime = optime * float64(dayCount)
|
||||
//商品数
|
||||
highSkuCount := 0
|
||||
storeSkus, _ := dao.GetStoresSkusForManageState(db, v, model.StoreSkuBindStatusNormal)
|
||||
for _, v := range storeSkus {
|
||||
if v.UnitPrice > v.MidUnitPrice {
|
||||
highSkuCount++
|
||||
}
|
||||
retVal = []*GetStoreManageStateResult{result}
|
||||
// getStoreManageStateResult = append(getStoreManageStateResult, result)
|
||||
return retVal, err
|
||||
}, storeIDsPage)
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
result, _ := task.GetResult(0)
|
||||
for _, v := range result {
|
||||
getStoreManageStateResult = append(getStoreManageStateResult, v.(*GetStoreManageStateResult))
|
||||
}
|
||||
result.SkuCount, result.HighSkuCount = len(storeSkus), highSkuCount
|
||||
//活动丰富度
|
||||
handler := partner.GetPurchasePlatformFromVendorID(vendorID)
|
||||
ample, _ := handler.GetActAmple(ctx, storeDetail.VendorStoreID, storeDetail.VendorStoreID)
|
||||
result.ActAmple = ample
|
||||
//订单
|
||||
refuseOrderCount := 0
|
||||
orderList, _ := dao.QueryOrdersForManageState(db, v, vendorID, model.OrderStatusCanceled, fromTimeT, toTimeT)
|
||||
for _, v := range orderList {
|
||||
if v.BindID == 0 {
|
||||
refuseOrderCount++
|
||||
}
|
||||
}
|
||||
result.NullOrderCount, result.RefuseOrderCount = len(orderList), refuseOrderCount
|
||||
//评分(美团)
|
||||
if vendorID == model.VendorIDMTWM {
|
||||
mtapi := partner.CurAPIManager.GetAPI(model.VendorIDMTWM, storeDetail.VendorOrgCode).(*mtwmapi.API)
|
||||
if scoreResult, err := mtapi.CommentScore(storeDetail.VendorStoreID); err == nil {
|
||||
result.StoreScore = scoreResult.AvgPoiScore
|
||||
}
|
||||
}
|
||||
// retVal = []*GetStoreManageStateResult{result}
|
||||
// getStoreManageStateResult = append(getStoreManageStateResult, result)
|
||||
// return retVal, err
|
||||
// }, storeIDsPage)
|
||||
// tasksch.HandleTask(task, nil, true).Run()
|
||||
// result, _ := task.GetResult(0)
|
||||
// for _, v := range result {
|
||||
// getStoreManageStateResult = append(getStoreManageStateResult, v.(*GetStoreManageStateResult))
|
||||
// }
|
||||
}
|
||||
return &model.PagedInfo{
|
||||
TotalCount: len(storeIDs),
|
||||
|
||||
Reference in New Issue
Block a user