示例#1
0
文件: mta.php 项目: pedrocones/store
 public function index()
 {
     $this->load->model('mta/mta_affiliate');
     $this->load->model('mta/mta_product_affiliate');
     $data['link_downline'] = $this->url->link('mta/affiliate_downline', 'token=' . $this->session->data['token'], 'SSL');
     $data['unconverted_affiliates'] = $this->model_mta_mta_affiliate->countPreMtaAffiliates();
     if ($data['unconverted_affiliates']) {
         $data = array_merge($data, array('text_unconverted_affiliates', 'text_convert_affiliates'));
     }
     $data = $this->_preprocess($data, array('insert', 'add'));
     $data['has_default'] = $this->model_mta_mta_affiliate->getDefaultSchemeId() ? true : false;
     if (!$data['has_default']) {
         $this->error = array_merge($this->error, array('no_default', 'no_default_unconverted'));
     }
     $data['schemes'] = $this->model_mta_mta_affiliate->getSchemes(array('sort' => 'default', 'order' => 'desc'));
     $data['user_types'] = array('affiliate' => 'a', 'product' => 'p', 'product_discount' => 'p_d', 'product_special' => 'p_s', 'product_coupon' => 'p_c', 'product_affiliate' => 'pa', 'product_affiliate_discount' => 'pa_d', 'product_affiliate_special' => 'pa_s', 'product_affiliate_coupon' => 'pa_c');
     $data['user_types_lng'] = array();
     $_trans = array();
     foreach ($data['user_types'] as $_k => $_v) {
         $_kAr = explode('_', $_k);
         $_kAr2 = array();
         foreach ($_kAr as $_k2) {
             if (!isset($_trans[$_k2])) {
                 $_trans[$_k2] = $this->language->get('word_' . $_k2);
             }
             $_kAr2[] = ucfirst($_trans[$_k2]);
         }
         $data['user_types_lng'][$_k] = implode(' / ', $_kAr2);
     }
     $data['s_opts'] = array();
     $data['all_fixed'] = array();
     foreach ($data['schemes'] as $i => $s) {
         $s['id'] = $s['mta_scheme_id'];
         $s['name'] = $s['scheme_name'];
         $s['user_count'] = $this->_count_scheme_users($s['id']);
         $s['user_total'] = array_sum(array_values($s['user_count']));
         foreach ($data['user_types'] as $_k => $_v) {
             if (!isset($s['user_count'][$_k])) {
                 $s['user_count'][$_k] = 0;
             }
         }
         $_c = unserialize($s['all_commissions']);
         foreach ($_c as $ii => $v) {
             foreach ($v as $i2 => $v2) {
                 $_c[$ii][$i2] = mta_float4($v2);
             }
             $_c[$ii] = implode(', ', $_c[$ii]);
         }
         $s['commissions'] = implode('<br />', $_c);
         unset($s['mta_scheme_id']);
         unset($s['scheme_name']);
         unset($s['all_commissions']);
         unset($s['all_autoadd']);
         $s['edit_link'] = array('text' => $this->language->get('text_edit'), 'href' => $this->url->link('mta/mta/edit', 'token=' . $this->session->data['token'] . '&id=' . $s['id'], 'SSL'));
         $data['s_opts'][] = array('id' => $s['id'], 'name' => $s['name']);
         if ($s['commission_type'] == 'fixed') {
             $data['all_fixed'][] = (int) $s['id'];
         }
         $data['schemes'][$i] = $s;
     }
     $data['all_fixed'] = json_encode($data['all_fixed']);
     $data['num_schemes'] = sizeof($data['schemes']);
     $this->load->model('localisation/order_status');
     $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
     $data['autoadd_statuses'] = $this->config->get('mta_ypx_autoadd_statuses');
     if (!is_array($data['autoadd_statuses'])) {
         $data['autoadd_statuses'] = $this->config->get('config_complete_status');
     }
     $data = $this->_process_errors($data);
     $data['header'] = $this->load->controller('common/header');
     $data['column_left'] = $this->load->controller('common/column_left');
     $data['footer'] = $this->load->controller('common/footer');
     $data['config'] = $this->config;
     $this->response->setOutput($this->load->view('mta/mta.tpl', $data));
 }
