Initial import
This commit is contained in:
199
application/controllers/one_mitra/Updatestatus.php
Normal file
199
application/controllers/one_mitra/Updatestatus.php
Normal file
@@ -0,0 +1,199 @@
|
||||
<?php
|
||||
class Updatestatus extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
function index()
|
||||
{
|
||||
echo "Api: UPDATE STATUS QR & PEMERIKSAAN";
|
||||
}
|
||||
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 getRegionalIPAddress()
|
||||
{
|
||||
$sql_get = "SELECT S_SystemIPAddressRegional
|
||||
FROM conf_systems
|
||||
WHERE S_SystemsIsActive = 'Y'";
|
||||
|
||||
$qry = $this->db->query($sql_get);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("get ip regional failed", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
|
||||
$data = $qry->result_array();
|
||||
return $data[0]['S_SystemIPAddressRegional'];
|
||||
}
|
||||
function updatestatus()
|
||||
{
|
||||
try {
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
|
||||
$limit = 10;
|
||||
if (isset($prm['limit'])) {
|
||||
$limit = $prm['limit'];
|
||||
}
|
||||
|
||||
$getIPRegionalAddress = $this->getRegionalIPAddress();
|
||||
|
||||
// T_OrderFutureOrderID,
|
||||
// T_OrderOderHeaderID,
|
||||
// FutureMapT_OrderHeaderID
|
||||
$sql = "SELECT
|
||||
GROUP_CONCAT(T_OrderID) AS ID
|
||||
FROM one_mitra.t_order
|
||||
JOIN future_map
|
||||
ON T_OrderFutureOrderID = FutureMapFutureOrderID
|
||||
AND FutureMapIsActive = 'Y'
|
||||
WHERE
|
||||
T_OrderOderHeader IS NULL
|
||||
AND T_OrderIsActive = 'Y'
|
||||
LIMIT ?";
|
||||
$qry = $this->db->query($sql, [$limit]);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("", $this->db->error());
|
||||
exit;
|
||||
}
|
||||
$statusOrder = $qry->result_array();
|
||||
|
||||
// T_OrderFutureOrderID,
|
||||
// FutureQrCodeConfirmIsStatus
|
||||
$sql = "SELECT
|
||||
GROUP_CONCAT(T_OrderID) AS ID
|
||||
FROM one_mitra.t_order
|
||||
JOIN future_qrcode_confirm
|
||||
ON T_OrderFutureOrderID = FutureQrCodeConfirmFutureOrderID
|
||||
AND FutureQrCodeConfirmIsActive = 'Y'
|
||||
AND FutureQrCodeConfirmIsStatus IN ('S','R')
|
||||
WHERE T_OrderIsActive = 'Y'
|
||||
AND T_OrderWAStatus = 'N'
|
||||
LIMIT ?";
|
||||
$qry = $this->db->query($sql, [$limit]);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("", $this->db->error());
|
||||
exit;
|
||||
}
|
||||
$statusWa = $qry->result_array();
|
||||
if (count($statusWa) > 0) {
|
||||
$statusWa = explode(',', $statusWa[0]['ID']);
|
||||
} else {
|
||||
$statusWa = [];
|
||||
}
|
||||
if (count($statusOrder) > 0) {
|
||||
$statusOrder = explode(',', $statusOrder[0]['ID']);
|
||||
} else {
|
||||
$statusOrder = [];
|
||||
}
|
||||
$data = [
|
||||
"order" => $statusOrder,
|
||||
"wa" => $statusWa,
|
||||
];
|
||||
|
||||
$z_param = gzcompress(json_encode($data));
|
||||
$resp = $this->post("http://$getIPRegionalAddress/one-api/one_mitra/Updatestatusreg/updatestatusorder", $z_param);
|
||||
$resultUnc = gzuncompress($resp);
|
||||
$result = json_decode($resultUnc, true);
|
||||
// $this->sys_ok($result);
|
||||
// exit;
|
||||
|
||||
|
||||
$successOrder = $result['order']['success'];
|
||||
$successWa = $result['wa']['success'];
|
||||
for ($i = 0; $i < count($successOrder); $i++) {
|
||||
$sql = "UPDATE one_mitra.t_order
|
||||
SET T_OrderOderHeader = 'Y'
|
||||
WHERE T_OrderID = ?
|
||||
AND T_OrderIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, [$successOrder[$i]]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db($this->db->error());
|
||||
exit;
|
||||
}
|
||||
}
|
||||
for ($i = 0; $i < count($successWa); $i++) {
|
||||
$sql = "UPDATE one_mitra.t_order
|
||||
SET T_OrderWAStatus = 'Y'
|
||||
WHERE T_OrderID = ?
|
||||
AND T_OrderIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, [$successWa[$i]]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db($this->db->error());
|
||||
exit;
|
||||
}
|
||||
}
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
function convertobjtoarr($data)
|
||||
{
|
||||
|
||||
if (is_object($data)) {
|
||||
$data = get_object_vars($data);
|
||||
}
|
||||
|
||||
if (is_array($data)) {
|
||||
return array_map(__FUNCTION__, $data);
|
||||
} else {
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user