feat: 产品/客户/订单批量删除;接入 GeoLite2 城市库(地理分布/激活记录/审计日志显示归属地);仪表盘趋势图美化
This commit is contained in:
1 parent
252ae14aef
commit
473dcd0aab
24 files changed
+431
-34
No files matched your search
@@ -0,0 +1,41 @@
|
||||
package customer
|
||||
|
||||
import "backend/internal/model"
|
||||
|
||||
// BatchDeleteResult 批量删除结果 // Logan.Li
|
||||
type BatchDeleteResult struct {
|
||||
Deleted int `json:"deleted"`
|
||||
Skipped int `json:"skipped"`
|
||||
Failed int `json:"failed"`
|
||||
SkippedIDs []uint `json:"skipped_ids,omitempty"`
|
||||
}
|
||||
|
||||
// BatchDelete 批量删除客户:名下有 License 的跳过;其余软删除并清理产品关联 // Logan.Li
|
||||
func (s *CustomerService) BatchDelete(ids []uint) (*BatchDeleteResult, error) {
|
||||
result := &BatchDeleteResult{}
|
||||
seen := map[uint]struct{}{}
|
||||
for _, id := range ids {
|
||||
if id == 0 {
|
||||
continue
|
||||
}
|
||||
if _, ok := seen[id]; ok {
|
||||
continue
|
||||
}
|
||||
seen[id] = struct{}{}
|
||||
|
||||
var licCount int64
|
||||
s.db.Model(&model.License{}).Where("customer_id = ?", id).Count(&licCount)
|
||||
if licCount > 0 {
|
||||
result.Skipped++
|
||||
result.SkippedIDs = append(result.SkippedIDs, id)
|
||||
continue
|
||||
}
|
||||
if err := s.db.Delete(&model.Customer{}, id).Error; err != nil {
|
||||
result.Failed++
|
||||
continue
|
||||
}
|
||||
s.db.Where("customer_id = ?", id).Delete(&model.CustomerProduct{})
|
||||
result.Deleted++
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
Reference in new issue
Block a user