示例#2
0
 public function saveScheme()
 {
     $query = isset($this->scheme['id']) ? 'update ' : 'insert ';
     $query .= DB_PREFIX . "mta_scheme set scheme_name='" . $this->db->escape($this->scheme['name']) . "', description='" . $this->db->escape($this->scheme['description']) . "', max_levels='" . $this->scheme['max_levels'] . "', is_default='" . intval($this->scheme['is_default']) . "', all_commissions='" . $this->db->escape(serialize($this->scheme['_commissions'])) . "', all_autoadd='" . $this->db->escape(serialize($this->scheme['_autoadd'])) . "', commission_type='" . $this->scheme['commission_type'] . "', before_shipping='" . intval($this->scheme['before_shipping']) . "', eternal='" . intval($this->scheme['eternal']) . "'";
     if (!isset($this->scheme['id'])) {
         $query .= ", signup_code='" . $this->db->escape($this->scheme['signup_code']) . "'";
     }
     if (isset($this->scheme['id'])) {
         $query .= " where mta_scheme_id='" . $this->scheme['id'] . "'";
     }
     $this->db->query('start transaction');
     $dsid = $this->getDefaultSchemeId();
     if ($dsid && $this->scheme['is_default']) {
         $this->db->query("update " . DB_PREFIX . "mta_scheme set is_default='0' where is_default!='0'");
     }
     if (isset($this->scheme['id'])) {
         $this->db->query("delete from " . DB_PREFIX . "mta_autoapprove where mta_scheme_id='" . $this->scheme['id'] . "'");
         if ($this->db->countAffected() < 1) {
             return $this->_rollback();
         }
         $this->db->query("delete from " . DB_PREFIX . "mta_scheme_levels where mta_scheme_id='" . $this->scheme['id'] . "'");
         if ($this->db->countAffected() < 1) {
             return $this->_rollback();
         }
     }
     $this->db->query($query);
     if (!isset($this->scheme['id'])) {
         if ($this->db->countAffected() < 1) {
             return $this->_rollback();
         }
         $sid = $this->db->getLastId();
         if (!$sid) {
             return $this->_rollback();
         }
         $this->scheme['id'] = intval($sid);
         $this->scheme_id = $this->scheme['id'];
     }
     $_autoapprove = array();
     for ($i = 0; $i < sizeof($this->scheme['_autoapprove']); $i++) {
         $_autoapprove[] = "('" . $this->scheme['id'] . "','" . ($i + 1) . "','" . intval($this->scheme['_autoapprove'][$i]) . "')";
     }
     $this->db->query("insert into " . DB_PREFIX . "mta_autoapprove (mta_scheme_id , signup_level, autoapprove) values " . implode(',', $_autoapprove));
     if ($this->db->countAffected() < 1 || !$this->db->getLastId()) {
         return $this->_rollback();
     }
     $_levels = array();
     foreach ($this->scheme['_commissions'] as $i => $v) {
         foreach ($v as $i2 => $v2) {
             $_levels[] = "('" . $this->scheme['id'] . "','" . ($i + 1) . "','" . ($i2 + 1) . "','" . mta_float4($v2) . "','" . intval($this->scheme['_autoadd'][$i][$i2]) . "')";
         }
     }
     $this->db->query("insert into " . DB_PREFIX . "mta_scheme_levels (mta_scheme_id, num_levels, level, commission, autoadd) values " . implode(',', $_levels));
     if ($this->db->countAffected() < 1 || !$this->db->getLastId()) {
         return $this->_rollback();
     }
     $this->_fixDefaultScheme();
     return $this->_commit();
 }
