<?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 AjaxAction extends SunnyiAction{
    	//获取子地区列表
	public function getChildRegion()
	{
		$pid = intval($_REQUEST['pid']);
		$childRegionList = M("RegionConf")->where("pid=".$pid)->field("id,name")->findAll();
		echo json_encode($childRegionList);
	}
	
	//修改显示方式
	public function changeListType()
	{
		$type = intval($_REQUEST['type']);
		Session::set("list_type",$type);
	}
	
    public function getOrderStatus()
    {
    	$sn = $_REQUEST['sn'];
    	$order_info = D("Order")->where("sn='".$sn."'")->find();
    	if(!$order_info)
    	{
    		$html = "<span style='color:#f30;'>".L("ORDER_NOT_EXIST")."</span>";
    	}
    	else 
    	{
    		$html =  "<span style='color:#f30;'>".L("ORDER_SN").":".$order_info['sn'].L("ORDER_STATUS_".$order_info['status'])."</span>";;
    	}
    	
    	echo $html;
    }
   
    public function subScribe()
    {
    	$email = $_REQUEST['email'];
    	if(check_mail($email))
    	{
    		if(D("MailAddressList")->where("mail_address='".$email."'")->count()>0||
    		D("User")->where("email='".$email."'")->count()>0)
    		{
    			echo L("EMAIL_EXIST");
    		}
    		else 
    		{
    			$data['mail_address'] = $email;
    			$data['status']  = 1;
    			if(D("MailAddressList")->add($data))    			
    				echo L("SUBSCRIBE_SUCCESS");
    				else 
    				echo L("SUBSCRIBE_FAILED");
    		}
    	}
    	else
    	{
    		echo L("EMAIL_FORMAT_ERROR");
    	}
    }

 	public function subScribeBack()
    {
    	$email = $_REQUEST['email'];
    	if(check_mail($email))
    	{
    		
    		if(D("MailAddressList")->where("mail_address='".$email."'")->getField("user_id")!=0||
    		D("User")->where("email='".$email."'")->count()>0
    		)
    		{
    			echo L("MEMBER_EMAIL");
    		}
    		elseif(D("MailAddressList")->where("mail_address='".$email."'")->count()==0)
    		{
    			echo L("EMAIL_NOT_EXIST");
    		}
    		else 
    		{
		  			if(D("MailAddressList")->where("mail_address='".$email."'")->delete())    			
    				echo L("SUBSCRIBEBACK_SUCCESS");
    				else 
    				echo L("SUBSCRIBEBACK_FAILED");
    		}
    	}
    	else
    	{
    		echo L("EMAIL_FORMAT_ERROR");
    	}
    }
    
	function getPayment(){
		$id = intval($_REQUEST ['id']);
		$sql_str = 'select a.*, b.unit, b.radio from '.C("DB_PREFIX").'Payment a left outer join '.C("DB_PREFIX").'currency b on b.id = a.currency where a.id = '.$id; 
		$model = D ("Payment");
		$vo = $model->query($sql_str);			
		echo json_encode($vo[0]);
	}    
}
?>