159 lines
5.2 KiB
PHP
159 lines
5.2 KiB
PHP
<?php
|
|
class Downloadinfo extends MY_Controller
|
|
{
|
|
var $db_onedev;
|
|
var $hostname;
|
|
var $load;
|
|
public function index()
|
|
{
|
|
echo "Downloadinfo API";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->hostname = 'devbandungraya.aplikasi.web.id';
|
|
// $this->hostname = 'bankpoint.jala.my.id';
|
|
$this->db_onedev = $this->load->database("onedev", true);
|
|
}
|
|
|
|
public function getdata()
|
|
{
|
|
$sql = "SELECT Status_GatewayLastInfoDownloaded
|
|
FROM one_pointreward.status_gateway
|
|
LIMIT 1";
|
|
|
|
$qry = $this->db_onedev->query($sql, array());
|
|
|
|
|
|
$result = [];
|
|
|
|
if (!$qry) {
|
|
$rst["message"] = "Err select orderheaderid | " . $this->db_onedev->error()["message"] . "|"
|
|
. $this->db_onedev->last_query();
|
|
// $this->resp["message"] = "Err select orderheaderid | " . $this->db_onedev->error()["message"] . "|"
|
|
// . $this->db_onedev->last_query();
|
|
}
|
|
$rows = $qry->result_array();
|
|
print_r($rows);
|
|
if (count($rows) == 0) {
|
|
$rst["message"] = "No Pending Request";
|
|
//$this->resp["message"] = "No Pending Request";
|
|
} else {
|
|
foreach ($rows as $k => $v) {
|
|
$data = array(
|
|
"date" => $v["Status_GatewayLastInfoDownloaded"]
|
|
);
|
|
$param = json_encode($data);
|
|
$url = "http://" . $this->hostname . "/one-api/tools/member/info/get_data_by_date/";
|
|
// echo "to $url \n param : $param\n";
|
|
$post_rst = $this->post($url, $param);
|
|
$rst = json_decode(gzuncompress($post_rst), true);
|
|
|
|
// echo $rst["status"];
|
|
print_r($rst);
|
|
$result[] = $rst;
|
|
if ($rst["status"] == "OK") {
|
|
} else {
|
|
}
|
|
}
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
}
|
|
function downloadInfo()
|
|
{
|
|
$sql = "SELECT Status_GatewayLastInfoDownloaded
|
|
FROM one_pointreward.status_gateway
|
|
LIMIT 1";
|
|
$qry = $this->db_onedev->query($sql, []);
|
|
|
|
if (!$qry) {
|
|
$this->sys_error_db("Error get last downloade info");
|
|
exit;
|
|
}
|
|
$info = $qry->result_array();
|
|
$result = array();
|
|
if (count($info) > 0) {
|
|
$lastDownloaded = $info[0]['Status_GatewayLastInfoDownloaded'];
|
|
$data = array(
|
|
"date" => $lastDownloaded
|
|
);
|
|
$param = json_encode($data);
|
|
|
|
$url = "http://" . $this->hostname . "/one-api/tools/member/info/get_data_by_date/";
|
|
|
|
$post_rst = $this->post($url, $param);
|
|
$rst = json_decode(gzuncompress($post_rst), true);
|
|
if ($rst['status'] == "OK") {
|
|
$result = $rst;
|
|
} else {
|
|
echo json_encode($rst);
|
|
exit;
|
|
}
|
|
}
|
|
echo json_encode($rst);
|
|
exit;
|
|
}
|
|
|
|
public function insertInfo($nik, $visit, $point)
|
|
{
|
|
// {"member_nik":"0123459547894563","member_point":"20000","member_visit":"2"}
|
|
$sql = "INSERT INTO one_pointreward.member_infonational(
|
|
MemberInfoNasionalNIK,
|
|
MemberInfoNasionalCountVisit,
|
|
MemberInfoNasionalPoint)
|
|
VALUES(
|
|
'{$nik}',
|
|
'{$visit}',
|
|
'{$point}'
|
|
) ON DUPLICATE KEY UPDATE
|
|
MemberInfoNasionalCountVisit = '{$visit}',
|
|
MemberInfoNasionalPoint = '{$point}',
|
|
MemberInfoNasionalLastUpdated = NOW()";
|
|
$qry = $this->db_onedev->query($sql, []);
|
|
if (!$qry) {
|
|
$this->sys_error_db("Error insert member nasional");
|
|
exit;
|
|
}
|
|
$this->updateStatus();
|
|
$this->sys_ok("Success");
|
|
}
|
|
public function updateStatus()
|
|
{
|
|
$sql = "UPDATE one_pointreward.status_gateway
|
|
SET Status_GatewayLastInfoDownloaded = NOW()
|
|
WHERE Status_GatewayID = 1";
|
|
$qry = $this->db_onedev->query($sql, []);
|
|
|
|
if (!$qry) {
|
|
$this->sys_error_db("Error update status gateway");
|
|
exit;
|
|
}
|
|
}
|
|
public function post($url, $data)
|
|
{
|
|
$ch = curl_init($url);
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
|
"Content-Type: application/text",
|
|
"Content-Length: " . strlen($data),
|
|
]);
|
|
$result = curl_exec($ch);
|
|
if (curl_error($ch) != "") {
|
|
echo json_encode([
|
|
"status" => "ERR",
|
|
"message" => "Http Error : " . curl_error($ch),
|
|
]);
|
|
curl_close($ch);
|
|
exit();
|
|
}
|
|
curl_close($ch);
|
|
return $result;
|
|
}
|
|
}
|