<?php
require_once __DIR__.'/_bootstrap.php';
use App\Core\AffiliateService;use App\Core\Database;
$job='rank_upgrade';$started=date('Y-m-d H:i:s');try{$members=Database::fetchAll('SELECT id FROM affiliate_members WHERE status IN ("active","suspended")');$changed=0;foreach($members as $m){$before=Database::safeFetchOne('SELECT rank_code FROM affiliate_members WHERE id=?',[$m['id']]);$after=AffiliateService::upgradeRank((int)$m['id']);if($after!==($before['rank_code']??null))$changed++;}cron_log($job,'success','Checked '.count($members).' members; '.$changed.' rank(s) changed.',$started);}catch(Throwable $e){cron_log($job,'failed',$e->getMessage(),$started);exit(1);}
