config=D('Config');
}
/**
* author jade
* intro 激活码包方法
* param $group 调用系统配置项目
* return bool
*/
/*public function index()
{
ini_set('memory_limit', '2048M');
set_time_limit(0);
$t1 = microtime(true);
$dir = 'Data/active/jsl_1_27.txt';
$cont = file_get_contents(iconv("utf-8","gbk",$dir));
$cont = preg_replace('/\n|\r\n/','*',$cont);
$data = explode("*",$cont);
$data = array_filter($data);
$total = count($data);
$succ = 0;
foreach($data as $v){
$time = time();
$res = $this->data($time,$v,$dir);
if($res){
$succ++;
}
}
$t2 = microtime(true);
echo '耗时'.round($t2-$t1,3).'秒
';
echo 'Now memory_get_usage: ' . memory_get_usage() . '
';
echo $succ;
}
protected function data($time,$data,$dir){
$dir_arr = explode('/',$dir);
$dir = array_pop($dir_arr);
$param = explode(",",$data);
$url = parse_url($param[0]);
$url = substr($url['path'],1);
$re = M()->execute('update `qr_codes` set update_time = '.$time.', active_time= '.$time.', status=1 '.'where code='."'".$url."'");
//日志
if(!$re){
w_log('Data/log/'.$dir,$data."插入失败,错误原因,激活失败");
return 0;
}else{
return 1;
}
}*/
public function index()
{
ini_set('memory_limit', '512M');
set_time_limit(0);
G('begin');
if(empty(I('txt'))){
return "亲,输入文件名";
}
$dir = 'Data/active/'.I('txt').'.txt';
$cont='';
$cont.= file_get_contents(iconv("utf-8","gbk",$dir));
$cont = preg_replace('/\n|\r\n/','*',$cont);
$data = explode("*",$cont);
$data = array_filter($data);
$succ = 0;
foreach($data as $v){
$res = $this->data(time(),$v,$dir);
if($res){
$succ++;
}
}
G('end');
echo G('begin','end').'s,'.G('begin','end','m').'kb'.'
';
//unlink($dir);
w_log('Data/log/update_succ.txt',I('txt').'文件 成功插入'.$succ.'条,耗时'.G('begin','end').'秒\n');
echo $succ;
}
protected function data($time,$data,$dir){
$dir_arr = explode('/',$dir);
$dir = $dir_arr[2];
$param = explode(",",$data);
$url = substr(parse_url($param[0], PHP_URL_PATH),1);
$re = M()->execute('update `qr_codes` set update_time = '.$time.', active_time= '.$time.', status=1 '.'where code='."'".$url."' and status = 0");
//日志
if(!$re){
w_log('Data/log/'.$dir,$data."插入失败,错误原因,".M()->getError());
return 0;
}else{
return 1;
}
}
protected function data1($time,$data,$dir){
$dir_arr = explode('/',$dir);
$dir = array_pop($dir_arr);
$param = explode(",",$data);
$url = parse_url($param[0]);
$url = substr($url['path'],1);
$where = array();
$where['code'] = $url;
if(count($param)==2){
$where['varify_code'] = $param[1];
}
$return = M('codes')->where($where)->find();
if(!$return){
//写入日志
w_log('Data/log/'.$dir,$data."插入失败,错误原因,不存在");
}else{
if($return['Status']==1){
w_log('Data/log/'.$dir,$data."插入失败,错误原因,已激活");
return 1;
}else{
//激活
$re = M()->execute('update `qr_codes` set update_time = '.$time.', active_time= '.$time.', status=1 '.'where id='.$return["id"]);
//日志
if(!$re){
w_log('Data/log/'.$dir,$data."插入失败,错误原因,激活失败");
return 0;
}else{
return 1;
}
}
}
}
public function check_code(){
ini_set('memory_limit', '2048M');
set_time_limit(0);
$arr1 = array('jsl_1.txt','jsl_2.txt','jsl_3.txt','jsl_4.txt','jsl_5.txt','jsl_6.txt','jsl_7.txt');
$arr2 = array('jsl_114300.txt','jsl_352000.txt','jsl_389066.txt','jsl_435731.txt','jsl_449840.txt','jsl_453771.txt','jsl_501431.txt');
$code1 = '';
$code2 = '';
foreach($arr1 as $v){
$code1.= file_get_contents(iconv("utf-8","gbk",'Data/active/'.$v));
}
foreach($arr2 as $v){
$code2.= file_get_contents(iconv("utf-8","gbk",'Data/active/'.$v));
}
$code1 = preg_replace('/\n|\r\n/','*',$code1);
$code1_arr= explode("*",$code1);
$code1_arr = array_filter($code1_arr);
$code2 = preg_replace('/\n|\r\n/','*',$code2);
$code2_arr= explode("*",$code2);
$code2_arr = array_filter($code2_arr);
unset($arr1) ;unset($arr2) ;unset($code1) ;unset($code2) ;
//$result=array_intersect($code1_arr,$code2_arr);
$num = count($code2_arr)-count(array_unique($code2_arr));
$return = array_diff_assoc ($code2_arr, array_unique($code2_arr));
w_log('Data/log/chonghe.txt','自身重合数据:');
foreach($return as $v){
w_log('Data/log/chonghe.txt',$v);
}
w_log('Data/log/chonghe.txt','总数'.$num);
w_log('Data/log/chonghe.txt','和第一批重合数据:');
$return1 = array_intersect($code1_arr,array_unique($code2_arr));
foreach($return1 as $v){
w_log('Data/log/chonghe.txt',$v);
}
w_log('Data/log/chonghe.txt','总数'.count($return1));
unset($code1_arr) ;unset($code2_arr) ;
echo yes;
}
}