Commodity.php 24 KB

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