<?php
/**
 * 用户账户变更记录
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author xiaogg <xiaogg@sina.cn>
 */
 
namespace Admin\Controller;
class AccountLogController extends BaseController{
    public function _initialize(){
        parent::_initialize();
        $this->account_type=strtoarray(C('ACCOUNT_TYPE'));$this->assign('account_type',$this->account_type);
		//处理数组（销毁掉不需要的元素）
		$arr = $this->account_type;
		unset($arr[3],$arr[7]);
		$this->account_type = $arr;
		//处理数组结束
		
		$this->account_status=strtoarray(C('ACCOUNT_STATUS'));$this->assign('account_status',$this->account_status);
		
		$arr_s = $this->account_status;
		unset($arr_s[6],$arr_s[7],$arr_s[9],$arr_s[11],$arr_s[12],$arr_s[13]);
		$this->account_status = $arr_s;
    }
    public function _before_delete(){exit;}
    public function index(){
        $name = CONTROLLER_NAME;
        $map=array();
        $postdata=array_map('trim',I('request.'));
        $uid=trim(I('param.uid'));
        if(!empty($postdata['uid'])){
			$where_m['id']=$uid;
			$m_list=M('Member')->where($where_m)->field('id')->select();
			if($m_list){
                $me_list='';
				foreach($m_list as $k=>$v){
					$me_list.=$v['id'].',';
				}
				$map['uid']=array('in',rtrim($me_list,','));
			}else{
				$map['uid']=$uid;
			}
		}
        if(!empty($postdata['type']))$map['type']=$postdata['type'];
        if(!empty($postdata['status']))$map['status']=$postdata['status'];
        if(!empty($postdata['keyword']))$map['change_desc']=array('like','%'.$postdata['keyword'].'%');
        $list = $this->lists($name,$map);
        $this->assign('list', $list);
        $this->assign('type', $postdata['type']);
        $this->display();
    }
    public function show_account(){
        $map=array();
        $uid=trim(I('param.uid'));
        $map['uid']=$uid;
        $list = $this->lists('AccountLog',$map);
        $this->assign('list', $list);
        $this->display();
    }
    public function add() {
        $uid=I('uid');
        $userinfo=idtoname($uid,'Member','*','id',false);
        $this->assign('userinfo', $userinfo);
		$this->display ('add');
	}
	public function change_money(){
		$postdata=I('post.');exit;
		$adminid=UID;
        if(!$postdata['uid'])$this->error('请先选择用户ID');
        if($postdata){
			if(!$postdata['change_desc'])$this->error('请填写变更理由！');
            if($postdata['change_num']>0 || $postdata['change_num']<0){
                $addid=account_change($postdata['uid'],$postdata['change_num'],$postdata['change_type'],$postdata['change_status'],$postdata['change_desc'],$adminid);
				//增加累计充值
				// if($postdata['change_status'] == 1 || $postdata['change_status'] == 12){
					// account_change($postdata['uid'],$postdata['change_num'],7,$postdata['change_status'],'累计充值',$adminid);
                    // $grade_choices = C('GRADE_CHOICES');//会员升级选择
                    // if(C('IS_MEMBER_UPGRADE')){
                        // if($grade_choices == 2){//累计充值升级
                            // user_ranks($pay_info['user_id']);
                        // }
                    // }
				// }
				//添加平台出入账日志
				if($postdata['change_num']>0){$change_desc='后台手动变更（平台出账）';}else{$change_desc='后台手动变更（平台入账）';}
				if($postdata['change_type']==1){
					account_change($postdata['uid'],-$postdata['change_num'],$postdata['change_type'],$postdata['change_status'],$change_desc,$adminid,false,3);
				}
                if($addid){
					$this->success('变更成功',U('Member/index?uid='.$postdata['uid']));
				}else{
					$this->error('变更失败',U('Member/index?uid='.$postdata['uid']));
				}
            }else{
                $this->error('请填写变更数量',U('Member/index?uid='.$postdata['uid']));
            }
		}
	}
}