优化合同个管理和产品管理相关功能

This commit is contained in:
2026-09-12 23:29:45 +08:00
parent 2b1874943f
commit 4455b95e37
92 changed files with 5367 additions and 3144 deletions
+33 -3
View File
@@ -287,9 +287,20 @@ func (c *BackendCrmAttachController) List() {
includeSource := strings.TrimSpace(c.GetString("include_source")) == "1"
tenantID := pipelineTenantID(claims)
page, _ := strconv.Atoi(c.GetString("page"))
pageSize, _ := strconv.Atoi(c.GetString("pageSize"))
if page < 1 {
page = 1
}
if pageSize < 1 {
pageSize = 20
}
offset := (page - 1) * pageSize
var list []models.TenantCrmAttach
total := 0
if includeSource && relatedType != "" && relatedID != "" && relatedID != "0" {
// 链路模式:线索 → 商机 → 项目 累积
// 链路模式:线索 → 商机 → 项目 累积(跨表汇总后内存分页)
rid, _ := strconv.ParseUint(relatedID, 10, 64)
rt, _ := strconv.Atoi(relatedType)
for _, r := range relatedChain(tenantID, int8(rt), rid) {
@@ -303,6 +314,16 @@ func (c *BackendCrmAttachController) List() {
list = append(list, rows...)
}
sort.Slice(list, func(i, j int) bool { return list[i].ID > list[j].ID })
total = len(list)
start := offset
if start > total {
start = total
}
end := start + pageSize
if end > total {
end = total
}
list = list[start:end]
} else {
cond := orm.NewCondition().And("tenant_id", tenantID).And("delete_time__isnull", true)
if relatedType != "" {
@@ -311,9 +332,18 @@ func (c *BackendCrmAttachController) List() {
if relatedID != "" {
cond = cond.And("related_id", relatedID)
}
_, _ = models.Orm.QueryTable(new(models.TenantCrmAttach)).SetCond(cond).OrderBy("-id").All(&list)
qs := models.Orm.QueryTable(new(models.TenantCrmAttach)).SetCond(cond)
if cnt, err := qs.Count(); err == nil {
total = int(cnt)
}
_, _ = qs.OrderBy("-id").Limit(pageSize, offset).All(&list)
}
pipelineOk(&c.Controller, map[string]interface{}{"list": list, "total": len(list)})
pipelineOk(&c.Controller, map[string]interface{}{
"list": list,
"total": total,
"page": page,
"pageSize": pageSize,
})
}
// Add POST /backend/crm/attach/add