Batch 6a: application controllers base
This commit is contained in:
104
application/controllers/tools/Outgoingref.php
Normal file
104
application/controllers/tools/Outgoingref.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
class OutgoingRef 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();
|
||||
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/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/update";
|
||||
$result = $this->post($url,$param);
|
||||
print_r($result);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user