| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- <?php
- /**
- * author xtj
- * intro 二维码类
- */
- namespace Admin\Controller;
- use Think\Page;
- class QrController extends AdminController
- {
- protected $fileLog, $product, $task, $bach, $QrView;
- /**
- * author xtj
- * intro 类初始化方法
- * param
- * return
- */
- public function _initialize()
- {
- parent::_initialize();
- $this->fileLog = M('FileLog');//上传文件日
- $this->product = M('product');
- $this->task = M('task');
- $this->bach = M('bach');
- $this->QrView = D('QrView');
- }
- /**
- * author xtj
- * 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 xtj
- * intro 把文件从临时目录中获取
- * param
- * return bool
- */
- public function Upload()
- {
- if (!is_array(I('url')) || empty(I('url'))) alert(array('code' => 0, 'msg' => '请联系开发人员'));
- foreach (I('url') as $k => $v) {
- $filename = basename($v, '.txt');//文件名
- $source = explode('_', $filename);
- $task_id = $source[2];//任务id
- $bach_name = $source[0] . '_' . $source[1];//批次名
- $url = 'Data/Code_Add_list/' . $bach_name . '/' . get_current_admin_name() . '/' . $bach_name . '_' . $source[2] . '/0/';//路径:上传路径
- $url1 = 'Data/Code_Add_list/' . $bach_name . '/' . get_current_admin_name() . '/' . $bach_name . '_' . $source[2] . '/1/';//路径:激活完路径
- $path = $url . basename($v);//路径+文件
- $is_verify = I('get.is_verify');//pathinfo 支持I接受post和get
- $bach_id = $this->bach
- ->where(array('name' => $bach_name))
- ->getField('id');
- if (count(array_filter($source)) != count($source)) alert(array('code' => 0, 'msg' => '文件名存在无效参数'));
- if (!file_exists($url)) mkdir($url, 0777, true);
- if (!file_exists($url1)) mkdir($url1, 0777, true);
- if (!copy($v, $path)) alert(array('code' => 0, 'msg' => '上传失败'));
- //暂时不执行这个方法
- /*
- if (!$this->fileLog->where(array('filename' => $filename, 'creator' => get_current_admin_name()))->find()) {
- //上传记录日志
- $file_log['creator'] = get_current_admin_name();
- $file_log['batch_id'] = $bach_id;
- $file_log['url'] = $url;
- $file_log['path'] = $path;
- $file_log['filename'] = $filename;
- $file_log['create_time'] = time();
- $file_log['is_verify'] = $is_verify;
- $file_log['task_id'] = $task_id;
- $this->fileLog->add($file_log)
- }
- *
- */
- //$status = empty($is_verify) ? 1 : 2;//1 管理员上传 2.印刷厂上传
-
- }
- $this->task->where(array('bach_id' => $bach_id, 'id' => $task_id))->setField('status', 1);
- alert(array('code' => 1, 'msg' => '上传成功'));
- /*if (get_current_admin_id() != 1 && !empty($is_verify)) {
- //调用插入接口
- R('Activate/index', array('bach_id' => $bach_id));
- alert(array('code' => 1, 'msg' => '上传成功,校验中'));
- } else {
- alert(array('code' => 1, 'msg' => '上传成功'));
- }*/
- }
- /**
- * author xtj
- * intro 上传文件到零时目录
- * param
- * return bool
- */
- public function UploadTemp()
- {
- $fullName = $_FILES['file']['name'];
- $fileName = basename($fullName, '.txt');
- $source = explode('_', $fileName);
- $task_id = $source[2];//任务id
- $bach_name = $source[0] . '_' . $source[1];//批次名
- $this->UploadCheck($fileName, $bach_name, $task_id);
- $config = C('UPLOAD_FILE_CONFIG');//获取上传配置
- if (!file_exists('Temp/')) {
- mkdir('Temp/', '0777', true);
- }
- $config['rootPath'] = './Temp/';//文件上传保存的根路径
- $config['subName'] = $bach_name . '/' . get_current_admin_name() . '/' . $bach_name . '_' . $task_id;//子目录创建方式
- $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/' . $config['subName'] . '/' . $fullName));
- }
- }
- /**
- * author xtj
- * intro 上传规则检测
- * param
- * return bool
- */
- public function UploadCheck($fileName, $bach_name, $task_id)
- {
- if ((get_current_admin_name() == 'admin') && (I('get.is_verify') == 1)) alert(array('code' => 0, 'msg' => '此模块只允许印刷厂组用户操作'));
- if (strpos($fileName, '_') === false) alert(array('code' => 0, 'msg' => '文件格式不规范,格式:批次名_任务ID'));
- if (!$this->task->where(array('name' => $bach_name, 'id' => $task_id))->find()) {
- alert(array('code' => 0, 'msg' => '批次名对应的任务ID不存在'));
- }
- return true;
- }
- /**
- * author xtj
- * 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)
- . '<input class="form-control input-sm" value="'
- . $data['path'] . '">';
- }
- // 使用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 xtj
- * 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);
- }
- }
|