123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- package chat
- import (
- "context"
- "errors"
- "wechat-api/ent"
- "wechat-api/internal/service/addfriend"
- "wechat-api/internal/svc"
- "wechat-api/internal/types"
- "wechat-api/internal/utils/contextkey"
- "github.com/suyuan32/simple-admin-common/enum/errorcode"
- "github.com/suyuan32/simple-admin-common/msg/errormsg"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type AddFriendByPhoneLogic struct {
- logx.Logger
- ctx context.Context
- svcCtx *svc.ServiceContext
- }
- func NewAddFriendByPhoneLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddFriendByPhoneLogic {
- return &AddFriendByPhoneLogic{
- Logger: logx.WithContext(ctx),
- ctx: ctx,
- svcCtx: svcCtx}
- }
- func (l *AddFriendByPhoneLogic) AddFriendByPhone(req *types.AddFriendByPhoneReq) (resp *types.BaseMsgResp, err error) {
- // todo: add your logic here and delete this line
- var (
- apiKeyObj *ent.ApiKey
- ok bool
- )
- //从上下文中获取鉴权中间件埋下的apiAuthInfo
- apiKeyObj, ok = contextkey.AuthTokenInfoKey.GetValue(l.ctx)
- if !ok {
- return nil, errors.New("content get auth info err")
- }
- err = l.AppendWechaFriendAddReq(apiKeyObj, req)
- if err != nil {
- return nil, err
- }
- //addfriend.NewAddWechatFriendService(l.ctx, l.svcCtx).AddNewFriend(req.WeChatId, req.Phone, req.Message)
- addfriend.NewAddWechatFriendService(l.ctx, l.svcCtx).FindFriendByContent(req.WeChatId, req.Phone)
- resp = &types.BaseMsgResp{
- Msg: errormsg.Success,
- Code: errorcode.OK,
- }
- return resp, nil
- }
- func (l *AddFriendByPhoneLogic) AppendWechaFriendAddReq(apiKeyObj *ent.ApiKey, req *types.AddFriendByPhoneReq) error {
- res, err := l.svcCtx.DB.AddWechatFriendLog.Create().
- SetNotNilOwnerWxID(&req.WeChatId).
- SetNotNilOwnerWxType(&req.Type).
- SetNotNilFindContent(&req.Phone).
- SetNotNilMessage(&req.Message).
- Save(l.ctx)
- if err == nil {
- logx.Infof("AppendWechaFriendAddReq succ,get id:%d", res.ID)
- }
- return err
- }
|