Yii 表模型类具备的方法的一个例子(必须+可选)

<?php

/**
 * This is the model class for table "financing_autobid".
 *
 * The followings are the available columns in table 'financing_autobid':
 * @property interger $BidID
 * @property interger $CustomerID
 * @property interger $BidAmount
 * @property interger $SingleAmount
 * @property interger $InterestRate
 * @property tinyint  $LoanPeriod
 * @property tinyint  $State
 * @property interger $CreateDate
 * @property interger $UpdateDate
 */
class FinancingAutoBid extends CActiveRecord
{
	const CURRENT_STATUS_CLOSE = 0;
	const CURRENT_STATUS_OPEN  = 1;
	
	/*
	 * 获取状态列表
	 * @return array
	 */
	public static function getStateList()
	{
		return array(
				self::CURRENT_STATUS_OPEN  => Yii::t( 'type', '开启自动投标' ),
				self::CURRENT_STATUS_CLOSE => Yii::t( 'type', '关闭自动投标' ),	
		);
	}
	
	/*
	 * 获取状态标签
	 * @return string
	 */
	public static function getStateLabel( $intState )
	{
		$arrState = self::getStateList();
	
		return $arrState[$intState];
	}
	

	/*
	 * 获取借款周期列表
	 * @return array
	 */
	public static function getLoanPeriodList()
	{
		return array(
				1 => Yii::t( 'type', '1个月' ),
				2 => Yii::t( 'type', '2个月' ),
				3 => Yii::t( 'type', '3个月' ),
		);
	}
	
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return FinancingBorrow the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
	
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'financing_autobid';
	}
	
	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
				array('BidAmount, SingleAmount, InterestRate, State', 'required'),
				array('LoanPeriod','required','message'=>'请选择一个或多个货款周期'),
 				array('BidAmount, SingleAmount', 'numerical', 'integerOnly'=>true),
 				array('BidAmount, SingleAmount, InterestRate', 'length', 'max'=>10),
				array('BidAmount, SingleAmount','isVerify', 'divisor'=>100 ),
				array('InterestRate','isInRange','max'=>25,'min'=>1),
				// The following rule is used by search().
				// Please remove those attributes that should not be searched.
				array('BidID, CustomerID, BidAmount, SingleAmount, InterestRate, LoanPeriod, State', 'safe', 'on'=>'search'),
		);
	}
	
	public function isVerify( $attribute, $params ){
		if ( $this->$attribute <= 0 ){
			$this->addError($attribute, '输入的金额应大于0');
		}
		
		if ( $this->$attribute % $params['divisor'] !=0 ){	
			$this->addError($attribute, '金额要是100的整数倍!');
		}
		
		if ($this->SingleAmount>$this->BidAmount){
			$this->addError('SingleAmount', '单笔投标额度不能大于投标总额');
		}

	}
	
	public function isInRange( $attribute, $params ){
		if ( !is_numeric( $this->$attribute ) ){
			$this->addError( $attribute, '请输入数字' );
		}
		if ( $this->$attribute <$params['min']){
			$this->addError($attribute, '最低利率不能低于1%');
		}
		if ($this->$attribute >$params['max']){
			$this->addError($attribute, '最低利率不能大于25%');
		}
	}
	
	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
				//'Pledge' => array( self::BELONGS_TO, 'FinancingPledge', 'PledgeID' ),
				//'Customer' => array( self::BELONGS_TO, 'User', 'CustomerID' ),
		);
	}
	
	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
				'BidID' => Yii::t( 'label', '投标流水号' ),
				'CustomerID' => Yii::t( 'label', '用户ID' ),
				'BidAmount' => Yii::t( 'label', '投标金额(预计)' ),
				'SingleAmount' => Yii::t( 'label', '单笔投标最大额度' ),
				'InterestRate' => Yii::t( 'label', '最低利率' ),
				'LoanPeriod' => Yii::t( 'label', '贷款周期' ),
				'State' => Yii::t( 'label', '状态' ),
		);
	}
	
	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.
	
		$criteria=new CDbCriteria;
	
		$criteria->compare('BidID',$this->BidID,true);
		$criteria->compare('CustomerID',$this->CustomerID,true);
		$criteria->compare('BidAmount',$this->BidAmount,true);
		$criteria->compare('SingleAmount',$this->SingleAmount);
		$criteria->compare('InterestRate',$this->InterestRate,true);
		$criteria->compare('LoanPeriod',$this->LoanPeriod,true);
		$criteria->compare('State',$this->State,true);
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值