| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798 | 
							- <?php defined('BASEPATH') OR exit('No direct script access allowed');
 
- class Commodity extends Start_Controller {
 
- 	public function __construct(){
 
- 		parent::__construct();
 
- 		$this->load->library('session');
 
- 		$this->load->_model('Model_commodity','commodity');
 
- 		$this->load->_model('Model_commodityread','commodityread');
 
- 		$this->load->_model('Model_shop','shop');
 
- 		$this->load->_model('Model_apismt','apismt');
 
- 		$this->load->_model('Model_typeclass','typeclass');
 
- 		$this->load->_model('Model_commodityread_del','commodityreaddel');
 
- 		$this->load->_model('Model_classid','classid');
 
- 		$this->load->_model("Model_logic_order","logic_order");
 
- 		$this->load->_model("Model_logic_ding","logic_ding");
 
- 	}
 
- 	//定义方法的调用规则 获取URI第二段值
 
-     public function _remap($arg,$arg_array)
 
-     {
 
- 		if($arg == 'aeorder')//同步
 
-         {
 
-              $this->_aeorder();
 
-         }
 
- 		else if($arg == 'edit')//修改
 
-         {
 
-              $this->_edit($arg_array);
 
-         }
 
- 		else if($arg == 'batchedit')//批量修改
 
-         {
 
-              $this->_batchedit();
 
-         }
 
- 		else if($arg == 'skuedit')//修改
 
-         {
 
-              $this->_skuedit($arg_array);
 
-         }
 
- 		else if($arg == 'excel_export'){
 
- 			$this->_excel_export();
 
- 		}
 
- 		else
 
- 		{
 
- 			 $this->_index();
 
- 		}
 
-     }
 
- 	//管理
 
- 	public function _index()
 
- 	{
 
- 		$dt = 0;
 
- 		if(isset($_SESSION['api']))
 
- 		{
 
- 			$user = $this->user->get_api($_SESSION['api']);
 
- 			$usp = $user;
 
- 		    $fgshop = "";$sid = "";
 
- 		    $usersp = explode('|',trim($user['shop'],'|'));
 
- 			foreach ($usersp as $value) 
 
- 		    {
 
- 				$fgshop .= " shop = ".$value." or";
 
- 				$sid .= " id = ".$value." or";
 
- 			}
 
- 		}
 
- 		$post = $this->input->post(NULL, TRUE);
 
- 		if(isset($post['page']))
 
- 		{
 
- 		    $page = $this->input->post('page',true);
 
- 		    $perpage = $this->input->post('perpage',true);
 
- 			$shop = $this->input->post('shop',true);
 
- 			$productid = $this->input->post('productid',true);
 
- 			$title = $this->input->post('title',true);
 
- 			$type = $this->input->post('type',true);
 
- 			$code = $this->input->post('code',true);
 
- 			$skuid = $this->input->post('skuid',true);
 
- 			$category = $this->input->post('category',true);
 
- 			$categorytypeclass =  $this->typeclass->get_titleclassid($category,16);
 
- 			$where = "1=1 and (".rtrim($fgshop,'or').")";
 
- 			if($shop)
 
-             {
 
-                 $where  .= " and shop = '$shop'";
 
-             }
 
- 			if($productid)
 
-             {
 
-                 $where  .= " and productid = '$productid'";
 
-             }
 
- 			if($title)
 
-             {
 
- 				$where  .= " and title like '%$title%'";
 
-             }
 
- 			if($type)
 
-             {
 
-                 $where  .= " and type = '$type'";
 
-             }
 
- 			if($category)
 
-             {
 
-                 $where  .= " and category like '%".$categorytypeclass['id']."%'";
 
-             }
 
- 			if($code)
 
-             {
 
- 				$u = $this->commodityread->get_sku($code);
 
- 				$u = $u['productid'];
 
-                 $where  .= " and productid = '$u'";
 
-             }
 
- 			if($skuid)
 
-             {
 
- 				$u = $this->commodityread->get_skuid($skuid);
 
- 				$u = $u['productid'];
 
-                 $where  .= " and productid = '$u'";
 
-             }
 
-             //数据排序
 
-             $order_str = "time desc";
 
-             if(empty($page))
 
- 		    {
 
-                 $start = 0;
 
- 		    	$perpage = 1;
 
-             }
 
- 		    else
 
- 		    {
 
-                 $start = ($page - 1)*$perpage;
 
-             }
 
-             //取得信息列表
 
-             $info_list = $this->commodity->find_all($where,'id,shop,productid,img,title,category,time',$order_str,$start,$perpage);
 
- 			 //格式化数据
 
-             foreach ($info_list as $key=>$v) 
 
- 		    {
 
- 				$shop = $this->shop->read($v['shop']);
 
- 				$info_list[$key]['shop'] = $shop['shopname'];
 
- 				$info_list[$key]['img'] = "<img src='".$v['img']."' style='height:55px' />";
 
- 				$category = '';
 
- 				if($v['category'])
 
- 				{
 
- 				    $v['category'] = explode(',',trim($v['category'],','));
 
- 				    foreach ($v['category'] as $vv) 
 
- 		            {
 
- 				        $typeclass = $this->typeclass->read($vv);
 
- 					    $category .= "<p>".$typeclass['title']."</p>";
 
- 				    }
 
- 				    $info_list[$key]['category'] = $category;
 
- 				}
 
- 				else
 
- 				{
 
- 					$info_list[$key]['category'] = '';
 
- 				}
 
- 				$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>";
 
- 				
 
-             }
 
- 		    $total = $this->commodity->find_count($where);
 
- 		    $pagenum = ceil($total/$perpage);
 
- 		    $over = $total-($start+$perpage);
 
- 		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
 
- 		    echo json_encode($rows);exit;
 
- 		}
 
- 		$wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
 
- 		$this->data['wlshop'] = $wlshop;
 
- 		$this->_Template('commodity',$this->data);
 
- 	}
 
- 	//修改
 
- 	public function _edit($arg_array)
 
- 	{
 
- 		$post = $this->input->post(NULL, TRUE);
 
- 		if(isset($post['id']))
 
- 		{
 
- 			$id = $this->input->post('id',true);
 
- 			$category = $this->input->post('category',true);
 
- 			$data = $this->input->post('data');
 
- 			if($data)
 
- 			{
 
- 			    $data = explode('|',rtrim($data,'|'));
 
- 			    foreach ($data as $v) 
 
- 		        {
 
- 				    $d = explode('@',$v);
 
- 				    $this->commodityread->save(array('sku'=>$d[1]),$d[0]);
 
- 			    }
 
- 			}
 
- 			if($this->commodity->save(array('category'=>','.$category),$id))
 
-         	{
 
-          		echo json_encode(array('msg'=>'操作成功','success'=>true));exit;
 
-        	 	}
 
-        		else
 
-         	{
 
-            		echo json_encode(array('msg'=>'操作失败,请重试','success'=>false));exit;
 
-         	}
 
- 		}
 
- 		$arg_array = $arg_array[0];
 
- 		$commodity = $this->commodity->read($arg_array);
 
- 		$this->data['commodity'] = $commodity;
 
- 		$sku = $this->commodityread->find_all('productid = '.$commodity['productid']);
 
- 		$this->data['sku'] = $sku;
 
- 		$this->_Template('commodity_edit',$this->data);
 
- 	}
 
- 	
 
- 	public function _batchedit_b()//老系统形式,保留,不用
 
- 	{
 
- 		$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)'); //产品人发类型颜色
 
- 		$dtc = array();$ctd = array();
 
- 		foreach ($dictionaries as $v) 
 
- 		{
 
- 			if(stripos($v['spare'],'|') !== false)//如果有多个值
 
- 			{
 
- 				$v['spare'] = explode('|',$v['spare']);
 
- 				foreach ($v['spare'] as $vs)
 
- 		        {
 
- 					$dtc[strtolower($vs)] = array('classid'=>$v['classid'],'title'=>$v['title'],'id'=>$v['id']);
 
- 				}
 
- 			}
 
- 			else
 
- 			{
 
- 				$dtc[strtolower($v['spare'])] = array('classid'=>$v['classid'],'title'=>$v['title'],'id'=>$v['id']);
 
- 			}
 
- 			$ctd[$v['id']] = $v['title'];
 
- 		}
 
- 		$ctd[126] = 'Hair Weaving';
 
- 		$ctd[127] = 'Closure';
 
- 		$ctd[128] = 'Wigs';
 
- 		$ctd[130] = 'Clip-in Full Head';
 
- 		$post = $this->input->post(NULL, TRUE);
 
- 		if(isset($post['id']))
 
- 		{
 
- 			$id = $this->input->post('id',true);
 
- 			$ndata = $this->input->post('data',true);
 
- 			$id = explode(',',rtrim($id,','));
 
- 			$data = explode('-',rtrim($ndata,'-'));
 
- 			$rows = array();
 
- 			foreach ($id as $val) 
 
- 		    {
 
- 				//a:颜色 b:密度 c:头路设计
 
- 			    $u = $this->commodityread->read($val);
 
- 				$u['codeid'] = strtolower($u['codeid']);
 
- 				$u['codeid'] = str_replace(array('stretched length','inches','& '),array('length','',''),$u['codeid']);
 
- 				$sku = explode(';',rtrim($u['codeid'],';'));
 
- 				$codeid = array();$whlabel = ''; $fpdata = '';
 
- 				foreach ($sku as $v)
 
- 		        {
 
- 					$va = explode(':',$v);
 
- 					$codeid[$va[0]] = $va[1];
 
- 				}
 
- 				$num = '';$ti = '';$tit = '';$error = '';$i = 1;
 
- 				foreach ($data as $k=>$v) 
 
- 		        {
 
- 					if($v == 'a')
 
- 					{
 
- 						if(isset($codeid['color']) && isset($dtc[$codeid['color']]))
 
- 						{
 
- 						    $num .= $dtc[$codeid['color']]['id'].'-';
 
- 							$ti .= $dtc[$codeid['color']]['title'].' ';
 
- 						}
 
- 						else
 
- 						{
 
- 							$num .= '57-';
 
- 							$ti .= 'Natural Black ';
 
- 						}
 
- 					}
 
- 					else if($v == 'b')
 
- 					{
 
- 						if(isset($codeid['density']) && isset($dtc[$codeid['density']]))
 
- 						{
 
- 						    $num .= $dtc[$codeid['density']]['id'].'-';
 
- 							$ti .= $dtc[$codeid['density']]['title'].' ';
 
- 						}
 
- 						else
 
- 						{
 
- 							$num .= '71-';
 
- 							$ti .= '150% ';
 
- 						}
 
- 					}
 
- 					else if($v == 'c')
 
- 					{
 
- 						if(isset($codeid['part design']) && isset($dtc[$codeid['part design']]))
 
- 						{
 
- 						    $num .= $dtc[$codeid['part design']]['id'].'-';
 
- 							$ti .= $dtc[$codeid['part design']]['title'].' ';
 
- 						}
 
- 						else
 
- 						{
 
- 							$num .= '75-';
 
- 							$ti .= 'Free Part ';
 
- 						}
 
- 					}
 
- 					else
 
- 					{
 
- 						if($i == 2)
 
- 						{
 
- 							$num .= $v.'-id-';
 
- 						}
 
- 						else
 
- 						{
 
- 							$num .= $v.'-';
 
- 						}
 
- 						$ti .= $ctd[$v].' ';
 
- 					}
 
- 					$i++;
 
- 			    }
 
- 				if(stripos($codeid['length'],'closure') !== false && stripos($ndata,'127') !== false)
 
- 				{
 
- 					$v = preg_replace(array('/([\s\S]*)closure/','/([\s\S]*)closure\s/'),array('',''),$codeid['length']);
 
- 					$v = preg_replace('/([\s]*)/','',$v);
 
- 					$fpdata = $dtc[$v]['id'].',-'.str_replace('id-','',$num).'|'.$ti.$v.'inch |1|0.00|0.00|'.$v.'|0.00|0.00;';
 
- 					$tit = '<p>'.$ti.$v.'inch</p>';
 
- 					$whlabel = '|'.str_replace(array('-','id'),array('',$dtc[$v]['id']),$num).'-1';
 
- 				}
 
- 				else
 
- 				{
 
- 				    $codeid['length'] = explode(' ',$codeid['length']);
 
- 				    foreach ($codeid['length'] as $v) 
 
- 		            {
 
- 					    if(is_numeric($v))
 
- 					    {
 
- 					    	$fpdata .= $dtc[$v]['id'].',-'.str_replace('id-','',$num).'|'.$ti.$v.'inch |1|0.00|0.00|'.$v.'|0.00|0.00;';
 
- 						    $tit .= '<p>'.$ti.$v.'inch</p>';
 
- 						    $whlabel .= '|'.str_replace(array('-','id'),array('',$dtc[$v]['id']),$num).'-1';
 
- 					    }
 
- 					    else
 
- 					    {
 
- 					    	break;
 
- 					    }
 
- 				    }
 
- 				}
 
- 				$fa = '';$wl = '';
 
- 				$u['fpdata'] = explode(';',rtrim($u['fpdata'],';'));
 
- 				$u['whlabel'] = explode('|',trim($u['whlabel'],'|'));
 
- 				for($i=0;$i<count($u['fpdata']);$i++) 
 
- 		        {
 
- 					if(stripos($u['fpdata'][$i],$data[0]) === false)
 
- 					{
 
- 						if($u['fpdata'][$i] != '')
 
- 						{
 
- 						    $fa .= $u['fpdata'][$i].';';
 
- 							$te = explode('|',$u['fpdata'][$i]);
 
- 						    $tit .= '<p>'.$te[1].'</p>';
 
- 						}
 
- 					}
 
- 					if(stripos($u['whlabel'][$i],$data[0]) === false)
 
- 					{
 
- 						if($u['whlabel'][$i] != '')
 
- 						{
 
- 						    $wl .= '|'.$u['whlabel'][$i];
 
- 						}
 
- 					}
 
- 				}
 
- 				$this->commodityread->save(array('fpdata'=>$fa.$fpdata,'whlabel'=>$wl.$whlabel.'|'),$val);
 
- 				$rows[] = array('id'=>$val,'title'=>$tit);
 
-             }
 
- 			echo json_encode(array('rows'=>$rows,'success'=>true));exit;
 
- 		}
 
- 	}
 
