- 创建或更新京西门店,注册用户时,自动根据门店的tel1,tel2添加门店老板角色
This commit is contained in:
@@ -273,7 +273,7 @@ func DeleteConfig(ctx *jxcontext.Context, key, configType string) (err error) {
|
||||
}
|
||||
}
|
||||
errList.AddErr(err)
|
||||
storeList, err2 := dao.GetStoreList4Role(db, key)
|
||||
storeList, err2 := dao.GetStoreList(db, nil, nil, key)
|
||||
if err = err2; err == nil && len(storeList) > 0 {
|
||||
storeIDs := make([]int, len(storeList))
|
||||
for k, v := range storeList {
|
||||
|
||||
@@ -8,10 +8,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/authz/autils"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/auth2"
|
||||
"git.rosy.net.cn/jx-callback/business/authz"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/autonavi"
|
||||
"git.rosy.net.cn/baseapi/platformapi/baidunavi"
|
||||
@@ -700,8 +697,8 @@ func UpdateStore(ctx *jxcontext.Context, storeID int, payload map[string]interfa
|
||||
dao.Commit(db)
|
||||
globals.SugarLogger.Debugf("UpdateStore track:%s, before call SyncStore", ctx.GetTrackInfo())
|
||||
_, err = CurVendorSync.SyncStore(ctx, db, -1, store.ID, false, userName)
|
||||
if valid["tel1"] != nil {
|
||||
AddStoreBossByMoble(ctx, utils.Interface2String(valid["tel1"]), storeID)
|
||||
if valid["tel1"] != nil || valid["tel2"] != nil {
|
||||
TryAddStoreBossRole4StoreByMobile(ctx, store.ID, []string{utils.Interface2String(valid["tel1"]), utils.Interface2String(valid["tel2"])})
|
||||
}
|
||||
if syncStatus&model.SyncFlagStoreAddress != 0 || valid["tel1"] != nil || valid["payeeName"] != nil {
|
||||
updateCourierStores(ctx, storeID)
|
||||
@@ -797,7 +794,7 @@ func CreateStore(ctx *jxcontext.Context, storeExt *StoreExt, userName string) (i
|
||||
store.ID = existingID
|
||||
if err = dao.CreateEntity(db, store); err == nil {
|
||||
UpdateOrCreateCourierStores(ctx, store.ID, false, false, false)
|
||||
AddStoreBossByMoble(ctx, storeExt.Tel1, storeExt.ID)
|
||||
TryAddStoreBossRole4StoreByMobile(ctx, storeExt.ID, []string{storeExt.Tel1, storeExt.Tel2})
|
||||
return store.ID, err
|
||||
}
|
||||
return 0, err
|
||||
@@ -1791,24 +1788,3 @@ func SyncStoresQualify(ctx *jxcontext.Context, storeIDs []int, isAsync, isContin
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func AddStoreBossByMoble(ctx *jxcontext.Context, mobile string, storeID int) (num int64, err error) {
|
||||
if mobile != "" {
|
||||
if globals.EnableWXAuth2 {
|
||||
db := dao.GetDB()
|
||||
userList, _, err2 := dao.GetUsers(db, 0, "", nil, "", mobile, 0, 0)
|
||||
globals.SugarLogger.Debugf("AddStoreBossByMoble mobile:%s, userList:%s", mobile, utils.Format4Output(userList, true))
|
||||
if err = err2; err == nil && len(userList) > 0 {
|
||||
if err = AddRoles4User(ctx, userList[0].GetID(), []*authz.RoleInfo{
|
||||
autils.NewRole(authz.StoreRoleBoss, storeID),
|
||||
}); err == nil {
|
||||
num = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
if !globals.DisableWXAuth1 {
|
||||
num, err = BindMobile2Store(ctx, mobile, storeID)
|
||||
}
|
||||
}
|
||||
return num, err
|
||||
}
|
||||
|
||||
@@ -114,6 +114,7 @@ func RegisterUserWithMobile(ctx *jxcontext.Context, user *model.User, mobileVeri
|
||||
user.Type |= model.UserTypeStoreBoss
|
||||
}
|
||||
if err = CreateUser(user, utils.LimitUTF8StringLen(ctx.GetRealRemoteIP()+","+inAuthInfo.GetAuthID(), 32)); err == nil {
|
||||
TryAddStoreBossRole4User(ctx, user)
|
||||
if outAuthInfo, err = auth2.BindUser(mobileAuth, user); err == nil && inAuthInfo != nil {
|
||||
err = auth2.AddAuthBind(&outAuthInfo.UserBasic, inAuthInfo)
|
||||
}
|
||||
@@ -124,6 +125,40 @@ func RegisterUserWithMobile(ctx *jxcontext.Context, user *model.User, mobileVeri
|
||||
return outAuthInfo, err
|
||||
}
|
||||
|
||||
func TryAddStoreBossRole4User(ctx *jxcontext.Context, user *model.User) (err error) {
|
||||
if user.Type&model.UserTypeStoreBoss != 0 {
|
||||
userMobile := user.GetMobile()
|
||||
if userMobile != "" {
|
||||
if storeList, err := dao.GetStoreList(dao.GetDB(), nil, []string{userMobile}, ""); err == nil && len(storeList) > 0 {
|
||||
roleList := make([]*authz.RoleInfo, len(storeList))
|
||||
for k, v := range storeList {
|
||||
roleList[k] = autils.NewRole(authz.StoreRoleBoss, v.ID)
|
||||
}
|
||||
err = AddRoles4User(ctx, user.GetID(), roleList)
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func TryAddStoreBossRole4StoreByMobile(ctx *jxcontext.Context, storeID int, mobileList []string) (err error) {
|
||||
if storeID > 0 {
|
||||
var userIDs []string
|
||||
for _, v := range mobileList {
|
||||
if v != "" {
|
||||
if userList, _, err := dao.GetUsers(dao.GetDB(), model.UserTypeStoreBoss, "", nil, "", v, 0, -1); err == nil && len(userList) > 0 {
|
||||
userIDs = append(userIDs, userList[0].GetID())
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(userIDs) > 0 {
|
||||
role := autils.NewRole(authz.StoreRoleBoss, storeID)
|
||||
err = AddUsers4Role(ctx, role, userIDs)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func HandleOrder4Consignee(order *model.GoodsOrder) (err error) {
|
||||
var user *model.User
|
||||
authType := jxutils.GetAuthType4Vendor(order.VendorID)
|
||||
|
||||
@@ -445,16 +445,25 @@ func GetOpenedStoreCouriersByStoreID(db *DaoDB, storeID, vendorID int) (storeMap
|
||||
return storeMaps, nil
|
||||
}
|
||||
|
||||
func GetStoreList4Role(db *DaoDB, shortRoleName string) (storeList []*model.Store, err error) {
|
||||
func GetStoreList(db *DaoDB, idList []int, mobileList []string, shortRoleName string) (storeList []*model.Store, err error) {
|
||||
sql := `
|
||||
SELECT t1.*
|
||||
FROM store t1
|
||||
WHERE t1.deleted_at = ? AND (t1.market_man_role = ? OR t1.operator_role = ? OR t1.operator_role2 = ?)`
|
||||
WHERE t1.deleted_at = ?`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
shortRoleName,
|
||||
shortRoleName,
|
||||
shortRoleName,
|
||||
}
|
||||
if len(idList) > 0 {
|
||||
sql += " AND t1.id IN (" + GenQuestionMarks(len(idList)) + ")"
|
||||
sqlParams = append(sqlParams, idList)
|
||||
}
|
||||
if len(mobileList) > 0 {
|
||||
sql += " AND (t1.tel1 IN (" + GenQuestionMarks(len(mobileList)) + ") OR t1.tel2 IN (" + GenQuestionMarks(len(mobileList)) + ")"
|
||||
sqlParams = append(sqlParams, mobileList, mobileList)
|
||||
}
|
||||
if shortRoleName != "" {
|
||||
sql += " AND (t1.market_man_role = ? OR t1.operator_role = ? OR t1.operator_role2 = ?)"
|
||||
sqlParams = append(sqlParams, shortRoleName, shortRoleName, shortRoleName)
|
||||
}
|
||||
err = GetRows(db, &storeList, sql, sqlParams...)
|
||||
return storeList, err
|
||||
|
||||
@@ -32,7 +32,7 @@ func TestFormalizeStoreStatus(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetStoreList4Role(t *testing.T) {
|
||||
storeList, err := GetStoreList4Role(GetDB(), "NiuBi")
|
||||
storeList, err := GetStoreList(GetDB(), "NiuBi")
|
||||
t.Log(utils.Format4Output(storeList, false))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
Reference in New Issue
Block a user