1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- package whatsapp
- import (
- "context"
- "wechat-api/ent"
- "wechat-api/ent/whatsapp"
- "wechat-api/internal/utils/dberrorhandler"
- "github.com/suyuan32/simple-admin-common/msg/errormsg"
- "wechat-api/hook/aliyun"
- "wechat-api/internal/svc"
- "wechat-api/internal/types"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type CreateWhatsappLogic struct {
- ctx context.Context
- svcCtx *svc.ServiceContext
- logx.Logger
- }
- func NewCreateWhatsappLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateWhatsappLogic {
- return &CreateWhatsappLogic{
- ctx: ctx,
- svcCtx: svcCtx,
- Logger: logx.WithContext(ctx),
- }
- }
- func (l *CreateWhatsappLogic) CreateWhatsapp(req *types.WhatsappInfo) (*types.BaseMsgResp, error) {
- add, err := aliyun.AddCamsPhoneNumber(*req.PhoneName, *req.Cc, *req.WaId, *req.PhoneName)
- //l.Logger.Infof("add=%v err=%v\n", add, err)
- if err == nil && *add.Body.Code == "OK" {
- var stringSlice []string
- _, err := l.svcCtx.DB.Whatsapp.Query().
- Where(whatsapp.WaID(*req.WaId)).
- Where(whatsapp.Phone(*req.Phone)).
- Where(whatsapp.Cc(*req.Cc)).
- First(l.ctx)
- if err != nil && ent.IsNotFound(err) {
- _, err = l.svcCtx.DB.Whatsapp.Create().
- SetNotNilWaID(req.WaId).
- SetNotNilCallback(req.Callback).
- SetNotNilAccount(req.Account).
- SetNotNilPhone(req.Phone).
- SetNotNilCc(req.Cc).
- SetNotNilPhoneName(req.PhoneName).
- SetNotNilPhoneStatus(req.PhoneStatus).
- SetNotNilOrganizationID(req.OrganizationId).
- SetNotNilAgentID(req.AgentId).
- SetNotNilAPIBase(req.ApiBase).
- SetNotNilAPIKey(req.ApiKey).
- SetNotNilAllowList(stringSlice).
- SetNotNilGroupAllowList(stringSlice).
- SetNotNilBlockList(stringSlice).
- SetNotNilGroupBlockList(stringSlice).
- Save(l.ctx)
- if err != nil {
- return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
- }
- }
- }
- return &types.BaseMsgResp{Msg: errormsg.CreateSuccess}, nil
- }
|