f
This commit is contained in:
@@ -18,7 +18,9 @@ import (
|
||||
"tyapi-server/internal/domains/certification/services"
|
||||
finance_service "tyapi-server/internal/domains/finance/services"
|
||||
user_entities "tyapi-server/internal/domains/user/entities"
|
||||
user_service "tyapi-server/internal/domains/user/services"
|
||||
user_service "tyapi-server/internal/domains/user/services"
|
||||
"tyapi-server/internal/config"
|
||||
"tyapi-server/internal/infrastructure/external/notification"
|
||||
"tyapi-server/internal/infrastructure/external/storage"
|
||||
"tyapi-server/internal/shared/database"
|
||||
"tyapi-server/internal/shared/esign"
|
||||
@@ -47,7 +49,8 @@ type CertificationApplicationServiceImpl struct {
|
||||
enterpriseInfoSubmitRecordRepo repositories.EnterpriseInfoSubmitRecordRepository
|
||||
txManager *database.TransactionManager
|
||||
|
||||
logger *zap.Logger
|
||||
wechatWorkService *notification.WeChatWorkService
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
// NewCertificationApplicationService 创建认证应用服务
|
||||
@@ -67,7 +70,12 @@ func NewCertificationApplicationService(
|
||||
ocrService sharedOCR.OCRService,
|
||||
txManager *database.TransactionManager,
|
||||
logger *zap.Logger,
|
||||
cfg *config.Config,
|
||||
) CertificationApplicationService {
|
||||
var wechatSvc *notification.WeChatWorkService
|
||||
if cfg != nil && cfg.WechatWork.WebhookURL != "" {
|
||||
wechatSvc = notification.NewWeChatWorkService(cfg.WechatWork.WebhookURL, cfg.WechatWork.Secret, logger)
|
||||
}
|
||||
return &CertificationApplicationServiceImpl{
|
||||
aggregateService: aggregateService,
|
||||
userAggregateService: userAggregateService,
|
||||
@@ -83,6 +91,7 @@ func NewCertificationApplicationService(
|
||||
enterpriseInfoSubmitRecordService: enterpriseInfoSubmitRecordService,
|
||||
ocrService: ocrService,
|
||||
txManager: txManager,
|
||||
wechatWorkService: wechatSvc,
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
@@ -1104,6 +1113,35 @@ func (s *CertificationApplicationServiceImpl) completeUserActivationWithoutContr
|
||||
return err
|
||||
}
|
||||
|
||||
// 企业认证成功企业微信通知(仅展示企业名称和联系手机)
|
||||
if s.wechatWorkService != nil {
|
||||
user, err := s.userAggregateService.GetUserWithEnterpriseInfo(ctx, cert.UserID)
|
||||
if err == nil {
|
||||
companyName := "未知企业"
|
||||
phone := ""
|
||||
if user.EnterpriseInfo != nil {
|
||||
companyName = user.EnterpriseInfo.CompanyName
|
||||
if user.EnterpriseInfo.LegalPersonPhone != "" {
|
||||
phone = user.EnterpriseInfo.LegalPersonPhone
|
||||
}
|
||||
}
|
||||
if user.Phone != "" && phone == "" {
|
||||
phone = user.Phone
|
||||
}
|
||||
content := fmt.Sprintf(
|
||||
"### 【天远API】企业认证成功\n"+
|
||||
"> 企业名称:%s\n"+
|
||||
"> 联系手机:%s\n"+
|
||||
"> 完成时间:%s\n"+
|
||||
"\n该企业已完成认证,请相关同事同步更新内部系统。",
|
||||
companyName,
|
||||
phone,
|
||||
time.Now().Format("2006-01-02 15:04:05"),
|
||||
)
|
||||
_ = s.wechatWorkService.SendMarkdownMessage(ctx, content)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
finance_services "tyapi-server/internal/domains/finance/services"
|
||||
product_repositories "tyapi-server/internal/domains/product/repositories"
|
||||
user_repositories "tyapi-server/internal/domains/user/repositories"
|
||||
"tyapi-server/internal/infrastructure/external/notification"
|
||||
"tyapi-server/internal/shared/component_report"
|
||||
"tyapi-server/internal/shared/database"
|
||||
"tyapi-server/internal/shared/export"
|
||||
@@ -43,6 +44,7 @@ type FinanceApplicationServiceImpl struct {
|
||||
exportManager *export.ExportManager
|
||||
logger *zap.Logger
|
||||
config *config.Config
|
||||
wechatWorkService *notification.WeChatWorkService
|
||||
}
|
||||
|
||||
// NewFinanceApplicationService 创建财务应用服务
|
||||
@@ -63,6 +65,11 @@ func NewFinanceApplicationService(
|
||||
config *config.Config,
|
||||
exportManager *export.ExportManager,
|
||||
) FinanceApplicationService {
|
||||
var wechatSvc *notification.WeChatWorkService
|
||||
if config != nil && config.WechatWork.WebhookURL != "" {
|
||||
wechatSvc = notification.NewWeChatWorkService(config.WechatWork.WebhookURL, config.WechatWork.Secret, logger)
|
||||
}
|
||||
|
||||
return &FinanceApplicationServiceImpl{
|
||||
aliPayClient: aliPayClient,
|
||||
wechatPayService: wechatPayService,
|
||||
@@ -79,9 +86,46 @@ func NewFinanceApplicationService(
|
||||
exportManager: exportManager,
|
||||
logger: logger,
|
||||
config: config,
|
||||
wechatWorkService: wechatSvc,
|
||||
}
|
||||
}
|
||||
|
||||
// getUserContactInfo 获取企业名称和联系手机号(尽量用企业信息里的手机号,退化到用户登录手机号)
|
||||
func (s *FinanceApplicationServiceImpl) getUserContactInfo(ctx context.Context, userID string) (companyName, phone string) {
|
||||
companyName = "未知企业"
|
||||
phone = ""
|
||||
|
||||
if userID == "" {
|
||||
return
|
||||
}
|
||||
|
||||
user, err := s.userRepo.GetByIDWithEnterpriseInfo(ctx, userID)
|
||||
if err != nil {
|
||||
s.logger.Warn("获取用户企业信息失败,使用默认企业名称",
|
||||
zap.String("user_id", userID),
|
||||
zap.Error(err),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
// 登录手机号
|
||||
if user.Phone != "" {
|
||||
phone = user.Phone
|
||||
}
|
||||
|
||||
// 企业名称和企业手机号
|
||||
if user.EnterpriseInfo != nil {
|
||||
if user.EnterpriseInfo.CompanyName != "" {
|
||||
companyName = user.EnterpriseInfo.CompanyName
|
||||
}
|
||||
if user.EnterpriseInfo.LegalPersonPhone != "" {
|
||||
phone = user.EnterpriseInfo.LegalPersonPhone
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (s *FinanceApplicationServiceImpl) CreateWallet(ctx context.Context, cmd *commands.CreateWalletCommand) (*responses.WalletResponse, error) {
|
||||
// 调用钱包聚合服务创建钱包
|
||||
wallet, err := s.walletService.CreateWallet(ctx, cmd.UserID)
|
||||
@@ -936,6 +980,33 @@ func (s *FinanceApplicationServiceImpl) processAlipayPaymentSuccess(ctx context.
|
||||
zap.String("amount", amount.String()),
|
||||
)
|
||||
|
||||
// 充值成功企业微信通知(仅充值订单,且忽略发送错误)
|
||||
if s.wechatWorkService != nil {
|
||||
// 再次获取充值记录,拿到用户ID
|
||||
rechargeRecord, err := s.rechargeRecordRepo.GetByID(ctx, alipayOrder.RechargeID)
|
||||
if err == nil {
|
||||
companyName, phone := s.getUserContactInfo(ctx, rechargeRecord.UserID)
|
||||
content := fmt.Sprintf(
|
||||
"### 【天远API】用户充值成功通知\n"+
|
||||
"> 企业名称:%s\n"+
|
||||
"> 联系手机:%s\n"+
|
||||
"> 充值渠道:支付宝\n"+
|
||||
"> 充值金额:%s 元\n"+
|
||||
"> 时间:%s\n",
|
||||
companyName,
|
||||
phone,
|
||||
amount.String(),
|
||||
time.Now().Format("2006-01-02 15:04:05"),
|
||||
)
|
||||
_ = s.wechatWorkService.SendMarkdownMessage(ctx, content)
|
||||
} else {
|
||||
s.logger.Warn("获取充值记录失败,跳过企业微信充值通知",
|
||||
zap.String("out_trade_no", outTradeNo),
|
||||
zap.Error(err),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1681,6 +1752,24 @@ func (s *FinanceApplicationServiceImpl) processWechatPaymentSuccess(ctx context.
|
||||
zap.String("user_id", rechargeRecord.UserID),
|
||||
)
|
||||
|
||||
// 微信充值成功企业微信通知(忽略发送错误)
|
||||
if s.wechatWorkService != nil {
|
||||
companyName, phone := s.getUserContactInfo(ctx, rechargeRecord.UserID)
|
||||
content := fmt.Sprintf(
|
||||
"### 【天远API】用户充值成功通知\n"+
|
||||
"> 企业名称:%s\n"+
|
||||
"> 联系手机:%s\n"+
|
||||
"> 充值渠道:微信\n"+
|
||||
"> 充值金额:%s 元\n"+
|
||||
"> 时间:%s\n",
|
||||
companyName,
|
||||
phone,
|
||||
amount.String(),
|
||||
time.Now().Format("2006-01-02 15:04:05"),
|
||||
)
|
||||
_ = s.wechatWorkService.SendMarkdownMessage(ctx, content)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -7,12 +7,14 @@ import (
|
||||
"time"
|
||||
|
||||
"tyapi-server/internal/application/finance/dto"
|
||||
"tyapi-server/internal/config"
|
||||
"tyapi-server/internal/domains/finance/entities"
|
||||
finance_repo "tyapi-server/internal/domains/finance/repositories"
|
||||
"tyapi-server/internal/domains/finance/services"
|
||||
"tyapi-server/internal/domains/finance/value_objects"
|
||||
user_repo "tyapi-server/internal/domains/user/repositories"
|
||||
user_service "tyapi-server/internal/domains/user/services"
|
||||
"tyapi-server/internal/infrastructure/external/notification"
|
||||
"tyapi-server/internal/infrastructure/external/storage"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
@@ -59,8 +61,9 @@ type InvoiceApplicationServiceImpl struct {
|
||||
userAggregateService user_service.UserAggregateService
|
||||
|
||||
// 外部服务依赖
|
||||
storageService *storage.QiNiuStorageService
|
||||
logger *zap.Logger
|
||||
storageService *storage.QiNiuStorageService
|
||||
logger *zap.Logger
|
||||
wechatWorkServer *notification.WeChatWorkService
|
||||
}
|
||||
|
||||
// NewInvoiceApplicationService 创建发票应用服务
|
||||
@@ -76,7 +79,13 @@ func NewInvoiceApplicationService(
|
||||
userInvoiceInfoService services.UserInvoiceInfoService,
|
||||
storageService *storage.QiNiuStorageService,
|
||||
logger *zap.Logger,
|
||||
cfg *config.Config,
|
||||
) InvoiceApplicationService {
|
||||
var wechatSvc *notification.WeChatWorkService
|
||||
if cfg != nil && cfg.WechatWork.WebhookURL != "" {
|
||||
wechatSvc = notification.NewWeChatWorkService(cfg.WechatWork.WebhookURL, cfg.WechatWork.Secret, logger)
|
||||
}
|
||||
|
||||
return &InvoiceApplicationServiceImpl{
|
||||
invoiceRepo: invoiceRepo,
|
||||
userInvoiceInfoRepo: userInvoiceInfoRepo,
|
||||
@@ -89,6 +98,7 @@ func NewInvoiceApplicationService(
|
||||
userInvoiceInfoService: userInvoiceInfoService,
|
||||
storageService: storageService,
|
||||
logger: logger,
|
||||
wechatWorkServer: wechatSvc,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +185,7 @@ func (s *InvoiceApplicationServiceImpl) ApplyInvoice(ctx context.Context, userID
|
||||
}
|
||||
|
||||
// 10. 构建响应DTO
|
||||
return &dto.InvoiceApplicationResponse{
|
||||
resp := &dto.InvoiceApplicationResponse{
|
||||
ID: application.ID,
|
||||
UserID: application.UserID,
|
||||
InvoiceType: application.InvoiceType,
|
||||
@@ -183,7 +193,33 @@ func (s *InvoiceApplicationServiceImpl) ApplyInvoice(ctx context.Context, userID
|
||||
Status: application.Status,
|
||||
InvoiceInfo: invoiceInfo,
|
||||
CreatedAt: application.CreatedAt,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// 11. 企业微信通知(忽略发送错误),只使用企业名称和联系电话
|
||||
if s.wechatWorkServer != nil {
|
||||
companyName := userWithEnterprise.EnterpriseInfo.CompanyName
|
||||
phone := user.Phone
|
||||
if userWithEnterprise.EnterpriseInfo.LegalPersonPhone != "" {
|
||||
phone = userWithEnterprise.EnterpriseInfo.LegalPersonPhone
|
||||
}
|
||||
|
||||
content := fmt.Sprintf(
|
||||
"### 【天远API】用户申请开发票\n"+
|
||||
"> 企业名称:%s\n"+
|
||||
"> 联系手机:%s\n"+
|
||||
"> 申请开票金额:%s 元\n"+
|
||||
"> 发票类型:%s\n"+
|
||||
"> 申请时间:%s\n",
|
||||
companyName,
|
||||
phone,
|
||||
application.Amount.String(),
|
||||
string(application.InvoiceType),
|
||||
time.Now().Format("2006-01-02 15:04:05"),
|
||||
)
|
||||
_ = s.wechatWorkServer.SendMarkdownMessage(ctx, content)
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// GetUserInvoiceInfo 获取用户发票信息
|
||||
|
||||
Reference in New Issue
Block a user