aa
This commit is contained in:
@@ -397,97 +397,87 @@ func GetManageState(ctx *jxcontext.Context, cityCodes []int, vendorID int) (getM
|
||||
|
||||
func RefreshStoreManageState(ctx *jxcontext.Context) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
vendorIDs = []int{model.VendorIDJD, model.VendorIDMTWM, model.VendorIDEBAI}
|
||||
dayTimeBegin, dayTimeEnd = utils.Str2Time(utils.Time2Str(utils.Time2Date(time.Now())) + "00:00:00"), utils.Str2Time(utils.Time2Str(utils.Time2Date(time.Now())) + "23:59:59")
|
||||
coverAreaFlag = time.Now().Hour() == 10 && time.Now().Minute() > 0 && time.Now().Minute() < 12
|
||||
db = dao.GetDB()
|
||||
vendorIDs = []int{model.VendorIDJD, model.VendorIDMTWM, model.VendorIDEBAI}
|
||||
messageFlag = time.Now().Hour() == 10 && time.Now().Minute() > 0 && time.Now().Minute() < 12
|
||||
)
|
||||
task := tasksch.NewParallelTask("RefreshStoreManageState", tasksch.NewParallelConfig().SetParallelCount(3).SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
vendorID := batchItemList[0].(int)
|
||||
storeMaps, err := dao.GetStoresMapList(db, []int{vendorID}, nil, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", "", "")
|
||||
paged, err := dao.GetStoreManageState(db, nil, nil, vendorID, 0, 0, model.UnlimitedPageSize)
|
||||
var (
|
||||
storeManageStates = paged.Data.([]*dao.GetStoreManageStateResult)
|
||||
storeMapsMap = make(map[int]*model.StoreMap)
|
||||
storeManagesMap = make(map[int]*dao.GetStoreManageStateResult)
|
||||
deleteList []int
|
||||
createList, updateList []*model.StoreMap
|
||||
)
|
||||
for _, v := range storeMaps {
|
||||
storeMapsMap[v.StoreID] = v
|
||||
}
|
||||
for _, v := range storeManageStates {
|
||||
storeManagesMap[v.StoreID] = v
|
||||
if storeMapsMap[v.StoreID] != nil {
|
||||
updateList = append(updateList, storeMapsMap[v.StoreID])
|
||||
} else {
|
||||
deleteList = append(deleteList, v.StoreID)
|
||||
}
|
||||
}
|
||||
for _, v := range storeMapsMap {
|
||||
if storeManagesMap[v.StoreID] == nil {
|
||||
createList = append(createList, v)
|
||||
}
|
||||
}
|
||||
task2 := tasksch.NewParallelTask("GetStoreManageState2", tasksch.NewParallelConfig().SetParallelCount(50).SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
storeMap := batchItemList[0].(*model.StoreMap)
|
||||
if storeMap.VendorOrgCode == "" || storeMap.VendorStoreID == "" {
|
||||
return retVal, err
|
||||
step := batchItemList[0].(int)
|
||||
switch step {
|
||||
case 0:
|
||||
task3 := tasksch.NewParallelTask("deleteList", tasksch.NewParallelConfig().SetParallelCount(50).SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
storeID := batchItemList[0].(int)
|
||||
storeManage := &model.StoreManageState{
|
||||
StoreID: storeID,
|
||||
VendorID: vendorID,
|
||||
}
|
||||
dao.DeleteEntity(db, storeManage, "StoreID", "VendorID")
|
||||
return retVal, err
|
||||
}, deleteList)
|
||||
tasksch.HandleTask(task3, task, true).Run()
|
||||
task3.GetResult(0)
|
||||
case 1:
|
||||
task3 := tasksch.NewParallelTask("createList", tasksch.NewParallelConfig().SetParallelCount(50).SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
storeMap := batchItemList[0].(*model.StoreMap)
|
||||
if storeMap.VendorOrgCode == "" || storeMap.VendorStoreID == "" {
|
||||
return retVal, err
|
||||
}
|
||||
storeDetail, _ := dao.GetStoreDetail(db, storeMap.StoreID, vendorID, storeMap.VendorOrgCode)
|
||||
storeManage := buildStoreManageState(ctx, db, storeMap, storeDetail, messageFlag)
|
||||
dao.UpdateEntity(db, storeManage)
|
||||
return retVal, err
|
||||
}, createList)
|
||||
tasksch.HandleTask(task3, task, true).Run()
|
||||
task3.GetResult(0)
|
||||
case 2:
|
||||
task3 := tasksch.NewParallelTask("updateList", tasksch.NewParallelConfig().SetParallelCount(50).SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
storeMap := batchItemList[0].(*model.StoreMap)
|
||||
if storeMap.VendorOrgCode == "" || storeMap.VendorStoreID == "" {
|
||||
return retVal, err
|
||||
}
|
||||
storeDetail, _ := dao.GetStoreDetail(db, storeMap.StoreID, vendorID, storeMap.VendorOrgCode)
|
||||
storeManage := buildStoreManageState(ctx, db, storeMap, storeDetail, messageFlag)
|
||||
dao.CreateEntity(db, storeManage)
|
||||
return retVal, err
|
||||
}, updateList)
|
||||
tasksch.HandleTask(task3, task, true).Run()
|
||||
task3.GetResult(0)
|
||||
}
|
||||
storeDetail, _ := dao.GetStoreDetail(db, storeMap.StoreID, vendorID, storeMap.VendorOrgCode)
|
||||
storeManage := &model.StoreManageState{
|
||||
StoreID: storeMap.StoreID,
|
||||
VendorID: storeMap.VendorID,
|
||||
}
|
||||
dao.WrapAddIDCULEntity(storeManage, ctx.GetUserName())
|
||||
handler := partner.GetPurchasePlatformFromVendorID(vendorID)
|
||||
store, err := handler.ReadStore(ctx, storeDetail.VendorOrgCode, storeDetail.VendorStoreID)
|
||||
// if coverAreaFlag {
|
||||
if vendorID == model.VendorIDJD && store.DeliveryRangeType != model.DeliveryRangeTypePolygon {
|
||||
storeManage.CoverArea = utils.Str2Float64(fmt.Sprintf("%.2f", math.Pi*utils.Str2Float64WithDefault(store.DeliveryRange, 0)/float64(1000)*utils.Str2Float64WithDefault(store.DeliveryRange, 0)/float64(1000)))
|
||||
} else {
|
||||
storeManage.CoverArea = utils.Str2Float64(fmt.Sprintf("%.2f", CalculateCoverArea(strings.Split(store.DeliveryRange, ";"), vendorID)))
|
||||
}
|
||||
// }
|
||||
storeManage.CoverArea = utils.Str2Float64(fmt.Sprintf("%.2f", storeManage.CoverArea))
|
||||
//营业状态
|
||||
storeManage.VendorStatus = store.Status
|
||||
//不一致发消息
|
||||
if coverAreaFlag {
|
||||
vendorStatus, status := -1, -1
|
||||
if store.Status == model.StoreStatusOpened {
|
||||
vendorStatus = 1
|
||||
}
|
||||
if storeDetail.Status == model.StoreStatusOpened {
|
||||
status = 1
|
||||
}
|
||||
statusMap := map[int]string{
|
||||
1: "营业",
|
||||
-1: "休息",
|
||||
}
|
||||
if vendorStatus != status {
|
||||
content := "您的门店 [" + storeDetail.Name + "],ID:[" + utils.Int2Str(storeDetail.ID) + "],在[" + model.VendorChineseNames[vendorID] + "] 平台上营业状态和京西不一致!平台状态:【" + statusMap[vendorStatus] + "】,京西状态:【" + statusMap[status] + "】"
|
||||
if user, err := dao.GetUserByID(db, "mobile", storeDetail.MarketManPhone); err == nil {
|
||||
ddmsg.SendUserMessage(dingdingapi.MsgTyeText, user.UserID, "平台门店状态变化", content)
|
||||
}
|
||||
}
|
||||
}
|
||||
//营业时长
|
||||
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()
|
||||
}
|
||||
storeManage.OpenTime = utils.Str2Float64(fmt.Sprintf("%.2f", optime))
|
||||
//商品数
|
||||
highSkuCount := 0
|
||||
storeSkus, _ := dao.GetStoresSkusForManageState(db, storeMap.StoreID, model.StoreSkuBindStatusNormal)
|
||||
for _, v := range storeSkus {
|
||||
if v.UnitPrice > v.MidUnitPrice {
|
||||
highSkuCount++
|
||||
}
|
||||
}
|
||||
storeManage.SkuCount, storeManage.HighSkuCount = len(storeSkus), highSkuCount
|
||||
//活动丰富度
|
||||
ample, _ := handler.GetActAmple(ctx, storeDetail.VendorStoreID, storeDetail.VendorStoreID)
|
||||
storeManage.ActAmple = ample
|
||||
//订单
|
||||
refuseOrderCount := 0
|
||||
orderList, _ := dao.QueryOrdersForManageState(db, storeMap.StoreID, vendorID, model.OrderStatusCanceled, dayTimeBegin, dayTimeEnd)
|
||||
for _, v := range orderList {
|
||||
if v.BindID == 0 {
|
||||
refuseOrderCount++
|
||||
}
|
||||
}
|
||||
storeManage.NullOrderCount, storeManage.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 {
|
||||
storeManage.StoreScore = scoreResult.AvgPoiScore
|
||||
}
|
||||
}
|
||||
dao.CreateOrUpdate(db, storeManage)
|
||||
return retVal, err
|
||||
}, storeMaps)
|
||||
tasksch.HandleTask(task2, task, true).Run()
|
||||
}, []int{0, 1, 2})
|
||||
tasksch.HandleTask(task, task2, true).Run()
|
||||
task2.GetResult(0)
|
||||
return retVal, err
|
||||
}, vendorIDs)
|
||||
@@ -495,6 +485,84 @@ func RefreshStoreManageState(ctx *jxcontext.Context) {
|
||||
task.GetID()
|
||||
}
|
||||
|
||||
func buildStoreManageState(ctx *jxcontext.Context, db *dao.DaoDB, storeMap *model.StoreMap, storeDetail *dao.StoreDetail, messageFlag bool) *model.StoreManageState {
|
||||
var (
|
||||
dayTimeBegin, dayTimeEnd = utils.Str2Time(utils.Time2Str(utils.Time2Date(time.Now())) + "00:00:00"), utils.Str2Time(utils.Time2Str(utils.Time2Date(time.Now())) + "23:59:59")
|
||||
)
|
||||
storeManage := &model.StoreManageState{
|
||||
StoreID: storeMap.StoreID,
|
||||
VendorID: storeMap.VendorID,
|
||||
}
|
||||
dao.WrapAddIDCULEntity(storeManage, ctx.GetUserName())
|
||||
handler := partner.GetPurchasePlatformFromVendorID(storeMap.VendorID)
|
||||
store, _ := handler.ReadStore(ctx, storeDetail.VendorOrgCode, storeDetail.VendorStoreID)
|
||||
// if coverAreaFlag {
|
||||
if storeMap.VendorID == model.VendorIDJD && store.DeliveryRangeType != model.DeliveryRangeTypePolygon {
|
||||
storeManage.CoverArea = utils.Str2Float64(fmt.Sprintf("%.2f", math.Pi*utils.Str2Float64WithDefault(store.DeliveryRange, 0)/float64(1000)*utils.Str2Float64WithDefault(store.DeliveryRange, 0)/float64(1000)))
|
||||
} else {
|
||||
storeManage.CoverArea = utils.Str2Float64(fmt.Sprintf("%.2f", CalculateCoverArea(strings.Split(store.DeliveryRange, ";"), storeMap.VendorID)))
|
||||
}
|
||||
// }
|
||||
storeManage.CoverArea = utils.Str2Float64(fmt.Sprintf("%.2f", storeManage.CoverArea))
|
||||
//营业状态
|
||||
storeManage.VendorStatus = store.Status
|
||||
//不一致发消息
|
||||
if messageFlag {
|
||||
vendorStatus, status := -1, -1
|
||||
if store.Status == model.StoreStatusOpened {
|
||||
vendorStatus = 1
|
||||
}
|
||||
if storeDetail.Status == model.StoreStatusOpened {
|
||||
status = 1
|
||||
}
|
||||
statusMap := map[int]string{
|
||||
1: "营业",
|
||||
-1: "休息",
|
||||
}
|
||||
if vendorStatus != status {
|
||||
content := "您的门店 [" + storeDetail.Name + "],ID:[" + utils.Int2Str(storeDetail.ID) + "],在[" + model.VendorChineseNames[storeMap.VendorID] + "] 平台上营业状态和京西不一致!平台状态:【" + statusMap[vendorStatus] + "】,京西状态:【" + statusMap[status] + "】"
|
||||
if user, err := dao.GetUserByID(db, "mobile", storeDetail.MarketManPhone); err == nil {
|
||||
ddmsg.SendUserMessage(dingdingapi.MsgTyeText, user.UserID, "平台门店状态变化", content)
|
||||
}
|
||||
}
|
||||
}
|
||||
//营业时长
|
||||
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()
|
||||
}
|
||||
storeManage.OpenTime = utils.Str2Float64(fmt.Sprintf("%.2f", optime))
|
||||
//商品数
|
||||
highSkuCount := 0
|
||||
storeSkus, _ := dao.GetStoresSkusForManageState(db, storeMap.StoreID, model.StoreSkuBindStatusNormal)
|
||||
for _, v := range storeSkus {
|
||||
if v.UnitPrice > v.MidUnitPrice {
|
||||
highSkuCount++
|
||||
}
|
||||
}
|
||||
storeManage.SkuCount, storeManage.HighSkuCount = len(storeSkus), highSkuCount
|
||||
//活动丰富度
|
||||
ample, _ := handler.GetActAmple(ctx, storeDetail.VendorStoreID, storeDetail.VendorStoreID)
|
||||
storeManage.ActAmple = ample
|
||||
//订单
|
||||
refuseOrderCount := 0
|
||||
orderList, _ := dao.QueryOrdersForManageState(db, storeMap.StoreID, storeMap.VendorID, model.OrderStatusCanceled, dayTimeBegin, dayTimeEnd)
|
||||
for _, v := range orderList {
|
||||
if v.BindID == 0 {
|
||||
refuseOrderCount++
|
||||
}
|
||||
}
|
||||
storeManage.NullOrderCount, storeManage.RefuseOrderCount = len(orderList), refuseOrderCount
|
||||
//评分(美团)
|
||||
if storeMap.VendorID == model.VendorIDMTWM {
|
||||
mtapi := partner.CurAPIManager.GetAPI(model.VendorIDMTWM, storeDetail.VendorOrgCode).(*mtwmapi.API)
|
||||
if scoreResult, err := mtapi.CommentScore(storeDetail.VendorStoreID); err == nil {
|
||||
storeManage.StoreScore = scoreResult.AvgPoiScore
|
||||
}
|
||||
}
|
||||
return storeManage
|
||||
}
|
||||
|
||||
func GetStoreManageState(ctx *jxcontext.Context, storeIDs, brandIDs []int, vendorID, sortType, offset, pageSize int) (pageInfo *model.PagedInfo, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
|
||||
Reference in New Issue
Block a user