Weight.php 21 KB

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