| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153 | 
							- <?php defined('BASEPATH') OR exit('No direct script access allowed');
 
- class customertt extends Start_Controller {
 
- 	public function __construct(){
 
- 		parent::__construct();
 
- 		$this->load->library('session');
 
- 		$this->load->_model('Model_customertt','customertt');
 
- 		$this->load->_model('Model_typeclass','typeclass');
 
- 		$this->load->_model('Model_shop','shop');
 
- 		$this->load->_model('Model_country','country');
 
- 		$this->load->_model('Model_express','express');
 
- 		$this->load->_model('Model_fullorder','fullorder');
 
- 		$this->load->_model('Model_fullordertt','fullordertt');
 
- 		$this->load->_model('Model_excel','excel');
 
- 		$this->load->_model('Model_whlabel','whlabel');
 
- 		$this->load->_model('Model_warehouse','warehouse');
 
- 		$this->load->_model('Model_specialstock','specialstock');
 
- 		$this->load->_model('Model_ck','ck');
 
- 		$this->load->_model('Model_weight','weight');
 
- 		$this->load->_model('Model_pay','pay');
 
- 		$this->load->_model('Model_setting','setting');
 
- 		$this->load->_model('Model_classid','classid');
 
- 		$this->load->_model('Model_apiyy','apiyy');
 
- 		//$this->load->_model('Model_apiyy','apiyy');
 
- 		$this->load->_model('Model_whlabel_fc','whlabel_fc');
 
- 		$this->load->_model("Model_logic_order","logic_order");
 
- 	}
 
- 	//定义方法的调用规则 获取URI第二段值
 
-     public function _remap($arg,$arg_array)
 
-     {
 
- 		if($arg == 'add')//添加
 
-         {
 
-              $this->_add();
 
-         }
 
- 		else if($arg == 'edit')//修改
 
-         {
 
-              $this->_edit($arg_array);
 
-         }
 
- 		else if($arg == 'del')//黑名单
 
-         {
 
-              $this->_del();
 
-         }
 
- 		else if($arg == 'change')//更改名单状态
 
-         {
 
-              $this->_change();
 
-         }
 
- 		else if($arg == 'mdedit')//修改
 
-         {
 
-              $this->_mdedit($arg_array);
 
-         }
 
- 		else if($arg == 'black')//黑名单
 
-         {
 
-              $this->_black();
 
-         }
 
- 		else if($arg == 'excela')
 
-         {
 
-              $this->_excela();
 
-         }
 
- 		else if($arg == 'excel')//下载excel
 
-         {
 
-              $this->_excel();
 
-         }
 
- 		else if($arg == 'indexexcel')//下载excel
 
-         {
 
-              $this->_indexexcel();
 
-         }
 
- 		else if($arg == 'down')//黑名单
 
-         {
 
-              $this->_down();
 
-         }
 
- 		else if($arg == 'bankdown')//下载客户
 
-         {
 
-              $this->_bankdown();
 
-         }
 
- 		else if($arg == 'newold')//新老客户比
 
-         {
 
-              $this->_newold();
 
-         }
 
- 		else if($arg == 'dgso')
 
-         {
 
-              $this->_dgso();
 
-         }
 
- 		else if($arg == 'cx')
 
-         {
 
-              $this->_cx();
 
-         }
 
- 		else
 
- 		{
 
- 			 $this->_index();
 
- 		}
 
-     }
 
- 	//管理
 
- 	public function _index_xxxxxx()//通过索引订单查询购买次数,太慢,暂时抛弃
 
- 	{
 
- 		$user = $this->user->get_api($_SESSION['api']);
 
- 		if($user)
 
- 		{
 
- 		    $fgshop = "";$sid = "";
 
- 		    $user = explode('|',trim($user['shop'],'|'));
 
- 			foreach ($user 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);
 
- 			$numphone = $this->input->post('numphone',true);
 
- 			$name = $this->input->post('name',true);
 
- 			$email = $this->input->post('email',true);
 
- 			$address = $this->input->post('address',true);
 
- 			$level = $this->input->post('level',true);
 
- 			$num = $this->input->post('num',true);
 
- 			$timetk = $this->input->post('timetk',true);
 
- 			$timetj = $this->input->post('timetj',true);
 
- 			$timetk = strtotime($timetk);
 
- 			$timetj = strtotime($timetj);
 
- 			$where = "1=1 and type = 1 and (".rtrim($fgshop,'or').")";
 
- 			if($shop)
 
-             {
 
-                 $where  .= " and shop = '$shop'";
 
-             }
 
- 			if($numphone)
 
-             {
 
-                 $where  .= " and numphone = '$numphone'";
 
-             }
 
- 			if($name)
 
-             {
 
-                 $where  .= " and name like '%$name%'";
 
-             }
 
- 			if($email)
 
-             {
 
-                 $where  .= " and email like '%$email%'";
 
-             }
 
- 			if($level)
 
-             {
 
-                 $where  .= " and level = '$level'";
 
-             }
 
- 			if($address)
 
-             {
 
-                 $where  .= " and address like '%$address%'";
 
-             }
 
- 			if($timetk && $timetj)
 
-             {
 
-                 //$where  .= " and ((time > '$timetk' and time < '$timetj') or time = 0)";
 
- 				$where  .= " and ((time > '$timetk' and time < '$timetj') or time = '0')";
 
-             }
 
-             //数据排序
 
-             $order_str = "id desc";
 
- 			$numdata = array();
 
-             if(empty($page))
 
- 		    {
 
-                 $start = 0;
 
- 		    	$perpage = 1;
 
-             }
 
- 		    else
 
- 		    {
 
-                 $start = ($page - 1)*$perpage;
 
-             }
 
-             //取得信息列表
 
- 			if($num > 0)
 
- 			{
 
- 				$info_list = $this->customertt->find_all($where,'id,shop,source,name,email,country,level,money,num,time,count,type',$order_str);
 
- 			}
 
- 			else
 
- 			{
 
-                 $info_list = $this->customertt->find_all($where,'id,shop,source,name,email,country,level,money,num,time,count,type',$order_str,$start,$perpage);
 
- 			}
 
- 			foreach ($info_list as $key=>$value)
 
- 		    {
 
- 				$shop = $this->shop->read($value['shop']);
 
- 				$info_list[$key]['shop'] = $shop['shopname'];
 
- 				$source = $this->typeclass->read($value['source']);
 
- 				$info_list[$key]['source'] = $source['title'];
 
- 				if($value['email'] != '0' && $value['email'] != '' && $value['email'] != '无')
 
- 		        {
 
- 					$gnum =  $this->fullordertt->find_count("email = '".$value['email']."' and shop = '".$value['shop']."' and mergeid = 0 and buytime > '$timetk' and buytime < '$timetj'");
 
- 				}
 
- 		        else
 
- 				{
 
- 					$gnum = 0;
 
- 				}
 
- 				$info_list[$key]['num'] =  $gnum;
 
- 				if($value['country'] != 0)
 
- 				{
 
- 				    $country = $this->country->read($value['country']);
 
- 				    $info_list[$key]['country'] = $country['name'];
 
- 				}
 
- 				else
 
- 				{
 
- 					$info_list[$key]['country'] = "未知";
 
- 				}
 
- 				if($value['level'] == 1)
 
- 				{
 
- 					$info_list[$key]['level'] = "网红";
 
- 				}
 
- 				else if($value['level'] == 2)
 
- 				{
 
- 					$info_list[$key]['level'] = "批发";
 
- 				}
 
- 				else if($value['level'] == 3)
 
- 				{
 
- 					$info_list[$key]['level'] = "店铺转线下";
 
- 				}
 
- 				else if($value['level'] == 4)
 
- 				{
 
- 					$info_list[$key]['level'] = "线下其他";
 
- 				}
 
- 				else if($value['level'] == 5)
 
- 				{
 
- 					$info_list[$key]['level'] = "店内客户";
 
- 				}
 
- 				if($value['time'] != 0)
 
- 				{
 
- 					$info_list[$key]['time'] = date('Y-m-d',$value['time']);
 
- 				}
 
- 				else
 
- 				{
 
- 					$info_list[$key]['time'] = "无";
 
- 				}
 
- 				$info_list[$key]['type'] = "<a href='javascript:void(0);' class='window' data-h='/customertt/mdedit/".$value['id']."' data-t='客户下单'><b>下单</b></a>    <a class='customer' data-type='2' data-t='yr' data-id='".$value['id']."' href='javascript:void(0);'>移入黑名单</a>";
 
- 				if($num >= '10' && $gnum >= '10')
 
- 				{
 
- 					$numdata[] = $info_list[$key];
 
- 				}
 
- 				else if ($num > '0' && $num < '10' && $gnum == $num)
 
- 				{
 
- 					$numdata[] = $info_list[$key];
 
- 				}
 
- 		    }
 
- 			if($num > 0)
 
- 			{
 
- 				$info_list = array_slice($numdata,$start,$perpage);;
 
- 				$total = count($numdata);
 
- 			}
 
- 			else
 
- 			{
 
- 				 $total = $this->customertt->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('customertt',$this->data);
 
- 	}
 
- 	public function _index()//通过计数,2020/02/21已校准
 
- 	{
 
- 		$user = $this->user->get_api($_SESSION['api']);
 
- 		if($user)
 
- 		{
 
- 		    $fgshop = "";$sid = "";
 
- 		    $users = explode('|',trim($user['shop'],'|'));
 
- 			foreach ($users as $value) 
 
- 		    {
 
- 				$fgshop .= " shop = ".$value." or";
 
- 				$sid .= " id = ".$value." or";
 
- 			}
 
- 			if($user['vip'] == 1)
 
- 			{
 
- 				$vip = 1;
 
- 			}
 
- 			else
 
- 			{
 
- 				$vip = 0;
 
- 			}
 
- 		}
 
- 		else
 
- 		{
 
- 			$vip = 0;
 
- 		}
 
- 		$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);
 
- 			$numphone = $this->input->post('numphone',true);
 
- 			$name = $this->input->post('name',true);
 
- 			$email = $this->input->post('email',true);
 
- 			$address = $this->input->post('address',true);
 
- 			$country = $this->input->post('country',true);
 
- 			$level = $this->input->post('level',true);
 
- 			$num = $this->input->post('num',true);
 
- 			$timetk = $this->input->post('timetk',true);
 
- 			$timetj = $this->input->post('timetj',true);
 
- 			$timetk = strtotime($timetk);
 
- 			$timetj = strtotime($timetj);
 
- 			$where = "1=1 and type = 1 and (".rtrim($fgshop,'or').")";
 
- 			if($shop)
 
-             {
 
-                 $where  .= " and shop = '$shop'";
 
-             }
 
- 			if($numphone != '')
 
-             {
 
- 				if($numphone == '0')
 
- 				{
 
- 					$where  .= " and phone = '$numphone'" ;
 
- 				}
 
- 				else
 
- 				{
 
-                     $where  .= " and numphone = '$numphone' and phone != ''" ;
 
- 				}
 
-             }
 
- 			if($name)
 
-             {
 
-                 $where  .= " and name like '%$name%'";
 
-             }
 
- 			if($country)
 
-             {
 
-                 $where  .= " and country = '$country'";
 
-             }
 
- 			if($email)
 
-             {
 
-                 $where  .= " and email like '%$email%'";
 
-             }
 
- 			if($level != '')
 
-             {
 
-                 $where  .= " and level = '$level'";
 
-             }
 
- 			if($address)
 
-             {
 
-                 $where  .= " and address like '%$address%'";
 
-             }
 
- 			if($num > 0 && $num < 10 && $num != '2a')
 
-             {
 
-                 $where  .= " and num = '$num'";
 
-             }
 
- 			else if($num > 9)
 
-             {
 
-                 $where  .= " and num > '9'";
 
-             }
 
- 			else if($num == '2a')
 
-             {
 
-                 $where  .= " and num > '1'";
 
-             }
 
- 			else if($num == '0')
 
- 			{
 
- 				$where  .= " and num = '0'";
 
- 			}
 
- 			else
 
- 			{
 
- 				$where  .= " and num >= '0'";
 
- 			}
 
- 			if($timetk && $timetj)
 
-             {
 
- 				$where  .= " and ((time > '$timetk' and time < '$timetj') or time = '0')";
 
-             }
 
-             //数据排序
 
-             $order_str = "time desc";
 
- 			$numdata = array();
 
-             if(empty($page))
 
- 		    {
 
-                 $start = 0;
 
- 		    	$perpage = 1;
 
-             }
 
- 		    else
 
- 		    {
 
-                 $start = ($page - 1)*$perpage;
 
-             }
 
-             //取得信息列表
 
- 			$info_list = $this->customertt->find_all($where,'id,shop,source,name,email,phone,country,level,money,num,numphone,time,count,type',$order_str,$start,$perpage);
 
- 			foreach ($info_list as $key=>$value) 
 
- 		    {
 
- 				$shop = $this->shop->read($value['shop']);
 
- 				$info_list[$key]['shop'] = $shop['shopname'];
 
- 				$source = $this->typeclass->read($value['source']);
 
- 				$info_list[$key]['source'] = $source['title'];
 
- 				if($value['country'] != 0)
 
- 				{
 
- 				    $country = $this->country->read($value['country']);
 
- 				    $info_list[$key]['country'] = $country['name'];
 
- 				}
 
- 				else
 
- 				{
 
- 					$info_list[$key]['country'] = "未知";
 
- 				}
 
- 				if($value['level'] == 1)
 
- 				{
 
- 					$info_list[$key]['level'] = "网红";
 
- 				}
 
- 				else if($value['level'] == 2)
 
- 				{
 
- 					$info_list[$key]['level'] = "批发";
 
- 				}
 
- 				else if($value['level'] == 3)
 
- 				{
 
- 					$info_list[$key]['level'] = "店铺转线下";
 
- 				}
 
- 				else if($value['level'] == 4)
 
- 				{
 
- 					$info_list[$key]['level'] = "线下其他";
 
- 				}
 
- 				else if($value['level'] == 5)
 
- 				{
 
- 					$info_list[$key]['level'] = "店内客户";
 
- 				}
 
- 				else
 
- 				{
 
- 					$info_list[$key]['level'] = "未定义";
 
- 				}
 
- 				if($value['time'] != 0)
 
- 				{
 
- 					$info_list[$key]['time'] = date('Y-m-d',$value['time']);
 
- 				}
 
- 				else
 
- 				{
 
- 					$info_list[$key]['time'] = "无";
 
- 				}
 
- 				//$gmcs = $this->fullordertt->find_count("email = '".$value['email']."' time > '$timetk' and time < '$timetj'");
 
- 				//$info_list[$key]['num'] = $gmcs;
 
- 				$info_list[$key]['numphone'] = ($value['num'] > 0)?sprintf("%01.2f",$value['money']/$value['num']):0;
 
- 				$info_list[$key]['type'] = "<p><a href='javascript:void(0);' class='window' data-h='/customertt/mdedit/".$value['id']."' data-t='客户下单'><b>下单</b></a></p><a class='customer' data-type='2' data-t='yr' data-id='".$value['id']."' href='javascript:void(0);'>移入黑名单</a>";
 
- 		    }
 
- 			$total = $this->customertt->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->data['vip'] = $vip;
 
- 		$this->_Template('customertt',$this->data);
 
- 	}
 
- 	
 
- 	
 
- 	public function _dgso()
 
- 	{
 
- 		$user = $this->user->get_api($_SESSION['api']);
 
- 		if($user)
 
- 		{
 
- 		    $fgshop = "";$sid = "";
 
- 		    $users = explode('|',trim($user['shop'],'|'));
 
- 			foreach ($users as $value) 
 
- 		    {
 
- 				$fgshop .= " shop = ".$value." or";
 
- 				$sid .= " id = ".$value." or";
 
- 			}
 
- 			if($user['vip'] == 1)
 
- 			{
 
- 				$vip = 1;
 
- 			}
 
- 			else
 
- 			{
 
- 				$vip = 0;
 
- 			}
 
- 		}
 
- 		else
 
- 		{
 
- 			$vip = 0;
 
- 		}
 
- 		$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);
 
- 			$numphone = $this->input->post('numphone',true);
 
- 			$name = $this->input->post('name',true);
 
- 			$email = $this->input->post('email',true);
 
- 			$address = $this->input->post('address',true);
 
- 			$level = $this->input->post('level',true);
 
- 			$num = $this->input->post('num',true);
 
- 			$timetk = $this->input->post('timetk',true);
 
- 			$timetj = $this->input->post('timetj',true);
 
- 			$timetk = strtotime($timetk);
 
- 			$timetj = strtotime($timetj);
 
- 			$where = "1=1 and (".rtrim($fgshop,'or').")";
 
- 			if($numphone)
 
-             {
 
-                 $where  .= " and numphone = '$numphone'";
 
-             }
 
- 			if($email)
 
-             {
 
-                 $where  .= " and email like '%$email%'";
 
-             }
 
- 			if($address)
 
-             {
 
-                 $where  .= " and address like '%$address%'";
 
-             }
 
- 			if($numphone || $email || $address)
 
- 			{
 
- 			    $d = $this->customertt->find_all($where);
 
- 				$data = $this->customertt->find_all("address like '%".$d[0]['address']."%' or email like '%".$d[0]['email']."%' or numphone like '%".$d[0]['numphone']."%'",'id,shop,source,name,email,country,level,money,num,time,type,numphone,address');
 
- 			    //$temp_key = array_column($data,'id');  //键值
 
-                 //$Newdata = array_combine($temp_key,$data) ;
 
- 			    $cx = array();
 
- 			    $info_list = $this->_dgcz($cx,$data);
 
- 				$info_list = array_values($info_list);
 
- 				$total = count($info_list);
 
- 		    $pagenum = ceil($total/$perpage);
 
- 		    $over = $total-$perpage;
 
- 			}
 
- 			else
 
- 			{
 
- 				  //数据排序
 
-             $order_str = "id desc";
 
- 			$numdata = array();
 
-             if(empty($page))
 
- 		    {
 
-                 $start = 0;
 
- 		    	$perpage = 1;
 
-             }
 
- 		    else
 
- 		    {
 
-                 $start = ($page - 1)*$perpage;
 
-             }
 
-             //取得信息列表
 
- 			$info_list = $this->customertt->find_all($where,'id,shop,source,name,email,country,level,money,num,time,type',$order_str,$start,$perpage);
 
- 			$total = $this->customertt->find_count($where);
 
- 		    $pagenum = ceil($total/$perpage);
 
- 		    $over = $total-($start+$perpage);
 
- 			}
 
- 			foreach ($info_list as $key=>$value) 
 
- 		    {
 
- 				$shop = $this->shop->read($value['shop']);
 
- 				$info_list[$key]['shop'] = $shop['shopname'];
 
- 				$source = $this->typeclass->read($value['source']);
 
- 				$info_list[$key]['source'] = $source['title'];
 
- 				if($value['country'] != 0)
 
- 				{
 
- 				    $country = $this->country->read($value['country']);
 
- 				    $info_list[$key]['country'] = $country['name'];
 
- 				}
 
- 				else
 
- 				{
 
- 					$info_list[$key]['country'] = "未知";
 
- 				}
 
- 				if($value['level'] == 1)
 
- 				{
 
- 					$info_list[$key]['level'] = "网红";
 
- 				}
 
- 				else if($value['level'] == 2)
 
- 				{
 
- 					$info_list[$key]['level'] = "批发";
 
- 				}
 
- 				else if($value['level'] == 3)
 
- 				{
 
- 					$info_list[$key]['level'] = "店铺转线下";
 
- 				}
 
- 				else if($value['level'] == 4)
 
- 				{
 
- 					$info_list[$key]['level'] = "线下其他";
 
- 				}
 
- 				else if($value['level'] == 5)
 
- 				{
 
- 					$info_list[$key]['level'] = "店内客户";
 
- 				}
 
- 				if($value['time'] != 0)
 
- 				{
 
- 					$info_list[$key]['time'] = date('Y-m-d',$value['time']);
 
- 				}
 
- 				else
 
- 				{
 
- 					$info_list[$key]['time'] = "无";
 
- 				}
 
- 				if($value['type'] != 2)
 
- 				{
 
- 				    $info_list[$key]['type'] = "<a href='javascript:void(0);' class='window' data-h='/customertt/mdedit/".$value['id']."' data-t='客户下单'><b>下单</b></a>    <a class='customer' data-type='2' data-t='yr' data-id='".$value['id']."' href='javascript:void(0);'>移入黑名单</a>";
 
- 				}
 
- 				else
 
- 				{
 
- 					$info_list[$key]['type'] = "黑名单客户";
 
- 				}
 
- 				unset($info_list[$key]['numphone']);
 
- 				unset($info_list[$key]['address']);
 
- 		    }
 
- 			
 
- 		    $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->data['vip'] = $vip;
 
- 		$this->_Template('customertt_dgso',$this->data);
 
- 	}
 
- 	
 
- 	public function _dgcz($child,$data)
 
-     {
 
-         foreach ($data as $key => $value) 
 
- 		{
 
-            if (!isset($child[$value['id']])) 
 
- 	       {
 
-                $child[$value['id']] = $value; 
 
-                $rows = $this->customertt->find_all("address like '%".$value['address']."%' or email like '%".$value['email']."%' or numphone like '%".$value['numphone']."%'",'id,shop,source,name,email,country,level,money,num,time,type,numphone,address');
 
-                $this->_dgcz($child,$rows);
 
-            }
 
-         }
 
-         return $child;
 
-      }
 
- 	 
 
- 	//管理
 
- 	public function _black()
 
- 	{
 
- 		/**
 
- 		$user = $this->user->get_api($_SESSION['api']);
 
- 		if($user)
 
- 		{
 
- 		    $fgshop = "";$sid = "";
 
- 		    $user = explode('|',trim($user['shop'],'|'));
 
- 			foreach ($user 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);
 
- 			$numphone = $this->input->post('numphone',true);
 
- 			$name = $this->input->post('name',true);
 
- 			$email = $this->input->post('email',true);
 
- 			$address = $this->input->post('address',true);
 
- 			$xtime = $this->input->post('xtime',true);
 
- 			//$where = "1=1 and type = 2 and (".rtrim($fgshop,'or').")";
 
- 			$timetk = $this->input->post('timetk',true);
 
- 			$timetj = $this->input->post('timetj',true);
 
- 			$timetk = strtotime($timetk);
 
- 			$timetj = strtotime($timetj);
 
- 			$where = "1=1 and type = 2";
 
- 			if($shop)
 
-             {
 
-                 $where  .= " and shop = '$shop'";
 
-             }
 
- 			if($xtime)
 
-             {
 
-                 $where  .= " and typetime > '$timetk' and typetime < '$timetj'";
 
-             }
 
- 			if($numphone != '')
 
-             {
 
- 				if($numphone == '0')
 
- 				{
 
- 					$where  .= " and phone = '$numphone'" ;
 
- 				}
 
- 				else
 
- 				{
 
-                     $where  .= " and numphone = '$numphone' and phone != ''" ;
 
- 				}
 
-             }
 
- 			if($name)
 
-             {
 
-                 $where  .= " and name like '%$name%'";
 
-             }
 
- 			if($email)
 
-             {
 
-                 $where  .= " and email like '%$email%'";
 
-             }
 
- 			$hmdaddress1 = str_replace(array(' parkway',' drive',' street',' road',' avenue',' boulevard',' alley',' court',' place',' lane',' manor',' terrace',' trail',' view',' cove'),array(' pkwy',' dr',' st',' rd',' av',' blvd',' aly',' ct',' pl',' ln',' mnr',' ter',' trl',' vw',' cv'),strtolower($address));
 
- 			$hmdaddress2 = str_replace(array(' pkwy',' dr',' st',' rd',' av',' blvd',' aly',' ct',' pl',' ln',' mnr',' ter',' trl',' vw',' cv'),array(' parkway',' drive',' street',' road',' avenue',' boulevard',' alley',' court',' place',' lane',' manor',' terrace',' trail',' view',' cove'),strtolower($address));
 
- 			$hmdaddress3 = str_replace(array(' avenue',' ave',' av'),array(' ave',' avenue',' ave'),strtolower($address));
 
- 			if($address)
 
-             {
 
-                 $where  .= " and (address like '%$address%' or address like '%$hmdaddress1%' or address like '%$hmdaddress2%' or address like '%$hmdaddress3%')";
 
-             }
 
-             //数据排序
 
-             $order_str = "id desc";
 
-             if(empty($page))
 
- 		    {
 
-                 $start = 0;
 
- 		    	$perpage = 1;
 
-             }
 
- 		    else
 
- 		    {
 
-                 $start = ($page - 1)*$perpage;
 
-             }
 
-             //取得信息列表
 
-             $info_list = $this->customertt->find_all($where,'id,shop,source,name,email,address,phone,count,typetime,type',$order_str,$start,$perpage);
 
- 			foreach ($info_list as $key=>$value) 
 
- 		    {
 
- 				$shop = $this->shop->read($value['shop']);
 
- 				$info_list[$key]['shop'] = $shop['shopname'];
 
- 				$source = $this->typeclass->read($value['source']);
 
- 				$info_list[$key]['source'] = $source['title'];
 
- 				if($value['typetime'] > 0)
 
- 				{
 
- 					$info_list[$key]['typetime'] = date('Y-m-d',$value['typetime']);
 
- 				}
 
- 				else
 
- 				{
 
- 					$info_list[$key]['typetime'] = '无';
 
- 				}
 
- 				$info_list[$key]['type'] = "<a class='customer' data-type='1' data-t='yc' data-id='".$value['id']."' href='javascript:void(0);'>移出</a>";
 
- 		    }
 
- 		    $total = $this->customertt->find_count($where);
 
- 		    $pagenum = ceil($total/$perpage);
 
- 		    $over = $total-($start+$perpage);
 
- 		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'a'=>$hmdaddress1);
 
- 		    echo json_encode($rows);exit;
 
- 		}
 
- 		if(isset($post['s']))  
 
- 		{
 
-             $id_arr = $this->input->post('s');
 
-             $id_arr =  explode(',',$id_arr);
 
-             if(!$id_arr)
 
-             {
 
-                 echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
 
-             }
 
-             //循环删除记录
 
-             foreach ($id_arr as $v) 
 
- 		    {
 
-                 $this->customertt->remove($v);
 
-             }
 
-             echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));exit;
 
- 		}
 
- 		//$wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
 
- 		$wlshop = $this->shop->find_all('1=1');
 
- 		$this->data['wlshop'] = $wlshop;
 
- 		$this->_Template('customertt_black',$this->data);
 
- 	}
 
- 	public function _cx()
 
- 	{
 
- 		$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);
 
- 			$numphone = $this->input->post('numphone',true);
 
- 			$name = $this->input->post('name',true);
 
- 			$email = $this->input->post('email',true);
 
- 			$address = $this->input->post('address',true);
 
- 			$xtime = $this->input->post('xtime',true);
 
- 			//$where = "1=1 and type = 2 and (".rtrim($fgshop,'or').")";
 
- 			$timetk = $this->input->post('timetk',true);
 
- 			$timetj = $this->input->post('timetj',true);
 
- 			$timetk = strtotime($timetk);
 
- 			$timetj = strtotime($timetj);
 
- 			$where = "1=1 and type = 2";
 
- 			if($shop)
 
-             {
 
-                 $where  .= " and shop = '$shop'";
 
-             }
 
- 			if($xtime)
 
-             {
 
-                 $where  .= " and typetime > '$timetk' and typetime < '$timetj'";
 
-             }
 
- 			if($numphone)
 
-             {
 
-                 $where  .= " and numphone = '$numphone'";
 
-             }
 
- 			if($name)
 
-             {
 
-                 $where  .= " and name like '%$name%'";
 
-             }
 
- 			if($email)
 
-             {
 
-                 $where  .= " and email like '%$email%'";
 
-             }
 
- 			$hmdaddress1 = str_replace(array(' parkway',' drive',' street',' road',' avenue',' boulevard',' alley',' court',' place',' lane',' manor',' terrace',' trail',' view',' cove'),array(' pkwy',' dr',' st',' rd',' av',' blvd',' aly',' ct',' pl',' ln',' mnr',' ter',' trl',' vw',' cv'),strtolower($address));
 
- 			$hmdaddress2 = str_replace(array(' pkwy',' dr',' st',' rd',' av',' blvd',' aly',' ct',' pl',' ln',' mnr',' ter',' trl',' vw',' cv'),array(' parkway',' drive',' street',' road',' avenue',' boulevard',' alley',' court',' place',' lane',' manor',' terrace',' trail',' view',' cove'),strtolower($address));
 
- 			$hmdaddress3 = str_replace(array(' avenue',' ave',' av'),array(' ave',' avenue',' ave'),strtolower($address));
 
- 			if($address)
 
-             {
 
-                 $where  .= " and (address like '%$address%' or address like '%$hmdaddress1%' or address like '%$hmdaddress2%' or address like '%$hmdaddress3%')";
 
-             }
 
-             //数据排序
 
-             $order_str = "id desc";
 
-             if(empty($page))
 
- 		    {
 
-                 $start = 0;
 
- 		    	$perpage = 1;
 
-             }
 
- 		    else
 
- 		    {
 
-                 $start = ($page - 1)*$perpage;
 
-             }
 
-             //取得信息列表
 
-             $info_list = $this->customertt->find_all($where,'id,shop,source,name,email,address,phone,count,typetime',$order_str,$start,$perpage);
 
- 			foreach ($info_list as $key=>$value) 
 
- 		    {
 
- 				$shop = $this->shop->read($value['shop']);
 
- 				$info_list[$key]['shop'] = $shop['shopname'];
 
- 				$source = $this->typeclass->read($value['source']);
 
- 				$info_list[$key]['source'] = $source['title'];
 
- 				if($value['typetime'] > 0)
 
- 				{
 
- 					$info_list[$key]['typetime'] = date('Y-m-d',$value['typetime']);
 
- 				}
 
- 				else
 
- 				{
 
- 					$info_list[$key]['typetime'] = '无';
 
- 				}
 
- 		    }
 
- 		    $total = $this->customertt->find_count($where);
 
- 		    $pagenum = ceil($total/$perpage);
 
- 		    $over = $total-($start+$perpage);
 
- 		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'a'=>$hmdaddress1);
 
- 		    echo json_encode($rows);exit;
 
- 		}
 
- 		if(isset($post['s']))  
 
- 		{
 
-             $id_arr = $this->input->post('s');
 
-             $id_arr =  explode(',',$id_arr);
 
-             if(!$id_arr)
 
-             {
 
-                 echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
 
-             }
 
-             //循环删除记录
 
-             foreach ($id_arr as $v) 
 
- 		    {
 
-                 $this->customertt->remove($v);
 
-             }
 
-             echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));exit;
 
- 		}
 
- 	    $wlshop = $this->shop->find_all('1=1');
 
- 		$this->data['wlshop'] = $wlshop;
 
- 		$this->_Template('customertt_black_cx',$this->data);
 
- 	}
 
- 	//添加
 
- 	public function _add()
 
- 	{
 
- 		$user = $this->user->get_api($_SESSION['api']);
 
- 		if($user)
 
- 		{
 
- 		    $fgshop = "";$sid = "";
 
- 		    $user = explode('|',trim($user['shop'],'|'));
 
- 			foreach ($user as $value) 
 
- 		    {
 
- 				$fgshop .= " shop = ".$value." or";
 
- 				$sid .= " id = ".$value." or";
 
- 			}
 
- 		}
 
- 		$post = $this->input->post(NULL, TRUE);
 
- 		if(isset($post['shop']))
 
- 		{
 
- 			$post['shop'] = $this->input->post('shop',true);
 
- 			$post['source'] = $this->input->post('source',true);
 
- 			$post['level'] = $this->input->post('level',true);
 
- 			$post['country'] = $this->input->post('country',true);
 
- 			$name = $this->input->post('name',true);
 
- 			$post['name'] = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$name);
 
- 			$post['phone'] = $this->input->post('phone',true);
 
- 			$email = $this->input->post('email',true);
 
- 			$post['email'] = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$email);
 
- 			$post['province'] = $this->input->post('province',true);
 
- 			$post['city'] = $this->input->post('city',true);
 
- 			//$post['street'] = $this->input->post('street',true);
 
- 			$address = $this->input->post('address',true);
 
- 			$post['address'] = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$address);
 
- 			//$post['address2'] = $this->input->post('address2',true);
 
- 			$post['count'] = $this->input->post('count',true);
 
- 			$str = $post['phone'];
 
- 			preg_match_all('/[0-9]/u',$str,$result);
 
- 			$numphone = join('',$result[0]);
 
- 			$post['numphone'] = $numphone;
 
- 			$post['zhcx'] = $post['shop'].'-'.$post['email'];
 
- 			$kh = $this->customertt->get_email($post['email'],$post['shop']);
 
- 			if($kh)
 
- 			{
 
- 				echo json_encode(array('msg'=>'此客户已存在!','success'=>false));exit;
 
- 			}
 
- 			if($this->customertt->insert($post))
 
-         	{
 
- 				echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
 
-        	 	}
 
-        		else
 
-         	{
 
-            		echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
 
-         	}
 
- 		}
 
- 		 $country = $this->country->find_all('1=1','id,name','name asc');
 
- 		 $this->data['country'] = $country;
 
- 		 $wlshop = $this->shop->find_all("type = 1514 and (".rtrim($sid,'or').")");
 
- 		 $this->data['wlshop'] = $wlshop;
 
- 		$this->_Template('customertt_add',$this->data);
 
- 	}
 
- 	//修改
 
- 	public function _edit($arg_array)
 
- 	{
 
- 		$user = $this->user->get_api($_SESSION['api']);
 
- 		if($user)
 
- 		{
 
- 		    $fgshop = "";$sid = "";
 
- 		    $user = explode('|',trim($user['shop'],'|'));
 
- 			foreach ($user as $value) 
 
- 		    {
 
- 				$fgshop .= " shop = ".$value." or";
 
- 				$sid .= " id = ".$value." or";
 
- 			}
 
- 		}
 
- 		$post = $this->input->post(NULL, TRUE);
 
- 		if(isset($post['id']))
 
- 		{
 
- 			$id = $this->input->post('id',true);
 
- 			$us = $this->customertt->read($id);
 
- 			$post['shop'] = $this->input->post('shop',true);
 
- 			$post['source'] = $this->input->post('source',true);
 
- 			$post['level'] = $this->input->post('level',true);
 
- 			$post['country'] = $this->input->post('country',true);
 
- 			$name = $this->input->post('name',true);
 
- 			$post['name'] = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$name);
 
- 			$post['phone'] = $this->input->post('phone',true);
 
- 			$email = $this->input->post('email',true);
 
- 			$post['email'] = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$email);
 
- 			$post['province'] = $this->input->post('province',true);
 
- 			$post['city'] = $this->input->post('city',true);
 
- 			//$post['street'] = $this->input->post('street',true);
 
- 			$address = $this->input->post('address',true);
 
- 			$post['address'] = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$address);
 
- 			//$post['address2'] = $this->input->post('address2',true);
 
- 			$post['type'] = $this->input->post('type',true);
 
- 			$post['count'] = $this->input->post('count',true);
 
- 			$str = $post['phone'];
 
- 			preg_match_all('/[0-9]/u',$str,$result);
 
- 			$numphone = join('',$result[0]);
 
- 			$post['numphone'] = $numphone;
 
- 			$post['zhcx'] = $post['shop'].'-'.$post['email'];
 
- 			if($this->customertt->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];
 
- 		$customertt = $this->customertt->read($arg_array);
 
- 		$this->data['customertt'] = $customertt;
 
- 		$country = $this->country->find_all('1=1','id,name','name asc');
 
- 		$this->data['country'] = $country;
 
- 		 $wlshop = $this->shop->find_all("type = 1514 and (".rtrim($sid,'or').")");
 
- 		$this->data['wlshop'] = $wlshop;
 
- 		if($customertt['email'] != '0' && $customertt['email'] != '' && $customertt['email'] != '无')
 
- 		{
 
- 		    $fdata =  $this->fullordertt->find_all('email = "'.$customertt['email'].'" and shop = "'.$customertt['shop'].'" and mergeid = 0','orderinfo,state,product,name,email,dtime,shouldmoney','id desc');
 
- 		    foreach ($fdata as $k=>$v) 
 
- 		    {
 
- 				$d = $this->fullordertt->get_orderinfo($v['orderinfo']);
 
- 				$fdata[$k]['orderinfo'] = "<a href='/fullordertt/readonly/".$d['id']."'>".$v['orderinfo']."</a>";
 
- 		    	$typeclass = $this->typeclass->read($v['state']);
 
- 		    	$fdata[$k]['state'] = $typeclass['spare'];
 
- 		    	$fdata[$k]['dtime'] = date('Y-m-d',$v['dtime']);
 
- 		    }
 
- 		    $this->data['data'] = $fdata;
 
- 		}
 
- 		$this->_Template('customertt_edit',$this->data);
 
- 	}
 
- 	//删除
 
- 	public function _del()
 
- 	{
 
- 		$post = $this->input->post(NULL, TRUE);
 
- 		if(isset($post['s']))  
 
- 		{
 
-             $id_arr = $this->input->post('s');
 
-             $id_arr =  explode(',',$id_arr);
 
-             if(!$id_arr)
 
-             {
 
-                 echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
 
-             }
 
-             //循环删除记录
 
- 			$a=0;
 
-             foreach ($id_arr as $v) 
 
- 		    {
 
- 				$customertt = $this->customertt->read($v);
 
- 				if($customertt['email'] != '0' && $customertt['email'] != '' && $customertt['email'] != '无')
 
- 				{
 
- 		    		$fdata =  $this->fullordertt->find_count('email = "'.$customertt['email'].'" and shop = "'.$customertt['shop'].'" and mergeid = 0');
 
- 		        }
 
- 				if($fdata > 0)
 
- 				{
 
- 					$a++;
 
- 					continue;
 
- 				}
 
- 				else
 
- 				{
 
-                     $this->customertt->remove($v);
 
- 				}
 
-             }
 
- 			if($a > 0)
 
- 			{
 
-                 echo json_encode(array('del'=>$id_arr,'msg'=>'无订单客户删除成功,有订单的客户无法删除!','success'=>true));
 
- 			}
 
- 			else
 
- 			{
 
- 				echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
 
- 			}
 
- 		}
 
-     }
 
- 	//操作
 
- 	public function _change()
 
- 	{
 
- 		$post = $this->input->post(NULL, TRUE);
 
- 		if(isset($post['type']))  
 
- 		{
 
-             $type = $this->input->post('type',true);
 
- 			$id = $this->input->post('id',true);
 
- 			$count = $this->input->post('count',true);
 
-             if($this->customertt->save(array('type'=>$type,'count'=>$count,'typetime'=>time()),$id))
 
-         	{
 
-          		echo json_encode(array('msg'=>'操作成功!','success'=>true));exit;
 
-        	 	}
 
-        		else
 
-         	{
 
-            		echo json_encode(array('msg'=>'操作失败,请重试','success'=>false));exit;
 
-         	}
 
- 		}
 
-     }
 
- 	//修改客户分类
 
- 	public function _mdedit($arg_array)
 
- 	{
 
- 		$user = $this->user->get_api($_SESSION['api']);
 
- 		if($user)
 
- 		{
 
- 			$uu = $user;
 
- 		    $fgshop = "";$sid = "";
 
- 			$u = $user;
 
- 		    $user = explode('|',trim($user['shop'],'|'));
 
- 			foreach ($user as $value) 
 
- 		    {
 
- 				$fgshop .= " shop = ".$value." or";
 
- 				$sid .= " id = ".$value." or";
 
- 			}
 
- 		}
 
- 		$post = $this->input->post(NULL, TRUE);
 
- 		if(isset($post['shop']))
 
- 		{
 
- 			$fpcount = $this->input->post('fpcount',true);
 
- 			if(!$fpcount)
 
- 			{
 
- 				echo json_encode(array('msg'=>'需要先清理浏览器缓存,刷新当前页面后再试!','success'=>false));exit;
 
- 			}
 
- 			$customerttid = $this->input->post('customerttid',true);
 
- 			$shop = $this->input->post('shop',true);
 
- 			$sp = $this->shop->read($shop);
 
- 			$num = $this->fullordertt->find_count('shop = "'.$sp['id'].'" and gtime = "'.date('Ymd',time()).'"');
 
- 			$post['source'] = 1;//订单类型:1.线下订单2.PC3.手机
 
- 			$post['state'] = 207;//订单状态:207等待发货
 
- 			$post['review'] = 2;//审核状态:1.未送审2.待审核3.不通过4取消重审5.审核通过6.自动通过
 
- 			$post['print'] = 1;//打印状态:1.不可打印2.未打印3.已打印
 
- 			$post['library'] = 1;//出库状态:1.未出库2.已出库3.已退库
 
- 			$post['libraryconfirm'] = 1;//出库确认:1.不允许2.允许
 
- 			$post['link'] = $sp['link'];
 
- 			$post['issku'] = $sp['sku'];
 
- 			if($post['print'] != 3)
 
- 			{
 
- 			    $post['librarynot'] = "订单未打印,未审核或未通过";//不能出库原因
 
- 			}
 
- 			$orderinfo = $this->input->post('orderinfo',true);
 
- 			$post['shop'] = $sp['id'];
 
- 			$post['user'] = $sp['shopuser'];
 
- 			$post['number'] = $sp['shortname'].'-'.date('ymd',time()).'-'.(substr(strval($num+1+1000),1,3));//编号 
 
- 			if($orderinfo != "")
 
- 			{
 
- 				$ordefin = $this->fullordertt->get_orderinfo($orderinfo);
 
- 				if($ordefin)
 
- 				{
 
- 					echo json_encode(array('msg'=>'订单号重复!','success'=>false));exit;
 
- 				}
 
- 				else
 
- 				{
 
- 				    $post['orderinfo'] = $orderinfo;
 
- 				}
 
- 			}
 
- 			else
 
- 			{
 
- 			    $post['orderinfo'] = $sp['id'].date('ymdHis',time()).rand(0,1);//订单号
 
- 			}
 
- 			/**
 
- 			if($post['paypal'] != '')
 
- 			{
 
- 			    $pp = $this->fullordertt->get_paypal($post['paypal']);	
 
- 			    if($pp)
 
- 			    {
 
- 				    echo json_encode(array('msg'=>'此交易号的订单已存在!','success'=>false));exit;
 
- 			    }
 
- 		    }
 
- 			**/
 
- 			$post['client'] = $this->input->post('client',true);//客户名称
 
- 			$btime = $this->input->post('buytime',true);//付款时间
 
- 			$post['buytime'] = strtotime($btime);//时间转UX
 
- 			$post['dtime'] = time();//订单时间
 
- 			$post['gtime'] = date('Ymd',time());//格式化时间
 
- 			//$post['pay'] = $this->input->post('pay',true);//支付方式
 
- 			$post['capital'] = $this->input->post('capital',true);//资金状态
 
- 			$post['type'] = $this->input->post('warehouse',true);//发货仓库
 
- 			$post['currency'] = $this->input->post('currency',true);//币种
 
- 			$currency = $this->typeclass->read($post['currency']);
 
- 			$post['currencytitle'] = $currency['title'];//币种名称
 
- 			$post['freight'] = $this->input->post('freight',true);//运费
 
- 			$post['expressmoney'] = $this->input->post('expressmoney',true);//物流金额
 
- 			$post['shouldmoney'] = $this->input->post('shouldmoney',true);//应收金额
 
- 			$post['skje'] = $post['shouldmoney'];//收款金额
 
- 			$product = $this->input->post('product');//产品名称
 
- 			$product = str_replace(array('%26','%2B'),array('&','+'),$product);
 
- 			$post['product'] = preg_replace('/( | | |\s)/',' ',$product);
 
- 			$orderremarks = $this->input->post('orderremarks');//订单备注
 
- 			$orderremarks = str_replace(array('%26','%2B'),array('&','+'),$orderremarks);
 
- 			$post['orderremarks'] = preg_replace('/( | | |\s)/',' ',$orderremarks);
 
- 			$shipremarks = $this->input->post('shipremarks');//仓库品名
 
- 			$shipremarks = str_replace(array('%26','%2B'),array('&','+'),$shipremarks);//仓库品名
 
- 			$post['shipremarks'] = preg_replace('/( | | |\s)/',' ',$shipremarks);
 
- 			$post['email'] = $this->input->post('email',true);//邮箱
 
- 			$name = $this->input->post('name',true);//名称
 
- 			$post['name'] = preg_replace('/( | | |\s)/',' ',$name);
 
- 			$post['phone'] = $this->input->post('phone',true);//电话
 
- 			$post['phone'] = preg_replace('/\D/s','',$post['phone']);
 
- 			$post['country'] = $this->input->post('country',true);//国家
 
- 			$ct = $this->country->read($post['country']);//国家
 
- 			$post['al'] = $ct['lb'];//国家二字码
 
- 			$post['province'] = $this->input->post('province',true);//省、州
 
- 			$post['province'] = preg_replace("/^[\s\v".chr(227).chr(128)."]+/","", $post['province']); //替换开头空字符
 
-             $post['province'] = preg_replace("/[\s\v".chr(227).chr(128)."]+$/","", $post['province']); //替换结尾空字符
 
- 			$post['city'] = $this->input->post('city',true);//城市
 
- 			$post['city'] = preg_replace("/^[\s\v".chr(227).chr(128)."]+/","", $post['city']); //替换开头空字符
 
-             $post['city'] = preg_replace("/[\s\v".chr(227).chr(128)."]+$/","", $post['city']); //替换结尾空字符
 
- 			$post['zipcode'] = $this->input->post('zipcode',true);//邮编
 
- 			$post['zipcode'] = preg_replace("/^[\s\v".chr(227).chr(128)."]+/","", $post['zipcode']); //替换开头空字符
 
-             $post['zipcode'] = preg_replace("/[\s\v".chr(227).chr(128)."]+$/","", $post['zipcode']); //替换结尾空字符
 
- 			$post['address'] = $this->input->post('address',true);//地址
 
- 			$post['printtype'] = $this->input->post('printtype',true);//打印类型
 
- 			$fpdata = $this->input->post('fpdata');//购买产品内容
 
- 			$fpdata = str_replace(array('%26','%2B'),array('&','+'),$fpdata);
 
- 			$post['fpdata'] = $fpdata;
 
- 			$post['sbpm'] = $this->input->post('sbpm',true);//申报品名
 
- 			$post['zwpm'] = $this->input->post('zwpm',true);//中文品名
 
- 			$post['ts'] = $this->input->post('ts',true);//条数
 
- 			$post['dtsbjz'] = $this->input->post('dtsbjz',true);//单条申报价
 
- 			$post['zsbjz'] = $this->input->post('zsbjz',true);//总申报价
 
- 			$post['zzl'] = $this->input->post('zzl',true);//总重量
 
- 			$post['zjs'] = $this->input->post('zjs',true);//总件数
 
- 			$post['express'] = $this->input->post('express',true);//快递公司
 
- 			$post['printtype'] = $this->input->post('printtype',true);//打印类型
 
- 			$post['quantity'] = $this->input->post('quantity',true);//数量
 
- 			//$post['paypal'] = $this->input->post('paypal',true);//支付号
 
- 			//$post['guarantee'] = $this->input->post('guarantee',true);//卖家保障
 
- 			$post['msg'] = $this->input->post('msg',true);//发送留言类型
 
- 			$post['ioss'] = $this->input->post('ioss',true);
 
- 			$post['sbpm'] = $this->input->post('sbpm',true);
 
- 			//$pay = $this->pay->get_typeclass($post['pay']);
 
- 			$yga = $post['shouldmoney'];
 
- 			$post['budget'] = 0;
 
- 			/**
 
- 			if($pay)
 
- 			{
 
- 				$ygc = $pay['estimaterate'];//预估到账公式
 
- 				$ifbudget = eval("return $yga*1.$ygc;");
 
- 				$post['estimaterate'] = $pay['estimaterate'];
 
- 				if($ifbudget > 0)
 
- 				{
 
- 				    $post['budget'] = eval("return $yga*1.$ygc;");//预估到帐金额
 
- 				}
 
- 			}
 
- 			else
 
- 			{
 
- 				$ygb = $sp['estimaterate'];//店铺默认到账公式
 
- 				$ifbudget = eval("return $yga*1.$ygb;");
 
- 				$post['estimaterate'] = $sp['estimaterate'];
 
- 				if($ifbudget > 0)
 
- 				{
 
- 		    	    $post['budget'] = eval("return $yga*1.$ygb;");//预估到帐金额
 
- 				}
 
- 			}
 
- 			**/
 
- 			    $ygb = $sp['estimaterate'];//店铺默认到账公式
 
- 				$ifbudget = eval("return $yga*1.$ygb;");
 
- 				$post['estimaterate'] = $sp['estimaterate'];
 
- 				if($ifbudget > 0)
 
- 				{
 
- 		    	    $post['budget'] = eval("return $yga*1.$ygb;");//预估到帐金额
 
- 				}
 
- 			$baddress = $this->input->post('baddress',true);
 
- 			$saddress = $this->input->post('saddress',true);
 
- 			$baddress = array_reverse(explode(',',$baddress));
 
- 			$saddress = array_reverse(explode(',',$saddress));
 
- 			$bar = '';$sar = '';
 
- 			$cr = $this->country->read($post['country']);
 
- 			$baddress[1] = $cr['lb'];
 
- 			$saddress[1] = $cr['lb'];
 
- 			$baddress = array_reverse($baddress);
 
- 			$saddress = array_reverse($saddress);
 
- 			for($i=0;$i<count($baddress);$i++)
 
- 			{
 
- 				$bar .= $baddress[$i].',';
 
- 			}
 
- 			for($i=0;$i<count($saddress);$i++)
 
- 			{
 
- 				$sar .= $saddress[$i].',';
 
- 			}
 
- 			$post['baddress'] = rtrim($bar,',');//卖家保障
 
- 			$post['saddress'] = rtrim($sar,',');//卖家保障
 
- 			$whlabel = $this->input->post('whlabel',true);
 
- 			if($post['express'] == 2 && (stripos($post['name'],'&') !== false || stripos($post['name'],"'") !== false))
 
- 			{
 
- 				echo json_encode(array('msg'=>'USPS收件人或公司名不可用特殊符号!','success'=>false));exit;
 
- 			}
 
- 			if(strlen($post['client']) > 35 || strlen($post['name']) > 35)//收件人姓名或公司名不允许超过35位
 
- 			{
 
- 				echo json_encode(array('msg'=>'收件人姓名或公司名不可超过35个字符!','success'=>false));exit;
 
- 			}
 
- 			if(($post['express'] == '5' || $post['express'] == '24' || $post['express'] == '42' || $post['express'] == '31') && $post['country'] != 192)
 
- 			{
 
- 				echo json_encode(array('msg'=>'非美国无法选择Fedex、DHL官方-美国!','success'=>false));exit;
 
- 			}
 
- 			if($post['express'] == '3' && $post['country'] != 192 && $post['country'] != 35)
 
- 			{
 
- 				echo json_encode(array('msg'=>'非美国和加拿大无法选择UPS!','success'=>false));exit;
 
- 			}
 
- 			if($post['express'] == '3' && $post['country'] == 35 && $post['zsbjz'] > 20)
 
- 			{
 
- 				echo json_encode(array('msg'=>'UPS加拿大最高申报不可超过20','success'=>false));exit;
 
- 			}
 
- 			if($post['express'] == '2' && $post['warehouse'] != 5)
 
- 			{
 
- 				echo json_encode(array('msg'=>'非美国仓无法选择USPS!','success'=>false));exit;
 
- 			}
 
- 			if($post['express'] == '99' && $post['bx'] > 0)
 
- 			{
 
- 				echo json_encode(array('msg'=>'此物流不允许购买保险','success'=>false));exit;
 
- 			}
 
- 			if($post['express'] == 42 && $post['sbpm'] != 'Human Hair Wigs' && $post['sbpm'] != 'Human Hair Goods')//$post['express'] == 3 || 
 
- 			{
 
- 				echo json_encode(array('msg'=>'此快递方式必须选择Human Hair Wigs/Human Hair Goods!','success'=>false));exit;
 
- 			}
 
- 			if($post['express'] == 24 && $post['sbpm'] != 'Hair Sample' && $post['sbpm'] != 'Human Hair Wigs' && $post['sbpm'] != 'Human Hair Goods')//$post['express'] == 3 || 
 
- 			{
 
- 				echo json_encode(array('msg'=>'此快递方式必须选择Hair Sample/Human Hair Wigs/Human Hair Goods!','success'=>false));exit;
 
- 			}
 
- 			if($post['country'] != 192 && $post['express'] == 1 && $post['sbpm'] != 'Synthetic Hair Wigs' && $post['sbpm'] != 'Synthetic Hair Goods')//$post['express'] == 3 || 
 
- 			{
 
- 				echo json_encode(array('msg'=>'非美国选择官方DHL必须选择Synthetic Hair Wigs/Synthetic Hair Goods','success'=>false));exit;
 
- 			}
 
- 			/**
 
- 			if($post['pay'] == '22' && ($post['paypal'] == '' || $post['guarantee'] == ''))
 
- 			{
 
- 				echo json_encode(array('msg'=>'交易号和卖家保障必须填写','success'=>false));exit;
 
- 			}
 
- 			if($post['pay'] == '23' && $post['paypal'] == '')
 
- 			{
 
- 				echo json_encode(array('msg'=>'交易号必须填写','success'=>false));exit;
 
- 			}
 
- 			**/
 
- 			$express = $this->express->read($post['express']);
 
- 			if($post['zsbjz'] > $express['sbjz'])
 
- 			{
 
- 				echo json_encode(array('msg'=>'总申报价值不可超出'.$express['sbjz'],'success'=>false));exit;
 
- 			}
 
- 			if($post['shouldmoney'] > $express['shouldmoney'] && $express['shouldmoney'] != 0)
 
- 			{
 
- 				echo json_encode(array('msg'=>'订单金额不可超出'.$express['shouldmoney'],'success'=>false));exit;
 
- 			}
 
- 			if($express['ioss'] == 1 && $post['ioss'] == '')
 
- 			{
 
- 				 echo json_encode(array('msg'=>'此快递方式必须选择IOSS!','success'=>false));exit;
 
- 			}
 
- 			if(strlen($post['address']) > $express['addresssize'] || strlen($post['address2']) > $express['addresssize'])
 
- 			{
 
- 				echo json_encode(array('msg'=>'此快递方地址不可超出'.$express['addresssize'].'个字符','success'=>false));exit;
 
- 			}
 
- 			if(strlen($post['address']) < 5)
 
- 			{
 
- 				echo json_encode(array('msg'=>'地址不可留空!','success'=>false));exit;
 
- 			}
 
- 			if($post['express'] == '2' && $post['zzl'] > '16' && $post['js'] == '0')
 
- 			{
 
- 				echo json_encode(array('msg'=>'重量大于16不可按Ground Advantage提交!','success'=>false));exit;
 
- 			}
 
- 			if($post['express'] == '2' && isset($post['js']) && $post['js'] == '0'&& $post['qm'] == '1')
 
- 			{
 
- 				echo json_encode(array('msg'=>'Ground Advantage不可使用签名服务!','success'=>false));exit;
 
- 			}
 
- 			if(($post['express'] == '3' || $post['express'] == '42' || $post['express'] == '24') && $post['shouldmoney'] < 1)
 
- 			{
 
- 				echo json_encode(array('msg'=>'零金额订单不可发 UPS/DHL官方-美国/Fedex(杭州)','success'=>false));exit;
 
- 			}
 
- 			if($post['express'] == '42' && $post['zsbjz'] < 1)
 
- 			{
 
- 				echo json_encode(array('msg'=>'零申报金额不可发 DHL官方-美国','success'=>false));exit;
 
- 			}
 
- 			if($post['express'] == '6' && $post['province'] == '')
 
- 			{
 
- 				echo json_encode(array('msg'=>'选择DPEX必须填写州信息','success'=>false));exit;
 
- 			}
 
- 			//减少代码复用吧
 
- 			$lo_ret = $this->logic_order->checkEditCustomer($post);
 
- 			if($lo_ret['code'] != 1){
 
- 				echo json_encode(array('msg'=>$lo_ret['msg'],'success'=>false));exit;
 
- 			}
 
- 			/**
 
- 			$post['saddress']
 
- 			if($post['printtype'] == 1)//如果是运单
 
- 			{
 
- 				$post['productdescription'] = $this->input->post('productdescription',true);
 
- 			    $post['customs'] = $this->input->post('customs',true);
 
- 			}
 
- 			**/
 
- 			//开始注释 xyxg
 
- 			/**
 
- 			$warehousenew = $this->warehouse->read($post['type']);
 
- 			$ft = array();
 
- 			$ftdata = explode('|',rtrim($fpcount,'|'));
 
- 			foreach ($ftdata as $va)
 
- 			{
 
- 				$ftitle = '';
 
- 				$va = explode('-',trim($va,'-'));
 
- 				foreach ($va as $v)
 
- 			    {
 
- 					$v = $this->typeclass->read($v);
 
- 					$ftitle .= $v['title'].' ';
 
- 				}
 
- 				$ft[] = rtrim($ftitle,' ');
 
- 			}
 
- 			$kcyz = $this->whlabel->get_kc($post['state'],$post['state'],$warehousenew['zd'],$warehousenew['ys'],$post['type'],$whlabel,$fpcount,$ft,$post['number'],$shop);//新添加订单老状态state和新状态state一样,不用走删除占用步奏
 
- 			if($kcyz['t'] > '0')
 
- 			{
 
- 				echo $kcyz['m'];exit;
 
- 			}
 
- 			else
 
- 			{
 
- 			    if($this->fullordertt->insert($post))
 
-         	    {
 
- 					$cusnum = $this->customertt->read($customerttid);
 
- 					$this->customertt->save(array('num'=>$cusnum['num']+1,'time'=>$post['buytime']),$customerttid);
 
-          		    echo json_encode(array('msg'=>'下单成功','success'=>true));exit;
 
-        	 	    }
 
-        		    else
 
-         	    {
 
-            		    echo json_encode(array('msg'=>'下单失败,请重试','success'=>false));exit;
 
-         	    }
 
- 			}
 
- 			//结束注释 
 
- 			**/
 
- 			$dtctitle = array();
 
- 			$dictionaries = $this->typeclass->find_all();
 
- 			foreach ($dictionaries as $v)
 
- 			{
 
- 				$dtctitle[$v['id']] = array($v['title'],$v['bqsku']);
 
- 			}
 
- 			$fpdata = $post['fpdata'];
 
- 			if(stripos($fpdata,'-128-') !== false || stripos($fpdata,'-127-') !== false)
 
- 			{
 
- 			    $dfp =  explode(';',trim($fpdata,';'));
 
- 			    $fdata = '';
 
- 			    foreach ($dfp as $k=>$v)
 
- 			    {
 
- 				    $ptitleb = '';
 
- 				    $fp = explode('|',trim($v,'|'));
 
- 				    $fp0 = explode(',',$fp[0]);
 
- 				    $fp1 = explode('-',trim($fp0[1],'-'));
 
- 				    foreach ($fp1 as $vv)
 
- 				    {
 
- 					    $ptitleb .= isset($dtctitle[$vv])?$dtctitle[$vv][0].' ':'';
 
- 				    }
 
- 				    $ptitleb .= $dtctitle[$fp0[0]][1].'inch ';
 
- 				    $fp[1] = $ptitleb;
 
- 				    $fdata .= implode("|",$fp).";";
 
- 			    }
 
- 			    $fpdata = $fdata;
 
- 			}
 
- 			
 
- 			$warehouse = $this->warehouse->read($post['type']);
 
- 			if($warehouse['bdcountry'] != 0 && $post['country'] != $warehouse['bdcountry'])
 
- 			{
 
- 				echo json_encode(array('msg'=>'当前国家无法选择'.$warehouse['title'].'!','success'=>false));exit;
 
- 			}
 
- 			    $kcyz = $this->ck->get_kc($post['state'],$warehouse,$post['shop'],$post['number'],$whlabel,$fpdata);
 
- 			    if($kcyz['t'] > '0')
 
- 			    {
 
- 					echo $kcyz['m'];exit;
 
- 			    }
 
- 			    else if($kcyz['fpdata'] != '')
 
- 			    {
 
- 				    $post['whlabel'] = $kcyz['whlabel'];
 
- 				    $post['fpdata'] = $kcyz['fpdata'];
 
- 			    }
 
- 				$fl = $this->ck->get_fl($warehouse['hz'],$whlabel,$fpdata);
 
- 				$post['sfxh'] = $fl['sfxh'];
 
- 				$post['ckfl'] = $fl['ckfl'];
 
- 				
 
- 				//查询净重开始
 
- 			$post['jweight'] = $this->weight->get_weightcx($post['fpdata']);
 
- 			//查询净重结束
 
- 					$cusnum = $this->customertt->read($customerttid);
 
- 					$this->customertt->save(array('num'=>$cusnum['num']+1,'time'=>$post['buytime']),$customerttid);
 
- 					$this->fullordertt->insert($post);
 
- 					echo json_encode(array('msg'=>'下单成功','success'=>true));exit;
 
- 		}
 
- 		$arg_array = $arg_array[0];//用户ID
 
- 		$customertt = $this->customertt->read($arg_array);//用户信息
 
- 		$this->data['customertt'] = $customertt;
 
- 		$country = $this->country->find_all('1=1','id,name','name asc');//国家
 
- 		$this->data['country'] = $country;
 
- 		$express = $this->express->find_all();//物流商
 
- 		$this->data['express'] = $express;
 
- 		$bm = $this->country->read($customertt['country']);
 
- 		$this->data['bm'] = $bm;
 
- 		$wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
 
- 		$this->data['wlshop'] = $wlshop;
 
- 		$this->data['user'] = $u['userid'];
 
- 		$this->_Template('customertt_mdedit',$this->data);
 
- 	}
 
