From af769258d2015ab1b3daeaeea70361bf4f46da2b Mon Sep 17 00:00:00 2001 From: "hangyu.tao" Date: Fri, 16 Jan 2026 16:28:50 +0800 Subject: [PATCH] fix_trial --- frontend/js/main.js | 7 ++++--- internal/handlers/trial_period_handler.go | 20 ++++++++------------ 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/frontend/js/main.js b/frontend/js/main.js index 6807117..4c4e95f 100644 --- a/frontend/js/main.js +++ b/frontend/js/main.js @@ -1096,14 +1096,15 @@ document.addEventListener('DOMContentLoaded', function () { const customersData = await customersResponse.json(); const customersMap = customersData.customerMap || {}; - // Collect unique trial customer names + // Collect unique trial customer names - only include valid customer names const trialCustomerNames = new Set(); trialPeriods.forEach(period => { - // Check if customerId is in map, otherwise use customerId directly as name - const customerName = customersMap[period.customerId] || period.customerId; + // Only add if customerId exists in map (valid customer) + const customerName = customersMap[period.customerId]; if (customerName) { trialCustomerNames.add(customerName); } + // If customerId not in map, skip it (deleted customer) - don't add UUID as name }); // Update total customers to include trial customers diff --git a/internal/handlers/trial_period_handler.go b/internal/handlers/trial_period_handler.go index 7eca434..a054951 100644 --- a/internal/handlers/trial_period_handler.go +++ b/internal/handlers/trial_period_handler.go @@ -343,26 +343,22 @@ func (h *TrialPeriodHandler) GetTrialCustomerList(w http.ResponseWriter, r *http } } - // Get unique customer names + // Get unique customer names (only include customers that exist in storage) seenNames := make(map[string]bool) var customerNames []string for customerID := range customerIDs { // Try to get customer name from customer storage - var customerName string customer, err := h.customerStorage.GetCustomerByID(customerID) if err == nil && customer != nil && customer.CustomerName != "" { - customerName = customer.CustomerName - } else { - // If customer not found, use customer ID as name - customerName = customerID - } - - // Add to list if not seen before - if !seenNames[customerName] { - customerNames = append(customerNames, customerName) - seenNames[customerName] = true + customerName := customer.CustomerName + // Add to list if not seen before + if !seenNames[customerName] { + customerNames = append(customerNames, customerName) + seenNames[customerName] = true + } } + // Skip customers that don't exist in storage (don't show ID as name) } w.Header().Set("Content-Type", "application/json")