添加猜胜负逻辑

main
liutk 2024-07-08 16:24:54 +08:00
parent 09f9309b3a
commit f2b05925e4
6 changed files with 66 additions and 4 deletions

View File

@ -12,7 +12,7 @@ use Slowlyo\OwlAdmin\Controllers\AdminController;
use App\Services\Admin\ActivityService; use App\Services\Admin\ActivityService;
use App\Traits\CustomActionTrait; use App\Traits\CustomActionTrait;
use App\Admin\Components; use App\Admin\Components;
use App\Enums\Score; use App\Enums\{Score, ScoreMin};
use App\Models\Activity; use App\Models\Activity;
use Illuminate\Http\Request; use Illuminate\Http\Request;
@ -156,6 +156,7 @@ class ActivityController extends AdminController
'away_logo'=>'${away_logo}', 'away_logo'=>'${away_logo}',
'game_at'=>'${game_at}', 'game_at'=>'${game_at}',
'mark'=>'${mark}', 'mark'=>'${mark}',
'score_type'=>'${score_type}',
], ],
]) ])
->body([ ->body([
@ -170,6 +171,10 @@ class ActivityController extends AdminController
Components::make()->imageControl('away_logo', __('admin.activity_games.away_logo')), Components::make()->imageControl('away_logo', __('admin.activity_games.away_logo')),
]), ]),
amis()->DateTimeControl('game_at', __('admin.activity_games.game_at'))->format('YYYY-MM-DD HH:mm:ss')->required(true), amis()->DateTimeControl('game_at', __('admin.activity_games.game_at'))->format('YYYY-MM-DD HH:mm:ss')->required(true),
amis()->RadiosControl('score_type', __('admin.activity_games.score_type'))->options([
1=>'猜比分',
2=>'猜胜负',
])->selectFirst()->required(),
Components::make()->sortControl('mark', __('admin.activity_games.mark'))->required(true), Components::make()->sortControl('mark', __('admin.activity_games.mark'))->required(true),
]) ])
])->size('lg') ])->size('lg')
@ -210,6 +215,10 @@ class ActivityController extends AdminController
Components::make()->cropImageControl('away_logo', __('admin.activity_games.away_logo')), Components::make()->cropImageControl('away_logo', __('admin.activity_games.away_logo')),
]), ]),
amis()->DateTimeControl('game_at', __('admin.activity_games.game_at'))->format('YYYY-MM-DD HH:mm:ss')->required(true), amis()->DateTimeControl('game_at', __('admin.activity_games.game_at'))->format('YYYY-MM-DD HH:mm:ss')->required(true),
amis()->RadiosControl('score_type', __('admin.activity_games.score_type'))->options([
1=>'猜比分',
2=>'猜胜负',
])->selectFirst()->required()->disabledOn('${state > 0}'),
Components::make()->sortControl('mark', __('admin.activity_games.mark'))->required(true), Components::make()->sortControl('mark', __('admin.activity_games.mark'))->required(true),
]) ])
])->size('lg')) ])->size('lg'))
@ -239,7 +248,9 @@ class ActivityController extends AdminController
->api('post:' .admin_url('activity_games/${id}/finish')) ->api('post:' .admin_url('activity_games/${id}/finish'))
->body([ ->body([
amis()->SelectControl('score', __('admin.activity_games.score')) amis()->SelectControl('score', __('admin.activity_games.score'))
->options(Score::options())->required(), ->options(Score::options())->required()->visibleOn('${score_type == 1}'),
amis()->SelectControl('score', __('admin.activity_games.score'))
->options(ScoreMin::options())->required()->visibleOn('${score_type == 2}'),
]) ])
]))->visibleOn('${state == 1}'), ]))->visibleOn('${state == 1}'),
]), ]),

View File

@ -0,0 +1,19 @@
<?php
namespace App\Enums;
enum ScoreMin: string
{
case WIN = '胜';
case DRAW = '平';
case LOSE = '负';
public static function options()
{
$options = [];
foreach(self::cases() as $score){
$options[$score->value] = $score->value;
}
return $options;
}
}

View File

@ -28,6 +28,7 @@ class ActivityGameResource extends JsonResource
'game_day' => $this->game_at->format('Y-m-d'), 'game_day' => $this->game_at->format('Y-m-d'),
'game_at_comparison_now' => $this->state < 2 ? now()->gte($this->game_at) : true, 'game_at_comparison_now' => $this->state < 2 ? now()->gte($this->game_at) : true,
'mark' => $this->mark, 'mark' => $this->mark,
'score_type' => $this->score_type ?? 1,//1为猜比分2为猜胜负
'game_score' => $this->score, 'game_score' => $this->score,
'has_guess' => !$this->logs->isEmpty() ? ($this->logs[0]->score):false, 'has_guess' => !$this->logs->isEmpty() ? ($this->logs[0]->score):false,
'has_guess_right' => !$this->logs->isEmpty() ? ($this->logs[0]->is_right):false, 'has_guess_right' => !$this->logs->isEmpty() ? ($this->logs[0]->is_right):false,

View File

@ -15,7 +15,7 @@ class ActivityGame extends Model
]; ];
protected $fillable = [ protected $fillable = [
'state', 'score', 'state', 'score', 'score_type'
]; ];
public function scopeShow($q) public function scopeShow($q)

View File

@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('activity_games', function (Blueprint $table) {
//
$table->unsignedTinyInteger('score_type')->default(1)->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('activity_games', function (Blueprint $table) {
//
$table->dropColumn(['score_type']);
});
}
};

View File

@ -351,7 +351,8 @@ return [
'game_at' => '比赛时间', 'game_at' => '比赛时间',
'mark' => '奖励', 'mark' => '奖励',
'score' => '比分', 'score' => '比分',
'state' => '状态' 'state' => '状态',
'score_type' => '竞猜方式'
], ],
'activity_gifts' => [ 'activity_gifts' => [
'name' => '奖品名称', 'name' => '奖品名称',