vhost init...4

This commit is contained in:
최준흠 2024-05-20 19:18:29 +09:00
parent ecf4565fd5
commit 47f1a7c648
6 changed files with 67 additions and 43 deletions

View File

@ -4,20 +4,36 @@ namespace App\Cells;
use App\Cells\BaseCell; use App\Cells\BaseCell;
use App\Models\DeviceModel; use App\Models\DeviceModel;
use App\Models\ProductDeviceModel;
class ProductCell extends BaseCell class ProductCell extends BaseCell
{ {
private $_deviceModel = null; private $_deviceModel = null;
private $_productDeviceModel = null;
final protected function getDeviceModel(): DeviceModel final protected function getDeviceModel(): DeviceModel
{ {
return $this->_deviceModel = $this->_deviceModel ?: new DeviceModel(); return $this->_deviceModel = $this->_deviceModel ?: new DeviceModel();
} }
final protected function getProductDeviceModel(): ProductDeviceModel
{
return $this->_productDeviceModel = $this->_productDeviceModel ?: new ProductDeviceModel();
}
public function device(array $cellDatas = []) public function device(array $cellDatas = [])
{ {
$cellDatas['defaults'] = [];
if (array_key_exists('entity', $cellDatas)) {
foreach ($this->getProductDeviceModel()->getEntitys(
['product_uid' => $cellDatas['entity']->getPrimaryKey()]
) as $productDevieceEntity) {
$cellDatas['defaults'][$productDevieceEntity->device_uid] = $productDevieceEntity;
}
}
$cellDatas['device'] = []; $cellDatas['device'] = [];
$cellDatas['device']['categorys'] = ['server', 'cpu', 'memory', 'disk', 'nic', 'publicip', 'os']; $cellDatas['device']['categorys'] = ['server', 'cpu', 'memory', 'disk', 'nic', 'publicip', 'os'];
$cellDatas['device']['options'] = $this->getDeviceModel()->getOptions(); $cellDatas['device']['options'] = $this->getDeviceModel()->getOptions();
//dd($cellDatas);
return view( return view(
'Views/cells/product/' . __FUNCTION__, 'Views/cells/product/' . __FUNCTION__,
['cellDatas' => $cellDatas] ['cellDatas' => $cellDatas]

View File

@ -132,23 +132,6 @@ class ProductController extends AdminController
return array(); return array();
//return $this->add_procedure($product, 1, $this->_viewDatas['fieldDatas']['paymentday']); //return $this->add_procedure($product, 1, $this->_viewDatas['fieldDatas']['paymentday']);
} }
//실서버
protected function beremetal_process(ProductEntity $entity, array $devices = []): array
{
$fields = ['server', 'cpu', 'memory', 'disk', 'nic', 'publicip', 'os'];
//fieldData 적용
foreach ($fields as $field) {
$formDatas = ['product_uid' => $entity->getPrimaryKey()];
$formDatas['device_uid'] = $this->request->getPost($field);
$formDatas['device_cnt'] = $this->request->getPost($field . "_cnt") ?: 1;
if (!is_null($formDatas['device_uid'])) {
$devices[$field] = $this->getProductDeviceModel()->create($formDatas);
}
}
dd($devices);
return $devices;
}
//주문처리 //주문처리
protected function device_process(ProductEntity $entity): array protected function device_process(ProductEntity $entity): array
{ {
@ -157,7 +140,24 @@ class ProductController extends AdminController
return $this->virtual_process($entity); return $this->virtual_process($entity);
break; break;
case 'beremetal': case 'beremetal':
return $this->beremetal_process($entity); //상품관련 tw_product_device 기존정보 삭제처리
foreach ($this->getProductDeviceModel()->getEntitys(
['product_uid' => $entity->getPrimaryKey()]
) as $productDeviceEntity) {
$this->getProductDeviceModel()->delete($productDeviceEntity);
}
//상품관련 tw_product_device 기존정보 생성처리
$devices = [];
foreach (['server', 'cpu', 'memory', 'disk', 'nic', 'publicip', 'os'] as $field) {
$formDatas = ['product_uid' => $entity->getPrimaryKey()];
$formDatas['device_uid'] = $this->request->getPost($field);
$formDatas['device_cnt'] = $this->request->getPost($field . "_cnt") ?: 1;
if ($formDatas['product_uid'] && $formDatas['device_uid']) {
$devices[$field] = $this->getProductDeviceModel()->create($formDatas);
}
}
// dd($devices);
return $devices;
break; break;
default: default:
throw new \Exception($this->_viewDatas['fieldDatas']['category'] . "는 알수없는 상품 구분입니다. 다시 확인 부탁드립니다."); throw new \Exception($this->_viewDatas['fieldDatas']['category'] . "는 알수없는 상품 구분입니다. 다시 확인 부탁드립니다.");
@ -178,10 +178,8 @@ class ProductController extends AdminController
{ {
$this->_viewDatas['fieldDatas']['price'] = $this->calculate_price(); $this->_viewDatas['fieldDatas']['price'] = $this->calculate_price();
$entity = parent::update_process($entity); $entity = parent::update_process($entity);
foreach ($this->getProductDeviceModel()->getEntitys(['product_uid' => $entity->getPrimaryKey()]) as $productDeviceEntity) {
$this->getProductDeviceModel()->delete($productDeviceEntity);
}
$entity->setDevices($this->device_process($entity)); $entity->setDevices($this->device_process($entity));
// dd($entity);
return $entity; return $entity;
} }
} }

View File

@ -154,7 +154,9 @@ CREATE TABLE vhost.tw_product_device (
product_uid varchar(36) NOT NULL COMMENT '상품 정보', product_uid varchar(36) NOT NULL COMMENT '상품 정보',
device_uid varchar(36) NOT NULL COMMENT '장비 정보', device_uid varchar(36) NOT NULL COMMENT '장비 정보',
device_cnt int(3) unsigned NOT NULL DEFAULT 1 COMMENT '장비 갯수', device_cnt int(3) unsigned NOT NULL DEFAULT 1 COMMENT '장비 갯수',
updated_at timestamp NULL DEFAULT NULL,
created_at timestamp NOT NULL DEFAULT current_timestamp(), created_at timestamp NOT NULL DEFAULT current_timestamp(),
deleted_at timestamp NULL DEFAULT NULL,
PRIMARY KEY (uid), PRIMARY KEY (uid),
KEY product_uid (product_uid), KEY product_uid (product_uid),
KEY device_uid (device_uid), KEY device_uid (device_uid),

View File

@ -164,15 +164,12 @@ abstract class BaseModel extends Model
} }
return $this->first() ?: throw new \Exception(__FUNCTION__ . "에서 {$this->getClassName()}의 해당 데이터가 없습니다."); return $this->first() ?: throw new \Exception(__FUNCTION__ . "에서 {$this->getClassName()}의 해당 데이터가 없습니다.");
} }
public function getEntitys(array $conditions = [], array $entitys = []): array public function getEntitys(array $conditions = []): array
{ {
foreach ($conditions as $field => $value) { foreach ($conditions as $field => $value) {
$this->where($field, $value); $this->where($field, $value);
} }
foreach ($this->findAll() as $entity) { return $this->findAll();
$entitys[$entity->getPrimaryKey()] = $entity;
}
return $entitys;
} }
//Field별 Form Option용 //Field별 Form Option용
public function getOptionLabel($entity) public function getOptionLabel($entity)
@ -181,7 +178,10 @@ abstract class BaseModel extends Model
} }
public function getOptions(array $conditions = array(), $options = array()): array public function getOptions(array $conditions = array(), $options = array()): array
{ {
foreach ($this->getEntitys($conditions, $options) as $entity) { foreach ($conditions as $field => $value) {
$this->where($field, $value);
}
foreach ($this->findAll() as $entity) {
$options[$entity->getPrimaryKey()] = $this->getOptionLabel($entity); $options[$entity->getPrimaryKey()] = $this->getOptionLabel($entity);
} }
return $options; return $options;
@ -244,19 +244,32 @@ abstract class BaseModel extends Model
return $entity; return $entity;
} }
final protected function save_process($entity)
{
// echo var_export($entity, true);
// exit;
if ($entity->hasChanged()) {
if (!$this->save($entity)) {
log_message("error", __FUNCTION__ . "에서 호출:" . $this->getLastQuery());
log_message("error", implode("\n", $this->errors()));
throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . $this->getLastQuery() . "\n" . var_export($this->errors(), true));
}
} else {
throw new \Exception(__FUNCTION__ . " 오류 발생.\n 기존정보와 동일하여 수정되지 않았습니다.");
}
return $entity;
}
protected function create_process($entity, array $formDatas) protected function create_process($entity, array $formDatas)
{ {
foreach ($this->allowedFields as $field) { foreach ($this->allowedFields as $field) {
$entity = $this->changeFormData('create', $field, $formDatas, $entity); $entity = $this->changeFormData('create', $field, $formDatas, $entity);
} }
//primaryKey가 수동입력이면 $entity = $this->save_process($entity);
if (!$this->useAutoIncrement) { //primaryKey가 자동입력이면
// $pk = $this->primaryKey; if ($this->useAutoIncrement) {
// $entity->$pk = $this->getUUID(); $pk = $this->primaryKey;
//위 형식을 아래와같이 변경 $entity->$pk = $this->insertID();
$entity->$$this->primaryKey = $this->getUUID();
} }
$this->insert($entity);
return $entity; return $entity;
} }
final protected function modify_process($entity, array $formDatas) final protected function modify_process($entity, array $formDatas)
@ -265,9 +278,7 @@ abstract class BaseModel extends Model
$entity = $this->changeFormData('modify', $field, $formDatas, $entity); $entity = $this->changeFormData('modify', $field, $formDatas, $entity);
} }
$entity->updated_at = time(); $entity->updated_at = time();
//dd($entity); return $this->save_process($entity);
$this->update($entity->getPrimaryKey(), $entity);
return $entity;
} }
//Index관련 //Index관련

