Esempio n. 1
0
 public static function info($code)
 {
     $info = PostTracker::request('http://russianpostcalc.ru/api_v1.php', array('method' => 'parcel', 'rpo' => $code));
     $data = array();
     if ($info['status0']) {
         $log = json_decode($info['log_json'], true);
         foreach ($log as $l) {
             $data[] = array('date' => $l['date'], 'city' => $l['place'], 'index' => $l['index'], 'pro' => $l['status1'], 'state' => $l['status0'], 'status' => sprintf('%s - %s (%s)', $l['status1'], $l['status0'], $l['index']));
         }
     }
     return $data;
 }
Esempio n. 2
0
        PostTracker::check($t['track_code']);
        $core->db->query("UPDATE " . DB_ORDER . " SET track_on = 1, track_check = '{$ct}' WHERE order_id = '" . $t['order_id'] . "' LIMIT 1");
    }
    unset($t, $totrack, $pt);
}
// Processing track codes for now
$mt = $thetime - 14400;
$spsrs = array();
$sql = "SELECT order_id, comp_id, order_status, track_code, track_status, order_delivery FROM " . DB_ORDER . " WHERE order_status IN ( 8, 9 ) AND track_on = 1 AND track_check < '{$mt}' LIMIT 1";
while ($t = $core->db->row($sql)) {
    // Different delivery types
    $status = $date = '';
    switch ($t['order_delivery']) {
        // Post Tracker for Russian Post
        case 1:
            if ($info = PostTracker::info($t['track_code'])) {
                $todo = true;
                foreach ($info as $i) {
                    if ($i['pro'] == 'Возврат') {
                        order_edit($core, $t['order_id'], array('status' => 11));
                        $todo = false;
                        break;
                    }
                }
                $now = end($info);
                $status = $status = sprintf('%s - %s (%s, %s)', $now['pro'], $now['state'], $now['index'], $now['city']);
                $date = $now['date'];
                if ($todo && $status) {
                    if ($now['pro'] == 'Вручение') {
                        order_edit($core, $t['order_id'], array('status' => 10));
                    } elseif ($t['order_status'] == 8) {
Esempio n. 3
0
function order_action($core)
{
    $action = $core->get['a'] ? $core->get['a'] : null;
    $id = $core->post['id'] ? (int) $core->post['id'] : ($core->get['id'] ? (int) $core->get['id'] : 0);
    switch ($action) {
        case 'order-notify':
            $prev = (int) $core->get['prev'];
            if ($core->user->comp && !$core->user->call) {
                echo json_encode(array('previous' => time(), 'ords' => $core->db->field("SELECT COUNT(*) FROM " . DB_ORDER . " WHERE order_status = 1 AND order_time >= '{$prev}' AND comp_id = '" . $core->user->comp . "'")));
            } else {
                echo json_encode(array('previous' => time(), 'ords' => $core->db->field("SELECT COUNT(*) FROM " . DB_ORDER . " WHERE order_status = 1 AND order_time >= '{$prev}'")));
            }
            $core->_die();
        case 'order-spsr':
            $comp = $core->user->comp ? $core->wmsale->get('comp', $core->user->comp) : false;
            $to = $core->text->line($core->post['to']);
            $area = $core->text->line($core->post['area']);
            $price = $core->text->line($core->post['price']);
            require_once PATH . 'lib/spsr.php';
            if ($comp['comp_spsr_login'] && $comp['comp_spsr_pass']) {
                $spsr = new SPSRtrack($comp['comp_spsr_login'], $comp['comp_spsr_pass'], $comp['comp_spsr'], SPSR_COOKIE);
            } else {
                $spsr = new SPSRtrack(SPSR_LOGIN, SPSR_PASS, SPSR_ID, SPSR_COOKIE);
            }
            $info = $spsr->price($comp['comp_spsr_from'] ? $comp['comp_spsr_from'] : SPSR_CITY, $to, $area, $price);
            unset($spsr);
            echo json_encode($info);
            $core->_die();
        case 'order-rupost':
            $to = (int) $core->get['to'];
            $price = (int) $core->get['price'];
            $req = $reqmd5 = array('apikey' => RUP_API, 'method' => 'calc', 'from_index' => RUP_FROM, 'to_index' => $to, 'weight' => RUP_WG, 'ob_cennost_rub' => $price);
            $reqmd5[] = RUP_KEY;
            $req['hash'] = md5(implode('|', $reqmd5));
            $info = json_decode(curl('http://russianpostcalc.ru/api_v1.php', $req), true);
            if ($info['calc']) {
                $d = 0;
                $c = 0;
                foreach ($info['calc'] as $i) {
                    if ($i['type'] == 'rp_1class') {
                        $d = $i['days'];
                        $c = $i['cost'];
                        break;
                    }
                }
                $res = $d ? array('ok' => 1, 'dd' => $d, 'cost' => $c) : array('error' => 'nodelivery');
            } else {
                $res = array('error' => 'bad');
            }
            echo json_encode($res);
            $core->_die();
        case 'order-phone':
            $phone = preg_replace('#([^0-9]+)#', '', $core->get['phone']);
            $ptc = substr($phone, 1, 6);
            $data = $core->db->row("SELECT * FROM " . DB_PDB . " WHERE `phone` = '{$ptc}' LIMIT 1");
            if ($data) {
                $place = $data['region'];
                if ($data['city']) {
                    $place .= ', ' . $data['city'];
                }
                printf("<b>База</b>: %s (%s)", $data['operator'], $place);
            }
            $curl = curl_init('http://mnp.tele2.ru/gateway.php?' . substr($phone, 1));
            curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0');
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
            curl_setopt($curl, CURLOPT_REFERER, 'http://mnp.tele2.ru/whois.html');
            curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/json, text/javascript, */*; q=0.01', 'Accept-Language: ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3', 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8', 'X-Requested-With: XMLHttpRequest'));
            $tele2 = curl_exec($curl);
            curl_close($curl);
            if ($tele2) {
                $tele2info = json_decode($tele2, true);
                if (is_array($tele2info['response'])) {
                    if ($data) {
                        echo '<br />';
                    }
                    printf("<b>Tele2</b>: %s (%s)", $tele2info['response']['mnc']['value'], $tele2info['response']['geocode']['value']);
                }
            }
            $core->_die();
        case 'order-move':
            $comp = (int) $core->post['comp'];
            if (($core->user->level || $core->user->call) && $comp && order_edit($core, $id, array('comp' => $comp))) {
                msgo($core, 'move');
            } else {
                msgo($core, 'nomove');
            }
        case 'order-pickup':
            if ($oid = order_take($core, $id)) {
                $core->go($core->url('i', 'order', $oid));
            } else {
                $core->go($core->url('m', 'order', 'pickup'));
            }
        case 'order-call':
            $status = $core->text->link($core->post['status']);
            if ($status == 'del' && !$core->user->level) {
                msgo($core, 'call');
            }
            if ($status == 'shave' && !($core->user->level || $core->user->shave)) {
                msgo($core, 'call');
            }
            if ($cs = order_accept($status)) {
                order_edit($core, $id, $cs);
            }
            msgo($core, 'call');
        case 'order-send':
            $code = $core->text->line($core->post['code']);
            if (order_edit($core, $id, array('status' => 8, 'track' => $code))) {
                msgo($core, 'send');
            } else {
                msgo($core, 'nocode');
            }
        case 'order-trackcall':
            $status = (int) $core->post['status'];
            $core->db->query("UPDATE " . DB_ORDER . " SET track_calls = track_calls + 1, track_result = '{$status}', track_call = '" . time() . "' WHERE order_id = '{$id}' LIMIT 1");
            msgo($core, 'called');
        case 'order-esend':
            if (order_edit($core, $id, array('status' => 8))) {
                msgo($core, 'send');
            } else {
                msgo($core, 'nocode');
            }
        case 'order-snew':
            $core->db->query("UPDATE " . DB_ORDER . " SET order_courier = 0 WHERE order_id = '{$id}' LIMIT 1");
            msgo($core, 'save');
        case 'order-sold':
            $core->db->query("UPDATE " . DB_ORDER . " SET order_courier = 1 WHERE order_id = '{$id}' LIMIT 1");
            msgo($core, 'save');
        case 'order-courier':
            $from = $core->post['from'] ? form2date($core->post['from']) : false;
            $to = $core->post['to'] ? form2date($core->post['to']) : false;
            $onew = $core->post['new'] ? 1 : 0;
            $mark = $core->post['mark'] ? 1 : 0;
            $done = $core->post['done'] ? 1 : 0;
            $comp = $core->wmsale->get('comp', $core->user->comp);
            require_once PATH_LIB . 'addr.php';
            require_once PATH_LIB . 'docs.php';
            docs_spsr_make($core, $comp, $from, $to, $onew, $mark, $done);
            $core->_die();
        case 'order-packed':
            if (order_edit($core, $id, array('status' => 7))) {
                msgo($core, 'pack');
            } else {
                msgo($core, 'error');
            }
        case 'order-arrive':
            if (order_edit($core, $id, array('status' => 9))) {
                msgo($core, 'arrive');
            } else {
                msgo($core, 'error');
            }
        case 'order-done':
            if (order_edit($core, $id, array('status' => 10))) {
                msgo($core, 'done');
            } else {
                msgo($core, 'error');
            }
        case 'order-return':
            if (order_edit($core, $id, array('status' => 11))) {
                msgo($core, 'done');
            } else {
                msgo($core, 'error');
            }
        case 'order-uncheck':
            if (order_edit($core, $id, array('check' => 0))) {
                msgo($core, 'done');
            } else {
                msgo($core, 'error');
            }
        case 'order-reset':
            if (order_edit($core, $id, array('status' => 12))) {
                msgo($core, 'done');
            } else {
                msgo($core, 'error');
            }
        case 'order-docs':
            $ord = $core->db->row("SELECT * FROM " . DB_ORDER . " WHERE order_id = '{$id}' LIMIT 1");
            if ($core->user->level || $core->user->call || $core->user->id == $ord['user_id'] || $core->user->comp == $ord['comp_id']) {
                $comp = $core->wmsale->get('comp', $ord['comp_id']);
                require_once PATH_LIB . 'docs.php';
                docs_xls_make($ord, $comp);
                $core->_die();
            } else {
                $core->go($core->url('mm', '', 'access'));
            }
        case 'order-edit':
            $changes = array();
            $order = $core->db->row("SELECT * FROM " . DB_ORDER . " WHERE order_id = '{$id}' LIMIT 1");
            $status = $order['order_status'];
            // Basic order info
            if (isset($core->post['name'])) {
                $changes['name'] = $core->text->line($core->post['name']);
            }
            if (isset($core->post['addr'])) {
                $changes['addr'] = $core->text->line($core->post['addr']);
            }
            if (isset($core->post['area'])) {
                $changes['area'] = $core->text->line($core->post['area']);
            }
            if (isset($core->post['city'])) {
                $changes['city'] = $core->text->line($core->post['city']);
            }
            if (isset($core->post['street'])) {
                $changes['street'] = $core->text->line($core->post['street']);
            }
            if (isset($core->post['phone'])) {
                $changes['phone'] = preg_replace('#([^0-9]+)#', '', $core->post['phone']);
            }
            if (isset($core->post['index'])) {
                $changes['index'] = (int) $core->post['index'];
            }
            if (isset($core->post['track'])) {
                $changes['track'] = $core->text->line($core->post['track']);
            }
            // Item delivery and counts
            if (isset($core->post['delivery'])) {
                $changes['delivery'] = (int) $core->post['delivery'];
            }
            if (isset($core->post['discount'])) {
                $changes['discount'] = (int) $core->post['discount'];
            }
            if (isset($core->post['more'])) {
                $changes['more'] = (int) $core->post['more'];
            }
            if (isset($core->post['counts'])) {
                $changes['counts'] = array();
                foreach ($core->post['counts'] as $i => $c) {
                    if ($c = (int) $c) {
                        $changes['counts'][(int) $i] = $c;
                    }
                }
            }
            if (isset($core->post['comment'])) {
                $changes['comment'] = $core->text->line($core->post['comment']);
            }
            if (isset($core->post['meta']) && is_array($core->post['meta'])) {
                $changes['meta'] = array();
                foreach ($core->post['meta'] as $k => $v) {
                    $changes['meta'][$k] = stripslashes($v);
                }
            }
            // Check for status
            $act = $core->text->link($core->post['act']);
            switch ($status) {
                case 2:
                case 3:
                case 4:
                    // Order accept progress
                    if ($status == 'del' && !$core->user->level) {
                        break;
                    }
                    if ($status == 'shave' && !($core->user->level || $core->user->shave)) {
                        break;
                    }
                    if ($cs = order_accept($act)) {
                        $changes += $cs;
                    }
                    break;
                case 6:
                    // Packing
                    if ($act == 'done') {
                        $changes['status'] = 7;
                    }
                    break;
                case 7:
                    // Sending
                    if ($act == 'done') {
                        $changes['status'] = 8;
                    }
                    if ($act == 'back') {
                        $changes['status'] = 6;
                    }
                    break;
                case 8:
                case 9:
                    // Delivery and payment
                    if ($act == 'done') {
                        $changes['status'] = $status + 1;
                    }
                    if ($act == 'return') {
                        $changes['status'] = 11;
                    }
                    if ($act == 'back') {
                        $changes['status'] = $status - 1;
                    }
                    break;
            }
            // Checks and controls of orders
            if ($core->post['check']) {
                $changes['check'] = 1;
            }
            if ($core->post['uncheck']) {
                $changes['check'] = 0;
            }
            // Saving order data
            order_edit($core, $id, $changes, $order);
            // Processing bans
            if ($core->post['banip'] || $core->post['banphone']) {
                require_once PATH . 'lib/ban.php';
                if ($core->post['banip']) {
                    ban_ip($core, $order['order_ip'], true);
                }
                if ($core->post['banphone']) {
                    ban_phone($core, $order['order_phone']);
                }
            }
            // Processing order cancels
            if ($core->post['delip'] || $core->post['delphone']) {
                $sql = "SELECT order_id FROM " . DB_ORDER . " WHERE order_id != '" . $order['order_id'] . "' AND order_status < 5 AND comp_id = '" . $order['comp_id'] . "'";
                if ($core->post['delip']) {
                    $sql .= " AND order_ip = '" . $order['order_ip'] . "'";
                }
                if ($core->post['delphone']) {
                    $sql .= " AND order_phone = '" . $order['order_phone'] . "'";
                }
                $ids = $core->db->col($sql);
                foreach ($ids as $i) {
                    order_edit($core, $i, array('status' => 5, 'reason' => 7));
                }
            }
            // Order save competed, returning back
            if ($core->post['next']) {
                $core->go($core->url('a', 'order-pickup', ''));
            } else {
                $core->go($core->post['r'] ? $core->post['r'] : $core->url('mm', 'order', 'save'));
            }
        case 'track-info':
            $order = $core->db->row("SELECT * FROM " . DB_ORDER . " WHERE order_id = '{$id}' LIMIT 1");
            if ($order['track_code']) {
                $core->tpl->load('track', 'track');
                $core->tpl->vars('track', array('id' => $id));
                switch ($order['order_delivery']) {
                    case 1:
                        require_once PATH . 'lib/track.php';
                        $info = PostTracker::info($order['track_code']);
                        break;
                    case 2:
                        require_once PATH . 'lib/spsr.php';
                        $info = SPSRtrack::info($order['track_code']);
                        break;
                }
                foreach ($info as $i) {
                    $core->tpl->block('track', 'place', array('date' => $i['date'] . ($i['time'] ? ' ' . $i['time'] : ''), 'status' => $i['status'], 'city' => $i['city']));
                }
                $core->tpl->output('track');
            }
            $core->_die();
    }
    return false;
}