Browse Source

#2225

update wechat bind rule
tags/v1.22.9.2^2
chenyifan01 3 years ago
parent
commit
42d13cef3c
4 changed files with 19 additions and 4 deletions
  1. +4
    -0
      models/wechat_bind.go
  2. +3
    -3
      modules/auth/wechat/bind.go
  3. +1
    -1
      routers/reward/point/point.go
  4. +11
    -0
      services/task/task.go

+ 4
- 0
models/wechat_bind.go View File

@@ -96,3 +96,7 @@ func UnbindWechatOpenId(userId int64, oldWechatOpenID string) error {
sess.Insert(logParam)
return sess.Commit()
}

func CountWechatBindLog(wechatOpenId string, action WechatBindAction) (int64, error) {
return x.Where("wechat_open_id = ? and action = ?", action, wechatOpenId).Count(&WechatBindLog{})
}

+ 3
- 3
modules/auth/wechat/bind.go View File

@@ -38,7 +38,7 @@ func (err WechatBindError) Error() string {
}

func BindWechat(userId int64, wechatOpenId string) error {
if !IsWechatAccountAvailable(userId, wechatOpenId) {
if !IsWechatAccountUsed(userId, wechatOpenId) {
log.Error("bind wechat failed, because user use wrong wechat account to bind,userId=%d wechatOpenId=%s", userId, wechatOpenId)
return NewWechatBindError(BIND_REPLY_WECHAT_ACCOUNT_USED)
}
@@ -60,9 +60,9 @@ func IsUserAvailableForWechatBind(userId int64, wechatOpenId string) bool {
return currentOpenId == "" || currentOpenId == wechatOpenId
}

//IsWechatAccountAvailable if wechat account used by another account,return false
//IsWechatAccountUsed if wechat account used by another account,return false
//if wechat account not used or used by the given user,return true
func IsWechatAccountAvailable(userId int64, wechatOpenId string) bool {
func IsWechatAccountUsed(userId int64, wechatOpenId string) bool {
user := models.GetUserByWechatOpenId(wechatOpenId)
if user != nil && user.WechatOpenId != "" && user.ID != userId {
return false


+ 1
- 1
routers/reward/point/point.go View File

@@ -48,7 +48,7 @@ func GetPointRecordList(ctx *context.Context) {
}

r, err := reward.GetRewardRecordList(models.RewardRecordListOpts{
ListOptions: models.ListOptions{PageSize: 20, Page: page},
ListOptions: models.ListOptions{PageSize: 10, Page: page},
UserId: ctx.User.ID,
OperateType: t,
RewardType: models.RewardTypePoint,


+ 11
- 0
services/task/task.go View File

@@ -16,6 +16,17 @@ func Accomplish(action models.Action) {
if action.Repo.IsPrivate {
return
}
case models.ActionBindWechat:
n, err := models.CountWechatBindLog(action.Content, models.WECHAT_BIND)
if err != nil {
log.Error("CountWechatBindLog error when accomplish task,err=%v", err)
return
}
//if wechatOpenId has been bound before,the action can not get reward
if n > 1 {
return
}

}
go accomplish(action)
}


Loading…
Cancel
Save