码迷,mamicode.com
首页 > Web开发 > 详细

phpexce 表格上传与下载

时间:2018-12-18 20:56:50      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:domain   nal   ted   imm   str   term   ase   backend   efi   

<?php
//每天更新商家
include_once(dirname(dirname(__FILE__))."/config/const_cron.php");
require_once(dirname(dirname(__FILE__))."/phpexcel/PHPExcel.php");
echo "Begin ---".date(‘Y-m-d H:i:s‘)."\n\n";

$objMysql = new Mysql($databaseInfo["INFO_CA_DB_NAME"], $databaseInfo["INFO_CA_DB_HOST"], $databaseInfo["INFO_CA_DB_USER"], $databaseInfo["INFO_CA_DB_PASS"]);
$objMysqlBackend = new Mysql($databaseInfo["INFO_BACKEND_DB_NAME"], $databaseInfo["INFO_BACKEND_DB_HOST"], $databaseInfo["INFO_BACKEND_DB_USER"], $databaseInfo["INFO_BACKEND_DB_PASS"]);
$objMerchant = new NormalMerchant($objMysql);

$url = dirname(__FILE__);
$fileMerchant = $url."/".MERCHANT_TXT.".xlsx";
$fileCate = $url."/".CATEGORY_TXT.".xlsx";

$PHPReader = new PHPExcel_Reader_Excel2007();
if(!$PHPReader->canRead($fileMerchant)){
$PHPReader = new PHPExcel_Reader_Excel5();
if(!$PHPReader->canRead($fileMerchant)){
echo $fileMerchant."\033[01;40;32m read xlsx fault :".date("Y-m-d H:i:s")."\033[0m",PHP_EOL;
exit;
}
}

if(defined("IS_CATEGORY") && IS_CATEGORY ==‘1‘){
if(!$PHPReader->canRead($fileCate)){
$PHPReader = new PHPExcel_Reader_Excel5();
if(!$PHPReader->canRead($fileCate)){
echo $fileCate."\033[01;40;32m read xlsx fault :".date("Y-m-d H:i:s")."\033[0m",PHP_EOL;
exit;
}
}
$PHPExcelC = $PHPReader->load($fileCate);
$currentSheetC = $PHPExcelC->getSheet(0);
$currentRowC = 2;
$totleRowC = $currentSheetC->getHighestRow();
$cateArr = [];
for($currentRowC;$currentRowC<=$totleRowC;$currentRowC++){
$MerId = intval(trim($currentSheetC->getCell(‘A‘.$currentRowC)->getValue()));
$CatId = intval(trim($currentSheetC->getCell(‘B‘.$currentRowC)->getValue()));
$Type = trim($currentSheetC->getCell(‘C‘.$currentRowC)->getValue());
$catprimary = trim($currentSheetC->getCell(‘D‘.$currentRowC)->getValue());
$cateArr[$currentRowC][‘MerId‘] = $MerId;
$cateArr[$currentRowC][‘CatId‘] = $CatId;
$cateArr[$currentRowC][‘Type‘] = $Type;
$cateArr[$currentRowC][‘catprimary‘] = $catprimary;
}
}

$PHPExcelM = $PHPReader->load($fileMerchant);
$currentSheetM = $PHPExcelM->getSheet(0);
$currentRowM = 1;
$totleRowM = $currentSheetM->getHighestRow();
//print_r($totleRowM);
$excute_num = 0;

$sta = START_TIME;
$num = NUM_EVERYDAY;
$timmm = date(‘Y-m-d‘);
$exx = (strtotime($timmm) - strtotime($sta))/(24*3600) ;
if((int)($num) >0){
$sss = $exx * $num ;
$eee = $sss + ($num-1) ;
}else{
$sss = $exx * 300 ;
$eee = $sss + 299 ;
}
for($currentRowM;$currentRowM<=$totleRowM;$currentRowM++){

if($currentRowM < $sss ){
continue;
}
if($currentRowM >$eee){
break;
}

$ID = intval(trim($currentSheetM->getCell(‘A‘.$currentRowM)->getValue()));
$Name = trim($currentSheetM->getCell(‘B‘.$currentRowM)->getValue());
$domain = trim($currentSheetM->getCell(‘C‘.$currentRowM)->getValue());
$UrlName = trim($currentSheetM->getCell(‘D‘.$currentRowM)->getValue());
$UrlName = $UrlName.strtolower(trim($domain))."/";
$OriginalUrl = trim($currentSheetM->getCell(‘E‘.$currentRowM)->getValue());
$rank = trim($currentSheetM->getCell(‘F‘.$currentRowM)->getValue());
$mer_country = trim($currentSheetM->getCell(‘G‘.$currentRowM)->getValue());
$grade = trim($currentSheetM->getCell(‘H‘.$currentRowM)->getValue());
$long_name = trim($currentSheetM->getCell(‘I‘.$currentRowM)->getValue());
$logo = trim($currentSheetM->getCell(‘J‘.$currentRowM)->getValue());
$about = addslashes(trim($currentSheetM->getCell(‘K‘.$currentRowM)->getValue()));
$tips = addslashes(trim($currentSheetM->getCell(‘L‘.$currentRowM)->getValue()));

$sql = "select id from normalmerchant where domain = ‘".addslashes($domain)."‘ limit 1";
$dadd = $objMysql -> getRows($sql);
if($dadd){
continue;
echo $domain." exists\n";
}

$sql = "INSERT INTO normalmerchant (id,Name, Logo, MobileLogo, AddTime, Editor, IsActive, OriginalUrl, UrlName,rank,grade,country,domain,TermName,about,tips) VALUES(‘$ID‘,‘".addslashes($Name)."‘, ‘$logo‘, ‘$logo‘, ‘".date(‘Y-m-d H:i:s‘)."‘, ‘vickyzhang‘, ‘YES‘, ‘".addslashes($OriginalUrl)."‘, ‘".addslashes($UrlName)."‘,‘$rank‘,‘$grade‘,‘$mer_country‘,‘".addslashes($domain)."‘,‘".addslashes($long_name)."‘,‘$about‘,‘$tips‘)";

$qryId = $objMysql->query($sql);
$mid = $objMysql->getLastInsertId($qryId);
if(!$mid) continue;

$sql = "INSERT INTO normalmerchant_addinfo (ID) VALUES(‘$mid‘)";
$objMysql->query($sql);

$excute_num++;
if($totleRowC > 1){
if($mid){
foreach ($cateArr as $key => $value) {
if($value[‘MerId‘] == $ID){
if(trim($value[‘Type‘]) == ‘yes‘){
$type = 0;
}else{
$type = 1;
}
$sql = "INSERT INTO r_mer_category (MerId, CatId, Type, catprimary) VALUES(‘{$value[‘MerId‘]}‘,‘{$value[‘CatId‘]}‘,‘{$type}‘, ‘{$value[‘catprimary‘]}‘)";
echo $sql;
$objMysql->query($sql);
}
}
}
}
echo $mid."\r\n";
}
echo "insert mer cnt :".$i."\r\n";

 

下载链接https://stuhausteducn-my.sharepoint.com/:u:/g/personal/141419030129_stu_haust_edu_cn/EWIuoOZOLGdAlWfJP3V43pcBMMTFig2uVhJEMDc_o2C1-g?e=AXJ3LV

phpexce 表格上传与下载

标签:domain   nal   ted   imm   str   term   ase   backend   efi   

原文地址:https://www.cnblogs.com/yaradish/p/10139883.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!