- 	//上传excel
 
- 	public function _excela()
 
- 	{
 
- 		$dir = '/data/excel/'.date('Ymd',time()).'/';
 
- 		$config['upload_path'] = '.'.$dir ;
 
- 		$config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
 
-         $config['allowed_types'] = 'xls|xlsx';
 
-         $config['max_size'] = 10240;
 
- 		$this->load->library('upload', $config);
 
- 		$this->upload->initialize($config);
 
-         if ($this->upload->do_upload('userfile'))
 
-         {
 
- 			$full_path = $dir.$this->upload->data('file_name');
 
- 			$fileName = '.' . $full_path;
 
-             if (!file_exists($fileName)) 
 
- 			{
 
- 				echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
 
-             }
 
- 			else
 
- 			{
 
- 				require_once "./data/excel/PHPExcel/IOFactory.php";
 
- 				@$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
 
- 				@$phpExcel->setActiveSheetIndex(0);// 设置为默认表
 
- 				$sheetCount = $phpExcel->getSheetCount();// 获取表格数量
 
- 				$row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
 
- 				$column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
 
- 				++$column;//如果列数大于26行
 
- 				$list = array();
 
- 				for ($i = 2; $i <= $row; $i++) // 行数循环
 
- 				{
 
- 					$data = array();
 
-                     for ($c = 'A'; $c != $column; $c++)  // 列数循环
 
- 	                {
 
- 						$data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
 
-                     }
 
- 					$list[] = $data;
 
-                 }
 
- 			}
 
- 			$i = 0;
 
- 		    $this->db->trans_begin();
 
- 		    foreach ($list as $key=>$value)
 
- 		    {
 
- 				$value['1'] = $value['1']?str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['1']):'';
 
- 				$value['7'] = $value['7']?str_replace('/( | | |\s)/','',$value['7']):'';
 
- 				if($value['7'] == "" || $value['11'] == "")
 
- 				{
 
- 					$i++;
 
- 					continue;
 
- 				}
 
- 				else
 
- 				{
 
- 					$value['7'] = str_replace('/( | | |\s)/','',$value['7']);
 
- 				}
 
- 				$shop = $this->shop->get_name($value['9']);
 
- 				if(!$shop)
 
- 				{
 
- 					$i++;
 
- 					continue;
 
- 				}
 
- 				if($value['11'] == 2)
 
- 				{
 
- 				    $repeat = $this->customertt->get_address($value['1']);//只判断地址
 
- 				}
 
- 				else
 
- 				{
 
- 					$repeat = $this->customertt->find_all('email = "'.$value[7].'" and shop = "'.$shop['id'].'"');//只判断邮箱
 
- 				}
 
- 				/*  判断邮箱和地址
 
- 				if($value['1'] == "" || $value['1'] == " ")
 
- 				{
 
- 					if($value['7'] == "" || $value['7'] == " ")
 
- 					{
 
- 						$repeat = 1;
 
- 					}
 
- 					else
 
- 					{
 
- 						$repeat = $this->customertt->get_email($value['7']);
 
- 					}
 
- 				}
 
- 				else
 
- 				{
 
- 					$repeat = $this->customertt->get_address($value['1']);
 
- 				}
 
- 				*/
 
- 				if(isset($repeat[0]['type']))
 
- 				{
 
- 					if($repeat[0]['type'] == $value['11'])
 
- 					{
 
- 						$i++;
 
- 					}
 
- 					else if($repeat[0]['type'] != $value['11'])
 
- 					{
 
- 						$this->customertt->save(array('type'=>$value['11']),$repeat[0]['id']);
 
- 					}
 
- 				}
 
- 				else
 
- 				{
 
- 					$source = $this->typeclass->get_title($value['10']);
 
- 					if($source)
 
- 					{
 
- 					    $post['name'] = ($value['0'] && $value['0'] != 'NULL')?str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['0']):'';
 
- 					    $post['email'] = $value['7'];
 
- 						if($value['5'] != '')
 
- 						{
 
- 					        $country = $this->country->get_ename(str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['5']));
 
- 							$post['country'] = $country['id'];
 
- 						}
 
- 						$post['level'] = $value['8']?$value['8']:5;
 
- 					    $post['phone'] = $value['6']?$value['6']:'';
 
- 					    $post['province'] = $value['3']?$value['3']:'';
 
- 					    $post['city'] = $value['2']?$value['2']:'';
 
- 					    $post['address'] = $value['1'];
 
- 					    $post['zipcode'] = $value['4']?$value['4']:'';
 
- 						$post['shop'] = $shop['id'];
 
- 					    $post['source'] = $source['id'];
 
- 						$post['type'] = $value['11'];
 
- 						$val12 = $value['12']?$value['12']:'';
 
- 						$post['count'] = $val12;
 
- 						$str = $post['phone'];
 
- 						preg_match_all('/[0-9]/u',$str,$result);
 
- 						$numphone = join('',$result[0]);
 
- 						$post['numphone'] = $numphone;
 
- 		    	        $this->customertt->insert($post);
 
- 					}
 
-                 }
 
