function get_surface_trackno($ebayid, $packingstatus)
{
    global $dbConn;
    global $transportData;
    //运输方式
    //ebay_account 为新系统的 accountId;
    //ebay_userid  为新系统的 platformUsername
    //$sql = "SELECT ebay_countryname,ebay_state,ebay_city,ebay_postcode,ebay_carrier,ebay_account,ebay_userid,ebay_usermail FROM ebay_order WHERE ebay_id='{$ebayid}'";
    //$sql = "SELECT ebay_countryname,ebay_state,ebay_city,ebay_postcode,ebay_carrier,ebay_account,ebay_userid,ebay_usermail FROM ebay_order WHERE ebay_id='{$ebayid}'";	//查询订单的地址信息
    $sql = 'SELECT sou.`countryName`,sou.`state`,sou.`city`,sou.`zipCode`,so.`transportId`,so.`accountId`,sou.`platformUsername`,sou.`email` 
			FROM `om_shipped_order` AS so
			LEFT JOIN `om_account` AS ea ON so.`accountId` = ea.`id`
			LEFT JOIN `om_shipped_order_userInfo` AS sou ON so.`id` = sou.`omOrderId`
			WHERE so.id = \'' . $ebayid . '\'';
    //获取订单的运输方式等信息
    $query = $dbConn->query($sql);
    $orderinfo = $dbConn->fetch_one($query);
    $uesrid = $orderinfo['platformUsername'];
    $uesremail = $orderinfo['email'];
    $ebay_carrier = str_replace('平邮', '挂号', $transportData[$orderinfo['transportId']]);
    $starttime = time() - 3 * 24 * 3600;
    $endtime = time();
    /*$sql = "SELECT ebay_account,ebay_tracknumber,ebay_carrier,ebay_userid,ebay_usermail FROM ebay_order WHERE ebay_combine!='1' AND scantime>'{$starttime}' AND scantime<'{$endtime}' AND ebay_carrier='$ebay_carrier' AND ebay_postcode='{$orderinfo['ebay_postcode']}' ORDER BY scantime DESC LIMIT 10";*/
    $sql = 'SELECT so.`id`,so.`recordNumber`,so.`accountId`,so.`ShippedTime`,so.`transportId`,so.`marketTime`,so.`orderStatus`,ea.`account`,
				sou.`countrySn`,sou.`countryName`,sou.`city`,sou.`email`,sou.`platformUsername`,sou.`zipCode`,sow.`weighTime`,sow.`weighStaffId`,ot.`tracknumber` 
			FROM `om_shipped_order` AS so
			LEFT JOIN `om_account` AS ea ON so.`accountId` = ea.`id`
			LEFT JOIN `om_shipped_order_userInfo` AS sou ON so.`id` = sou.`omOrderId` 
			LEFT JOIN `om_shipped_order_warehouse` AS sow ON so.`id` = sow.`omOrderId` 
			LEFT JOIN `om_order_tracknumber` AS ot ON so.`id` = ot.`omOrderId` 
			WHERE so.combineOrder != 1 AND sow.`weighTime` >= ' . $starttime . ' AND sow.`weighTime` <= ' . $endtime . '
			AND so.`transportId` = \'' . $orderinfo['transportId'] . '\'
			AND sou.`zipCode` = \'' . $orderinfo['zipCode'] . '\' ORDER BY sow.`weighTime` DESC LIMIT 10';
    //获取订单的运输方式等信息
    //echo $sql."\n\n";
    $query = $dbConn->query($sql);
    $orders = $dbConn->fetch_array_all($query);
    //print_r($orders);exit;
    if (empty($orders)) {
        $_orderinfo = $orderinfo;
        unset($_orderinfo['zipCode'], $_orderinfo['transportId'], $_orderinfo['platformUsername'], $_orderinfo['email']);
        //$_orderinfo['accountId']
        //ebay_countryname,ebay_state,ebay_city
        $wheres = array();
        while (!empty($_orderinfo)) {
            $wheres[] = $_orderinfo;
            array_pop($_orderinfo);
        }
        //print_r($wheres);exit;
        foreach ($wheres as $where) {
            $where = array2strarray($where);
            $sql_where = array();
            foreach ($where as $_k => $_v) {
                if (empty($_k)) {
                    continue;
                }
                $_v = trim($_v);
                $sql_where[] = "{$_k}={$_v}";
            }
            //$sql = "SELECT ebay_account,ebay_tracknumber,ebay_carrier,ebay_userid,ebay_usermail FROM ebay_order WHERE ebay_combine!='1' AND scantime>'{$starttime}' AND scantime<'{$endtime}' AND ebay_carrier='$ebay_carrier' AND ".implode(' AND ', $sql_where)." ORDER BY scantime DESC LIMIT 10";
            $sql = 'SELECT so.`id`,so.`recordNumber`,so.`accountId`,so.`ShippedTime`,so.`transportId`,so.`marketTime`,so.`orderStatus`,ea.`account`,
						sou.`countrySn`,sou.`countryName`,sou.`city`,sou.`email`,sou.`platformUsername`,sou.`zipCode`,sow.`weighTime`,sow.`weighStaffId`,ot.`tracknumber`
					FROM `om_shipped_order` AS so 
					LEFT JOIN `om_account` AS ea ON so.`accountId` = ea.`id` 
					LEFT JOIN `om_shipped_order_userInfo` AS sou ON so.`id` = sou.`omOrderId` 
					LEFT JOIN `om_shipped_order_warehouse` AS sow ON so.`id` = sow.`omOrderId` 
					LEFT JOIN `om_order_tracknumber` AS ot ON so.`id` = ot.`omOrderId` 
					WHERE so.combineOrder != 1 AND sow.`weighTime` >= ' . $starttime . ' AND sow.`weighTime` <= ' . $endtime . '  
					AND so.`transportId` = \'' . $orderinfo['transportId'] . '\' AND ' . implode(' AND ', $sql_where) . ' ORDER BY sow.`weighTime` DESC LIMIT 10	';
            //echo "$sql\n\n";exit;
            $sql = $dbConn->query($sql);
            $orders = $dbConn->fetch_array_all($sql);
            if (!empty($orders)) {
                break;
            }
        }
    }
    foreach ($orders as $order) {
        if ($uesrid != $order['id'] && $uesremail != $order['email'] && !check_is_useful($order['tracknumber'], $orderinfo['accountId'], $orderinfo['platformUsername'], $orderinfo['email'])) {
            $surfacedata = array();
            $surfacedata['order_id'] = $ebayid;
            $surfacedata['account'] = $order['accountId'];
            //被使用的账号
            $surfacedata['use_account'] = $orderinfo['accountId'];
            //当前上传跟踪号的账号
            $surfacedata['shippingstatus'] = 1;
            $surfacedata['packingstatus'] = $packingstatus;
            $surfacedata['trackno'] = $order['tracknumber'];
            $surfacedata['carrier'] = $transportData[$order['transportId']];
            //$order['ebay_carrier'];
            $surfacedata['saleuser'] = $orderinfo['platformUsername'];
            $surfacedata['saleemail'] = $orderinfo['email'];
            backup_surfaceid($surfacedata);
            unset($order['ebay_userid'], $order['email']);
            return $order;
        }
    }
    $trackno = 'WD' . str_pad($ebayid, 9, "0", STR_PAD_LEFT) . "CN";
    if (!check_is_useful($trackno, $orderinfo['accountId'], $orderinfo['platformUsername'], $orderinfo['email'])) {
        $surfacedata = array();
        $surfacedata['order_id'] = $ebayid;
        $surfacedata['account'] = 'wedo';
        //被使用的账号
        $surfacedata['use_account'] = $orderinfo['accountId'];
        //当前上传跟踪号的账号
        $surfacedata['shippingstatus'] = 1;
        $surfacedata['packingstatus'] = $packingstatus;
        $surfacedata['trackno'] = $trackno;
        $surfacedata['carrier'] = 'wedo';
        $surfacedata['saleuser'] = $orderinfo['platformUsername'];
        $surfacedata['saleemail'] = $orderinfo['email'];
        backup_surfaceid($surfacedata);
    }
    //print_r(array('ebay_account'=>'wedo', 'ebay_tracknumber'=>$trackno, 'ebay_carrier'=>'61'));exit;
    return array('ebay_account' => 'wedo', 'ebay_tracknumber' => $trackno, 'ebay_carrier' => '61');
    //'ebay_carrier'=>'wedo'
}
function get_surface_trackno($ebayid, $packingstatus)
{
    global $dbcon;
    $sql = "SELECT ebay_countryname,ebay_state,ebay_city,ebay_postcode,ebay_carrier,ebay_account,ebay_userid,ebay_usermail FROM ebay_order WHERE ebay_id='{$ebayid}'";
    $sql = $dbcon->query($sql);
    $orderinfo = $dbcon->fetch_one($sql);
    $ebay_carrier = str_replace('平邮', '挂号', $orderinfo['ebay_carrier']);
    $starttime = time() - 3 * 24 * 3600;
    $endtime = time();
    $sql = "SELECT ebay_account,ebay_tracknumber,ebay_carrier FROM ebay_order WHERE ebay_combine!='1' AND ebay_carrier='{$ebay_carrier}' AND scantime BETWEEN '{$starttime}' AND '{$endtime}' AND ebay_postcode='{$orderinfo['ebay_postcode']}' AND ebay_countryname='{$orderinfo['ebay_countryname']}' ORDER BY ebay_id DESC";
    //$sql = "SELECT * FROM ebay_order as eo WHERE eo.ebay_combine!='1' AND eo.scantime > '1390320000' AND eo.scantime < '1390492799' AND eo.ebay_carrier='中国邮政挂号' AND eo.ebay_countryname = 'Brazil' AND eo.ebay_state = 'Parana' AND eo.ebay_city = 'Nova Esperanca'";
    $sql = "SELECT ebay_account,ebay_tracknumber,ebay_carrier FROM ebay_order WHERE ebay_combine!='1' AND scantime>'{$starttime}' AND scantime<'{$endtime}' AND ebay_carrier='{$ebay_carrier}' AND ebay_postcode='{$orderinfo['ebay_postcode']}' ORDER BY scantime DESC LIMIT 10";
    echo "{$sql}\n\n";
    $sql = $dbcon->query($sql);
    $orders = $dbcon->getResultArray($sql);
    if (empty($orders)) {
        $_orderinfo = $orderinfo;
        unset($_orderinfo['ebay_postcode'], $_orderinfo['ebay_carrier'], $_orderinfo['ebay_account'], $_orderinfo['ebay_userid'], $_orderinfo['ebay_usermail']);
        $wheres = array();
        /*while (!empty($_orderinfo)){
        			$wheres[] = $_orderinfo;
        			array_pop($_orderinfo);
        		}*/
        $wheres[] = $_orderinfo;
        foreach ($wheres as $where) {
            $where = array2strarray($where);
            $sql_where = array();
            foreach ($where as $_k => $_v) {
                if (empty($_k)) {
                    continue;
                }
                $_v = trim($_v);
                $sql_where[] = "{$_k}={$_v}";
            }
            $sql = "SELECT ebay_account,ebay_tracknumber,ebay_carrier FROM ebay_order WHERE ebay_combine!='1' AND scantime>'{$starttime}' AND scantime<'{$endtime}' AND ebay_carrier='{$ebay_carrier}' AND " . implode(' AND ', $sql_where) . " ORDER BY scantime DESC LIMIT 10";
            echo "{$sql}\n\n";
            $sql = $dbcon->query($sql);
            $orders = $dbcon->getResultArray($sql);
            if (!empty($orders)) {
                break;
            }
        }
    }
    foreach ($orders as $order) {
        if (!check_is_useful($order['ebay_tracknumber'], $orderinfo['ebay_account'], $orderinfo['ebay_userid'], $orderinfo['ebay_usermail'])) {
            $surfacedata = array();
            $surfacedata['order_id'] = $ebayid;
            $surfacedata['account'] = $order['ebay_account'];
            $surfacedata['use_account'] = $orderinfo['ebay_account'];
            $surfacedata['shippingstatus'] = 1;
            $surfacedata['packingstatus'] = $packingstatus;
            $surfacedata['trackno'] = $order['ebay_tracknumber'];
            $surfacedata['carrier'] = $order['ebay_carrier'];
            $surfacedata['saleuser'] = $orderinfo['ebay_userid'];
            $surfacedata['saleemail'] = $orderinfo['ebay_usermail'];
            backup_surfaceid($surfacedata);
            return $order;
        }
    }
    $trackno = 'WD' . str_pad($ebayid, 9, "0", STR_PAD_LEFT) . "CN";
    if (!check_is_useful($trackno, $orderinfo['ebay_account'], $orderinfo['ebay_userid'], $orderinfo['ebay_usermail'])) {
        $surfacedata = array();
        $surfacedata['order_id'] = $ebayid;
        $surfacedata['account'] = 'wedo';
        $surfacedata['use_account'] = $orderinfo['ebay_account'];
        $surfacedata['shippingstatus'] = 1;
        $surfacedata['packingstatus'] = $packingstatus;
        $surfacedata['trackno'] = $trackno;
        $surfacedata['carrier'] = 'wedo';
        $surfacedata['saleuser'] = $orderinfo['ebay_userid'];
        $surfacedata['saleemail'] = $orderinfo['ebay_usermail'];
        backup_surfaceid($surfacedata);
    }
    return array('ebay_account' => 'wedo', 'ebay_tracknumber' => $trackno, 'ebay_carrier' => 'wedo');
}