shoppingmallv2 init...

This commit is contained in:
최준흠 2023-08-02 15:02:26 +09:00
parent 9abeb19cbc
commit ec51486a53
21 changed files with 150 additions and 42 deletions

View File

@ -21,12 +21,12 @@ class OrderController extends AdminController
final public function getFields(string $action = ""): array
{
$fields = ['product_uid', "quantity", "price", "status"];
$fields = ["user_uid", 'product_uid', "quantity", "price", "status"];
switch ($action) {
case "index":
case "excel":
case "view":
return ['product_uid', "user_uid", "quantity", "price", "status", "updated_at", "created_at"];
return ["user_uid", 'product_uid', "name", "quantity", "price", "status", "updated_at", "created_at"];
break;
default:
return $fields;
@ -35,7 +35,7 @@ class OrderController extends AdminController
}
final public function getFieldFilters(): array
{
return ['product_uid', "user_uid", "status"];
return ["user_uid", 'product_uid', "status"];
}
final public function getFieldBatchFilters(): array
{

View File

@ -23,12 +23,12 @@ class OrderController extends FrontController
final public function getFields(string $action = ""): array
{
$fields = ['product_uid', "quantity", "price", "status"];
$fields = ["product_uid", "quantity", "price", "status"];
switch ($action) {
case "index":
case "excel":
case "view":
return ['product_uid', "quantity", "price", "status", "updated_at", "created_at"];
return ['name', "quantity", "price", "status", "updated_at", "created_at"];
break;
default:
return $fields;
@ -44,6 +44,7 @@ class OrderController extends FrontController
return ["status"];
}
//Insert관련 (주문)
//세션에 장바구니에 담긴 Order UID를 추가해준다.
private function setCart(OrderEntity $entity)
{
@ -62,9 +63,11 @@ class OrderController extends FrontController
}
//상품재고 줄이기,Order(장바구니)에넣기,Order(장바구니)번호 세션넣기
$this->_productModel->decreaseStock($product, $this->_viewDatas['fieldDatas']['quantity']);
//상품명을 복사해서 구매한 상품명에 넣기
$this->_viewDatas['fieldDatas'][$this->_model->getTitleField()] = $product->getTitle();
//장바구니에 넣기
$entity = parent::insert_process();
//Cart세션정의
//장바구니 세션정의
$this->setCart($entity);
return $entity;
}
@ -100,6 +103,34 @@ class OrderController extends FrontController
}
}
//Delete 관련 (주문취소)
protected function delete_process($entity)
{
if (!$this->_model->delete($entity->getPrimaryKey())) {
log_message("error", __FUNCTION__ . "에서 호출:" . $this->_model->getLastQuery());
log_message("error", implode("\n", $this->_model->errors()));
throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . var_export($this->_model->errors(), true));
}
return $entity;
}
public function delete($uid)
{
$msg = "";
try {
$entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$this->delete_process($entity);
$msg = "{$this->_viewDatas['title']}에서 해당 상품 {$entity->quantity}개를 완료하였습니다.";
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']));
} catch (\Exception $e) {
$msg = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage();
log_message("error", $e->getMessage());
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']));
} finally {
$this->_session->setFlashdata("return_message", $msg);
}
}
//Index관련
protected function index_setCondition()
{
parent::index_setCondition();

View File

@ -46,6 +46,7 @@ CREATE TABLE shoppingmall.tw_order (
uid varchar(36) NOT NULL,
product_uid varchar(36) NULL COMMENT '상품 정보',
user_uid varchar(36) NULL COMMENT '사용자 정보',
name varchar(255) NOT NULL COMMENT '상품명',
quantity varchar(255) NOT NULL COMMENT '수량',
price int(10) UNSIGNED NOT NULL COMMENT '구매가',
status varchar(10) NOT NULL DEFAULT 'use' COMMENT 'use: 주문대기, unuse: 사용않함 등등',

View File

@ -16,7 +16,7 @@ class OrderEntity extends BaseEntity
}
final public function getTitle(): string
{
return $this->attributes['product_uid'];
return $this->attributes['name'];
}
final public function getStatus(): string
{

View File

@ -108,11 +108,20 @@ function getFieldIndex_Row_BoardConfigHelper($field, $entity, array $fieldFilter
{
switch ($field) {
default:
if (in_array($field, $fieldFilters)) {
$attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field);
return getFieldFilter_BoardConfigHelper($field, $entity->$field, $fieldFormOptions, [...$attributes, 'style' => 'width:100%']);
}
return getFieldView_BoardConfigHelper($field, $entity, $fieldFormOptions, $attributes);
break;
}
} //
function getFieldIndex_Row_BoardConfigHelper_Admin($field, $entity, array $fieldFilters, $fieldFormOptions, $attributes = array()): string
{
switch ($field) {
default:
if (in_array($field, $fieldFilters)) {
$attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field);
return getFieldFilter_BoardConfigHelper($field, $entity->$field, $fieldFormOptions, $attributes);
}
return getFieldIndex_Row_BoardConfigHelper($field, $entity, $fieldFormOptions, $attributes);
break;
}
} //

View File

@ -125,11 +125,20 @@ function getFieldIndex_Row_BoardHelper($field, $entity, array $fieldFilters, $fi
{
switch ($field) {
default:
if (in_array($field, $fieldFilters)) {
$attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field);
return getFieldFilter_BoardHelper($field, $entity->$field, $fieldFormOptions, [...$attributes, 'style' => 'width:100%']);
}
return getFieldView_BoardHelper($field, $entity, $fieldFormOptions, $attributes);
break;
}
} //
function getFieldIndex_Row_BoardHelper_Admin($field, $entity, array $fieldFilters, $fieldFormOptions, $attributes = array()): string
{
switch ($field) {
default:
if (in_array($field, $fieldFilters)) {
$attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field);
return getFieldFilter_BoardHelper($field, $entity->$field, $fieldFormOptions, $attributes);
}
return getFieldIndex_Row_BoardHelper($field, $entity, $fieldFormOptions, $attributes);
break;
}
} //

