model
public function get_customers() {
$data = array();
if(is_array($this->config->get('finance_customer_group'))){
$customer_group_id = implode(",", $this->config->get('finance_customer_group'));
$query = $this->db->query("SELECT *, CONCAT(firstname, ' ', lastname) AS name FROM " . DB_PREFIX . "customer WHERE customer_group_id IN (" . $customer_group_id . ") ORDER BY name ASC");
$data = $query->rows;
}
return $data;
}
Передаю в Controller
$customers = $this->model_module_finance->get_customers();
$this->data['customers'] = array();
foreach($customers as $customer){
$costumer_id = $this->model_module_finance->getIdCustomer($customer['customer_id']); Передаю в model
if($costumer_id['customer_id'] == $customer['customer_id']) {
$this->data['customers'][] = array(
'name' => $customer['name'],
'orders' => $costumer_id['orders'],
'href' => $this->url->link('module/finance/customer_info', 'customer_id=' . $customer['customer_id'] . '&token=' . $this->session->data['token'], 'SSL')
);
}else{
$this->data['customers'][] = array(
'name' => $customer['name'],
'orders' => 0,
'href' => $this->url->link('module/finance/customer_info', 'customer_id=' . $customer['customer_id'] . '&token=' . $this->session->data['token'], 'SSL')
);
}
}
public function getIdCustomer($customer_id){ Передаю данные в Controller
$query = $this->db->query("SELECT oc_order.customer_id, COUNT(oc_order.order_id) as orders FROM oc_order WHERE oc_order.customer_id = '".$customer_id."' AND oc_order.order_id NOT IN (SELECT order_id FROM oc_finance_order WHERE oc_finance_order.customer_id = '".$customer_id."' ) AND oc_order.order_status_id > 0 AND oc_order.order_status_id !=7 GROUP BY oc_order.firstname ORDER BY oc_order.firstname ASC");
return $query->row;
}
Долго грузится, записей в базе в order
более 15000 Можно ускорить загрузку?
customer
только те записи у которых естьWHERE customer_group_id IN (" . $customer_group_id . ")
а вторяorder
выбирает те записи у которых ` WHERE oc_order.customer_id = '".$customer_id."' `