guessing-miniprogram/app/Http/Resources/Api/ActivityGameResource.php

43 lines
1.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace App\Http\Resources\Api;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Http\Response;
class ActivityGameResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'activity_id' => $this->activity_id,
'name' => $this->name,
'home_field' => $this->home_field ??'',
'home_logo' => $this->home_logo ??'',
'away' => $this->away ??'',
'away_logo' => $this->away_logo ??'',
'game_at' => $this->game_at->format('Y-m-d H:i'),
'little_game_at' => $this->game_at->format('H:i'),
'game_day' => $this->game_at->format('Y-m-d'),
'game_at_comparison_now' => $this->state < 2 ? now()->gte($this->game_at) : true,
'mark' => $this->mark,
'score_type' => $this->score_type ?? 1,//1为猜比分2为猜胜负
'game_score' => $this->score,
'has_guess' => !$this->logs->isEmpty() ? ($this->logs[0]->score):false,
'has_guess_right' => !$this->logs->isEmpty() ? ($this->logs[0]->is_right):false,
'state' => $this->state,
];
}
public function with($request)
{
return ['code' => Response::HTTP_OK, 'message' => ''];
}
}