This commit is contained in:
苏尹岚
2021-01-22 10:05:43 +08:00
parent f85fa9e12a
commit 519592bc31
14 changed files with 145 additions and 30 deletions

View File

@@ -458,7 +458,7 @@ func DeleteConfig(ctx *jxcontext.Context, key, configType string) (err error) {
}
}
errList.AddErr(err)
storeList, err2 := dao.GetStoreList(db, nil, nil, nil, nil, key)
storeList, err2 := dao.GetStoreList(db, nil, nil, nil, nil, nil, key)
if err = err2; err == nil && len(storeList) > 0 {
storeIDs := make([]int, len(storeList))
for k, v := range storeList {

View File

@@ -5,6 +5,8 @@ import (
"strings"
"time"
"git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
@@ -222,6 +224,12 @@ func UpdateUserRole(ctx *jxcontext.Context, userIDs []string, roleIDs []int) (er
}
}
}
for _, v := range userIDs {
if user, err := dao.GetUserByID(db, "userID", v); err == nil {
user.Type = user.Type | model.UserTypeRole
dao.UpdateEntity(db, user, "Type")
}
}
dao.Commit(db)
return err
}
@@ -299,3 +307,51 @@ func UpdateRoleMenu(ctx *jxcontext.Context, roleIDs, menuIDs []int) (err error)
dao.Commit(db)
return err
}
func GetUserStoresResultMap(userID string) (resultMap map[int]int, err error) {
var (
db = dao.GetDB()
brandIDMap = make(map[int]int)
cityCodeMap = make(map[int]int)
storeIDMap = make(map[int]int)
brandIDs, cityCodes, storeIDs []int
stores []*model.Store
)
resultMap = make(map[int]int)
userRoles, err := dao.GetUserRole2(db, []string{userID}, nil)
for _, v := range userRoles {
if _, ok := brandIDMap[v.BrandID]; !ok {
brandIDMap[v.BrandID] = 1
}
for _, cityCode := range jxutils.StrListToIntList(strings.Split(v.CityCodes, ",")) {
if _, ok := cityCodeMap[cityCode]; !ok {
cityCodeMap[cityCode] = 1
}
}
for _, storeID := range jxutils.StrListToIntList(strings.Split(v.StoreIDs, ",")) {
if _, ok := storeIDMap[storeID]; !ok {
storeIDMap[storeID] = 1
}
}
}
for k, _ := range brandIDMap {
brandIDs = append(brandIDs, k)
}
for k, _ := range cityCodeMap {
cityCodes = append(cityCodes, k)
}
for k, _ := range storeIDMap {
storeIDs = append(storeIDs, k)
}
if cityCodeMap[0] != 0 {
stores, err = dao.GetStoreList(db, nil, nil, nil, brandIDs, nil, "")
} else {
stores, err = dao.GetStoreList(db, storeIDs, cityCodes, nil, brandIDs, nil, "")
}
for _, v := range stores {
if _, ok := resultMap[v.ID]; !ok {
resultMap[v.ID] = v.ID
}
}
return resultMap, err
}

View File

