| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- <?php
- /**
- * author jade
- * intro 激活类
- */
- namespace Admin\Controller;
- class activate1Controller extends AdminController
- {
- protected $config;
- /**
- * author jade
- * intro 类初始化方法
- * param
- * return
- */
- public function _initialize()
- {
- parent::_initialize();
- $this->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).'秒<br>';
- echo 'Now memory_get_usage: ' . memory_get_usage() . '<br />';
- 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'.'<br/>';
- //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;
- }
- }
|