Browse Source

临时几个需求修改

liwei 4 days ago
parent
commit
d90148cc76
2 changed files with 23 additions and 1 deletions
  1. 8 1
      crontask/wx_add_friend.go
  2. 15 0
      internal/logic/chat/add_friend_by_phone_logic.go

+ 8 - 1
crontask/wx_add_friend.go

@@ -121,8 +121,15 @@ func (me *CronTask) getTaskList() ([]*ent.AddWechatFriendLog, error) {
 		WITH RandRanked AS (
     		SELECT %s,ROW_NUMBER() OVER(PARTITION BY owner_wx_id ORDER BY id DESC) as rn
     		FROM add_wechat_friend_log
-		    WHERE is_can_add = 1 AND task_count < 3)
+		    WHERE is_can_add = 1 )
 		SELECT %s FROM RandRanked WHERE rn = 1;`, fieldListStr, fieldListStr)
+	/*
+				rawQuery := fmt.Sprintf(`
+				WITH RandRanked AS (
+		    		SELECT %s,ROW_NUMBER() OVER(PARTITION BY owner_wx_id ORDER BY id DESC) as rn
+		    		FROM add_wechat_friend_log
+				    WHERE is_can_add = 1 AND task_count < 3)
+				SELECT %s FROM RandRanked WHERE rn = 1;`, fieldListStr, fieldListStr)*/
 
 	//fmt.Println(rawQuery)
 	// 执行原始查询

+ 15 - 0
internal/logic/chat/add_friend_by_phone_logic.go

@@ -12,6 +12,7 @@ import (
 	"wechat-api/internal/types"
 	"wechat-api/internal/utils/typekit"
 
+	"github.com/go-sql-driver/mysql"
 	"github.com/suyuan32/simple-admin-common/enum/errorcode"
 	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 	"github.com/zeromicro/go-zero/core/logx"
@@ -157,6 +158,7 @@ func (l *AddFriendByPhoneLogic) AddFriendByPhone(req *types.AddFriendByPhoneReq)
 		}
 		logx.Infof("chat.AppendWechaFriendAddLog succ,get id:%d", id)
 
+		continue
 		if req.Type != 1 {
 			continue //企微忽略后面
 		}
@@ -171,12 +173,21 @@ func (l *AddFriendByPhoneLogic) AddFriendByPhone(req *types.AddFriendByPhoneReq)
 	return &types.BaseMsgResp{Msg: errormsg.Success, Code: errorcode.OK}, nil
 }
 
+func isDuplicateEntry(err error) bool {
+	var mysqlErr *mysql.MySQLError
+	if errors.As(err, &mysqlErr) {
+		return mysqlErr.Number == 1062
+	}
+	return false
+}
+
 func (l *AddFriendByPhoneLogic) AppendWechaFriendAddInfo(addInfo *AddFriendByPhoneInfo) (int64, error) {
 
 	isCanAdd := 0
 	if addInfo.Type != 1 {
 		isCanAdd = 1
 	}
+	isCanAdd = 1
 	res, err := l.svcCtx.DB.AddWechatFriendLog.Create().
 		SetNotNilOwnerWxID(&addInfo.WeChatId).
 		SetNotNilOwnerWxType(&addInfo.Type).
@@ -189,6 +200,10 @@ func (l *AddFriendByPhoneLogic) AppendWechaFriendAddInfo(addInfo *AddFriendByPho
 	id := int64(0)
 	if err == nil {
 		id = res.ID
+	} else {
+		if isDuplicateEntry(err) {
+			err = errors.New("手机号不能重复绑定")
+		}
 	}
 	return id, err
 }