<?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 PaymentAction extends CommonAction {
	
	function getPayment(){
		$id = intval($_REQUEST ['id']);
		$model = D ("Payment");
		$vo = $model->getById ($id);			
		echo json_encode($vo);
	}
		
	function getPaymentList(){
		$currency_id= intval($_REQUEST ['currency_id']);
		$model = D ("Payment");
		$voList = $model->field('id,name_'.DEFAULT_LANG_ID.' as name')->where("currency=".$currency_id)->findAll();			
		echo json_encode($voList);
	}	
	
	
	public function edit()
	{
		$name=$this->getActionName();
		$model = M ( $name );
		$id = $_REQUEST [$model->getPk ()];
		$vo = $model->getById ( $id );
		$vo['config'] = unserialize($vo['config']);	

		$payment_model = $vo['class_name']."Payment";
		$current_model = new $payment_model;
		foreach($vo['config'] as $k=>$item)
		{
			$current_model->config[$k] = $item;
		}
		$vo['config'] = $current_model->config;
		if($vo['fee_type']==0)
		$vo['fee'] = getBaseMoney($vo['fee'],$vo['currency']);
		
		if($vo['cost_fee_type']==0)
		$vo['cost_fee'] = getBaseMoney($vo['cost_fee'],$vo['currency']);
		
		$this->assign ( 'vo', $vo );
		
		$currency_list = D("Currency")->findAll();
		$default_lang_id = D("LangConf")->where("lang_name='".C('DEFAULT_LANG')."'")->getField("id");
		foreach($currency_list as $k=>$v)
		{
			$currency_list[$k]['name'] = $v['name_'.$default_lang_id];
		}
		$this->assign('currency_list',$currency_list);
		
		$this->display ();
	}
	
	public function update()
	{
		$payment_model = D("Payment");
		if (!$payment_model->create()){
			$this->error($payment_model->getError());
		}		
		$data = $_POST;
		$payment_model->save($data);
		$this->success (L('EDIT_SUCCESS'));		
	}
	public function forbid() {
		$id = $_REQUEST ['id'];	
		$sql_str = "update ".C("DB_PREFIX")."payment set status = 0 where id=".$id ;
		$list = D("Payment")->query($sql_str);
		if ($list!==false) {			
			$this->assign ( "jumpUrl", $this->getReturnUrl () );
			$this->success ( L('FORBID_SUCCESS') ,1);
		} else {
			$this->error  (  L('FORBID_FAILED') ,1);
		}
	}
	
	function resume() {
		$id = $_REQUEST ['id'];
		$sql_str = "update ".C("DB_PREFIX")."payment set status = 1 where id=".$id ;
		$list = D("Payment")->query($sql_str);
		if ($list!==false) {
			$this->assign ( "jumpUrl", $this->getReturnUrl () );
			$this->success ( L('RESUME_SUCCESS') ,1);
			
		} else {
			$this->error ( L('RESUME_FAILED') ,1);
		}
	}
	
}
?>