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

83 lines
1.9 KiB
PHP

<?php
namespace App\Service\business;
use App\BaseApp\BaseService;
use App\Models\business\ColorcardModel;
use App\Models\business\CompanyModel;
use Exception;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
/**
* 色卡所属公司
*/
class CompanyService extends BaseService
{
public function __construct()
{
parent::__construct();
$this->model = CompanyModel::class;
$this->selectField = ['id', 'name', 'phone', 'address', 'status', 'created_at', 'updated_at'];
$this->queryField = ['name' => 'like', 'phone' => 'like', 'address' => 'like', 'status' => '='];
}
/**
* @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('company', $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]);
}
}