<?php
// +----------------------------------------------------------------------
// | Sunnyi 多语商城建站系统 (Build on ThinkPHP)
// +----------------------------------------------------------------------
// | Copyright (c) 2009 http://www.sunnyi.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 商易网络(admin@sunnyi.cn)
// +----------------------------------------------------------------------

// 会员配送
class UcConsigneeAction extends UserCenterAction {
	public function index()
	{
    	//初始化分页
    	$page = intval($_REQUEST[C("VAR_PAGE")]);
    	if($page==0)
    	$page = 1;
    	$result = D("UserConsignee")->getConsigneeList(intval($_SESSION['user_id']),$page);
    	
    	$this->assign("consignee_list",$result['list']);
    	//分页
		$page = new Page($result['total'],C("PAGE_LISTROWS"));   //初始化分页对象 		
		$p  =  $page->show();
        $this->assign('pages',$p);
        //end 分页  
        
        
        //输出一级地区
		$region_lv1_list = D("RegionConf")->where("pid=0")->order('name asc')->findAll();
		$this->assign("region_lv1_list_new",$region_lv1_list);
		
		$this->display("Page:user_center_frame");
	}	
	
	
	
	//修改
	public function modify()
	{
		  $data["region_lv1"] =  $_POST["region_lv1"];
  		  $data["region_lv2"] =  $_POST["region_lv2"];
  		  $data["region_lv3"] =	$_POST["region_lv3"];
  		  $data["region_lv4"] =    $_POST["region_lv4"];
		  $data["address"] =  $_POST["address"];
		  $data["consignee"] = $_POST["consignee"];
		  $data["zip"] = $_POST["zip"];
		  $data["fix_phone"] = $_POST["fix_phone"];
		  $data["fax_phone"] = $_POST["fax_phone"];
		  $data["mobile_phone"] = $_POST["mobile_phone"];
		  $data["id"] = $_POST["id"];
		  $data['user_id'] = intval($_SESSION['user_id']);

			//开始验证
	   		if($data['consignee']=="")
	   		{
	   			$this->error(L("CONSIGNEE_EMPTY"));
	   		}
   			if($data['fix_phone']=="")
	   		{
	   			$this->error(L("FIXPHONE_EMPTY"));
	   		}
   			if($data['zip']=="")
	   		{
	   			$this->error(L("ZIP_EMPTY"));
	   		}
   			if($data['address']=="")
	   		{
	   			$this->error(L("ADDRESS_EMPTY"));
	   		}
	   		
		  $rs = D("UserConsignee")->save($data);
		  $this->success(L("MODIFY_SUCCESS"));
	}
	
	//删除
	public function delete()
	{
		$id = intval($_REQUEST['id']);
		D("UserConsignee")->where("id=".$id)->delete();
		$this->success(L("DELETE_SUCCESS"));
	}
	
	//添加
	public function insert()
	{
		  $data["region_lv1"] =  $_POST["region_lv1"];
  		  $data["region_lv2"] =  $_POST["region_lv2"];
  		  $data["region_lv3"] =	$_POST["region_lv3"];
  		  $data["region_lv4"] =    $_POST["region_lv4"];
		  $data["address"] =  $_POST["address"];
		  $data["consignee"] = $_POST["consignee"];
		  $data["zip"] = $_POST["zip"];
		  $data["fix_phone"] = $_POST["fix_phone"];
		  $data["fax_phone"] = $_POST["fax_phone"];
		  $data["mobile_phone"] = $_POST["mobile_phone"];
		  $data['user_id'] = intval($_SESSION['user_id']);
		  
		  
		  
			//开始验证
	   		if($data['consignee']=="")
	   		{
	   			$this->error(L("CONSIGNEE_EMPTY"));
	   		}
   			if($data['fix_phone']=="")
	   		{
	   			$this->error(L("FIXPHONE_EMPTY"));
	   		}
   			if($data['zip']=="")
	   		{
	   			$this->error(L("ZIP_EMPTY"));
	   		}
   			if($data['address']=="")
	   		{
	   			$this->error(L("ADDRESS_EMPTY"));
	   		}
		  
		  
		  
		  $rs = D("UserConsignee")->add($data);
		  if($rs)
		  {
		  	$this->success(L("ADD_SUCCESS"));
		  }
		  else 
		  {
		  	$this->error(L("ADD_FAILED"));
		  }
	}
}
?>