52 lines
2.1 KiB
PHP
52 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Part;
|
|
|
|
use App\Entities\Equipment\ServerPartEntity;
|
|
use App\Entities\Part\PartEntity;
|
|
use App\Models\CommonModel;
|
|
use App\Services\CommonService;
|
|
|
|
abstract class PartService extends CommonService
|
|
{
|
|
protected function __construct(CommonModel $model)
|
|
{
|
|
parent::__construct($model);
|
|
$this->addClassPaths('Part');
|
|
}
|
|
public function getEntity(string|int|array $where, ?string $message = null): ?PartEntity
|
|
{
|
|
return parent::getEntity($where, $message);
|
|
}
|
|
|
|
//서버파트관련 작업
|
|
public function attachToServerPart(ServerPartEntity $serverPartEntity): mixed
|
|
{
|
|
//부품정보가져오기
|
|
$entity = $this->getEntity($serverPartEntity->getPartUID());
|
|
if (!$entity) {
|
|
throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 부품정보를 찾을수없습니다.");
|
|
}
|
|
//부품정보에 서버정보 설정 및 서비스,고객정보 정의
|
|
if ($entity->getAvailable() < $serverPartEntity->getCnt()) {
|
|
throw new \Exception("현재 사용가능 갯수[{$entity->getAvailable()}]보다 지정하신 갯수({$serverPartEntity->getCnt()})가 더 많습니다.");
|
|
}
|
|
return $this->model->modify($entity, ['used' => $entity->getUsed() + $serverPartEntity->getCnt()]);
|
|
}
|
|
public function detachFromServerPart(ServerPartEntity $serverPartEntity): mixed
|
|
{
|
|
//부품정보가져오기
|
|
$entity = $this->getEntity($serverPartEntity->getPartUID());
|
|
if (!$entity) {
|
|
throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 부품정보를 찾을수없습니다.");
|
|
}
|
|
//부품정보에 서버정보 설정 및 서비스,고객정보 정의
|
|
if ($entity->getUsed() < $serverPartEntity->getCnt()) {
|
|
throw new \Exception("현재 사용된 갯수[{$entity->getUsed()}]보다 지정하신 갯수({$serverPartEntity->getCnt()})가 더 많습니다.");
|
|
}
|
|
$entity = $this->model->modify($entity, ['used' => $entity->getUsed() - $serverPartEntity->getCnt()]);
|
|
// dd($entity);
|
|
return $entity;
|
|
}
|
|
}
|