1: | <?php
2: | namespace Opencart\Admin\Model\Extension\Opencart\Report;
3: | /**
4: | * Class Marketing
5: | *
6: | * @package Opencart\Admin\Model\Extension\Opencart\Report
7: | */
8: | class Marketing extends \Opencart\System\Engine\Model {
9: | /**
10: | * Get Marketing
11: | *
12: | * @param array<string, mixed> $data
13: | *
14: | * @return array<int, array<string, mixed>>
15: | */
16: | public function getMarketing(array $data = []): array {
17: | $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`";
18: |
19: | if (!empty($data['filter_order_status_id'])) {
20: | $sql .= " AND o1.`order_status_id` = '" . (int)$data['filter_order_status_id'] . "'";
21: | } else {
22: | $sql .= " AND o1.`order_status_id` > '0'";
23: | }
24: |
25: | if (!empty($data['filter_date_start'])) {
26: | $sql .= " AND DATE(o1.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_start']) . "')";
27: | }
28: |
29: | if (!empty($data['filter_date_end'])) {
30: | $sql .= " AND DATE(o1.`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_end']) . "')";
31: | }
32: |
33: | $sql .= ") AS `orders`, (SELECT SUM(`total`) FROM `" . DB_PREFIX . "order` o2 WHERE o2.`marketing_id` = m.`marketing_id`";
34: |
35: | if (!empty($data['filter_order_status_id'])) {
36: | $sql .= " AND o2.`order_status_id` = '" . (int)$data['filter_order_status_id'] . "'";
37: | } else {
38: | $sql .= " AND o2.`order_status_id` > '0'";
39: | }
40: |
41: | if (!empty($data['filter_date_start'])) {
42: | $sql .= " AND DATE(o2.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_start']) . "')";
43: | }
44: |
45: | if (!empty($data['filter_date_end'])) {
46: | $sql .= " AND DATE(o2.`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_end']) . "')";
47: | }
48: |
49: | $sql .= " GROUP BY o2.`marketing_id`) AS `total` FROM `" . DB_PREFIX . "marketing` m ORDER BY m.`date_added` ASC";
50: |
51: | if (isset($data['start']) || isset($data['limit'])) {
52: | if ($data['start'] < 0) {
53: | $data['start'] = 0;
54: | }
55: |
56: | if ($data['limit'] < 1) {
57: | $data['limit'] = 20;
58: | }
59: |
60: | $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
61: | }
62: |
63: | $query = $this->db->query($sql);
64: |
65: | return $query->rows;
66: | }
67: |
68: | /**
69: | * Get Total Marketing
70: | *
71: | * @param array<mixed> $data
72: | *
73: | * @return int
74: | */
75: | public function getTotalMarketing(array $data = []): int {
76: | $query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "marketing`");
77: |
78: | return (int)$query->row['total'];
79: | }
80: | }
81: |

OpenCart API API documentation generated by ApiGen dev-master