147 lines
4.4 KiB
PHP
147 lines
4.4 KiB
PHP
<?php
|
|
class Uploadpoint extends MY_Controller
|
|
{
|
|
var $db;
|
|
var $load;
|
|
var $sspricemou;
|
|
var $hostname;
|
|
var $db_onedev;
|
|
|
|
public function index()
|
|
{
|
|
echo "CPONE MD PRICE API";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_onedev = $this->load->database("onedev", true);
|
|
$this->hostname = 'bankpoint.jala.my.id';
|
|
// $this->load->library("SsPriceMou");
|
|
}
|
|
function reply($resp)
|
|
{
|
|
echo json_encode($resp);
|
|
}
|
|
|
|
function reply_gz($resp, $debug = "")
|
|
{
|
|
if ($debug != "") {
|
|
echo json_encode($resp);
|
|
} else {
|
|
echo gzcompress(json_encode($resp));
|
|
}
|
|
}
|
|
|
|
function get_param()
|
|
{
|
|
$body = file_get_contents("php://input");
|
|
return json_decode($body, true);
|
|
}
|
|
|
|
function get_param_z()
|
|
{
|
|
$body_z = file_get_contents("php://input");
|
|
$body = gzuncompress($body_z);
|
|
return json_decode($body, true);
|
|
}
|
|
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;
|
|
}
|
|
public function list($date = "")
|
|
{
|
|
if ($date == "") {
|
|
$date = date("Y-m-d");
|
|
}
|
|
$sql = "select *
|
|
FROM
|
|
member_point_confirm
|
|
WHERE Member_PointConfirmIsSent = 'N'
|
|
AND date(Member_PointConfirmLastUpdated) = ?";
|
|
|
|
$qry = $this->db_onedev->query($sql, array($date));
|
|
//echo $this->db_onedev->last_query();
|
|
if (!$qry) {
|
|
$rst["message"] = "Err select member_point_confirm | " . $this->db_onedev->error()["message"] . "|"
|
|
. $this->db_onedev->last_query();
|
|
}
|
|
$rows = $qry->result_array();
|
|
//print_r($rows);
|
|
if ($api == "Y") {
|
|
$this->sys_ok($data);
|
|
# code...
|
|
}
|
|
return $rows;
|
|
}
|
|
function upload($date = "")
|
|
{
|
|
if ($date == "") {
|
|
$date = date("Y-m-d");
|
|
}
|
|
$url_nat = "http://" . $this->hostname . "/one-api/tools/member/downloadpoint/getpoint/";
|
|
$data = $this->list($date);
|
|
//echo "\n data : \n "; print_r($data);
|
|
$prm = array(
|
|
"status" => 'OK',
|
|
"data" => $data,
|
|
);
|
|
$prm_json = gzcompress(json_encode($prm));
|
|
// echo "JSON PRM \n";
|
|
// print_r($prm_json);
|
|
// echo " \n";
|
|
// print_r($url_nat . "generate");
|
|
// echo " \n";
|
|
if (count($data) > 0) {
|
|
# code...
|
|
$resp = $this->post($url_nat . "generate", $prm_json);
|
|
// echo "JSON resp \n";
|
|
// print_r($resp);
|
|
$retVal = json_decode(gzuncompress($resp), true);
|
|
// print_r($retVal);
|
|
if ($retVal['status'] == 'OK') {
|
|
$this->updateStatusUpload($retVal['data']);
|
|
$this->sys_ok("Success". print_r($data,true));
|
|
} else {
|
|
$this->sys_error($retVal);
|
|
};
|
|
} else {
|
|
$this->sys_ok("Tidak ada data update");
|
|
}
|
|
}
|
|
function updateStatusUpload($data)
|
|
{
|
|
|
|
for ($i = 0; $i < count($data); $i++) {
|
|
$member = $data[$i];
|
|
$sql = "UPDATE member_point_confirm SET Member_PointConfirmIsSent = 'Y' WHERE Member_PointConfirmT_OrderHeaderID = ?";
|
|
$qry = $this->db->query($sql, [$member['Member_PointConfirmT_OrderHeaderID']]);
|
|
|
|
if (!$qry) {
|
|
$this->sys_error_db("Error update status tabel member");
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
}
|