Commodity.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Commodity extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_commodity','commodity');
  7. $this->load->_model('Model_commodityread','commodityread');
  8. $this->load->_model('Model_shop','shop');
  9. $this->load->_model('Model_apismt','apismt');
  10. $this->load->_model('Model_typeclass','typeclass');
  11. $this->load->_model('Model_commodityread_del','commodityreaddel');
  12. $this->load->_model('Model_classid','classid');
  13. $this->load->_model("Model_logic_u9tools","logic_u9tools");
  14. }
  15. //定义方法的调用规则 获取URI第二段值
  16. public function _remap($arg,$arg_array)
  17. {
  18. if($arg == 'aeorder')//同步
  19. {
  20. $this->_aeorder();
  21. }
  22. else if($arg == 'edit')//修改
  23. {
  24. $this->_edit($arg_array);
  25. }
  26. else if($arg == 'batchedit')//批量修改
  27. {
  28. $this->_batchedit();
  29. }
  30. else if($arg == 'skuedit')//修改
  31. {
  32. $this->_skuedit($arg_array);
  33. }
  34. else if($arg == 'excel_export'){
  35. $this->_excel_export();
  36. }
  37. else
  38. {
  39. $this->_index();
  40. }
  41. }
  42. //管理
  43. public function _index()
  44. {
  45. $dt = 0;
  46. if(isset($_SESSION['api']))
  47. {
  48. $user = $this->user->get_api($_SESSION['api']);
  49. $usp = $user;
  50. $fgshop = "";$sid = "";
  51. $usersp = explode('|',trim($user['shop'],'|'));
  52. foreach ($usersp as $value)
  53. {
  54. $fgshop .= " shop = ".$value." or";
  55. $sid .= " id = ".$value." or";
  56. }
  57. }
  58. $post = $this->input->post(NULL, TRUE);
  59. if(isset($post['page']))
  60. {
  61. $page = $this->input->post('page',true);
  62. $perpage = $this->input->post('perpage',true);
  63. $shop = $this->input->post('shop',true);
  64. $productid = $this->input->post('productid',true);
  65. $title = $this->input->post('title',true);
  66. $type = $this->input->post('type',true);
  67. $code = $this->input->post('code',true);
  68. $skuid = $this->input->post('skuid',true);
  69. $category = $this->input->post('category',true);
  70. $categorytypeclass = $this->typeclass->get_titleclassid($category,16);
  71. $where = "1=1 and (".rtrim($fgshop,'or').")";
  72. if($shop)
  73. {
  74. $where .= " and shop = '$shop'";
  75. }
  76. if($productid)
  77. {
  78. $where .= " and productid = '$productid'";
  79. }
  80. if($title)
  81. {
  82. $where .= " and title like '%$title%'";
  83. }
  84. if($type)
  85. {
  86. $where .= " and type = '$type'";
  87. }
  88. if($category)
  89. {
  90. $where .= " and category like '%".$categorytypeclass['id']."%'";
  91. }
  92. if($code)
  93. {
  94. $u = $this->commodityread->get_sku($code);
  95. $u = $u['productid'];
  96. $where .= " and productid = '$u'";
  97. }
  98. if($skuid)
  99. {
  100. $u = $this->commodityread->get_skuid($skuid);
  101. $u = $u['productid'];
  102. $where .= " and productid = '$u'";
  103. }
  104. //数据排序
  105. $order_str = "time desc";
  106. if(empty($page))
  107. {
  108. $start = 0;
  109. $perpage = 1;
  110. }
  111. else
  112. {
  113. $start = ($page - 1)*$perpage;
  114. }
  115. //取得信息列表
  116. $info_list = $this->commodity->find_all($where,'id,shop,productid,img,title,category,time',$order_str,$start,$perpage);
  117. //格式化数据
  118. foreach ($info_list as $key=>$v)
  119. {
  120. $shop = $this->shop->read($v['shop']);
  121. $info_list[$key]['shop'] = $shop['shopname'];
  122. $info_list[$key]['img'] = "<img src='".$v['img']."' style='height:55px' />";
  123. $category = '';
  124. if($v['category'])
  125. {
  126. $v['category'] = explode(',',trim($v['category'],','));
  127. foreach ($v['category'] as $vv)
  128. {
  129. $typeclass = $this->typeclass->read($vv);
  130. $category .= "<p>".$typeclass['title']."</p>";
  131. }
  132. $info_list[$key]['category'] = $category;
  133. }
  134. else
  135. {
  136. $info_list[$key]['category'] = '';
  137. }
  138. $info_list[$key]['time'] = "<p><a href='http://posting.aliexpress.com/wsproduct/edit_wholesale_product.htm?product_id=".$v['productid']."' target='_blank'>编辑</a></p><p><a href='http://www.aliexpress.com/item/".$v['productid'].".html' target='_blank'>浏览</a></p>";
  139. }
  140. $total = $this->commodity->find_count($where);
  141. $pagenum = ceil($total/$perpage);
  142. $over = $total-($start+$perpage);
  143. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  144. echo json_encode($rows);exit;
  145. }
  146. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  147. $this->data['wlshop'] = $wlshop;
  148. $this->_Template('commodity',$this->data);
  149. }
  150. //修改
  151. public function _edit($arg_array)
  152. {
  153. $post = $this->input->post(NULL, TRUE);
  154. if(isset($post['id']))
  155. {
  156. $id = $this->input->post('id',true);
  157. $category = $this->input->post('category',true);
  158. $data = $this->input->post('data');
  159. if($data)
  160. {
  161. $data = explode('|',rtrim($data,'|'));
  162. foreach ($data as $v)
  163. {
  164. $d = explode('@',$v);
  165. $this->commodityread->save(array('sku'=>$d[1]),$d[0]);
  166. }
  167. }
  168. if($this->commodity->save(array('category'=>','.$category),$id))
  169. {
  170. echo json_encode(array('msg'=>'操作成功','success'=>true));exit;
  171. }
  172. else
  173. {
  174. echo json_encode(array('msg'=>'操作失败,请重试','success'=>false));exit;
  175. }
  176. }
  177. $arg_array = $arg_array[0];
  178. $commodity = $this->commodity->read($arg_array);
  179. $this->data['commodity'] = $commodity;
  180. $sku = $this->commodityread->find_all('productid = '.$commodity['productid']);
  181. $this->data['sku'] = $sku;
  182. $this->_Template('commodity_edit',$this->data);
  183. }
  184. public function _batchedit_b()//老系统形式,保留,不用
  185. {
  186. $dictionaries = $this->typeclass->find_all('ae!= "" and (classid=13 or classid=22 or classid=8 or classid=15 or classid=27 or classid=25 or classid=26 or classid=18 or classid=14 or classid=9 or classid=12 or classid=10 or classid=6)'); //产品人发类型颜色
  187. $dtc = array();$ctd = array();
  188. foreach ($dictionaries as $v)
  189. {
  190. if(stripos($v['spare'],'|') !== false)//如果有多个值
  191. {
  192. $v['spare'] = explode('|',$v['spare']);
  193. foreach ($v['spare'] as $vs)
  194. {
  195. $dtc[strtolower($vs)] = array('classid'=>$v['classid'],'title'=>$v['title'],'id'=>$v['id']);
  196. }
  197. }
  198. else
  199. {
  200. $dtc[strtolower($v['spare'])] = array('classid'=>$v['classid'],'title'=>$v['title'],'id'=>$v['id']);
  201. }
  202. $ctd[$v['id']] = $v['title'];
  203. }
  204. $ctd[126] = 'Hair Weaving';
  205. $ctd[127] = 'Closure';
  206. $ctd[128] = 'Wigs';
  207. $ctd[130] = 'Clip-in Full Head';
  208. $post = $this->input->post(NULL, TRUE);
  209. if(isset($post['id']))
  210. {
  211. $id = $this->input->post('id',true);
  212. $ndata = $this->input->post('data',true);
  213. $id = explode(',',rtrim($id,','));
  214. $data = explode('-',rtrim($ndata,'-'));
  215. $rows = array();
  216. foreach ($id as $val)
  217. {
  218. //a:颜色 b:密度 c:头路设计
  219. $u = $this->commodityread->read($val);
  220. $u['codeid'] = strtolower($u['codeid']);
  221. $u['codeid'] = str_replace(array('stretched length','inches','& '),array('length','',''),$u['codeid']);
  222. $sku = explode(';',rtrim($u['codeid'],';'));
  223. $codeid = array();$whlabel = ''; $fpdata = '';
  224. foreach ($sku as $v)
  225. {
  226. $va = explode(':',$v);
  227. $codeid[$va[0]] = $va[1];
  228. }
  229. $num = '';$ti = '';$tit = '';$error = '';$i = 1;
  230. foreach ($data as $k=>$v)
  231. {
  232. if($v == 'a')
  233. {
  234. if(isset($codeid['color']) && isset($dtc[$codeid['color']]))
  235. {
  236. $num .= $dtc[$codeid['color']]['id'].'-';
  237. $ti .= $dtc[$codeid['color']]['title'].' ';
  238. }
  239. else
  240. {
  241. $num .= '57-';
  242. $ti .= 'Natural Black ';
  243. }
  244. }
  245. else if($v == 'b')
  246. {
  247. if(isset($codeid['density']) && isset($dtc[$codeid['density']]))
  248. {
  249. $num .= $dtc[$codeid['density']]['id'].'-';
  250. $ti .= $dtc[$codeid['density']]['title'].' ';
  251. }
  252. else
  253. {
  254. $num .= '71-';
  255. $ti .= '150% ';
  256. }
  257. }
  258. else if($v == 'c')
  259. {
  260. if(isset($codeid['part design']) && isset($dtc[$codeid['part design']]))
  261. {
  262. $num .= $dtc[$codeid['part design']]['id'].'-';
  263. $ti .= $dtc[$codeid['part design']]['title'].' ';
  264. }
  265. else
  266. {
  267. $num .= '75-';
  268. $ti .= 'Free Part ';
  269. }
  270. }
  271. else
  272. {
  273. if($i == 2)
  274. {
  275. $num .= $v.'-id-';
  276. }
  277. else
  278. {
  279. $num .= $v.'-';
  280. }
  281. $ti .= $ctd[$v].' ';
  282. }
  283. $i++;
  284. }
  285. if(stripos($codeid['length'],'closure') !== false && stripos($ndata,'127') !== false)
  286. {
  287. $v = preg_replace(array('/([\s\S]*)closure/','/([\s\S]*)closure\s/'),array('',''),$codeid['length']);
  288. $v = preg_replace('/([\s]*)/','',$v);
  289. $fpdata = $dtc[$v]['id'].',-'.str_replace('id-','',$num).'|'.$ti.$v.'inch |1|0.00|0.00|'.$v.'|0.00|0.00;';
  290. $tit = '<p>'.$ti.$v.'inch</p>';
  291. $whlabel = '|'.str_replace(array('-','id'),array('',$dtc[$v]['id']),$num).'-1';
  292. }
  293. else
  294. {
  295. $codeid['length'] = explode(' ',$codeid['length']);
  296. foreach ($codeid['length'] as $v)
  297. {
  298. if(is_numeric($v))
  299. {
  300. $fpdata .= $dtc[$v]['id'].',-'.str_replace('id-','',$num).'|'.$ti.$v.'inch |1|0.00|0.00|'.$v.'|0.00|0.00;';
  301. $tit .= '<p>'.$ti.$v.'inch</p>';
  302. $whlabel .= '|'.str_replace(array('-','id'),array('',$dtc[$v]['id']),$num).'-1';
  303. }
  304. else
  305. {
  306. break;
  307. }
  308. }
  309. }
  310. $fa = '';$wl = '';
  311. $u['fpdata'] = explode(';',rtrim($u['fpdata'],';'));
  312. $u['whlabel'] = explode('|',trim($u['whlabel'],'|'));
  313. for($i=0;$i<count($u['fpdata']);$i++)
  314. {
  315. if(stripos($u['fpdata'][$i],$data[0]) === false)
  316. {
  317. if($u['fpdata'][$i] != '')
  318. {
  319. $fa .= $u['fpdata'][$i].';';
  320. $te = explode('|',$u['fpdata'][$i]);
  321. $tit .= '<p>'.$te[1].'</p>';
  322. }
  323. }
  324. if(stripos($u['whlabel'][$i],$data[0]) === false)
  325. {
  326. if($u['whlabel'][$i] != '')
  327. {
  328. $wl .= '|'.$u['whlabel'][$i];
  329. }
  330. }
  331. }
  332. $this->commodityread->save(array('fpdata'=>$fa.$fpdata,'whlabel'=>$wl.$whlabel.'|'),$val);
  333. $rows[] = array('id'=>$val,'title'=>$tit);
  334. }
  335. echo json_encode(array('rows'=>$rows,'success'=>true));exit;
  336. }
  337. }
  338. public function _skuedit($arg_array)
  339. {
  340. $post = $this->input->post(NULL, TRUE);
  341. if(isset($post['id']))
  342. {
  343. $id = $this->input->post('id',true);
  344. $post['fpdata'] = $this->input->post('fpdata',true);
  345. $post['whlabel'] = $this->input->post('whlabel',true);
  346. if($this->commodityread->save($post,$id))
  347. {
  348. echo json_encode(array('msg'=>'操作成功','success'=>true));exit;
  349. }
  350. else
  351. {
  352. echo json_encode(array('msg'=>'操作失败,请重试','success'=>false));exit;
  353. }
  354. }
  355. $arg_array = $arg_array[0];$fpdata = array();
  356. $commodityread = $this->commodityread->read($arg_array);
  357. if(stripos($commodityread['fpdata'],';') !== false)
  358. {
  359. $fpdata = explode(';',rtrim($commodityread['fpdata'],';'));
  360. foreach ($fpdata as $k=>$v)
  361. {
  362. $fpdata[$k] = explode('|',$v);
  363. }
  364. }
  365. $this->data['fpdata'] = $fpdata;
  366. $this->data['commodityread'] = $commodityread;
  367. $this->_Template('commodityread_edit',$this->data);
  368. }
  369. //获取
  370. public function _aeorder()
  371. {
  372. $sid = '';
  373. if(isset($_SESSION['api']))
  374. {
  375. $user = $this->user->get_api($_SESSION['api']);
  376. $user = explode('|',trim($user['shop'],'|'));
  377. foreach ($user as $value)
  378. {
  379. $sid .= " id = '$value' or";
  380. }
  381. $sid = " and (".rtrim($sid,'or').")";
  382. }
  383. $post = $this->input->post(NULL, TRUE);
  384. if($sid)
  385. {
  386. $shop = $this->shop->find_all("code != '' and type = '270'".$sid);//获取店铺信息
  387. foreach ($shop as $value)
  388. {
  389. $res = array();
  390. for($x=1;$x<5;$x++)
  391. {
  392. $resi = $this->apismt->get_commoditylist($x,100,$value['code']);//获取商品列表
  393. if($resi)
  394. {
  395. $res += $resi;
  396. }
  397. }
  398. if($res)
  399. {
  400. $yzpid = $this->commodity->find_all('shop = '.$value['id']);
  401. foreach ($yzpid as $v)
  402. {
  403. if($v['productid'] == '' || $v['productid'] == '0')
  404. {
  405. $this->commodity->remove($v['id']);
  406. continue;
  407. }
  408. if(!isset($res[$v['productid']]))
  409. {
  410. $this->commodity->save(array('type'=>'offline'),$v['id']);
  411. }
  412. }
  413. foreach ($res as $v)
  414. {
  415. $productid = $this->commodity->get_productid($v);
  416. //if(!$productid)
  417. //{
  418. @$read = $this->apismt->get_commodityread($v,$value['code']);
  419. if(is_array($read))
  420. {
  421. @$cid = $this->apismt->get_commoditysku($read['cid'],$value['code']);
  422. }
  423. else
  424. {
  425. continue;
  426. }
  427. //处理结束
  428. if(isset($cid[0]))
  429. {
  430. // 处理 $cid
  431. $cc = array();
  432. foreach ($cid as $c)
  433. {
  434. $names = json_decode($c['names'],true);
  435. $cc[$c['id']] = $names['en'];
  436. if(!isset($c['values']))
  437. {
  438. continue;
  439. }
  440. if(isset($c['values']['aeop_attr_value_dto'][0]))
  441. {
  442. foreach ($c['values']['aeop_attr_value_dto'] as $cv)
  443. {
  444. if(isset($read['gg'][$cv['id']]))//如果有自定义
  445. {
  446. $cc[$cv['id']] = $read['gg'][$cv['id']];
  447. }
  448. else
  449. {
  450. $cnames = json_decode($cv['names'],true);
  451. $cc[$cv['id']] = $cnames['en'];
  452. }
  453. }
  454. }
  455. else
  456. {
  457. $cnames = json_decode($c['values']['aeop_attr_value_dto']['names'],true);
  458. $cc[$c['values']['aeop_attr_value_dto']['id']] = $cnames['en'];
  459. }
  460. }
  461. $read['title'] = ($read['title'])?$read['title']:'';
  462. if(!$productid)
  463. {
  464. //处理结束
  465. $this->commodity->insert(array('shop'=>$value['id'],'productid'=>$v,'title'=>$read['title'],'img'=>$read['img'],'type'=>$read['type'],'time'=>time()));
  466. }
  467. else
  468. {
  469. $this->commodity->save(array('shop'=>$value['id'],'productid'=>$read['productid'],'title'=>$read['title'],'img'=>$read['img'],'type'=>$read['type']),$productid['id']);
  470. }
  471. $this->_aeordersku($read['sku'],$value['id'],$v,$cc);
  472. }
  473. //}
  474. }
  475. }
  476. else
  477. {
  478. continue;
  479. }
  480. }
  481. echo json_encode(array('msg'=>'同步完成!','success'=>true));exit;
  482. }
  483. }
  484. public function _aeordersku($sku,$shop,$productid,$cc)
  485. {
  486. $yzsku = $this->commodityread->find_all("productid = '$productid'");
  487. foreach ($yzsku as $v)
  488. {
  489. $s = 0;
  490. if(!isset($sku[$v['skuid']]))
  491. {
  492. $skuid = explode(';',$v['skuid']);
  493. if(count($skuid) < 2)
  494. {
  495. $this->commodityreaddel->insert($v);
  496. $this->commodityread->remove($v['id']);//asd
  497. continue;
  498. }
  499. else
  500. {
  501. $skuidarray = $this->_qpl($skuid);
  502. foreach ($skuidarray as $skuv)
  503. {
  504. if(isset($sku[$skuv]))
  505. {
  506. $this->commodityread->save(array('skuid'=>$skuv),$v['id']);
  507. $s++;
  508. break 1;
  509. }
  510. }
  511. }
  512. if($s < 1)
  513. {
  514. $this->commodityreaddel->insert($v);
  515. $this->commodityread->remove($v['id']);//asd
  516. }
  517. }
  518. }
  519. foreach ($sku as $v)
  520. {
  521. $read = $this->commodityread->get_productid($productid,$v['skuid']);
  522. if(isset($read['productid']))
  523. {
  524. $cd = explode(';',$v['skuid']);$cod = '';
  525. foreach ($cd as $vv)
  526. {
  527. $cv = explode(':',$vv);
  528. $cod .=$cc[$cv[0]].":".$cc[$cv[1]].";";
  529. }
  530. $this->commodityread->save(array('shop'=>$shop,'productid'=>$productid,'codeid'=>$cod,'skuid'=>$v['skuid'],'code'=>$v['code'],'time'=>time()),$read['id']);
  531. }
  532. else
  533. {
  534. $cd = explode(';',$v['skuid']);$cod = '';
  535. foreach ($cd as $vv)
  536. {
  537. $cv = explode(':',$vv);
  538. $cod .=$cc[$cv[0]].":".$cc[$cv[1]].";";
  539. }
  540. $this->commodityread->insert(array('shop'=>$shop,'productid'=>$productid,'codeid'=>$cod,'skuid'=>$v['skuid'],'code'=>$v['code'],'time'=>time()));
  541. }
  542. }
  543. }
  544. public function _qpl($source)//全排列
  545. {
  546. $qpl = array();
  547. sort($source); //保证初始数组是有序的
  548. $last = count($source) - 1; //$source尾部元素下标
  549. $x = $last;
  550. $count = 1; //组合个数统计
  551. $qpl[implode(';', $source)] = implode(';', $source); //输出第一种组合
  552. while (true)
  553. {
  554. $y = $x--; //相邻的两个元素
  555. if ($source[$x] < $source[$y])//如果前一个元素的值小于后一个元素的值
  556. {
  557. $z = $last;
  558. while ($source[$x] > $source[$z]) //从尾部开始,找到第一个大于 $x 元素的值
  559. {
  560. $z--;
  561. }
  562. /* 交换 $x 和 $z 元素的值 */
  563. list($source[$x], $source[$z]) = array($source[$z], $source[$x]);
  564. /* 将 $y 之后的元素全部逆向排列 */
  565. for ($i = $last; $i > $y; $i--, $y++)
  566. {
  567. list($source[$i], $source[$y]) = array($source[$y], $source[$i]);
  568. }
  569. $qpl[implode(';', $source)] = implode(';', $source); //输出组合
  570. $x = $last;
  571. $count++;
  572. }
  573. if ($x == 0)//全部组合完毕
  574. {
  575. break;
  576. }
  577. }
  578. return $qpl;
  579. }
  580. public function _skudelhf($a)//commodityread 同步删除的恢复
  581. {
  582. $this->db->trans_begin();
  583. $qbpid = array();
  584. $a = $this->commodityread->find_all("time > '1653613200'");
  585. foreach ($a as $v)
  586. {
  587. $qbpid[$v['productid']] = $v['productid'];
  588. }
  589. foreach ($qbpid as $valer)
  590. {
  591. $del = $this->commodityreaddel->find_all("productid = '".$valer."' and sku != ''",'*','id asc');
  592. if($del)
  593. {
  594. foreach ($del as $val)
  595. {
  596. $skuid = explode(';',$val['skuid']);
  597. if(count($skuid) < 2)
  598. {
  599. continue;
  600. }
  601. $skuidarray = $this->_qpl($skuid);
  602. $red = $this->commodityread->find_all("productid = '".$val['productid']."' and sku = ''");
  603. foreach ($red as $v)
  604. {
  605. if(isset($skuidarray[$v['skuid']]))
  606. {
  607. $this->commodityread->save(array('sku'=>$val['sku']),$v['id']);
  608. }
  609. }
  610. }
  611. }
  612. }
  613. if ($this->db->trans_status() === TRUE)
  614. {
  615. $this->db->trans_commit();
  616. echo 1;
  617. }
  618. else
  619. {
  620. $this->db->trans_rollback();
  621. echo 2;
  622. }
  623. }
  624. public function _excel_export(){
  625. if(isset($_SESSION['api']))
  626. {
  627. $user = $this->user->get_api($_SESSION['api']);
  628. $usp = $user;
  629. $fgshop = "";$sid = "";
  630. $usersp = explode('|',trim($user['shop'],'|'));
  631. foreach ($usersp as $value)
  632. {
  633. $fgshop .= " shop = ".$value." or";
  634. $sid .= " id = ".$value." or";
  635. }
  636. }
  637. $params = $this->input->get(NULL, TRUE);
  638. if(isset($params['excel']) && $params['excel'] == 1){
  639. $shop = $this->input->get('shop',true);
  640. $productid = $this->input->get('productid',true);
  641. $title = $this->input->get('title',true);
  642. $type = $this->input->get('type',true);
  643. $code = $this->input->get('code',true);
  644. $skuid = $this->input->get('skuid',true);
  645. $category = $this->input->get('category',true);
  646. $categorytypeclass = $this->typeclass->get_titleclassid($category,16);
  647. $where = "1=1 and (".rtrim($fgshop,'or').")";
  648. if($shop)
  649. {
  650. $where .= " and shop = '$shop'";
  651. }
  652. if($productid)
  653. {
  654. $where .= " and productid = '$productid'";
  655. }
  656. if($title)
  657. {
  658. $where .= " and title like '%$title%'";
  659. }
  660. if($type)
  661. {
  662. $where .= " and type = '$type'";
  663. }
  664. if($category)
  665. {
  666. $where .= " and category like '%".$categorytypeclass['id']."%'";
  667. }
  668. if($code)
  669. {
  670. $u = $this->commodityread->get_sku($code);
  671. $u = $u['productid'];
  672. $where .= " and productid = '$u'";
  673. }
  674. if($skuid)
  675. {
  676. $u = $this->commodityread->get_skuid($skuid);
  677. $u = $u['productid'];
  678. $where .= " and productid = '$u'";
  679. }
  680. //数据排序
  681. $order_str = "time desc";
  682. //取得信息列表
  683. $info_list = $this->commodity->find_all($where,'id,shop,productid,img,title,category,time',$order_str);
  684. //格式化数据
  685. $final_list = [];
  686. $shop_where = trim($sid,'or');
  687. $shop_list = $this->shop->find_all($shop_where,'id,shopname');
  688. $shop_list = array_column($shop_list,'shopname','id');
  689. $typeclass = [];
  690. $classid = $this->classid->sku();
  691. $tcall = $this->typeclass->find_all();
  692. foreach ($tcall as $v)
  693. {
  694. //$tcjm[$v['id']] = array($v['jm'],$v['classid']);
  695. $typeclass[$v['id']] = array('zh'=>$v['zh'],'classid'=>$v['classid'],'bm'=>$v['bm'],'title'=>$v['title'],'jm'=>$v['jm']);
  696. }
  697. foreach ($info_list as $key=>$v)
  698. {
  699. $shopname = isset($shop_list[$v['shop']])?$shop_list[$v['shop']]:'';
  700. $skulist = $this->commodityread->find_all("productid = ".$v['productid']);
  701. $tmp_list = [];
  702. foreach($skulist as $skv){
  703. $u9_info = $this->logic_u9tools->getOneU9bmHasGift($skv['sku'],$classid,$typeclass);
  704. echo "<pre>";
  705. print_r($u9_info);
  706. die;
  707. $tmp_list[] = [
  708. 'codeid' => $skv['codeid'],
  709. 'erp_sku' => $skv['sku'],
  710. 'jm'=>$u9_info['jm'],
  711. 'zh'=>$u9_info['zh'],
  712. ];
  713. }
  714. $tmp_codeid = "";
  715. $tmp_erp_sku = "";
  716. $tmp_jm = "";
  717. $tmp_zh = "";
  718. foreach($tmp_list as $t){
  719. $tmp_codeid .= $t['codeid']."<br>";
  720. $tmp_erp_sku .= $t['erp_sku']."<br>";
  721. $tmp_jm .= $t['jm']."<br>";
  722. $tmp_zh .= $t['zh']."<br>";
  723. }
  724. $final_list[] = [
  725. 'shopname' => $shopname,
  726. 'productid' => $v['productid'],
  727. 'codeid' => $tmp_codeid,
  728. 'erp_sku' => $tmp_erp_sku,
  729. 'jm' => $tmp_jm,
  730. 'zh' => $tmp_zh,
  731. 'title' => $v['title'],
  732. ];
  733. }
  734. //生成excel
  735. $filename = '速卖通-'.date('Ymd',time()).".xlsx";
  736. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\"><head>
  737. <!--[if gte mso 9]><xml>
  738. <x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>EXCEL</x:Name><x:WorksheetOptions><x:Print><x:ValidPrinterInfo /></x:Print></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml>
  739. <![endif]-->
  740. </head><body>";
  741. $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  742. $str .= "<tr><td>店铺名称</td><td>速卖通产品ID</td><td>速卖通品名</td><td>速卖通编码</td><td>erpSKU</td><td>用友简码</td><td>仓库品名</td></tr>";
  743. foreach ($final_list as $key=>$value)
  744. {
  745. $str .= "<tr>";
  746. $str .= "<td>". $value['shopname']. "</td>";
  747. $str .= "<td>". $value['productid']. "</td>";
  748. $str .= "<td>". $value['title']. "</td>";
  749. $str .= "<td>". $value['codeid']. "</td>";
  750. $str .= "<td>". $value['erp_sku']. "</td>";
  751. $str .= "<td>". $value['jm']. "</td>";
  752. $str .= "<td>". $value['zh']. "</td>";
  753. $str .= "</tr>";
  754. }
  755. $str .= "</table></body></html>";
  756. header( "Content-Type: application/vnd.ms-excel; name='excel'" );
  757. header( "Content-type: application/octet-stream" );
  758. header( "Content-Disposition: attachment; filename=".$filename );
  759. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  760. header( "Pragma: no-cache" );
  761. header( "Expires: 0" );
  762. exit($str);
  763. }
  764. }
  765. }