Weight.php 21 KB

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