Weight.php 21 KB

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