chore: update

This commit is contained in:
2026-03-19 19:56:51 +01:00
parent 3384ebded0
commit 7173266bb9
31 changed files with 3645 additions and 1942 deletions
+3 -10
View File
@@ -104,14 +104,8 @@ func (d *Database) AssignDeliveryPerson(commandID int, livreurUsername string) e
// ÉTAPE 3: Vérifier que la commande est assignable
// ============================================
// ✅ Vérifier si déjà assignée à un autre livreur
if currentLivreur.Valid && currentLivreur.String != "" && currentLivreur.String != livreurUsername {
log.Printf("❌ Commande déjà assignée à: %s", currentLivreur.String)
return fmt.Errorf("commande déjà assignée au livreur '%s'", currentLivreur.String)
}
// ✅ Vérifier le statut
validStatusesForAssignment := []string{"pending"}
// ✅ Vérifier le statut (pending ou assigned pour permettre la réassignation)
validStatusesForAssignment := []string{"pending", "assigned"}
isValidStatus := false
for _, vs := range validStatusesForAssignment {
if currentStatus == vs {
@@ -135,8 +129,7 @@ func (d *Database) AssignDeliveryPerson(commandID int, livreurUsername string) e
status = 'assigned',
updated_at = CURRENT_TIMESTAMP
WHERE id = $2
AND status IN ('pending')
AND (livreur_assign IS NULL OR livreur_assign = '' OR livreur_assign = $1)`
AND status IN ('pending', 'assigned')`
result, err := tx.Exec(updateQuery, livreurUsername, commandID)
if err != nil {
+42
View File
@@ -172,6 +172,48 @@ func (d *Database) NotifyAllAdminCabine(commandID int, clientUsername, deliveryA
log.Printf("📬 [ADMIN_NOTIF] Notif Redis + push (%d tokens) pour commande #%d", sent, commandID)
}
// NotifyAllAdminCabineAlert envoie une notification Redis + push à tous les admins/cabines
// lors du déclenchement d'une alerte par un livreur.
func (d *Database) NotifyAllAdminCabineAlert(alertID int, livreurUsername, alertMessage string) {
rows, err := d.Query(
`SELECT username, COALESCE(push_token, '') FROM users WHERE role IN ('admin','cabine')`,
)
if err != nil {
log.Printf("❌ [ALERT_NOTIF] Erreur lecture users admin/cabine: %v", err)
return
}
defer rows.Close()
title := "🚨 Alerte livreur"
body := fmt.Sprintf("%s — livreur : %s", alertMessage, livreurUsername)
notification := map[string]interface{}{
"alert_id": alertID,
"type": "alert",
"message": body,
"created_at": time.Now().Format(time.RFC3339),
"read": false,
}
notifJSON, _ := json.Marshal(notification)
sent := 0
for rows.Next() {
var username, token string
if err := rows.Scan(&username, &token); err != nil {
continue
}
notifKey := fmt.Sprintf("notifications:%s", username)
Redis.LPush(RedisCtx, notifKey, notifJSON)
Redis.Expire(RedisCtx, notifKey, 7*24*time.Hour)
if token != "" {
go sendExpoPushWithChannel(token, title, body, alertID, "alert", "orders")
sent++
}
}
log.Printf("🚨 [ALERT_NOTIF] Notif Redis + push (%d tokens) pour alerte #%d de %s", sent, alertID, livreurUsername)
}
// AddDeliveryRating ajoute une note pour un livreur
func (d *Database) AddDeliveryRating(livreurUsername string, commandID, rating int, comment string) error {
query := `
+4
View File
@@ -74,6 +74,7 @@ type AppSettings struct {
PointsPools []PointsPool `json:"points_pools"` // types de points personnalisés
ReferralEnabled bool `json:"referral_enabled"` // activer/désactiver le système de parrainage
CryptoPaymentEnabled bool `json:"crypto_payment_enabled"` // activer/désactiver le paiement crypto
CryptoOnly bool `json:"crypto_only"` // forcer le paiement crypto uniquement (pas d'espèces)
NowPaymentsAPIKey string `json:"nowpayments_api_key"` // clé API NowPayments
NowPaymentsIPNSecret string `json:"nowpayments_ipn_secret"` // secret IPN NowPayments
NowPaymentsCurrencies []string `json:"nowpayments_currencies"` // cryptos acceptées (ex: ["btc","eth","ltc"])
@@ -157,6 +158,8 @@ func (d *Database) GetSettings() (AppSettings, error) {
settings.ReferralEnabled = value == "true"
case "crypto_payment_enabled":
settings.CryptoPaymentEnabled = value == "true"
case "crypto_only":
settings.CryptoOnly = value == "true"
case "nowpayments_api_key":
settings.NowPaymentsAPIKey = value
case "nowpayments_ipn_secret":
@@ -232,6 +235,7 @@ func (d *Database) UpdateSettings(s AppSettings) error {
{"points_pools", string(poolsJSON)},
{"referral_enabled", boolStr(s.ReferralEnabled)},
{"crypto_payment_enabled", boolStr(s.CryptoPaymentEnabled)},
{"crypto_only", boolStr(s.CryptoOnly)},
{"nowpayments_api_key", s.NowPaymentsAPIKey},
{"nowpayments_ipn_secret", s.NowPaymentsIPNSecret},
{"nowpayments_currencies", string(currenciesJSON)},