View File

@ -3,7 +3,6 @@
namespace App\Models; namespace App\Models;
use App\Entities\ProductDeviceEntity; use App\Entities\ProductDeviceEntity;
use App\Entities\ProductEntity;
class ProductDeviceModel extends BaseModel class ProductDeviceModel extends BaseModel
{ {
@ -11,7 +10,7 @@ class ProductDeviceModel extends BaseModel
protected $returnType = ProductDeviceEntity::class; protected $returnType = ProductDeviceEntity::class;
public function __construct() public function __construct()
{ {
parent::__construct('ProductDevic'); parent::__construct('ProductDevice');
$this->allowedFields = [ $this->allowedFields = [
...$this->allowedFields, "product_uid", "device_uid", "device_cnt" ...$this->allowedFields, "product_uid", "device_uid", "device_cnt"
]; ];
@ -43,9 +42,7 @@ class ProductDeviceModel extends BaseModel
} }
public function create(array $formDatas): ProductDeviceEntity public function create(array $formDatas): ProductDeviceEntity
{ {
$entity = $this->create_process(new ProductDeviceEntity(), $formDatas); return $this->create_process(new ProductDeviceEntity(), $formDatas);
dd($entity);
return $entity;
} }
public function modify(ProductDeviceEntity $entity, array $formDatas): ProductDeviceEntity public function modify(ProductDeviceEntity $entity, array $formDatas): ProductDeviceEntity
{ {

View File

@ -10,7 +10,7 @@
<?= form_dropdown( <?= form_dropdown(
$category, $category,
$cellDatas['device']['options'][$category], $cellDatas['device']['options'][$category],
old($category, array_key_exists('entity', $cellDatas) ? $cellDatas['entity']->$category : DEFAULTS['EMPTY']), $cellDatas['defaults'],
[ [
'id' => $category, 'id' => $category,
'size' => "6", 'size' => "6",