modify file name

This commit is contained in:
苏尹岚
2020-10-22 15:16:06 +08:00
parent b9c49f75a5
commit 51a9c62beb
3 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,192 @@
package controllers
import (
"git.rosy.net.cn/baseapi/platformapi/weixinapi"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/auth2"
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
"git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/business/jxutils/jsonerr"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/model/dao"
"github.com/astaxie/beego"
)
type User2Controller struct {
beego.Controller
}
// @Title 用户注册
// @Description 用户注册
// @Param token header string false "管理员token"
// @Param payload formData string true "json数据User对象(手机号必填)"
// @Param mobileVerifyCode formData string false "手机验证码通过auth2.SendVerifyCode获得mobileVerifyCode与authToken不能同时为空"
// @Param authToken formData string false "之前通过login得到的认证TOKENmobileVerifyCode与authToken不能同时为空"
// @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, manTokenInfo *auth2.AuthInfo
)
if params.AuthToken != "" {
inAuthInfo, err = auth2.GetTokenInfo(params.AuthToken)
} else if params.Token != "" {
manTokenInfo, err = auth2.GetTokenInfo(params.Token)
}
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, manTokenInfo)
}
}
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"
// @Param storeIDs query string true "门店ID"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /LoadMyCart [get]
func (c *User2Controller) LoadMyCart() {
c.callLoadMyCart(func(params *tUser2LoadMyCartParams) (retVal interface{}, errCode string, err error) {
_, userID := params.Ctx.GetMobileAndUserID()
var storeIDs []int
if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs); err == nil {
retVal, err = cms.LoadUserCart(params.Ctx, userID, storeIDs)
}
return retVal, "", err
})
}
// @Title 存储用户指定门店的购物车信息
// @Description 存储用户指定门店的购物车信息
// @Param token header string true "认证token"
// @Param storeID formData int true "门店ID"
// @Param payload formData string false "完整的购物车商品列表"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /SaveMyCart [post]
func (c *User2Controller) SaveMyCart() {
c.callSaveMyCart(func(params *tUser2SaveMyCartParams) (retVal interface{}, errCode string, err error) {
var cartItems []*model.UserCartItem
_, userID := params.Ctx.GetMobileAndUserID()
if err = jxutils.Strings2Objs(params.Payload, &cartItems); err == nil {
err = cms.SaveUserCart(params.Ctx, userID, params.StoreID, cartItems)
}
return retVal, "", err
})
}
// @Title 得到用户自己的信息
// @Description 得到用户自己的信息
// @Param token header string true "认证token"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetSelfInfo [get]
func (c *User2Controller) GetSelfInfo() {
c.callGetSelfInfo(func(params *tUser2GetSelfInfoParams) (retVal interface{}, errCode string, err error) {
retVal, err = cms.GetSelfInfo(params.Ctx)
return retVal, "", err
})
}
// @Title 根据小程序jsCode修改用户信息
// @Description 根据小程序jsCode修改用户信息
// @Param token header string true "认证token"
// @Param data query string true "加密数据"
// @Param iv query string true "iv"
// @Param jsCode query string false "小程序jsCode"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /UpdateUserByMiniInfo [put]
func (c *Auth2Controller) UpdateUserByMiniInfo() {
c.callUpdateUserByMiniInfo(func(params *tAuth2UpdateUserByMiniInfoParams) (retVal interface{}, errCode string, err error) {
authInfo, err := params.Ctx.GetV2AuthInfo()
if err == nil {
decryptedDataBase64, err2 := weixin.AutherObjMini.DecryptData(authInfo, GetComposedCode(&c.Controller, params.JsCode), params.Data, params.Iv)
if err = err2; err == nil {
var userInfo *weixinapi.MiniUserInfo
if err = utils.UnmarshalUseNumber([]byte(decryptedDataBase64), &userInfo); err == nil {
retVal = userInfo
if user := params.Ctx.GetFullUser(); user != nil {
if userInfo.AvatarURL != "" {
user.Avatar = userInfo.AvatarURL
}
if userInfo.PurePhoneNumber != "" {
user.Mobile = utils.String2Pointer(userInfo.PurePhoneNumber)
}
_, err = dao.UpdateEntity(dao.GetDB(), user)
if err != nil && dao.IsDuplicateError(err) {
if mobileAuth, err2 := auth2.LoginInternal(params.Ctx.Context, auth2.AuthTypeMobile, userInfo.PurePhoneNumber, auth2.UserIDMobile, auth2.InternalAuthSecret); err2 == nil {
err = jsonerr.New(mobileAuth, model.ErrCodeJsonUserAlreadyExist)
}
} else if err == nil && userInfo.PurePhoneNumber != "" {
if tokenInfo, err := auth2.GetTokenInfo(params.Token); err == nil {
tokenInfo.Mobile = userInfo.PurePhoneNumber
auth2.SetUserInfo(params.Token, tokenInfo, auth2.DefTokenDuration)
}
}
}
}
}
}
return retVal, "", err
})
}
// @Title 会员充值
// @Description 会员充值
// @Param token header string false "认证token"
// @Param memberID formData int true "会员ID"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /InvestMember [post]
func (c *User2Controller) InvestMember() {
c.callInvestMember(func(params *tUser2InvestMemberParams) (retVal interface{}, errCode string, err error) {
errCode, err = cms.InvestMember(params.Ctx, params.MemberID)
return retVal, errCode, err
})
}