| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501 | <?php defined('BASEPATH') OR exit('No direct script access allowed');class Purchaseorder extends Start_Controller {	public function __construct(){		parent::__construct();		$this->load->library('session');		$this->load->_model('Model_purchaseorder','purchaseorder');		$this->load->_model('Model_purchase','purchase');		$this->load->_model('Model_shop','shop');		$this->load->_model('Model_typeclass','typeclass');		$this->load->_model('Model_express','express');		$this->load->_model('Model_country','country');		$this->load->_model('Model_productdescribe','productdescribe');		$this->load->_model('Model_customs','customs');		$this->load->_model('Model_detailed','detailed');		$this->load->_model('Model_productdescription','productdescription');		$this->load->_model('Model_logistics','logistics');		$this->load->_model('Model_hl','hl');		$this->load->_model('Model_excel','excel');		$this->load->_model('Model_warehouse','warehouse');	}	//定义方法的调用规则 获取URI第二段值    public function _remap($arg,$arg_array)    {		if($arg == 'add')//添加        {             $this->_add();        }		else if($arg == 'edit')//修改        {             $this->_edit($arg_array);        }		else if($arg == 'price')//获取供应商价格表        {             $this->_price();        }		else if($arg == 'del')//修改        {             $this->_del();        }		else if($arg == 'describe')        {             $this->_describe();        }		else if($arg == 'list')        {             $this->_list();        }		else if($arg == 'monitor')        {             $this->_monitor();        }		else if($arg == 'lssue')        {             $this->_lssue();        }		else		{			 $this->_index();		}    }	//管理	public function _index()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['page']))  		{		    $page = $this->input->post('page',true);		    $perpage = $this->input->post('perpage',true);			$purchase = $this->input->post('purchase',true);//供应商			$orderinfo = $this->input->post('orderinfo',true);//订单号			$type = $this->input->post('type',true);//订单状态			$ktime = $this->input->post('ktime',true);			$jtime = $this->input->post('jtime',true);			$ktime = strtotime($ktime);			$jtime = strtotime($jtime);			$where = "1=1";			if($purchase)            {                $where  .= " and purchase = '$purchase'";            }			if($ktime && $jtime)            {                $where  .= " and addtime > '$ktime' and addtime < '$jtime'";            }			if($orderinfo)            {                $where  .= " and orderinfo = '$orderinfo'";            }			if($type)            {                $where  .= " and type = '$type'";            }            //数据排序            $order_str = "id desc";            if(empty($page))		    {                $start = 0;		    	$perpage = 1;            }		    else		    {                $start = ($page - 1)*$perpage;            }            //取得信息列表            $info_list = $this->purchaseorder->find_all($where,'id,purchase,orderinfo,type,time,addtime,monitor',$order_str,$start,$perpage);			 //格式化数据            foreach ($info_list as $key=>$value) 		    {				$purchase = $this->purchase->read($value['purchase']);				$info_list[$key]['purchase'] = $purchase['title'];				if($value['type'] == 1)				{					$info_list[$key]['type'] = "待发货";				}				else if($value['type'] == 2)				{					$info_list[$key]['type'] = "已发货";				}				else if($value['type'] == 3)				{					$info_list[$key]['type'] = "已验收";				}				$info_list[$key]['time'] = date('Y-m-d',$value['time']);				$info_list[$key]['addtime'] = date('Y-m-d H:i:s',$value['addtime']);				if($value['monitor'] == 0)				{					$info_list[$key]['monitor'] = "";				}				else				{				    $info_list[$key]['monitor'] = date('Y-m-d H:i:s',$value['monitor']);				}            }		    $total = $this->purchaseorder->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;		}		$this->data['purchase'] = $this->purchase->find_all();		$this->_Template('purchaseorder',$this->data);	}		//管理	public function _list()	{		$this->_Template('purchaseorder_list',$this->data);	}		//添加	public function _add()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['purchase']))		{			$post['purchase'] = $this->input->post('purchase',true);			$post['price'] = $this->input->post('price',true);			$post['warehouse'] = $this->input->post('warehouse',true);			$time = $this->input->post('time',true);			$post['time'] = strtotime($time);			$post['money'] = $this->input->post('money',true);			$post['content'] = $this->input->post('content',true);			$post['client'] = $this->input->post('client');			$post['name'] = $this->input->post('name',true);			$post['phone'] = $this->input->post('phone',true);			$post['country'] = $this->input->post('country',true);			$post['province'] = $this->input->post('province',true);			$post['city'] = $this->input->post('city',true);			$post['zipcode'] = $this->input->post('zipcode',true);			$post['street'] = $this->input->post('street',true);			$post['address'] = $this->input->post('address',true);			$post['express'] = $this->input->post('express',true);			$post['product'] = $this->input->post('fpdata',true);			$post['orderinfo'] = date('Ymd',time()).rand(100,999);			$post['addtime'] = time();			if($this->purchaseorder->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');//所有国家信息		$this->data['country'] = $country;		$purchase = $this->purchase->find_all('1=1','id,title');		$this->data['purchase'] = $purchase;		$this->_Template('purchaseorder_add',$this->data);		//$price = explode('|',trim($purchase['price'],'|'));//数组化权限内容		//$pricetitle = explode('|',trim($purchase['pricetitle'],'|'));//数组化权限内容	}	//修改	public function _edit($arg_array)	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['id']))		{			$id = $this->input->post('id',true);			$post['purchase'] = $this->input->post('purchase',true);			$post['price'] = $this->input->post('price',true);			$post['warehouse'] = $this->input->post('warehouse',true);			$time = $this->input->post('time',true);			$post['time'] = strtotime($time);			$post['money'] = $this->input->post('money',true);			$post['content'] = $this->input->post('content',true);			$post['client'] = $this->input->post('client');			$post['name'] = $this->input->post('name',true);			$post['phone'] = $this->input->post('phone',true);			$post['country'] = $this->input->post('country',true);			$post['province'] = $this->input->post('province',true);			$post['city'] = $this->input->post('city',true);			$post['zipcode'] = $this->input->post('zipcode',true);			$post['street'] = $this->input->post('street',true);			$post['address'] = $this->input->post('address',true);			$post['express'] = $this->input->post('express',true);			$post['product'] = $this->input->post('fpdata',true);			if($this->purchaseorder->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];		$purchaseorder = $this->purchaseorder->read($arg_array);		$country = $this->country->find_all('1=1','id,name');//所有国家信息		$this->data['purchaseorder'] = $purchaseorder;		//获取供应商价格表开始			$data = $this->purchase->read($purchaseorder['purchase']);			$priceid = explode('|',rtrim($data['price'],'|'));//数组内容			$pricetitle = explode('|',rtrim($data['pricetitle'],'|'));//数组内容			$price = array();			for($i=0;$i<count($priceid);$i++) 		    {			    $price[] = array('id'=>$priceid[$i],'title'=>$pricetitle[$i]);            }		//获取供应商价格表结束		$purchase = $this->purchase->find_all('1=1','id,title');		$this->data['purchase'] = $purchase;		$this->data['price'] = $price;		$this->data['country'] = $country;		$fpdata = explode('*',rtrim($purchaseorder['product'],'*'));		foreach ($fpdata as $k=>$v) 		{			$fpdata[$k] = explode('|',$v);        }		$this->data['fpdata'] = $fpdata;		$this->_Template('purchaseorder_edit',$this->data);	}	//查找供应商价格表	public function _price()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['id']))		{			$id = $this->input->post('id',true);			$data = $this->purchase->read($id);			$priceid = explode('|',rtrim($data['price'],'|'));//数组内容			$pricetitle = explode('|',rtrim($data['pricetitle'],'|'));//数组内容			$price = array();			for($i=0;$i<count($priceid);$i++) 		    {			    $price[] = array('id'=>$priceid[$i],'title'=>$pricetitle[$i]);            }			echo json_encode(array('msg'=>($price),'success'=>true));exit;		}	}	//查找商品价格	public function _describe()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['data']))  		{            $data = $this->input->post('data');			$priceid = $this->input->post('priceid');            $data =  explode('-',$data);			$number = '';$num = count($data);            //循环删除记录            for($i=0;$i<$num-1;$i++)		    {				if($data[$i] != 0)				{				    $number=$number.$data[$i];					if($i == 2)				    {					    $number=$number.$data[$num-1];				    }				}            }			$list = $this->productdescribe->get_price($priceid,$number);			if($list)			{				echo json_encode(array('msg'=>($list),'n'=>$data[$num-1],'success'=>true));			}			else			{				echo json_encode(array('msg'=>'此信息没有配置价格!','n'=>$data[$num-1],'success'=>false));exit;			}		}    }	//删除	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;            }            //循环删除记录            foreach ($id_arr as $v) 		    {                $this->purchaseorder->remove($v);            }            echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));		}    }		//管理	public function _lssue()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['id']))  		{			$id = $this->input->post('id',true);			if($this->purchaseorder->save(array('type'=>2,'lssue'=>time()),$id))        	{         		echo json_encode(array('msg'=>'操作成功','id'=>$id,'success'=>true));exit;       	 	}       		else        	{           		echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;        	}		}		if(isset($post['page']))  		{		    $page = $this->input->post('page',true);		    $perpage = $this->input->post('perpage',true);			$purchase = $this->input->post('purchase',true);//供应商			$orderinfo = $this->input->post('orderinfo',true);//订单号			$type = $this->input->post('type',true);//订单状态			$ktime = $this->input->post('ktime',true);			$jtime = $this->input->post('jtime',true);			$ktime = strtotime($ktime);			$jtime = strtotime($jtime);			$where = "1=1 and type = 1";			if($purchase)            {                $where  .= " and purchase = '$purchase'";            }			if($ktime && $jtime)            {                $where  .= " and addtime > '$ktime' and addtime < '$jtime'";            }			if($orderinfo)            {                $where  .= " and orderinfo = '$orderinfo'";            }			if($type)            {                $where  .= " and type = '$type'";            }            //数据排序            $order_str = "id desc";            if(empty($page))		    {                $start = 0;		    	$perpage = 1;            }		    else		    {                $start = ($page - 1)*$perpage;            }            //取得信息列表            $info_list = $this->purchaseorder->find_all($where,'id,purchase,orderinfo,type,time,addtime,currency',$order_str,$start,$perpage);			 //格式化数据            foreach ($info_list as $key=>$value) 		    {				$purchase = $this->purchase->read($value['purchase']);				$info_list[$key]['purchase'] = $purchase['title'];				if($value['type'] == 1)				{					$info_list[$key]['type'] = "待发货";				}				else if($value['type'] == 2)				{					$info_list[$key]['type'] = "已发货";				}				else if($value['type'] == 3)				{					$info_list[$key]['type'] = "已验收";				}				$info_list[$key]['time'] = date('Y-m-d',$value['time']);				$info_list[$key]['addtime'] = date('Y-m-d H:i:s',$value['addtime']);				$info_list[$key]['currency'] = "<p><b class='purchaseorder' data-id='".$value['id']."'>标记为已发货</b></p>";            }		    $total = $this->purchaseorder->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;		}		$this->data['purchase'] = $this->purchase->find_all();		$this->_Template('purchaseorder_lssue',$this->data);	}	//管理	public function _monitor()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['id']))  		{			$id = $this->input->post('id',true);			if($this->purchaseorder->save(array('type'=>3,'monitor'=>time()),$id))        	{         		echo json_encode(array('msg'=>'操作成功','id'=>$id,'success'=>true));exit;       	 	}       		else        	{           		echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;        	}		}		if(isset($post['page']))  		{		    $page = $this->input->post('page',true);		    $perpage = $this->input->post('perpage',true);			$purchase = $this->input->post('purchase',true);//供应商			$orderinfo = $this->input->post('orderinfo',true);//订单号			$type = $this->input->post('type',true);//订单状态			$ktime = $this->input->post('ktime',true);			$jtime = $this->input->post('jtime',true);			$ktime = strtotime($ktime);			$jtime = strtotime($jtime);			$where = "1=1 and type = 2";			if($purchase)            {                $where  .= " and purchase = '$purchase'";            }			if($ktime && $jtime)            {                $where  .= " and addtime > '$ktime' and addtime < '$jtime'";            }			if($orderinfo)            {                $where  .= " and orderinfo = '$orderinfo'";            }			if($type)            {                $where  .= " and type = '$type'";            }            //数据排序            $order_str = "id desc";            if(empty($page))		    {                $start = 0;		    	$perpage = 1;            }		    else		    {                $start = ($page - 1)*$perpage;            }            //取得信息列表            $info_list = $this->purchaseorder->find_all($where,'id,purchase,orderinfo,type,time,addtime,lssue,currency',$order_str,$start,$perpage);			 //格式化数据            foreach ($info_list as $key=>$value) 		    {				$purchase = $this->purchase->read($value['purchase']);				$info_list[$key]['purchase'] = $purchase['title'];				if($value['type'] == 1)				{					$info_list[$key]['type'] = "待发货";				}				else if($value['type'] == 2)				{					$info_list[$key]['type'] = "已发货";				}				else if($value['type'] == 3)				{					$info_list[$key]['type'] = "已验收";				}				$info_list[$key]['time'] = date('Y-m-d',$value['time']);				$info_list[$key]['addtime'] = date('Y-m-d H:i:s',$value['addtime']);				$info_list[$key]['lssue'] = date('Y-m-d H:i:s',$value['lssue']);				$info_list[$key]['currency'] = "<p><b class='purchaseorder' data-id='".$value['id']."'>标记为已验收</b></p>";            }		    $total = $this->purchaseorder->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;		}		$this->data['purchase'] = $this->purchase->find_all();		$this->_Template('purchaseorder_monitor',$this->data);	}}
 |