shoppingmallv2 init...
This commit is contained in:
parent
789d2c5cb7
commit
a01793a50a
@ -34,6 +34,20 @@ abstract class BaseBackend
|
||||
return $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
|
||||
}
|
||||
|
||||
//transaction관련
|
||||
final public function transBegin()
|
||||
{
|
||||
$this->_model->transBegin();
|
||||
}
|
||||
final public function transCommit()
|
||||
{
|
||||
$this->_model->transBegin();
|
||||
}
|
||||
final public function transRollback()
|
||||
{
|
||||
$this->_model->transRollback();
|
||||
}
|
||||
|
||||
//초기화
|
||||
final public function getFields(string $action)
|
||||
{
|
||||
|
||||
@ -73,6 +73,7 @@ class OrderBackend extends BaseBackend
|
||||
}
|
||||
//상품모델에서 Order에 담은 갯수만큼 재고에서 뺀다.
|
||||
$this->getProductModel()->decreaseStock($product, $fieldDatas['quantity']);
|
||||
// throw new \Exception(var_export($fieldDatas, true));
|
||||
return parent::insert($fieldDatas);
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,20 +23,19 @@ class OrderController extends AdminController
|
||||
try {
|
||||
$this->_viewDatas = $this->init(__FUNCTION__);
|
||||
//Transaction manully 시작
|
||||
$this->_backend->transBegin();
|
||||
// $this->_backend->transBegin();
|
||||
$this->insert_process();
|
||||
$entity = $this->_backend->insert($this->_viewDatas['fieldDatas']);
|
||||
//Transaction manully Commit
|
||||
$this->_backend->transCommit();
|
||||
// $this->_backend->transCommit();
|
||||
$msg = sprintf(
|
||||
"%s에서 %s상품 %s개를 장바구니에 담았습니다.",
|
||||
"%s에서 해당 상품 %s개를 장바구니에 담았습니다.",
|
||||
$this->_viewDatas['title'],
|
||||
$entity->getTtile(),
|
||||
$this->_viewDatas['fieldDatas']['quantity']
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
//Transaction manully Rollback
|
||||
$this->_backend->transRollback();
|
||||
// $this->_backend->transRollback();
|
||||
$msg = sprintf(
|
||||
"%s에서 다음 오류로 인해 장바구니에 담기를 실패하였습니다.\n%s",
|
||||
$this->_viewDatas['title'],
|
||||
|
||||
@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
use App\Entities\BaseEntity;
|
||||
use CodeIgniter\Model;
|
||||
|
||||
abstract class BaseModel extends Model
|
||||
{
|
||||
@ -153,7 +153,7 @@ abstract class BaseModel extends Model
|
||||
}
|
||||
break;
|
||||
case "user_uid": //입력데이터로 있을시 추가, 없을시는 입력의 경우에만 자동으로 추가
|
||||
if (array_key_exists($field, $formDatas) && $formDatas[$field]) {
|
||||
if (array_key_exists($field, $formDatas) && !is_null($formDatas[$field])) {
|
||||
$entity->$field = $formDatas[$field];
|
||||
} elseif ($action == 'create' && $this->_session->get(SESSION_NAMES["ISLOGIN"])) {
|
||||
$auth = $this->_session->get(SESSION_NAMES["AUTH"]);
|
||||
@ -163,17 +163,17 @@ abstract class BaseModel extends Model
|
||||
case "passwd":
|
||||
// echo var_export($this->validationRules, true);
|
||||
// exit;
|
||||
if (array_key_exists($field, $formDatas) && $formDatas[$field]) {
|
||||
if (array_key_exists($field, $formDatas) && !is_null($formDatas[$field])) {
|
||||
$entity->$field = password_hash($formDatas[$field], PASSWORD_DEFAULT);
|
||||
}
|
||||
break;
|
||||
case "content":
|
||||
if (array_key_exists($field, $formDatas) && $formDatas[$field]) {
|
||||
if (array_key_exists($field, $formDatas) && !is_null($formDatas[$field])) {
|
||||
$entity->$field = htmlentities($formDatas[$field]);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (array_key_exists($field, $formDatas) && $formDatas[$field]) {
|
||||
if (array_key_exists($field, $formDatas) && !is_null($formDatas[$field])) {
|
||||
$entity->$field = $formDatas[$field];
|
||||
}
|
||||
break;
|
||||
@ -181,7 +181,7 @@ abstract class BaseModel extends Model
|
||||
return $entity;
|
||||
}
|
||||
|
||||
private function save_process($entity)
|
||||
final protected function save_process($entity)
|
||||
{
|
||||
// echo var_export($entity, true);
|
||||
// exit;
|
||||
@ -189,7 +189,7 @@ abstract class BaseModel extends Model
|
||||
if (!$this->save($entity)) {
|
||||
log_message("error", __FUNCTION__ . "에서 호출:" . $this->getLastQuery());
|
||||
log_message("error", implode("\n", $this->errors()));
|
||||
throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . var_export($this->errors(), true));
|
||||
throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . $this->getLastQuery() . "\n" . var_export($this->errors(), true));
|
||||
}
|
||||
//primaryKey가 자동입력이면
|
||||
if ($this->useAutoIncrement) {
|
||||
|
||||
@ -89,13 +89,13 @@ class BoardConfigModel extends BaseModel
|
||||
case "isupload":
|
||||
case "isdownload":
|
||||
case "isaccess":
|
||||
if (array_key_exists($field, $formDatas) && $formDatas[$field]) {
|
||||
if (array_key_exists($field, $formDatas) && !is_null($formDatas[$field])) {
|
||||
$entity->$field = is_array($formDatas[$field]) ? implode("|", $formDatas[$field]) : $formDatas[$field];
|
||||
}
|
||||
break;
|
||||
case "head":
|
||||
case "tail":
|
||||
if (array_key_exists($field, $formDatas) && $formDatas[$field]) {
|
||||
if (array_key_exists($field, $formDatas) && !is_null($formDatas[$field])) {
|
||||
$entity->$field = htmlentities($formDatas[$field]);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -103,11 +103,12 @@ class ProductModel extends BaseModel
|
||||
final public function decreaseStock(ProductEntity $entity, int $cnt)
|
||||
{
|
||||
if ($entity->getStock() == $cnt) {
|
||||
$this->builder()->set('status', "outofstock");
|
||||
$entity->status = "outofstock";
|
||||
}
|
||||
//escape -> false옵션 반드시 있어야함
|
||||
$this->builder()->set('stock', "stock-{$cnt}", false);
|
||||
$this->builder()->where($this->primaryKey, $entity->getPrimaryKey());
|
||||
$this->builder()->update();
|
||||
$entity->stock -= $cnt;
|
||||
$this->save_process($entity);
|
||||
// throw new \Exception($this->getLastQuery());
|
||||
// echo "TEST";
|
||||
// exit;
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ class UserModel extends BaseModel
|
||||
{
|
||||
switch ($field) {
|
||||
case "role":
|
||||
if (array_key_exists($field, $formDatas) && $formDatas[$field]) {
|
||||
if (array_key_exists($field, $formDatas) && !is_null($formDatas[$field])) {
|
||||
$entity->$field = is_array($formDatas[$field]) ? implode("|", $formDatas[$field]) : $formDatas[$field];
|
||||
}
|
||||
break;
|
||||
|
||||
@ -26,7 +26,9 @@
|
||||
<?php foreach ($fields as $field) : ?>
|
||||
<td nowrap><?= getFieldIndex_Row_OrderHelper($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>
|
||||
<td>
|
||||
<?= $entity->getStatus() == DEFAULTS['STATUS'] ? anchor(current_url() . '/delete/' . $entity->getPrimaryKey(), ICONS['DELETE'], ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) : "" ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php $i++; ?>
|
||||
<?php endforeach; ?>
|
||||
@ -36,7 +38,6 @@
|
||||
<li class="nav-item"><?= form_checkbox(array("id" => "batchjobuids_checkbox")) ?>ALL</li>
|
||||
<?php foreach ($batchjobFilters as $field) : ?><li class="nav-item"><?= getFieldFilter_OrderHelper($field, DEFAULTS['EMPTY'], $fieldFormOptions) ?></li><?php endforeach; ?>
|
||||
<li class="nav-item"><?= form_submit('', '일괄처리', array("class" => "btn btn-outline btn-warning")); ?></li>
|
||||
<li class="nav-item"><?= anchor(current_url() . '/insert', '입력', ["class" => "btn btn-sm btn-primary btn-circle", "target" => "_self"]) ?></li>
|
||||
</ul>
|
||||
<?= $pagination ?>
|
||||
</div>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user