View File

@ -117,11 +117,20 @@ function getFieldIndex_Row_CategoryHelper($field, $entity, array $fieldFilters,
{
switch ($field) {
default:
if (in_array($field, $fieldFilters)) {
$attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field);
return getFieldFilter_CategoryHelper($field, $entity->$field, $fieldFormOptions, [...$attributes, 'style' => 'width:100%']);
}
return getFieldView_CategoryHelper($field, $entity, $fieldFormOptions, $attributes);
break;
}
} //
function getFieldIndex_Row_CategoryHelper_Admin($field, $entity, array $fieldFilters, $fieldFormOptions, $attributes = array()): string
{
switch ($field) {
default:
if (in_array($field, $fieldFilters)) {
$attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field);
return getFieldFilter_CategoryHelper($field, $entity->$field, $fieldFormOptions, $attributes);
}
return getFieldIndex_Row_CategoryHelper($field, $entity, $fieldFormOptions, $attributes);
break;
}
} //

View File

@ -92,4 +92,17 @@ function getFieldIndex_Row_OrderHelper($field, $entity, array $fieldFilters, $fi
return getFieldView_OrderHelper($field, $entity, $fieldFilters, $fieldFormOptions, $attributes);
break;
}
} //
function getFieldIndex_Row_OrderHelper_Admin($field, $entity, array $fieldFilters, $fieldFormOptions, $attributes = array()): string
{
switch ($field) {
default:
if (in_array($field, $fieldFilters)) {
$attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field);
return getFieldFilter_OrderHelper($field, $entity->$field, $fieldFormOptions, $attributes);
}
return getFieldIndex_Row_OrderHelper($field, $entity, $fieldFormOptions, $attributes);
break;
}
} //

View File

@ -129,11 +129,20 @@ function getFieldIndex_Row_ProductHelper($field, $entity, array $fieldFilters, $
{
switch ($field) {
default:
if (in_array($field, $fieldFilters)) {
$attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field);
return getFieldFilter_ProductHelper($field, $entity->$field, $fieldFormOptions, [...$attributes, 'style' => 'width:100%']);
}
return getFieldView_ProductHelper($field, $entity, $fieldFormOptions, $attributes);
break;
}
} //
function getFieldIndex_Row_ProductHelper_Admin($field, $entity, array $fieldFilters, $fieldFormOptions, $attributes = array()): string
{
switch ($field) {
default:
if (in_array($field, $fieldFilters)) {
$attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field);
return getFieldFilter_ProductHelper($field, $entity->$field, $fieldFormOptions, $attributes);
}
return getFieldIndex_Row_ProductHelper($field, $entity, $fieldFormOptions, $attributes);
break;
}
} //

View File

