Qr1Controller.class.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. /**
  3. * author jade
  4. * intro 二维码类
  5. */
  6. namespace Admin\Controller;
  7. use Think\Page;
  8. class Qr1Controller extends AdminController
  9. {
  10. protected $fileLog, $product, $task, $bach, $QrView;
  11. /**
  12. * author jade
  13. * intro 类初始化方法
  14. * param
  15. * return
  16. */
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->activatelist = M('activate_list');//激活文件夹
  21. }
  22. /**
  23. * author jade
  24. * intro 上传txt码包验证方法
  25. * param
  26. * return
  27. */
  28. public function uploadVerify()
  29. {
  30. if (get_current_admin_id() == 1) $this->error('暂不支持管理员操作');
  31. //获取需要拒绝的批次ID
  32. $bach_data = $this->task
  33. ->distinct(true)
  34. ->where(array('printer_id' => get_current_admin_id(), 'status' => 0))
  35. ->getField('bach_id', true);
  36. if (!empty($bach_data)) $where['id'] = array('not in', $bach_data);
  37. $where['printer_id'] = get_current_admin_id();
  38. $bach_result = $this->bach
  39. ->where($where)
  40. ->field('name')
  41. ->select();
  42. $this->bach_result = $bach_result;
  43. $this->meta_title = '数据校验';
  44. $this->display();
  45. }
  46. /**
  47. * author jade
  48. * intro 把文件从临时目录中获取
  49. * param
  50. * return bool
  51. */
  52. public function Upload()
  53. {
  54. if (!is_array(I('url')) || empty(I('url'))) alert(array('code' => 0, 'msg' => '请联系开发人员'));
  55. $active_batch = I('active_batch');
  56. $id = I('id');
  57. foreach (I('url') as $k => $v) {
  58. $filename = basename($v, '.txt');//文件名
  59. $url = 'Data/Code_Active_list/'. $active_batch. '/0/';//路径
  60. $path = $url . basename($v);//路径+文件
  61. if (!copy($v, $path)) alert(array('code' => 0, 'msg' => '上传失败'));
  62. //unlink($v);
  63. /*上传成功一次修改一次数据 start*/
  64. $count = $this->getnum($path);
  65. $this->activatelist->where('id = '.$id)->setInc('num',$count);
  66. /*上传成功一次修改一次数据 stop*/
  67. }
  68. alert(array('code' => 1, 'msg' => '上传成功'));
  69. }
  70. public function getnum($dir){
  71. $cont='';
  72. $cont.= file_get_contents(iconv("utf-8","gbk",$dir));
  73. $cont = preg_replace('/\n|\r\n/','*',$cont);
  74. $data = explode("*",$cont);
  75. unset($cont);
  76. $data = array_filter($data);
  77. $count = count($data);
  78. return $count;
  79. }
  80. /**
  81. * author jade
  82. * intro 上传文件到零时目录
  83. * param
  84. * return bool
  85. */
  86. public function UploadTemp()
  87. {
  88. $fullName = $_FILES['file']['name'];
  89. $fileName = basename($fullName, '.txt');
  90. $this->UploadCheck($fullName,$fileName);
  91. $config = C('UPLOAD_FILE_CONFIG');//获取上传配置
  92. if (!file_exists('Temp/')) {
  93. mkdir('Temp/', '0777', true);
  94. }
  95. // if(is_file('./Temp/'.$fullName)){
  96. // $fileName = $fileName.rand(100000,999999);
  97. // }
  98. $config['rootPath'] = './Temp/';//文件上传保存的根路径
  99. $config['savePath'] = '/';//文件上传保存的根路径
  100. $config['subName'] = false;//子目录创建方式
  101. $config['saveName'] = $fileName;//上传文件的保存规则
  102. $upload = new \Think\Upload($config);
  103. $info = $upload->upload();
  104. if (!$info) {
  105. alert(array('code' => 0, 'msg' => $upload->getError()));
  106. } else {
  107. alert(array('code' => 1, 'msg' => '上传成功', 'file' => 'Temp/'. $fileName.'.txt'));
  108. }
  109. }
  110. /**
  111. * author jade
  112. * intro 上传规则检测
  113. * param
  114. * return bool
  115. */
  116. public function UploadCheck($fullName,$fileName)
  117. {
  118. if (preg_match("/[\x7f-\xff]/", $fileName)) {
  119. alert(array('code' => 0, 'msg' => '文件格式不规范,文件名包含汉字'));
  120. }
  121. if(is_file('./Temp/'.$fullName)){
  122. $fileName = $fileName.rand(100000,999999);
  123. alert(array('code' => 0, 'msg' => '重复上传'));
  124. }
  125. return true;
  126. }
  127. /**
  128. * author jade
  129. * intro 码包详情页面
  130. * param
  131. * return array obj json bool string resource
  132. */
  133. public function fileList()
  134. {
  135. $keyword = I('keyword', '', 'string');
  136. $map['filename'] = array('like', '%' . $keyword . '%');
  137. $p = !empty($_GET["p"]) ? $_GET['p'] : 1;
  138. $data_list = $this->fileLog
  139. ->page($p, C('ADMIN_PAGE_ROWS'))
  140. ->where($map)
  141. ->order('id desc')
  142. ->select();
  143. $page = new Page(
  144. $this->fileLog->where($map)->count(),
  145. C('ADMIN_PAGE_ROWS')
  146. );
  147. foreach ($data_list as &$data) {
  148. $data['filename'] = cut_str($data['filename'], 0, 30)
  149. . '<input class="form-control input-sm" value="'
  150. . $data['path'] . '">';
  151. }
  152. // 使用Builder快速建立列表页面。
  153. $builder = new \Common\Builder\ListBuilder();
  154. $builder->setMetaTitle('码包管理')// 设置页面标题
  155. ->setSearch('请输入ID/上传关键字', U('fileList'))
  156. ->addTableColumn('id', 'ID')
  157. ->addTableColumn('creator', '作者')
  158. ->addTableColumn('batch_id', '批次号')
  159. ->addTableColumn('is_verify', '类型', 'radio', array(0 => '二维码', 1 => '二维码+数字验证'))
  160. ->addTableColumn('path', '文件名及路径')
  161. ->addTableColumn('total', '总条数')
  162. ->addTableColumn('success_num', '成功条数')
  163. ->addTableColumn('error_num', '失败条数')
  164. ->addTableColumn('create_time', '创建时间', 'time')
  165. ->setTableDataList($data_list)// 数据列表
  166. ->setTableDataPage($page->show())// 数据列表分页
  167. ->display();
  168. }
  169. /**
  170. * author jade
  171. * intro 批次详情
  172. * param
  173. * return array obj json bool string resource
  174. */
  175. public function getBachInfo()
  176. {
  177. $data = $this->QrView->where(array('bach.name' => I('bach_name')))->select();
  178. return $this->ajaxReturn($data);
  179. }
  180. }