- 			}
 
- 			if ($this->db->trans_status() === FALSE)
 
-             {
 
- 				$this->db->trans_commit();
 
- 				echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
 
-             }
 
-             else
 
-             {
 
- 				if(count($list) == $i)
 
- 				{
 
- 					$til = '导入全部失败!请检查导入信息';
 
- 				}
 
- 				else if(count($list) > $i && $i != 0)
 
- 				{
 
- 					$til = '部分导入成功!'.$i.'条信息有问题,请排查';
 
- 				}
 
- 				else  if($i < 1)
 
- 				{
 
- 					$til = '导入成功!';
 
- 				}
 
-                 $this->db->trans_commit();
 
- 				echo json_encode(array('msg'=>$til,'success'=>true));exit;
 
-             }
 
-         }
 
- 		else
 
- 		{
 
- 			echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
 
- 		}
 
-     }
 
- 	
 
- 	public function _indexexcel()//通过计数,2020/02/21已校准
 
- 	{
 
- 		$user = $this->user->get_api($_SESSION['api']);
 
- 		if($user)
 
- 		{
 
- 		    $fgshop = "";$sid = "";
 
- 		    $users = explode('|',trim($user['shop'],'|'));
 
- 			foreach ($users as $value) 
 
- 		    {
 
- 				$fgshop .= " shop = ".$value." or";
 
- 				$sid .= " id = ".$value." or";
 
- 			}
 
- 			if($user['vip'] == 1)
 
- 			{
 
- 				$vip = 1;
 
- 			}
 
- 			else
 
- 			{
 
- 				$vip = 0;
 
- 			}
 
- 		}
 
- 		else
 
- 		{
 
- 			$vip = 0;
 
- 		}
 
- 		$post = $this->input->post(NULL, TRUE);
 
- 		if(isset($_GET['timetk']))  
 
- 		{
 
- 			$shop = $this->input->get('shop',true);
 
- 			$numphone = $this->input->get('numphone',true);
 
- 			$name = $this->input->get('name',true);
 
- 			$email = $this->input->get('email',true);
 
- 			$address = $this->input->get('address',true);
 
- 			$level = $this->input->get('level',true);
 
- 			$num = $this->input->get('num',true);
 
- 			$country = $this->input->get('country',true);
 
- 			$excelid = $this->input->get('sid',true);
 
- 			$timetk = $this->input->get('timetk',true);
 
- 			$timetj = $this->input->get('timetj',true);
 
- 			$timetk = strtotime($timetk);
 
- 			$timetj = strtotime($timetj);
 
- 			$where = "1=1 and type = 1 and (".rtrim($fgshop,'or').")";
 
- 			if($shop)
 
-             {
 
-                 $where  .= " and shop = '$shop'";
 
-             }
 
- 			if($numphone)
 
-             {
 
-                 $where  .= " and numphone = '$numphone'";
 
-             }
 
- 			if($name)
 
-             {
 
-                 $where  .= " and name like '%$name%'";
 
-             }
 
- 			if($email)
 
-             {
 
-                 $where  .= " and email like '%$email%'";
 
-             }
 
- 			if($level)
 
-             {
 
-                 $where  .= " and level = '$level'";
 
-             }
 
- 			if($country)
 
-             {
 
-                 $where  .= " and country = '$country'";
 
-             }
 
- 			if($address)
 
-             {
 
-                 $where  .= " and address like '%$address%'";
 
-             }
 
- 			if($num > 0 && $num < 10 && $num != '2a')
 
-             {
 
-                 $where  .= " and num = '$num'";
 
-             }
 
- 			else if($num > 9)
 
-             {
 
-                 $where  .= " and num > '9'";
 
-             }
 
- 			else if($num == '2a')
 
-             {
 
-                 $where  .= " and num > '1'";
 
-             }
 
- 			else
 
- 			{
 
- 				$where  .= " and num >= '0'";
 
- 			}
 
- 			if($timetk && $timetj)
 
-             {
 
- 				$where  .= " and ((time > '$timetk' and time < '$timetj') or time = '0')";
 
-             }
 
- 			$xzid = '';
 
- 			if($excelid)
 
-             {
 
- 				$excelid = explode(',',trim($excelid,','));
 
- 				foreach ($excelid as $key=>$value) 
 
- 		        {
 
- 					$xzid .= " id = ".$value." or";
 
- 				}
 
-                 $where .= " and (".rtrim($xzid,'or').")";;
 
-             }
 
-             //数据排序
 
-             $order_str = "id desc";
 
- 			$numdata = array();
 
-             if(empty($page))
 
- 		    {
 
-                 $start = 0;
 
- 		    	$perpage = 1;
 
-             }
 
- 		    else
 
- 		    {
 
-                 $start = ($page - 1)*$perpage;
 
-             }
 
-             //取得信息列表
 
- 			$info_list = $this->customertt->find_all($where,'shop,name,email,phone,country,level,money,num,numphone,time,count',$order_str);
 
- 			foreach ($info_list as $key=>$value) 
 
- 		    {
 
- 				$shop = $this->shop->read($value['shop']);
 
- 				$info_list[$key]['shop'] = $shop['shopname'];
 
- 				if($value['country'] != 0)
 
- 				{
 
- 				    $country = $this->country->read($value['country']);
 
- 				    $info_list[$key]['country'] = $country['name'];
 
- 				}
 
- 				else
 
- 				{
 
- 					$info_list[$key]['country'] = "未知";
 
- 				}
 
- 				if($value['level'] == 1)
 
- 				{
 
- 					$info_list[$key]['level'] = "网红";
 
- 				}
 
- 				else if($value['level'] == 2)
 
- 				{
 
- 					$info_list[$key]['level'] = "批发";
 
- 				}
 
- 				else if($value['level'] == 3)
 
- 				{
 
- 					$info_list[$key]['level'] = "店铺转线下";
 
- 				}
 
- 				else if($value['level'] == 4)
 
- 				{
 
- 					$info_list[$key]['level'] = "线下其他";
 
- 				}
 
- 				else if($value['level'] == 5)
 
- 				{
 
- 					$info_list[$key]['level'] = "店内客户";
 
- 				}
 
- 				if($value['time'] != 0)
 
- 				{
 
- 					$info_list[$key]['time'] = date('Y-m-d',$value['time']);
 
- 				}
 
- 				else
 
- 				{
 
- 					$info_list[$key]['time'] = "无";
 
- 				}
 
- 				$info_list[$key]['numphone'] = ($value['num'] > 0 && $value['money'] > 0)?sprintf("%01.2f",$value['money']/$value['num']):0;
 
- 				if(isset($value['email']) && $user['excelpass'] == '1')
 
- 				{
 
- 					$emailpass = $this->setting->get_excelpass($value['email']);
 
- 					$info_list[$key]['email'] = $emailpass;
 
- 				}
 
- 				if(isset($value['phone']) && $user['excelpass'] == '1')
 
- 				{
 
- 					$phone = $this->setting->get_excelpass($value['phone']);
 
- 					$info_list[$key]['phone'] = $phone;
 
- 				}
 
- 		    }
 
- 			$title = "按条件导出"; 
 
-             $titlename = "<table border=1>
 
-             <tr align='center'>
 
- 			<td>店铺</td>
 
- 			<td>名称</td>
 
-             <td>邮箱</td>
 
- 			<td>电话</td>
 
- 			<td>国家</td>
 
- 			<td>类型</td>
 
- 			<td>总额</td>
 
- 			<td>成交次数</td>
 
- 			<td>客单价</td>
 
- 			<td>最后购买日期</td>
 
- 			<td>备注</td>
 
-             </tr>
 
-             </table>"; 
 
-             $filename = $title.".xls";
 
- 			$tail = "";
 
-             $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
 
- 		}
 
- 	}
 
