Authored by xiaofeng.yao@yoho.cn

增加在线人数隔时间上报

  1 +<?php
  2 +
  3 +namespace common\models;
  4 +
  5 +use Yii;
  6 +
  7 +/**
  8 + * This is the model class for table "{{%rooms_nums_report}}".
  9 + *
  10 + * @property integer $id
  11 + * @property integer $room_id
  12 + * @property integer $like_num
  13 + * @property integer $audience_num
  14 + * @property integer $online_num
  15 + * @property integer $replay_num
  16 + * @property integer $vest_online_num
  17 + * @property integer $create_time
  18 + */
  19 +class RoomsNumsReport extends \yii\db\ActiveRecord
  20 +{
  21 + /**
  22 + * @inheritdoc
  23 + */
  24 + public static function tableName()
  25 + {
  26 + return '{{%rooms_nums_report}}';
  27 + }
  28 +
  29 + /*public function behaviors()
  30 + {
  31 + return [
  32 + [
  33 + 'class' => \yii\behaviors\TimestampBehavior::className(),
  34 + 'createdAtAttribute' => 'create_time',
  35 + ]
  36 + ];
  37 + }*/
  38 +
  39 + /**
  40 + * @inheritdoc
  41 + */
  42 + public function rules()
  43 + {
  44 + return [
  45 + [['room_id', 'like_num', 'audience_num', 'online_num', 'replay_num', 'vest_online_num', 'create_time'], 'integer'],
  46 + [['create_time'], 'required'],
  47 + ];
  48 + }
  49 +
  50 + /**
  51 + * @inheritdoc
  52 + */
  53 + public function attributeLabels()
  54 + {
  55 + return [
  56 + 'id' => 'ID',
  57 + 'room_id' => 'Room ID',
  58 + 'like_num' => 'Like Num',
  59 + 'audience_num' => 'Audience Num',
  60 + 'online_num' => 'Online Num',
  61 + 'replay_num' => 'Replay Num',
  62 + 'vest_online_num' => 'Vest Online Num',
  63 + 'create_time' => 'Create Time',
  64 + ];
  65 + }
  66 +
  67 + /**
  68 + * 插入
  69 + * @param $parameters array 数据
  70 + * @return bool
  71 + */
  72 + public function create($parameters)
  73 + {
  74 + $this->attributes = [
  75 + 'room_id' => (int)$parameters['room'],
  76 + 'like_num' => (int)$parameters['likeNums'],
  77 + 'online_num' => (int)$parameters['onlineNums'],
  78 + 'audience_num' => (int)$parameters['audienceNums'],
  79 + 'vest_online_num' => (int)$parameters['vestOnlineNums'],
  80 + 'create_time' => time()
  81 + ];
  82 + return $this->save(false);
  83 + }
  84 +}
@@ -6,7 +6,7 @@ use soa\controllers\BaseController; @@ -6,7 +6,7 @@ use soa\controllers\BaseController;
6 use common\models\RoomNums; 6 use common\models\RoomNums;
7 use common\models\Video; 7 use common\models\Video;
8 use common\models\Room; 8 use common\models\Room;
9 - 9 +use common\models\RoomsNumsReport;
10 /** 10 /**
11 * Room controller 11 * Room controller
12 */ 12 */
@@ -24,6 +24,10 @@ class RoomController extends BaseController @@ -24,6 +24,10 @@ class RoomController extends BaseController
24 24
25 $room_id = $gets['room']; 25 $room_id = $gets['room'];
26 if ($room_id) { 26 if ($room_id) {
  27 + //插入统计表
  28 + $roomReportModel = new RoomsNumsReport();
  29 + $roomReportModel->create($gets);
  30 + //插入or更新数据表
27 if (!$model = RoomNums::findOne(['room_id' => $room_id])) { 31 if (!$model = RoomNums::findOne(['room_id' => $room_id])) {
28 $model = new RoomNums(); 32 $model = new RoomNums();
29 $model->room_id = $room_id; 33 $model->room_id = $room_id;