- 将微信的备注改为店名相关的信息
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"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"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"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"
|
||||
@@ -15,13 +16,6 @@ import (
|
||||
"github.com/astaxie/beego/orm"
|
||||
)
|
||||
|
||||
type StoreUserInfo struct {
|
||||
legacymodel.WeiXins
|
||||
ParentMobile string `json:"parentMobile"`
|
||||
Members []*legacymodel.WeiXins `orm:"-" json:"members"`
|
||||
MembersStr string `json:"-"`
|
||||
}
|
||||
|
||||
var (
|
||||
LoginTypeFieldMap = map[string]string{
|
||||
mobile.LoginType: "tel",
|
||||
@@ -30,7 +24,7 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func GetStoreUsers(ctx *jxcontext.Context, storeID int) (storeUserInfos []*StoreUserInfo, err error) {
|
||||
func GetStoreUsers(ctx *jxcontext.Context, storeID int) (storeUserInfos []*dao.StoreUserInfo, err error) {
|
||||
sql := `
|
||||
SELECT t1.id, t1.jxstoreid, t1.openid, t1.tel, t1.nickname, t1.parentid, t3.tel parent_mobile,
|
||||
CONCAT("[", GROUP_CONCAT(CONCAT('{"id":', t2.id, ',"parentID":', t2.parentid, ',"tel":"', t2.tel, '","nickname":"', IF(t2.nickname IS NULL, "", t2.nickname), '"}')), "]") members_str
|
||||
@@ -51,61 +45,32 @@ func GetStoreUsers(ctx *jxcontext.Context, storeID int) (storeUserInfos []*Store
|
||||
return storeUserInfos, err
|
||||
}
|
||||
|
||||
func GetUserInfo(ctx *jxcontext.Context, mobile string) (storeUserInfo *StoreUserInfo, err error) {
|
||||
sql := `
|
||||
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.tel = ?
|
||||
GROUP BY 1,2,3,4,5,6,7;
|
||||
`
|
||||
storeUserInfo = new(StoreUserInfo)
|
||||
if err = dao.GetRow(nil, storeUserInfo, sql, mobile); err == nil {
|
||||
if storeUserInfo.MembersStr != "" {
|
||||
err = utils.UnmarshalUseNumber([]byte(storeUserInfo.MembersStr), &storeUserInfo.Members)
|
||||
}
|
||||
}
|
||||
return storeUserInfo, err
|
||||
func GetUserInfo(ctx *jxcontext.Context, mobile string) (storeUserInfo *dao.StoreUserInfo, err error) {
|
||||
return dao.GetUserStoreInfo(dao.GetDB(), "tel", mobile)
|
||||
}
|
||||
|
||||
func GetSelfInfo(ctx *jxcontext.Context) (storeUserInfo *StoreUserInfo, err error) {
|
||||
func GetSelfInfo(ctx *jxcontext.Context) (storeUserInfo *dao.StoreUserInfo, err error) {
|
||||
loginInfo := ctx.GetLoginInfo()
|
||||
if loginInfo == nil {
|
||||
return nil, auth.ErrAPINeedRealLogin
|
||||
}
|
||||
|
||||
fieldName := LoginTypeFieldMap[loginInfo.GetAuthType()]
|
||||
if fieldName == "" {
|
||||
return nil, auth.ErrIllegalLoginType
|
||||
}
|
||||
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.%s = ?
|
||||
GROUP BY 1,2,3,4,5,6,7;
|
||||
`, fieldName)
|
||||
storeUserInfo = new(StoreUserInfo)
|
||||
if err = dao.GetRow(nil, storeUserInfo, sql, loginInfo.GetAuthID()); err == nil || err == orm.ErrNoRows { // todo
|
||||
err = nil
|
||||
if storeUserInfo.MembersStr != "" {
|
||||
err = utils.UnmarshalUseNumber([]byte(storeUserInfo.MembersStr), &storeUserInfo.Members)
|
||||
}
|
||||
}
|
||||
return storeUserInfo, err
|
||||
return dao.GetUserStoreInfo(dao.GetDB(), fieldName, loginInfo.GetAuthID())
|
||||
}
|
||||
|
||||
func UnbindMobile(ctx *jxcontext.Context, mobile string) (num int64, err error) {
|
||||
return dao.UpdateEntityByKV(nil, &legacymodel.WeiXins{}, map[string]interface{}{
|
||||
db := dao.GetDB()
|
||||
num, err = dao.UpdateEntityByKV(db, &legacymodel.WeiXins{}, map[string]interface{}{
|
||||
"JxStoreID": 0,
|
||||
"ParentID": -1,
|
||||
}, map[string]interface{}{
|
||||
"Tel": mobile,
|
||||
})
|
||||
jxutils.HandleUserWXRemark(db, mobile)
|
||||
return num, err
|
||||
}
|
||||
|
||||
func BindMobile2Store(ctx *jxcontext.Context, mobile string, storeID int) (num int64, err error) {
|
||||
@@ -126,6 +91,7 @@ func BindMobile2Store(ctx *jxcontext.Context, mobile string, storeID int) (num i
|
||||
}
|
||||
}
|
||||
}
|
||||
jxutils.HandleUserWXRemark(db, mobile)
|
||||
return num, err
|
||||
}
|
||||
|
||||
@@ -157,6 +123,7 @@ func AddMobile2Mobile(ctx *jxcontext.Context, parentMobile, mobile string) (num
|
||||
err = fmt.Errorf("%s本身是成员", parentMobile)
|
||||
}
|
||||
}
|
||||
jxutils.HandleUserWXRemark(db, mobile)
|
||||
return num, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user