Skip to content
Permalink
Browse files

update Moyaposylka provider

  • Loading branch information...
Anisan committed Nov 14, 2018
1 parent 928f162 commit 993e82c8a700777bb6a046663812b81de1f023e4
@@ -199,11 +199,14 @@ function usual(&$out) {
$status['TRACK_ID'] = $rec['ID'];
$status['PROVIDER'] = -1;
SQLInsert("pt_status", $status);
$this->addTrackToProvider($rec);
$this->exec_script_newstatus($rec,"");
$this->updateStatusInit($rec);
}
$this->redirect("?");
}else if ($this->mode=='del_track') {
$rec = SQLSelectOne("SELECT * FROM pt_track WHERE ID='" . $this->id . "'");
$this->delTrackFromProvider($rec);
SQLExec("DELETE FROM pt_track WHERE ID='" . $this->id . "'");
SQLExec("DELETE FROM pt_status WHERE TRACK_ID='" . $this->id . "'");
$this->redirect("?");
@@ -336,13 +339,16 @@ function archive($rec,$acrhive) {
$status['TRACK_ID'] = $rec['ID'];
$status['PROVIDER'] = -1;
$rec['ARCHIVE']=$acrhive;
$provider = $this->getProvider();
if (!$rec['ARCHIVE'])
{
$status['STATUS_INFO'] = "Unarchived (enable monitoring)";
$provider->unarchiveTrack($rec);
}
else
{
$status['STATUS_INFO'] = "Archived (disable monitoring)";
$provider->archiveTrack($rec);
}
SQLUpdate("pt_track", $rec);
SQLInsert("pt_status", $status);
@@ -395,6 +401,19 @@ function getProvider() {
return $provider;
}
function addTrackToProvider($rec) {
$this->getConfig();
$provider = $this->getProvider();
$provider->addTrack($rec);
}
function delTrackFromProvider($rec) {
$this->getConfig();
$provider = $this->getProvider();
$provider->delTrack($rec);
}
function updateStatusInit($rec) {
$this->getConfig();
$provider = $this->getProvider();
@@ -2,5 +2,9 @@
interface IProvider
{
public function getStatus($track);
public function addTrack($rec);
public function delTrack($rec);
public function archiveTrack($rec);
public function unarchiveTrack($rec);
}
?>
@@ -14,10 +14,11 @@ function __construct($apikey) {
$this->headers[] = "X-Authorization-Token: $apikey";
}
public function query($url, $method)
public function query($url, $method, $params)
{
if ($this->debug)
echo 'Moyaposylka:'.$method." ".$url."<br>";
if (!$params)
$params = array(
'countryCode' => 'RU'
);
@@ -57,15 +58,70 @@ public function getCarrier($track)
return $carriers[0]["code"];
}
public function addTrack($rec)
{
$track = $rec['TRACK'];
$carrier = $this->getCarrier($track);
if ($carrier == "") return;
$url = $this->tracker_url."trackers/".$carrier."/".$track;
$params = array(
'countryCode' => 'RU',
'name' => $rec['NAME'],
'notes' => $rec['DESCRIPTION']
);
$output = $this->query($url,"POST",$params);
if ($this->debug)
echo ($output);
}
public function delTrack($rec)
{
$track = $rec['TRACK'];
$carrier = $this->getCarrier($track);
if ($carrier == "") return;
$url = $this->tracker_url."trackers/".$carrier."/".$track;
$output = $this->query($url,"DELETE");
if ($this->debug)
echo ($output);
}
public function archiveTrack($rec)
{
//PUT https://moyaposylka.ru/api/v1/trackers/{carrier}/{barcode}/archive
$track = $rec['TRACK'];
$carrier = $this->getCarrier($track);
if ($carrier == "") return;
$url = $this->tracker_url."trackers/".$carrier."/".$track."/archive";
$output = $this->query($url,"PUT");
if ($this->debug)
echo ($output);
}
public function unarchiveTrack($rec)
{
//PUT https://moyaposylka.ru/api/v1/trackers/{carrier}/{barcode}/unarchive
$track = $rec['TRACK'];
$carrier = $this->getCarrier($track);
if ($carrier == "") return;
$url = $this->tracker_url."trackers/".$carrier."/".$track."/unarchive";
$output = $this->query($url,"PUT");
if ($this->debug)
echo ($output);
}
public function getStatus($track)
{
$res = array();
$carrier = $this->getCarrier($track);
if ($carrier == "") return $res;
$url = $this->tracker_url."trackers/".$carrier."/".$track."/realtime";
$output = $this->query($url,"POST");
$url = $this->tracker_url."trackers/".$carrier."/".$track;
$output = $this->query($url,"GET");
$data = json_decode($output,true);
//if ($this->check_error($data)) return $res;
@@ -18,6 +18,20 @@ class SeventeenTrack implements IProvider
function __construct() {
}
public function addTrack($rec)
{
}
public function delTrack($rec)
{
}
public function archiveTrack($rec)
{
}
public function unarchiveTrack($rec)
{
}
public function getStatus($track)
{
$val = json_encode(
@@ -13,7 +13,21 @@ function __construct($apikey) {
$this->headers = array();
$this->headers[] = "X-Authorization-Token: $apikey";
}
public function addTrack($rec)
{
}
public function delTrack($rec)
{
}
public function archiveTrack($rec)
{
}
public function unarchiveTrack($rec)
{
}
public function query($url)
{
$ch = curl_init();
@@ -13,6 +13,20 @@ function __construct($login, $password, $lang = "RUS")
$this->client = new SoapClient("https://tracking.russianpost.ru/rtm34?wsdl", array('trace' => 1, 'soap_version' => SOAP_1_2));
}
public function addTrack($rec)
{
}
public function delTrack($rec)
{
}
public function archiveTrack($rec)
{
}
public function unarchiveTrack($rec)
{
}
public function getStatus($track)
{
$res = array();
@@ -13,7 +13,20 @@ function __construct($apikey, $domain) {
$this->apikey = $apikey;
$this->domain = $domain;
}
public function addTrack($rec)
{
}
public function delTrack($rec)
{
}
public function archiveTrack($rec)
{
}
public function unarchiveTrack($rec)
{
}
public function getStatus($track)
{
$res = array();

0 comments on commit 993e82c

Please sign in to comment.
You can’t perform that action at this time.