Weight.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Weight extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_weight','weight');
  7. $this->load->_model('Model_typeclass','typeclass');
  8. $this->load->_model('Model_excel','excel');
  9. }
  10. //定义方法的调用规则 获取URI第二段值
  11. public function _remap($arg,$arg_array)
  12. {
  13. if($arg == 'add')//添加
  14. {
  15. $this->_add();
  16. }
  17. else if($arg == 'edit')//修改
  18. {
  19. $this->_edit($arg_array);
  20. }
  21. else if($arg == 'del')//修改
  22. {
  23. $this->_del();
  24. }
  25. else if($arg == 'cx')
  26. {
  27. $this->_cx();
  28. }
  29. else if($arg == 'weight')
  30. {
  31. $this->_weight();
  32. }
  33. else if($arg == 'excel')//修改
  34. {
  35. $this->_excel();
  36. }
  37. else if($arg == 'drexcel')//修改
  38. {
  39. $this->_drexcel($arg_array);
  40. }
  41. else if($arg == 'mb')//修改
  42. {
  43. $this->_mb();
  44. }
  45. else
  46. {
  47. $this->_index();
  48. }
  49. }
  50. //管理
  51. public function _index()
  52. {
  53. $post = $this->input->post(NULL, TRUE);
  54. if(isset($post['page']))
  55. {
  56. $page = $this->input->post('page',true);
  57. $perpage = $this->input->post('perpage',true);
  58. $sku = $this->input->post('sku',true);
  59. $title = $this->input->post('title',true);
  60. $features = $this->input->post('category',true);
  61. $where = "1=1 ";
  62. if($features)
  63. {
  64. $where .= " and features like '%$features-%'";
  65. }
  66. if($sku)
  67. {
  68. $where .= " and sku like '%$sku%'";
  69. }
  70. if($title)
  71. {
  72. $where .= " and title like '%$title%'";
  73. }
  74. //数据排序
  75. $order_str = "id asc";
  76. if(empty($page))
  77. {
  78. $start = 0;
  79. $perpage = 1;
  80. }
  81. else
  82. {
  83. $start = ($page - 1)*$perpage;
  84. }
  85. //取得信息列表
  86. $info_list = $this->weight->find_all($where,'id,title,sku,weight',$order_str,$start,$perpage);
  87. foreach ($info_list as $key=>$value)
  88. {
  89. $info_list[$key]['weight'] = $value['weight'].'克';
  90. }
  91. $total = $this->weight->find_count($where);
  92. $pagenum = ceil($total/$perpage);
  93. $over = $total-($start+$perpage);
  94. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  95. echo json_encode($rows);exit;
  96. }
  97. $this->_Template('weight',$this->data);
  98. }
  99. //添加
  100. public function _add()
  101. {
  102. $post = $this->input->post(NULL, TRUE);
  103. if(isset($post['weight']))
  104. {
  105. $list = array();$num = "";$title = "";
  106. $post['weight'] = $this->input->post('weight',true);
  107. $category = $this->input->post('category',true);
  108. $list['category'] = $category;
  109. $list['hairtype'] = $this->input->post('hairtype',true);
  110. $list['grade'] = $this->input->post('grade',true);
  111. $size = $this->input->post('size',true);
  112. $list['size'] = rtrim($size,',');
  113. $list['hairnumber'] = $this->input->post('hairnumber',true);
  114. $list['extension'] = $this->input->post('extension',true);
  115. if($category == 1297)
  116. {
  117. $list['sywignumber'] = $this->input->post('sywignumber',true);
  118. }
  119. if($category == 1702)
  120. {
  121. $list['syhairnumber'] = $this->input->post('syhairnumber',true);
  122. $list['syother'] = $this->input->post('syother',true);
  123. }
  124. if($category == 133)
  125. {
  126. $list['fittype'] = $this->input->post('fittype',true);
  127. $list['acother'] = $this->input->post('acother',true);
  128. }
  129. $list['color'] = $this->input->post('color',true);
  130. $list['lowe'] = $this->input->post('lowe',true);
  131. if($category == 127)
  132. {
  133. $list['type'] = $this->input->post('type',true);
  134. $list['headroad'] = $this->input->post('headroad',true);
  135. $list['density'] = $this->input->post('density',true);
  136. if($list['type'] == 195 || $list['type'] == 197 || $list['type'] == 199)
  137. {
  138. $list['lacesize'] = $this->input->post('lacesize',true);
  139. }
  140. $list['lacecolor'] = $this->input->post('lacecolor',true);
  141. $list['lacetypes'] = $this->input->post('lacetypes',true);
  142. }
  143. if($category == 128)
  144. {
  145. $list['lacetype'] = $this->input->post('lacetype',true);
  146. $list['haircap'] = $this->input->post('haircap',true);
  147. $list['density'] = $this->input->post('density',true);
  148. $list['lacecolor'] = $this->input->post('lacecolor',true);
  149. $list['lacetypes'] = $this->input->post('lacetypes',true);
  150. $list['wigother'] = $this->input->post('wigother',true);
  151. }
  152. if($category == 129)
  153. {
  154. $list['wide'] = $this->input->post('wide',true);
  155. }
  156. if($category == 131)
  157. {
  158. $list['gifttype'] = $this->input->post('gifttype',true);
  159. $list['giftother'] = $this->input->post('giftother',true);
  160. }
  161. if($category == 134)
  162. {
  163. $list['pieceweight'] = $this->input->post('pieceweight',true);
  164. }
  165. if($category == 1297)
  166. {
  167. $list['synthetictype'] = $this->input->post('synthetictype',true);
  168. $list['sywigother'] = $this->input->post('sywigother',true);
  169. }
  170. if($category == 130 || $category == 133 || $category == 1702)
  171. {
  172. $list['items'] = $this->input->post('items',true);
  173. }
  174. if($category == 1702)
  175. {
  176. $list['syhairther'] = $this->input->post('syhairther',true);
  177. }
  178. foreach($list as $k=>$v)
  179. {
  180. if($v != 0)
  181. {
  182. $num .=$v.'-';
  183. $post[$k] = $v;
  184. $typeclass = $this->typeclass->read($v);
  185. $title = $title.$typeclass['title']." ";
  186. }
  187. }
  188. $post['sku'] = rtrim($num,'-');
  189. $post['title'] = rtrim($title,' ');
  190. $rows = $this->weight->get_title($title);
  191. if(!$rows)
  192. {
  193. $this->weight->insert($post);
  194. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  195. }
  196. else
  197. {
  198. echo json_encode(array('msg'=>'添加失败,有重复数据','success'=>false));exit;
  199. }
  200. }
  201. $this->_Template('weight_add',$this->data);
  202. }
  203. //修改
  204. public function _edit($arg_array)
  205. {
  206. $post = $this->input->post(NULL, TRUE);
  207. if(isset($post['id']))
  208. {
  209. $list = array();$num = "";$title = "";
  210. $id = $this->input->post('id',true);
  211. $data = $this->weight->read($id);
  212. foreach($data as $k=>$v)
  213. {
  214. $post[$k] = 0;
  215. }
  216. $post['id'] = $id;
  217. $post['sku'] = $this->input->post('sku',true);
  218. $post['weight'] = $this->input->post('weight',true);
  219. $category = $this->input->post('category',true);
  220. $list['category'] = $category;
  221. $list['hairtype'] = $this->input->post('hairtype',true);
  222. $list['grade'] = $this->input->post('grade',true);
  223. $size = $this->input->post('size',true);
  224. $list['size'] = rtrim($size,',');
  225. $list['hairnumber'] = $this->input->post('hairnumber',true);
  226. $list['extension'] = $this->input->post('extension',true);
  227. if($category == 1297)
  228. {
  229. $list['sywignumber'] = $this->input->post('sywignumber',true);
  230. }
  231. if($category == 1702)
  232. {
  233. $list['syhairnumber'] = $this->input->post('syhairnumber',true);
  234. $list['syother'] = $this->input->post('syother',true);
  235. }
  236. if($category == 133)
  237. {
  238. $list['fittype'] = $this->input->post('fittype',true);
  239. $list['acother'] = $this->input->post('acother',true);
  240. }
  241. $list['color'] = $this->input->post('color',true);
  242. $list['lowe'] = $this->input->post('lowe',true);
  243. if($category == 127)
  244. {
  245. $list['type'] = $this->input->post('type',true);
  246. $list['headroad'] = $this->input->post('headroad',true);
  247. $list['density'] = $this->input->post('density',true);
  248. if($list['type'] == 195 || $list['type'] == 197 || $list['type'] == 199)
  249. {
  250. $list['lacesize'] = $this->input->post('lacesize',true);
  251. }
  252. $list['lacecolor'] = $this->input->post('lacecolor',true);
  253. $list['lacetypes'] = $this->input->post('lacetypes',true);
  254. }
  255. if($category == 128)
  256. {
  257. $list['lacetype'] = $this->input->post('lacetype',true);
  258. $list['haircap'] = $this->input->post('haircap',true);
  259. $list['density'] = $this->input->post('density',true);
  260. $list['lacecolor'] = $this->input->post('lacecolor',true);
  261. $list['lacetypes'] = $this->input->post('lacetypes',true);
  262. $list['wigother'] = $this->input->post('wigother',true);
  263. }
  264. if($category == 129)
  265. {
  266. $list['wide'] = $this->input->post('wide',true);
  267. }
  268. if($category == 131)
  269. {
  270. $list['gifttype'] = $this->input->post('gifttype',true);
  271. $list['giftother'] = $this->input->post('giftother',true);
  272. }
  273. if($category == 134)
  274. {
  275. $list['pieceweight'] = $this->input->post('pieceweight',true);
  276. }
  277. if($category == 1297)
  278. {
  279. $list['synthetictype'] = $this->input->post('synthetictype',true);
  280. $list['sywigother'] = $this->input->post('sywigother',true);
  281. }
  282. if($category == 130 || $category == 133 || $category == 1702)
  283. {
  284. $list['items'] = $this->input->post('items',true);
  285. }
  286. if($category == 1702)
  287. {
  288. $list['syhairther'] = $this->input->post('syhairther',true);
  289. }
  290. foreach($list as $k=>$v)
  291. {
  292. if($v != 0)
  293. {
  294. $num .=$v.'-';
  295. $post[$k] = $v;
  296. $typeclass = $this->typeclass->read($v);
  297. $title = $title.$typeclass['title']." ";
  298. }
  299. }
  300. $post['sku'] = rtrim($num,'-');
  301. $post['title'] = rtrim($title,' ');
  302. $rows = $this->weight->get_title($title);
  303. if(!$rows || $rows['id'] == $id)
  304. {
  305. $this->weight->save($post,$id);
  306. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  307. }
  308. else
  309. {
  310. echo json_encode(array('msg'=>'修改失败,有重复数据','success'=>false));exit;
  311. }
  312. }
  313. $arg_array = $arg_array[0];
  314. $weight = $this->weight->read($arg_array);
  315. $this->data['weight'] = $weight;
  316. $this->_Template('weight_edit',$this->data);
  317. }
  318. //删除
  319. public function _del()
  320. {
  321. $post = $this->input->post(NULL, TRUE);
  322. if(isset($post['s']))
  323. {
  324. $id_arr = $this->input->post('s');
  325. $id_arr = explode(',',$id_arr);
  326. if(!$id_arr)
  327. {
  328. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  329. }
  330. //循环删除记录
  331. foreach ($id_arr as $v)
  332. {
  333. $this->weight->remove($v);
  334. }
  335. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  336. }
  337. }
  338. //笛卡儿积
  339. function cp($ps,$sets,$list)
  340. {
  341. $result = array();$j=0;
  342. for($i=0,$count=count($sets); $i<$count-1; $i++)
  343. {
  344. if($i==0)
  345. {
  346. $result = $sets[$i];
  347. }
  348. $tmp = array();
  349. foreach($result as $res)
  350. {
  351. foreach($sets[$i+1] as $set)
  352. {
  353. $tmp[] = $res.','.$set;
  354. }
  355. }
  356. $result = $tmp;
  357. }
  358. $this->db->trans_begin();
  359. foreach ($result as $v)
  360. {
  361. $post = array();$title = "";$num="";
  362. $data = explode(',',$v);
  363. for($i=0;$i<count($list); $i++)
  364. {
  365. $post[$list[$i]] = $data[$i];
  366. $typeclass = $this->typeclass->read($data[$i]);
  367. $title = $title.$typeclass['title']." ";
  368. if($data[$i] != 0)
  369. {
  370. $num .=$data[$i];//所有数据ID拼接
  371. }
  372. }
  373. foreach ($ps as $kp=>$vp)
  374. {
  375. $post[$kp] = $vp;
  376. }
  377. $post['number'] = $num;
  378. $info_list = $this->weight->get_number($num);//查询weight是否存在此拼接的数据ID
  379. if($info_list)
  380. {
  381. $j++;
  382. }
  383. else
  384. {
  385. $skunum = $this->weight->find_count();
  386. $post['sku'] = 'LY'.substr(strval($skunum+1+10000000),1,7);
  387. $post['title'] = rtrim($title,' ');
  388. $this->weight->insert($post);
  389. }
  390. }
  391. if ($this->db->trans_status() === FALSE)
  392. {
  393. $this->db->trans_commit();
  394. return NULL;
  395. }
  396. else
  397. {
  398. $this->db->trans_commit();
  399. return $j;
  400. }
  401. }
  402. public function _weight()
  403. {
  404. $post = $this->input->post(NULL, TRUE);
  405. if(isset($post['data']))
  406. {
  407. $data = $this->input->post('data');
  408. $list = explode('-',rtrim($data,'-'));
  409. $weight = '';$lssku = '';$sku = array();
  410. $weightdata = $this->weight->find_all();
  411. foreach ($weightdata as $w)
  412. {
  413. $sku[$w['sku']] = $w['weight'];
  414. }
  415. if(stripos($data,'126') !== false && isset($sku['126']))
  416. {
  417. $weight = $sku['126'];
  418. }
  419. else if(stripos($data,'127') !== false)
  420. {
  421. if(isset($list[8]))
  422. {
  423. $sku127a = $list[0].'-'.$list[2].'-'.$list[4].'-'.$list[5].'-'.$list[8];
  424. $sku127b = $list[0].'-'.$list[4].'-'.$list[5].'-'.$list[8];
  425. if(isset($sku[$sku127a]))
  426. {
  427. $weight = $sku[$sku127a];
  428. }
  429. else if(isset($sku[$sku127b]))
  430. {
  431. $weight = $sku[$sku127b];
  432. }
  433. else
  434. {
  435. $weight = 0;
  436. }
  437. }
  438. }
  439. else if(stripos($data,'128') !== false)
  440. {
  441. $sku128 = $list[0].'-'.$list[4].'-'.$list[5].'-'.$list[7];
  442. if(isset($sku[$sku128]))
  443. {
  444. $weight = $sku[$sku128];
  445. }
  446. else
  447. {
  448. $weight = 0;
  449. }
  450. }
  451. else if(stripos($data,'130') !== false || stripos($data,'133') !== false)
  452. {
  453. $sku130 = $list[0].'-'.$list[5].'-'.$list[4];
  454. if(isset($sku[$sku130]))
  455. {
  456. $weight = $sku[$sku130];
  457. }
  458. else
  459. {
  460. $weight = 0;
  461. }
  462. }
  463. else
  464. {
  465. $weight = 0;
  466. }
  467. echo json_encode(array('weight'=>$weight,'success'=>true));
  468. }
  469. }
  470. public function _cx()
  471. {
  472. $post = $this->input->post(NULL, TRUE);
  473. if(isset($post['data']))
  474. {
  475. $weight = 0;
  476. $list = $this->input->post('data');
  477. $list = '-'.$list;
  478. $listarray = explode('-',trim($list,'-'));
  479. $tc = array();
  480. $typeclass = $this->typeclass->find_all();
  481. foreach ($typeclass as $v)
  482. {
  483. $tc[$v['id']] = $v;
  484. }
  485. $listarray = array_filter($listarray);
  486. $ttpx = array('128'=>'','18'=>'','14'=>'','10'=>'');
  487. $features = '';
  488. if(stripos($list,'-126-') !== false)
  489. {
  490. $features = $listarray[0];
  491. }
  492. else if(stripos($list,'-127-') !== false)
  493. {
  494. $features = $listarray[0].'-'.$listarray[8].'-'.$listarray[4];
  495. }
  496. else if(stripos($list,'-128-') !== false)
  497. {
  498. foreach ($listarray as $v)
  499. {
  500. if(isset($tc[$v]) && isset($ttpx[$tc[$v]['classid']]))
  501. {
  502. $ttpx[$tc[$v]['classid']] = $v;
  503. }
  504. }
  505. $features = '128'.implode("-",$ttpx);
  506. }
  507. else if(stripos($list,'-130-') !== false || stripos($list,'-133-') !== false)
  508. {
  509. $features = $listarray[0].'-'.$listarray[5].'-'.(isset($listarray[4])?$listarray[4]:'');
  510. }
  511. $data = $this->weight->get_features($features);
  512. if($data)
  513. {
  514. $weight = $data['weight'];
  515. }
  516. echo json_encode(array('weight'=>$weight,'success'=>true));
  517. }
  518. }
  519. public function _excel()
  520. {
  521. if(isset($_GET['excel']))
  522. {
  523. $where = "1=1";
  524. $features = $this->input->get('category',true);
  525. $sku = $this->input->get('sku',true);
  526. $title = $this->input->get('title',true);
  527. if($sku)
  528. {
  529. $where .= " and sku like '%$sku%'";
  530. }
  531. if($title)
  532. {
  533. $where .= " and title like '%$title%'";
  534. }
  535. if($features)
  536. {
  537. $where .= " and features like '%$features%'";
  538. }
  539. $order_str = "id asc";
  540. $list = array();
  541. $rows = $this->weight->find_all($where,'title,sku,weight');
  542. $title = "产品重量";
  543. $titlename = "<table border=1>
  544. <tr align='center'>
  545. <td>产品名称</td>
  546. <td>sku</td>
  547. <td>重量</td>
  548. </tr>
  549. </table>";
  550. $filename = $title.".xls";
  551. $tail = "";
  552. $this->excel->get_fz2($rows,$titlename,$filename,$tail);
  553. }
  554. }
  555. public function _mb()
  556. {
  557. $list = array();
  558. $rows = array();
  559. $title = "导入模板";
  560. $titlename = "<table border=1>
  561. <tr align='center'>
  562. <td>标签sku</td>
  563. <td>重量</td>
  564. </tr>
  565. </table>";
  566. $filename = $title.".xls";
  567. $tail = "";
  568. $this->excel->get_fz2($rows,$titlename,$filename,$tail);
  569. }
  570. public function _drexcel($arg_array)
  571. {
  572. $dir = '/data/excel/'.date('Ymd',time()).'/';
  573. $config['upload_path'] = '.'.$dir ;
  574. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  575. $config['allowed_types'] = 'xls|xlsx|csv';
  576. $config['max_size'] = 10240;
  577. $this->load->library('upload', $config);
  578. $this->upload->initialize($config);
  579. if ($this->upload->do_upload('userfile'))
  580. {
  581. $full_path = $dir.$this->upload->data('file_name');
  582. $fileName = '.' . $full_path;
  583. if (!file_exists($fileName))
  584. {
  585. echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
  586. }
  587. else
  588. {
  589. libxml_use_internal_errors(true);
  590. require_once "./data/excel/PHPExcel/IOFactory.php";
  591. $phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
  592. $phpExcel->setActiveSheetIndex(0);// 设置为默认表
  593. $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
  594. $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
  595. $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
  596. ++$column;//如果列数大于26行
  597. $list = array();
  598. for ($i = 2; $i <= $row; $i++) // 行数循环
  599. {
  600. $data = array();
  601. for ($c = 'A'; $c != $column; $c++) // 列数循环
  602. {
  603. $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
  604. }
  605. $list[] = $data;
  606. }
  607. }
  608. $i = 0;$j = 0;$ed = array();
  609. foreach ($list as $key=>$value)
  610. {
  611. $tc = 0;
  612. $i = $key+1;
  613. $time = time();
  614. $post['sku'] = $value['0'];//SKU
  615. $post['weight'] = $value['1'];//重量
  616. $post['features'] = $arg_array[0].'-';
  617. $post['title'] = $arg_array[1].' ';
  618. $post['title'] = str_replace('%20',' ',$post['title']);
  619. $s = $this->weight->get_sku($post['sku']);
  620. if($s)
  621. {
  622. $ed[] = array($i.'行 - '.$value['0'].' - 此信息已存在!');
  623. $j++;
  624. continue;
  625. }
  626. $features = explode('-',trim($post['sku'],'-'));
  627. foreach ($features as $k=>$v)
  628. {
  629. /**
  630. if($k > 0 && is_numeric($v))
  631. {
  632. $v = $v.'inch';
  633. }
  634. **/
  635. $title = $this->typeclass->get_bq_sku($v);
  636. if(isset($title['id']))
  637. {
  638. $post['features'] .= $title['id'].'-';
  639. $post['title'] .= $v.' ';
  640. }
  641. else
  642. {
  643. $ed[] = array($i.'行 - '.$value['0'].' - 字典库中不存在此名称!');
  644. $j++;
  645. $tc = 1;
  646. break(1);
  647. }
  648. }
  649. if($tc == 1)
  650. {
  651. continue;
  652. }
  653. $post['title'] = trim($post['title'],' ');
  654. $post['title'] = str_replace('Hair Weaving-','',$post['title']);
  655. $post['features'] = trim($post['features'],'-');
  656. $f = $this->weight->get_features($post['features']);
  657. if($f)
  658. {
  659. $ed[] = array($i.'行 - '.$value['0'].' - 此信息已存在!');
  660. $j++;
  661. continue;
  662. }
  663. $this->weight->insert($post);
  664. }
  665. if($j > 0)
  666. {
  667. $tt = date('Ymd',time());
  668. $title = '导入错误信息-'.$tt;
  669. $titlename = "<table border=1><tr><td>错误详情</td></tr></table>";
  670. $tail = "\n";
  671. $filename = $title.".xls";
  672. $ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);
  673. $dir = '/data/excel/'.$time.'/';
  674. $file_name = 'error_'.$time.rand(1000,9999);
  675. if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);
  676. $myfile = fopen(".".$dir.$file_name.".xls", "w") or die();
  677. fwrite($myfile,$ecl);
  678. fclose($myfile);
  679. $error = $dir.$file_name.'.xls';
  680. echo json_encode(array('msg'=>'导入成功,'.$j.'条异常,','error'=>$error,'success'=>true));exit;
  681. }
  682. else
  683. {
  684. echo json_encode(array('msg'=>'导入成功!','error'=>1,'success'=>true));exit;
  685. }
  686. }
  687. }
  688. }