feat: 客户关联产品并支持按产品圈选通知群体

新增客户-产品多对多关联,列表可按产品筛选并复制邮箱;发证/下单自动回填历史关联。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Logan.LiandCursor committed 2026-08-12 21:58:35 +08:00
1 parent d0e1ca3729
commit 4c46088f4f
10 files changed
+337 -89

No files matched your search

@@ -3,6 +3,7 @@ package order
import (
"backend/internal/dto"
"backend/internal/model"
customersvc "backend/internal/service/customer"
"backend/internal/service/payment"
"backend/utils"
"errors"
@@ -142,6 +143,7 @@ func (s *OrderService) CreateOrder(req dto.CreateOrderRequest, clientIP, userAge
if err := s.db.Create(&order).Error; err != nil {
return nil, errors.New("创建订单失败")
}
_ = customersvc.AttachProduct(s.db, customer.ID, product.ID)
// 6. 生成收银台地址 // Logan.Li
var checkoutURL string
@@ -365,6 +367,7 @@ func (s *OrderService) PaymentWebhook(req dto.PaymentWebhookRequest, clientIP st
if err := tx.Create(&lic).Error; err != nil {
return err
}
_ = customersvc.AttachProduct(tx, order.CustomerID, order.ProductID)
if err := tx.Model(&model.Order{}).Where("id = ?", order.ID).
Update("license_id", lic.ID).Error; err != nil {
return err
@@ -471,6 +474,7 @@ func (s *OrderService) ManualGrant(req dto.ManualGrantRequest, operatorID uint,
if err := s.db.Create(&lic).Error; err != nil {
return nil, errors.New("创建 License 失败")
}
_ = customersvc.AttachProduct(s.db, customer.ID, req.ProductID)
// 创建/更新权益记录 // Logan.Li
renewable := plan.PlanType != "perpetual" && plan.PlanType != "lifetime"