- 001
- 002
- 003
- 004
- 005
- 006
- 007
- 008
- 009
- 010
- 011
- 012
- 013
- 014
- 015
- 016
- 017
- 018
- 019
- 020
- 021
- 022
- 023
- 024
- 025
- 026
- 027
- 028
- 029
- 030
- 031
- 032
- 033
- 034
- 035
- 036
- 037
- 038
- 039
- 040
- 041
- 042
- 043
- 044
- 045
- 046
- 047
- 048
- 049
- 050
- 051
- 052
- 053
- 054
- 055
- 056
- 057
- 058
- 059
- 060
- 061
- 062
- 063
- 064
- 065
- 066
- 067
- 068
- 069
- 070
- 071
- 072
- 073
- 074
- 075
- 076
- 077
- 078
- 079
- 080
- 081
- 082
- 083
- 084
- 085
- 086
- 087
- 088
- 089
- 090
- 091
- 092
- 093
- 094
- 095
- 096
- 097
- 098
- 099
- 100
<?php
namespace App\Http\Controllers\api\v1;
use App\Http\Controllers\Controller;
use App\Http\Requests\StandartRequest;
use App\Models\Attractions;
use App\Models\AttractionSessionUpdates;
use App\Models\Locations;
use App\Models\SessionAttractionHistory;
use App\Models\SessionsHistoryAttractions;
use App\Models\SessionsHistoryGames;
use App\Models\Statistic\CountEndAttractionSessions;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
class AttractionEndSessionsCount extends Controller
{
public function endSessions(StandartRequest $request){
$this->now_time = Carbon::now();
$locations = Locations::where('user_id', '=', Auth::user()->id)->get();
if (count($locations) == 0){
return response()->json(['code' => "404", 'status' => 'error' , 'message'=> "locations not found"]);
}
try {
$request_from = $request->input('date_from');
$from = Carbon::parse($request_from."00:00:01");
$date_to = $request->input('date_to');
$to = Carbon::parse($date_to."11:59:59");
} catch (\Exception $exception){
return response()->json(['code' => "422", 'status' => 'error' , 'message'=> "dates have bad format, failed parse"]);
}
if ($from->timestamp > $to->timestamp){
return response()->json(['code' => "422", 'status' => 'error' , 'message'=> "the start date is larger than the end date"]);
}
$is_detail = $request->input('detail', 'daily');
$arr = $this->prepareLocationsAndAttrctions($locations, $from, $to, $is_detail);
$locations_ids = [];
foreach ($locations as $loc){
$locations_ids[] = $loc->id;
}
$history = CountEndAttractionSessions::query()->whereIn('location_id', array_values($locations_ids))
->whereBetween('day_date', [$from->startOfDay()->format('Y-m-d H:i:s'), $to->endOfDay()->format('Y-m-d H:i:s')])
->get();
$resp = $this->fillResults($arr ,$history, $is_detail);
if ($this->is_today){
$resp = $this->fillTodayResult($resp, $locations_ids, $is_detail);
}
return response()->json(['code' => "200", 'status' => 'success' , 'data'=> $resp]);
}
private function fillResults($arr ,$history, $is_detail){
foreach ($history as $value){
try {
if ($is_detail == 'hourly'){
$arr['locations'][$value->location_id]['attractions'][$value->attraction_id]['list'][$value->day_date->format('d-m-Y')][$value->day_date->format('H:00:00')] =
[
// общее количество игр
'total_count' => $value->total_count ?? 0,
//общее количество обновлений
'total_updates_count' => $value->total_updates_count ?? 0,
// количество пролонгейт обновлений
'add_time' => $value->add_time ?? 0,
// количество лет_гейм обновлений
'let_game_end' => $value->let_game_end ?? 0,
//средняя длина игры в секундах
'avg_duration' => [
'sum_seconds' => $value->avg_duration_second_sum,
'count_games' => $value->avg_duration_count_games,
],
// минимальная игра в секундах
'min_duration' => $value->min_duration,
// максимальная игра в секундах
'max_duration' => $value->max_duration,
];
for ($i = 1; $i <= 10; $i++){
$selector = 'max_players_'.$i;
$arr['locations'][$value->location_id]
['attractions'][$value->attraction_id]
['list'][$value->day_date->format('d-m-Y')]
[$value->day_date->format('H:00:00')]
['max_players'][$i] = (int)$value->$selector;
}
}elseif ($is_detail == 'daily') {
$arr['locations'][$value->location_id]['attractions'][$value->attraction_id]
['list'][$value->day_date->format('d-m-Y')]['total_count'] += $value->total_count;
$arr['locations'][$value->location_id]['attractions'][$value->attraction_id]
guest6 06.10.2023 00:53 # −2