QrController.class.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?php
  2. /**
  3. * author xtj
  4. * intro 二维码类
  5. */
  6. namespace Admin\Controller;
  7. use Think\Page;
  8. class QrController extends AdminController
  9. {
  10. protected $fileLog, $product, $task, $bach, $QrView;
  11. /**
  12. * author xtj
  13. * intro 类初始化方法
  14. * param
  15. * return
  16. */
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->fileLog = M('FileLog');//上传文件日
  21. $this->product = M('product');
  22. $this->task = M('task');
  23. $this->bach = M('bach');
  24. $this->QrView = D('QrView');
  25. }
  26. /**
  27. * author xtj
  28. * intro 上传txt码包验证方法
  29. * param
  30. * return
  31. */
  32. public function UploadVerify()
  33. {
  34. if (get_current_admin_id() == 1) $this->error('暂不支持管理员操作');
  35. //获取需要拒绝的批次ID
  36. $bach_data = $this->task
  37. ->distinct(true)
  38. ->where(array('printer_id' => get_current_admin_id(), 'status' => 0))
  39. ->getField('bach_id', true);
  40. if (!empty($bach_data)) $where['id'] = array('not in', $bach_data);
  41. $where['printer_id'] = get_current_admin_id();
  42. $bach_result = $this->bach
  43. ->where($where)
  44. ->field('name')
  45. ->select();
  46. $this->bach_result = $bach_result;
  47. $this->meta_title = '数据校验';
  48. $this->display();
  49. }
  50. /**
  51. * author xtj
  52. * intro 把文件从临时目录中获取
  53. * param
  54. * return bool
  55. */
  56. public function Upload()
  57. {
  58. if (!is_array(I('url')) || empty(I('url'))) alert(array('code' => 0, 'msg' => '请联系开发人员'));
  59. foreach (I('url') as $k => $v) {
  60. $filename = basename($v, '.txt');//文件名
  61. $source = explode('_', $filename);
  62. $task_id = $source[2];//任务id
  63. $bach_name = $source[0] . '_' . $source[1];//批次名
  64. $url = 'Data/Code_Add_list/' . $bach_name . '/' . get_current_admin_name() . '/' . $bach_name . '_' . $source[2] . '/0/';//路径:上传路径
  65. $url1 = 'Data/Code_Add_list/' . $bach_name . '/' . get_current_admin_name() . '/' . $bach_name . '_' . $source[2] . '/1/';//路径:激活完路径
  66. $path = $url . basename($v);//路径+文件
  67. $is_verify = I('get.is_verify');//pathinfo 支持I接受post和get
  68. $bach_id = $this->bach
  69. ->where(array('name' => $bach_name))
  70. ->getField('id');
  71. if (count(array_filter($source)) != count($source)) alert(array('code' => 0, 'msg' => '文件名存在无效参数'));
  72. if (!file_exists($url)) mkdir($url, 0777, true);
  73. if (!file_exists($url1)) mkdir($url1, 0777, true);
  74. if (!copy($v, $path)) alert(array('code' => 0, 'msg' => '上传失败'));
  75. //暂时不执行这个方法
  76. /*
  77. if (!$this->fileLog->where(array('filename' => $filename, 'creator' => get_current_admin_name()))->find()) {
  78. //上传记录日志
  79. $file_log['creator'] = get_current_admin_name();
  80. $file_log['batch_id'] = $bach_id;
  81. $file_log['url'] = $url;
  82. $file_log['path'] = $path;
  83. $file_log['filename'] = $filename;
  84. $file_log['create_time'] = time();
  85. $file_log['is_verify'] = $is_verify;
  86. $file_log['task_id'] = $task_id;
  87. $this->fileLog->add($file_log)
  88. }
  89. *
  90. */
  91. //$status = empty($is_verify) ? 1 : 2;//1 管理员上传 2.印刷厂上传
  92. }
  93. $this->task->where(array('bach_id' => $bach_id, 'id' => $task_id))->setField('status', 1);
  94. alert(array('code' => 1, 'msg' => '上传成功'));
  95. /*if (get_current_admin_id() != 1 && !empty($is_verify)) {
  96. //调用插入接口
  97. R('Activate/index', array('bach_id' => $bach_id));
  98. alert(array('code' => 1, 'msg' => '上传成功,校验中'));
  99. } else {
  100. alert(array('code' => 1, 'msg' => '上传成功'));
  101. }*/
  102. }
  103. /**
  104. * author xtj
  105. * intro 上传文件到零时目录
  106. * param
  107. * return bool
  108. */
  109. public function UploadTemp()
  110. {
  111. $fullName = $_FILES['file']['name'];
  112. $fileName = basename($fullName, '.txt');
  113. $source = explode('_', $fileName);
  114. $task_id = $source[2];//任务id
  115. $bach_name = $source[0] . '_' . $source[1];//批次名
  116. $this->UploadCheck($fileName, $bach_name, $task_id);
  117. $config = C('UPLOAD_FILE_CONFIG');//获取上传配置
  118. if (!file_exists('Temp/')) {
  119. mkdir('Temp/', '0777', true);
  120. }
  121. $config['rootPath'] = './Temp/';//文件上传保存的根路径
  122. $config['subName'] = $bach_name . '/' . get_current_admin_name() . '/' . $bach_name . '_' . $task_id;//子目录创建方式
  123. $config['saveName'] = $fileName;//上传文件的保存规则
  124. $upload = new \Think\Upload($config);
  125. $info = $upload->upload();
  126. if (!$info) {
  127. alert(array('code' => 0, 'msg' => $upload->getError()));
  128. } else {
  129. alert(array('code' => 1, 'msg' => '上传成功', 'file' => 'Temp/' . $config['subName'] . '/' . $fullName));
  130. }
  131. }
  132. /**
  133. * author xtj
  134. * intro 上传规则检测
  135. * param
  136. * return bool
  137. */
  138. public function UploadCheck($fileName, $bach_name, $task_id)
  139. {
  140. if ((get_current_admin_name() == 'admin') && (I('get.is_verify') == 1)) alert(array('code' => 0, 'msg' => '此模块只允许印刷厂组用户操作'));
  141. if (strpos($fileName, '_') === false) alert(array('code' => 0, 'msg' => '文件格式不规范,格式:批次名_任务ID'));
  142. if (!$this->task->where(array('name' => $bach_name, 'id' => $task_id))->find()) {
  143. alert(array('code' => 0, 'msg' => '批次名对应的任务ID不存在'));
  144. }
  145. return true;
  146. }
  147. /**
  148. * author xtj
  149. * intro 码包详情页面
  150. * param
  151. * return array obj json bool string resource
  152. */
  153. public function fileList()
  154. {
  155. $keyword = I('keyword', '', 'string');
  156. $map['filename'] = array('like', '%' . $keyword . '%');
  157. $p = !empty($_GET["p"]) ? $_GET['p'] : 1;
  158. $data_list = $this->fileLog
  159. ->page($p, C('ADMIN_PAGE_ROWS'))
  160. ->where($map)
  161. ->order('id desc')
  162. ->select();
  163. $page = new Page(
  164. $this->fileLog->where($map)->count(),
  165. C('ADMIN_PAGE_ROWS')
  166. );
  167. foreach ($data_list as &$data) {
  168. $data['filename'] = cut_str($data['filename'], 0, 30)
  169. . '<input class="form-control input-sm" value="'
  170. . $data['path'] . '">';
  171. }
  172. // 使用Builder快速建立列表页面。
  173. $builder = new \Common\Builder\ListBuilder();
  174. $builder->setMetaTitle('码包管理')// 设置页面标题
  175. ->setSearch('请输入ID/上传关键字', U('fileList'))
  176. ->addTableColumn('id', 'ID')
  177. ->addTableColumn('creator', '作者')
  178. ->addTableColumn('batch_id', '批次号')
  179. ->addTableColumn('is_verify', '类型', 'radio', array(0 => '二维码', 1 => '二维码+数字验证'))
  180. ->addTableColumn('path', '文件名及路径')
  181. ->addTableColumn('total', '总条数')
  182. ->addTableColumn('success_num', '成功条数')
  183. ->addTableColumn('error_num', '失败条数')
  184. ->addTableColumn('create_time', '创建时间', 'time')
  185. ->setTableDataList($data_list)// 数据列表
  186. ->setTableDataPage($page->show())// 数据列表分页
  187. ->display();
  188. }
  189. /**
  190. * author xtj
  191. * intro 批次详情
  192. * param
  193. * return array obj json bool string resource
  194. */
  195. public function getBachInfo()
  196. {
  197. $data = $this->QrView->where(array('bach.name' => I('bach_name')))->select();
  198. return $this->ajaxReturn($data);
  199. }
  200. }