| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066 | 
							- <?php defined('BASEPATH') OR exit('No direct script access allowed');
 
- class Customersmt extends Start_Controller {
 
- 	public function __construct(){
 
- 		parent::__construct();
 
- 		$this->load->library('session');
 
- 		$this->load->_model('Model_customersmt','customersmt');
 
- 		$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_fullordersmt','fullordersmt');
 
- 		$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_classid','classid');
 
- 		$this->load->_model('Model_apiyy','apiyy');
 
- 		$this->load->_model('Model_whlabel_fc','whlabel_fc');
 
- 	}
 
- 	//定义方法的调用规则 获取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 == 'down')//黑名单
 
-         {
 
-              $this->_down();
 
-         }
 
- 		else
 
- 		{
 
- 			 $this->_index();
 
- 		}
 
-     }
 
- 	//管理
 
- 	public function _index()
 
- 	{
 
- 		$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);
 
- 			$name = $this->input->post('name',true);
 
- 			$fullname = $this->input->post('fullname',true);
 
- 			$userid = $this->input->post('userid',true);
 
- 			$address = $this->input->post('address',true);
 
- 			$level = $this->input->post('level',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($name)
 
-             {
 
-                 $where  .= " and name like '%$name%'";
 
-             }
 
- 			if($fullname)
 
-             {
 
-                 $where  .= " and fullname = '$fullname'";
 
-             }
 
- 			if($userid)
 
-             {
 
-                 $where  .= " and userid like '%$userid%'";
 
-             }
 
- 			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)";
 
-             }
 
-             //数据排序
 
-             $order_str = "id desc";
 
-             if(empty($page))
 
- 		    {
 
-                 $start = 0;
 
- 		    	$perpage = 1;
 
-             }
 
- 		    else
 
- 		    {
 
-                 $start = ($page - 1)*$perpage;
 
-             }
 
-             //取得信息列表
 
-             $info_list = $this->customersmt->find_all($where,'id,shop,source,name,fullname,country,level,money,num,time,count,type',$order_str,$start,$perpage);
 
- 			foreach ($info_list as $key=>$value) 
 
- 		    {
 
- 				$us = $this->customersmt->read($value['id']);
 
- 				$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['fullname'] != '')
 
- 		        {
 
- 					$info_list[$key]['num'] =  $this->fullordersmt->find_count('fullname = "'.$value['fullname'].'" and shop = "'.$value['shop'].'" and mergeid = 0 and buytime != 0');
 
- 				}
 
- 		        else
 
- 				{
 
- 					$info_list[$key]['num'] = $this->fullordersmt->find_count('address = "'.$us['address'].'" and shop = "'.$value['shop'].'" and mergeid = 0 and buytime != 0');
 
- 				}
 
- 				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='/customersmt/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>";
 
- 		    }
 
- 		    $total = $this->customersmt->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('customersmt',$this->data);
 
- 	}
 
- 	//管理
 
- 	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);
 
- 			$name = $this->input->post('name',true);
 
- 			$userid = $this->input->post('userid',true);
 
- 			$address = $this->input->post('address',true);
 
- 			$where = "1=1 and type = 2 and (".rtrim($fgshop,'or').")";
 
- 			//$where = "1=1 and type = 2";
 
- 			if($shop)
 
-             {
 
-                 $where  .= " and shop = '$shop'";
 
-             }
 
- 			if($name)
 
-             {
 
-                 $where  .= " and name like '%$name%'";
 
-             }
 
- 			if($userid)
 
-             {
 
-                 $where  .= " and userid like '%$userid%'";
 
-             }
 
- 			if($address)
 
-             {
 
-                 $where  .= " and address like '%$address%'";
 
-             }
 
-             //数据排序
 
-             $order_str = "id desc";
 
-             if(empty($page))
 
- 		    {
 
-                 $start = 0;
 
- 		    	$perpage = 1;
 
-             }
 
- 		    else
 
- 		    {
 
-                 $start = ($page - 1)*$perpage;
 
-             }
 
-             //取得信息列表
 
-             $info_list = $this->customersmt->find_all($where,'id,shop,source,name,userid,address,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->customersmt->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'));
 
- 		$wlshop = $this->shop->find_all('1=1');
 
- 		$this->data['wlshop'] = $wlshop;
 
- 		$this->_Template('customersmt_black',$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);
 
- 			$userid = $this->input->post('userid',true);
 
- 			$post['userid'] = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$userid);
 
- 			$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);
 
- 			$post['zhcx'] = $post['shop'].'-'.$post['userid'];
 
