|
@@ -3,6 +3,7 @@ package chat
|
|
|
import (
|
|
|
"context"
|
|
|
"errors"
|
|
|
+ "fmt"
|
|
|
|
|
|
"wechat-api/ent"
|
|
|
"wechat-api/ent/predicate"
|
|
@@ -32,13 +33,13 @@ func NewAddFriendByPhoneLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
|
|
|
svcCtx: svcCtx}
|
|
|
}
|
|
|
|
|
|
-func GetRandWxid(idList []string) string {
|
|
|
- id := ""
|
|
|
- if len(idList) > 0 {
|
|
|
- typekit.ShuffleList(idList)
|
|
|
- id = idList[0]
|
|
|
+func GetListRandOne(strList []string) string {
|
|
|
+ one := ""
|
|
|
+ if len(strList) > 0 {
|
|
|
+ typekit.ShuffleList(strList)
|
|
|
+ one = strList[0]
|
|
|
}
|
|
|
- return id
|
|
|
+ return one
|
|
|
}
|
|
|
|
|
|
func (l *AddFriendByPhoneLogic) getWxInfoList(preds ...predicate.Wx) ([]*ent.Wx, error) {
|
|
@@ -81,7 +82,7 @@ func (l *AddFriendByPhoneLogic) rebuildAddFriendByPhoneInfos(req *types.AddFrien
|
|
|
return nil, err
|
|
|
}
|
|
|
infos := []AddFriendByPhoneInfo{}
|
|
|
- for idx, phone := range req.Phones {
|
|
|
+ for idx, phone := range req.Phones { //以phones为主,逐一绑定wxid,多余的wxid忽略
|
|
|
info := AddFriendByPhoneInfo{Type: req.Type, WeChatId: req.WeChatIds[idx],
|
|
|
Phone: phone, Message: req.Message, CallbackURL: req.CallbackURL, Oid: int64(Oid)}
|
|
|
infos = append(infos, info)
|
|
@@ -89,6 +90,44 @@ func (l *AddFriendByPhoneLogic) rebuildAddFriendByPhoneInfos(req *types.AddFrien
|
|
|
return infos, nil
|
|
|
}
|
|
|
|
|
|
+/*
|
|
|
+1.手机号是必传的,至少有1个
|
|
|
+2.微信号可以不传为空,这种情况拿当前登录者同租户OID的微信ID随机绑定传入的每个手机号
|
|
|
+3.微信号数量等于或者大于手机号数量,则按输入前后顺序逐一绑定,多出来的微信号忽略
|
|
|
+4.当微信号数量小于手机号数量,多出来的手机号则从输入的微信号中随机找1个绑定
|
|
|
+*/
|
|
|
+
|
|
|
+func (l *AddFriendByPhoneLogic) alignWxidsAndPhones(Oid uint64, CType uint64,
|
|
|
+ weChatIds []string, phones []string) (bool, []string, []string, error) {
|
|
|
+
|
|
|
+ lenWechatIds := len(weChatIds)
|
|
|
+ lenPhones := len(phones)
|
|
|
+
|
|
|
+ if lenPhones == 0 {
|
|
|
+ return false, nil, nil, errors.New("phones empty")
|
|
|
+ }
|
|
|
+
|
|
|
+ if lenWechatIds == 0 { //输入wxids为空,从当前库中同Oid的Wxid里随机选1个
|
|
|
+ allWxIds, err := l.getWxIdListByOid(Oid, CType)
|
|
|
+ if err != nil {
|
|
|
+ return false, weChatIds, phones, err
|
|
|
+ }
|
|
|
+ if len(allWxIds) == 0 {
|
|
|
+ return false, weChatIds, phones, fmt.Errorf("wxids empty(%d)", Oid)
|
|
|
+ }
|
|
|
+ for range lenPhones {
|
|
|
+ weChatIds = append(weChatIds, GetListRandOne(allWxIds))
|
|
|
+ }
|
|
|
+ } else if lenWechatIds < lenPhones { //当wxids数量小于phones数量,从已输入wxids随机选1个对齐phones
|
|
|
+ for range lenPhones - lenWechatIds {
|
|
|
+ weChatIds = append(weChatIds, GetListRandOne(weChatIds))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //剩下的case就是wxids数量等于或大于phones
|
|
|
+ return true, weChatIds, phones, nil
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
func (l *AddFriendByPhoneLogic) alignWxidsAndPhones(Oid uint64, CType uint64,
|
|
|
weChatIds []string, phones []string) (bool, []string, []string, error) {
|
|
|
|
|
@@ -114,14 +153,15 @@ func (l *AddFriendByPhoneLogic) alignWxidsAndPhones(Oid uint64, CType uint64,
|
|
|
weChatIds = append(weChatIds, GetRandWxid(allWxIds))
|
|
|
}
|
|
|
} else { //case 3: 输入的wxids比phones大
|
|
|
- /*
|
|
|
- for i := 0; i < lenWechatIds-lenPhones; i++ {
|
|
|
- phones = append(phones, GetRandWxid(phones))
|
|
|
- }
|
|
|
- */
|
|
|
+
|
|
|
+ // for i := 0; i < lenWechatIds-lenPhones; i++ {
|
|
|
+ // phones = append(phones, GetRandWxid(phones))
|
|
|
+ // }
|
|
|
+
|
|
|
}
|
|
|
return true, weChatIds, phones, nil
|
|
|
}
|
|
|
+*/
|
|
|
|
|
|
func (l *AddFriendByPhoneLogic) AddFriendByPhone(req *types.AddFriendByPhoneReq) (resp *types.BaseMsgResp, err error) {
|
|
|
// todo: add your logic here and delete this line
|