where('UserID', $UserID)->first(); if ($UserAgent) { // 上级ID $Higher1ID = $UserAgent->Higher1ID; // 上上级ID $Higher2ID = $UserAgent->Higher2ID; // 设置默认值 $DirectRebate1 = $DirectRebate2 = 0; // 1、找出充值用户上级ID if ($Higher1ID > 0) { // 充值金额 * 百分比例 $AgentRebateRatio1 = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')->where('StatusName', 'AgentRebateRatio1')->select('StatusValue')->first()->StatusValue / NumConfig::NUM_VALUE ?? 0; $DirectRebate1 = $amount * $AgentRebateRatio1; $rKey = sprintf(ExtensionCopy::RECHARGE_PEOPLE_SETS, $Higher1ID); Redis::sAdd($rKey, $UserID); Redis::expire($rKey, 86400*60); $rKey = sprintf(ExtensionCopy::RECHARGE, $Higher1ID); Redis::incr($rKey, $amount); Redis::expire($rKey, 86400*60); self::add($Higher1ID, $Higher2ID, $DirectRebate1, $UserID, $orderSn); $dailyKey = 'daily_spread_rebate_stat_'.date('Ymd'); Redis::incr($dailyKey, $DirectRebate1); Redis::expire($dailyKey, 86400*3); } // 2、找出上上级ID if ($Higher2ID > 0) { // 充值金额 * 百分比例 $AgentRebateRatio2 = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')->where('StatusName', 'AgentRebateRatio2')->select('StatusValue')->first()->StatusValue / NumConfig::NUM_VALUE ?? 0; $DirectRebate2 = $amount * $AgentRebateRatio2; $rKey = sprintf(ExtensionCopy::RECHARGE_PEOPLE_SETS, $Higher2ID); Redis::sAdd($rKey, $UserID); Redis::expire($rKey, 86400*60); $rKey = sprintf(ExtensionCopy::RECHARGE, $Higher2ID); Redis::incr($rKey, $amount); Redis::expire($rKey, 86400*60); self::add($Higher2ID, 0, $DirectRebate2, $UserID, $orderSn, 2); $dailyKey = 'daily_spread_rebate_stat_'.date('Ymd'); Redis::incr($dailyKey, $DirectRebate2); Redis::expire($dailyKey, 86400*3); } // 修改推广奖励数据 $data = [ 'TotalReward1' => $DirectRebate1 + $UserAgent->TotalReward1, 'Balance1' => $DirectRebate1 + $UserAgent->Balance1, 'TotalReward2' => $DirectRebate2 + $UserAgent->TotalReward2, 'Balance2' => $DirectRebate2 + $UserAgent->Balance2, ]; DB::connection('write')->table('QPAccountsDB.dbo.UserAgent')->where('UserID', $UserID)->update($data); // 增加总奖励 $TotalReward = $DirectRebate1 + $DirectRebate2; DB::connection('write')->table('QPAccountsDB.dbo.SystemAgentReward')->increment('TotalReward', $TotalReward); } } public static function add($UserID, $SpreaderID, $DirectRebate, $SourceUserID, $OrderSn, $Level = 1, $orderIds = '', $Type = 3) { $data = [ 'UserID' => $UserID, 'SpreaderID' => $SpreaderID, 'DirectRebate' => $DirectRebate, 'SourceUserID' => $SourceUserID, 'OrderSn' => $OrderSn, 'Level' => $Level, 'orderIds' => $orderIds, 'Type' => $Type ]; self::query()->insert($data); } }