- GetStores添加订单相关的查询条件
This commit is contained in:
@@ -104,7 +104,7 @@ var (
|
||||
)
|
||||
|
||||
// todo 门店绑定信息可以考虑以数组形式返回,而不是现在这样
|
||||
func GetStores(ctx *jxcontext.Context, keyword string, params map[string]interface{}, offset, pageSize int) (retVal *StoresInfo, err error) {
|
||||
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) {
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS
|
||||
CAST(t1.lng AS DECIMAL(15,6))/1000000 float_lng,
|
||||
@@ -324,6 +324,8 @@ func GetStores(ctx *jxcontext.Context, keyword string, params map[string]interfa
|
||||
var storeList []*StoreExt
|
||||
mapLimit := false
|
||||
if err = dao.GetRows(db, &storeList, sql, sqlParams...); err == nil {
|
||||
retVal.TotalCount = dao.GetLastTotalRowCount(db)
|
||||
dao.Commit(db)
|
||||
// globals.SugarLogger.Debugf("GetStores, len(storeList):%d", len(storeList))
|
||||
var (
|
||||
mapLatitude, mapLongitude float64
|
||||
@@ -343,32 +345,57 @@ func GetStores(ctx *jxcontext.Context, keyword string, params map[string]interfa
|
||||
if valid {
|
||||
if v.StoreMapStr != "" {
|
||||
if err = utils.UnmarshalUseNumber([]byte(v.StoreMapStr), &v.StoreMaps); err != nil {
|
||||
dao.Rollback(db)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if v.CourierMapStr != "" {
|
||||
if err = utils.UnmarshalUseNumber([]byte(v.CourierMapStr), &v.CourierMaps); err != nil {
|
||||
dao.Rollback(db)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
retVal.Stores = append(retVal.Stores, v)
|
||||
}
|
||||
}
|
||||
retVal.Stores, err = filterStoreByOrderInfo(db, retVal.Stores, orderTimeFrom, orderTimeTo, orderCountFrom, orderCountTo)
|
||||
if mapLimit {
|
||||
retVal.TotalCount = len(retVal.Stores)
|
||||
} else {
|
||||
retVal.TotalCount = dao.GetLastTotalRowCount(db)
|
||||
}
|
||||
} else {
|
||||
dao.Rollback(db)
|
||||
}
|
||||
dao.Commit(db)
|
||||
if mapLimit {
|
||||
if mapLimit && len(retVal.Stores) > 0 {
|
||||
retVal.MapCenterLng, retVal.MapCenterLat = getMapCenter(retVal.Stores)
|
||||
}
|
||||
return retVal, err
|
||||
}
|
||||
|
||||
func filterStoreByOrderInfo(db *dao.DaoDB, inStores []*StoreExt, orderTimeFrom, orderTimeTo time.Time, orderCountFrom, orderCountTo int) (outStores []*StoreExt, err error) {
|
||||
if len(inStores) > 0 && !utils.IsTimeZero(orderTimeFrom) {
|
||||
storeIDs := make([]int, len(inStores))
|
||||
for k, v := range inStores {
|
||||
storeIDs[k] = v.ID
|
||||
}
|
||||
orderSaleList, err2 := dao.GetStoresOrderSaleInfo(dao.GetDB(), storeIDs, orderTimeFrom, orderTimeTo, []int{model.OrderStatusFinished})
|
||||
if err = err2; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
storeOrderCountMap := make(map[int]int)
|
||||
for _, v := range orderSaleList {
|
||||
storeOrderCountMap[v.StoreID] += v.Count
|
||||
}
|
||||
|
||||
for _, v := range inStores {
|
||||
orderCount := storeOrderCountMap[v.ID]
|
||||
if orderCount >= orderCountFrom && orderCount <= orderCountTo {
|
||||
outStores = append(outStores, v)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
outStores = inStores
|
||||
}
|
||||
return outStores, err
|
||||
}
|
||||
|
||||
func getMapCenter(storeList []*StoreExt) (lng, lat float64) {
|
||||
globals.SugarLogger.Debugf("getMapCenter len(storeList):%d", len(storeList))
|
||||
if len(storeList) == 0 {
|
||||
@@ -573,7 +600,7 @@ func SetStoreStatus(ctx *jxcontext.Context, storeID, status int) (err error) {
|
||||
func EnableHaveRestStores(ctx *jxcontext.Context, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
storeInfo, err := GetStores(ctx, "", map[string]interface{}{
|
||||
"statuss": string(utils.MustMarshal([]int{model.StoreStatusHaveRest})),
|
||||
}, 0, model.UnlimitedPageSize)
|
||||
}, 0, model.UnlimitedPageSize, utils.ZeroTimeValue, utils.ZeroTimeValue, 0, 0)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user