- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 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]
Комментарии (1) RSS