@ -98,11 +98,20 @@ function getFieldIndex_Row_UserSNSHelper($field, $entity, array $fieldFilters, $
{
switch ($field) {
default:
if (in_array($field, $fieldFilters)) {
$attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field);
return getFieldFilter_UserSNSHelper($field, $entity->$field, $fieldFormOptions, [...$attributes, 'style' => 'width:100%']);
}
return getFieldView_UserSNSHelper($field, $entity, $fieldFormOptions, $attributes);
break;
}
} //
function getFieldIndex_Row_UserSNSHelper_Admin($field, $entity, array $fieldFilters, $fieldFormOptions, $attributes = array()): string
{
switch ($field) {
default:
if (in_array($field, $fieldFilters)) {
$attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field);
return getFieldFilter_UserSNSHelper($field, $entity->$field, $fieldFormOptions, $attributes);
}
return getFieldIndex_Row_UserSNSHelper($field, $entity, $fieldFormOptions, $attributes);
break;
}
} //

View File

@ -104,11 +104,20 @@ function getFieldIndex_Row_UserHelper($field, $entity, array $fieldFilters, $fie
{
switch ($field) {
default:
if (in_array($field, $fieldFilters)) {
$attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field);
return getFieldFilter_UserHelper($field, $entity->$field, $fieldFormOptions, [...$attributes, 'style' => 'width:100%']);
}
return getFieldView_UserHelper($field, $entity, $fieldFormOptions, $attributes);
break;
}
} //
function getFieldIndex_Row_UserHelper_Admin($field, $entity, array $fieldFilters, $fieldFormOptions, $attributes = array()): string
{
switch ($field) {
default:
if (in_array($field, $fieldFilters)) {
$attributes["onChange"] = sprintf('location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), $entity->getPrimaryKey(), $field, $field);
return getFieldFilter_UserHelper($field, $entity->$field, $fieldFormOptions, $attributes);
}
return getFieldIndex_Row_UserHelper($field, $entity, $fieldFormOptions, $attributes);
break;
}
} //

View File

@ -6,11 +6,12 @@ return [
'product_uid' => "상품정보",
'sess_id' => "세션ID",
'user_uid' => "사용자정보",
'name' => "상품명",
'quantity' => "수량",
'price' => "구매가",
'status' => "상태",
'updated_at' => "수정일",
'created_at' => "작성일"
],
"STATUS" => ["use" => "장바구니", "unuse" => "주문취소", "confirm" => "주문완료",]
"STATUS" => ["use" => "결제", "unuse" => "주문취소", "confirm" => "주문완료",]
];

View File

