merciless
Đã tốn tiền
Hi các thím,
Em bị tình trạng này mong các thím giúp đỡ ạ.
Mô tả:
Web hiển thị nút Xóa.
Người dùng cần có quyền xóa (quyền số 13 trong mảng của group_permission)
Tình trạng lỗi: Người dùng có hay không có quyền số 13 đều Xóa được nội dung.
Kiểm thử với ($this->db->trans_status() === FALSE) thì không thấy kết quả, cũng không hiển thị được thông báo thất bại. Em google chiều giờ mà chưa tìm ra nguyên nhân.
Dưới đây là các đoạn code liên quan.
Rất mong các thím hướng dẫn cách khắc phục
1. Đoạn code hiển thị nút xóa
2. Đoạn code update và điều kiện khi người dùng bấm nút xóa
3. Đoạn js thông báo thành công _ lỗi
Em bị tình trạng này mong các thím giúp đỡ ạ.
Mô tả:
Web hiển thị nút Xóa.
Người dùng cần có quyền xóa (quyền số 13 trong mảng của group_permission)
Tình trạng lỗi: Người dùng có hay không có quyền số 13 đều Xóa được nội dung.
Kiểm thử với ($this->db->trans_status() === FALSE) thì không thấy kết quả, cũng không hiển thị được thông báo thất bại. Em google chiều giờ mà chưa tìm ra nguyên nhân.
Dưới đây là các đoạn code liên quan.
Rất mong các thím hướng dẫn cách khắc phục
1. Đoạn code hiển thị nút xóa
<i class="fa fa-trash-o" style="color: darkred;" title="<?php if ($option == 1)
echo 'Xóa vĩnh viễn';
else
echo 'Xóa'?>"
onclick="<?php if ($option == 1)
echo 'cms_del_order';
else
echo 'cms_del_temp_order'?>(<?php echo $item['ID'] . ',' . $page; ?>)"></i>
echo 'Xóa vĩnh viễn';
else
echo 'Xóa'?>"
onclick="<?php if ($option == 1)
echo 'cms_del_order';
else
echo 'cms_del_temp_order'?>(<?php echo $item['ID'] . ',' . $page; ?>)"></i>
2. Đoạn code update và điều kiện khi người dùng bấm nút xóa
public function cms_del_temp_order($id)
{
if ($this->auth == null || !in_array(13, $this->auth['group_permission']))
$this->cms_common_string->cms_redirect(CMS_BASE_URL . 'backend');
$id = (int)$id;
$order = $this->db->from('orders')->where(['ID' => $id, 'deleted' => 0])->get()->row_array();
$store_id = $order['store_id'];
$this->db->trans_begin();
$user_init = $this->auth['id'];
if (isset($order) && count($order)) {
if ($order['order_status'] == 1) {
$list_products = json_decode($order['detail_order'], true);
foreach ($list_products as $item) {
$inventory_quantity = $this->db->select('quantity')->from('inventory')->where(['store_id' => $store_id, 'product_id' => $item['id']])->get()->row_array();
if (!empty($inventory_quantity)) {
$this->db->where(['store_id' => $store_id, 'product_id' => $item['id']])->update('inventory', ['quantity' => $inventory_quantity['quantity'] + $item['quantity'], 'user_upd' => $user_init]);
} else {
$inventory = ['store_id' => $store_id, 'product_id' => $item['id'], 'quantity' => $item['quantity'], 'user_init' => $user_init];
$this->db->insert('inventory', $inventory);
}
$product = $this->db->select('prd_sls')->from('products')->where('ID', $item['id'])->get()->row_array();
$sls['prd_sls'] = $product['prd_sls'] + $item['quantity'];
$this->db->where('ID', $item['id'])->update('products', $sls);
$this->db->where(['transaction_id' => $id, 'product_id' => $item['id'], 'store_id' => $store_id])->update('report', ['deleted' => 1, 'user_upd' => $user_init]);
}
$this->db->where('order_id', $id)->update('receipt', ['deleted' => 1, 'user_upd' => $user_init]);
$this->db->where('ID', $id)->update('orders', ['deleted' => 1, 'user_upd' => $user_init]);
$this->cms_del_temp_input($id);
} else {
$this->db->where('ID', $id)->update('orders', ['deleted' => 1, 'user_upd' => $user_init]);
}
}
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
echo $this->messages = "0";
} else {
$this->db->trans_commit();
echo $this->messages = "1";
}
}
public function cms_del_order($id)
{
if ($this->auth == null || !in_array(13, $this->auth['group_permission']))
$this->cms_common_string->cms_redirect(CMS_BASE_URL . 'backend');
$id = (int)$id;
$order = $this->db->from('orders')->where(['ID' => $id, 'deleted' => 1])->get()->row_array();
$this->db->trans_begin();
if (isset($order) && count($order)) {
$this->db->where('ID', $id)->update('orders', ['deleted' => 2, 'user_upd' => $this->auth['id']]);
} else
echo $this->messages = "0";
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
echo $this->messages = "0";
} else {
$this->db->trans_commit();
echo $this->messages = "1";
}
}
{
if ($this->auth == null || !in_array(13, $this->auth['group_permission']))
$this->cms_common_string->cms_redirect(CMS_BASE_URL . 'backend');
$id = (int)$id;
$order = $this->db->from('orders')->where(['ID' => $id, 'deleted' => 0])->get()->row_array();
$store_id = $order['store_id'];
$this->db->trans_begin();
$user_init = $this->auth['id'];
if (isset($order) && count($order)) {
if ($order['order_status'] == 1) {
$list_products = json_decode($order['detail_order'], true);
foreach ($list_products as $item) {
$inventory_quantity = $this->db->select('quantity')->from('inventory')->where(['store_id' => $store_id, 'product_id' => $item['id']])->get()->row_array();
if (!empty($inventory_quantity)) {
$this->db->where(['store_id' => $store_id, 'product_id' => $item['id']])->update('inventory', ['quantity' => $inventory_quantity['quantity'] + $item['quantity'], 'user_upd' => $user_init]);
} else {
$inventory = ['store_id' => $store_id, 'product_id' => $item['id'], 'quantity' => $item['quantity'], 'user_init' => $user_init];
$this->db->insert('inventory', $inventory);
}
$product = $this->db->select('prd_sls')->from('products')->where('ID', $item['id'])->get()->row_array();
$sls['prd_sls'] = $product['prd_sls'] + $item['quantity'];
$this->db->where('ID', $item['id'])->update('products', $sls);
$this->db->where(['transaction_id' => $id, 'product_id' => $item['id'], 'store_id' => $store_id])->update('report', ['deleted' => 1, 'user_upd' => $user_init]);
}
$this->db->where('order_id', $id)->update('receipt', ['deleted' => 1, 'user_upd' => $user_init]);
$this->db->where('ID', $id)->update('orders', ['deleted' => 1, 'user_upd' => $user_init]);
$this->cms_del_temp_input($id);
} else {
$this->db->where('ID', $id)->update('orders', ['deleted' => 1, 'user_upd' => $user_init]);
}
}
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
echo $this->messages = "0";
} else {
$this->db->trans_commit();
echo $this->messages = "1";
}
}
public function cms_del_order($id)
{
if ($this->auth == null || !in_array(13, $this->auth['group_permission']))
$this->cms_common_string->cms_redirect(CMS_BASE_URL . 'backend');
$id = (int)$id;
$order = $this->db->from('orders')->where(['ID' => $id, 'deleted' => 1])->get()->row_array();
$this->db->trans_begin();
if (isset($order) && count($order)) {
$this->db->where('ID', $id)->update('orders', ['deleted' => 2, 'user_upd' => $this->auth['id']]);
} else
echo $this->messages = "0";
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
echo $this->messages = "0";
} else {
$this->db->trans_commit();
echo $this->messages = "1";
}
}
3. Đoạn js thông báo thành công _ lỗi
function cms_del_temp_order($id, $page) {
var conf = confirm('Bạn chắc chắn muốn xóa đơn hàng này?');
if (conf) {
var $param = {
'type': 'POST',
'url': 'orders/cms_del_temp_order/' + $id,
'data': null,
'callback': function (data) {
if (data == '1') {
cms_paging_order($page);
$('.ajax-success-ct').html('Xóa đơn hàng thành công.').parent().fadeIn().delay(1000).fadeOut('slow');
} else if (data == '0') {
$('.ajax-error-ct').html('Oops! This system is errors! please try again.').parent().fadeIn().delay(1000).fadeOut('slow');
}
}
};
cms_adapter_ajax($param);
}
}
var conf = confirm('Bạn chắc chắn muốn xóa đơn hàng này?');
if (conf) {
var $param = {
'type': 'POST',
'url': 'orders/cms_del_temp_order/' + $id,
'data': null,
'callback': function (data) {
if (data == '1') {
cms_paging_order($page);
$('.ajax-success-ct').html('Xóa đơn hàng thành công.').parent().fadeIn().delay(1000).fadeOut('slow');
} else if (data == '0') {
$('.ajax-error-ct').html('Oops! This system is errors! please try again.').parent().fadeIn().delay(1000).fadeOut('slow');
}
}
};
cms_adapter_ajax($param);
}
}