- 	
 
- 	//下载excel
 
- 	public function _excel()
 
- 	{
 
- 		if(isset($_GET['excel']))  
 
- 		{
 
- 			if(isset($_SESSION['api']))
 
- 		    {
 
- 			    $user = $this->user->get_api($_SESSION['api']);
 
- 			    $usp = $user;
 
- 		        $fgshop = "";$sid = "";
 
- 		        $user = explode('|',trim($user['shop'],'|'));
 
- 			    foreach ($user as $value) 
 
- 		        {
 
- 				    $fgshop .= " shop = ".$value." or";
 
- 				    $sid .= " id = ".$value." or";
 
- 			    }
 
- 		    }
 
- 			$dowid = $this->input->get('a');
 
- 			$wid = "";
 
- 			if($dowid != "")
 
- 			{
 
- 				$id_arr =  explode(',',rtrim($dowid,','));
 
- 				$wid  .= " id = 0 or";
 
- 				foreach ($id_arr as $v) 
 
- 		        {
 
-                     $wid  .= " id = '$v' or";
 
-                 }
 
- 				$wid = " and".rtrim($wid,'or');
 
- 			}
 
- 			$excel = $this->input->get('excel',true);
 
- 			$page = $this->input->get('page',true);
 
- 		    $perpage = $this->input->get('perpage',true);
 
- 			$shop = $this->input->get('shop',true);
 
- 			$name = $this->input->get('name',true);
 
- 			$country = $this->input->get('country',true);
 
- 			$email = $this->input->get('email',true);
 
- 			$address = $this->input->get('address',true);
 
- 			$level = $this->input->get('level',true);
 
- 			$num = $this->input->get('num',true);
 
- 			$timetk = $this->input->get('timetk',true);
 
- 			$timetj = $this->input->get('timetj',true);
 
- 			$timetk = strtotime($timetk);
 
- 			$timetj = strtotime($timetj);
 
- 			$where = "1 = 1 and (".rtrim($fgshop,'or').")";
 
- 			if($shop)
 
-             {
 
-                 $where  .= " and shop = '$shop'";
 
-             }
 
- 			if($name)
 
-             {
 
-                 $where  .= " and name like '%$name%'";
 
-             }
 
- 			if($email)
 
-             {
 
-                 $where  .= " and email like '%$email%'";
 
-             }
 
- 			if($country)
 
-             {
 
-                 $where  .= " and country = '$country'";
 
-             }
 
- 			if($level)
 
-             {
 
-                 $where  .= " and level = '$level'";
 
-             }
 
- 			if($num != '')
 
- 			{
 
- 				$nu = 1;
 
- 			    if($num > 9)
 
-                 {
 
-                     $where  .= " and num > '9'";
 
-                 }
 
- 			    else if($num == '2a')
 
-                 {
 
-                     $where  .= " and num > '1'";
 
-                 }
 
- 				else
 
-                 {
 
-                     $where  .= " and num = '$num'";
 
-                 }
 
- 			}
 
- 			else
 
- 			{
 
- 				$nu = 2;
 
- 				$where  .= " and num >= '0'";
 
- 			}
 
- 			if($address)
 
-             {
 
-                 $where  .= " and address like '%$address%'";
 
-             }
 
- 			if($timetk && $timetj)
 
-             {
 
-                 $where  .= " and time > '$timetk' and time < '$timetj'";
 
-             }
 
- 			$where  .= " and type = 1";//白名单用户
 
- 			$info_list = array();
 
- 			if($excel == 2) //老客户列表
 
- 			{
 
- 				//$where = str_replace("level = '$level'","level > '1'",$where);
 
-                 $info_list = $this->customertt->find_all($where.$wid,'name,email,country,time,num,money,numphone','time desc');
 
- 				foreach ($info_list as $key=>$value) 
 
- 		        {
 
- 					$info_list[$key]['time'] = date('Y-m-d H:i:s',$value['time']);
 
- 					if($value['country'] != 0)
 
- 				    {
 
- 					    $country = $this->country->read($value['country']);
 
- 					    $info_list[$key]['country'] = $country['ename'];
 
- 					}
 
- 					else
 
- 					{
 
- 						$info_list[$key]['country'] = '';
 
- 					}
 
- 					$info_list[$key]['numphone'] = sprintf("%01.2f",$value['money']/$value['num']);
 
- 					if(isset($value['email']) && $usp['excelpass'] == '1')
 
- 					{
 
- 						$emailpass = $this->setting->get_excelpass($value['email']);
 
- 						$info_list[$key]['email'] = $emailpass;
 
- 					}
 
- 				}
 
- 				/**
 
-                 foreach ($info_list as $key=>$value) 
 
- 		        {
 
- 					$value['time'] = date('Y-m-d H:i:s',$value['time']);
 
- 					$d = $this->fullordertt->find_count('email = "'.$value['email'].'" and shop = "'.$value['shop'].'" and mergeid = 0','orderinfo,state,product,name,email,dtime,shouldmoney','time desc');
 
- 					if($d > 1)
 
- 					{
 
- 						$info_list[] = $v;
 
- 					}
 
- 				}
 
- 				**/
 
- 				
 
- 				$fzh = "<td>客户名</td><td>客户邮箱</td><td>客户国家</td><td>最近一次下单时间</td><td>购买次数</td><td>购买总金额</td><td>客单价</td>";
 
- 				$title = "老客户列表"; 
 
-             }
 
- 			else
 
- 			{
 
- 				$fdata = $this->customertt->find_all($where.$wid,'email,shop','time desc');
 
- 				foreach ($fdata as $key=>$value) 
 
- 		        {
 
- 					$d = $this->fullordertt->find_all('email = "'.$value['email'].'" and shop = "'.$value['shop'].'" and mergeid = 0   and  extra_status = 0 ','orderinfo,state,product,shipremarks,name,email,country,dtime,shouldmoney','time desc');
 
- 					if($nu == 2)
 
- 					{
 
- 					    if(count($d) > 1)
 
- 				  	    {
 
- 					        foreach ($d as $k=>$v) 
 
- 		                    {
 
- 						        $v['dtime'] = date('Y-m-d H:i:s',$v['dtime']);
 
- 						        $typeclass = $this->typeclass->read($v['state']);
 
- 		    	                $v['state'] = $typeclass['spare'];
 
- 							    if($v['country'] != 0)
 
- 				                {
 
- 							        $country = $this->country->read($v['country']);
 
- 							        $v['country'] = $country['ename'];
 
- 							    }
 
- 							    else
 
- 							    {
 
- 								    $v['country'] = '';
 
- 							    }
 
- 								if(isset($v['email']) && $usp['excelpass'] == '1')
 
- 								{
 
- 									$emailpass = $this->setting->get_excelpass($v['email']);
 
- 									$v['email'] = $emailpass;
 
- 								}
 
- 						        $info_list[] = $v;
 
- 					       }
 
- 						}
 
- 					}
 
- 					else
 
- 					{
 
- 						foreach ($d as $k=>$v) 
 
- 		                    {
 
- 						        $v['dtime'] = date('Y-m-d H:i:s',$v['dtime']);
 
- 						        $typeclass = $this->typeclass->read($v['state']);
 
- 		    	                $v['state'] = $typeclass['spare'];
 
- 							    if($v['country'] != 0)
 
- 				                {
 
- 							        $country = $this->country->read($v['country']);
 
- 							        $v['country'] = $country['ename'];
 
- 							    }
 
- 							    else
 
- 							    {
 
- 								    $v['country'] = '';
 
- 							    }
 
- 								if(isset($v['email']) && $usp['excelpass'] == '1')
 
- 								{
 
- 									$emailpass = $this->setting->get_excelpass($v['email']);
 
- 									$v['email'] = $emailpass;
 
- 								}
 
- 						        $info_list[] = $v;
 
- 					       }
 
- 					}
 
- 				}
 
- 				$fzh = "<td>订单号</td><td>订单状态</td><td>产品名</td><td>仓库品名</td><td>客户名</td><td>客户邮箱</td><td>客户国家</td><td>下单时间</td><td>订单金额</td>";
 
- 				$title = "老客户订单列表"; 
 
- 			}
 
-             $titlename = "<table border=1>
 
-             <tr>"
 
-             .$fzh.
 
-             "</tr>
 
-             </table>";
 
- 			$tail = "\n";
 
-             $filename =  $title.'-'.date('Ymd',time()).".xls";
 
-             $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
 
- 	    }
 
-     }
 
