Weight.php 21 KB

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