| 1: | <?php
|
| 2: | namespace Opencart\Catalog\Model\Account;
|
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: |
|
| 8: | class Affiliate extends \Opencart\System\Engine\Model {
|
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: |
|
| 17: | public function addAffiliate(int $customer_id, array $data): void {
|
| 18: | $this->db->query("INSERT INTO `" . DB_PREFIX . "customer_affiliate` SET `customer_id` = '" . (int)$customer_id . "', `company` = '" . $this->db->escape($data['company']) . "', `website` = '" . $this->db->escape($data['website']) . "', `tracking` = '" . $this->db->escape(oc_token(10)) . "', `commission` = '" . (float)$this->config->get('config_affiliate_commission') . "', `tax` = '" . $this->db->escape($data['tax']) . "', `payment_method` = '" . $this->db->escape($data['payment_method']) . "', `cheque` = '" . $this->db->escape($data['cheque']) . "', `paypal` = '" . $this->db->escape($data['paypal']) . "', `bank_name` = '" . $this->db->escape($data['bank_name']) . "', `bank_branch_number` = '" . $this->db->escape($data['bank_branch_number']) . "', `bank_swift_code` = '" . $this->db->escape($data['bank_swift_code']) . "', `bank_account_name` = '" . $this->db->escape($data['bank_account_name']) . "', `bank_account_number` = '" . $this->db->escape($data['bank_account_number']) . "', `custom_field` = '" . $this->db->escape(isset($data['custom_field']) ? json_encode($data['custom_field']) : '') . "', `status` = '" . (int)!$this->config->get('config_affiliate_approval') . "', `date_added` = NOW()");
|
| 19: |
|
| 20: | if ($this->config->get('config_affiliate_approval')) {
|
| 21: | $this->load->model('account/approval');
|
| 22: |
|
| 23: | $this->model_account_approval->addApproval($customer_id, 'affiliate');
|
| 24: | }
|
| 25: | }
|
| 26: |
|
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: |
|
| 35: | public function editAffiliate(int $customer_id, array $data): void {
|
| 36: | $this->db->query("UPDATE `" . DB_PREFIX . "customer_affiliate` SET `company` = '" . $this->db->escape($data['company']) . "', `website` = '" . $this->db->escape($data['website']) . "', `commission` = '" . (float)$this->config->get('config_affiliate_commission') . "', `tax` = '" . $this->db->escape($data['tax']) . "', `payment_method` = '" . $this->db->escape($data['payment_method']) . "', `cheque` = '" . $this->db->escape($data['cheque']) . "', `paypal` = '" . $this->db->escape($data['paypal']) . "', `bank_name` = '" . $this->db->escape($data['bank_name']) . "', `bank_branch_number` = '" . $this->db->escape($data['bank_branch_number']) . "', `bank_swift_code` = '" . $this->db->escape($data['bank_swift_code']) . "', `bank_account_name` = '" . $this->db->escape($data['bank_account_name']) . "', `bank_account_number` = '" . $this->db->escape($data['bank_account_number']) . "', `custom_field` = '" . $this->db->escape(isset($data['custom_field']) ? json_encode($data['custom_field']) : '') . "' WHERE `customer_id` = '" . (int)$customer_id . "'");
|
| 37: | }
|
| 38: |
|
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | |
| 44: | |
| 45: |
|
| 46: | public function deleteAffiliate(int $customer_id): void {
|
| 47: | $this->db->query("DELETE FROM `" . DB_PREFIX . "customer_affiliate` WHERE `customer_id` = '" . (int)$customer_id . "'");
|
| 48: |
|
| 49: | $this->deleteReports($customer_id);
|
| 50: | }
|
| 51: |
|
| 52: | |
| 53: | |
| 54: | |
| 55: | |
| 56: | |
| 57: | |
| 58: |
|
| 59: | public function getAffiliate(int $customer_id): array {
|
| 60: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer_affiliate` WHERE `customer_id` = '" . (int)$customer_id . "'");
|
| 61: |
|
| 62: | if ($query->num_rows) {
|
| 63: | return $query->row + ['custom_field' => json_decode($query->row['custom_field'], true)];
|
| 64: | } else {
|
| 65: | return [];
|
| 66: | }
|
| 67: | }
|
| 68: |
|
| 69: | |
| 70: | |
| 71: | |
| 72: | |
| 73: | |
| 74: | |
| 75: |
|
| 76: | public function getAffiliateByTracking(string $code): array {
|
| 77: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer_affiliate` WHERE `tracking` = '" . $this->db->escape($code) . "'");
|
| 78: |
|
| 79: | if ($query->num_rows) {
|
| 80: | return $query->row + ['custom_field' => json_decode($query->row['custom_field'], true)];
|
| 81: | } else {
|
| 82: | return [];
|
| 83: | }
|
| 84: | }
|
| 85: |
|
| 86: | |
| 87: | |
| 88: | |
| 89: | |
| 90: | |
| 91: | |
| 92: | |
| 93: | |
| 94: |
|
| 95: | public function addReport(int $customer_id, string $ip, string $country = ''): void {
|
| 96: | $this->db->query("INSERT INTO `" . DB_PREFIX . "customer_affiliate_report` SET `customer_id` = '" . (int)$customer_id . "', `store_id` = '" . (int)$this->config->get('config_store_id') . "', `ip` = '" . $this->db->escape($ip) . "', `country` = '" . $this->db->escape($country) . "', `date_added` = NOW()");
|
| 97: | }
|
| 98: |
|
| 99: | |
| 100: | |
| 101: | |
| 102: | |
| 103: | |
| 104: | |
| 105: |
|
| 106: | public function deleteReports(int $customer_id): void {
|
| 107: | $this->db->query("DELETE FROM `" . DB_PREFIX . "customer_affiliate_report` WHERE `customer_id` = '" . (int)$customer_id . "'");
|
| 108: | }
|
| 109: | }
|
| 110: | |