| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- namespace App\Game;
- use App\Http\helper\NumConfig;
- use App\Services\ExtensionCopy;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Redis;
- class AgentUser extends Model
- {
- const TABLE = 'webgame.AgentUser';
- protected $connection='mysql';
- protected $primaryKey='GlobalUID';
- public $incrementing = false; // 非自增主键
- protected $keyType = 'string'; // 主键类型为字符串
- protected $table = self::TABLE;
- public $timestamps = false;
- protected $fillable = [
- 'GlobalUID', 'UserID', 'LinkCode','LinkRewards', 'Higher1GUID', 'Higher2GUID', 'Higher3GUID', 'Higher4GUID',
- 'Higher1ID', 'Higher2ID', 'Higher3ID', 'Higher4ID', 'TotalReward1', 'TotalReward2',
- 'TotalReward3', 'TotalReward4', 'downCount1', 'downCount2', 'downCount3', 'downCount4','RewardRate','RewardLimit'
- ];
- // 推广员奖励
- public static function reward($UserID, $amount, $orderSn)
- {
- $UserAgent = self::query()->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);
- }
- }
|