222 lines
9.1 KiB
Go
222 lines
9.1 KiB
Go
package controllers
|
||
|
||
import (
|
||
"git.rosy.net.cn/jx-callback/business/auth2"
|
||
"git.rosy.net.cn/jx-callback/business/authz"
|
||
"git.rosy.net.cn/jx-callback/business/authz/autils"
|
||
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||
"git.rosy.net.cn/jx-callback/business/model"
|
||
"github.com/astaxie/beego"
|
||
)
|
||
|
||
type User2Controller struct {
|
||
beego.Controller
|
||
}
|
||
|
||
// @Title 用户注册
|
||
// @Description 用户注册
|
||
// @Param payload formData string true "json数据,User对象(手机号必填)"
|
||
// @Param mobileVerifyCode formData string true "手机验证码(通过auth2.SendVerifyCode获得)"
|
||
// @Param authToken formData string false "之前通过login得到的认证TOKEN(可以为空)"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /RegisterUser [post]
|
||
func (c *User2Controller) RegisterUser() {
|
||
c.callRegisterUser(func(params *tUser2RegisterUserParams) (retVal interface{}, errCode string, err error) {
|
||
var (
|
||
user model.User
|
||
inAuthInfo *auth2.AuthInfo
|
||
)
|
||
if params.AuthToken != "" {
|
||
inAuthInfo, err = auth2.GetTokenInfo(params.AuthToken)
|
||
}
|
||
if err == nil {
|
||
if err = jxutils.Strings2Objs(params.Payload, &user); err == nil {
|
||
user.Type = 0
|
||
retVal, err = cms.RegisterUserWithMobile(params.Ctx, &user, params.MobileVerifyCode, inAuthInfo)
|
||
}
|
||
}
|
||
return retVal, errCode, err
|
||
})
|
||
}
|
||
|
||
// @Title 得到用户已经成功绑定的认证信息
|
||
// @Description 得到用户已经成功绑定的认证信息
|
||
// @Param token header string true "认证token"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /GetBindAuthInfo [get]
|
||
func (c *User2Controller) GetBindAuthInfo() {
|
||
c.callGetBindAuthInfo(func(params *tUser2GetBindAuthInfoParams) (retVal interface{}, errCode string, err error) {
|
||
retVal, err = cms.GetUserBindAuthInfo(params.Ctx)
|
||
return retVal, "", err
|
||
})
|
||
}
|
||
|
||
// @Title 得到用户列表
|
||
// @Description 得到用户列表
|
||
// @Param token header string true "认证token"
|
||
// @Param userType query int true "用户类型(0表示全部)"
|
||
// @Param keyword query string faslse "关键字,可以部分匹配"
|
||
// @Param userIDs query string faslse "用户id列表"
|
||
// @Param userID2 query string faslse "用户id2,必须全匹配(外部唯一标识)"
|
||
// @Param mobile query string faslse "用户手机,必须全匹配"
|
||
// @Param offset query int false "门店列表起始序号(以0开始,缺省为0)"
|
||
// @Param pageSize query int false "门店列表页大小(缺省为50,-1表示全部)"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /GetUsers [get]
|
||
func (c *User2Controller) GetUsers() {
|
||
c.callGetUsers(func(params *tUser2GetUsersParams) (retVal interface{}, errCode string, err error) {
|
||
var userIDs []string
|
||
if err = jxutils.Strings2Objs(params.UserIDs, &userIDs); err == nil {
|
||
retVal, err = cms.GetUsers(params.Ctx, params.UserType, params.Keyword, userIDs, params.UserID2, params.Mobile, params.Offset, params.PageSize)
|
||
}
|
||
return retVal, "", err
|
||
})
|
||
}
|
||
|
||
// @Title 得到用户自己的门店列表
|
||
// @Description 得到用户自己的门店列表
|
||
// @Param token header string true "认证token"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /GetMyStoreList [get]
|
||
func (c *User2Controller) GetMyStoreList() {
|
||
c.callGetMyStoreList(func(params *tUser2GetMyStoreListParams) (retVal interface{}, errCode string, err error) {
|
||
retVal, errCode, err = cms.GetMyStoreListNew(params.Ctx)
|
||
return retVal, errCode, err
|
||
})
|
||
}
|
||
|
||
// @Title 得到可用的门店角色列表
|
||
// @Description 得到可用的门店角色列表
|
||
// @Param token header string true "认证token"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /GetStoreRoleList [get]
|
||
func (c *User2Controller) GetStoreRoleList() {
|
||
c.callGetStoreRoleList(func(params *tUser2GetStoreRoleListParams) (retVal interface{}, errCode string, err error) {
|
||
retVal, err = cms.GetStoreRoleList(params.Ctx)
|
||
return retVal, "", err
|
||
})
|
||
}
|
||
|
||
// @Title 得到用户所具有的角色列表
|
||
// @Description 得到用户所具有的角色列表
|
||
// @Param token header string true "认证token"
|
||
// @Param userID query string true "用户i"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /GetUserRoleList [get]
|
||
func (c *User2Controller) GetUserRoleList() {
|
||
c.callGetUserRoleList(func(params *tUser2GetUserRoleListParams) (retVal interface{}, errCode string, err error) {
|
||
retVal, err = cms.GetUserRoleList(params.Ctx, params.UserID)
|
||
return retVal, "", err
|
||
})
|
||
}
|
||
|
||
// @Title 得到角色包括的用户列表
|
||
// @Description 得到角色包括的用户列表
|
||
// @Param token header string true "认证token"
|
||
// @Param roleName query string true "角色名"
|
||
// @Param storeID query int false "门店ID(如果是全局角色不用填)"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /GetRoleUserList [get]
|
||
func (c *User2Controller) GetRoleUserList() {
|
||
c.callGetRoleUserList(func(params *tUser2GetRoleUserListParams) (retVal interface{}, errCode string, err error) {
|
||
retVal, err = cms.GetRoleUserList(params.Ctx, autils.NewRole(params.RoleName, params.StoreID))
|
||
return retVal, "", err
|
||
})
|
||
}
|
||
|
||
// @Title 给指定用户添加角色列表
|
||
// @Description 给指定用户添加角色列表
|
||
// @Param token header string true "认证token"
|
||
// @Param userID formData string true "用户ID"
|
||
// @Param roleList formData string true "角色列表"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /AddRoles4User [post]
|
||
func (c *User2Controller) AddRoles4User() {
|
||
c.callAddRoles4User(func(params *tUser2AddRoles4UserParams) (retVal interface{}, errCode string, err error) {
|
||
var roleList []*authz.RoleInfo
|
||
if err = jxutils.Strings2Objs(params.RoleList, &roleList); err == nil {
|
||
err = cms.AddRoles4User(params.Ctx, params.UserID, roleList)
|
||
}
|
||
return retVal, "", err
|
||
})
|
||
}
|
||
|
||
// @Title 给指定用户删除角色列表
|
||
// @Description 给指定用户删除角色列表
|
||
// @Param token header string true "认证token"
|
||
// @Param userID query string true "用户ID"
|
||
// @Param roleList query string true "角色列表"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /DeleteRoles4User [delete]
|
||
func (c *User2Controller) DeleteRoles4User() {
|
||
c.callDeleteRoles4User(func(params *tUser2DeleteRoles4UserParams) (retVal interface{}, errCode string, err error) {
|
||
var roleList []*authz.RoleInfo
|
||
if err = jxutils.Strings2Objs(params.RoleList, &roleList); err == nil {
|
||
err = cms.DeleteRoles4User(params.Ctx, params.UserID, roleList)
|
||
}
|
||
return retVal, "", err
|
||
})
|
||
}
|
||
|
||
// @Title 给指定角色添加用户列表
|
||
// @Description 给指定角色添加用户列表
|
||
// @Param token header string true "认证token"
|
||
// @Param roleName formData string true "角色名"
|
||
// @Param storeID formData int false "门店ID"
|
||
// @Param userIDs formData string true "用户ID列表"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /AddUsers4Role [post]
|
||
func (c *User2Controller) AddUsers4Role() {
|
||
c.callAddUsers4Role(func(params *tUser2AddUsers4RoleParams) (retVal interface{}, errCode string, err error) {
|
||
var userIDs []string
|
||
if err = jxutils.Strings2Objs(params.UserIDs, &userIDs); err == nil {
|
||
err = cms.AddUsers4Role(params.Ctx, autils.NewRole(params.RoleName, params.StoreID), userIDs)
|
||
}
|
||
return retVal, "", err
|
||
})
|
||
}
|
||
|
||
// @Title 给指定角色删除用户列表
|
||
// @Description 给指定角色删除用户列表
|
||
// @Param token header string true "认证token"
|
||
// @Param roleName query string true "角色名"
|
||
// @Param storeID query int false "门店ID"
|
||
// @Param userIDs query string true "用户ID列表"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /DeleteUsers4Role [delete]
|
||
func (c *User2Controller) DeleteUsers4Role() {
|
||
c.callDeleteUsers4Role(func(params *tUser2DeleteUsers4RoleParams) (retVal interface{}, errCode string, err error) {
|
||
var userIDs []string
|
||
if err = jxutils.Strings2Objs(params.UserIDs, &userIDs); err == nil {
|
||
err = cms.DeleteUsers4Role(params.Ctx, autils.NewRole(params.RoleName, params.StoreID), userIDs)
|
||
}
|
||
return retVal, "", err
|
||
})
|
||
}
|
||
|
||
// @Title 给指定角色添加用户列表
|
||
// @Description 给指定角色添加用户列表
|
||
// @Param token header string true "认证token"
|
||
// @Param mobile formData string false "手机号"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /TransferLegacyWeixins [post]
|
||
func (c *User2Controller) TransferLegacyWeixins() {
|
||
c.callTransferLegacyWeixins(func(params *tUser2TransferLegacyWeixinsParams) (retVal interface{}, errCode string, err error) {
|
||
err = cms.TransferLegacyWeixins(params.Mobile)
|
||
return retVal, "", err
|
||
})
|
||
}
|