- 	//下载excel模板
 
- 	public function _bankdown()
 
- 	{
 
- 		if(isset($_GET['bankdown']))  
 
- 		{
 
- 			$numphone = $this->input->post('numphone',true);
 
- 			$xtime = $this->input->get('xtime',true);
 
- 			//$where = "1=1 and type = 2 and (".rtrim($fgshop,'or').")";
 
- 			$shop = $this->input->get('shop',true);
 
- 			$name = $this->input->get('name',true);
 
- 			$email = $this->input->get('email',true);
 
- 			$address = $this->input->get('address',true);
 
- 			$type = $this->input->get('type',true);
 
- 			$id = $this->input->get('id',true);
 
- 			$timetk = $this->input->get('timetk',true);
 
- 			$timetj = $this->input->get('timetj',true);
 
- 			$timetk = strtotime($timetk);
 
- 			$timetj = strtotime($timetj);
 
- 			if($type)
 
-             {
 
-                 $where = "type = '$type'";
 
-             }
 
- 			else
 
- 			{
 
- 				$where = "id != 0";
 
- 			}
 
- 			
 
- 			if($id)
 
-             {
 
- 				$id = explode('|',trim($id,'|'));
 
- 				$downid = '';
 
- 				foreach ($id as $value) 
 
- 		    	{
 
- 					$downid .= " id = ".$value." or";
 
- 				}
 
-                 $where .= " and (".rtrim($downid,'or').")";
 
-             }
 
- 			if(!$shop)
 
- 		    {
 
- 			    $user = $this->user->get_api($_SESSION['api']);
 
- 			    $usp = $user;
 
- 		        $fgshop = "";$sid = "";
 
- 		        $user = explode('|',trim($user['shop'],'|'));
 
- 			    foreach ($user as $value) 
 
- 		        {
 
- 				    $fgshop .= " shop = ".$value." or";
 
- 				    $sid .= " id = ".$value." or";
 
- 			    }
 
- 				$where .= " and (".rtrim($fgshop,'or').")";
 
- 		    }
 
- 			else
 
- 			{
 
- 				$where .= " and shop = '$shop'";
 
- 			}
 
- 			if($email)
 
-             {
 
-                 $where  .= " and email = '$email'";
 
-             }
 
- 			if($name)
 
-             {
 
-                 $where  .= " and name = '$name'";
 
-             }
 
- 			if($address)
 
-             {
 
-                 $where  .= " and address = '$address'";
 
-             }
 
- 			if($xtime)
 
-             {
 
-                 $where  .= " and typetime > '$timetk' and typetime < '$timetj'";
 
-             }
 
- 			 $info_list = $this->customertt->find_all($where,'name,address,city,province,zipcode,country,phone,email,level,shop,source,type,count,typetime');
 
- 			foreach ($info_list as $key=>$v) 
 
- 		    {
 
- 				$country = $this->country->read($v['country']);
 
- 				$info_list[$key]['country'] = $country['ename'];
 
- 				if($v['level'] == 1)
 
- 				{
 
- 					$info_list[$key]['level'] = '网红';
 
- 				}
 
- 				else if($v['level'] == 2)
 
- 				{
 
- 					$info_list[$key]['level'] = '批发';
 
- 				}
 
- 				else if($v['level'] == 3)
 
- 				{
 
- 					$info_list[$key]['level'] = '店铺转线下';
 
- 				}
 
- 				else if($v['level'] == 4)
 
- 				{
 
- 					$info_list[$key]['level'] = '线下其他';
 
- 				}
 
- 				else if($v['level'] == 5)
 
- 				{
 
- 					$info_list[$key]['level'] = '店内';
 
- 				}
 
- 				else
 
- 				{
 
- 					$info_list[$key]['level'] = '未知';
 
- 				}
 
- 				if($v['typetime'] != 0)
 
- 				{
 
- 					$info_list[$key]['typetime'] = date('Y-m-d',$v['typetime']);
 
- 				}
 
- 				else
 
- 				{
 
- 					$info_list[$key]['typetime'] = "无";
 
- 				}
 
- 				$shop = $this->shop->read($v['shop']);
 
- 				$info_list[$key]['shop'] = $shop['shopname'];
 
- 				$source = $this->typeclass->read($v['source']);
 
- 				$info_list[$key]['source'] = $source['title'];
 
- 			}
 
- 			$titledata = array('姓名','详细地址','城市','省/州','邮编','国家','电话','邮箱','类型(1:网红2:批发3:店铺转线下4:线下其他5:店内)','所属店铺(必须ERP已有店铺)','来源(数据字典的户来源需存在)','黑白名单(白名单填1或黑名单填2)','备注','客户分类时间');
 
- 			$fzh = "";
 
- 			foreach ($titledata as $v)
 
- 		    {
 
- 				$fzh .= "<td>".$v."</td>";
 
- 			}
 
-             $title = "客户导出";
 
-             $titlename = "<table border=1>
 
-             <tr>"
 
-             .$fzh.
 
-             "</tr>
 
-             </table>";
 
- 			$tail = "\n";
 
-             $filename = $title.".xls";
 
-             $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
 
- 	    }
 
- 	}
 
