Changeset View
Changeset View
Standalone View
Standalone View
src/app/Console/Commands/Data/Stats/CollectorCommand.php
<?php | <?php | ||||
namespace App\Console\Commands\Data\Stats; | namespace App\Console\Commands\Data\Stats; | ||||
use App\Http\Controllers\API\V4\Admin\StatsController; | use App\Http\Controllers\API\V4\Admin\StatsController; | ||||
use App\Providers\PaymentProvider; | use App\Payment; | ||||
use App\User; | use App\User; | ||||
use Illuminate\Console\Command; | use Illuminate\Console\Command; | ||||
use Illuminate\Support\Facades\DB; | use Illuminate\Support\Facades\DB; | ||||
class CollectorCommand extends Command | class CollectorCommand extends Command | ||||
{ | { | ||||
/** | /** | ||||
* The name and signature of the console command. | * The name and signature of the console command. | ||||
Show All 24 Lines | class CollectorCommand extends Command | ||||
*/ | */ | ||||
protected function collectPayersCount(): void | protected function collectPayersCount(): void | ||||
{ | { | ||||
$tenant_id = \config('app.tenant_id'); | $tenant_id = \config('app.tenant_id'); | ||||
// A subquery to get the all wallets with a successful payment | // A subquery to get the all wallets with a successful payment | ||||
$payments = DB::table('payments') | $payments = DB::table('payments') | ||||
->selectRaw('distinct wallet_id') | ->selectRaw('distinct wallet_id') | ||||
->where('status', PaymentProvider::STATUS_PAID); | ->where('status', Payment::STATUS_PAID); | ||||
// A subquery to get users' wallets (by entitlement) - one record per user | // A subquery to get users' wallets (by entitlement) - one record per user | ||||
$wallets = DB::table('entitlements') | $wallets = DB::table('entitlements') | ||||
->selectRaw("min(wallet_id) as id, entitleable_id as user_id") | ->selectRaw("min(wallet_id) as id, entitleable_id as user_id") | ||||
->where('entitleable_type', User::class) | ->where('entitleable_type', User::class) | ||||
->groupBy('entitleable_id'); | ->groupBy('entitleable_id'); | ||||
// Count all non-degraded and non-deleted users with any successful payment | // Count all non-degraded and non-deleted users with any successful payment | ||||
Show All 28 Lines |