70 lines
1.9 KiB
PHP
70 lines
1.9 KiB
PHP
|
|
|
|
<?php if (!defined('BASEPATH')) {
|
|
exit('No direct script access allowed');
|
|
}
|
|
|
|
class Credit_card_benefit_model extends CI_Model
|
|
{
|
|
private $read_replica;
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
|
}
|
|
|
|
public function insert($data) {
|
|
$data_insert = [];
|
|
|
|
foreach($data['benefits[]'] as $key => $val) {
|
|
$data_insert[] = [
|
|
'credit_card_id' => $data['credit_card_id'],
|
|
'benefit' => $val,
|
|
'expired_date' => (empty($data['expired_date[]'][$key])
|
|
? null
|
|
: $data['expired_date[]'][$key])
|
|
];
|
|
}
|
|
|
|
if ($data_insert) {
|
|
$this->db->insert_batch('credit_card_benefits', $data_insert);
|
|
}
|
|
}
|
|
|
|
public function delete($data) {
|
|
$this->db->where('credit_card_id', $data['credit_card_id']);
|
|
$this->db->delete('credit_card_benefits');
|
|
}
|
|
|
|
public function getBenefitByCardID($id) {
|
|
$this->read_replica->select([
|
|
'id',
|
|
'benefit',
|
|
'DATE(expired_date) AS expired_date'
|
|
]);
|
|
$this->read_replica->from('credit_card_benefits');
|
|
$this->read_replica->where('credit_card_id', $id);
|
|
$this->read_replica->order_by('benefit ASC');
|
|
|
|
return $this->read_replica->get()->result_array();
|
|
}
|
|
|
|
public function update($data) {
|
|
$data_update = [];
|
|
|
|
foreach($data['benefit_id'] as $key => $val) {
|
|
$data_update[] = [
|
|
'id' => $val,
|
|
'benefit' => $data['benefit'][$key],
|
|
'expired_date' => (empty($data['expired_date'][$key])
|
|
? null
|
|
: $data['expired_date'][$key])
|
|
];
|
|
}
|
|
|
|
if ($data_update) {
|
|
$this->db->update_batch('credit_card_benefits', $data_update, 'id');
|
|
}
|
|
}
|
|
} |