shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

marketing.php (2057B)


      1 <?php
      2 class ModelExtensionReportMarketing extends Model {
      3 	public function getMarketing($data = array()) {
      4 		$sql = "SELECT m.marketing_id, m.name AS campaign, m.code, m.clicks AS clicks, (SELECT COUNT(DISTINCT order_id) FROM `" . DB_PREFIX . "order` o1 WHERE o1.marketing_id = m.marketing_id";
      5 
      6 		if (!empty($data['filter_order_status_id'])) {
      7 			$sql .= " AND o1.order_status_id = '" . (int)$data['filter_order_status_id'] . "'";
      8 		} else {
      9 			$sql .= " AND o1.order_status_id > '0'";
     10 		}
     11 
     12 		if (!empty($data['filter_date_start'])) {
     13 			$sql .= " AND DATE(o1.date_added) >= '" . $this->db->escape($data['filter_date_start']) . "'";
     14 		}
     15 
     16 		if (!empty($data['filter_date_end'])) {
     17 			$sql .= " AND DATE(o1.date_added) <= '" . $this->db->escape($data['filter_date_end']) . "'";
     18 		}
     19 
     20 		$sql .= ") AS `orders`, (SELECT SUM(total) FROM `" . DB_PREFIX . "order` o2 WHERE o2.marketing_id = m.marketing_id";
     21 
     22 		if (!empty($data['filter_order_status_id'])) {
     23 			$sql .= " AND o2.order_status_id = '" . (int)$data['filter_order_status_id'] . "'";
     24 		} else {
     25 			$sql .= " AND o2.order_status_id > '0'";
     26 		}
     27 
     28 		if (!empty($data['filter_date_start'])) {
     29 			$sql .= " AND DATE(o2.date_added) >= '" . $this->db->escape($data['filter_date_start']) . "'";
     30 		}
     31 
     32 		if (!empty($data['filter_date_end'])) {
     33 			$sql .= " AND DATE(o2.date_added) <= '" . $this->db->escape($data['filter_date_end']) . "'";
     34 		}
     35 
     36 		$sql .= " GROUP BY o2.marketing_id) AS `total` FROM `" . DB_PREFIX . "marketing` m ORDER BY m.date_added ASC";
     37 
     38 		if (isset($data['start']) || isset($data['limit'])) {
     39 			if ($data['start'] < 0) {
     40 				$data['start'] = 0;
     41 			}
     42 
     43 			if ($data['limit'] < 1) {
     44 				$data['limit'] = 20;
     45 			}
     46 
     47 			$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
     48 		}
     49 
     50 		$query = $this->db->query($sql);
     51 
     52 		return $query->rows;
     53 	}
     54 
     55 	public function getTotalMarketing($data = array()) {
     56 		$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "marketing`");
     57 
     58 		return $query->row['total'];
     59 	}
     60 }