- fix bug in cms.GetSelfInfo

This commit is contained in:
gazebo
2018-12-28 11:43:50 +08:00
parent 74b29acd4e
commit 0e84d152c0
2 changed files with 25 additions and 10 deletions

View File

@@ -4,6 +4,8 @@ import (
"fmt"
"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/model"
"git.rosy.net.cn/jx-callback/business/model/dao"
@@ -19,6 +21,14 @@ type StoreUserInfo struct {
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) {
sql := `
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
}
func GetSelfInfo(ctx *jxcontext.Context, openID string) (storeUserInfo *StoreUserInfo, err error) {
sql := `
func GetSelfInfo(ctx *jxcontext.Context) (storeUserInfo *StoreUserInfo, err error) {
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,
CONCAT("[", GROUP_CONCAT(CONCAT('{"id":', t2.id, ',"tel":"', t2.tel, '","nickname":"', IF(t2.nickname IS NULL, "", t2.nickname), '"}')), "]") members_str
FROM weixins t1
LEFT JOIN weixins t2 ON t2.parentid = t1.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;
`
`, fieldName)
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
if storeUserInfo.MembersStr != "" {
err = utils.UnmarshalUseNumber([]byte(storeUserInfo.MembersStr), &storeUserInfo.Members)

View File

@@ -1,7 +1,6 @@
package controllers
import (
"git.rosy.net.cn/jx-callback/business/jxcallback/auth"
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
"github.com/astaxie/beego"
)
@@ -46,10 +45,7 @@ func (c *UserController) TmpGetUserInfo() {
// @router /TmpGetSelfInfo [get]
func (c *UserController) TmpGetSelfInfo() {
c.callTmpGetSelfInfo(func(params *tUserTmpGetSelfInfoParams) (retVal interface{}, errCode string, err error) {
tokenInfo, err2 := auth.GetUserInfo(params.Token)
if err = err2; err == nil {
retVal, err = cms.GetSelfInfo(params.Ctx, tokenInfo.ID)
}
retVal, err = cms.GetSelfInfo(params.Ctx)
return retVal, "", err
})
}