- 	public function _skuedit($arg_array)
 
- 	{
 
- 		$post = $this->input->post(NULL, TRUE);
 
- 		if(isset($post['id']))
 
- 		{
 
- 			$id = $this->input->post('id',true);
 
- 			$post['fpdata'] = $this->input->post('fpdata',true);
 
- 			$post['whlabel'] = $this->input->post('whlabel',true);
 
- 			if($this->commodityread->save($post,$id))
 
-         	{
 
-          		echo json_encode(array('msg'=>'操作成功','success'=>true));exit;
 
-        	 	}
 
-        		else
 
-         	{
 
-            		echo json_encode(array('msg'=>'操作失败,请重试','success'=>false));exit;
 
-         	}
 
- 		}
 
- 		$arg_array = $arg_array[0];$fpdata = array();
 
- 		$commodityread = $this->commodityread->read($arg_array);
 
- 		if(stripos($commodityread['fpdata'],';') !== false)
 
- 		{
 
- 		    $fpdata = explode(';',rtrim($commodityread['fpdata'],';'));
 
- 		    foreach ($fpdata as $k=>$v) 
 
- 		    {
 
- 			    $fpdata[$k] = explode('|',$v);
 
-             }
 
- 		}
 
- 		$this->data['fpdata'] = $fpdata;
 
- 		$this->data['commodityread'] = $commodityread;
 
- 		$this->_Template('commodityread_edit',$this->data);
 
- 	}
 
