<?php
Doo::loadCore ( 'db/DooModel' );
class RILecturer extends DooModel {
	public $rlid;
	public $rid;
	public $ltype;
	public $lecturerName;
	public $schoolDay;
	public $taxation;
	public $price;
	public $fees;
	
	public $_table = 'CLD_RILecturer';
	public $_primarykey = 'rlid';
	public $_fields = array (
			'rlid',
			'rid',
			'ltype',
			'lecturerName',
			'schoolDay',
			'taxation',
			'price',
			'fees',
			
	);
	
	function getRILecturerByRlid($rlid){
		$detail=$this->getOne(array (
				'where' => "rlid=".$rlid,
				'asArray' => TRUE
		));
		
		return $detail;
	}
	
	/**
	 * 根据rid获得教师详情
	 * @param number $rid
	 */
	function getRILecturerByRid($rid=0){
		$sql = 'select (@rowNO := @rowNo+1) AS  i, a.* from ' . $this->_table . ' a, (select @rowNO :=0) b where rid='.$rid;
		$query = Doo::db ()->query ( $sql );
		$list = $query->fetchAll ();
		
		Doo::loadClass ( 'XDeode' );
		$XDeode = new XDeode ( 5 );
		
		foreach ($list as $key=>$value){
			$list[$key]['rlidKey']=$XDeode->encode ( $value ['rlid'] );
			$list[$key]['sum']=$value['schoolDay']*$value['price'];
		}
		return $list;
	}

    /**
     * 获得教师支出的金额
     * @param string $rids
     * @return int
     */
	function getRILecturerPriceByRids($rids=''){
        if (empty($rids)){
            return 0;
        }
        $list = $this->find ( array (
            'where' => " rid in (" .$rids.")",
            'asArray' => TRUE
        ) );
        $bValue=0;
        foreach ($list as $key=>$value){
            if($value['fees']=='0.00'){
                $bValue+=($value['price']*$value['schoolDay']);
            }else{
                $bValue+=$value['fees'];
            }
        }
        return $bValue;
    }
	
}

?>