71 lines
1.9 KiB
PHP
71 lines
1.9 KiB
PHP
<?php
|
|
|
|
if (!defined('BASEPATH')) {
|
|
exit('No direct script access allowed');
|
|
}
|
|
|
|
/**
|
|
* Summary Report Model
|
|
*/
|
|
class Summary_report_model extends CI_Model {
|
|
|
|
protected $table = 'subscription_summary';
|
|
|
|
// read only database
|
|
private $read_replica;
|
|
|
|
function __construct() {
|
|
parent::__construct();
|
|
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
|
}
|
|
|
|
/**
|
|
* get summary report from worker
|
|
* @return array
|
|
*/
|
|
public function getSummaryReport( $params = array(), $limit = 0, $offset = 0 ) {
|
|
try {
|
|
$this->read_replica->select( '
|
|
mc.id as cardid,
|
|
mc.name as cardname,
|
|
sr.country as location,
|
|
(mc.card_points*50) as points,
|
|
sr.last_24hours as last_24hours,
|
|
sr.last_7days as last_7days,
|
|
sr.last_14days as last_14days,
|
|
sr.last_30days as last_30days,
|
|
sr.total_sub as total_sub,
|
|
sr.total_redeem as total_redeem
|
|
' );
|
|
$this->read_replica->from( sprintf( '%s sr', $this->table ) );
|
|
$this->read_replica->join( 'main_cards mc', 'mc.id = sr.card_id' );
|
|
// condition
|
|
if ( isset( $params['card_id'] ) and !empty( $params['card_id'] ) ) {
|
|
$this->read_replica->where( 'mc.id', $params['card_id'] );
|
|
}
|
|
|
|
if ( isset( $params['name'] ) and !empty( $params['name'] ) ) {
|
|
$this->read_replica->like( 'lower(mc.name)', strtolower( $params['name'] ) );
|
|
}
|
|
|
|
if ( isset( $params['location'] ) and !empty( $params['location'] ) ) {
|
|
$this->read_replica->like( 'lower(sr.country)', strtolower( $params['location'] ) );
|
|
}
|
|
|
|
if ( isset( $params['points'] ) and !empty( $params['points'] ) ) {
|
|
$this->read_replica->where( '(mc.card_points*50)', $params['points'] );
|
|
}
|
|
|
|
if ( $limit ) {
|
|
$this->read_replica->limit( $limit, $offset );
|
|
}
|
|
|
|
$this->read_replica->order_by( 'last_7days', 'desc' );
|
|
$results = $this->read_replica->get()->result_array();
|
|
|
|
return $results;
|
|
} catch (Exception $e) {
|
|
|
|
}
|
|
}
|
|
} |