Trademark.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Trademark extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->_model('Model_trademark','trademark');
  6. $this->load->_model('Model_excel','excel');
  7. }
  8. //定义方法的调用规则 获取URI第二段值
  9. public function _remap($arg,$arg_array)
  10. {
  11. if($arg == 'add')//添加
  12. {
  13. $this->_add();
  14. }
  15. else if($arg == 'edit')//修改
  16. {
  17. $this->_edit($arg_array);
  18. }
  19. else if($arg == 'del')//修改
  20. {
  21. $this->_del();
  22. }
  23. else if($arg == 'rows')//修改
  24. {
  25. $this->_rows();
  26. }
  27. else if($arg == 'code')
  28. {
  29. $this->_code($arg_array);
  30. }
  31. else if($arg == 'excel')
  32. {
  33. $this->_excel();
  34. }
  35. else if($arg == 'down')
  36. {
  37. $this->_down();
  38. }
  39. else
  40. {
  41. $this->_index();
  42. }
  43. }
  44. //管理
  45. public function _index()
  46. {
  47. $post = $this->input->post(NULL, TRUE);
  48. if(isset($post['page']))
  49. {
  50. $page = $this->input->post('page',true);
  51. $perpage = $this->input->post('perpage',true);
  52. $name = $this->input->post('name',true);
  53. $type = $this->input->post('type',true);
  54. $class = $this->input->post('class',true);
  55. $owner = $this->input->post('owner',true);
  56. $agent = $this->input->post('agent',true);
  57. $number = $this->input->post('number',true);
  58. $xztime = $this->input->post('xztime',true);
  59. $timetk = $this->input->post('timetk',true);
  60. $timetj = $this->input->post('timetj',true);
  61. $timetk = strtotime($timetk);
  62. $timetj = strtotime($timetj);
  63. $where = "1=1 ";
  64. //数据排序
  65. $order_str = $xztime." desc";
  66. if($name)
  67. {
  68. $where .= " and name like '%$name%'";
  69. }
  70. if($type)
  71. {
  72. $where .= " and type = '$type'";
  73. }
  74. if($class)
  75. {
  76. $where .= " and class like '%$class%'";
  77. }
  78. if($owner)
  79. {
  80. $where .= " and owner like '%$owner%'";
  81. }
  82. if($agent)
  83. {
  84. $where .= " and agent like '%$agent%'";
  85. }
  86. if($number)
  87. {
  88. $where .= " and number like '%$number%'";
  89. }
  90. if($timetk && $timetj)
  91. {
  92. $where .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";
  93. }
  94. if(empty($page))
  95. {
  96. $start = 0;
  97. $perpage = 1;
  98. }
  99. else
  100. {
  101. $start = ($page - 1)*$perpage;
  102. }
  103. //取得信息列表
  104. $info_list = $this->trademark->find_all($where,'id,type,name,number,class,owner,agent,djtime,sqtime,ggtime',$order_str,$start,$perpage);
  105. //格式化数据
  106. foreach ($info_list as $key=>$value)
  107. {
  108. if($value['type'] == 1)
  109. {
  110. $info_list[$key]['type'] = '国内商标';
  111. }
  112. else if($value['type'] == 2)
  113. {
  114. $info_list[$key]['type'] = '美国商标';
  115. }
  116. else if($value['type'] == 3)
  117. {
  118. $info_list[$key]['type'] = '国内专利';
  119. }
  120. else if($value['type'] == 4)
  121. {
  122. $info_list[$key]['type'] = '美国专利';
  123. }
  124. else if($value['type'] == 5)
  125. {
  126. $info_list[$key]['type'] = '欧洲商标';
  127. }
  128. $info_list[$key]['djtime'] = ($value['djtime'] > 0)?date('Y-m-d H:i:s',$value['djtime']):'';
  129. $info_list[$key]['sqtime'] = ($value['sqtime'] > 0)?date('Y-m-d H:i:s',$value['sqtime']):'';
  130. $info_list[$key]['ggtime'] = ($value['ggtime'] > 0)?date('Y-m-d H:i:s',$value['ggtime']):'';
  131. }
  132. $total = $this->trademark->find_count($where);
  133. $pagenum = ceil($total/$perpage);
  134. $over = $total-($start+$perpage);
  135. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  136. echo json_encode($rows);exit;
  137. }
  138. $this->_Template('trademark',$this->data);
  139. }
  140. //添加
  141. public function _add()
  142. {
  143. $post = $this->input->post(NULL, TRUE);
  144. if(isset($post['name']))
  145. {
  146. if($this->trademark->insert($post))
  147. {
  148. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  149. }
  150. else
  151. {
  152. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  153. }
  154. }
  155. $this->_Template('trademark_add',$this->data);
  156. }
  157. //修改
  158. public function _edit($arg_array)
  159. {
  160. $post = $this->input->post(NULL, TRUE);
  161. if(isset($post['id']))
  162. {
  163. $id = $this->input->post('id',true);
  164. if($this->trademark->save($post,$id))
  165. {
  166. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  167. }
  168. else
  169. {
  170. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  171. }
  172. }
  173. $arg_array = $arg_array[0];
  174. $trademark = $this->trademark->read($arg_array);
  175. $this->data['trademark'] = $trademark;
  176. $this->_Template('trademark_edit',$this->data);
  177. }
  178. //删除
  179. public function _del()
  180. {
  181. $post = $this->input->post(NULL, TRUE);
  182. if(isset($post['s']))
  183. {
  184. $id_arr = $this->input->post('s');
  185. $id_arr = explode(',',$id_arr);
  186. if(!$id_arr)
  187. {
  188. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  189. }
  190. //循环删除记录
  191. foreach ($id_arr as $v)
  192. {
  193. $this->trademark->remove($v);
  194. }
  195. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  196. }
  197. }
  198. public function _excel()
  199. {
  200. $dir = '/data/excel/'.date('Ymd',time()).'/';
  201. $config['upload_path'] = '.'.$dir ;
  202. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  203. $config['allowed_types'] = 'xls|xlsx|csv';
  204. $config['max_size'] = 10240;
  205. $this->load->library('upload', $config);
  206. $this->upload->initialize($config);
  207. if ($this->upload->do_upload('userfile'))
  208. {
  209. $full_path = $dir.$this->upload->data('file_name');
  210. $fileName = '.' . $full_path;
  211. if (!file_exists($fileName))
  212. {
  213. echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
  214. }
  215. else
  216. {
  217. require_once "./data/excel/PHPExcel/IOFactory.php";
  218. $phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
  219. $phpExcel->setActiveSheetIndex(0);// 设置为默认表
  220. $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
  221. $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
  222. $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
  223. ++$column;//如果列数大于26行
  224. $list = array();
  225. for ($i = 2; $i <= $row; $i++) // 行数循环
  226. {
  227. $data = array();
  228. for ($c = 'A'; $c != $column; $c++) // 列数循环
  229. {
  230. $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
  231. }
  232. $list[] = $data;
  233. }
  234. }
  235. $i = 0;$j = 0;$ed = array();$tytime = time();
  236. foreach ($list as $key=>$value)
  237. {
  238. $cf = $this->trademark->find_all("number = '".$value['3']."'");
  239. if(!isset($value['3'][0]))
  240. {
  241. $post['name'] = $value['2'];
  242. if($value['1'] == '国内商标')
  243. {
  244. $post['value'] = 1;
  245. }
  246. else if($value['1'] == '美国商标')
  247. {
  248. $post['value'] = 2;
  249. }
  250. else if($value['1'] == '国内专利')
  251. {
  252. $post['value'] = 3;
  253. }
  254. else if($value['1'] == '美国专利')
  255. {
  256. $post['value'] = 4;
  257. }
  258. else if($value['1'] == '欧洲商标')
  259. {
  260. $post['value'] = 5;
  261. }
  262. $post['number'] = $value['3'];
  263. $post['class'] = $value['4'];
  264. $post['sqtime'] = $value['5'];
  265. $post['ggtime'] = $value['6'];
  266. $post['owner'] = $value['7'];
  267. $this->trademark->insert($post);
  268. }
  269. else
  270. {
  271. $ed[] = array($value['3'].'-有重复');
  272. $i++;
  273. }
  274. sleep(2);//停留2秒
  275. }
  276. if($i+$j > 0)
  277. {
  278. $time = date('Ymd',time());
  279. $title = '错误信息-'.$time;
  280. $titlename = "<table border=1><tr><td>错误详情</td></tr></table>";
  281. $tail = "\n";
  282. $filename = $title.".xls";
  283. $ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);
  284. $dir = '/data/excel/'.$time.'/';
  285. $file_name = 'error_'.$time.rand(1000,9999);
  286. if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);
  287. $myfile = fopen(".".$dir.$file_name.".xls", "w") or die();
  288. fwrite($myfile,$ecl);
  289. fclose($myfile);
  290. $error = $dir.$file_name.'.xls';
  291. echo json_encode(array('msg'=>'添加成功,'.$i.'条异常,'.$j.'条失败','error'=>$error,'success'=>true));exit;
  292. }
  293. else
  294. {
  295. echo json_encode(array('msg'=>'添加成功!','error'=>1,'success'=>true));exit;
  296. }
  297. }
  298. else
  299. {
  300. echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
  301. }
  302. }
  303. //下载excel模板
  304. public function _down()
  305. {
  306. if(isset($_GET['excela']))
  307. {
  308. $title = "许昌龙熠美发饰品有限公司第一届雀王争霸赛";
  309. $titlename = "<table border=1>
  310. <tr><th colspan='8' align='left'><h3>许昌龙熠美发饰品有限公司第一届雀王争霸赛<h3></th></tr>
  311. <tr>
  312. <td>参加/不参加</td
  313. <td>选手昵称</td>
  314. <td>年龄</td>
  315. <td>喜好</td>
  316. <td>联系电话</td>
  317. <td>麻龄</td>
  318. <td>输赢</td>
  319. <td>牌后总结</td>
  320. </tr>
  321. </table>";
  322. $filename = $title.".xls";
  323. $tail = "\n";
  324. $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
  325. exit;
  326. $title = "导入模板";
  327. $titledata = array(array('序号','商标类型','商标名称','注册号','国际分类','申请日期','注册公告日期','申请人'),array('1','国内商标','AAA','1111111','18','2000-01-01','2000-01-01','许昌龙熠美发饰品有限公司'));
  328. $filename = $title.".xls";
  329. $this->get_excel($titledata,$filename);
  330. }
  331. }
  332. public function get_excel($titledata,$filename)
  333. {
  334. require_once "./data/excel/PHPExcel/IOFactory.php";
  335. $objPHPExcel = new \PHPExcel();
  336. $objPHPExcel->setActiveSheetIndex(0);
  337. $dataArray = $titledata;
  338. $objPHPExcel->getActiveSheet()->fromArray($dataArray, null, 'A1');
  339. header('Content-Type: application/vnd.ms-excel');
  340. header('Content-Disposition: attachment;filename='.$filename);
  341. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
  342. $objWriter->save('php://output');
  343. $objPHPExcel->disconnectWorksheets();
  344. }
  345. }