dbmsv2/app/Services/Equipment/PartService.php
2025-09-17 15:04:01 +09:00

83 lines
2.5 KiB
PHP

<?php
namespace App\Services\Equipment;
use App\Entities\Equipment\PartEntity;
use App\Entities\Equipment\ServerPartEntity;
use App\Helpers\Equipment\PartHelper;
use App\Models\Equipment\PartModel;
class PartService extends EquipmentService
{
public function __construct()
{
parent::__construct(new PartModel(), new PartHelper());
$this->addClassName('Part');
}
public function getFormFields(): array
{
return [
"type",
"title",
"price",
"stock",
"status",
];
}
public function getFormFilters(): array
{
return [
'type',
'status',
];
}
public function getIndexFields(): array
{
return [
"type",
"title",
"price",
"stock",
"status",
];
}
public function getBatchjobFields(): array
{
return ['type', 'status'];
}
//기본 기능부분
//FieldForm관련용
//서비스파트 설정
public function setServerPart(ServerPartEntity $serverPartEntity, mixed $uid, string $status): PartEntity
{
$entity = $this->getEntity($uid);
if (!($entity instanceof PartEntity)) {
throw new \Exception("{$uid}에 해당하는 부품정보를 찾을수없습니다.");
}
//부품정보에 서버정보 설정 및 서비스,고객정보 정의
$formDatas = [];
if ($status === STATUS['AVAILABLE']) { //해지된 부품 재고수를 처리
$formDatas['stock'] = $entity->getStock() + $serverPartEntity->getCnt();
}
if ($status === STATUS['OCCUPIED']) { //추가된 부품 재고수를 처리
if ($entity->getStock() < $serverPartEntity->getCnt()) {
throw new \Exception("현재 재고수[{$entity->getStock()}]보다 지정하신 갯수({$serverPartEntity->getCnt()})가 더 많습니다.");
}
$formDatas['stock'] = $entity->getStock() - $serverPartEntity->getCnt();
}
return $this->modify($entity, $formDatas);
}
//OrderBy 처리
public function setOrderBy(mixed $field = null, mixed $value = null): void
{
$this->getModel()->orderBy('code ASC');
parent::setOrderBy($field, $value);
}
public function create(array $formDatas): PartEntity
{
$entity = parent::create($formDatas);
return $this->modify($entity, ['code' => $entity->getType() . $entity->getPK()]);
}
}