- 	
 
- 	//获取
 
- 	public function _aeorder()
 
- 	{
 
- 		$sid = '';
 
- 		if(isset($_SESSION['api']))
 
- 		{
 
- 			$user = $this->user->get_api($_SESSION['api']);
 
- 		    $user = explode('|',trim($user['shop'],'|'));
 
- 			foreach ($user as $value) 
 
- 		    {
 
- 				$sid .= " id = '$value' or";
 
- 			}
 
- 			$sid = " and (".rtrim($sid,'or').")";
 
- 		}
 
- 		$post = $this->input->post(NULL, TRUE);
 
- 		if($sid)  
 
- 		{
 
- 			$shop = $this->shop->find_all("code != '' and type = '270'".$sid);//获取店铺信息
 
- 			foreach ($shop as $value)
 
- 		    {
 
- 				$res = array();
 
- 				for($x=1;$x<5;$x++)
 
- 				{
 
- 				    $resi = $this->apismt->get_commoditylist($x,100,$value['code']);//获取商品列表
 
- 					if($resi)
 
- 					{
 
- 				        $res += $resi;
 
- 					}
 
- 				}
 
- 				if($res)
 
- 				{
 
- 				        $yzpid = $this->commodity->find_all('shop = '.$value['id']);
 
- 						foreach ($yzpid as $v)
 
- 		        	    {
 
- 							if($v['productid'] == '' || $v['productid'] == '0')
 
- 							{
 
- 								$this->commodity->remove($v['id']);
 
- 								continue;
 
- 							}
 
- 							if(!isset($res[$v['productid']]))
 
- 							{
 
- 								$this->commodity->save(array('type'=>'offline'),$v['id']);
 
- 							}
 
- 						}
 
- 						foreach ($res as $v)
 
- 		        	    {
 
- 						    $productid = $this->commodity->get_productid($v);
 
- 						    //if(!$productid)
 
- 							//{
 
- 								@$read = $this->apismt->get_commodityread($v,$value['code']);
 
- 								//$this->logic_ding->sendToDing("速卖通获取商品详情"."【".json_encode($read)."】");
 
- 								if(is_array($read))
 
- 								{
 
- 									@$cid = $this->apismt->get_commoditysku($read['cid'],$value['code']);
 
- 								}
 
- 								else
 
- 								{
 
- 									continue;
 
- 								}
 
- 								//处理结束
 
- 								if(isset($cid[0]))
 
- 								{
 
- 									// 处理 $cid
 
- 									$cc = array();
 
- 									foreach ($cid as $c)
 
- 		        	            	{
 
- 										$names = json_decode($c['names'],true);
 
- 										$cc[$c['id']] = $names['en'];
 
- 										if(!isset($c['values']))
 
- 										{
 
- 											continue;
 
- 										}
 
- 										if(isset($c['values']['aeop_attr_value_dto'][0]))
 
- 										{
 
- 									 	   foreach ($c['values']['aeop_attr_value_dto'] as $cv)
 
- 		        	                 	   {
 
- 											   if(isset($read['gg'][$cv['id']]))//如果有自定义
 
- 											   {
 
- 												   $cc[$cv['id']] = $read['gg'][$cv['id']];
 
- 											   }
 
- 											   else
 
- 											   {
 
- 											       $cnames = json_decode($cv['names'],true);
 
- 											       $cc[$cv['id']] = $cnames['en'];
 
- 											   }
 
- 									    	}
 
- 										}
 
- 										else
 
- 										{
 
- 											$cnames = json_decode($c['values']['aeop_attr_value_dto']['names'],true);
 
- 											$cc[$c['values']['aeop_attr_value_dto']['id']] = $cnames['en'];
 
- 										}
 
- 									}
 
- 									$read['title'] = ($read['title'])?$read['title']:'';
 
- 									if(!$productid)
 
- 									{
 
- 									    //处理结束
 
- 							            $this->commodity->insert(array('shop'=>$value['id'],'productid'=>$v,'title'=>$read['title'],'img'=>$read['img'],'type'=>$read['type'],'time'=>time()));
 
- 									}
 
- 									else
 
- 									{
 
- 										$this->commodity->save(array('shop'=>$value['id'],'productid'=>$read['productid'],'title'=>$read['title'],'img'=>$read['img'],'type'=>$read['type']),$productid['id']);
 
- 									}
 
- 									$this->_aeordersku($read['sku'],$value['id'],$v,$cc);
 
- 								}
 
- 						    //}
 
- 					    }
 
- 				}
 
- 				else
 
- 				{
 
- 					continue;
 
- 				}
 
- 			}
 
- 			echo json_encode(array('msg'=>'同步完成!','success'=>true));exit;
 
- 		}
 
- 	}
 
