diff --git a/business/auth2/auth2.go b/business/auth2/auth2.go index eeed650c3..83875e419 100644 --- a/business/auth2/auth2.go +++ b/business/auth2/auth2.go @@ -5,6 +5,7 @@ import ( "encoding/base64" "errors" "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" + "git.rosy.net.cn/jx-callback/business/partner" "regexp" "strings" "time" @@ -499,10 +500,43 @@ func DeletedTokenInfoWithoutParam(authInfo *AuthInfo) (err error) { type UserInfo struct { model.User - WxInfo string `json:"wxInfo"` - BrandMaps string `json:"brandMaps"` + WxInfo string `json:"wxInfo"` + BrandMaps []*BrandMap `json:"brandMaps"` +} + +type BrandMap struct { + BrandID int `orm:"column(brand_id)" json:"brandID"` + Name string `json:"name"` + ManageCount int `json:"managerCount"` + Balance int `json:"balance"` } func GetUserInfo(ctx *jxcontext.Context) (userInfo *UserInfo, err error) { - return nil, err + var ( + db = dao.GetDB() + ) + sql := ` + SELECT a.*, b.detail_data wx_info + FROM user a + LEFT JOIN auth_bind b ON a.user_id = b.user_id AND b.type_id = ? AND b.type = ? + WHERE a.user_id = ? + ` + sqlParams := []interface{}{"wx2bb99eb5d2c9b82c", "weixinsns", ctx.GetUserID()} + if err = dao.GetRow(db, &userInfo, sql, sqlParams); err == nil && userInfo != nil { + if brandUsers, _ := dao.GetBrandUser(db, 0, ctx.GetUserID()); len(brandUsers) > 0 { + for _, v := range brandUsers { + brands, _ := dao.GetBrands(db, "", v.BrandID) + balance, _ := partner.CurStoreAcctManager.GetBrandBalance(v.BrandID) + brandMap := &BrandMap{ + BrandID: v.BrandID, + Name: brands[0].Name, + Balance: balance, + } + stores, _ := dao.GetStoreList(db, nil, nil, nil, []int{v.BrandID}, nil, "") + brandMap.ManageCount = len(stores) + userInfo.BrandMaps = append(userInfo.BrandMaps, brandMap) + } + } + } + return userInfo, err }