|
@@ -3,6 +3,8 @@ package whatsapp
|
|
|
import (
|
|
|
"context"
|
|
|
"github.com/suyuan32/simple-admin-core/rpc/types/core"
|
|
|
+ "github.com/zeromicro/go-zero/core/errorx"
|
|
|
+ "wechat-api/hook/aliyun"
|
|
|
|
|
|
"wechat-api/ent/predicate"
|
|
|
"wechat-api/ent/whatsapp"
|
|
@@ -32,9 +34,21 @@ func NewGetWhatsappListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *G
|
|
|
|
|
|
func (l *GetWhatsappListLogic) GetWhatsappList(req *types.WhatsappListReq) (*types.WhatsappListResp, error) {
|
|
|
var predicates []predicate.Whatsapp
|
|
|
- if req.Callback != nil {
|
|
|
- predicates = append(predicates, whatsapp.CallbackContains(*req.Callback))
|
|
|
+ if req.OrganizationId != nil {
|
|
|
+ predicates = append(predicates, whatsapp.OrganizationID(*req.OrganizationId))
|
|
|
}
|
|
|
+ if req.Phone != nil {
|
|
|
+ predicates = append(predicates, whatsapp.Phone(*req.Phone))
|
|
|
+ }
|
|
|
+ if req.PhoneName != nil {
|
|
|
+ predicates = append(predicates, whatsapp.PhoneName(*req.PhoneName))
|
|
|
+ }
|
|
|
+ if req.WaId != nil && *req.WaId != "" {
|
|
|
+ predicates = append(predicates, whatsapp.WaID(*req.WaId))
|
|
|
+ } else {
|
|
|
+ return nil, errorx.NewInvalidArgumentError("通道ID不能为空")
|
|
|
+ }
|
|
|
+
|
|
|
data, err := l.svcCtx.DB.Whatsapp.Query().Where(predicates...).WithAgent().Page(l.ctx, req.Page, req.PageSize)
|
|
|
|
|
|
if err != nil {
|
|
@@ -45,6 +59,11 @@ func (l *GetWhatsappListLogic) GetWhatsappList(req *types.WhatsappListReq) (*typ
|
|
|
resp.Msg = errormsg.Success
|
|
|
resp.Data.Total = data.PageDetails.Total
|
|
|
|
|
|
+ result, err := aliyun.QueryCamsChatappPhoneNumbers(*req.WaId)
|
|
|
+ l.Logger.Infof("result=%v err=%v\n", result, err)
|
|
|
+
|
|
|
+ phoneNumbers := result.Body.PhoneNumbers
|
|
|
+
|
|
|
for _, v := range data.List {
|
|
|
organizationName := ""
|
|
|
if v.OrganizationID > 0 {
|
|
@@ -72,6 +91,18 @@ func (l *GetWhatsappListLogic) GetWhatsappList(req *types.WhatsappListReq) (*typ
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ var phoneStatus, quality, verifyStatus, frequency string
|
|
|
+ currentPhone := v.Cc + v.Phone
|
|
|
+ for _, v := range phoneNumbers {
|
|
|
+ if *v.PhoneNumber == currentPhone {
|
|
|
+ phoneStatus = *v.Status
|
|
|
+ verifyStatus = *v.CodeVerificationStatus
|
|
|
+ quality = *v.QualityRating
|
|
|
+ frequency = *v.MessagingLimitTier
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
resp.Data.Data = append(resp.Data.Data,
|
|
|
types.WhatsappInfo{
|
|
|
BaseIDInfo: types.BaseIDInfo{
|
|
@@ -85,7 +116,10 @@ func (l *GetWhatsappListLogic) GetWhatsappList(req *types.WhatsappListReq) (*typ
|
|
|
Phone: &v.Phone,
|
|
|
Cc: &v.Cc,
|
|
|
PhoneName: &v.PhoneName,
|
|
|
- PhoneStatus: &v.PhoneStatus,
|
|
|
+ PhoneStatus: &phoneStatus,
|
|
|
+ Quality: &quality,
|
|
|
+ VerifyStatus: &verifyStatus,
|
|
|
+ Frequency: &frequency,
|
|
|
OrganizationId: &v.OrganizationID,
|
|
|
OrganizationName: &organizationName,
|
|
|
AgentId: &v.AgentID,
|