示例#3
0
 public function createOrder($order_id, $aff_data)
 {
     //echo '1 $aff_data: ' . print_r($aff_data, 1);//-tmp
     $mta_order_ids = array();
     $this->db->query('start transaction');
     $_res = $this->db->query("SELECT mta_order_id from " . DB_PREFIX . "mta_order where order_id='" . (int) $order_id . "'");
     if ($_res->num_rows > 0) {
         $_moids = array();
         foreach ($_res->rows as $_r) {
             $_moids[] = $_r['mta_order_id'];
         }
         $this->db->query("delete from " . DB_PREFIX . "mta_order_product where mta_order_id IN (" . implode(',', $_moids) . ")");
         $this->db->query("delete from " . DB_PREFIX . "mta_order where order_id='" . (int) $order_id . "'");
     }
     foreach ($aff_data['order'] as $_o) {
         if ($_o['commission'] < 0.01) {
             continue;
         }
         $this->db->query("delete from " . DB_PREFIX . "mta_order where affiliate_id='{$_o['affiliate_id']}' and order_id='" . (int) $order_id . "'");
         $this->db->query("insert into " . DB_PREFIX . "mta_order (order_id, affiliate_id, commission, autoadd) values ('" . (int) $order_id . "', '{$_o['affiliate_id']}', '" . mta_float4($_o['commission']) . "', '" . (int) $_o['autoadd'] . "')");
         $mta_order_ids[$_o['affiliate_id']] = $this->db->getLastId();
     }
     //ar($aff_id => array('commission' =>, 'autoadd' =>, 'mta_scheme_id'=>,'num_levels'=>,'level'=>)
     if (sizeof($mta_order_ids) > 0) {
         $this->db->query("delete from " . DB_PREFIX . "mta_order_product where mta_order_id IN (" . implode(',', array_values($mta_order_ids)) . ")");
     }
     foreach ($aff_data['order_product'] as $product_id => $_ar) {
         $_res = $this->db->query("SELECT order_product_id from " . DB_PREFIX . "order_product where order_id='" . (int) $order_id . "' and product_id='{$product_id}'");
         if ($_res->num_rows > 0) {
             $_order_product_id = $_res->row['order_product_id'];
             foreach ($_ar as $_aff_id => $_op) {
                 if ($_op['commission'] < 0.01) {
                     continue;
                 }
                 $this->db->query("delete from " . DB_PREFIX . "mta_order_product where affiliate_id='{$_aff_id}' and order_product_id='{$_order_product_id}'");
                 $this->db->query("insert into " . DB_PREFIX . "mta_order_product (mta_order_id, product_id, order_product_id, affiliate_id, commission, mta_scheme_id, num_levels, level, autoadd) values ('" . $mta_order_ids[$_aff_id] . "', '{$product_id}', '{$_order_product_id}', '{$_aff_id}', '" . mta_float4($_op['commission']) . "', '{$_op['mta_scheme_id']}', '{$_op['num_levels']}', '{$_op['level']}', '" . (int) $_op['autoadd'] . "')");
             }
         }
     }
     $this->_commit();
 }
示例#4
0
 protected function &setScheme($s)
 {
     $this->scheme = array();
     if (!isset($s['id']) || !mta_check_int($s['id']) || $s['id'] < 1) {
         $this->scheme['error'] = 'Invalid ID';
         return $this->scheme;
     }
     $this->scheme_id = $s['id'];
     foreach (array('is_default', 'before_shipping') as $_k) {
         $this->scheme[$_k] = (bool) $s[$_k];
     }
     foreach (array('max_levels', 'eternal') as $_k) {
         $this->scheme[$_k] = (int) $s[$_k];
     }
     foreach ($s['_autoapprove'] as $i => $v) {
         $s['_autoapprove'][$i] = (bool) $v;
     }
     foreach ($s['_autoadd'] as $i => $v) {
         foreach ($v as $i2 => $v2) {
             $v[$i2] = (bool) $v2;
         }
         $s['_autoadd'][$i] = $v;
     }
     foreach ($s['_commissions'] as $i => $v) {
         foreach ($v as $i2 => $v2) {
             $v[$i2] = mta_float4($v2);
         }
         $s['_commissions'][$i] = $v;
     }
     foreach ($s as $k => $v) {
         if (!isset($this->scheme[$k])) {
             $this->scheme[$k] = $v;
         }
     }
     $dsid = $this->getDefaultSchemeId();
     if (!$dsid && !$this->scheme['is_default']) {
         $this->scheme['is_default'] = true;
     }
     //if($this->scheme['commission_type'] != 'percentage') $this->scheme['is_default'] = false;
     return $this->scheme;
 }