|
|
@@ -95,271 +95,3 @@ func (self *UserController) BindingTel() {
|
|
|
self.Data["json"] = user
|
|
|
self.ServeJSON()
|
|
|
}
|
|
|
-
|
|
|
-// //获取用户绑定状态
|
|
|
-// func (self *UserController) GetCurrentUserBindingState() {
|
|
|
-// user := self.GetCurrentUser(false)
|
|
|
-// wxUser := self.GetCurrentWxUser(false)
|
|
|
-// if wxUser == nil && user == nil {
|
|
|
-// self.ReturnError(403, apps.UserNeedLogin, "", nil)
|
|
|
-// }
|
|
|
-// type CurrentUser struct {
|
|
|
-// User *user_model.User `orm:"-" json:"user"`
|
|
|
-// WxUser *user_model.WxUser `orm:"-" json:"wx_user"`
|
|
|
-// WxBindingUrl string `orm:"-" json:"wx_binding_url"`
|
|
|
-// }
|
|
|
-
|
|
|
-// bindingUrl := ""
|
|
|
-
|
|
|
-// //防止在其他端绑定,这里要再次做校验
|
|
|
-// if wxUser == nil && user != nil {
|
|
|
-// wxUser = user_model.GetWxUserByUserId(user.Id, false)
|
|
|
-// }
|
|
|
-
|
|
|
-// if wxUser != nil && user == nil {
|
|
|
-// if wxUser.UserId != 0 {
|
|
|
-// user = user_model.GetUserById(wxUser.UserId, false)
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// if wxUser == nil && user != nil {
|
|
|
-
|
|
|
-// uuId := tool.Get8Uuid()
|
|
|
-// k := fmt.Sprintf("user_controller.BindingWxUser[%s]", uuId)
|
|
|
-// cache.Cache.Put(k, user.Id, 20*time.Minute)
|
|
|
-// bindingUrl = fmt.Sprintf("%s/v1/tool/qrcode?url=%s/v1/user/binding/wx/%s",
|
|
|
-// beego.AppConfig.String("ApiHost"), beego.AppConfig.String("ApiHost"), uuId)
|
|
|
-
|
|
|
-// // fmt.Println("************* bindingUrl: %s", bindingUrl)
|
|
|
-// }
|
|
|
-
|
|
|
-// currentUser := new(CurrentUser)
|
|
|
-// if user != nil {
|
|
|
-// user.Head = user_model.GetFullImgUrl(user.Head)
|
|
|
-// }
|
|
|
-// if wxUser != nil {
|
|
|
-// wxUser.Head = user_model.GetFullImgUrl(wxUser.Head)
|
|
|
-// }
|
|
|
-// currentUser.User = user
|
|
|
-// currentUser.WxUser = wxUser
|
|
|
-// currentUser.WxBindingUrl = bindingUrl
|
|
|
-
|
|
|
-// self.Data["json"] = currentUser
|
|
|
-// self.ServeJSON()
|
|
|
-// }
|
|
|
-
|
|
|
-// //绑定微信用户
|
|
|
-// func (self *UserController) BindingWxUser() {
|
|
|
-// uuId := self.Ctx.Input.Param(":key")
|
|
|
-// var userId int64
|
|
|
-// //从缓存中取到待绑定userId
|
|
|
-// k := fmt.Sprintf("user_controller.BindingWxUser[%s]", uuId)
|
|
|
-// if r, ok := cache.Cache.Get(k).(int64); ok {
|
|
|
-// userId = r
|
|
|
-// }
|
|
|
-// //校验user存在
|
|
|
-// user := user_model.GetUserById(userId, false)
|
|
|
-// if user == nil {
|
|
|
-// self.ReturnError(403, apps.BindingWxUserError, "", nil)
|
|
|
-// }
|
|
|
-// //校验wx_user已登录,且记录被创建
|
|
|
-// wxUser := self.GetCurrentWxUser(false)
|
|
|
-// if wxUser == nil {
|
|
|
-// self.ReturnError(403, apps.BindingWxUserError, "", nil)
|
|
|
-// }
|
|
|
-
|
|
|
-// //确保没有wx_user绑定过该user_id
|
|
|
-// existedWxUser := user_model.GetWxUserByUserId(user.Id, false)
|
|
|
-// if wxUser.UserId == 0 && existedWxUser == nil {
|
|
|
-// //绑定微信user和user
|
|
|
-// wxUser.UserId = user.Id
|
|
|
-// wxUser.Save()
|
|
|
-// user.CopyWxUserHead(wxUser.Head)
|
|
|
-// if user.Nickname == "" {
|
|
|
-// user.Nickname = wxUser.Nickname
|
|
|
-// }
|
|
|
-// if user.Country == "" {
|
|
|
-// user.Country = wxUser.Country
|
|
|
-// }
|
|
|
-// if user.Province == "" {
|
|
|
-// user.Province = wxUser.Province
|
|
|
-// }
|
|
|
-// if user.City == "" {
|
|
|
-// user.City = wxUser.City
|
|
|
-// }
|
|
|
-// if user.Sex == 0 {
|
|
|
-// user.Sex = wxUser.Sex
|
|
|
-// }
|
|
|
-// user.Save()
|
|
|
-// cache.Cache.Delete(k)
|
|
|
-// } else {
|
|
|
-// self.ReturnError(403, apps.BindingWxUserError, "", nil)
|
|
|
-// }
|
|
|
-// self.Redirect(fmt.Sprintf("%s/user/binding/state", beego.AppConfig.String("WxHost")), 302)
|
|
|
-// }
|
|
|
-
|
|
|
-// //绑定身份证
|
|
|
-// func (self *UserController) BindingIdCard() {
|
|
|
-// idCard := self.GetString("identity_card")
|
|
|
-// realName := self.GetString("real_name")
|
|
|
-// user := self.GetCurrentUser(false)
|
|
|
-// if user.IsCertification == 1 {
|
|
|
-// self.ReturnError(403, apps.UserHasBindIdCard, "", nil)
|
|
|
-// }
|
|
|
-// if idCard == "" || realName == "" {
|
|
|
-// self.ReturnError(403, apps.BindingIdCardEmpty, "", nil)
|
|
|
-// }
|
|
|
-
|
|
|
-// idCardLength := len(idCard)
|
|
|
-// if idCardLength != 15 && idCardLength != 18 {
|
|
|
-// self.ReturnError(403, apps.BindingIdCardLengthError, "", nil)
|
|
|
-// }
|
|
|
-
|
|
|
-// userWithIdCard := user_model.GetUserByIdCardNo(idCard, false)
|
|
|
-// if userWithIdCard != nil {
|
|
|
-// self.ReturnError(403, apps.BindingIdCardExist, "", nil)
|
|
|
-// }
|
|
|
-
|
|
|
-// user.RealName = realName
|
|
|
-// user.IdentityCard = idCard
|
|
|
-// user.IsCertification = 1
|
|
|
-// birth, err := time.Parse("20060102", idCard[6:14])
|
|
|
-// if err == nil {
|
|
|
-// user.Birthday = birth
|
|
|
-// }
|
|
|
-
|
|
|
-// age, getAagError := getAgeByIdCardNo(user.IdentityCard)
|
|
|
-// if getAagError == nil {
|
|
|
-// user.Age = age
|
|
|
-// }
|
|
|
-
|
|
|
-// user.Save()
|
|
|
-
|
|
|
-// self.Data["json"] = user
|
|
|
-// self.ServeJSON()
|
|
|
-// }
|
|
|
-
|
|
|
-// //根据身份证获取年龄
|
|
|
-// func getAgeByIdCardNo(idCardNo string) (int64, error) {
|
|
|
-// age, err := user.CaculateAgeByIdCard(idCardNo)
|
|
|
-// if err != nil {
|
|
|
-// return 0, err
|
|
|
-// }
|
|
|
-// return age, nil
|
|
|
-// }
|
|
|
-
|
|
|
-// //迁移余额,春节翻红包专题
|
|
|
-// func moveFHBBalance(wxUser *user_model.WxUser, user *user_model.User) {
|
|
|
-// list := balance_model.GetValidWxBalances(wxUser.Id, balance_model.WX_BALANCE_SOURCE_NEW_YEAR_FHB_2017)
|
|
|
-// for _, item := range list {
|
|
|
-// //标记迁移
|
|
|
-// item.State = 1
|
|
|
-// item.Save()
|
|
|
-// go new(balance_model.Balance).Create(user.Id, item.Amount, item.Source,
|
|
|
-// item.RelateId, item.Remark, 1)
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// //迁移wx user balance 中数据到balance
|
|
|
-// func moveWxBalacneToBalance(wxUser *user_model.WxUser, user *user_model.User) {
|
|
|
-// list := balance_model.GetAllValidWxBalances(wxUser.Id)
|
|
|
-// for _, item := range list {
|
|
|
-// //标记迁移
|
|
|
-// item.State = 1
|
|
|
-// item.Save()
|
|
|
-// new(balance_model.Balance).Create(user.Id, item.Amount, item.Source,
|
|
|
-// item.RelateId, item.Remark, 1)
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// //更新wxUser上下级的邀请关系。仅适用于user先创建,wxuser后绑定的情况
|
|
|
-// func updateInviteRelation(wxUser *user_model.WxUser, user *user_model.User) {
|
|
|
-// if wxUser == nil || user == nil {
|
|
|
-// return
|
|
|
-// }
|
|
|
-
|
|
|
-// //user有邀请人时才执行更新上级的动作
|
|
|
-// if user.InviteId != 0 {
|
|
|
-// wxInviter := user_model.GetWxUserByUserId(user.InviteId, true)
|
|
|
-// //更新上级:微信用户的邀请人与User的邀请人有冲突,以user为准
|
|
|
-// if wxInviter != nil && wxUser.InviteId != wxInviter.Id {
|
|
|
-// //更新树型结构中受益人
|
|
|
-// orgWxInviter := user_model.GetWxUserById(wxUser.InviteId, true)
|
|
|
-// if orgWxInviter != nil {
|
|
|
-// list := user_model.GetWxBindingBenefitRecords(wxUser.Id, orgWxInviter.Id)
|
|
|
-// for _, item := range list {
|
|
|
-// //变更受益人
|
|
|
-// item.BenefitWxUId = wxInviter.Id
|
|
|
-// item.Save()
|
|
|
-// }
|
|
|
-
|
|
|
-// //删除间接邀请绑定记录
|
|
|
-// inDirectList := user_model.GetIndirectWxBindingBenefitRecords(wxUser.Id, orgWxInviter.Id)
|
|
|
-// for _, item := range inDirectList {
|
|
|
-// item.Delete()
|
|
|
-// }
|
|
|
-// }
|
|
|
-// //更新wxUser邀请人
|
|
|
-// wxUser.InviteId = wxInviter.Id
|
|
|
-// wxUser.UpdateField("InviteId")
|
|
|
-// beego.BeeLogger.Warn("Wxuser Inviter Relationship-binding1, wxUserId:%d, inviteId:%d, userId: %d, tel: %d, userInviteId: %d", wxUser.Id, wxUser.InviteId, user.Id, user.Tel, user.InviteId)
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// //更新下级
|
|
|
-// list := user_model.GetInviteList(user.Id, 1, 99999, false)
|
|
|
-// for _, child := range list {
|
|
|
-// wxChild := user_model.GetWxUserByUserId(child.Id, false)
|
|
|
-// if wxChild != nil && wxChild.InviteId != wxUser.Id {
|
|
|
-// //更新树型结构受益人
|
|
|
-// orgWxChildInviter := user_model.GetWxUserById(wxChild.InviteId, true)
|
|
|
-// if orgWxChildInviter != nil {
|
|
|
-// // user_model.UpdateBenefitWxUId(wxUser.Id, orgWxInviter.Id, wxInviter.Id)
|
|
|
-// list := user_model.GetWxBindingBenefitRecords(wxChild.Id, orgWxChildInviter.Id)
|
|
|
-// for _, item := range list {
|
|
|
-// //变更受益人
|
|
|
-// item.BenefitWxUId = wxUser.Id
|
|
|
-// item.Save()
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// //更新wxUser邀请人
|
|
|
-// wxChild.InviteId = wxUser.Id
|
|
|
-// wxChild.UpdateField("InviteId")
|
|
|
-// beego.BeeLogger.Warn("Wxuser Inviter Relationship-binding2, wxUserId:%d, inviteId:%d", wxUser.Id, wxUser.InviteId)
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// //给邀请人发送绑定手机通知
|
|
|
-// func sendBindingMsgToInviter(wxUser *user_model.WxUser, user *user_model.User) {
|
|
|
-// if wxUser == nil || user == nil {
|
|
|
-// return
|
|
|
-// }
|
|
|
-
|
|
|
-// wxInviter := user_model.GetWxUserById(wxUser.InviteId, true)
|
|
|
-// if wxInviter != nil {
|
|
|
-// now := time.Now()
|
|
|
-// //给直属邀请人发邀请成功通知
|
|
|
-// openId := wxInviter.MpOpenid
|
|
|
-// url := fmt.Sprintf("%s/user/promot", beego.AppConfig.String("MHost"))
|
|
|
-// title := "有人通过您的邀请注册成功。若TA投资项目,您将获得投资金额1%的奖励\n"
|
|
|
-// telwStar := tool.ReplaceTelMid4(user.Tel)
|
|
|
-// cTime := now.Format("2006-01-02 15:04:05")
|
|
|
-// remark := "\n点击详情,可以看一看TA"
|
|
|
-// wx_mp.TmplmsgInviteSignUp(openId, url, title, wxUser.Nickname, telwStar, cTime, remark)
|
|
|
-
|
|
|
-// // 取消二级关系
|
|
|
-// // preWxInviter := user_model.GetWxUserById(wxInviter.InviteId, true)
|
|
|
-// // if preWxInviter != nil {
|
|
|
-// // //给间接邀请人发注册成功通知
|
|
|
-// // openId := preWxInviter.MpOpenid
|
|
|
-// // url := fmt.Sprintf("%s/user/promot", beego.AppConfig.String("MHost"))
|
|
|
-// // title := fmt.Sprintf("有人通过%s的邀请注册成功。若TA投资项目,您将获得投资金额3‰的奖励\n", wxInviter.Nickname)
|
|
|
-// // telwStar := tool.ReplaceTelMid4(user.Tel)
|
|
|
-// // cTime := now.Format("2006-01-02 15:04:05")
|
|
|
-// // remark := "\n点击详情,可以看一看TA"
|
|
|
-// // wx_mp.TmplmsgInviteSignUp(openId, url, title, wxUser.Nickname, telwStar, cTime, remark)
|
|
|
-// // }
|
|
|
-// }
|
|
|
-// }
|