@ -14,19 +14,21 @@ class OrderModel extends BaseModel
public function __construct(array $fields = array())
{
parent::__construct('Order');
$this->allowedFields = ["uid", "user_uid", ...$this->allowedFields, ...$fields];
$this->allowedFields = ["uid", "user_uid", "name", ...$this->allowedFields, ...$fields];
$this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),];
}
final public function getTitleField(): string
{
return 'product_uid';
return 'name';
}
protected function getFieldRule(string $field, array $rules, string $action = ""): array
{
switch ($field) {
case $this->getTitleField():
case 'product_uid':
$rules[$field] = "required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]";
break;
case $this->getTitleField():
$rules[$field] = "required|trim|string";
break;
case 'quantity':
case 'price':

View File

@ -24,7 +24,7 @@
<?= anchor(current_url() . '/update/' . $entity->getPrimaryKey(), $total_count - (($page - 1) * $per_page + $i), ["target" => "_self"]) ?>
</td>
<?php foreach ($fields as $field) : ?>
<td nowrap><?= getFieldIndex_Row_BoardHelper($field, $entity, $fieldFilters, $fieldFormOptions) ?></td>
<td nowrap><?= getFieldIndex_Row_BoardHelper_Admin($field, $entity, $fieldFilters, $fieldFormOptions) ?></td>
<?php endforeach; ?>
<td><?= anchor(current_url() . '/delete/' . $entity->getPrimaryKey(), ICONS['DELETE'], ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) ?></td>
</tr>

View File

@ -24,7 +24,7 @@
<?= anchor(current_url() . '/update/' . $entity->getPrimaryKey(), $total_count - (($page - 1) * $per_page + $i), ["target" => "_self"]) ?>
</td>
<?php foreach ($fields as $field) : ?>
<td nowrap><?= getFieldIndex_Row_BoardConfigHelper($field, $entity, $fieldFilters, $fieldFormOptions) ?></td>
<td nowrap><?= getFieldIndex_Row_BoardConfigHelper_Admin($field, $entity, $fieldFilters, $fieldFormOptions) ?></td>
<?php endforeach; ?>
<td><?= anchor(current_url() . '/delete/' . $entity->getPrimaryKey(), ICONS['DELETE'], ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) ?></td>
</tr>

View File

@ -24,7 +24,7 @@
<?= anchor(current_url() . '/update/' . $entity->getPrimaryKey(), $total_count - (($page - 1) * $per_page + $i), ["target" => "_self"]) ?>
</td>
<?php foreach ($fields as $field) : ?>
<td nowrap><?= getFieldIndex_Row_CategoryHelper($field, $entity, $fieldFilters, $fieldFormOptions) ?></td>
<td nowrap><?= getFieldIndex_Row_CategoryHelper_Admin($field, $entity, $fieldFilters, $fieldFormOptions) ?></td>
<?php endforeach; ?>
<td><?= anchor(current_url() . '/delete/' . $entity->getPrimaryKey(), ICONS['DELETE'], ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) ?></td>
</tr>

View File

@ -24,7 +24,7 @@
<?= $total_count - (($page - 1) * $per_page + $i) ?>
</td>
<?php foreach ($fields as $field) : ?>
<td nowrap><?= getFieldIndex_Row_OrderHelper($field, $entity, $fieldFilters, $fieldFormOptions) ?></td>
<td nowrap><?= getFieldIndex_Row_OrderHelper_Admin($field, $entity, $fieldFilters, $fieldFormOptions) ?></td>
<?php endforeach; ?>
<td>
<?= $entity->getStatus() == DEFAULTS['STATUS'] ? anchor(current_url() . '/delete/' . $entity->getPrimaryKey(), ICONS['DELETE'], ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) : "" ?>

View File

@ -24,7 +24,7 @@
<?= anchor(current_url() . '/update/' . $entity->getPrimaryKey(), $total_count - (($page - 1) * $per_page + $i), ["target" => "_self"]) ?>
</td>
<?php foreach ($fields as $field) : ?>
<td nowrap><?= getFieldIndex_Row_ProductHelper($field, $entity, $fieldFilters, $fieldFormOptions) ?></td>
<td nowrap><?= getFieldIndex_Row_ProductHelper_Admin($field, $entity, $fieldFilters, $fieldFormOptions) ?></td>
<?php endforeach; ?>
<td><?= anchor(current_url() . '/delete/' . $entity->getPrimaryKey(), ICONS['DELETE'], ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) ?></td>
</tr>

View File

@ -24,7 +24,7 @@
<?= anchor(current_url() . '/update/' . $entity->getPrimaryKey(), $total_count - (($page - 1) * $per_page + $i), ["target" => "_self"]) ?>
</td>
<?php foreach ($fields as $field) : ?>
<td nowrap><?= getFieldIndex_Row_UserHelper($field, $entity, $fieldFilters, $fieldFormOptions) ?></td>
<td nowrap><?= getFieldIndex_Row_UserHelper_Admin($field, $entity, $fieldFilters, $fieldFormOptions) ?></td>
<?php endforeach; ?>
<td><?= anchor(current_url() . '/delete/' . $entity->getPrimaryKey(), ICONS['DELETE'], ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) ?></td>
</tr>

View File

@ -24,7 +24,7 @@
<?= anchor(current_url() . '/update/' . $entity->getPrimaryKey(), $total_count - (($page - 1) * $per_page + $i), ["target" => "_self"]) ?>
</td>
<?php foreach ($fields as $field) : ?>
<td nowrap><?= getFieldIndex_Row_UserSNSHelper($field, $entity, $fieldFilters, $fieldFormOptions) ?></td>
<td nowrap><?= getFieldIndex_Row_UserSNSHelper_Admin($field, $entity, $fieldFilters, $fieldFormOptions) ?></td>
<?php endforeach; ?>
<td><?= anchor(current_url() . '/delete/' . $entity->getPrimaryKey(), ICONS['DELETE'], ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) ?></td>
</tr>

View File

@ -13,6 +13,7 @@
<tr>
<th>번호</th>
<?php foreach ($fields as $field) : ?><th><?= getFieldIndex_Column_OrderHelper($field, $order_field, $order_value) ?></th><?php endforeach; ?>
<th>작업</th>
</tr>
<?php $i = 0; ?>
<?php foreach ($entitys as $entity) : ?>
@ -23,6 +24,11 @@
<?php foreach ($fields as $field) : ?>
<td nowrap><?= getFieldView_OrderHelper($field, $entity, $fieldFilters, $fieldFormOptions) ?></td>
<?php endforeach; ?>
<td>
<?php if ($entity->getStatus() == DEFAULTS['STATUS']) : ?>
<?= anchor(current_url() . '/delete/' . $entity->getPrimaryKey(), ICONS['DELETE'], ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) ?>
<?php endif; ?>
</td>
</tr>
<?php $i++; ?>
<?php endforeach; ?>