vhost init...4
This commit is contained in:
parent
ecf4565fd5
commit
47f1a7c648
@ -4,20 +4,36 @@ namespace App\Cells;
|
||||
|
||||
use App\Cells\BaseCell;
|
||||
use App\Models\DeviceModel;
|
||||
use App\Models\ProductDeviceModel;
|
||||
|
||||
class ProductCell extends BaseCell
|
||||
{
|
||||
private $_deviceModel = null;
|
||||
private $_productDeviceModel = null;
|
||||
|
||||
final protected function getDeviceModel(): 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 = [])
|
||||
{
|
||||
$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']['categorys'] = ['server', 'cpu', 'memory', 'disk', 'nic', 'publicip', 'os'];
|
||||
$cellDatas['device']['options'] = $this->getDeviceModel()->getOptions();
|
||||
//dd($cellDatas);
|
||||
return view(
|
||||
'Views/cells/product/' . __FUNCTION__,
|
||||
['cellDatas' => $cellDatas]
|
||||
|
||||
@ -132,23 +132,6 @@ class ProductController extends AdminController
|
||||
return array();
|
||||
//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
|
||||
{
|
||||
@ -157,7 +140,24 @@ class ProductController extends AdminController
|
||||
return $this->virtual_process($entity);
|
||||
break;
|
||||
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;
|
||||
default:
|
||||
throw new \Exception($this->_viewDatas['fieldDatas']['category'] . "는 알수없는 상품 구분입니다. 다시 확인 부탁드립니다.");
|
||||
@ -178,10 +178,8 @@ class ProductController extends AdminController
|
||||
{
|
||||
$this->_viewDatas['fieldDatas']['price'] = $this->calculate_price();
|
||||
$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));
|
||||
// dd($entity);
|
||||
return $entity;
|
||||
}
|
||||
}
|
||||
|
||||
@ -154,7 +154,9 @@ CREATE TABLE vhost.tw_product_device (
|
||||
product_uid varchar(36) NOT NULL COMMENT '상품 정보',
|
||||
device_uid varchar(36) NOT NULL 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(),
|
||||
deleted_at timestamp NULL DEFAULT NULL,
|
||||
PRIMARY KEY (uid),
|
||||
KEY product_uid (product_uid),
|
||||
KEY device_uid (device_uid),
|
||||
|
||||
@ -164,15 +164,12 @@ abstract class BaseModel extends Model
|
||||
}
|
||||
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) {
|
||||
$this->where($field, $value);
|
||||
}
|
||||
foreach ($this->findAll() as $entity) {
|
||||
$entitys[$entity->getPrimaryKey()] = $entity;
|
||||
}
|
||||
return $entitys;
|
||||
return $this->findAll();
|
||||
}
|
||||
//Field별 Form Option용
|
||||
public function getOptionLabel($entity)
|
||||
@ -181,7 +178,10 @@ abstract class BaseModel extends Model
|
||||
}
|
||||
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);
|
||||
}
|
||||
return $options;
|
||||
@ -244,19 +244,32 @@ abstract class BaseModel extends Model
|
||||
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)
|
||||
{
|
||||
foreach ($this->allowedFields as $field) {
|
||||
$entity = $this->changeFormData('create', $field, $formDatas, $entity);
|
||||
}
|
||||
//primaryKey가 수동입력이면
|
||||
if (!$this->useAutoIncrement) {
|
||||
// $pk = $this->primaryKey;
|
||||
// $entity->$pk = $this->getUUID();
|
||||
//위 형식을 아래와같이 변경
|
||||
$entity->$$this->primaryKey = $this->getUUID();
|
||||
$entity = $this->save_process($entity);
|
||||
//primaryKey가 자동입력이면
|
||||
if ($this->useAutoIncrement) {
|
||||
$pk = $this->primaryKey;
|
||||
$entity->$pk = $this->insertID();
|
||||
}
|
||||
$this->insert($entity);
|
||||
return $entity;
|
||||
}
|
||||
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->updated_at = time();
|
||||
//dd($entity);
|
||||
$this->update($entity->getPrimaryKey(), $entity);
|
||||
return $entity;
|
||||
return $this->save_process($entity);
|
||||
}
|
||||
|
||||
//Index관련
|
||||
|
||||
@ -3,7 +3,6 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Entities\ProductDeviceEntity;
|
||||
use App\Entities\ProductEntity;
|
||||
|
||||
class ProductDeviceModel extends BaseModel
|
||||
{
|
||||
@ -11,7 +10,7 @@ class ProductDeviceModel extends BaseModel
|
||||
protected $returnType = ProductDeviceEntity::class;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('ProductDevic');
|
||||
parent::__construct('ProductDevice');
|
||||
$this->allowedFields = [
|
||||
...$this->allowedFields, "product_uid", "device_uid", "device_cnt"
|
||||
];
|
||||
@ -43,9 +42,7 @@ class ProductDeviceModel extends BaseModel
|
||||
}
|
||||
public function create(array $formDatas): ProductDeviceEntity
|
||||
{
|
||||
$entity = $this->create_process(new ProductDeviceEntity(), $formDatas);
|
||||
dd($entity);
|
||||
return $entity;
|
||||
return $this->create_process(new ProductDeviceEntity(), $formDatas);
|
||||
}
|
||||
public function modify(ProductDeviceEntity $entity, array $formDatas): ProductDeviceEntity
|
||||
{
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
<?= form_dropdown(
|
||||
$category,
|
||||
$cellDatas['device']['options'][$category],
|
||||
old($category, array_key_exists('entity', $cellDatas) ? $cellDatas['entity']->$category : DEFAULTS['EMPTY']),
|
||||
$cellDatas['defaults'],
|
||||
[
|
||||
'id' => $category,
|
||||
'size' => "6",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user