@@ -290,11 +290,16 @@ func RespondToAddressProposal(c *gin.Context) {
|
||||
|
||||
// La colonne proposed_address est vidée par RespondToAddressProposal dès
|
||||
// qu'elle est traitée : on la lit avant l'appel pour pouvoir regéocoder la
|
||||
// nouvelle adresse en cas d'acceptation.
|
||||
// nouvelle adresse en cas d'acceptation. On récupère aussi le livreur
|
||||
// assigné : ProposeAddressChange autorise un changement d'adresse même en
|
||||
// "en_route" (voir commands.go ~L236-240), donc un livreur peut déjà être
|
||||
// en train de rouler vers l'ancienne adresse au moment de l'acceptation.
|
||||
var proposedAddress string
|
||||
var livreurAssign string
|
||||
if req.Accepted {
|
||||
if command, err := database.GetCommandByID(commandID); err == nil {
|
||||
proposedAddress, _ = command["proposed_address"].(string)
|
||||
livreurAssign, _ = command["livreur_assign"].(string)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,6 +310,19 @@ func RespondToAddressProposal(c *gin.Context) {
|
||||
|
||||
if req.Accepted && proposedAddress != "" {
|
||||
updateCommandDestinationCoords(database, geoService, commandID, proposedAddress)
|
||||
|
||||
// L'ETA en cache correspond au trajet vers l'ancienne destination —
|
||||
// on l'invalide pour forcer un recalcul sur les nouvelles coordonnées.
|
||||
db.Redis.Del(db.RedisCtx, fmt.Sprintf("command:eta:%d", commandID))
|
||||
|
||||
// Sans cette notification, le livreur déjà en route continuerait à
|
||||
// naviguer vers l'ancienne adresse sans savoir que la destination a
|
||||
// changé en base.
|
||||
if livreurAssign != "" {
|
||||
clientOrderID := database.GetClientOrderID(commandID)
|
||||
livreurMsg := fmt.Sprintf("⚠️ Le client a changé l'adresse de livraison de la commande #%d : %s. Merci de mettre à jour votre itinéraire.", clientOrderID, proposedAddress)
|
||||
database.NotifyLivreur(livreurAssign, commandID, "address_changed", livreurMsg)
|
||||
}
|
||||
}
|
||||
|
||||
action := "refusée"
|
||||
|
||||
@@ -73,10 +73,11 @@ func GetMyDeliveries(c *gin.Context) {
|
||||
itemsSummary := make([]gin.H, len(items))
|
||||
for j, item := range items {
|
||||
itemsSummary[j] = gin.H{
|
||||
"produit": item["produit"],
|
||||
"quantite": item["quantite"],
|
||||
"prix": item["prix"],
|
||||
"is_reward": item["is_reward"],
|
||||
"produit": item["produit"],
|
||||
"quantite": item["quantite"],
|
||||
"prix": item["prix"],
|
||||
"promo_discount": item["promo_discount"],
|
||||
"is_reward": item["is_reward"],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,10 +156,11 @@ func GetDeliveryDetails(c *gin.Context) {
|
||||
itemsSummary := make([]gin.H, len(items))
|
||||
for i, item := range items {
|
||||
itemsSummary[i] = gin.H{
|
||||
"produit": item["produit"],
|
||||
"quantite": item["quantite"],
|
||||
"prix": item["prix"],
|
||||
"is_reward": item["is_reward"],
|
||||
"produit": item["produit"],
|
||||
"quantite": item["quantite"],
|
||||
"prix": item["prix"],
|
||||
"promo_discount": item["promo_discount"],
|
||||
"is_reward": item["is_reward"],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,6 +175,7 @@ func GetDeliveryDetails(c *gin.Context) {
|
||||
"total_prix": command["total_prix"],
|
||||
"referral_used": command["referral_used"],
|
||||
"created_at": command["created_at"],
|
||||
"is_new_client": isFirstOrder(command["client_order_number"]),
|
||||
"client_info": clientInfo,
|
||||
"items": itemsSummary,
|
||||
"items_count": len(items),
|
||||
@@ -623,3 +626,9 @@ func GetMyDeliveryStats(c *gin.Context) {
|
||||
"today_revenue": todayRow.Revenue,
|
||||
})
|
||||
}
|
||||
|
||||
// isFirstOrder indique si la commande est la toute première du client (client_order_id == 1).
|
||||
func isFirstOrder(v any) bool {
|
||||
n, _ := strconv.Atoi(fmt.Sprintf("%v", v))
|
||||
return n == 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user