- 			if($this->customersmt->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 = 270 and (".rtrim($sid,'or').")");
 
- 		 $this->data['wlshop'] = $wlshop;
 
- 		$this->_Template('customersmt_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->customersmt->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);
 
- 			$userid = $this->input->post('userid',true);
 
- 			$post['userid'] = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$userid);
 
- 			$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);
 
- 			$post['zhcx'] = $post['shop'].'-'.$post['userid'];
 
- 			if($this->customersmt->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];
 
- 		$customersmt = $this->customersmt->read($arg_array);
 
- 		$this->data['customersmt'] = $customersmt;
 
- 		$country = $this->country->find_all('1=1','id,name','name asc');
 
- 		$this->data['country'] = $country;
 
- 		 $wlshop = $this->shop->find_all("type = 270 and (".rtrim($sid,'or').")");
 
- 		$this->data['wlshop'] = $wlshop;
 
- 		if($customersmt['userid'] != '')
 
- 		{
 
- 		    $fdata =  $this->fullordersmt->find_all('userid = "'.$customersmt['userid'].'" and shop = "'.$customersmt['shop'].'" and mergeid = 0','orderinfo,state,product,name,client,buytime,shouldmoney','id desc');
 
- 		    foreach ($fdata as $k=>$v) 
 
- 		    {
 
- 		    	$typeclass = $this->typeclass->read($v['state']);
 
- 		    	$fdata[$k]['state'] = $typeclass['title'];
 
- 		    	$fdata[$k]['buytime'] = date('Y-m-d',$v['buytime']);
 
- 		    }
 
- 		    $this->data['data'] = $fdata;
 
- 		}
 
- 		else
 
- 		{
 
- 		    $fdata =  $this->fullordersmt->find_all('address = "'.$customersmt['address'].'" and shop = "'.$customersmt['shop'].'" and mergeid = 0','orderinfo,state,product,name,client,buytime,shouldmoney','id desc');
 
- 		    foreach ($fdata as $k=>$v) 
 
- 		    {
 
- 		    	$typeclass = $this->typeclass->read($v['state']);
 
- 		    	$fdata[$k]['state'] = $typeclass['title'];
 
- 		    	$fdata[$k]['buytime'] = date('Y-m-d',$v['buytime']);
 
- 		    }
 
- 		    $this->data['data'] = $fdata;
 
- 		}
 
