- user man and user store bind.
This commit is contained in:
94
business/jxstore/cms/user.go
Normal file
94
business/jxstore/cms/user.go
Normal file
@@ -0,0 +1,94 @@
|
||||
package cms
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
)
|
||||
|
||||
type StoreUserInfo struct {
|
||||
model.WeiXins
|
||||
Members []*model.WeiXins `orm:"-" json:"members"`
|
||||
MembersStr string `orm:"members_str" json:"-"`
|
||||
}
|
||||
|
||||
func GetStoreUsers(storeID int) (storeUserInfo *StoreUserInfo, err error) {
|
||||
sql := `
|
||||
SELECT t1.id, t1.jxstoreid, t1.openid, t1.tel, t1.nickname, t1.parentid,
|
||||
CONCAT("[", GROUP_CONCAT(CONCAT('{"id":', t2.id, ',"parentID":', t2.parentid, ',"openID":"', IF(t2.openid IS NULL, "", t2.openid), '","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
|
||||
WHERE t1.parentid = -1 AND t1.jxstoreid = ?
|
||||
GROUP BY t1.id, t1.jxstoreid, t1.openid, t1.tel, t1.nickname, t1.parentid;
|
||||
`
|
||||
var storeUserInfos []*StoreUserInfo
|
||||
if err = dao.GetRows(nil, &storeUserInfos, sql, storeID); err == nil {
|
||||
storeUserInfo = storeUserInfos[0]
|
||||
if storeUserInfo.MembersStr != "" {
|
||||
err = utils.UnmarshalUseNumber([]byte(storeUserInfo.MembersStr), &storeUserInfo.Members)
|
||||
}
|
||||
}
|
||||
return storeUserInfo, err
|
||||
}
|
||||
|
||||
func GetUserInfo(mobile string) (storeUserInfo *StoreUserInfo, err error) {
|
||||
sql := `
|
||||
SELECT t1.id, t1.jxstoreid, t1.openid, t1.tel, t1.nickname, t1.parentid,
|
||||
CONCAT("[", GROUP_CONCAT(CONCAT('{"id":', t2.id, ',"openID":"', IF(t2.openid IS NULL, "", t2.openid), '","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
|
||||
WHERE t1.tel = ?
|
||||
GROUP BY t1.id, t1.jxstoreid, t1.openid, t1.tel, t1.nickname, t1.parentid;
|
||||
`
|
||||
var storeUserInfos []*StoreUserInfo
|
||||
if err = dao.GetRows(nil, &storeUserInfos, sql, mobile); err == nil {
|
||||
storeUserInfo = storeUserInfos[0]
|
||||
if storeUserInfo.MembersStr != "" {
|
||||
err = utils.UnmarshalUseNumber([]byte(storeUserInfo.MembersStr), &storeUserInfo.Members)
|
||||
}
|
||||
}
|
||||
return storeUserInfo, err
|
||||
}
|
||||
|
||||
func UnbindMobile(mobile string) (num int64, err error) {
|
||||
return dao.UpdateEntityByKV(nil, &model.WeiXins{}, map[string]interface{}{
|
||||
"Jxstoreid": nil,
|
||||
"Parentid": -1,
|
||||
}, map[string]interface{}{
|
||||
"Tel": mobile,
|
||||
})
|
||||
}
|
||||
|
||||
func BindMobile2Store(mobile string, storeID int) (num int64, err error) {
|
||||
return dao.UpdateEntityByKV(nil, &model.WeiXins{}, map[string]interface{}{
|
||||
"Jxstoreid": storeID,
|
||||
"Parentid": -1,
|
||||
}, map[string]interface{}{
|
||||
"Tel": mobile,
|
||||
})
|
||||
}
|
||||
|
||||
func AddMobile2Mobile(parentMobile, mobile string) (num int64, err error) {
|
||||
db := dao.GetDB()
|
||||
parentUser := &model.WeiXins{}
|
||||
parentUser.Tel = parentMobile
|
||||
if err = dao.GetEntity(db, parentUser, "Tel"); err == nil {
|
||||
if parentUser.ParentID == -1 {
|
||||
globals.SugarLogger.Debug(parentUser)
|
||||
num, err = dao.UpdateEntityByKV(db, &model.WeiXins{}, utils.Params2Map("ParentID", parentUser.ID), utils.Params2Map("Tel", mobile))
|
||||
} else {
|
||||
err = fmt.Errorf("%s本身是成员", parentMobile)
|
||||
}
|
||||
}
|
||||
return num, err
|
||||
}
|
||||
|
||||
func ChangeMobile(curMobile, expectedMobile string) (num int64, err error) {
|
||||
return dao.UpdateEntityByKV(nil, &model.WeiXins{}, map[string]interface{}{
|
||||
"Tel": expectedMobile,
|
||||
}, map[string]interface{}{
|
||||
"Tel": curMobile,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user