first commit
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
class ModelMarketingCoupon extends Model {
|
||||
public function addCoupon($data) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "coupon SET name = '" . $this->db->escape($data['name']) . "', code = '" . $this->db->escape($data['code']) . "', discount = '" . (float)$data['discount'] . "', type = '" . $this->db->escape($data['type']) . "', total = '" . (float)$data['total'] . "', logged = '" . (int)$data['logged'] . "', shipping = '" . (int)$data['shipping'] . "', date_start = '" . $this->db->escape($data['date_start']) . "', date_end = '" . $this->db->escape($data['date_end']) . "', uses_total = '" . (int)$data['uses_total'] . "', uses_customer = '" . (int)$data['uses_customer'] . "', status = '" . (int)$data['status'] . "', date_added = NOW()");
|
||||
|
||||
$coupon_id = $this->db->getLastId();
|
||||
|
||||
if (isset($data['coupon_product'])) {
|
||||
foreach ($data['coupon_product'] as $product_id) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "coupon_product SET coupon_id = '" . (int)$coupon_id . "', product_id = '" . (int)$product_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['coupon_category'])) {
|
||||
foreach ($data['coupon_category'] as $category_id) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "coupon_category SET coupon_id = '" . (int)$coupon_id . "', category_id = '" . (int)$category_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
return $coupon_id;
|
||||
}
|
||||
|
||||
public function editCoupon($coupon_id, $data) {
|
||||
$this->db->query("UPDATE " . DB_PREFIX . "coupon SET name = '" . $this->db->escape($data['name']) . "', code = '" . $this->db->escape($data['code']) . "', discount = '" . (float)$data['discount'] . "', type = '" . $this->db->escape($data['type']) . "', total = '" . (float)$data['total'] . "', logged = '" . (int)$data['logged'] . "', shipping = '" . (int)$data['shipping'] . "', date_start = '" . $this->db->escape($data['date_start']) . "', date_end = '" . $this->db->escape($data['date_end']) . "', uses_total = '" . (int)$data['uses_total'] . "', uses_customer = '" . (int)$data['uses_customer'] . "', status = '" . (int)$data['status'] . "' WHERE coupon_id = '" . (int)$coupon_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "coupon_product WHERE coupon_id = '" . (int)$coupon_id . "'");
|
||||
|
||||
if (isset($data['coupon_product'])) {
|
||||
foreach ($data['coupon_product'] as $product_id) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "coupon_product SET coupon_id = '" . (int)$coupon_id . "', product_id = '" . (int)$product_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "coupon_category WHERE coupon_id = '" . (int)$coupon_id . "'");
|
||||
|
||||
if (isset($data['coupon_category'])) {
|
||||
foreach ($data['coupon_category'] as $category_id) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "coupon_category SET coupon_id = '" . (int)$coupon_id . "', category_id = '" . (int)$category_id . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteCoupon($coupon_id) {
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "coupon WHERE coupon_id = '" . (int)$coupon_id . "'");
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "coupon_product WHERE coupon_id = '" . (int)$coupon_id . "'");
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "coupon_category WHERE coupon_id = '" . (int)$coupon_id . "'");
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "coupon_history WHERE coupon_id = '" . (int)$coupon_id . "'");
|
||||
}
|
||||
|
||||
public function getCoupon($coupon_id) {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "coupon WHERE coupon_id = '" . (int)$coupon_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
public function getCouponByCode($code) {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "coupon WHERE code = '" . $this->db->escape($code) . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
public function getCoupons($data = array()) {
|
||||
$sql = "SELECT coupon_id, name, code, discount, date_start, date_end, status FROM " . DB_PREFIX . "coupon";
|
||||
|
||||
$sort_data = array(
|
||||
'name',
|
||||
'code',
|
||||
'discount',
|
||||
'date_start',
|
||||
'date_end',
|
||||
'status'
|
||||
);
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY name";
|
||||
}
|
||||
|
||||
if (isset($data['order']) && ($data['order'] == 'DESC')) {
|
||||
$sql .= " DESC";
|
||||
} else {
|
||||
$sql .= " ASC";
|
||||
}
|
||||
|
||||
if (isset($data['start']) || isset($data['limit'])) {
|
||||
if ($data['start'] < 0) {
|
||||
$data['start'] = 0;
|
||||
}
|
||||
|
||||
if ($data['limit'] < 1) {
|
||||
$data['limit'] = 20;
|
||||
}
|
||||
|
||||
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
public function getCouponProducts($coupon_id) {
|
||||
$coupon_product_data = array();
|
||||
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "coupon_product WHERE coupon_id = '" . (int)$coupon_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$coupon_product_data[] = $result['product_id'];
|
||||
}
|
||||
|
||||
return $coupon_product_data;
|
||||
}
|
||||
|
||||
public function getCouponCategories($coupon_id) {
|
||||
$coupon_category_data = array();
|
||||
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "coupon_category WHERE coupon_id = '" . (int)$coupon_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$coupon_category_data[] = $result['category_id'];
|
||||
}
|
||||
|
||||
return $coupon_category_data;
|
||||
}
|
||||
|
||||
public function getTotalCoupons() {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "coupon");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function getCouponHistories($coupon_id, $start = 0, $limit = 10) {
|
||||
if ($start < 0) {
|
||||
$start = 0;
|
||||
}
|
||||
|
||||
if ($limit < 1) {
|
||||
$limit = 10;
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT ch.order_id, CONCAT(c.firstname, ' ', c.lastname) AS customer, ch.amount, ch.date_added FROM " . DB_PREFIX . "coupon_history ch LEFT JOIN " . DB_PREFIX . "customer c ON (ch.customer_id = c.customer_id) WHERE ch.coupon_id = '" . (int)$coupon_id . "' ORDER BY ch.date_added ASC LIMIT " . (int)$start . "," . (int)$limit);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
public function getTotalCouponHistories($coupon_id) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "coupon_history WHERE coupon_id = '" . (int)$coupon_id . "'");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
class ModelMarketingMarketing extends Model {
|
||||
public function addMarketing($data) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "marketing SET name = '" . $this->db->escape($data['name']) . "', description = '" . $this->db->escape($data['description']) . "', code = '" . $this->db->escape($data['code']) . "', date_added = NOW()");
|
||||
|
||||
return $this->db->getLastId();
|
||||
}
|
||||
|
||||
public function editMarketing($marketing_id, $data) {
|
||||
$this->db->query("UPDATE " . DB_PREFIX . "marketing SET name = '" . $this->db->escape($data['name']) . "', description = '" . $this->db->escape($data['description']) . "', code = '" . $this->db->escape($data['code']) . "' WHERE marketing_id = '" . (int)$marketing_id . "'");
|
||||
}
|
||||
|
||||
public function deleteMarketing($marketing_id) {
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "marketing WHERE marketing_id = '" . (int)$marketing_id . "'");
|
||||
}
|
||||
|
||||
public function getMarketing($marketing_id) {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "marketing WHERE marketing_id = '" . (int)$marketing_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
public function getMarketingByCode($code) {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "marketing WHERE code = '" . $this->db->escape($code) . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
public function getMarketings($data = array()) {
|
||||
$implode = array();
|
||||
|
||||
$order_statuses = $this->config->get('config_complete_status');
|
||||
|
||||
foreach ($order_statuses as $order_status_id) {
|
||||
$implode[] = "o.order_status_id = '" . (int)$order_status_id . "'";
|
||||
}
|
||||
|
||||
$sql = "SELECT *, (SELECT COUNT(*) FROM `" . DB_PREFIX . "order` o WHERE (" . implode(" OR ", $implode) . ") AND o.marketing_id = m.marketing_id) AS orders FROM " . DB_PREFIX . "marketing m";
|
||||
|
||||
$implode = array();
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$implode[] = "m.name LIKE '" . $this->db->escape($data['filter_name']) . "%'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_code'])) {
|
||||
$implode[] = "m.code = '" . $this->db->escape($data['filter_code']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_added'])) {
|
||||
$implode[] = "DATE(m.date_added) = DATE('" . $this->db->escape($data['filter_date_added']) . "')";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$sort_data = array(
|
||||
'm.name',
|
||||
'm.code',
|
||||
'm.date_added'
|
||||
);
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY m.name";
|
||||
}
|
||||
|
||||
if (isset($data['order']) && ($data['order'] == 'DESC')) {
|
||||
$sql .= " DESC";
|
||||
} else {
|
||||
$sql .= " ASC";
|
||||
}
|
||||
|
||||
if (isset($data['start']) || isset($data['limit'])) {
|
||||
if ($data['start'] < 0) {
|
||||
$data['start'] = 0;
|
||||
}
|
||||
|
||||
if ($data['limit'] < 1) {
|
||||
$data['limit'] = 20;
|
||||
}
|
||||
|
||||
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
public function getTotalMarketings($data = array()) {
|
||||
$sql = "SELECT COUNT(*) AS total FROM " . DB_PREFIX . "marketing";
|
||||
|
||||
$implode = array();
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$implode[] = "name LIKE '" . $this->db->escape($data['filter_name']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_code'])) {
|
||||
$implode[] = "code = '" . $this->db->escape($data['filter_code']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_added'])) {
|
||||
$implode[] = "DATE(date_added) = DATE('" . $this->db->escape($data['filter_date_added']) . "')";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user