105 lines
4.5 KiB
PHP
105 lines
4.5 KiB
PHP
<?php
|
|
class OutgoingRef_v2 extends MY_Controller
|
|
{
|
|
function __construct() {
|
|
parent::__construct();
|
|
$this->db = $this->load->database("onedev", true);
|
|
}
|
|
function process() {
|
|
$sql = "select tx_branch_status.*, M_BranchName
|
|
from tx_branch_status
|
|
join m_branch on TxBranchStatusM_BranchID = M_BranchID
|
|
where TxBranchStatusIsSent = 'N' and TxBranchStatusRetry < 5
|
|
limit 0,20";
|
|
$qry = $this->db->query($sql);
|
|
$sql_update = "update tx_branch_status set TxBranchStatusIsSent=?,
|
|
TxBranchStatusRetry = TxBranchStatusRetry + 1
|
|
where TxBranchStatusID = ?";
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
print_r($rows); exit;
|
|
foreach($rows as $r) {
|
|
$param = $r["TxBranchStatusJson"];
|
|
$stage = $r["TxBranchStatusStage"];
|
|
$ipAddress = $r["TxBranchStatusM_BranchIP"];
|
|
$branchName = $r["M_BranchName"];
|
|
$txID = $r["TxBranchStatusID"];
|
|
|
|
$url = "http://$ipAddress/one-api/tools/xstatusbranch_v2/update";
|
|
$rst = $this->post($url,$param);
|
|
if ($rst["status"] == "OK" ) {
|
|
$this->xlog("Update status $stage to $branchName @ $ipAddress [OK]");
|
|
$this->db->query($sql_update, array('Y',$txID));
|
|
} else {
|
|
$err_msg = print_r($rst,true);
|
|
$this->xlog("Update status $stage to $branchName @ $ipAddress [ERR] : $err_msg");
|
|
$this->db->query($sql_update, array('N',$txID));
|
|
}
|
|
}
|
|
} else {
|
|
$this->xlog("Err: " . print_r($this->db->error(),true));
|
|
}
|
|
}
|
|
function xlog($message) {
|
|
$dt = date("Y-m-d H:i:s");
|
|
echo "$dt $message\n";
|
|
}
|
|
function status($incomingRefID) {
|
|
$sql = "select * from incoming_ref where incomingRefID = ?";
|
|
$qry = $this->db->query($sql, array($incomingRefID) );
|
|
$rows = array();
|
|
$branchID = 0;
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
if ( count($rows) > 0 ) $branchID = $rows[0]["incomingRefM_BranchID"];
|
|
}
|
|
$ip_address= "";
|
|
if ($branchID > 0 ) {
|
|
$sql = "select *
|
|
from m_branch where M_BranchID = ?";
|
|
$qry = $this->db->query($sql, array($branchID) );
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
if(count($rows) > 0 ) $ip_address = $rows[0]["M_BranchIPAddress"];
|
|
}
|
|
}
|
|
if ($ip_address == "" ) {
|
|
echo "No IP Address from $branchID ";
|
|
exit;
|
|
}
|
|
$sql = "select
|
|
incomingRefT_RefDeliveryOrderID,
|
|
incomingRefDetailT_OrderDetailID,
|
|
incomingRefDetailStatus,
|
|
T_OrderDetailResult,
|
|
T_OrderDetailNat_NormalValueID,
|
|
T_OrderDetailVerification,
|
|
T_OrderDetailValidation
|
|
from incoming_ref_detail
|
|
join incoming_ref on incomingRefID = incomingRefDetailIncomingRefID
|
|
and incomingRefID = ?
|
|
left join t_orderdetail on incomingRefDetailNewT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
and T_OrderDetailIsActive = 'Y' and incomingRefDetailT_TestID = T_OrderDetailT_TestID";
|
|
$qry = $this->db->query($sql, array($incomingRefID));
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
$param = json_encode($rows);
|
|
$url = "http://$ip_address/one-api/tools/xstatusbranch_v2/update";
|
|
$result = $this->post($url,$param);
|
|
}
|
|
}
|
|
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_VERBOSE, true);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
|
'Content-Type: application/json',
|
|
'Content-Length: ' . strlen($data))
|
|
);
|
|
$result = curl_exec($ch);
|
|
return json_decode($result,true);
|
|
}
|
|
}
|