where("is_agency", 1)->cursor(); foreach ($agents as $agent) { echo $agent['id'] . "\r\n"; $start_time = Carbon::parse($startDate)->startOfWeek(Carbon::MONDAY)->toDateTimeString(); $end_time = Carbon::parse($startDate)->endOfWeek(Carbon::SUNDAY)->toDateTimeString(); $subscribe_performance = $this->get_subscribe_performance($agent, $start_time, $end_time); $contract_performance = $this->get_contract_performance($agent, $start_time, $end_time); $option_performance = $this->get_option_performance($agent, $start_time, $end_time); $subscribe_rebate_rate = $agent['subscribe_rebate_rate'] ?? 0.85; $contract_rebate_rate = $agent['contract_rebate_rate'] ?? 0.85; $option_rebate_rate = $agent['option_rebate_rate'] ?? 0.85; $subscribe_rebate = PriceCalculate($subscribe_performance, '*', $subscribe_rebate_rate, 8); $contract_rebate = PriceCalculate($contract_performance, '*', $contract_rebate_rate, 8); $option_rebate = PriceCalculate($option_performance, '*', $option_rebate_rate, 8); Performance::query()->updateOrCreate( ['aid' => $agent['id'], 'start_time' => $start_time, 'end_time' => $end_time], [ 'subscribe_performance' => $subscribe_performance, 'contract_performance' => $contract_performance, 'option_performance' => $option_performance, 'subscribe_rebate_rate' => $subscribe_rebate_rate, 'contract_rebate_rate' => $contract_rebate_rate, 'option_rebate_rate' => $option_rebate_rate, 'subscribe_rebate' => $subscribe_rebate, 'contract_rebate' => $contract_rebate, 'option_rebate' => $option_rebate, ] ); } } // 申购业绩 private function get_subscribe_performance($agent, $start_time, $end_time) { $start = strtotime($start_time); $end = strtotime($end_time); return UserSubscribeRecord::query()->whereHas('user', function ($q) use ($agent) { $q->where('is_system', 0)->where('referrer', $agent['id']); }) ->whereBetween('subscription_time', [$start, $end]) ->where('payment_currency', 'USDT') ->sum('payment_amount'); } // 合约业绩 private function get_contract_performance($agent, $start_time, $end_time) { $profit = ContractEntrust::query() ->where('order_type', 2) ->whereHas('user', function ($q) use ($agent) { $q->where('is_system', 0)->where('referrer', $agent['id']); }) ->whereDate('created_at', '>=', $start_time)->whereDate('created_at', '<=', $end_time) ->where('status', ContractEntrust::status_completed) ->sum('profit'); if ($profit < 0) { return abs($profit); } else { return 0; } } // 期权业绩 private function get_option_performance($agent, $start_time, $end_time) { // 这里分成2部分 用户亏的直接累加 用户赚的需要减去赌注=平台亏损 $builder = OptionSceneOrder::query()->whereHas('user', function ($q) use ($agent) { $q->where('is_system', 0)->where('referrer', $agent['id']); }) ->whereDate('created_at', '>=', $start_time)->whereDate('created_at', '<=', $end_time) ->where('bet_coin_name', 'USDT')->where('status', 2); $sum1 = (clone $builder)->where('delivery_amount', '<', 0)->sum('delivery_amount'); // 用户亏损 $sum2 = (clone $builder)->where('delivery_amount', '>', 0)->sum('delivery_amount'); // 用户盈利 $sum3 = (clone $builder)->where('delivery_amount', '>', 0)->sum('bet_amount'); // 用户押注 return abs($sum1 + ($sum2 - $sum3)); } }