标签: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
标签:domain nal ted imm str term ase backend efi
原文地址:https://www.cnblogs.com/yaradish/p/10139883.html