<?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 UserMoneyAction extends CommonAction{
	public function incharge()
	{
		//列表过滤器，生成查询Map对象
		$map = $this->_search ("UserIncharge");
		if (method_exists ( $this, '_filter' )) {
			$this->_filter ( $map );
		}
		$model = D ("UserIncharge");
		if (! empty ( $model )) {
			$this->_list ( $model, $map );
		}
		$this->display ();
		return;		
	}
	public function resumeIncharge()
	{
	//恢复指定记录

		$model = D ("UserIncharge");
		$pk = $model->getPk ();
		$id = $_GET [$pk];
		$condition = array ($pk => array ('in', $id ) );
		if (false !== $model->resume ( $condition )) {
			$incharge_info = $model->getById($id);
//			$user_info = D("User")->getById($incharge_info['user_id']);
//			D("User")->where("id=".$incharge_info['user_id'])->setField("money",$user_info['money']+$incharge_info['money']);
			user_money_log($incharge_info['user_id'],$id,'UserIncharge',$incharge_info['money'],'#INCHARGE_RESUME_SUCCESS#');
			$model -> where("id=".$id)->setField('update_time',time());
			$this->saveLog(1);
			$this->assign ( "jumpUrl", $this->getReturnUrl () );
			
			$this->success ( L('CONFIRM_SUCCESS') );
		} else {
			$this->saveLog(0);
			$this->error ( L('CONFIRM_FAILED') );
		}
	}
	public function forbidIncharge() {
		$model = D ("UserIncharge");
		$pk = $model->getPk ();
		$id = $_REQUEST [$pk];
		$condition = array ($pk => array ('in', $id ) );
		$list=$model->forbid ( $condition );
		if ($list!==false) {	
			$incharge_info = $model->getById($id);
			user_money_log($incharge_info['user_id'],$id,'UserIncharge',"-".$incharge_info['money'],'#INCHARGE_FORBID_SUCCESS#');
					
			$this->saveLog(1);
			$this->assign ( "jumpUrl", $this->getReturnUrl () );
			$this->success ( L('CANCEL_SUCCESS') );
		} else {
			$this->saveLog(0);
			$this->error  (  L('CANCEL_FAILED') );
		}
	}
	public function  foreverdeleteIncharge()
	{
		$name="UserIncharge";
		$model = D ($name);
		if (! empty ( $model )) {
			$pk = $model->getPk ();
			$id = $_REQUEST [$pk];
			if (isset ( $id )) {
				$condition = array ($pk => array ('in', explode ( ',', $id ) ) );
				if (false !== $model->where ( $condition )->delete ()) {
					//echo $model->getlastsql();
					$this->saveLog(1);
					$this->success (L('DEL_SUCCESS'));
				} else {
					$this->saveLog(0);
					$this->error (L('DEL_FAILED'));
				}
			} else {
				$this->saveLog(0);
				$this->error ( L('INVALID_OP') );
			}
		}
		$this->forward ();
	}
	
	//提现
	public function uncharge()
	{
		//列表过滤器，生成查询Map对象
		$map = $this->_search ("UserUncharge");
		if (method_exists ( $this, '_filter' )) {
			$this->_filter ( $map );
		}
		$model = D ("UserUncharge");
		if (! empty ( $model )) {
			$this->_list ( $model, $map );
		}
		$this->display ();
		return;		
	}
	public function resumeUncharge()
	{
	//恢复指定记录

		$model = D ("UserUncharge");
		$pk = $model->getPk ();
		$id = $_GET [$pk];
		$condition = array ($pk => array ('in', $id ) );
		if (false !== $model->resume ( $condition )) {
			$uncharge_info = $model->getById($id);
			$user_info = D("User")->getById($uncharge_info['user_id']);
			$money = $user_info['money']- $uncharge_info['money']>0?$user_info['money']- $uncharge_info['money']:0;
			D("User")->where("id=".$uncharge_info['user_id'])->setField("money",$money);
			
			$model -> where("id=".$id)->setField('update_time',time());
			$this->saveLog(1);
			$this->assign ( "jumpUrl", $this->getReturnUrl () );
			
			$this->success ( L('CONFIRM_SUCCESS') );
		} else {
			$this->saveLog(0);
			$this->error ( L('CONFIRM_FAILED') );
		}
	}
	public function forbidUncharge() {
		$model = D ("UserUncharge");
		$pk = $model->getPk ();
		$id = $_REQUEST [$pk];
		$condition = array ($pk => array ('in', $id ) );
		$list=$model->forbid ( $condition );
		if ($list!==false) {

			$uncharge_info = $model->getById($id);
			$user_info = D("User")->getById($uncharge_info['user_id']);
			D("User")->where("id=".$uncharge_info['user_id'])->setField("money",$user_info['money']+$uncharge_info['money']);
			
					
			$this->saveLog(1);
			$this->assign ( "jumpUrl", $this->getReturnUrl () );
			$this->success ( L('CANCEL_SUCCESS') );
		} else {
			$this->saveLog(0);
			$this->error  (  L('CANCEL_FAILED') );
		}
	}
	public function  foreverdeleteUncharge()
	{
		$name="UserUncharge";
		$model = D ($name);
		if (! empty ( $model )) {
			$pk = $model->getPk ();
			$id = $_REQUEST [$pk];
			if (isset ( $id )) {
				$condition = array ($pk => array ('in', explode ( ',', $id ) ) );
				if (false !== $model->where ( $condition )->delete ()) {
					//echo $model->getlastsql();
					$this->saveLog(1);
					$this->success (L('DEL_SUCCESS'));
				} else {
					$this->saveLog(0);
					$this->error (L('DEL_FAILED'));
				}
			} else {
				$this->saveLog(0);
				$this->error ( L('INVALID_OP') );
			}
		}
		$this->forward ();
	}
}
?>