/**
* @var string attribute : 日运费 (统计用)
* 需要对新增加的字段做个声明
*/
public $dayrate;
/*
* 统计功能: 统计每日的运费
*/
public function statistics()
{
$criteria = new CDbCriteria;
$criteria->select = 'remitdate, sum(rate) AS dayrate';
$criteria->group = 'remitdate';
return new CActiveDataProvider(get_class($this), array(
'criteria'=>$criteria,
'sort'=>array(
// 表头设置点击排序的字段
'attributes'=>array(
'remitdate',
'dayrate'=>array(
'asc'=>'dayrate',
'desc'=>'dayrate DESC',
)
),
'defaultOrder'=>'remitdate desc',
),
));
}
[Controller层]
/**
* 运单统计功能:
* 按日期统计
*/
public function actionReport()
{
$model=new Delivery('statistics');
$model->unsetAttributes(); // clear any default values
$this->render('report',array(
'model'=>$model,
));
}
[View层]
widget('zii.widgets.grid.CGridView', array(
'id'=>'delivery-grid',
'dataProvider'=>$model->statistics(),
'filter'=>$model,
'columns'=>array(
'remitdate',
'dayrate',
array(
'class'=>'CButtonColumn',
),
),
)); ?>
|