54 lines
2.4 KiB
PHP
54 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Part;
|
|
|
|
use App\Entities\Equipment\ServerPartEntity;
|
|
use App\Helpers\CommonHelper;
|
|
use App\Interfaces\Equipment\ServerPartInterface;
|
|
use App\Models\CommonModel;
|
|
use App\Services\CommonService;
|
|
|
|
abstract class PartService extends CommonService implements ServerPartInterface
|
|
{
|
|
protected function __construct(CommonModel $model, CommonHelper $helper)
|
|
{
|
|
parent::__construct($model, $helper);
|
|
$this->addClassName('Part');
|
|
}
|
|
|
|
//서버파트관련 작업
|
|
public function setServerPart(string $action, ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity
|
|
{
|
|
switch ($action) {
|
|
case 'create':
|
|
//부품정보가져오기
|
|
$entity = $this->getEntity($serverPartEntity->getPartUID());
|
|
if (!$entity) {
|
|
throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 부품정보를 찾을수없습니다.");
|
|
}
|
|
//부품정보에 서버정보 설정 및 서비스,고객정보 정의
|
|
if ($entity->getStock() < $serverPartEntity->getCnt()) {
|
|
throw new \Exception("현재 재고수[{$entity->getStock()}]보다 지정하신 갯수({$serverPartEntity->getCnt()})가 더 많습니다.");
|
|
}
|
|
$entity = parent::modify($entity, ['stock' => $entity->getStock() - $serverPartEntity->getCnt()]);
|
|
break;
|
|
case 'delete':
|
|
//부품정보가져오기
|
|
$entity = $this->getEntity($serverPartEntity->getPartUID());
|
|
if (!$entity) {
|
|
throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 부품정보를 찾을수없습니다.");
|
|
}
|
|
//부품정보에 서버정보 설정 및 서비스,고객정보 정의
|
|
if ($entity->getStock() < $serverPartEntity->getCnt()) {
|
|
throw new \Exception("현재 재고수[{$entity->getStock()}]보다 지정하신 갯수({$serverPartEntity->getCnt()})가 더 많습니다.");
|
|
}
|
|
$entity = parent::modify($entity, ['stock' => $entity->getStock() + $serverPartEntity->getCnt()]);
|
|
break;
|
|
default:
|
|
throw new \Exception("{$action}은 정의되지 않은 작업입니다.");
|
|
// break;
|
|
}
|
|
return $serverPartEntity;
|
|
}
|
|
}
|