activatelist = M('activate_list');//激活文件夹 } /** * author jade * intro 上传txt码包验证方法 * param * return */ public function uploadVerify() { if (get_current_admin_id() == 1) $this->error('暂不支持管理员操作'); //获取需要拒绝的批次ID $bach_data = $this->task ->distinct(true) ->where(array('printer_id' => get_current_admin_id(), 'status' => 0)) ->getField('bach_id', true); if (!empty($bach_data)) $where['id'] = array('not in', $bach_data); $where['printer_id'] = get_current_admin_id(); $bach_result = $this->bach ->where($where) ->field('name') ->select(); $this->bach_result = $bach_result; $this->meta_title = '数据校验'; $this->display(); } /** * author jade * intro 把文件从临时目录中获取 * param * return bool */ public function Upload() { if (!is_array(I('url')) || empty(I('url'))) alert(array('code' => 0, 'msg' => '请联系开发人员')); $active_batch = I('active_batch'); $id = I('id'); foreach (I('url') as $k => $v) { $filename = basename($v, '.txt');//文件名 $url = 'Data/Code_Active_list/'. $active_batch. '/0/';//路径 $path = $url . basename($v);//路径+文件 if (!copy($v, $path)) alert(array('code' => 0, 'msg' => '上传失败')); //unlink($v); /*上传成功一次修改一次数据 start*/ $count = $this->getnum($path); $this->activatelist->where('id = '.$id)->setInc('num',$count); /*上传成功一次修改一次数据 stop*/ } alert(array('code' => 1, 'msg' => '上传成功')); } public function getnum($dir){ $cont=''; $cont.= file_get_contents(iconv("utf-8","gbk",$dir)); $cont = preg_replace('/\n|\r\n/','*',$cont); $data = explode("*",$cont); unset($cont); $data = array_filter($data); $count = count($data); return $count; } /** * author jade * intro 上传文件到零时目录 * param * return bool */ public function UploadTemp() { $fullName = $_FILES['file']['name']; $fileName = basename($fullName, '.txt'); $this->UploadCheck($fullName,$fileName); $config = C('UPLOAD_FILE_CONFIG');//获取上传配置 if (!file_exists('Temp/')) { mkdir('Temp/', '0777', true); } // if(is_file('./Temp/'.$fullName)){ // $fileName = $fileName.rand(100000,999999); // } $config['rootPath'] = './Temp/';//文件上传保存的根路径 $config['savePath'] = '/';//文件上传保存的根路径 $config['subName'] = false;//子目录创建方式 $config['saveName'] = $fileName;//上传文件的保存规则 $upload = new \Think\Upload($config); $info = $upload->upload(); if (!$info) { alert(array('code' => 0, 'msg' => $upload->getError())); } else { alert(array('code' => 1, 'msg' => '上传成功', 'file' => 'Temp/'. $fileName.'.txt')); } } /** * author jade * intro 上传规则检测 * param * return bool */ public function UploadCheck($fullName,$fileName) { if (preg_match("/[\x7f-\xff]/", $fileName)) { alert(array('code' => 0, 'msg' => '文件格式不规范,文件名包含汉字')); } if(is_file('./Temp/'.$fullName)){ $fileName = $fileName.rand(100000,999999); alert(array('code' => 0, 'msg' => '重复上传')); } return true; } /** * author jade * intro 码包详情页面 * param * return array obj json bool string resource */ public function fileList() { $keyword = I('keyword', '', 'string'); $map['filename'] = array('like', '%' . $keyword . '%'); $p = !empty($_GET["p"]) ? $_GET['p'] : 1; $data_list = $this->fileLog ->page($p, C('ADMIN_PAGE_ROWS')) ->where($map) ->order('id desc') ->select(); $page = new Page( $this->fileLog->where($map)->count(), C('ADMIN_PAGE_ROWS') ); foreach ($data_list as &$data) { $data['filename'] = cut_str($data['filename'], 0, 30) . ''; } // 使用Builder快速建立列表页面。 $builder = new \Common\Builder\ListBuilder(); $builder->setMetaTitle('码包管理')// 设置页面标题 ->setSearch('请输入ID/上传关键字', U('fileList')) ->addTableColumn('id', 'ID') ->addTableColumn('creator', '作者') ->addTableColumn('batch_id', '批次号') ->addTableColumn('is_verify', '类型', 'radio', array(0 => '二维码', 1 => '二维码+数字验证')) ->addTableColumn('path', '文件名及路径') ->addTableColumn('total', '总条数') ->addTableColumn('success_num', '成功条数') ->addTableColumn('error_num', '失败条数') ->addTableColumn('create_time', '创建时间', 'time') ->setTableDataList($data_list)// 数据列表 ->setTableDataPage($page->show())// 数据列表分页 ->display(); } /** * author jade * intro 批次详情 * param * return array obj json bool string resource */ public function getBachInfo() { $data = $this->QrView->where(array('bach.name' => I('bach_name')))->select(); return $this->ajaxReturn($data); } }