1
0
Fork 0
party-rank-server/app/Admin/Services/UserScoreService.php

43 lines
1.3 KiB
PHP

<?php
namespace App\Admin\Services;
use App\Enums\CheckStatus;
use App\Exceptions\BaseException;
use App\ModelFilters\UserScoreFilter;
use App\Models\UserScore;
use Slowlyo\OwlAdmin\Admin;
class UserScoreService extends BaseService
{
protected array $withRelationships = ['user', 'type', 'checkUser'];
protected string $modelName = UserScore::class;
protected string $modelFilterName = UserScoreFilter::class;
public function check(UserScore $info, $options = [])
{
if ($info->check_status == CheckStatus::Success) {
throw new BaseException('已经审核过了');
}
$status = data_get($options, 'check_status');
$attributes = [
'check_status' => $status,
'check_remarks' => data_get($options, 'check_remarks'),
'check_user_id' => data_get($options, 'check_user_id', Admin::user()->id),
'check_at' => now(),
];
if ($status == CheckStatus::Success->value) {
$attributes['score'] = data_get($options, 'score', 0);
if ($attributes['score'] <= 0) {
throw new BaseException('得分必填');
}
PartyUserService::make()->incrementScore($info->user, $info->type?->key, $attributes['score']);
}
$info->update($attributes);
}
}