예제 #1
0
 /**
  * TrackWarnExportModel::exportXls()
  * 导出xls文件
  * @param array $res 结果值
  * @return string 文件路径
  */
 private function exportXls($tharr, $res)
 {
     $data = array();
     $tdarr = array();
     $dates = array();
     $pos = array();
     $filename = 'track_number_info_' . date('Y-m-d', time()) . '_' . $_SESSION[C('USER_AUTH_SYS_ID')];
     $statusList = C('TRACK_STATUS_DETAIL');
     $fileurl = WEB_URL . "temp/" . $filename . ".xls";
     $filepath = WEB_PATH . "html/temp/" . $filename . ".xls";
     array_push($data, $tharr);
     foreach ($res as $v) {
         $nodeList = TransOpenApiModel::getTrackNodeList($v['carrierId'], $v['channelId']);
         $detail = TransOpenApiModel::getTrackInfoLocal($v['trackNumber'], $v['carrierId']);
         $i = 0;
         foreach ($nodeList as $n) {
             foreach ($detail as $val) {
                 $keys = explode(" ", $n['nodeKey']);
                 foreach ($keys as $key) {
                     if (strpos($val['event'], $key) !== false && !in_array($val['event'], array('未妥投'))) {
                         $dates[$i] = !empty($val['trackTime']) ? date('Y-m-d H:i:s', $val['trackTime']) : '';
                         $pos[$i] = $val['postion'];
                         break;
                     }
                 }
             }
             $i++;
         }
         $tdarr = array($v['carrierNameCn'], $v['channelName'], $v['orderSn'], $v['recordId'], $v['trackNumber'], $v['weight'], $v['cost'], date('Y-m-d H:i:s', $v['scanTime']), $v['toCountry'], $v['lastEvent'], $v['lastPostion'], date('Y-m-d H:i:s', $v['lastTime']), $statusList[$v['status']], $dates[0], $pos[0], $dates[1], $pos[1], $dates[2], $pos[2], $v['platAccount'], $v['platForm']);
         array_push($data, $tdarr);
     }
     require_once WEB_PATH . "lib/php-export-data.class.php";
     $excel = new ExportDataExcel('file');
     $excel->filename = $filepath;
     $excel->initialize();
     foreach ($data as $row) {
         $excel->addRow($row);
     }
     $excel->finalize();
     unset($data);
     if (file_exists($filepath)) {
         return $fileurl;
     } else {
         return "fail";
     }
 }
//页码
$pagenum = isset($argv[2]) ? abs(intval($argv[2])) : 2000;
//每页多少条
$carrierId = !empty($argv[3]) ? abs(intval($argv[3])) : "";
//运输方式ID
$where = isset($argv[4]) ? $argv[4] : "";
//跟踪号状态
$numberList = TransOpenApiModel::getTrackNumberList($page, $pagenum, $carrierId, $where);
//获取符合条件的跟踪号列表
$total = count($numberList);
$chidArr = array('9' => 23, '8' => 43, '46' => 65, '47' => 66, '53' => 72);
echo $total . "条数据抓取开始,时间" . date('Y-m-d H:i:s', time()) . "\n\n";
foreach ($numberList as $v) {
    $data = array();
    $timestr = date('Y-m-d h:i:s', time());
    $detailInfo = TransOpenApiModel::getTrackInfoLocal($v['trackNumber'], $v['carrierId']);
    echo $res, "======", $v['trackNumber'], "===[{$timestr}]\n";
    //print_r($detailInfo);
    $nodeEff = "";
    $nodePlaceEff = "";
    if (is_array($detailInfo)) {
        $detailCount = count($detailInfo);
        if ($detailCount > 0) {
            $detailInfo['trackingEventList'] = $detailInfo;
            $detailInfo['numberInfo'] = $v;
            foreach ($detailInfo['trackingEventList'] as $key => $val) {
                unset($detailInfo['trackingEventList'][$key]);
                if ($key == 0) {
                    //得到跟踪号渠道信息
                    $channelId = TransOpenApiModel::getCarrierChannelByPostName($detailInfo['numberInfo']['carrierId'], $val['postion']);
                    if (!empty($channelId)) {