删除一些东西
This commit is contained in:
@@ -6,12 +6,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/event"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jsonerr"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
@@ -118,87 +114,6 @@ func init() {
|
||||
auth2.Init(userProvider)
|
||||
}
|
||||
|
||||
func RegisterUserWithMobile(ctx *jxcontext.Context, user *model.User, mobileVerifyCode string, inAuthInfo, manTokenInfo *auth2.AuthInfo) (outAuthInfo *auth2.AuthInfo, err error) {
|
||||
var mobileAuth *auth2.AuthInfo
|
||||
fakeMobile := false
|
||||
createName := ctx.GetRealRemoteIP()
|
||||
authType := auth2.AuthTypeMobile
|
||||
if manTokenInfo != nil && mobileVerifyCode == "" {
|
||||
_, err2 := dao.GetUserByID(dao.GetDB(), "user_id", manTokenInfo.GetID())
|
||||
if err = err2; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if utils.Pointer2String(user.Mobile) == "" {
|
||||
return nil, fmt.Errorf("管理员添加必须指定用户手机号")
|
||||
}
|
||||
mobileVerifyCode = auth2.InternalAuthSecret
|
||||
fakeMobile = true
|
||||
createName = manTokenInfo.GetName()
|
||||
}
|
||||
|
||||
if mobileVerifyCode != "" {
|
||||
if fakeMobile {
|
||||
mobileAuth, err = auth2.LoginInternal(ctx.Context, auth2.AuthTypeMobile, user.GetMobile(), auth2.UserIDMobile, mobileVerifyCode)
|
||||
} else {
|
||||
mobileAuth, err = auth2.Login(ctx.Context, auth2.AuthTypeMobile, user.GetMobile(), auth2.UserIDMobile, mobileVerifyCode)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if mobileAuth != nil && !mobileAuth.IsUserEmpty() {
|
||||
return nil, jsonerr.New(mobileAuth, model.ErrCodeJsonUserAlreadyExist)
|
||||
|
||||
// auth2.RemoveUserInfo(mobileAuth.Token)
|
||||
// if newAuthInfo, err := auth2.BindUser(mobileAuth, user); err == nil {
|
||||
// globals.SugarLogger.Debugf("testRegisterUserWithMobile", utils.Format4Output(mobileAuth, false), utils.Format4Output(newAuthInfo, false))
|
||||
// return nil, jsonerr.New(newAuthInfo, model.ErrCodeJsonUserAlreadyExist)
|
||||
// } else {
|
||||
// return nil, err
|
||||
// }
|
||||
}
|
||||
} else if inAuthInfo != nil {
|
||||
// user.Mobile = nil
|
||||
} else {
|
||||
return nil, fmt.Errorf("短信验证码与其它认证方式至少要指定一种")
|
||||
}
|
||||
|
||||
if inAuthInfo != nil {
|
||||
createName += "," + inAuthInfo.GetAuthID()
|
||||
authType = inAuthInfo.GetAuthType()
|
||||
if user.Avatar == "" {
|
||||
user.Avatar = inAuthInfo.GetAvatar()
|
||||
}
|
||||
}
|
||||
if err = CreateUser(user, utils.LimitUTF8StringLen(createName, 32)); err == nil {
|
||||
userProvider.UpdateLastLogin(user.GetID(), authType, ctx.GetRealRemoteIP())
|
||||
// TryAddStoreBossRole4User(ctx, user)
|
||||
if mobileAuth != nil {
|
||||
if outAuthInfo, err = auth2.BindUser(mobileAuth, user); err == nil && inAuthInfo != nil {
|
||||
err = auth2.AddAuthBind(&outAuthInfo.UserBasic, inAuthInfo)
|
||||
}
|
||||
} else {
|
||||
outAuthInfo, err = auth2.BindUser(inAuthInfo, user)
|
||||
}
|
||||
//给用户添加一条账单记录
|
||||
err = AddUserBill(user)
|
||||
} else if dao.IsDuplicateError(err) {
|
||||
err = auth2.ErrUserID2AlreadyExist
|
||||
}
|
||||
return outAuthInfo, err
|
||||
}
|
||||
|
||||
func AddUserBill(user *model.User) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
userBill := &model.UserBill{
|
||||
BillID: jxutils.GenBillID(),
|
||||
UserID: user.UserID,
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(userBill, jxcontext.AdminCtx.GetUserName())
|
||||
return dao.CreateEntity(db, userBill)
|
||||
}
|
||||
|
||||
func GetUserBindAuthInfo(ctx *jxcontext.Context) (authList []*model.AuthBind, err error) {
|
||||
authInfo, err := ctx.GetV2AuthInfo()
|
||||
if err == nil {
|
||||
@@ -207,34 +122,6 @@ func GetUserBindAuthInfo(ctx *jxcontext.Context) (authList []*model.AuthBind, er
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func CreateUser(user *model.User, creatorName string) (err error) {
|
||||
globals.SugarLogger.Debugf("CreateUser user:%s, creatorName:%s", utils.Format4Output(user, true), creatorName)
|
||||
|
||||
if user == nil || user.UserID2 == "" || user.Name == "" {
|
||||
return ErrUserIDAndNameMustGiven
|
||||
}
|
||||
if user.GetMobile() == "" {
|
||||
user.Mobile = nil
|
||||
}
|
||||
if user.GetEmail() == "" {
|
||||
user.Email = nil
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(user, creatorName)
|
||||
user.UserID = utils.GetUUID()
|
||||
user.Status = model.UserStatusNormal
|
||||
//推广码
|
||||
popCode := ""
|
||||
for {
|
||||
popCode = jxutils.GenRandomString(6)
|
||||
user2, _ := dao.GetUserByID(dao.GetDB(), "pop_code", popCode)
|
||||
if user2 == nil {
|
||||
user.PopCode = popCode
|
||||
break
|
||||
}
|
||||
}
|
||||
return dao.CreateEntity(nil, user)
|
||||
}
|
||||
|
||||
func DisableUser(ctx *jxcontext.Context, userID string) (err error) {
|
||||
userName := ctx.GetUserName()
|
||||
if _, err = dao.UpdateEntityLogically(dao.GetDB(), &model.User{}, map[string]interface{}{
|
||||
@@ -368,146 +255,6 @@ func RefreshUserMemberStatus(ctx *jxcontext.Context) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func UpdateUser(ctx *jxcontext.Context, payload map[string]interface{}) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
userID string
|
||||
)
|
||||
if payload["userID"] != nil {
|
||||
userID = payload["userID"].(string)
|
||||
} else {
|
||||
userID = ctx.GetUserID()
|
||||
}
|
||||
user := &model.User{
|
||||
UserID: userID,
|
||||
}
|
||||
dao.GetEntity(db, user, "UserID")
|
||||
//if payload["lng"] != nil && payload["lat"] != nil {
|
||||
// if address, districtCode, cityCode, err := getAddressInfoFromCoord(db, utils.MustInterface2Float64(payload["lng"]), utils.MustInterface2Float64(payload["lat"])); err == nil {
|
||||
// delete(payload, "lng")
|
||||
// delete(payload, "lat")
|
||||
// payload["address"] = address
|
||||
// payload["districtCode"] = districtCode
|
||||
// payload["cityCode"] = cityCode
|
||||
// } else {
|
||||
// return err
|
||||
// }
|
||||
//}
|
||||
//暂时用这个字段作为更新他的推广人
|
||||
if payload["popCode"] != nil {
|
||||
if user, err := dao.GetUserByID(db, "pop_code", payload["popCode"].(string)); err == nil {
|
||||
if user != nil {
|
||||
payload["popUser"] = user.UserID
|
||||
delete(payload, "popCode")
|
||||
} else {
|
||||
return fmt.Errorf("未查询到此推广人!%v", payload["popCode"])
|
||||
}
|
||||
}
|
||||
}
|
||||
valid := dao.StrictMakeMapByStructObject(payload, user, ctx.GetUserName())
|
||||
if len(valid) > 0 {
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
if _, err = dao.UpdateEntityByKV(db, user, valid, nil); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return err
|
||||
}
|
||||
dao.Commit(db, txDB)
|
||||
}
|
||||
if payload["popUser"] != nil {
|
||||
// InvestMemberAndUpdate := func(user *model.User) (err error) {
|
||||
// if _, err = InvestMember(ctx, 1, user.UserID, true); err == nil {
|
||||
|
||||
// }
|
||||
// user.PopFlag = model.YES
|
||||
// _, err = dao.UpdateEntity(db, user, "PopFlag")
|
||||
// return err
|
||||
// }
|
||||
user2, err2 := dao.GetUserByID(db, "user_id", payload["popUser"].(string))
|
||||
err = err2
|
||||
do := func(user *model.User, flag bool) (err error) {
|
||||
//if user.PopCount%4 == 0 && user.PopFlag == model.NO {
|
||||
// if _, err = InvestMember(ctx, 1, user.UserID, true); err == nil {
|
||||
// //发短信,公众号消息通知
|
||||
// smsmsg.SendSMSMsg([]string{*user.Mobile}, globals.SMSSignName, globals.SMSPopSuccessTemplate, nil)
|
||||
// // weixinmsg.SendMsgToUser(userID, templateID, data)
|
||||
// event.SendSysMessageSimple("您好,您已成功邀请4人加入我们,成功免费获得1个月会员!", user.UserID)
|
||||
// }
|
||||
// user.PopFlag = model.YES
|
||||
// dao.UpdateEntity(db, user, "PopFlag")
|
||||
//
|
||||
// if flag {
|
||||
// if users, _, err := dao.GetUsers(db, 0, "", user.UserID, nil, nil, nil, 0, 999); err == nil {
|
||||
// for _, v := range users {
|
||||
// v.PopedFlag = model.YES
|
||||
// dao.UpdateEntity(db, v, "PopedFlag")
|
||||
// }
|
||||
// }
|
||||
// _, err = event.CreateMessageGroup(ctx, user.UserID, "", "", 5, 100)
|
||||
// }
|
||||
//}
|
||||
return err
|
||||
}
|
||||
if user2 != nil {
|
||||
user2.PopCount++
|
||||
messageGroupsResult, err3 := dao.GetMessageGroups(db, user2.UserID, 0, model.GroupTypeMulit, false, "")
|
||||
err = err3
|
||||
//如果他已经有群了,被邀请人直接进群
|
||||
//如果他没群,在邀请到4个人的时候,自动创一个群,所有被邀请人打上标志
|
||||
if len(messageGroupsResult) > 0 {
|
||||
err = event.AddMessageGroup(ctx, messageGroupsResult[0].GroupID, user.UserID)
|
||||
//邀请过4人直接开通一个月会员
|
||||
do(user2, false)
|
||||
} else {
|
||||
//邀请过4人直接开通一个月会员并创建群组
|
||||
do(user2, true)
|
||||
}
|
||||
dao.UpdateEntity(db, user2, "PopCount")
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func AcceptAddGroup(ctx *jxcontext.Context, flag int) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
userID = ctx.GetUserID()
|
||||
)
|
||||
user, err := dao.GetUserByID(db, "user_id", userID)
|
||||
if user == nil {
|
||||
return fmt.Errorf("获取用户信息失败!")
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if user.PopedFlag == model.NO {
|
||||
return fmt.Errorf("获取用户邀请信息失败")
|
||||
}
|
||||
//同意加入
|
||||
if flag == model.YES {
|
||||
//1、找到这个人的邀请人
|
||||
//2、这个邀请人有群就直接进,没群就加入失败了
|
||||
messageGroupsResult, err := dao.GetMessageGroups(db, user.PopUser, 0, model.GroupTypeMulit, false, "")
|
||||
if err != nil {
|
||||
return fmt.Errorf("获取邀请人群信息失败! %v", err)
|
||||
}
|
||||
if len(messageGroupsResult) > 0 {
|
||||
err = event.AddMessageGroup(ctx, messageGroupsResult[0].GroupID, user.UserID)
|
||||
} else {
|
||||
return fmt.Errorf("获取邀请人群信息失败!")
|
||||
}
|
||||
}
|
||||
//同步同意都清标志
|
||||
user.PopedFlag = model.NO
|
||||
dao.UpdateEntity(db, user, "PopedFlag")
|
||||
return err
|
||||
}
|
||||
|
||||
type GetUserSerachKeywordResult struct {
|
||||
AllSpan []*model.UserSearch `json:"allSpan"`
|
||||
UserSpan []*model.UserSearch `json:"userSpan"`
|
||||
|
||||
Reference in New Issue
Block a user