91 lines
3.2 KiB
PHP
91 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Part;
|
|
|
|
use App\Entities\Equipment\ServerPartEntity;
|
|
use App\Entities\Part\OSEntity;
|
|
use App\Helpers\Part\OSHelper;
|
|
use App\Interfaces\Equipment\ServerPartInterface;
|
|
use App\Models\Part\OSModel;
|
|
|
|
|
|
class OSService extends PartService implements ServerPartInterface
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct(new OSModel(), new OSHelper());
|
|
$this->addClassName('OS');
|
|
}
|
|
public function getFormFields(): array
|
|
{
|
|
return [
|
|
"title",
|
|
"price",
|
|
"stock",
|
|
"status",
|
|
];
|
|
}
|
|
public function getFormFilters(): array
|
|
{
|
|
return [
|
|
'status',
|
|
];
|
|
}
|
|
public function getIndexFields(): array
|
|
{
|
|
return [
|
|
"title",
|
|
"price",
|
|
"stock",
|
|
"status",
|
|
];
|
|
}
|
|
public function getBatchjobFields(): array
|
|
{
|
|
return ['status'];
|
|
}
|
|
//기본 기능부분
|
|
//FieldForm관련용
|
|
//OrderBy 처리
|
|
public function setOrderBy(mixed $field = null, mixed $value = null): void
|
|
{
|
|
$this->getModel()->orderBy('title ASC');
|
|
parent::setOrderBy($field, $value);
|
|
}
|
|
|
|
//서버파트관련 작업
|
|
public function setServerPart(ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity
|
|
{
|
|
//부품정보가져오기
|
|
$entity = $this->getEntity($serverPartEntity->getPartUID());
|
|
if (!$entity instanceof OSEntity) {
|
|
throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 부품정보를 찾을수없습니다.");
|
|
}
|
|
//부품정보에 서버정보 설정 및 서비스,고객정보 정의
|
|
if ($entity->getStock() < $serverPartEntity->getCnt()) {
|
|
throw new \Exception("현재 재고수[{$entity->getStock()}]보다 지정하신 갯수({$serverPartEntity->getCnt()})가 더 많습니다.");
|
|
}
|
|
return $this->getModel()->modify($entity, ['stock' => $entity->getStock() - $serverPartEntity->getCnt()]);
|
|
}
|
|
public function changeServerPart(ServerPartEntity $oldServerPartEntity, ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity
|
|
{
|
|
|
|
//수정 전 부품연결정보관련 정보처리 갯수,파트가 달라졌을경우 (회수 -> 사용 처리)
|
|
//기존것 회수 처리
|
|
if ($oldServerPartEntity->getCnt() != $serverPartEntity->getCnt() || $oldServerPartEntity->getPartUID() !== $serverPartEntity->getPartUID()) {
|
|
$this->unsetServerPart($oldServerPartEntity, $serverPartDatas);
|
|
}
|
|
//신규것 사용처리
|
|
return $this->setServerPart($serverPartEntity, $serverPartDatas);
|
|
}
|
|
public function unsetServerPart(ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity
|
|
{
|
|
//부품정보가져오기
|
|
$entity = $this->getEntity($serverPartEntity->getPartUID());
|
|
if (!$entity instanceof OSEntity) {
|
|
throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 부품정보를 찾을수없습니다.");
|
|
}
|
|
return $this->getModel()->modify($entity, ['stock' => $entity->getStock() + $serverPartEntity->getCnt()]);
|
|
}
|
|
}
|