@@ -516,7 +516,23 @@ func GetStores(ctx *jxcontext.Context, keyword string, params map[string]interfa
} else {
retVal.Stores = storeList
}
//权限
if ctx.GetUserName() != "jxadmin" {
if user, err := dao.GetUserByID(db, "userID", ctx.GetUserID()); err == nil {
if user.Type&model.UserTypeRole != 0 {
if storeIDsMap, err := GetUserStoresResultMap(user.UserID); 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
}
}
}
}
// 订单情况过滤
storeList, err = filterStoreByOrderInfo(db, retVal.Stores, orderTimeFrom, orderTimeTo, orderCountFrom, orderCountTo)
if err != nil {
@@ -2254,7 +2270,7 @@ func SendAlarmVendorSnapshot(ctx *jxcontext.Context, parentTask tasksch.ITask, p
}
if len(userList) > 0 {
allStores, err := dao.GetStoreList(db, nil, nil, nil, nil, "")
allStores, err := dao.GetStoreList(db, nil, nil, nil, nil, nil, "")
if err != nil {
return err
}
@@ -2428,7 +2444,7 @@ func SaveAndSendAlarmVendorSnapshot(ctx *jxcontext.Context, vendorIDs, storeIDs
func SyncStoresCourierInfo(ctx *jxcontext.Context, storeIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
db := dao.GetDB()
storeList2, err := dao.GetStoreList(db, storeIDs, nil, nil, nil, "")
storeList2, err := dao.GetStoreList(db, storeIDs, nil, nil, nil, nil, "")
var storeList []*model.Store
for _, v := range storeList2 {
if v.Status != model.StoreStatusDisabled {
@@ -2957,7 +2973,7 @@ func UpdateJdStoreNameAll(ctx *jxcontext.Context) (err error) {
func DeletePrinterSeq(ctx *jxcontext.Context, storeIDs []int) (err error) {
db := dao.GetDB()
for _, v := range storeIDs {
stores, err := dao.GetStoreList(db, []int{v}, nil, nil, nil, "")
stores, err := dao.GetStoreList(db, []int{v}, nil, nil, nil, nil, "")
if err != nil || len(stores) == 0 {
return err
}
@@ -3010,7 +3026,7 @@ func checkYbParams(db *dao.DaoDB, storeMap *model.StoreMap, storeID int) (err er
}
}
}
stores, err := dao.GetStoreList(db, []int{storeID}, nil, nil, nil, "")
stores, err := dao.GetStoreList(db, []int{storeID}, nil, nil, nil, nil, "")
if len(stores) > 0 {
if configs, err := dao.QueryConfigs(dao.GetDB(), "yinbaoCookie", model.ConfigTypeCookie, ""); err == nil {
yinbaoCookie = configs[0].Value
@@ -3356,7 +3372,7 @@ func DisabledStoreWithoutVendor(ctx *jxcontext.Context, isContinueWhenError, isA
var (
db = dao.GetDB()
)
stores, err := dao.GetStoreList(db, nil, nil, []int{model.StoreStatusClosed, model.StoreStatusHaveRest, model.StoreStatusOpened}, nil, "")
stores, err := dao.GetStoreList(db, nil, nil, []int{model.StoreStatusClosed, model.StoreStatusHaveRest, model.StoreStatusOpened}, nil, nil, "")
task := tasksch.NewParallelTask("DisabledStoreWithoutVendor", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
store := batchItemList[0].(*model.Store)
@@ -3733,7 +3749,7 @@ func GetDiffJxStoreAndMTWMStoreInfo(ctx *jxcontext.Context, storeIDs []int) (err
tmpDiffStore := &TmpDiffStore{
StoreID: v.StoreID,
}
stores, err := dao.GetStoreList(db, []int{v.StoreID}, nil, nil, nil, "")
stores, err := dao.GetStoreList(db, []int{v.StoreID}, nil, nil, nil, nil, "")
store := stores[0]
place, _ := dao.GetPlaceByCode(db, store.CityCode)
tmpDiffStore.City = place.Name

View File

@@ -931,7 +931,7 @@ func UpdateStoresSkus(ctx *jxcontext.Context, causeFlag int, storeIDs []int, sku
func UpdateStoresSkusWithoutSync(ctx *jxcontext.Context, storeIDs []int, skuBindInfos []*StoreSkuBindInfo, isRefreshHigh bool) (err error) {
db := dao.GetDB()
if len(storeIDs) == 0 {
stores, _ := dao.GetStoreList(db, nil, nil, nil, nil, "")
stores, _ := dao.GetStoreList(db, nil, nil, nil, nil, nil, "")
for _, v := range stores {
storeIDs = append(storeIDs, v.ID)
}
@@ -3267,7 +3267,7 @@ func FocusStoreSkusByExcelBin(ctx *jxcontext.Context, reader io.Reader, isAsync,
skuIDs = append(skuIDs, k)
}
skuList, err := dao.GetSkus(db, skuIDs, nil, nil, nil, nil)
storeList, err := dao.GetStoreList(db, nil, nil, nil, nil, "")
storeList, err := dao.GetStoreList(db, nil, nil, nil, nil, nil, "")
if err != nil && len(skuList) == 0 {
return result, err
}
@@ -3454,7 +3454,7 @@ func AutoFocusStoreSkusForTopSkus(ctx *jxcontext.Context, isAsync, isContinueWhe
var (
result1 []interface{}
)
storeList, err := dao.GetStoreList(db, nil, nil, nil, nil, "")
storeList, err := dao.GetStoreList(db, nil, nil, nil, nil, nil, "")
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
switch step {
case 0:
@@ -3552,7 +3552,7 @@ func AutoFocusStoreSkusWithoutFocus(ctx *jxcontext.Context, skuIDs []int, isSync
nameMap = make(map[int]*StoreSkuBindInfo)
)
db := dao.GetDB()
storeList, err := dao.GetStoreList(db, nil, nil, nil, nil, "")
storeList, err := dao.GetStoreList(db, nil, nil, nil, nil, nil, "")
for _, v := range storeList {
storeSkuList, _ := dao.GetStoreSkusAndSkuName(db, []int{v.ID}, skuIDs, nil)
for _, vv := range storeSkuList {
@@ -4155,7 +4155,7 @@ func BackUpStoreSkuBind(ctx *jxcontext.Context, isAsync, isContinueWhenError boo
SnapshotAt: snapshotAt.AddDate(0, 0, -5),
}
dao.DeleteEntity(db, storeSkuBindHis, "SnapshotAt")
storeList, err := dao.GetStoreList(db, nil, nil, nil, nil, "")
storeList, err := dao.GetStoreList(db, nil, nil, nil, nil, nil, "")
task := tasksch.NewParallelTask("BackUpStoreSkuBind", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
store := batchItemList[0].(*model.Store)
@@ -4701,7 +4701,7 @@ func doStoreSkuAudit(ctx *jxcontext.Context, storeIDs []int, skuBindInfos []*Sto
time.Sleep(time.Second / 5)
db := dao.GetDB()
for _, storeID := range storeIDs {
stores, _ := dao.GetStoreList(db, []int{storeID}, nil, nil, nil, "")
stores, _ := dao.GetStoreList(db, []int{storeID}, nil, nil, nil, nil, "")
//扣点的门店改价不进审核
if len(stores) > 0 {
if stores[0].PayPercentage <= 50 || stores[0].StoreLevel == "E" || stores[0].StoreLevel == "D" {

View File

@@ -1321,7 +1321,7 @@ func SetMTPSStatus(ctx *jxcontext.Context, storeId, courierStatus int) {
//&& CourierStatus != 0
if storeId != 0 {
var ShopName string
StoreLists, _ := dao.GetStoreList(nil, []int{storeId}, nil, nil, nil, "")
StoreLists, _ := dao.GetStoreList(nil, []int{storeId}, nil, nil, nil, nil, "")
ShopName = StoreLists[0].Name
StoreInfoList := new(mtpsapi.GetStoreStatusResultAll)
StoreInfoList, _ = api.MtpsAPI.GetStoreStatus(ShopName)
@@ -1462,7 +1462,7 @@ func SetMTPSStatus(ctx *jxcontext.Context, storeId, courierStatus int) {
//test:
for _, StoreCourierList1 := range StoreCourierList {
diff := false
StoreLists, _ := dao.GetStoreList(db, []int{StoreCourierList1.StoreID}, nil, nil, nil, "")
StoreLists, _ := dao.GetStoreList(db, []int{StoreCourierList1.StoreID}, nil, nil, nil, nil, "")
if StoreLists == nil {
globals.SugarLogger.Debugf("StoreID为:%s,在store表未找到", StoreCourierList1.StoreID)
continue

View File

@@ -227,7 +227,7 @@ func TryAddStoreBossRole4User(ctx *jxcontext.Context, user *model.User) (err err
if user.Type&model.UserTypeStoreBoss != 0 {
userMobile := user.GetMobile()
if userMobile != "" {
if storeList, err := dao.GetStoreList(dao.GetDB(), nil, nil, nil, []string{userMobile}, ""); err == nil && len(storeList) > 0 {
if storeList, err := dao.GetStoreList(dao.GetDB(), nil, nil, nil, nil, []string{userMobile}, ""); err == nil && len(storeList) > 0 {
roleList := make([]*authz.RoleInfo, len(storeList))
for k, v := range storeList {
roleList[k] = autils.NewStoreBossRole(v.ID)