82 lines
2.2 KiB
PHP
82 lines
2.2 KiB
PHP
<?php if (!defined('BASEPATH')) {
|
|
exit('No direct script access allowed');
|
|
}
|
|
|
|
class Report_point_model extends CI_Model {
|
|
|
|
private $read_replica;
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
|
}
|
|
|
|
public function get_report_point_records(
|
|
$filters = [],
|
|
$limit = null,
|
|
$offset = null
|
|
) {
|
|
$combo_array = [
|
|
'status' => 'r.status'
|
|
];
|
|
|
|
$numeric_array = [
|
|
'member_id' => 'r.member_id',
|
|
'id' => 'm.id',
|
|
'from_points' => 'r.points >=',
|
|
'to_points' => 'r.points <='
|
|
];
|
|
|
|
$string_array = [
|
|
'description' => 'a.description'
|
|
];
|
|
|
|
$this->read_replica->select([
|
|
'm.firstname',
|
|
'm.lastname',
|
|
'm.id',
|
|
'a.description',
|
|
'r.points',
|
|
'r.added',
|
|
'r.status'
|
|
]);
|
|
|
|
$this->read_replica->from('members_points_redeem r');
|
|
$this->read_replica->join('points_redeem_avialable a', 'a.key=r.redeem_key', 'left');
|
|
$this->read_replica->join('members m', 'm.id = r.member_id', 'left');
|
|
|
|
$this->read_replica->where('r.status > 0');
|
|
foreach($filters as $key => $val) {
|
|
|
|
if (array_key_exists($key, $combo_array)) {
|
|
|
|
$this->read_replica->where($combo_array[$key], $val);
|
|
|
|
} else if (array_key_exists($key, $numeric_array)) {
|
|
|
|
$this->read_replica->where($numeric_array[$key], $val);
|
|
|
|
} else if (strpos($key, 'from') !== FALSE) {
|
|
|
|
$this->read_replica->where('DATE(r.added) >=', $val);
|
|
|
|
} else if (strpos($key, 'to') !== FALSE) {
|
|
|
|
$this->read_replica->where('DATE(r.added) <=', $val);
|
|
|
|
} else {
|
|
|
|
$this->read_replica->like('lower(' . $string_array[$key] . ')', strtolower($val));
|
|
|
|
}
|
|
}
|
|
|
|
if ($limit) {
|
|
$this->read_replica->limit($limit, $offset);
|
|
$this->read_replica->order_by('r.added DESC');
|
|
}
|
|
|
|
return $this->read_replica->get()->result_array();
|
|
}
|
|
} |