- 	//下载excel模板
 
- 	public function _down()
 
- 	{
 
- 		if(isset($_GET['excela']))  
 
- 		{
 
-             $title = "客户导入模板"; 
 
-             $titledata = array(array('姓名','详细地址','城市','省/州','邮编','国家','电话','邮箱','类型(1:网红2:批发3:店铺转线下4:线下其他5:店内)','所属店铺(必须ERP已有店铺)','来源(数据字典的户来源需存在)','黑白名单(白名单填1或黑名单填2)','备注'),array('lekia waites','700 Sandy Plains rd suite b14','marietta','Georgia','30066','United States','4047322519','lwaites@ccccare.com','5','supernovahair','独立站','1','备注'));
 
-             $filename = $title.".xls";
 
-             $this->customertt->get_excel($titledata,$filename);
 
- 	    }
 
- 	}
 
- 	public function _newold()
 
- 	{
 
- 		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['timek']))
 
- 		{
 
- 			$new = array();$old = array();$time=array();
 
- 			$timek = $this->input->post('timek',true);
 
- 			$timej = $this->input->post('timej',true);
 
- 			$k = strtotime($timek)-24*3600;//少一天为增加选择开始天时间
 
- 			$j = strtotime($timej);
 
- 			$n = ($j-$k)/(24*3600);
 
- 			if($n < 1)
 
- 			{
 
- 				$n = 1;
 
- 			}
 
- 			for($i=1;$i<$n;$i++)
 
- 		    {
 
- 				$nnum = 0;$onum = 0;
 
- 				$t = $j-($n*24*60*60)+($i*24*60*60);
 
- 			    $time[] = date('Y-m-d',$t);
 
- 				$ct = strtotime(date('Ymd',$t));
 
- 				$ctj = strtotime(date('Ymd',$t+24*3600));
 
- 				$info_list = $this->fullordertt->find_all("mergeid = '0' and dtime > '$ct' and dtime < '$ctj' and (".rtrim($fgshop,'or').")");
 
- 				foreach ($info_list as $value)
 
- 		    	{
 
- 					if($value['email'] != '0' && $value['email'] != '' && $value['email'] != '无')
 
- 		        	{
 
- 						$gnum =  $this->fullordertt->find_count("email = '".$value['email']."' and shop = '".$value['shop']."' and mergeid = 0");
 
- 						if($gnum >1)
 
- 						{
 
- 							$onum += 1;
 
- 						}
 
- 						else
 
- 						{
 
- 							$nnum += 1;
 
- 						}
 
- 					}
 
- 		        	else
 
- 					{
 
- 						$nnum += 1;
 
- 					}
 
- 				}
 
- 				$new[] = $nnum;
 
- 				$old[] = $onum;
 
- 			}
 
- 			echo @json_encode(array('time'=>$time,'cnew'=>$new,'cold'=>$old,'success'=>true));exit;
 
- 	    }
 
- 		$this->_Template('customertt_newold',$this->data);
 
- 	}
 
- }
 
 
  |