- 		$this->_Template('customersmt_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) 
 
- 		    {
 
- 				$customer = $this->customersmt->read($v);
 
- 				if($customer['email'] != '0' && $customer['email'] != '' && $customer['email'] != '无')
 
- 				{
 
- 		    		$fdata =  $this->fullordersmt->find_count('email = "'.$customer['email'].'" and shop = "'.$customer['shop'].'" and mergeid = 0');
 
- 					if($fdata > 0)
 
- 				    {
 
- 					   $a++;
 
- 					    continue;
 
- 				    }
 
- 				    else
 
- 				    {
 
-                         $this->customersmt->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->customersmt->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)
 
- 		{
 
- 		    $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']))
 
- 		{
 
- 			$fpcount = $this->input->post('fpcount',true);
 
- 			if(!$fpcount)
 
- 			{
 
- 				echo json_encode(array('msg'=>'需要先清理浏览器缓存,刷新当前页面后再试!','success'=>false));exit;
 
- 			}
 
- 			$customerid = $this->input->post('customerid',true);
 
- 			$shop = $this->input->post('shop',true);
 
- 			$sp = $this->shop->read($shop);
 
- 			$num = $this->fullordersmt->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['dlz'] = 3;//不需要声明
 
- 			$post['link'] = $sp['link'];
 
- 			$post['sku'] = $sp['sku'];
 
- 			if($post['print'] != 3)
 
- 			{
 
- 			    $post['librarynot'] = "订单未打印,未审核或未通过";//不能出库原因
 
- 			}
 
- 			$orderinfo = $this->input->post('orderinfo',true);
 
- 			if($orderinfo)
 
- 			{
 
- 			    $arr=strlen($orderinfo);
 
- 			    if($arr < 14 || $arr > 19)
 
- 			    {
 
- 			    	echo json_encode(array('msg'=>'订单号必须大于13位小于20位!','success'=>false));exit;
 
- 			    }
 
- 			}
 
- 			if($post['paypal'] != '')
 
- 			{
 
- 			$pp = $this->fullordersmt->get_paypal($post['paypal']);	
 
- 			if($pp)
 
- 			{
 
- 				echo json_encode(array('msg'=>'此交易号的订单已存在!','success'=>false));exit;
 
- 			}
 
- 			}
 
- 			$post['shop'] = $sp['id'];
 
- 			$post['user'] = $sp['shopuser'];
 
- 			$nut = time();
 
- 			$nma = substr(date('ymd',$nut),1);
 
- 			$nmb = substr(strval($num+1+1000),1,3);
 
- 			$post['number'] = $sp['shortname'].'-'.$nma.'-'.$nmb;//编号
 
- 			$post['numberpx'] = date('ymd',$nut)*10000+$nmb;//按编号排序
 
- 			if($orderinfo != "")
 
- 			{
 
- 				$ordefin = $this->fullordersmt->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);//订单号
 
- 			}
 
- 			$dtime = time();
 
- 			$post['client'] = $this->input->post('client',true);//客户名称
 
- 			$btime = $this->input->post('buytime',true);//付款时间
 
- 			$post['buytime'] = $btime?strtotime($btime):$dtime;//时间转UX
 
- 			$post['dtime'] =$dtime;//订单时间
 
- 			$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);
 
- 			$name = $this->input->post('name',true);//名称
 
- 			$post['name'] = preg_replace('/( | | |\s)/',' ',$name);
 
- 			$post['phone'] = $this->input->post('phone',true);//电话
 
- 			$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['city'] = $this->input->post('city',true);//城市
 
- 			$post['zipcode'] = $this->input->post('zipcode',true);//邮编
 
- 			$post['address'] = $this->input->post('address',true);//地址
 
- 			$post['express'] = $this->input->post('express',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['pay'] = $this->input->post('pay',true);//支付方式
 
- 			$post['ioss'] = $this->input->post('ioss',true);
 
- 			$post['sbpm'] = $this->input->post('sbpm',true);
 
- 			$whlabel = $this->input->post('whlabel',true);
 
- 			$pay = $this->pay->get_typeclass($post['pay']);
 
- 			$yga = $post['shouldmoney'];
 
- 			$post['budget'] = 0;
 
- 			if($pay)
 
- 			{
 
- 				$ygc = $pay['estimaterate'];//预估到账公式
 
- 				$post['estimaterate'] = $pay['estimaterate'];
 
- 				$ifbudget = eval("return $yga*1.$ygc;");
 
- 				if($ifbudget > 0)
 
- 				{
 
- 				    $post['budget'] = eval("return $yga*1.$ygc;");//预估到帐金额
 
- 				}
 
- 			}
 
- 			else
 
- 			{
 
- 				$ygb = $sp['estimaterate'];//店铺默认到账公式
 
- 				$post['estimaterate'] = $sp['estimaterate'];
 
- 				$ifbudget = eval("return $yga*1.$ygb;");
 
- 				if($ifbudget > 0)
 
- 				{
 
- 		    	    $post['budget'] = eval("return $yga*1.$ygb;");//预估到帐金额
 
- 				}
 
- 			}
 
- 			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'] == '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['express'] == '2' && $post['warehouse'] != 5)
 
- 			{
 
- 				echo json_encode(array('msg'=>'非美国仓无法选择USPS!','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($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;
 
- 			}
 
- 			/**
 
- 			$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->fullordersmt->insert($post))
 
-         	    {
 
- 					$cusnum = $this->customersmt->read($customerid);
 
- 					$this->customersmt->save(array('num'=>$cusnum['num']+1,'time'=>$post['buytime']),$customerid);
 
-          		    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->customersmt->read($customerid);
 
- 					$this->customersmt->save(array('num'=>$cusnum['num']+1,'time'=>$post['buytime']),$customerid);
 
- 					$this->fullordersmt->insert($post);
 
- 					echo json_encode(array('msg'=>'下单成功','success'=>true));exit;
 
- 		}
 
- 		$arg_array = $arg_array[0];//用户ID
 
- 		$customersmt = $this->customersmt->read($arg_array);//用户信息
 
- 		$this->data['customersmt'] = $customersmt;
 
- 		$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($customersmt['country']);
 
- 		$this->data['bm'] = $bm;
 
- 		$wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
 
- 		$this->data['wlshop'] = $wlshop;
 
- 		$this->data['user'] = $user;
 
- 		$this->_Template('customersmt_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['0'] == "" || $value['1'] == "" || $value['6'] == "" || $value['11'] == "")
 
- 				{
 
- 					$i++;
 
- 					continue;
 
- 				}
 
- 				$shop = $this->shop->get_name($value['9']);
 
- 				if(!$shop)
 
- 				{
 
- 					$i++;
 
- 					continue;
 
- 				}
 
- 				if($value['11'] == 2)
 
- 				{
 
- 				    $repeat = $this->customersmt->get_address($value['1']);//只判断地址
 
- 				}
 
- 				else
 
- 				{
 
- 					$repeat = $this->customersmt->find_all('name = "'.$value[0].'" and address = "'.$value[1].'" and phone = "'.$value[6].'" and shop = "'.$shop['id'].'"');//只判断邮箱
 
- 				}
 
- 				/*  判断邮箱和地址
 
- 				if($value['1'] == "" || $value['1'] == " ")
 
- 				{
 
- 					if($value['7'] == "" || $value['7'] == " ")
 
- 					{
 
- 						$repeat = 1;
 
- 					}
 
- 					else
 
- 					{
 
- 						$repeat = $this->customersmt->get_userid($value['7']);
 
- 					}
 
- 				}
 
- 				else
 
- 				{
 
- 					$repeat = $this->customersmt->get_address($value['1']);
 
- 				}
 
- 				*/
 
- 				if(isset($repeat['type']))
 
- 				{
 
- 					if($repeat['type'] == $value['11'])
 
- 					{
 
- 						$i++;
 
- 					}
 
- 					else if($repeat['type'] != $value['11'])
 
- 					{
 
- 						$this->customersmt->save(array('type'=>$value['11']),$repeat['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['userid'] = $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;
 
- 		    	        $this->customersmt->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;
 
- 		}
 
-     }
 
- 	
 
- 	//下载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);
 
- 			$userid = $this->input->get('userid',true);
 
- 			$address = $this->input->get('address',true);
 
- 			$level = $this->input->get('level',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($userid)
 
-             {
 
-                 $where  .= " and userid like '%$userid%'";
 
-             }
 
- 			if($level)
 
-             {
 
-                 $where  .= " and level = '$level'";
 
-             }
 
- 			if($address)
 
-             {
 
-                 $where  .= " and address like '%$address%'";
 
-             }
 
- 			if($timetk && $timetj)
 
-             {
 
-                 $where  .= " and time > '$timetk' and time < '$timetj'";
 
-             }
 
- 			$where  .= " and type = 1";//白名单用户
 
- 			if($excel == 2) //老客户列表
 
- 			{
 
-                 $info_list = $this->customersmt->find_all($where.$wid,'name,userid,time,num,money','time desc');
 
-                 foreach ($info_list as $key=>$value) 
 
- 		        {
 
- 					$info_list[$key]['time'] = date('Y-m-d H:i:s',$value['time']);
 
- 				}
 
- 				$fzh = "<td>客户名</td><td>客户邮箱</td><td>最近一次下单时间</td><td>购买次数</td><td>购买总金额</td>";
 
- 				$title = "老客户列表"; 
 
-             }
 
- 			else
 
- 			{
 
- 				$info_list = array();
 
- 				$fdata = $this->customersmt->find_all($where.$wid,'userid,shop','time desc');
 
- 				foreach ($fdata as $key=>$value) 
 
- 		        {
 
- 					$d = $this->fullordersmt->find_all('userid = "'.$value['userid'].'" and shop = "'.$value['shop'].'" and mergeid = 0','orderinfo,state,product,name,userid,dtime,shouldmoney','time desc');
 
- 					foreach ($d as $k=>$v) 
 
- 		            {
 
- 						$typeclass = $this->typeclass->read($v['state']);
 
- 		    	        $v['state'] = $typeclass['spare'];
 
- 						$info_list[] = $v;
 
- 					}
 
- 				}
 
- 				$fzh = "<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 _down()
 
- 	{
 
- 		if(isset($_GET['excela']))  
 
- 		{
 
-             $title = "客户导入模板"; 
 
-             $titledata = array(array('姓名(必填)','详细地址(必填)','城市','省/州','邮编','国家','电话(必填)','客户ID','类型(1:网红2:批发3:店铺转线下4:线下其他5:店内)','所属店铺(必须ERP已有店铺)','来源(数据字典的户来源需存在)','黑白名单(白名单填1或黑名单填2,必填)','备注'),array('lekia waites','700 Sandy Plains rd suite b14','marietta','Georgia','30066','United States','4047322519','123456','5','Ali Pearl Hair','速卖通','1','备注'));
 
-             $filename = $title.".xls";
 
-             $this->customersmt->get_excel($titledata,$filename);
 
- 	    }
 
- 	}
 
- }
 
 
  |