+ TmpGetMyStoreList

This commit is contained in:
gazebo
2019-07-29 13:44:22 +08:00
parent 40d96f3342
commit ee613bfa75
5 changed files with 80 additions and 3 deletions

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/auth2"
"git.rosy.net.cn/jx-callback/business/jxcallback/auth"
"git.rosy.net.cn/jx-callback/business/jxcallback/auth/mobile"
"git.rosy.net.cn/jx-callback/business/jxcallback/auth/weixin"
@@ -65,6 +66,33 @@ func GetSelfInfo(ctx *jxcontext.Context) (storeUserInfo *dao.StoreUserInfo, err
return storeUserInfo, err
}
func getMobileFromCtx(ctx *jxcontext.Context) (mobile string) {
token := ctx.GetToken()
if auth2.IsV2Token(token) {
authInfo, err2 := auth2.GetTokenInfo(token)
if err2 == nil {
if authInfo.TokenType == auth2.TokenTypeNormal {
mobile = authInfo.GetMobile()
}
}
} else {
userInfo, err2 := auth.GetUserInfo(token)
if err2 == nil {
mobile = userInfo.GetAuthID()
}
}
return mobile
}
func GetMyStoreList(ctx *jxcontext.Context) (storeList []*model.Store, err error) {
mobileNum := getMobileFromCtx(ctx)
if mobileNum == "" {
return nil, fmt.Errorf("不能得到用户手机号")
}
storeList, err = dao.GetStoreListByMobile(dao.GetDB(), mobileNum)
return storeList, err
}
func UnbindMobile(ctx *jxcontext.Context, mobile string) (num int64, err error) {
db := dao.GetDB()
num, err = dao.UpdateEntityByKV(db, &legacymodel.WeiXins{}, map[string]interface{}{

View File

@@ -4,7 +4,6 @@ import (
"errors"
"net/http"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/auth2"
"git.rosy.net.cn/jx-callback/business/jxcallback/auth"
"git.rosy.net.cn/jx-callback/business/model"
@@ -57,7 +56,7 @@ func New(notUsed interface{}, token string, w http.ResponseWriter, r *http.Reque
authInfo, err2 := auth2.GetTokenInfo(token)
if err = err2; err == nil {
ctx.userInfo = authInfo
// globals.SugarLogger.Debugf("jxcontext New, V2 authInfo:%s", utils.Format4Output(authInfo, false))
// globals.SugarLogger.Debugf("jxcontext New, V2 authInfo:%s", utils.Format4Output(authInfo, true))
if authInfo.TokenType != auth2.TokenTypeNormal {
err = errors.New("需要正式TOKEN")
}
@@ -65,7 +64,7 @@ func New(notUsed interface{}, token string, w http.ResponseWriter, r *http.Reque
} else {
userInfo, err2 := auth.GetUserInfo(token)
if err = err2; err == nil {
globals.SugarLogger.Debugf("jxcontext New, V1 authInfo:%s", utils.Format4Output(userInfo, false))
// globals.SugarLogger.Debugf("jxcontext New, V1 authInfo:%s", utils.Format4Output(userInfo, true))
ctx.userInfo = userInfo
}
}

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/model/legacymodel"
)
@@ -116,3 +117,30 @@ func GetUserStoreInfo(db *DaoDB, fieldName, fieldValue string) (storeUserInfo *S
}
return storeUserInfo, err
}
func GetStoreListByMobile(db *DaoDB, mobile string) (storeList []*model.Store, err error) {
if mobile != "" {
sql := `
SELECT DISTINCT *
FROM (
SELECT *
FROM store t1
WHERE (t1.market_man_phone = ? OR t1.operator_phone = ?)
UNION DISTINCT
SELECT t1.*
FROM store t1
JOIN weixins t2 ON t2.jxstoreid = t1.id AND t2.parentid = -1
LEFT JOIN weixins t3 ON t3.parentid = t2.id
WHERE (t2.tel = ? OR t3.tel = ?)
) t1
ORDER BY t1.name`
sqlParams := []interface{}{
mobile,
mobile,
mobile,
mobile,
}
err = GetRows(db, &storeList, sql, sqlParams...)
}
return storeList, err
}