Fix 5 bugs in chat and Telegram purchase flows
1. PublicChat::comprarPromoConSaldo — double saldo subtraction: $saldo->update()
already updates the model in memory, so $this->saldoUsuario = $saldo->valor - precio
was subtracting twice. Fixed by computing $nuevoSaldo before the update.
Also wrapped in DB::transaction (was missing unlike pagarConSaldo).
2. TelegramBotService::listServices — showed all services without filtering by the
user's rol_id, so users could see services with no plans for their role.
Now uses whereHas('tarifas', rol_id) like PublicChat and the web.
3. TelegramBotService::payWithSaldo — no DB::transaction; if saldo update failed
after historial was created, user got a free service. Now wrapped atomically.
4. TelegramBotService::buyPromoSaldo — same missing transaction + fecha_final was
hardcoded to 30 days instead of promo->dias. Both fixed.
5. TelegramBotService::showCredentials — N+1 queries loading cuentas lazily per
historial. Added cuentas to the eager-load list.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
1f25c31603
commit
2f5be9253b
@@ -909,10 +909,15 @@ class PublicChat extends Component
|
||||
'nombre_cliente' => $user->name,
|
||||
]);
|
||||
|
||||
Historial_cuenta::create(['historial_id' => $historial->id, 'cuenta_id' => $cuenta->id]);
|
||||
$cuenta->update(['estado' => 'ocupado']);
|
||||
$saldo->update(['valor' => $saldo->valor - $precio]);
|
||||
$this->saldoUsuario = $saldo->valor - $precio;
|
||||
$nuevoSaldo = $saldo->valor - $precio;
|
||||
|
||||
DB::transaction(function () use ($historial, $cuenta, $saldo, $nuevoSaldo) {
|
||||
Historial_cuenta::create(['historial_id' => $historial->id, 'cuenta_id' => $cuenta->id]);
|
||||
$cuenta->update(['estado' => 'ocupado']);
|
||||
$saldo->update(['valor' => $nuevoSaldo]);
|
||||
});
|
||||
|
||||
$this->saldoUsuario = $nuevoSaldo;
|
||||
|
||||
ChatMessage::create([
|
||||
'conversation_id' => $this->convId,
|
||||
|
||||
Reference in New Issue
Block a user