<?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);
}
}
Yii 表模型类具备的方法的一个例子(必须+可选)
最新推荐文章于 2021-03-10 13:03:01 发布