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

@@ -1,6 +1,7 @@
package customer
import (
"backend/internal/dto"
customerservice "backend/internal/service/customer"
"backend/utils"
"net/http"
@@ -21,13 +22,14 @@ func NewCustomerController(db *gorm.DB) *CustomerController {
return &CustomerController{svc: customerservice.NewCustomerService(db), db: db}
}
// List 客户列表 // Logan.Li
// List 客户列表(支持 product_id 筛选通知群体) // Logan.Li
func (ctrl *CustomerController) List(c *gin.Context) {
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
pageSize, _ := strconv.Atoi(c.DefaultQuery("page_size", "10"))
keyword := c.Query("keyword")
productID, _ := strconv.ParseUint(c.Query("product_id"), 10, 32)
customers, total, err := ctrl.svc.List(page, pageSize, keyword)
customers, total, err := ctrl.svc.List(page, pageSize, keyword, uint(productID))
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"code": 500, "message": err.Error()})
return
@@ -38,9 +40,10 @@ func (ctrl *CustomerController) List(c *gin.Context) {
}})
}
// GetAll 全部客户 // Logan.Li
// GetAll 全部客户(可选 product_id) // Logan.Li
func (ctrl *CustomerController) GetAll(c *gin.Context) {
customers, err := ctrl.svc.GetAll()
productID, _ := strconv.ParseUint(c.Query("product_id"), 10, 32)
customers, err := ctrl.svc.GetAll(uint(productID))
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"code": 500, "message": err.Error()})
return
@@ -61,15 +64,7 @@ func (ctrl *CustomerController) Get(c *gin.Context) {
// Create 创建客户 // Logan.Li
func (ctrl *CustomerController) Create(c *gin.Context) {
var req struct {
Name string `json:"name" binding:"required"`
Company string `json:"company"`
Email string `json:"email" binding:"omitempty,email"`
Phone string `json:"phone"`
Address string `json:"address"`
Notes string `json:"notes"`
Status *int `json:"status"`
}
var req dto.CustomerCreate
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"code": 400, "message": "参数错误: " + err.Error()})
return
@@ -86,15 +81,7 @@ func (ctrl *CustomerController) Create(c *gin.Context) {
// Update 更新客户 // Logan.Li
func (ctrl *CustomerController) Update(c *gin.Context) {
id, _ := strconv.ParseUint(c.Param("id"), 10, 32)
var req struct {
Name string `json:"name"`
Company string `json:"company"`
Email string `json:"email" binding:"omitempty,email"`
Phone string `json:"phone"`
Address string `json:"address"`
Notes string `json:"notes"`
Status *int `json:"status"`
}
var req dto.CustomerUpdate
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"code": 400, "message": "参数错误"})
return