48 lines
1.2 KiB
PHP
48 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace app\adminapi\logic\match;
|
|
|
|
use app\common\logic\BaseLogic;
|
|
use app\common\model\league\League;
|
|
|
|
class LeagueLogic extends BaseLogic
|
|
{
|
|
public static function detail($params): array
|
|
{
|
|
return League::findOrEmpty($params['id'])->toArray();
|
|
}
|
|
|
|
public static function edit(array $params): bool
|
|
{
|
|
try {
|
|
$league = League::findOrEmpty($params['id']);
|
|
if ($league->isEmpty()) {
|
|
self::setError('联赛不存在');
|
|
return false;
|
|
}
|
|
|
|
$data = [];
|
|
foreach (['label', 'icon', 'sort', 'is_show'] as $field) {
|
|
if (array_key_exists($field, $params)) {
|
|
$data[$field] = $params[$field];
|
|
}
|
|
}
|
|
if (array_key_exists('is_hot', $params)) {
|
|
$data['is_hot'] = $league->type === 'league' ? (int)$params['is_hot'] : 0;
|
|
}
|
|
if (!empty($data)) {
|
|
$league->save($data);
|
|
}
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
self::setError($e->getMessage());
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public static function delete(array $params)
|
|
{
|
|
League::destroy($params['id']);
|
|
}
|
|
}
|