Authored by xiaofeng.yao@yoho.cn

增加在线人数隔时间上报

<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "{{%rooms_nums_report}}".
*
* @property integer $id
* @property integer $room_id
* @property integer $like_num
* @property integer $audience_num
* @property integer $online_num
* @property integer $replay_num
* @property integer $vest_online_num
* @property integer $create_time
*/
class RoomsNumsReport extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%rooms_nums_report}}';
}
/*public function behaviors()
{
return [
[
'class' => \yii\behaviors\TimestampBehavior::className(),
'createdAtAttribute' => 'create_time',
]
];
}*/
/**
* @inheritdoc
*/
public function rules()
{
return [
[['room_id', 'like_num', 'audience_num', 'online_num', 'replay_num', 'vest_online_num', 'create_time'], 'integer'],
[['create_time'], 'required'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'room_id' => 'Room ID',
'like_num' => 'Like Num',
'audience_num' => 'Audience Num',
'online_num' => 'Online Num',
'replay_num' => 'Replay Num',
'vest_online_num' => 'Vest Online Num',
'create_time' => 'Create Time',
];
}
/**
* 插入
* @param $parameters array 数据
* @return bool
*/
public function create($parameters)
{
$this->attributes = [
'room_id' => (int)$parameters['room'],
'like_num' => (int)$parameters['likeNums'],
'online_num' => (int)$parameters['onlineNums'],
'audience_num' => (int)$parameters['audienceNums'],
'vest_online_num' => (int)$parameters['vestOnlineNums'],
'create_time' => time()
];
return $this->save(false);
}
}
... ...
... ... @@ -6,7 +6,7 @@ use soa\controllers\BaseController;
use common\models\RoomNums;
use common\models\Video;
use common\models\Room;
use common\models\RoomsNumsReport;
/**
* Room controller
*/
... ... @@ -24,6 +24,10 @@ class RoomController extends BaseController
$room_id = $gets['room'];
if ($room_id) {
//插入统计表
$roomReportModel = new RoomsNumsReport();
$roomReportModel->create($gets);
//插入or更新数据表
if (!$model = RoomNums::findOne(['room_id' => $room_id])) {
$model = new RoomNums();
$model->room_id = $room_id;
... ...