diff options
Diffstat (limited to 'public/admin/model/extension/report/coupon.php')
-rw-r--r-- | public/admin/model/extension/report/coupon.php | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/public/admin/model/extension/report/coupon.php b/public/admin/model/extension/report/coupon.php new file mode 100644 index 0000000..86038c7 --- /dev/null +++ b/public/admin/model/extension/report/coupon.php @@ -0,0 +1,60 @@ +<?php +class ModelExtensionReportCoupon extends Model { + public function getCoupons($data = array()) { + $sql = "SELECT ch.coupon_id, c.name, c.code, COUNT(DISTINCT ch.order_id) AS `orders`, SUM(ch.amount) AS total FROM `" . DB_PREFIX . "coupon_history` ch LEFT JOIN `" . DB_PREFIX . "coupon` c ON (ch.coupon_id = c.coupon_id)"; + + $implode = array(); + + if (!empty($data['filter_date_start'])) { + $implode[] = "DATE(ch.date_added) >= '" . $this->db->escape($data['filter_date_start']) . "'"; + } + + if (!empty($data['filter_date_end'])) { + $implode[] = "DATE(ch.date_added) <= '" . $this->db->escape($data['filter_date_end']) . "'"; + } + + if ($implode) { + $sql .= " WHERE " . implode(" AND ", $implode); + } + + $sql .= " GROUP BY ch.coupon_id ORDER BY total DESC"; + + 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 getTotalCoupons($data = array()) { + $sql = "SELECT COUNT(DISTINCT coupon_id) AS total FROM `" . DB_PREFIX . "coupon_history`"; + + $implode = array(); + + if (!empty($data['filter_date_start'])) { + $implode[] = "DATE(date_added) >= '" . $this->db->escape($data['filter_date_start']) . "'"; + } + + if (!empty($data['filter_date_end'])) { + $implode[] = "DATE(date_added) <= '" . $this->db->escape($data['filter_date_end']) . "'"; + } + + if ($implode) { + $sql .= " WHERE " . implode(" AND ", $implode); + } + + $query = $this->db->query($sql); + + return $query->row['total']; + } +}
\ No newline at end of file |