Activate1Controller.class.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. /**
  3. * author jade
  4. * intro 激活类
  5. */
  6. namespace Admin\Controller;
  7. class activate1Controller extends AdminController
  8. {
  9. protected $config;
  10. /**
  11. * author jade
  12. * intro 类初始化方法
  13. * param
  14. * return
  15. */
  16. public function _initialize()
  17. {
  18. parent::_initialize();
  19. $this->config=D('Config');
  20. }
  21. /**
  22. * author jade
  23. * intro 激活码包方法
  24. * param $group 调用系统配置项目
  25. * return bool
  26. */
  27. /*public function index()
  28. {
  29. ini_set('memory_limit', '2048M');
  30. set_time_limit(0);
  31. $t1 = microtime(true);
  32. $dir = 'Data/active/jsl_1_27.txt';
  33. $cont = file_get_contents(iconv("utf-8","gbk",$dir));
  34. $cont = preg_replace('/\n|\r\n/','*',$cont);
  35. $data = explode("*",$cont);
  36. $data = array_filter($data);
  37. $total = count($data);
  38. $succ = 0;
  39. foreach($data as $v){
  40. $time = time();
  41. $res = $this->data($time,$v,$dir);
  42. if($res){
  43. $succ++;
  44. }
  45. }
  46. $t2 = microtime(true);
  47. echo '耗时'.round($t2-$t1,3).'秒<br>';
  48. echo 'Now memory_get_usage: ' . memory_get_usage() . '<br />';
  49. echo $succ;
  50. }
  51. protected function data($time,$data,$dir){
  52. $dir_arr = explode('/',$dir);
  53. $dir = array_pop($dir_arr);
  54. $param = explode(",",$data);
  55. $url = parse_url($param[0]);
  56. $url = substr($url['path'],1);
  57. $re = M()->execute('update `qr_codes` set update_time = '.$time.', active_time= '.$time.', status=1 '.'where code='."'".$url."'");
  58. //日志
  59. if(!$re){
  60. w_log('Data/log/'.$dir,$data."插入失败,错误原因,激活失败");
  61. return 0;
  62. }else{
  63. return 1;
  64. }
  65. }*/
  66. public function index()
  67. {
  68. ini_set('memory_limit', '512M');
  69. set_time_limit(0);
  70. G('begin');
  71. if(empty(I('txt'))){
  72. return "亲,输入文件名";
  73. }
  74. $dir = 'Data/active/'.I('txt').'.txt';
  75. $cont='';
  76. $cont.= file_get_contents(iconv("utf-8","gbk",$dir));
  77. $cont = preg_replace('/\n|\r\n/','*',$cont);
  78. $data = explode("*",$cont);
  79. $data = array_filter($data);
  80. $succ = 0;
  81. foreach($data as $v){
  82. $res = $this->data(time(),$v,$dir);
  83. if($res){
  84. $succ++;
  85. }
  86. }
  87. G('end');
  88. echo G('begin','end').'s,'.G('begin','end','m').'kb'.'<br/>';
  89. //unlink($dir);
  90. w_log('Data/log/update_succ.txt',I('txt').'文件 成功插入'.$succ.'条,耗时'.G('begin','end').'秒\n');
  91. echo $succ;
  92. }
  93. protected function data($time,$data,$dir){
  94. $dir_arr = explode('/',$dir);
  95. $dir = $dir_arr[2];
  96. $param = explode(",",$data);
  97. $url = substr(parse_url($param[0], PHP_URL_PATH),1);
  98. $re = M()->execute('update `qr_codes` set update_time = '.$time.', active_time= '.$time.', status=1 '.'where code='."'".$url."' and status = 0");
  99. //日志
  100. if(!$re){
  101. w_log('Data/log/'.$dir,$data."插入失败,错误原因,".M()->getError());
  102. return 0;
  103. }else{
  104. return 1;
  105. }
  106. }
  107. protected function data1($time,$data,$dir){
  108. $dir_arr = explode('/',$dir);
  109. $dir = array_pop($dir_arr);
  110. $param = explode(",",$data);
  111. $url = parse_url($param[0]);
  112. $url = substr($url['path'],1);
  113. $where = array();
  114. $where['code'] = $url;
  115. if(count($param)==2){
  116. $where['varify_code'] = $param[1];
  117. }
  118. $return = M('codes')->where($where)->find();
  119. if(!$return){
  120. //写入日志
  121. w_log('Data/log/'.$dir,$data."插入失败,错误原因,不存在");
  122. }else{
  123. if($return['Status']==1){
  124. w_log('Data/log/'.$dir,$data."插入失败,错误原因,已激活");
  125. return 1;
  126. }else{
  127. //激活
  128. $re = M()->execute('update `qr_codes` set update_time = '.$time.', active_time= '.$time.', status=1 '.'where id='.$return["id"]);
  129. //日志
  130. if(!$re){
  131. w_log('Data/log/'.$dir,$data."插入失败,错误原因,激活失败");
  132. return 0;
  133. }else{
  134. return 1;
  135. }
  136. }
  137. }
  138. }
  139. public function check_code(){
  140. ini_set('memory_limit', '2048M');
  141. set_time_limit(0);
  142. $arr1 = array('jsl_1.txt','jsl_2.txt','jsl_3.txt','jsl_4.txt','jsl_5.txt','jsl_6.txt','jsl_7.txt');
  143. $arr2 = array('jsl_114300.txt','jsl_352000.txt','jsl_389066.txt','jsl_435731.txt','jsl_449840.txt','jsl_453771.txt','jsl_501431.txt');
  144. $code1 = '';
  145. $code2 = '';
  146. foreach($arr1 as $v){
  147. $code1.= file_get_contents(iconv("utf-8","gbk",'Data/active/'.$v));
  148. }
  149. foreach($arr2 as $v){
  150. $code2.= file_get_contents(iconv("utf-8","gbk",'Data/active/'.$v));
  151. }
  152. $code1 = preg_replace('/\n|\r\n/','*',$code1);
  153. $code1_arr= explode("*",$code1);
  154. $code1_arr = array_filter($code1_arr);
  155. $code2 = preg_replace('/\n|\r\n/','*',$code2);
  156. $code2_arr= explode("*",$code2);
  157. $code2_arr = array_filter($code2_arr);
  158. unset($arr1) ;unset($arr2) ;unset($code1) ;unset($code2) ;
  159. //$result=array_intersect($code1_arr,$code2_arr);
  160. $num = count($code2_arr)-count(array_unique($code2_arr));
  161. $return = array_diff_assoc ($code2_arr, array_unique($code2_arr));
  162. w_log('Data/log/chonghe.txt','自身重合数据:');
  163. foreach($return as $v){
  164. w_log('Data/log/chonghe.txt',$v);
  165. }
  166. w_log('Data/log/chonghe.txt','总数'.$num);
  167. w_log('Data/log/chonghe.txt','和第一批重合数据:');
  168. $return1 = array_intersect($code1_arr,array_unique($code2_arr));
  169. foreach($return1 as $v){
  170. w_log('Data/log/chonghe.txt',$v);
  171. }
  172. w_log('Data/log/chonghe.txt','总数'.count($return1));
  173. unset($code1_arr) ;unset($code2_arr) ;
  174. echo yes;
  175. }
  176. }