84 lines
1.9 KiB
PHP
84 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Service\business;
|
|
|
|
use App\BaseApp\BaseService;
|
|
use App\Models\business\CardClassModel;
|
|
use App\Models\business\ColorcardModel;
|
|
use Exception;
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
use Psr\Container\NotFoundExceptionInterface;
|
|
|
|
/**
|
|
* 色卡分类
|
|
*/
|
|
class CardClassService extends BaseService
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->model = CardClassModel::class;
|
|
$this->selectField = ['id', 'name', 'status', 'created_at', 'updated_at'];
|
|
$this->queryField = ['name' => 'like', 'status' => '='];
|
|
$this->orderBy = ['name' => 'id', 'sort' => 'asc'];
|
|
}
|
|
|
|
/**
|
|
* @throws ContainerExceptionInterface
|
|
* @throws NotFoundExceptionInterface
|
|
*/
|
|
public function list(): array
|
|
{
|
|
return $this->getPageList();
|
|
}
|
|
|
|
public function option(): mixed
|
|
{
|
|
return $this->getOption();
|
|
}
|
|
|
|
/**
|
|
* @throws Exception
|
|
*/
|
|
public function detail($id): mixed
|
|
{
|
|
return $this->getDetail($id);
|
|
}
|
|
|
|
public function create($params): mixed
|
|
{
|
|
return $this->insert($params);
|
|
}
|
|
|
|
/**
|
|
* @throws Exception
|
|
*/
|
|
public function update($id, $params): mixed
|
|
{
|
|
return $this->save($id, $params);
|
|
}
|
|
|
|
/**
|
|
* @throws Exception
|
|
*/
|
|
public function delete($id): mixed
|
|
{
|
|
$ids = array_values(array_filter(array_map('intval', is_array($id) ? $id : [$id])));
|
|
if (empty($ids)) {
|
|
$this->utils->errorThrow('参数错误');
|
|
}
|
|
if (ColorcardModel::whereIn('card_class', $ids)->where('deleted_at', 0)->exists()) {
|
|
$this->utils->errorThrow('该分类下仍有色卡,请先调整色卡分类');
|
|
}
|
|
return $this->del($ids);
|
|
}
|
|
|
|
/**
|
|
* @throws Exception
|
|
*/
|
|
public function status($id, $status): mixed
|
|
{
|
|
return $this->save($id, ['status' => (int) $status]);
|
|
}
|
|
}
|