- 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,
|
||||
})
|
||||
}
|
||||
@@ -187,3 +187,17 @@ func DeleteEntity(db *DaoDB, item interface{}, conditions map[string]interface{}
|
||||
}, reflect.TypeOf(item).Name())
|
||||
return num, err
|
||||
}
|
||||
|
||||
func UpdateBySQL(db *DaoDB, sql string, params ...interface{}) (num int64, err error) {
|
||||
if db == nil {
|
||||
db = GetDB()
|
||||
}
|
||||
err = utils.CallFuncLogError(func() error {
|
||||
result, err2 := db.db.Raw(sql, params...).Exec()
|
||||
if err2 == nil {
|
||||
num, _ = result.RowsAffected()
|
||||
}
|
||||
return err2
|
||||
}, sql)
|
||||
return num, err
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package model
|
||||
|
||||
type WeiXins struct {
|
||||
ID int `orm:"column(id)"`
|
||||
JxStoreID int `orm:"column(jxstoreid)"`
|
||||
OpenID string `orm:"column(openid);size(70);index"`
|
||||
Tel string `orm:"size(15);index"`
|
||||
ParentID int `orm:"column(parentid)"`
|
||||
NickName string `orm:"column(nickname);size(30)"`
|
||||
ID int `orm:"column(id)" json:"id"`
|
||||
JxStoreID int `orm:"column(jxstoreid)" json:"storeID"`
|
||||
OpenID string `orm:"column(openid);size(70);index" json:"openID"`
|
||||
Tel string `orm:"size(15);index" json:"tel"`
|
||||
ParentID int `orm:"column(parentid)" json:"parentID"`
|
||||
NickName string `orm:"column(nickname);size(30)" json:"nickname"`
|
||||
}
|
||||
|
||||
func (*WeiXins) TableName() string {
|
||||
|
||||
97
controllers/cms_user.go
Normal file
97
controllers/cms_user.go
Normal file
@@ -0,0 +1,97 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
type UserController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
// @Title 得到门店用户信息
|
||||
// @Description 得到门店用户信息
|
||||
// @Param token header string true "认证token"
|
||||
// @Param storeID query int true "门店号"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /TmpGetStoreUsers [get]
|
||||
func (c *UserController) TmpGetStoreUsers() {
|
||||
c.callTmpGetStoreUsers(func(params *tUserTmpGetStoreUsersParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = cms.GetStoreUsers(params.StoreID)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 得到用户门店及成员信息
|
||||
// @Description 得到用户门店及成员信息
|
||||
// @Param token header string true "认证token"
|
||||
// @Param mobile query string true "手机号"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /TmpGetUserInfo [get]
|
||||
func (c *UserController) TmpGetUserInfo() {
|
||||
c.callTmpGetUserInfo(func(params *tUserTmpGetUserInfoParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = cms.GetUserInfo(params.Mobile)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 取消手机门店绑定
|
||||
// @Description 此操作会将此手机关联的所有门店信息清除(取消组长,取消自己为他组组员),如果此人为组长,取消后组员也相应会取消门店绑定(但组员的成员关系还在)
|
||||
// @Param token header string true "认证token"
|
||||
// @Param mobile formData string true "手机号"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /TmpUnbindMobile [put]
|
||||
func (c *UserController) TmpUnbindMobile() {
|
||||
c.callTmpUnbindMobile(func(params *tUserTmpUnbindMobileParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = cms.UnbindMobile(params.Mobile)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 手机门店绑定
|
||||
// @Description 此操作会将此手机设置成为相应门的组长,如果之前有组员关系,则此操作后,组员也会自动与门店绑定
|
||||
// @Param token header string true "认证token"
|
||||
// @Param mobile formData string true "手机号"
|
||||
// @Param storeID formData int true "门店ID"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /TmpBindMobile2Store [put]
|
||||
func (c *UserController) TmpBindMobile2Store() {
|
||||
c.callTmpBindMobile2Store(func(params *tUserTmpBindMobile2StoreParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = cms.BindMobile2Store(params.Mobile, params.StoreID)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 将手机加到另一手机上
|
||||
// @Description 将手机加到另一手机上
|
||||
// @Param token header string true "认证token"
|
||||
// @Param parentMobile formData string true "父手机号"
|
||||
// @Param mobile formData string true "手机号"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /TmpAddMobile2Mobile [put]
|
||||
func (c *UserController) TmpAddMobile2Mobile() {
|
||||
c.callTmpAddMobile2Mobile(func(params *tUserTmpAddMobile2MobileParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = cms.AddMobile2Mobile(params.ParentMobile, params.Mobile)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 变更手机号
|
||||
// @Description 变更手机号
|
||||
// @Param token header string true "认证token"
|
||||
// @Param curMobile formData string true "当前手机号"
|
||||
// @Param expectedMobile formData string true "手机号"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /TmpChangeMobile [put]
|
||||
func (c *UserController) TmpChangeMobile() {
|
||||
c.callTmpChangeMobile(func(params *tUserTmpChangeMobileParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = cms.ChangeMobile(params.CurMobile, params.ExpectedMobile)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
@@ -303,4 +303,52 @@ func init() {
|
||||
MethodParams: param.Make(),
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"],
|
||||
beego.ControllerComments{
|
||||
Method: "TmpAddMobile2Mobile",
|
||||
Router: `/TmpAddMobile2Mobile`,
|
||||
AllowHTTPMethods: []string{"put"},
|
||||
MethodParams: param.Make(),
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"],
|
||||
beego.ControllerComments{
|
||||
Method: "TmpBindMobile2Store",
|
||||
Router: `/TmpBindMobile2Store`,
|
||||
AllowHTTPMethods: []string{"put"},
|
||||
MethodParams: param.Make(),
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"],
|
||||
beego.ControllerComments{
|
||||
Method: "TmpChangeMobile",
|
||||
Router: `/TmpChangeMobile`,
|
||||
AllowHTTPMethods: []string{"put"},
|
||||
MethodParams: param.Make(),
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"],
|
||||
beego.ControllerComments{
|
||||
Method: "TmpGetStoreUsers",
|
||||
Router: `/TmpGetStoreUsers`,
|
||||
AllowHTTPMethods: []string{"get"},
|
||||
MethodParams: param.Make(),
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"],
|
||||
beego.ControllerComments{
|
||||
Method: "TmpGetUserInfo",
|
||||
Router: `/TmpGetUserInfo`,
|
||||
AllowHTTPMethods: []string{"get"},
|
||||
MethodParams: param.Make(),
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"],
|
||||
beego.ControllerComments{
|
||||
Method: "TmpUnbindMobile",
|
||||
Router: `/TmpUnbindMobile`,
|
||||
AllowHTTPMethods: []string{"put"},
|
||||
MethodParams: param.Make(),
|
||||
Params: nil})
|
||||
|
||||
}
|
||||
|
||||
@@ -41,6 +41,11 @@ func init() {
|
||||
&controllers.CmsController{},
|
||||
),
|
||||
),
|
||||
beego.NSNamespace("/user",
|
||||
beego.NSInclude(
|
||||
&controllers.UserController{},
|
||||
),
|
||||
),
|
||||
)
|
||||
beego.AddNamespace(ns)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user