| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?php
- /**
- * author jade
- * intro 激活类
- */
- namespace Admin\Controller;
- class activateController extends AdminController
- {
- protected $config;
- /**
- * author jade
- * intro 类初始化方法
- * param
- * return
- */
- public function _initialize()
- {
- parent::_initialize();
- $this->config=D('Config');
- }
- /**
- * author xtj
- * intro 上传txt码包方法
- * param $group 调用系统配置项目
- * return bool
- */
-
- public function index($batch_id)
- {
- $file_log = M('file_log');
- ini_set('memory_limit', '2048M');
- set_time_limit(0);
- /*获取文件*/
- //$batch_id = 2;
- $where = array();
- $where['batch_id'] = $batch_id;
- $where['creator'] = 'admin';
- $file = $file_log->where($where)->getField('path',true);
- $printer_id = M('bach')->where('id = '.$batch_id)->getField('printer_id');
- $cont = '';
- $cont1 = '';
- $where = array();
- $where['batch_id'] = array('eq',$batch_id);
- $where['creator'] = array('neq','admin');
- $where['status'] = array('eq',0);
- $file1 = $file_log->field('id,path')->where($where)->select();
- if(count($file1)>0){
- foreach($file as $v){
- $fp = fopen(iconv("utf-8","gbk",$v), "r");
- $cont .= fread($fp,filesize(iconv("utf-8","gbk",$v)));
- $cont .="\n";
- $cont = preg_replace('/\n|\r\n/','*',$cont);
- }
- $data = array_filter(explode("*",$cont));
- foreach($file1 as $v){
- $name = explode('/',$v['path']);
- $name = explode('_',basename(array_pop($name),'.txt'));
- $tasks_id = $name[2] ;
- //查询任务对应的产品id
- $where= array();
- $where['id'] = $tasks_id ;
- $product = M('task')->field('product_id,is_verif')->where($where)->find();
- $product_id = $product['product_id'];
- $is_verif = $product['is_verif'];
- $cont1 = '';
- $cont1 .= file_get_contents(iconv("utf-8","gbk",$v['path']));
- $cont1 = preg_replace('/\n|\r\n/','*',$cont1);
- $data1 = explode("*",$cont1);
- $data1 = array_filter($data1);
- $total = count($data1);
- unset($cont1);
- $result=array_intersect($data,$data1);
- unset($data1);
- $this->add_data($result,$total,$batch_id,$tasks_id,$product_id,$printer_id,$v['id'],$is_verif);
- }
- }
- //批量修改task表
- $where= array();
- $where['bach_id'] = $batch_id ;
- $where['status'] = 2;
- $task_id = M('task')->where($where)->getField('id',true);
- foreach($task_id as $v){
- $where= array();
- $where['creator'] = array('neq','admin');
- $where['task_id'] = $v;
- $success_num = $file_log -> where($where)->sum(success_num);
- $error_num = $file_log -> where($where)->sum('error_num');
- if($success_num != ''){
- M()->execute('update `qr_task` set checked_num = '.$success_num.', wrong_num= '.$error_num.', status=3 '.'where id='.$v );
- }
- }
- }
-
- public function add_data($result,$total,$bach_id,$tasks_id,$product_id,$printer_id,$id,$is_verif){
- $data_new = array_chunk($result,10000);
- $i = count($data_new);
- if($i>0){
- $j = 0;
- $num = 0;
- for($j=0;$j<$i;$j++){
- $res = $this->data($data_new[$j],$bach_id,$tasks_id,$product_id,$printer_id,$is_verif);
- $num+=$res;
- }
- $succ = $num;
- $error = $total-$succ;
- //修改日志表
- M()->execute('update `qr_file_log` set total='.$total.', success_num='.$succ.',error_num='.$error.', status = 1 where id= '.$id);
- unset($data_new);
- }else{
- //直接修改file_log表
- M()->execute('update `qr_file_log` set total = '.$total.', success_num= 0 , error_num='.$total.', status = 1 where id='.$id );
- }
- unset($result);
- }
-
- public function data($data,$bach_id,$tasks_id,$product_id,$printer_id,$is_verif){
- $time = time();
- $p = $bach_id.",".$tasks_id.",".$product_id.",".$printer_id.",".$time.",".$time.",".$time.","."0,1";
- if($is_verif){
- array_walk($data, function(&$value,$key,$p){
- $value =parse_url($value);
- $value = substr($value['path'],1,-1);
- $value = "('" .str_replace(",","','",$value)."',".$p.")";
- },$p);
- }else{
- array_walk($data, function(&$value,$key,$p){
- $value =parse_url($value);
- $value = substr($value['path'],1,-1);
- $value = "('" .$value."',"."'',".$p.")";
- },$p);
- }
- $resultStr = join(",", $data);
- M()->execute("insert ignore INTO `qr_codes` (`code`,`varify_code`,`bach_id`,`tasks_id`,`product_id`,`printer_id`,`add_time`,`update_time`,`active_time`,`delete_time`,`Status`) values {$resultStr}");
- $res = M()->query('SELECT ROW_COUNT()');
- $num = $res[0]['ROW_COUNT()'];
- return $num;
- }
- }
|