- 	public function _aeordersku($sku,$shop,$productid,$cc)
 
- 	{
 
- 		$yzsku = $this->commodityread->find_all("productid = '$productid'");
 
- 		foreach ($yzsku as $v)
 
- 		{
 
- 			$s = 0;
 
- 			if(!isset($sku[$v['skuid']]))
 
- 			{
 
- 				$skuid = explode(';',$v['skuid']);
 
- 				if(count($skuid) < 2)
 
- 				{
 
- 					$this->commodityreaddel->insert($v);
 
- 					$this->commodityread->remove($v['id']);//asd
 
- 					continue;
 
- 				}
 
- 				else
 
- 				{
 
- 					$skuidarray = $this->_qpl($skuid);
 
- 					foreach ($skuidarray as $skuv)
 
- 		            {
 
- 						if(isset($sku[$skuv]))
 
- 						{
 
- 							$this->commodityread->save(array('skuid'=>$skuv),$v['id']);
 
- 							$s++;
 
- 							break 1;
 
- 						}
 
- 					}
 
- 				}
 
- 				if($s < 1)
 
- 				{
 
- 				    $this->commodityreaddel->insert($v);
 
- 				    $this->commodityread->remove($v['id']);//asd
 
- 				}
 
- 			}
 
- 		}
 
- 		foreach ($sku as $v)
 
- 	    {
 
- 			$read = $this->commodityread->get_productid($productid,$v['skuid']);
 
- 			if(isset($read['productid']))
 
- 			{
 
- 				$cd = explode(';',$v['skuid']);$cod = '';
 
- 				foreach ($cd as $vv)
 
- 	            {
 
- 					$cv = explode(':',$vv);
 
- 					$cod .=$cc[$cv[0]].":".$cc[$cv[1]].";";
 
- 				}
 
- 				$this->commodityread->save(array('shop'=>$shop,'productid'=>$productid,'codeid'=>$cod,'skuid'=>$v['skuid'],'code'=>$v['code'],'time'=>time()),$read['id']);
 
- 			}
 
- 			else
 
- 			{
 
- 				$cd = explode(';',$v['skuid']);$cod = '';
 
- 				foreach ($cd as $vv)
 
- 	            {
 
- 					$cv = explode(':',$vv);
 
- 					$cod .=$cc[$cv[0]].":".$cc[$cv[1]].";";
 
- 				}
 
- 				$this->commodityread->insert(array('shop'=>$shop,'productid'=>$productid,'codeid'=>$cod,'skuid'=>$v['skuid'],'code'=>$v['code'],'time'=>time()));
 
- 			}
 
- 		}
 
- 	}
 
