批量更新功能
This commit is contained in:
@@ -134,8 +134,18 @@ func (c *BackendErpSupplierController) List() {
|
||||
return
|
||||
}
|
||||
|
||||
// 标记「同时也是客户」:同一家单位可能既是供应商又是客户,列表上直接可见,避免重复转化
|
||||
alsoCustomer := partyNameExists(fmt.Sprintf("%d", claims.TenantId), "customer", collectSupplierNames(list))
|
||||
rows := make([]supplierListRow, 0, len(list))
|
||||
for _, r := range list {
|
||||
rows = append(rows, supplierListRow{
|
||||
TenantCrmSupplier: r,
|
||||
AlsoCustomer: alsoCustomer[strings.TrimSpace(r.SupplierName)],
|
||||
})
|
||||
}
|
||||
|
||||
c.supplierOk(map[string]interface{}{
|
||||
"list": list,
|
||||
"list": rows,
|
||||
"total": total,
|
||||
"page": page,
|
||||
"pageSize": pageSize,
|
||||
@@ -170,6 +180,48 @@ func (c *BackendErpSupplierController) Detail() {
|
||||
c.supplierOk(supplier)
|
||||
}
|
||||
|
||||
// ConvertToCustomer POST /backend/erp/supplier/:id/convert-customer
|
||||
// 供应商转客户:把供应商档案(含联系人)复制一套到客户库。
|
||||
// 同一家单位可能既是客户又是供应商,因此原供应商记录保留、不删除;
|
||||
// 客户库已存在同名企业时不重复建档,只把联系人补同步过去。
|
||||
func (c *BackendErpSupplierController) ConvertToCustomer() {
|
||||
claims, err := c.supplierClaims()
|
||||
if err != nil {
|
||||
c.supplierJsonErr(401, 401, err.Error())
|
||||
return
|
||||
}
|
||||
id, _ := strconv.ParseUint(c.Ctx.Input.Param(":id"), 10, 64)
|
||||
if id == 0 {
|
||||
c.supplierJsonErr(400, 400, "无效的ID")
|
||||
return
|
||||
}
|
||||
|
||||
tenantID := fmt.Sprintf("%d", claims.TenantId)
|
||||
var supplier models.TenantCrmSupplier
|
||||
if err := models.Orm.QueryTable(new(models.TenantCrmSupplier)).
|
||||
Filter("id", id).
|
||||
Filter("tenant_id", tenantID).
|
||||
Filter("delete_time__isnull", true).
|
||||
One(&supplier); err != nil {
|
||||
c.supplierJsonErr(404, 404, "供应商未找到")
|
||||
return
|
||||
}
|
||||
|
||||
existed, customerID, inserted, merged, cerr := convertSupplierToCustomer(tenantID, &supplier, claims)
|
||||
if cerr != nil {
|
||||
c.supplierJsonErr(500, 500, cerr.Error())
|
||||
return
|
||||
}
|
||||
c.supplierOk(map[string]interface{}{
|
||||
"id": customerID,
|
||||
"existed": existed,
|
||||
"contacts": map[string]interface{}{
|
||||
"inserted": inserted,
|
||||
"merged": merged,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// Create POST /backend/erp/supplier
|
||||
func (c *BackendErpSupplierController) Create() {
|
||||
claims, err := c.supplierClaims()
|
||||
|
||||
Reference in New Issue
Block a user