RoomsNumsReport.php 2.48 KB
<?php

namespace common\models;

use Yii;
use yii\helpers\ArrayHelper;

/**
 * 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);
    }

    public static function condition($condtion)
    {
        $model = parent::find();
        $filters = ArrayHelper::filter($condtion,['begin','end']);
        if($filters['begin'] && $filters['end']){
            $model->andWhere('create_time>='.strtotime($filters['begin']).' AND create_time<='.strtotime($filters['end']));
        }
        return $model;
    }
}