- 	
 
- 	public function _qpl($source)//全排列
 
- 	{
 
- 		$qpl = array();
 
- 		sort($source); //保证初始数组是有序的
 
- 		$last = count($source) - 1; //$source尾部元素下标
 
- 		$x = $last;
 
- 		$count = 1; //组合个数统计
 
- 		$qpl[implode(';', $source)] = implode(';', $source); //输出第一种组合
 
- 		while (true) 
 
- 		{
 
- 		    $y = $x--; //相邻的两个元素
 
- 		    if ($source[$x] < $source[$y])//如果前一个元素的值小于后一个元素的值
 
- 			{ 
 
- 		        $z = $last;
 
- 		        while ($source[$x] > $source[$z]) //从尾部开始,找到第一个大于 $x 元素的值
 
- 				{
 
- 					$z--;
 
- 				}
 
- 				/* 交换 $x 和 $z 元素的值 */
 
-                 list($source[$x], $source[$z]) = array($source[$z], $source[$x]);
 
-                 /* 将 $y 之后的元素全部逆向排列 */
 
-                 for ($i = $last; $i > $y; $i--, $y++) 
 
- 				{
 
- 					list($source[$i], $source[$y]) = array($source[$y], $source[$i]);
 
- 				}
 
- 				$qpl[implode(';', $source)] = implode(';', $source); //输出组合
 
- 				$x = $last;
 
- 				$count++;
 
- 			}
 
- 			if ($x == 0)//全部组合完毕
 
- 			{
 
- 			    break;
 
- 			}
 
- 		}
 
-         return $qpl;
 
- 	}
 
