- auto create weixin user.
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"github.com/astaxie/beego/orm"
|
||||
)
|
||||
|
||||
type StoreUserInfo struct {
|
||||
@@ -52,20 +53,26 @@ func GetUserInfo(mobile string) (storeUserInfo *StoreUserInfo, err error) {
|
||||
|
||||
func UnbindMobile(mobile string) (num int64, err error) {
|
||||
return dao.UpdateEntityByKV(nil, &model.WeiXins{}, map[string]interface{}{
|
||||
"Jxstoreid": nil,
|
||||
"Parentid": -1,
|
||||
"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,
|
||||
})
|
||||
db := dao.GetDB()
|
||||
user, err2 := verifyMobileIsBlank(db, mobile)
|
||||
if err = err2; err == nil || err == orm.ErrNoRows {
|
||||
user.JxStoreID = storeID
|
||||
if err == nil {
|
||||
num, err = dao.UpdateEntity(db, user, "JxStoreID")
|
||||
} else {
|
||||
err = dao.CreateEntity(db, user)
|
||||
num = 1
|
||||
}
|
||||
}
|
||||
return num, err
|
||||
}
|
||||
|
||||
func AddMobile2Mobile(parentMobile, mobile string) (num int64, err error) {
|
||||
@@ -75,7 +82,16 @@ func AddMobile2Mobile(parentMobile, mobile string) (num int64, err error) {
|
||||
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))
|
||||
user, err2 := verifyMobileIsBlank(db, mobile)
|
||||
if err = err2; err == nil || err == orm.ErrNoRows {
|
||||
user.ParentID = parentUser.ID
|
||||
if err == nil {
|
||||
num, err = dao.UpdateEntity(db, user, "ParentID")
|
||||
} else {
|
||||
err = dao.CreateEntity(db, user)
|
||||
num = 1
|
||||
}
|
||||
}
|
||||
} else {
|
||||
err = fmt.Errorf("%s本身是成员", parentMobile)
|
||||
}
|
||||
@@ -90,3 +106,17 @@ func ChangeMobile(curMobile, expectedMobile string) (num int64, err error) {
|
||||
"Tel": curMobile,
|
||||
})
|
||||
}
|
||||
|
||||
func verifyMobileIsBlank(db *dao.DaoDB, mobile string) (user *model.WeiXins, err error) {
|
||||
user = &model.WeiXins{
|
||||
Tel: mobile,
|
||||
}
|
||||
if err = dao.GetEntity(db, user, "Tel"); err == nil {
|
||||
if user.ParentID != -1 && user.ParentID != 0 {
|
||||
err = fmt.Errorf("%s已经是小组成员", mobile)
|
||||
} else if user.JxStoreID != 0 {
|
||||
err = fmt.Errorf("%s本身已经是%d的组长", mobile, user.JxStoreID)
|
||||
}
|
||||
}
|
||||
return user, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user