aa
This commit is contained in:
@@ -400,7 +400,7 @@ func getStoresSql(ctx *jxcontext.Context, keyword string, params map[string]inte
|
||||
if params["earningType"] != nil {
|
||||
if params["earningType"].(int) != 0 {
|
||||
if params["earningType"].(int) == 1 {
|
||||
sqlWhere += " AND t1.pay_percentage = 100"
|
||||
sqlWhere += " AND t1.pay_percentage >= 50"
|
||||
} else {
|
||||
sqlWhere += " AND t1.pay_percentage < 50"
|
||||
}
|
||||
@@ -438,6 +438,14 @@ func getStoresSql(ctx *jxcontext.Context, keyword string, params map[string]inte
|
||||
}
|
||||
}
|
||||
|
||||
if params["mapLongitude"] != nil && params["mapLatitude"] != nil && params["mapRadius"] != nil {
|
||||
mapLongitude := utils.Str2Float64(params["mapLongitude"].(string))
|
||||
mapLatitude := utils.Str2Float64(params["mapLatitude"].(string))
|
||||
mapRadius := params["mapRadius"].(int)
|
||||
sqlWhere += " AND getDistance(?, ?, CAST(t1.lng AS DECIMAL(15,6))/1000000, CAST(t1.lat AS DECIMAL(15,6))/1000000) * 1000 <= ?"
|
||||
sqlWhereParams = append(sqlWhereParams, mapLongitude, mapLatitude, mapRadius)
|
||||
}
|
||||
|
||||
sql = sqlFrom + sqlWhere
|
||||
sqlParams = append(sqlParams, sqlFromParams...)
|
||||
sqlParams = append(sqlParams, sqlWhereParams...)
|
||||
@@ -453,12 +461,12 @@ func setStoreMapInfo(ctx *jxcontext.Context, db *dao.DaoDB, storesInfo *StoresIn
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
isStoreVendorStatus := false
|
||||
if isBussinessStatus != nil {
|
||||
if isBussinessStatus.(bool) {
|
||||
isStoreVendorStatus = true
|
||||
}
|
||||
}
|
||||
//isStoreVendorStatus := false
|
||||
//if isBussinessStatus != nil {
|
||||
// if isBussinessStatus.(bool) {
|
||||
// isStoreVendorStatus = true
|
||||
// }
|
||||
//}
|
||||
storeMapMap := dao.StoreMapList2Map(storeMapList)
|
||||
storeCourierMap := dao.StoreCourierList2Map(storeCourierList)
|
||||
|
||||
@@ -478,39 +486,75 @@ func setStoreMapInfo(ctx *jxcontext.Context, db *dao.DaoDB, storesInfo *StoresIn
|
||||
v.CourierMaps = append(v.CourierMaps, v2)
|
||||
}
|
||||
}
|
||||
task := tasksch.NewParallelTask("上下线状态", tasksch.NewParallelConfig().SetParallelCount(4), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
store := batchItemList[0].(*StoreExt)
|
||||
for _, v2 := range store.StoreMaps {
|
||||
if isStoreVendorStatus {
|
||||
if handler := CurVendorSync.GetStoreHandler(v2.VendorID); handler != nil {
|
||||
if store, err := handler.ReadStore(ctx, v2.VendorOrgCode, v2.VendorStoreID); err == nil && store != nil {
|
||||
if store.Status != model.StoreStatusDisabled {
|
||||
v2.BussinessStatus = 1
|
||||
} else {
|
||||
v2.BussinessStatus = -1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return retVal, err
|
||||
}, storesInfo.Stores)
|
||||
task.Run()
|
||||
task.GetResult(0)
|
||||
//task := tasksch.NewParallelTask("上下线状态", tasksch.NewParallelConfig().SetParallelCount(4), ctx,
|
||||
// func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
// store := batchItemList[0].(*StoreExt)
|
||||
// for _, v2 := range store.StoreMaps {
|
||||
// if isStoreVendorStatus {
|
||||
// if handler := CurVendorSync.GetStoreHandler(v2.VendorID); handler != nil {
|
||||
// if store, err := handler.ReadStore(ctx, v2.VendorOrgCode, v2.VendorStoreID); err == nil && store != nil {
|
||||
// if store.Status != model.StoreStatusDisabled {
|
||||
// v2.BussinessStatus = 1
|
||||
// } else {
|
||||
// v2.BussinessStatus = -1
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return retVal, err
|
||||
// }, storesInfo.Stores)
|
||||
//task.Run()
|
||||
//task.GetResult(0)
|
||||
return nil
|
||||
}
|
||||
|
||||
// todo 门店绑定信息可以考虑以数组形式返回,而不是现在这样
|
||||
func GetStores(ctx *jxcontext.Context, keyword string, params map[string]interface{}, offset, pageSize int, orderTimeFrom, orderTimeTo time.Time, orderCountFrom, orderCountTo int) (retVal *StoresInfo, err error) {
|
||||
briefLevel := int(utils.ForceInterface2Int64(params["briefLevel"]))
|
||||
//权限
|
||||
if permission.IsRoled(ctx) {
|
||||
if storeIDsMap, err := permission.GetUserStoresResultMap(ctx.GetUserID()); err == nil {
|
||||
var storeIDs2 []int
|
||||
if params["storeIDs"] != nil {
|
||||
var storeIDs []int
|
||||
if err = utils.UnmarshalUseNumber([]byte(params["storeIDs"].(string)), &storeIDs); err == nil {
|
||||
for _, v := range storeIDs {
|
||||
if storeIDsMap[v] != 0 {
|
||||
storeIDs2 = append(storeIDs2, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(storeIDs2) == 0 {
|
||||
storeIDs2 = append(storeIDs2, -1)
|
||||
}
|
||||
} else {
|
||||
if params["storeID"] != nil {
|
||||
if storeIDsMap[int(utils.Interface2Int64WithDefault(params["storeID"], 0))] == 0 {
|
||||
params["storeID"] = nil
|
||||
}
|
||||
} else {
|
||||
if len(storeIDsMap) > 0 {
|
||||
for k, _ := range storeIDsMap {
|
||||
storeIDs2 = append(storeIDs2, k)
|
||||
}
|
||||
} else {
|
||||
storeIDs2 = append(storeIDs2, -1)
|
||||
}
|
||||
}
|
||||
}
|
||||
if data, err := json.Marshal(storeIDs2); err == nil {
|
||||
params["storeIDs"] = string(data)
|
||||
}
|
||||
}
|
||||
}
|
||||
sql, sqlParams, _, _, err := getStoresSql(ctx, keyword, params, orderTimeFrom, orderTimeTo)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sql = `
|
||||
SELECT
|
||||
SQL_CALC_FOUND_ROWS
|
||||
DISTINCT t1.*,
|
||||
CAST(t1.lng AS DECIMAL(15,6))/1000000 float_lng,
|
||||
CAST(t1.lat AS DECIMAL(15,6))/1000000 float_lat,
|
||||
@@ -528,6 +572,7 @@ func GetStores(ctx *jxcontext.Context, keyword string, params map[string]interfa
|
||||
(SELECT COUNT(*) FROM store t11 WHERE t11.link_store_id = t1.id) link_store_count
|
||||
` + sql + `
|
||||
ORDER BY t1.id DESC
|
||||
LIMIT ? OFFSET ?
|
||||
`
|
||||
db := dao.GetDB()
|
||||
retVal = &StoresInfo{}
|
||||
@@ -536,62 +581,52 @@ func GetStores(ctx *jxcontext.Context, keyword string, params map[string]interfa
|
||||
var storeList []*StoreExt
|
||||
offset = jxutils.FormalizePageOffset(offset)
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
mapLimit := false
|
||||
// globals.SugarLogger.Debug(sql)
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(sqlParams, false))
|
||||
|
||||
if err = dao.GetRows(db, &storeList, sql, sqlParams...); err == nil {
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
//mapLimit := false
|
||||
//globals.SugarLogger.Debug(sql)
|
||||
//globals.SugarLogger.Debug(utils.Format4Output(sqlParams, false))
|
||||
txDB, _ := dao.Begin(db)
|
||||
if err = dao.GetRowsTx(txDB, &storeList, sql, sqlParams...); err == nil {
|
||||
retVal.Stores = storeList
|
||||
retVal.TotalCount = dao.GetLastTotalRowCount2(db, txDB)
|
||||
// 地图区域限制过滤
|
||||
if mapLongitude2, ok := params["mapLongitude"].(string); ok {
|
||||
var (
|
||||
mapLatitude, mapLongitude float64
|
||||
mapRadius int
|
||||
)
|
||||
mapLimit = true
|
||||
mapLongitude = utils.Str2Float64(mapLongitude2)
|
||||
mapLatitude = utils.Str2Float64(params["mapLatitude"].(string))
|
||||
mapRadius = params["mapRadius"].(int)
|
||||
for _, v := range storeList {
|
||||
valid := !mapLimit
|
||||
if mapLimit {
|
||||
valid = jxutils.EarthDistance(mapLongitude, mapLatitude, v.FloatLng, v.FloatLat)*1000 <= float64(mapRadius)
|
||||
}
|
||||
if valid {
|
||||
retVal.Stores = append(retVal.Stores, v)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
retVal.Stores = storeList
|
||||
}
|
||||
//权限
|
||||
if permission.IsRoled(ctx) {
|
||||
if storeIDsMap, err := permission.GetUserStoresResultMap(ctx.GetUserID()); err == nil {
|
||||
var storeList2 []*StoreExt
|
||||
for _, v := range retVal.Stores {
|
||||
if storeIDsMap[v.ID] != 0 {
|
||||
storeList2 = append(storeList2, v)
|
||||
}
|
||||
}
|
||||
retVal.Stores = nil
|
||||
retVal.Stores = storeList2
|
||||
}
|
||||
}
|
||||
//if mapLongitude2, ok := params["mapLongitude"].(string); ok {
|
||||
// var (
|
||||
// mapLatitude, mapLongitude float64
|
||||
// mapRadius int
|
||||
// )
|
||||
// mapLimit = true
|
||||
// mapLongitude = utils.Str2Float64(mapLongitude2)
|
||||
// mapLatitude = utils.Str2Float64(params["mapLatitude"].(string))
|
||||
// mapRadius = params["mapRadius"].(int)
|
||||
// for _, v := range storeList {
|
||||
// valid := !mapLimit
|
||||
// if mapLimit {
|
||||
// valid = jxutils.EarthDistance(mapLongitude, mapLatitude, v.FloatLng, v.FloatLat)*1000 <= float64(mapRadius)
|
||||
// }
|
||||
// if valid {
|
||||
// retVal.Stores = append(retVal.Stores, v)
|
||||
// }
|
||||
// }
|
||||
//} else {
|
||||
// retVal.Stores = storeList
|
||||
//}
|
||||
// 订单情况过滤
|
||||
storeList, err = filterStoreByOrderInfo(db, retVal.Stores, orderTimeFrom, orderTimeTo, orderCountFrom, orderCountTo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//storeList, err = filterStoreByOrderInfo(db, retVal.Stores, orderTimeFrom, orderTimeTo, orderCountFrom, orderCountTo)
|
||||
//if err != nil {
|
||||
// return nil, err
|
||||
//}
|
||||
|
||||
// 分页
|
||||
retVal.TotalCount = len(storeList)
|
||||
retVal.Stores = nil
|
||||
for i := offset; i < offset+pageSize && i < len(storeList); i++ {
|
||||
storeIDs = append(storeIDs, storeList[i].ID)
|
||||
retVal.Stores = append(retVal.Stores, storeList[i])
|
||||
}
|
||||
if len(storeIDs) == 0 {
|
||||
return retVal, nil
|
||||
}
|
||||
//retVal.TotalCount = len(storeList)
|
||||
//retVal.Stores = nil
|
||||
//for i := offset; i < offset+pageSize && i < len(storeList); i++ {
|
||||
// storeIDs = append(storeIDs, storeList[i].ID)
|
||||
// retVal.Stores = append(retVal.Stores, storeList[i])
|
||||
//}
|
||||
//if len(storeIDs) == 0 {
|
||||
// return retVal, nil
|
||||
//}
|
||||
|
||||
// 导出门店地图标信息时,可能会需要转换门店坐标
|
||||
needConver2Baidu := int(utils.Interface2Int64WithDefault(params["coordinateType"], 0)) == model.CoordinateTypeBaiDu
|
||||
@@ -620,10 +655,8 @@ func GetStores(ctx *jxcontext.Context, keyword string, params map[string]interfa
|
||||
task.Run()
|
||||
task.GetResult(0)
|
||||
}
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dao.Commit(db, txDB)
|
||||
if len(retVal.Stores) > 0 {
|
||||
setStoreMapInfo(ctx, db, retVal, storeIDs, briefLevel, params["isBussinessStatus"])
|
||||
retVal.MapCenterLng, retVal.MapCenterLat = getMapCenter(retVal.Stores)
|
||||
@@ -4260,7 +4293,7 @@ func RefreshStoreBind(ctx *jxcontext.Context) (err error) {
|
||||
if store.OperatorPhone3 != "" {
|
||||
mobileList = append(mobileList, store.OperatorPhone3)
|
||||
}
|
||||
mobileList = append(mobileList, "18160030913", "15520595380", "18980410281", "18048531223", "18080188338", "13012345678")
|
||||
mobileList = append(mobileList, "18160030913", "15520595380", "18048531223", "18080188338", "13012345678")
|
||||
for _, v := range mobileList {
|
||||
if user, err := dao.GetUserByID(db, "mobile", v); err == nil && user != nil {
|
||||
userIDmap1[user.UserID] = user.UserID
|
||||
@@ -4296,7 +4329,13 @@ func UpdateVendorStoreBussinessStatus(ctx *jxcontext.Context, storeID, vendorID,
|
||||
return err
|
||||
}
|
||||
handler := partner.GetPurchasePlatformFromVendorID(vendorID)
|
||||
err = handler.UpdateStoreLineStatus(ctx, storeDetail.VendorOrgCode, storeID, storeDetail.VendorStoreID, status)
|
||||
if err = handler.UpdateStoreLineStatus(ctx, storeDetail.VendorOrgCode, storeID, storeDetail.VendorStoreID, status); err == nil {
|
||||
if storeMaps, _ := dao.GetStoresMapList(db, []int{vendorID}, []int{storeID}, nil, model.StoreStatusAll,
|
||||
model.StoreIsSyncAll, "", "", ""); len(storeMaps) > 0 {
|
||||
storeMaps[0].IsOnline = status
|
||||
dao.UpdateEntity(db, storeMaps[0], "IsOnline")
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -5164,3 +5203,28 @@ func UpdateOrCreateCourierStoresByBrand(ctx *jxcontext.Context, brandID, vendorI
|
||||
hint = task.ID
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func RefreshStoreIsOnline(ctx *jxcontext.Context) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
stores, _ := dao.GetStoresMapList(db, []int{model.VendorIDMTWM, model.VendorIDJD, model.VendorIDEBAI}, nil, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", "", "")
|
||||
task := tasksch.NewParallelTask("RefreshStoreBind", tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
storeMap := batchItemList[0].(*model.StoreMap)
|
||||
if handler := CurVendorSync.GetStoreHandler(storeMap.VendorID); handler != nil {
|
||||
if store, err := handler.ReadStore(ctx, storeMap.VendorOrgCode, storeMap.VendorStoreID); err == nil && store != nil {
|
||||
if store.Status != model.StoreStatusDisabled {
|
||||
storeMap.IsOnline = 1
|
||||
} else {
|
||||
storeMap.IsOnline = -1
|
||||
}
|
||||
dao.UpdateEntity(db, storeMap, "IsOnline")
|
||||
}
|
||||
}
|
||||
return retVal, err
|
||||
}, stores)
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
task.GetID()
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user