- 	
 
- 	public function _skudelhf($a)//commodityread 同步删除的恢复
 
- 	{
 
- 		$this->db->trans_begin();
 
- 		$qbpid = array();
 
- 		$a = $this->commodityread->find_all("time > '1653613200'");
 
- 		foreach ($a as $v)
 
- 	    {
 
- 		   $qbpid[$v['productid']] = $v['productid'];
 
- 	    }
 
- 		foreach ($qbpid as $valer)
 
- 	    {
 
- 	       $del = $this->commodityreaddel->find_all("productid = '".$valer."' and sku != ''",'*','id asc');
 
- 		   if($del)
 
- 		   {
 
- 	           foreach ($del as $val)
 
- 	           {
 
- 		           $skuid = explode(';',$val['skuid']);
 
- 				   if(count($skuid) < 2)
 
- 				   {
 
- 					   continue;
 
- 				   }
 
- 		           $skuidarray = $this->_qpl($skuid);
 
- 		           $red = $this->commodityread->find_all("productid = '".$val['productid']."' and sku = ''");
 
- 		           foreach ($red as $v)
 
- 	               {
 
- 					   if(isset($skuidarray[$v['skuid']]))
 
- 			           {
 
- 						   $this->commodityread->save(array('sku'=>$val['sku']),$v['id']);
 
- 			           }
 
- 		           }
 
- 	           }
 
- 		   }
 
- 	    }
 
- 	   if ($this->db->trans_status() === TRUE)
 
-         {
 
- 			$this->db->trans_commit();
 
- 			echo 1;
 
- 		}
 
- 		else
 
- 		{
 
- 			$this->db->trans_rollback();
 
- 			echo 2;
 
- 		}
 
- 	}
 
