- fix bug in cms.GetSelfInfo
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/jxcallback/auth/mobile"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/jxcallback/auth/weixin"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||||
@@ -19,6 +21,14 @@ type StoreUserInfo struct {
|
|||||||
MembersStr string `json:"-"`
|
MembersStr string `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
LoginTypeFieldMap = map[string]string{
|
||||||
|
mobile.LoginType: "tel",
|
||||||
|
weixin.LoginType: "openid",
|
||||||
|
weixin.LoginTypeMiniProgram: "openid_mini",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
func GetStoreUsers(ctx *jxcontext.Context, storeID int) (storeUserInfos []*StoreUserInfo, err error) {
|
func GetStoreUsers(ctx *jxcontext.Context, storeID int) (storeUserInfos []*StoreUserInfo, err error) {
|
||||||
sql := `
|
sql := `
|
||||||
SELECT t1.id, t1.jxstoreid, t1.openid, t1.tel, t1.nickname, t1.parentid, t3.tel parent_mobile,
|
SELECT t1.id, t1.jxstoreid, t1.openid, t1.tel, t1.nickname, t1.parentid, t3.tel parent_mobile,
|
||||||
@@ -59,18 +69,27 @@ func GetUserInfo(ctx *jxcontext.Context, mobile string) (storeUserInfo *StoreUse
|
|||||||
return storeUserInfo, err
|
return storeUserInfo, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetSelfInfo(ctx *jxcontext.Context, openID string) (storeUserInfo *StoreUserInfo, err error) {
|
func GetSelfInfo(ctx *jxcontext.Context) (storeUserInfo *StoreUserInfo, err error) {
|
||||||
sql := `
|
loginInfo := ctx.GetLoginInfo()
|
||||||
|
if loginInfo == nil {
|
||||||
|
return nil, fmt.Errorf("此API要求真正登录")
|
||||||
|
}
|
||||||
|
|
||||||
|
fieldName := LoginTypeFieldMap[loginInfo.LoginType]
|
||||||
|
if fieldName == "" {
|
||||||
|
return nil, fmt.Errorf("不支持的登录类型")
|
||||||
|
}
|
||||||
|
sql := fmt.Sprintf(`
|
||||||
SELECT t1.id, IF(t3.id IS NULL, t1.jxstoreid, t3.jxstoreid) jxstoreid, t1.openid, t1.tel, t1.nickname, t1.parentid, t3.tel parent_mobile,
|
SELECT t1.id, IF(t3.id IS NULL, t1.jxstoreid, t3.jxstoreid) jxstoreid, t1.openid, t1.tel, t1.nickname, t1.parentid, t3.tel parent_mobile,
|
||||||
CONCAT("[", GROUP_CONCAT(CONCAT('{"id":', t2.id, ',"tel":"', t2.tel, '","nickname":"', IF(t2.nickname IS NULL, "", t2.nickname), '"}')), "]") members_str
|
CONCAT("[", GROUP_CONCAT(CONCAT('{"id":', t2.id, ',"tel":"', t2.tel, '","nickname":"', IF(t2.nickname IS NULL, "", t2.nickname), '"}')), "]") members_str
|
||||||
FROM weixins t1
|
FROM weixins t1
|
||||||
LEFT JOIN weixins t2 ON t2.parentid = t1.id
|
LEFT JOIN weixins t2 ON t2.parentid = t1.id
|
||||||
LEFT JOIN weixins t3 ON t1.parentid = t3.id
|
LEFT JOIN weixins t3 ON t1.parentid = t3.id
|
||||||
WHERE t1.openid = ?
|
WHERE t1.%s = ?
|
||||||
GROUP BY 1,2,3,4,5,6,7;
|
GROUP BY 1,2,3,4,5,6,7;
|
||||||
`
|
`, fieldName)
|
||||||
storeUserInfo = new(StoreUserInfo)
|
storeUserInfo = new(StoreUserInfo)
|
||||||
if err = dao.GetRow(nil, storeUserInfo, sql, openID); err == nil || err == orm.ErrNoRows { // todo
|
if err = dao.GetRow(nil, storeUserInfo, sql, loginInfo.ID); err == nil || err == orm.ErrNoRows { // todo
|
||||||
err = nil
|
err = nil
|
||||||
if storeUserInfo.MembersStr != "" {
|
if storeUserInfo.MembersStr != "" {
|
||||||
err = utils.UnmarshalUseNumber([]byte(storeUserInfo.MembersStr), &storeUserInfo.Members)
|
err = utils.UnmarshalUseNumber([]byte(storeUserInfo.MembersStr), &storeUserInfo.Members)
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.rosy.net.cn/jx-callback/business/jxcallback/auth"
|
|
||||||
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
)
|
)
|
||||||
@@ -46,10 +45,7 @@ func (c *UserController) TmpGetUserInfo() {
|
|||||||
// @router /TmpGetSelfInfo [get]
|
// @router /TmpGetSelfInfo [get]
|
||||||
func (c *UserController) TmpGetSelfInfo() {
|
func (c *UserController) TmpGetSelfInfo() {
|
||||||
c.callTmpGetSelfInfo(func(params *tUserTmpGetSelfInfoParams) (retVal interface{}, errCode string, err error) {
|
c.callTmpGetSelfInfo(func(params *tUserTmpGetSelfInfoParams) (retVal interface{}, errCode string, err error) {
|
||||||
tokenInfo, err2 := auth.GetUserInfo(params.Token)
|
retVal, err = cms.GetSelfInfo(params.Ctx)
|
||||||
if err = err2; err == nil {
|
|
||||||
retVal, err = cms.GetSelfInfo(params.Ctx, tokenInfo.ID)
|
|
||||||
}
|
|
||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user