Weight.php 21 KB

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