20-02-2026
This commit is contained in:
parent
a8b395e20d
commit
a00c42e770
252 changed files with 28785 additions and 8907 deletions
119
app/Console/Commands/FixPaymentLinkStatus.php
Normal file
119
app/Console/Commands/FixPaymentLinkStatus.php
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\ShoppingInstance;
|
||||
use App\Models\ShoppingPayment;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class FixPaymentLinkStatus extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'payment:fix-link-status {--dry-run : Run without making changes}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Fix payment link status for paid orders that have incorrect status in shopping_instances';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$isDryRun = $this->option('dry-run');
|
||||
|
||||
if ($isDryRun) {
|
||||
$this->info(' DRY RUN MODE - No changes will be made');
|
||||
$this->newLine();
|
||||
}
|
||||
|
||||
$this->info('🔎 Searching for payment links with incorrect status...');
|
||||
$this->newLine();
|
||||
|
||||
// Find all ShoppingPayments with identifier that are paid
|
||||
$paidPayments = ShoppingPayment::whereNotNull('identifier')
|
||||
->whereHas('shopping_order', function ($query) {
|
||||
$query->where('paid', 1)
|
||||
->where('txaction', 'paid');
|
||||
})
|
||||
->with(['shopping_order'])
|
||||
->get();
|
||||
|
||||
$this->info("Found {$paidPayments->count()} paid payments with identifiers");
|
||||
$this->newLine();
|
||||
|
||||
$fixed = 0;
|
||||
$skipped = 0;
|
||||
$errors = 0;
|
||||
|
||||
foreach ($paidPayments as $payment) {
|
||||
$identifier = $payment->identifier;
|
||||
|
||||
// Find the corresponding ShoppingInstance
|
||||
$instance = ShoppingInstance::where('identifier', $identifier)->first();
|
||||
|
||||
if (! $instance) {
|
||||
$this->warn("⚠️ ShoppingInstance not found for identifier: {$identifier}");
|
||||
$errors++;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if status needs to be updated
|
||||
if ($instance->status < 10) {
|
||||
$oldStatus = $instance->status;
|
||||
$oldStatusName = $instance->getStatus();
|
||||
|
||||
if (! $isDryRun) {
|
||||
$instance->status = 10; // link_paid
|
||||
$instance->save();
|
||||
}
|
||||
|
||||
$this->line(sprintf(
|
||||
'%s Payment #%d: %s → %s (Order #%d, Amount: %s)',
|
||||
$isDryRun ? '📋' : '✅',
|
||||
$payment->id,
|
||||
$oldStatusName." ($oldStatus)",
|
||||
'link_paid (10)',
|
||||
$payment->shopping_order_id,
|
||||
$payment->getPaymentAmount()
|
||||
));
|
||||
|
||||
$fixed++;
|
||||
} else {
|
||||
$skipped++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->newLine();
|
||||
$this->info('📊 Summary:');
|
||||
$this->table(
|
||||
['Status', 'Count'],
|
||||
[
|
||||
['Fixed/Would fix', $fixed],
|
||||
['Already correct', $skipped],
|
||||
['Errors', $errors],
|
||||
['Total processed', $paidPayments->count()],
|
||||
]
|
||||
);
|
||||
|
||||
if ($isDryRun && $fixed > 0) {
|
||||
$this->newLine();
|
||||
$this->warn('⚠️ This was a DRY RUN. Run without --dry-run to apply changes.');
|
||||
}
|
||||
|
||||
if (! $isDryRun && $fixed > 0) {
|
||||
$this->newLine();
|
||||
$this->info("✨ Successfully updated {$fixed} payment link(s)!");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue