91 lines
3.1 KiB
PHP
91 lines
3.1 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;
|
|
use App\Interfaces\Equipment\ServerPartInterface;
|
|
|
|
class PartService extends EquipmentService implements ServerPartInterface
|
|
{
|
|
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, array $serverPartDatas): ServerPartEntity
|
|
{
|
|
if (!array_key_exists('part_uid', $serverPartDatas)) {
|
|
throw new \Exception(__METHOD__ . "에서 오류발생: 부품번호가 정의되지 않았습니다.");
|
|
}
|
|
if (!array_key_exists('status', $serverPartDatas)) {
|
|
throw new \Exception(__METHOD__ . "에서 오류발생: 상태가 정의되지 않았습니다.");
|
|
}
|
|
//부품정보가져오기
|
|
$entity = $this->getEntity($serverPartDatas['part_uid']);
|
|
if (!($entity instanceof PartEntity)) {
|
|
throw new \Exception("{$serverPartDatas['part_uid']}에 해당하는 부품정보를 찾을수없습니다.");
|
|
}
|
|
//부품정보에 서버정보 설정 및 서비스,고객정보 정의
|
|
$formDatas = [];
|
|
if ($serverPartDatas['status'] === STATUS['AVAILABLE']) { //해지된 부품 재고수를 처리
|
|
$formDatas['stock'] = $entity->getStock() + $serverPartEntity->getCnt();
|
|
}
|
|
if ($serverPartDatas['status'] === STATUS['OCCUPIED']) { //추가된 부품 재고수를 처리
|
|
if ($entity->getStock() < $serverPartEntity->getCnt()) {
|
|
throw new \Exception("현재 재고수[{$entity->getStock()}]보다 지정하신 갯수({$serverPartEntity->getCnt()})가 더 많습니다.");
|
|
}
|
|
$formDatas['stock'] = $entity->getStock() - $serverPartEntity->getCnt();
|
|
}
|
|
return $serverPartEntity->setPartEntity($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()]);
|
|
}
|
|
}
|