Files
lgp-admin-plus-api/app/Service/business/FactoryClassificationService.php
LQ bcf54c2727 初始化
缺陷:主题配色需要优化整体的同风格
2026-08-14 23:21:21 +08:00

84 lines
2.0 KiB
PHP

<?php
namespace App\Service\business;
use App\BaseApp\BaseService;
use App\Models\business\FactoryClassificationModel;
use App\Models\business\FactoryInfoModel;
use Exception;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
/**
* 工厂分类
*/
class FactoryClassificationService extends BaseService
{
public function __construct()
{
parent::__construct();
$this->model = FactoryClassificationModel::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 (FactoryInfoModel::whereIn('classification', $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]);
}
}