- 	public function _excel_export(){
 
- 		if(isset($_SESSION['api']))
 
- 		{
 
- 			$user = $this->user->get_api($_SESSION['api']);
 
- 			$usp = $user;
 
- 		    $fgshop = "";$sid = "";
 
- 		    $usersp = explode('|',trim($user['shop'],'|'));
 
- 			foreach ($usersp as $value) 
 
- 		    {
 
- 				$fgshop .= " shop = ".$value." or";
 
- 				$sid .= " id = ".$value." or";
 
- 			}
 
- 		}
 
- 		$params = $this->input->get(NULL, TRUE);
 
- 		if(isset($params['excel']) && $params['excel'] == 1){
 
- 			$shop = $this->input->get('shop',true);
 
- 			$productid = $this->input->get('productid',true);
 
- 			$title = $this->input->get('title',true);
 
- 			$type = $this->input->get('type',true);
 
- 			$code = $this->input->get('code',true);
 
- 			$skuid = $this->input->get('skuid',true);
 
- 			$category = $this->input->get('category',true);
 
- 			$categorytypeclass =  $this->typeclass->get_titleclassid($category,16);
 
- 			$where = "1=1 and (".rtrim($fgshop,'or').")";
 
- 			if($shop)
 
-             {
 
-                 $where  .= " and shop = '$shop'";
 
-             }
 
- 			if($productid)
 
-             {
 
-                 $where  .= " and productid = '$productid'";
 
-             }
 
- 			if($title)
 
-             {
 
- 				$where  .= " and title like '%$title%'";
 
-             }
 
- 			if($type)
 
-             {
 
-                 $where  .= " and type = '$type'";
 
-             }
 
- 			if($category)
 
-             {
 
-                 $where  .= " and category like '%".$categorytypeclass['id']."%'";
 
-             }
 
- 			if($code)
 
-             {
 
- 				$u = $this->commodityread->get_sku($code);
 
- 				$u = $u['productid'];
 
-                 $where  .= " and productid = '$u'";
 
-             }
 
- 			if($skuid)
 
-             {
 
- 				$u = $this->commodityread->get_skuid($skuid);
 
- 				$u = $u['productid'];
 
-                 $where  .= " and productid = '$u'";
 
-             }
 
-             //数据排序
 
-             $order_str = "time desc";
 
-           
 
-             //取得信息列表
 
-             $info_list = $this->commodity->find_all($where,'id,shop,productid,img,title,category,time',$order_str);
 
- 			 //格式化数据
 
- 			$final_list = [];
 
- 			$shop_where = trim($sid,'or');
 
- 			$shop_list = $this->shop->find_all($shop_where,'id,shopname');
 
- 			$shop_list = array_column($shop_list,'shopname','id');
 
- 			$typeclass = [];
 
- 			$classid = $this->classid->sku();
 
- 			$tcall = $this->typeclass->find_all();
 
- 			foreach ($tcall as $v)
 
- 			{
 
- 				//$tcjm[$v['id']] = array($v['jm'],$v['classid']);
 
- 				$typeclass[$v['id']] = array('zh'=>$v['zh'],'classid'=>$v['classid'],'bm'=>$v['bm'],'title'=>$v['title'],'jm'=>$v['jm']);
 
- 			}
 
- 			$dtctitle = [];
 
- 			foreach($tcall as $v){
 
- 				$dtctitle[$v['id']] = $v['title'];
 
- 			}
 
- 			$dtc = [];
 
- 			foreach ($tcall as $v) {
 
- 				if (stripos($v['spare'], '|') !== false) //如果有多个值
 
- 				{
 
- 					$v['spare'] = explode('|', $v['spare']);
 
- 					foreach ($v['spare'] as $k => $vs) {
 
- 						if (stripos($v['zh'], '|') !== false) {
 
- 							$vzh = explode('|', $v['zh']);
 
- 							$dtc[strtolower($vs)] = array('classid' => $v['classid'], 'zh' => $vzh[$k], 'id' => $v['id'], 'jm' => $v['jm'], 'spare' => $vs);
 
- 						} else {
 
- 							$dtc[strtolower($vs)] = array('classid' => $v['classid'], 'zh' => $v['zh'], 'id' => $v['id'], 'jm' => $v['jm'], 'spare' => $vs);
 
- 						}
 
- 					}
 
- 				} else {
 
- 					$dtc[strtolower($v['spare'])] = array('classid' => $v['classid'], 'zh' => $v['zh'], 'id' => $v['id'], 'jm' => $v['jm'], 'spare' => $v['spare']);
 
- 				}
 
- 			}
 
-             foreach ($info_list as $key=>$v) 
 
- 		    {
 
- 				$shopname = isset($shop_list[$v['shop']])?$shop_list[$v['shop']]:'';
 
- 				$skulist = $this->commodityread->find_all("productid = ".$v['productid']);
 
- 				$tmp_list = [];
 
- 				foreach($skulist as $skv){
 
- 					$tmp_sku = str_replace('--','-',$skv['sku']);
 
- 					$u9_info = $this->logic_order->skuTransferFeatures($tmp_sku,$typeclass,$dtc,$dtctitle,$classid);
 
- 					
 
- 					$tmp_list[] = [
 
- 						'codeid' => $skv['codeid'],
 
- 						'erp_sku' => $skv['sku'],
 
- 						'jm'=>$u9_info['jm'],
 
- 						'zh'=>$u9_info['zh'],
 
- 					];
 
- 				}
 
- 				$tmp_codeid = "";
 
- 				$tmp_erp_sku = "";
 
- 				$tmp_jm = "";
 
- 				$tmp_zh = "";
 
- 				foreach($tmp_list as $t){
 
- 					$tmp_codeid .= $t['codeid']."<br>";
 
- 					$tmp_erp_sku .= $t['erp_sku']."<br>";
 
- 					$tmp_jm .= $t['jm']."<br>";
 
- 					$tmp_zh .= $t['zh']."<br>";
 
- 				}
 
- 				$final_list[] = [
 
- 					'shopname' => $shopname,
 
- 					'productid' => "'".$v['productid'],
 
- 					'codeid' => $tmp_codeid,
 
- 					'erp_sku' => $tmp_erp_sku,
 
- 					'jm' => $tmp_jm,
 
- 					'zh' => $tmp_zh,
 
- 					'title' => $v['title'],				
 
- 				];
 
-             }
 
- 			//生成excel
 
-             $filename = '速卖通-'.date('Ymd',time()).".xlsx";
 
-             $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\"><head>
 
-             <!--[if gte mso 9]><xml>
 
-             <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>
 
-             <![endif]-->
 
-             </head><body>";
 
-             $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>"; 
 
-             $str .= "<tr><td>店铺名称</td><td>速卖通产品编码</td><td>速卖通标题</td><td>速卖通SKU名称</td><td>erpSKU</td><td>用友简码</td><td>仓库品名</td></tr>";
 
-             foreach ($final_list as $key=>$value) 
 
-             { 
 
- 				$str .= "<tr>";
 
- 				$str .= "<td>". $value['shopname']. "</td>";
 
- 				$str .= "<td>". $value['productid']. "</td>";	
 
- 				$str .= "<td>". $value['title']. "</td>";	
 
- 				$str .= "<td>". $value['codeid']. "</td>";
 
- 				$str .= "<td>". $value['erp_sku']. "</td>";
 
- 				$str .= "<td>". $value['jm']. "</td>";
 
- 				$str .= "<td>". $value['zh']. "</td>";
 
- 				$str .= "</tr>";
 
-             }
 
-             $str .= "</table></body></html>"; 
 
-             header( "Content-Type: application/vnd.ms-excel; name='excel'" ); 
 
-             header( "Content-type: application/octet-stream" ); 
 
-             header( "Content-Disposition: attachment; filename=".$filename ); 
 
-             header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" ); 
 
-             header( "Pragma: no-cache" ); 
 
-             header( "Expires: 0" ); 
 
-             exit($str); 
 
- 		}
 
- 	}
 
- }
 
 
  |