<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * 营销中心——贷款管理
 */

class my_loan_xiao extends MY_Controller{
    /**
    * 当前用户uid
    *
    * @access private
    * @var int
    */
    private  $_uid = 0;

    /**
    * 当前页码
    *
    * @access private
    * @var string
    */
    private $_current_page = 1;

    /**
    * 每页条目数
    *
    * @access private
    * @var int
    */
    private $_limit = 2;

    /**
    * 偏移
    *
    * @access private
    * @var int
    */
    private $_offset = 0;

    /**
    * 条目总数
    *
    * @access private
    * @var int
    */
    private $_total_count = 0;
    
    
    /**
     * 解析函数
     *
     * @access public
     * @return void
     */
    public function __construct() {
        parent::__construct();
        $this->config_cityflag = 'nj';
        //经纪人账号uid
        $this->_uid = $this->user_arr['uid']; 
		$this->load->model('loan_model');     
       
     
    }    
    
    /**
     * 消息管理
     */
    public function index(){     
		

        //最新的按揭推荐
        $mortgageLoan = $this->loan_model->getLoanProduct(1);
		//最新的信用推荐
		$creditLoan  = $this->loan_model->getLoanProduct(3);
       
		$this->load->model('broker_model');
		$info = $this->broker_model->get_broker_detail();
		$data['info'] = $info;
         /** 页面初始化 */
        $data['page_title'] = '营销中心-贷款管理-'.$tab;
        $data['css'] = load_css('zsb/css/v1.0/style1.css,zsb/css/v1.0/style_loan.css,zsb/css/v1.0/common_loan.css'); //需要加载的css  
      
        $data['mortgageLoan'] = $mortgageLoan; 
		$data['creditLoan'] = $creditLoan; 
        
        $data['username'] = $this->user_arr['username'];
		//print_r($data['info']['master_name']);die;
       //$this->load->view( 'loan_index', $data);
	    $data['google_analytics'] = get_ga_js_code('/个人中心/365贷款/申请贷款/');
        $this->view('ucenter','loan_index_xiao',$data);
    }
    
    
    
  
    
    /**
     * 添加记录
     * addLoan
     */
    public function addLoan(){
        $loan_name = $this->input->post('loan_name',TRUE);
        $loan_telno = $this->input->post('loan_telno',TRUE);
        $loan_amount = $this->input->post('loan_amount',TRUE);
        $kind = $this->input->post('pid',TRUE);        
        $loan_name = iconv("UTF-8","gb2312",$loan_name);
        if($loan_amount&&$loan_name&&$loan_telno){              
            $fieldData = array('username'=>$loan_name,'telno'=>$loan_telno,
                'broker'=>$this->user_arr['username'],'money'=>$loan_amount,'kind'=>$kind,'add_time'=>time(),'user_type'=>1);
            $return = $this->loan_model->insertRecord($fieldData);
            if($return>0){
                echo json_encode(array('result'=>1));
                exit;
            }else{
                 echo json_encode(array('result'=>0));
                exit;
            }
        }else{
             echo json_encode(array('result'=>0));
               exit;
        }
        
        
        
        
    }
    
    
    
   
    
    
    /**
     * 奖励规则
     * getRewardRule
     */
    
    private function getRewardRule(){        
        $key = $this->config_cityflag."_loan_reward_rule";
		//$this->mc->delete($key);
        $rewardArr = $this->mc->get($key);
        if($rewardArr === false) {
            $zsbLoanReward = new ZsbLoanReward();
            $rewardArr = $zsbLoanReward->findAllByOrder('id','desc');
            $this->mc->set($key,$rewardArr,1800);	
        }
        return $rewardArr;     
    
    }
    
   
    
    
 
    

    

    
}
