Authored by xiaofeng.yao@yoho.cn

后台房间、视频新增分享内容和排序字段,以及前台相应接口修改

@@ -9,6 +9,8 @@ use backend\widgets\Filter; @@ -9,6 +9,8 @@ use backend\widgets\Filter;
9 use backend\widgets\YHGImage\Common\Images as CommonImages; 9 use backend\widgets\YHGImage\Common\Images as CommonImages;
10 use app\models\Video; 10 use app\models\Video;
11 use yii\helpers\ArrayHelper; 11 use yii\helpers\ArrayHelper;
  12 +use app\models\Share;
  13 +use common\config\Params;
12 14
13 /** 15 /**
14 * Live controller 16 * Live controller
@@ -123,13 +125,12 @@ class LiveController extends BaseController @@ -123,13 +125,12 @@ class LiveController extends BaseController
123 $model = Video::findOne($posts['id']); 125 $model = Video::findOne($posts['id']);
124 if(!empty($model)) 126 if(!empty($model))
125 { 127 {
126 - $model->pic = $posts['pic'];  
127 - $model->url = $posts['url'];  
128 - $model->title = $posts['title'];  
129 - if($model->save()) 128 + if($model->edit($posts))
130 { 129 {
131 Yii::$app->session->setFlash('success', '编辑成功。'); 130 Yii::$app->session->setFlash('success', '编辑成功。');
132 - } 131 + }else{
  132 + Yii::$app->session->setFlash('error', '编辑失败。');
  133 + }
133 } 134 }
134 else 135 else
135 { 136 {
@@ -139,20 +140,56 @@ class LiveController extends BaseController @@ -139,20 +140,56 @@ class LiveController extends BaseController
139 } 140 }
140 else 141 else
141 { 142 {
142 - $id = Yii::$app->request->get('id', 0);  
143 - $video = Video::findOne(['id'=> $id]);  
144 - if(empty($video))  
145 - {  
146 - Yii::$app->session->setFlash('error', '找不到该视频');  
147 - return $this->redirect($this->_refer);  
148 - }  
149 - //图片上传组件  
150 - $uploader = \backend\widgets\UploadImage::self()->logo('pic', $video->pic);  
151 - return $this->render('videoedit', ['video' => $video, 'uploader' => $uploader]); 143 + $id = Yii::$app->request->get('id', 0);
  144 + $video = Video::findOne(['id' => $id]);
  145 + if (empty($video)) {
  146 + Yii::$app->session->setFlash('error', '找不到该视频');
  147 + return $this->redirect($this->_refer);
  148 + }
  149 + $videoShare = [];
  150 + if ($shareModel = Share::findOne(['obj_id' => $video->id, 'type' => Params::VIDEO_SHARE_TYPE])) {
  151 + $videoShare = $shareModel->toArray();
  152 + }
  153 + //图片上传组件
  154 + $uploader = \backend\widgets\UploadImage::self()->single('pic', $video->pic);
  155 + $sharePicUploader = \backend\widgets\UploadImage::self()->single('share_pic', $videoShare['pic']);
  156 +
  157 + return $this->render('videoedit', [
  158 + 'video' => $video,
  159 + 'uploader' => $uploader,
  160 + 'sharePicUploader' => $sharePicUploader,
  161 + 'videoShare' => $videoShare
  162 + ]);
152 } 163 }
153 } 164 }
154 165
155 /** 166 /**
  167 + * 删除视频记录
  168 + * @author yaoxiaofeng
  169 + */
  170 + public function actionVideodel()
  171 + {
  172 + if (!$id = Yii::$app->getRequest()->getQueryParam('id')) {
  173 + return $this->redirect($this->_refer);
  174 + }
  175 + do {
  176 + $model = Video::findOne($id);
  177 + if (empty($model)) {
  178 + Yii::$app->session->setFlash('error', '找不到该视频信息。');
  179 + break;
  180 + }
  181 + if ($model->delete()) {
  182 + Yii::$app->session->setFlash('success', '删除成功。');
  183 + } else {
  184 + Yii::$app->session->setFlash('error', '删除失败。');
  185 + }
  186 + break;
  187 + } while (false);
  188 +
  189 + return $this->redirect($this->_refer);
  190 + }
  191 +
  192 + /**
156 * 视频状态设置 193 * 视频状态设置
157 * @return 194 * @return
158 */ 195 */
@@ -307,11 +344,13 @@ class LiveController extends BaseController @@ -307,11 +344,13 @@ class LiveController extends BaseController
307 //图片上传组件 344 //图片上传组件
308 $picUploader = \backend\widgets\UploadImage::self()->single('pic',$model->pic); 345 $picUploader = \backend\widgets\UploadImage::self()->single('pic',$model->pic);
309 $backgroundUploader = \backend\widgets\UploadImage::self()->single('background_pic',$model->background_pic); 346 $backgroundUploader = \backend\widgets\UploadImage::self()->single('background_pic',$model->background_pic);
  347 + $sharePicUploader = \backend\widgets\UploadImage::self()->single('share_pic',$post['share_pic'] ? :'');
310 348
311 return $this->render('roomedit',[ 349 return $this->render('roomedit',[
312 'model'=> $model, 350 'model'=> $model,
313 'picUploader'=>$picUploader, 351 'picUploader'=>$picUploader,
314 'backgroundUploader'=>$backgroundUploader, 352 'backgroundUploader'=>$backgroundUploader,
  353 + 'sharePicUploader'=>$sharePicUploader,
315 'masters'=>$masters, 354 'masters'=>$masters,
316 ]); 355 ]);
317 } 356 }
@@ -351,12 +390,19 @@ class LiveController extends BaseController @@ -351,12 +390,19 @@ class LiveController extends BaseController
351 //图片上传组件 390 //图片上传组件
352 $picUploader = \backend\widgets\UploadImage::self()->single('pic',$model->pic); 391 $picUploader = \backend\widgets\UploadImage::self()->single('pic',$model->pic);
353 $backgroundUploader = \backend\widgets\UploadImage::self()->single('background_pic',$model->background_pic); 392 $backgroundUploader = \backend\widgets\UploadImage::self()->single('background_pic',$model->background_pic);
  393 + $sharePicUploader = \backend\widgets\UploadImage::self()->single('share_pic',$post['share_pic'] ? :'');
354 394
  395 + $roomShare = [];
  396 + if($shareModel = Share::findOne(['obj_id'=>$model->room_id,'type'=>Params::LIVE_SHARE_TYPE])) {
  397 + $roomShare = $shareModel->toArray();
  398 + }
355 return $this->render('roomedit',[ 399 return $this->render('roomedit',[
356 'model'=> $model, 400 'model'=> $model,
357 'picUploader'=>$picUploader, 401 'picUploader'=>$picUploader,
358 'backgroundUploader'=>$backgroundUploader, 402 'backgroundUploader'=>$backgroundUploader,
  403 + 'sharePicUploader'=>$sharePicUploader,
359 'masters'=>$masters, 404 'masters'=>$masters,
  405 + 'roomShare' => $roomShare
360 ]); 406 ]);
361 } 407 }
362 408
@@ -5,6 +5,8 @@ namespace app\models; @@ -5,6 +5,8 @@ namespace app\models;
5 use Yii; 5 use Yii;
6 use common\lib\QcloudApi\Client as QcloudApiClient; 6 use common\lib\QcloudApi\Client as QcloudApiClient;
7 use common\models\RoomNums; 7 use common\models\RoomNums;
  8 +use common\models\Share;
  9 +use common\config\Params;
8 10
9 /** 11 /**
10 * This is the model class for table "{{%room}}". 12 * This is the model class for table "{{%room}}".
@@ -39,7 +41,7 @@ class Room extends \yii\db\ActiveRecord @@ -39,7 +41,7 @@ class Room extends \yii\db\ActiveRecord
39 public function rules() 41 public function rules()
40 { 42 {
41 return [ 43 return [
42 - [['room_id', 'master_id', 'starting_time', 'best', 'vest', 'is_addup', 'living', 'status', 'create_time', 'update_time'], 'integer'], 44 + [['room_id', 'master_id', 'starting_time', 'best', 'vest', 'is_addup', 'living', 'status', 'unstart_sort', 'living_sort', 'create_time', 'update_time'], 'integer'],
43 [['title', 'watermark'], 'string', 'max' => 100], 45 [['title', 'watermark'], 'string', 'max' => 100],
44 [['app', 'secret'], 'string', 'max' => 50], 46 [['app', 'secret'], 'string', 'max' => 50],
45 [['pic', 'background_pic'], 'string', 'max' => 255], 47 [['pic', 'background_pic'], 'string', 'max' => 255],
@@ -69,6 +71,8 @@ class Room extends \yii\db\ActiveRecord @@ -69,6 +71,8 @@ class Room extends \yii\db\ActiveRecord
69 'vest' => '马甲状态', 71 'vest' => '马甲状态',
70 'living' => '直播状态', 72 'living' => '直播状态',
71 'status' => '房间状态', 73 'status' => '房间状态',
  74 + 'unstart_sort' => '未开始排序',
  75 + 'living_sort' => '直播中排序',
72 'create_time' => '创建时间', 76 'create_time' => '创建时间',
73 'update_time' => '更新时间', 77 'update_time' => '更新时间',
74 ]; 78 ];
@@ -197,6 +201,19 @@ class Room extends \yii\db\ActiveRecord @@ -197,6 +201,19 @@ class Room extends \yii\db\ActiveRecord
197 throw new \Exception(current($RoomQchannel->getFirstErrors())); 201 throw new \Exception(current($RoomQchannel->getFirstErrors()));
198 } 202 }
199 203
  204 + //插入分享内容
  205 + $RoomShare = new Share;
  206 + $RoomShare->setAttributes([
  207 + 'obj_id'=>$this->room_id,
  208 + 'type'=>Params::LIVE_SHARE_TYPE,
  209 + 'pic'=>$data['share_pic'],
  210 + 'title'=>$data['share_title'],
  211 + 'content'=>$data['share_content'],
  212 + ]);
  213 + if (!$RoomShare->save()){
  214 + throw new \Exception(current($RoomShare->getFirstErrors()));
  215 + }
  216 +
200 $transaction->commit(); 217 $transaction->commit();
201 return $this->room_id; 218 return $this->room_id;
202 }catch (\Exception $e) { 219 }catch (\Exception $e) {
@@ -244,6 +261,22 @@ class Room extends \yii\db\ActiveRecord @@ -244,6 +261,22 @@ class Room extends \yii\db\ActiveRecord
244 throw new \Exception(current($this->getFirstErrors())); 261 throw new \Exception(current($this->getFirstErrors()));
245 } 262 }
246 263
  264 + //编辑分享内容
  265 + if (!$RoomShare = Share::findOne(['type' => Params::LIVE_SHARE_TYPE, 'obj_id' => $this->room_id])) {
  266 + //编辑以前的房间时,没有相应的分享记录,那么这时候要重新创建一个对象来做插入
  267 + $RoomShare = new Share();
  268 + }
  269 + $RoomShare->setAttributes([
  270 + 'obj_id' => $this->room_id,
  271 + 'type' => Params::LIVE_SHARE_TYPE,
  272 + 'pic' => $data['share_pic'],
  273 + 'title' => $data['share_title'],
  274 + 'content' => $data['share_content'],
  275 + ]);
  276 + if (!$RoomShare->save()) {
  277 + throw new \Exception(current($RoomShare->getFirstErrors()));
  278 + }
  279 +
247 $transaction->commit(); 280 $transaction->commit();
248 return true; 281 return true;
249 }catch (\Exception $e) { 282 }catch (\Exception $e) {
@@ -272,12 +305,17 @@ class Room extends \yii\db\ActiveRecord @@ -272,12 +305,17 @@ class Room extends \yii\db\ActiveRecord
272 if (!$model->roomQchannel->delete()){ 305 if (!$model->roomQchannel->delete()){
273 throw new \Exception(current($model->roomQchannel->getFirstErrors())); 306 throw new \Exception(current($model->roomQchannel->getFirstErrors()));
274 } 307 }
275 - 308 +
276 if (!QcloudApiClient::self()->DeleteLVBChannel([$model->roomQchannel->channel_id])){ 309 if (!QcloudApiClient::self()->DeleteLVBChannel([$model->roomQchannel->channel_id])){
277 throw new \Exception(QcloudApiClient::self()->error()); 310 throw new \Exception(QcloudApiClient::self()->error());
278 } 311 }
279 } 312 }
280 313
  314 + //删除分享
  315 + $delShare = (new Share())->delLivingShare($model->room_id);
  316 + if (!$delShare) {
  317 + throw new \Exception("删除分享失败");
  318 + }
281 $transaction->commit(); 319 $transaction->commit();
282 return true; 320 return true;
283 }catch (\Exception $e) { 321 }catch (\Exception $e) {
  1 +<?php
  2 +
  3 +namespace app\models;
  4 +
  5 +use Yii;
  6 +use common\config\Params;
  7 +
  8 +/**
  9 + * This is the model class for table "{{%share}}".
  10 + *
  11 + * @property integer $id
  12 + * @property integer $obj_id
  13 + * @property integer $type
  14 + * @property string $title
  15 + * @property string $content
  16 + * @property integer $create_time
  17 + * @property integer $update_time
  18 + */
  19 +class Share extends \yii\db\ActiveRecord
  20 +{
  21 + /**
  22 + * @inheritdoc
  23 + */
  24 + public static function tableName()
  25 + {
  26 + return '{{%share}}';
  27 + }
  28 +
  29 + /**
  30 + * @inheritdoc
  31 + */
  32 + public function rules()
  33 + {
  34 + return [
  35 + [['obj_id', 'type', 'create_time', 'update_time'], 'integer'],
  36 + [['content'], 'string'],
  37 + [['pic'], 'string', 'max' => 200],
  38 + [['title'], 'string', 'max' => 100],
  39 + [['obj_id', 'type'], 'unique', 'targetAttribute' => ['obj_id', 'type'], 'message' => 'The combination of Obj ID and Type has already been taken.'],
  40 + ];
  41 + }
  42 +
  43 + /**
  44 + * @inheritdoc
  45 + */
  46 + public function attributeLabels()
  47 + {
  48 + return [
  49 + 'id' => 'ID',
  50 + 'obj_id' => 'Obj ID',
  51 + 'type' => 'Type',
  52 + 'pic' => '分享头图',
  53 + 'title' => '分享标题',
  54 + 'content' => '分享内容',
  55 + 'create_time' => 'Create Time',
  56 + 'update_time' => 'Update Time',
  57 + ];
  58 + }
  59 +
  60 + public function behaviors()
  61 + {
  62 + return [
  63 + [
  64 + 'class' => \yii\behaviors\TimestampBehavior::className(),
  65 + 'createdAtAttribute' => 'create_time',
  66 + 'updatedAtAttribute' => 'update_time',
  67 + ]
  68 + ];
  69 + }
  70 +
  71 + private function del($obj_id,$type)
  72 + {
  73 + return self::findOne(['obj_id'=>$obj_id,'type'=>$type])->delete();
  74 + }
  75 +
  76 + public function delLivingShare($room_id)
  77 + {
  78 + return $this->del($room_id,Params::LIVE_SHARE_TYPE);
  79 + }
  80 +
  81 + public function delVideoShare($video_id)
  82 + {
  83 + return $this->del($video_id,Params::VIDEO_SHARE_TYPE);
  84 + }
  85 +}
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 namespace app\models; 3 namespace app\models;
4 4
5 use Yii; 5 use Yii;
  6 +use common\config\Params;
6 7
7 /** 8 /**
8 * This is the model class for table "{{%video}}". 9 * This is the model class for table "{{%video}}".
@@ -38,7 +39,7 @@ class Video extends \yii\db\ActiveRecord @@ -38,7 +39,7 @@ class Video extends \yii\db\ActiveRecord
38 public function rules() 39 public function rules()
39 { 40 {
40 return [ 41 return [
41 - [['task_id', 'live_start_time', 'live_end_time', 'master_id', 'room_id', 'status', 'like_num', 'audience_num', 'replay_num', 'create_time', 'update_time'], 'integer'], 42 + [['task_id', 'live_start_time', 'live_end_time', 'master_id', 'room_id', 'status', 'like_num', 'audience_num', 'replay_num', 'sort', 'create_time', 'update_time'], 'integer'],
42 [['title', 'live_title'], 'string', 'max' => 100], 43 [['title', 'live_title'], 'string', 'max' => 100],
43 [['pic', 'url'], 'string', 'max' => 255], 44 [['pic', 'url'], 'string', 'max' => 255],
44 [['app'], 'string', 'max' => 50], 45 [['app'], 'string', 'max' => 50],
@@ -66,6 +67,7 @@ class Video extends \yii\db\ActiveRecord @@ -66,6 +67,7 @@ class Video extends \yii\db\ActiveRecord
66 'like_num' => 'Like Num', 67 'like_num' => 'Like Num',
67 'audience_num' => 'Audience Num', 68 'audience_num' => 'Audience Num',
68 'replay_num' => 'Replay Num', 69 'replay_num' => 'Replay Num',
  70 + 'sort' => 'Sort',
69 'create_time' => 'Create Time', 71 'create_time' => 'Create Time',
70 'update_time' => 'Update Time', 72 'update_time' => 'Update Time',
71 ]; 73 ];
@@ -107,7 +109,50 @@ class Video extends \yii\db\ActiveRecord @@ -107,7 +109,50 @@ class Video extends \yii\db\ActiveRecord
107 { 109 {
108 return $this->hasOne(Room::className(), ['room_id'=>'room_id']); 110 return $this->hasOne(Room::className(), ['room_id'=>'room_id']);
109 } 111 }
110 - 112 +
  113 + /**
  114 + * 编辑
  115 + * @param array $data
  116 + * @author yaoxiaofeng
  117 + * @return bool
  118 + */
  119 + public function edit(array $data)
  120 + {
  121 + $transaction = $this->getDb()->beginTransaction();
  122 + try {
  123 + $this->setAttributes([
  124 + 'pic' => $data['pic'],
  125 + 'url' => $data['url'],
  126 + 'title' => $data['title'],
  127 + 'sort' => $data['sort']
  128 + ]);
  129 + if (!$this->save()){
  130 + throw new \Exception(current($this->getFirstErrors()));
  131 + }
  132 + //编辑分享内容
  133 + if (!$share = Share::findOne(['type' => Params::VIDEO_SHARE_TYPE, 'obj_id' => $this->id])) {
  134 + //编辑以前的视频时,没有相应的分享记录,那么这时候要重新创建一个对象来做插入
  135 + $share = new Share();
  136 + }
  137 + $share->setAttributes([
  138 + 'obj_id' => $this->id,
  139 + 'type' => Params::VIDEO_SHARE_TYPE,
  140 + 'pic' => $data['share_pic'],
  141 + 'title' => $data['share_title'],
  142 + 'content' => $data['share_content'],
  143 + ]);
  144 + if (!$share->save()) {
  145 + throw new \Exception(current($share->getFirstErrors()));
  146 + }
  147 +
  148 + $transaction->commit();
  149 + return true;
  150 + } catch (\Exception $e) {
  151 + $transaction->rollBack();
  152 + Yii::$app->session->setFlash('warning', $e->getMessage());
  153 + return false;
  154 + }
  155 + }
111 /** 156 /**
112 * 根据条件 157 * 根据条件
113 * @param array $condition 158 * @param array $condition
@@ -136,7 +181,7 @@ class Video extends \yii\db\ActiveRecord @@ -136,7 +181,7 @@ class Video extends \yii\db\ActiveRecord
136 $model->andWhere($sql); 181 $model->andWhere($sql);
137 } 182 }
138 } 183 }
139 - $model->orderBy(['v.create_time' => SORT_DESC]); 184 + $model->orderBy(['v.sort'=>SORT_DESC,'v.create_time' => SORT_DESC]);
140 return $model; 185 return $model;
141 } 186 }
142 } 187 }
@@ -84,6 +84,8 @@ $this->registerJs($this->blocks['javascript'],View::POS_END) @@ -84,6 +84,8 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
84 <th>马甲状态|人数累加</th> 84 <th>马甲状态|人数累加</th>
85 <th>直播状态</th> 85 <th>直播状态</th>
86 <th>在线人数</th> 86 <th>在线人数</th>
  87 + <th>未开始排序</th>
  88 + <th>直播中排序</th>
87 <th>操作</th> 89 <th>操作</th>
88 </tr> 90 </tr>
89 </thead> 91 </thead>
@@ -110,8 +112,10 @@ $this->registerJs($this->blocks['javascript'],View::POS_END) @@ -110,8 +112,10 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
110 真实:<?=@$model->roomNums->online_num ? :0?>, 112 真实:<?=@$model->roomNums->online_num ? :0?>,
111 马甲:<?=@$model->roomNums->vest_online_num ? :0?> 113 马甲:<?=@$model->roomNums->vest_online_num ? :0?>
112 </td> 114 </td>
  115 + <td><?=$model->unstart_sort?></td>
  116 + <td><?=$model->living_sort?></td>
113 <td> 117 <td>
114 - 118 +
115 <span> 119 <span>
116 <?php if ($model->living == 1)://直播中?> 120 <?php if ($model->living == 1)://直播中?>
117 <button type="button" onclick="stopLiving(<?=$model->room_id?>)" class="btn btn-danger btn-metro">结束直播</button> 121 <button type="button" onclick="stopLiving(<?=$model->room_id?>)" class="btn btn-danger btn-metro">结束直播</button>
@@ -46,11 +46,12 @@ $this->registerJs($this->blocks['javascript'],View::POS_END) @@ -46,11 +46,12 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
46 ?> 46 ?>
47 </script> 47 </script>
48 48
49 -<div class="col-md-6">  
50 - <form id="form" method="POST" action="">  
51 - <div class="panel panel-default">  
52 -  
53 - <div class="panel-body"> 49 +<div class="col-md-9">
  50 +<form id="form" method="POST" action="">
  51 + <div class="panel panel-default">
  52 + <div class="panel-body">
  53 + <!-- 左侧表单 begin-->
  54 + <div class="col-md-6">
54 <div class="row"> 55 <div class="row">
55 <div class="form-group"> 56 <div class="form-group">
56 <label class="col-sm-3 control-label">房间号: </label> 57 <label class="col-sm-3 control-label">房间号: </label>
@@ -58,27 +59,27 @@ $this->registerJs($this->blocks['javascript'],View::POS_END) @@ -58,27 +59,27 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
58 <?=$model->room_id ? : '保存后生成'?> 59 <?=$model->room_id ? : '保存后生成'?>
59 </div> 60 </div>
60 </div> 61 </div>
61 - 62 +
62 <div class="form-group"> 63 <div class="form-group">
63 <label class="col-sm-3 control-label">直播标题: <span class="asterisk">*</span></label> 64 <label class="col-sm-3 control-label">直播标题: <span class="asterisk">*</span></label>
64 - <div class="col-sm-5"> 65 + <div class="col-sm-9">
65 <input type="text" name="title" class="form-control" required="required" value="<?=$model->title?>">(建议不超过18个汉字) 66 <input type="text" name="title" class="form-control" required="required" value="<?=$model->title?>">(建议不超过18个汉字)
66 </div> 67 </div>
67 </div> 68 </div>
68 - 69 +
69 <div class="form-group"> 70 <div class="form-group">
70 <label class="col-sm-3 control-label">水印文案: </label> 71 <label class="col-sm-3 control-label">水印文案: </label>
71 <div class="col-sm-5"> 72 <div class="col-sm-5">
72 <input type="text" name="watermark" class="form-control" value="<?=$model->watermark?>"> 73 <input type="text" name="watermark" class="form-control" value="<?=$model->watermark?>">
73 </div> 74 </div>
74 </div> 75 </div>
75 - 76 +
76 <div class="form-group"> 77 <div class="form-group">
77 <label class="col-sm-3 control-label">主播: <span class="asterisk">*</span></label> 78 <label class="col-sm-3 control-label">主播: <span class="asterisk">*</span></label>
78 <div class="col-sm-5"> 79 <div class="col-sm-5">
79 <?php echo Html::dropDownList('master_id', $model->master_id,$masters, ['class' => 'width300 select-basic', 'required'=>"required"]);?> 80 <?php echo Html::dropDownList('master_id', $model->master_id,$masters, ['class' => 'width300 select-basic', 'required'=>"required"]);?>
80 </div> 81 </div>
81 - 82 +
82 </div> 83 </div>
83 84
84 <div class="form-group"> 85 <div class="form-group">
@@ -87,21 +88,21 @@ $this->registerJs($this->blocks['javascript'],View::POS_END) @@ -87,21 +88,21 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
87 <input type="text" name="starting_time" class="form-control" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" value="<?=$model->starting_time ? date('Y-m-d H:i:s',$model->starting_time) : ''?>"> 88 <input type="text" name="starting_time" class="form-control" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" value="<?=$model->starting_time ? date('Y-m-d H:i:s',$model->starting_time) : ''?>">
88 </div> 89 </div>
89 </div> 90 </div>
90 - 91 +
91 <div class="form-group"> 92 <div class="form-group">
92 <label class="col-sm-3 control-label">房间密钥: <span class="asterisk">*</span></label> 93 <label class="col-sm-3 control-label">房间密钥: <span class="asterisk">*</span></label>
93 <div class="col-sm-5"> 94 <div class="col-sm-5">
94 <input type="text" name="secret" class="form-control" required="required" value="<?=$model->secret?>"> 95 <input type="text" name="secret" class="form-control" required="required" value="<?=$model->secret?>">
95 </div> 96 </div>
96 </div> 97 </div>
97 - 98 +
98 <div class="form-group"> 99 <div class="form-group">
99 <label class="col-sm-3 control-label">是否精选: </label> 100 <label class="col-sm-3 control-label">是否精选: </label>
100 <div class="col-sm-2"> 101 <div class="col-sm-2">
101 <?php echo Html::dropDownList('best', $model->best,Yii::$app->params['config']['best'], ['class' => 'form-control']);?> 102 <?php echo Html::dropDownList('best', $model->best,Yii::$app->params['config']['best'], ['class' => 'form-control']);?>
102 </div> 103 </div>
103 </div> 104 </div>
104 - 105 +
105 <div class="form-group"> 106 <div class="form-group">
106 <label class="col-sm-3 control-label">马甲状态: </label> 107 <label class="col-sm-3 control-label">马甲状态: </label>
107 <div class="col-sm-2"> 108 <div class="col-sm-2">
@@ -118,7 +119,7 @@ $this->registerJs($this->blocks['javascript'],View::POS_END) @@ -118,7 +119,7 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
118 <?php echo Html::dropDownList('living', $model->living,Yii::$app->params['config']['room_living'], ['class' => 'form-control']);?> 119 <?php echo Html::dropDownList('living', $model->living,Yii::$app->params['config']['room_living'], ['class' => 'form-control']);?>
119 </div> 120 </div>
120 </div> 121 </div>
121 - 122 +
122 <div class="form-group"> 123 <div class="form-group">
123 <label class="col-sm-3 control-label">头图: <span class="asterisk">*</span></label> 124 <label class="col-sm-3 control-label">头图: <span class="asterisk">*</span></label>
124 <div class="col-sm-9"> 125 <div class="col-sm-9">
@@ -128,7 +129,7 @@ $this->registerJs($this->blocks['javascript'],View::POS_END) @@ -128,7 +129,7 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
128 <?php endif;?> 129 <?php endif;?>
129 </div> 130 </div>
130 </div> 131 </div>
131 - 132 +
132 <div class="form-group"> 133 <div class="form-group">
133 <label class="col-sm-3 control-label">背景图: <span class="asterisk">*</span></label> 134 <label class="col-sm-3 control-label">背景图: <span class="asterisk">*</span></label>
134 <div class="col-sm-9"> 135 <div class="col-sm-9">
@@ -138,7 +139,7 @@ $this->registerJs($this->blocks['javascript'],View::POS_END) @@ -138,7 +139,7 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
138 <?php endif;?> 139 <?php endif;?>
139 </div> 140 </div>
140 </div> 141 </div>
141 - 142 +
142 <div class="form-group"> 143 <div class="form-group">
143 <label class="col-sm-3 control-label">业务线: <span class="asterisk">*</span></label> 144 <label class="col-sm-3 control-label">业务线: <span class="asterisk">*</span></label>
144 <div class="col-sm-5"> 145 <div class="col-sm-5">
@@ -147,18 +148,60 @@ $this->registerJs($this->blocks['javascript'],View::POS_END) @@ -147,18 +148,60 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
147 <?php endforeach;?> 148 <?php endforeach;?>
148 </div> 149 </div>
149 </div> 150 </div>
150 - 151 +
151 </div><!-- row --> 152 </div><!-- row -->
152 - </div><!-- panel-body -->  
153 - <div class="panel-footer"> 153 + </div>
  154 + <!-- 左侧表单 end-->
  155 + <!-- 右侧表单 begin-->
  156 + <div class="col-md-6">
154 <div class="row"> 157 <div class="row">
155 - <div class="col-sm-9 col-sm-offset-3">  
156 - <button class="btn btn-primary mr5" id="upload_button" onclick="return verify()">保存</button>  
157 - <a href="<?=$_refer?>" class="btn btn-dark">取消</a> 158 +
  159 + <div class="form-group">
  160 + <label class="col-sm-3 control-label">未开始排序: </label>
  161 + <div class="col-sm-3">
  162 + <input type="text" name="unstart_sort" class="form-control" value="<?=$model->unstart_sort?>">
  163 + </div>
  164 + <label class="col-sm-3 control-label">直播中排序: </label>
  165 + <div class="col-sm-3">
  166 + <input type="text" name="living_sort" class="form-control" value="<?=$model->living_sort?>">
  167 + </div>
158 </div> 168 </div>
159 - </div>  
160 - </div><!-- panel-footer -->  
161 - </div><!-- panel -->  
162 - </form>  
163 169
  170 + <div class="form-group">
  171 + <label class="col-sm-3 control-label">分享主图: </label>
  172 + <div class="col-sm-9">
  173 + <?=$sharePicUploader?>
  174 + <?php if ($model->id && $roomShare['pic']):?>
  175 + <div class="file-item thumbnail upload-state-done" id="share_pic"><img src="<?=CommonImages::getImageUrl($roomShare['pic'], 110, 110)?>"><div class="info">当前图片</div></div>
  176 + <?php endif;?>
  177 + </div>
  178 + </div>
  179 + <div class="form-group">
  180 + <label class="col-sm-3 control-label">分享标题: </label>
  181 + <div class="col-sm-9">
  182 + <input type="text" name="share_title" class="form-control" value="<?php echo ($model->id && $roomShare['title']) ? $roomShare['title']:''?>">
  183 + </div>
  184 + </div>
  185 + <div class="form-group">
  186 + <label class="col-sm-3 control-label">分享内容: </label>
  187 + <div class="col-sm-9">
  188 +<!-- <input type="text" name="share_content" class="form-control" value="">-->
  189 + <textarea rows="5" name="share_content" class="form-control"><?php echo ($model->id && $roomShare['content']) ? $roomShare['content']:''?></textarea>
  190 + </div>
  191 + </div>
  192 + </div>
  193 + </div>
  194 + <!-- 右侧表单 end-->
  195 + </div><!-- panel-body -->
  196 + <div class="panel-footer">
  197 + <div class="row">
  198 + <div class="col-sm-9 col-sm-offset-3">
  199 + <button class="btn btn-primary mr5" id="upload_button" onclick="return verify()">保存</button>
  200 + <a href="<?=$_refer?>" class="btn btn-dark">取消</a>
  201 + </div>
  202 + </div>
  203 + </div><!-- panel-footer -->
  204 + </div><!-- panel -->
  205 +</form>
164 </div> 206 </div>
  207 +
@@ -43,6 +43,7 @@ if(!isset($condition['backState'])) @@ -43,6 +43,7 @@ if(!isset($condition['backState']))
43 <th>对应主播</th> 43 <th>对应主播</th>
44 <th>对应直播房间号</th> 44 <th>对应直播房间号</th>
45 <th>腾讯视频连接</th> 45 <th>腾讯视频连接</th>
  46 + <th>排序</th>
46 <th>操作</th> 47 <th>操作</th>
47 <th>创建时间</th> 48 <th>创建时间</th>
48 </tr> 49 </tr>
@@ -63,10 +64,12 @@ if(!isset($condition['backState'])) @@ -63,10 +64,12 @@ if(!isset($condition['backState']))
63 </td> 64 </td>
64 <td><?php echo $video->room_id;?></td> 65 <td><?php echo $video->room_id;?></td>
65 <td><?php echo $video->url;?></td> 66 <td><?php echo $video->url;?></td>
  67 + <td><?php echo $video->sort;?></td>
66 <td style="white-space:nowrap"> 68 <td style="white-space:nowrap">
67 <div class="form-group" videoId="<?php echo $video->id;?>"> 69 <div class="form-group" videoId="<?php echo $video->id;?>">
68 <button class="btn btn-primary">编辑</button> 70 <button class="btn btn-primary">编辑</button>
69 <button class="btn btn-warning btn-metro" status="<?php echo $video->status;?>"><?php echo $video->status? '关闭':'开启';?></button> 71 <button class="btn btn-warning btn-metro" status="<?php echo $video->status;?>"><?php echo $video->status? '关闭':'开启';?></button>
  72 + <a class="btn btn-danger btn-metro" onclick="return confirm('删除该视频?')" href="/live/videodel/<?=$video->id?>" >删除</a>
70 </div> 73 </div>
71 </td> 74 </td>
72 <td><?php echo date('Y-m-d H:i:s', $video->create_time)?></td> 75 <td><?php echo date('Y-m-d H:i:s', $video->create_time)?></td>
@@ -26,10 +26,12 @@ use backend\widgets\YHGImage\Common\Images as CommonImages; @@ -26,10 +26,12 @@ use backend\widgets\YHGImage\Common\Images as CommonImages;
26 <div class="col-sm-5"> 26 <div class="col-sm-5">
27 <div class="col-sm-9"> 27 <div class="col-sm-9">
28 <?=$uploader?> 28 <?=$uploader?>
  29 + <?php if ($video->pic):?>
29 <div class="file-item thumbnail upload-state-done"> 30 <div class="file-item thumbnail upload-state-done">
30 - <img src="<?php echo CommonImages::getImageUrl($video->pic, 200, 200)?>">  
31 - <div class="info">当前图片</div> 31 + <img src="<?php echo CommonImages::getImageUrl($video->pic, 200, 200)?>">
  32 + <div class="info">当前图片</div>
32 </div> 33 </div>
  34 + <?php endif;?>
33 </div> 35 </div>
34 </div> 36 </div>
35 </div> 37 </div>
@@ -39,6 +41,33 @@ use backend\widgets\YHGImage\Common\Images as CommonImages; @@ -39,6 +41,33 @@ use backend\widgets\YHGImage\Common\Images as CommonImages;
39 <input type="text" name="url" class="form-control" value="<?php echo $video->url;?>"> 41 <input type="text" name="url" class="form-control" value="<?php echo $video->url;?>">
40 </div> 42 </div>
41 </div> 43 </div>
  44 + <div class="form-group">
  45 + <label class="col-sm-3 control-label">直播中排序: </label>
  46 + <div class="col-sm-3">
  47 + <input type="text" name="sort" class="form-control" value="<?=$video->sort?>">
  48 + </div>
  49 + </div>
  50 + <div class="form-group">
  51 + <label class="col-sm-3 control-label">分享主图: </label>
  52 + <div class="col-sm-9">
  53 + <?=$sharePicUploader?>
  54 + <?php if ($video->id && $videoShare['pic']):?>
  55 + <div class="file-item thumbnail upload-state-done" id="share_pic"><img src="<?=CommonImages::getImageUrl($videoShare['pic'], 110, 110)?>"><div class="info">当前图片</div></div>
  56 + <?php endif;?>
  57 + </div>
  58 + </div>
  59 + <div class="form-group">
  60 + <label class="col-sm-3 control-label">分享标题: </label>
  61 + <div class="col-sm-9">
  62 + <input type="text" name="share_title" class="form-control" value="<?php echo ($video->id && $videoShare['title']) ? $videoShare['title']:''?>">
  63 + </div>
  64 + </div>
  65 + <div class="form-group">
  66 + <label class="col-sm-3 control-label">分享内容: </label>
  67 + <div class="col-sm-9">
  68 + <textarea rows="5" name="share_content" class="form-control"><?php echo ($video->id && $videoShare['content']) ? $videoShare['content']:''?></textarea>
  69 + </div>
  70 + </div>
42 </div><!-- row --> 71 </div><!-- row -->
43 </div><!-- panel-body --> 72 </div><!-- panel-body -->
44 <div class="panel-footer"> 73 <div class="panel-footer">
@@ -28,7 +28,8 @@ class Environmen{ @@ -28,7 +28,8 @@ class Environmen{
28 Yii::setAlias('@admin', 'http://admin.live.yoho.cn'); 28 Yii::setAlias('@admin', 'http://admin.live.yoho.cn');
29 Yii::setAlias('@api', 'http://api.live.yoho.cn'); 29 Yii::setAlias('@api', 'http://api.live.yoho.cn');
30 30
31 - define('news_domain','http://newboys.yoho.cn/'); 31 + define('NEWS_DOMAIN','http://newboys.yoho.cn/');
  32 + define('YOHOBUY_H5_DOMAIN','http://m.yohobuy.com');
32 } 33 }
33 34
34 /** 35 /**
@@ -39,7 +40,8 @@ class Environmen{ @@ -39,7 +40,8 @@ class Environmen{
39 Yii::setAlias('@admin', 'http://testadmin.live.yoho.cn'); 40 Yii::setAlias('@admin', 'http://testadmin.live.yoho.cn');
40 Yii::setAlias('@api', 'http://testapi.live.yoho.cn'); 41 Yii::setAlias('@api', 'http://testapi.live.yoho.cn');
41 42
42 - define('news_domain','http://newboys.test.yoho.cn/'); 43 + define('NEWS_DOMAIN','http://newboys.test.yoho.cn/');
  44 + define('YOHOBUY_H5_DOMAIN','http://m.yohobuy.com');
43 } 45 }
44 } 46 }
45 Environmen::ENV(); 47 Environmen::ENV();
@@ -85,6 +87,15 @@ class Params { @@ -85,6 +87,15 @@ class Params {
85 */ 87 */
86 const UN_FORBID = 0; 88 const UN_FORBID = 0;
87 const IS_FORBID = 1; 89 const IS_FORBID = 1;
  90 +
  91 + /**
  92 + * 直播分享类型
  93 + */
  94 + const LIVE_SHARE_TYPE = 1;
  95 + /**
  96 + * 回看分享类型
  97 + */
  98 + const VIDEO_SHARE_TYPE = 2;
88 } 99 }
89 100
90 return [ 101 return [
@@ -143,5 +154,5 @@ return [ @@ -143,5 +154,5 @@ return [
143 'failed_code'=>8001, 154 'failed_code'=>8001,
144 //异常状态 155 //异常状态
145 'exception_code'=>500, 156 'exception_code'=>500,
146 - 'news_domain'=>news_domain, 157 + 'news_domain'=>NEWS_DOMAIN,
147 ]; 158 ];
@@ -37,7 +37,7 @@ class Room extends \yii\db\ActiveRecord @@ -37,7 +37,7 @@ class Room extends \yii\db\ActiveRecord
37 public function rules() 37 public function rules()
38 { 38 {
39 return [ 39 return [
40 - [['room_id', 'master_id', 'starting_time', 'best', 'vest', 'living', 'status', 'create_time', 'update_time'], 'integer'], 40 + [['room_id', 'master_id', 'starting_time', 'best', 'vest', 'living', 'status', 'unstart_sort', 'living_sort', 'create_time', 'update_time'], 'integer'],
41 [['title', 'watermark'], 'string', 'max' => 100], 41 [['title', 'watermark'], 'string', 'max' => 100],
42 [['app', 'secret'], 'string', 'max' => 50], 42 [['app', 'secret'], 'string', 'max' => 50],
43 [['pic', 'background_pic'], 'string', 'max' => 255], 43 [['pic', 'background_pic'], 'string', 'max' => 255],
  1 +<?php
  2 +
  3 +namespace common\models;
  4 +
  5 +use Yii;
  6 +use common\config\Params;
  7 +use backend\widgets\YHGImage\Common\Images as CommonImages;
  8 +
  9 +/**
  10 + * This is the model class for table "{{%share}}".
  11 + *
  12 + * @property integer $id
  13 + * @property integer $obj_id
  14 + * @property integer $type
  15 + * @property string $title
  16 + * @property string $content
  17 + * @property integer $create_time
  18 + * @property integer $update_time
  19 + */
  20 +class Share extends \yii\db\ActiveRecord
  21 +{
  22 + /**
  23 + * @inheritdoc
  24 + */
  25 + public static function tableName()
  26 + {
  27 + return '{{%share}}';
  28 + }
  29 +
  30 + /**
  31 + * @inheritdoc
  32 + */
  33 + public function rules()
  34 + {
  35 + return [
  36 + [['obj_id', 'type', 'create_time', 'update_time'], 'integer'],
  37 + [['content'], 'string'],
  38 + [['pic'], 'string', 'max' => 200],
  39 + [['title'], 'string', 'max' => 100],
  40 + [['obj_id', 'type'], 'unique', 'targetAttribute' => ['obj_id', 'type'], 'message' => 'The combination of Obj ID and Type has already been taken.'],
  41 + ];
  42 + }
  43 +
  44 + /**
  45 + * @inheritdoc
  46 + */
  47 + public function attributeLabels()
  48 + {
  49 + return [
  50 + 'id' => 'ID',
  51 + 'obj_id' => 'Obj ID',
  52 + 'type' => 'Type',
  53 + 'pic' => '分享头图',
  54 + 'title' => '分享标题',
  55 + 'content' => '分享内容',
  56 + 'create_time' => 'Create Time',
  57 + 'update_time' => 'Update Time',
  58 + ];
  59 + }
  60 +
  61 + public function getLivingShare($room_id)
  62 + {
  63 + return $this->get($room_id, Params::LIVE_SHARE_TYPE);
  64 + }
  65 +
  66 + public function getVideoShare($video_id)
  67 + {
  68 + return $this->get($video_id, Params::VIDEO_SHARE_TYPE);
  69 + }
  70 +
  71 + private function get($obj_id, $type)
  72 + {
  73 + $ret = [
  74 + 'share_pic' => 'http://img11.static.yhbimg.com/global/2016/08/17/18/01f17a9cd44149052482e4ee58e590cf1b.png?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80',
  75 + 'share_url' => ($type == Params::LIVE_SHARE_TYPE) ? YOHOBUY_H5_DOMAIN.'/activity/live/' . $obj_id : YOHOBUY_H5_DOMAIN.'/activity/live/replay/' . $obj_id,
  76 + 'share_title' => '有货潮流新品节直播开始啦,快来看!',
  77 + 'share_content' => 'YO\'HOOD嘉年华现场火热直播中,明星潮牌等你来!',
  78 + ];
  79 + if ($model = self::findOne(['obj_id' => $obj_id, 'type' => $type])) {
  80 + $ret['share_pic'] = CommonImages::getTemplateComplex($model->pic, 2);
  81 + $ret['share_title'] = $model->title;
  82 + $ret['share_content'] = $model->content;
  83 + }
  84 + return $ret;
  85 + }
  86 +}
@@ -6,6 +6,7 @@ use Yii; @@ -6,6 +6,7 @@ use Yii;
6 use common\lib\QcloudApi\Client as QcloudApiClient; 6 use common\lib\QcloudApi\Client as QcloudApiClient;
7 use common\lib\QcloudApi\QcloudApi as Qapi; 7 use common\lib\QcloudApi\QcloudApi as Qapi;
8 use common\lib\YohonowApi\Request as YHNowApiReq; 8 use common\lib\YohonowApi\Request as YHNowApiReq;
  9 +use common\config\Params;
9 10
10 /** 11 /**
11 * This is the model class for table "{{%video}}". 12 * This is the model class for table "{{%video}}".
@@ -115,26 +116,21 @@ class Video extends \yii\db\ActiveRecord @@ -115,26 +116,21 @@ class Video extends \yii\db\ActiveRecord
115 { 116 {
116 $transaction = $this->getDb()->beginTransaction(); 117 $transaction = $this->getDb()->beginTransaction();
117 try { 118 try {
118 - /*$qchannel = (new \yii\db\Query())  
119 - ->select('channel_id')  
120 - ->from('tbl_room_qchannel')  
121 - ->where(['room_id' => $room_id])  
122 - ->one();*/ 119 +
123 $room = (new \yii\db\Query()) 120 $room = (new \yii\db\Query())
124 - ->select('app,title,master_id') 121 + ->select('app,title,master_id,status')
125 ->from('tbl_room') 122 ->from('tbl_room')
126 ->where(['room_id' => $room_id]) 123 ->where(['room_id' => $room_id])
127 ->one(); 124 ->one();
128 - $time = time();  
129 - //此处有bug,channel_id必须要转成字符串,不然底层会转换成科学计数法的格式  
130 - //$ret = QcloudApiClient::self()->CreateRecord(strval($qchannel['channel_id']), date('Y-m-d H:i:s',time()+120), '');  
131 - //file_put_contents("/tmp/live.log",date('Y-m-d H:i:s')."|start ".var_export($ret,true),FILE_APPEND)."\n";  
132 - if (1) {//$ret['code'] == 0 125 + if(!$room['status']){
  126 + throw new \Exception("该房间已被禁用,请联系管理员");
  127 + }
  128 + if (1) {
133 $this->setAttributes([ 129 $this->setAttributes([
134 'app' => $room['app'], 130 'app' => $room['app'],
135 'task_id' => 0,//$ret['task_id'] 131 'task_id' => 0,//$ret['task_id']
136 'live_title' => $room['title'], 132 'live_title' => $room['title'],
137 - 'live_start_time' => $time, 133 + 'live_start_time' => time(),
138 'live_end_time' => 0, 134 'live_end_time' => 0,
139 'master_id' => $room['master_id'], 135 'master_id' => $room['master_id'],
140 'room_id' => $room_id, 136 'room_id' => $room_id,
@@ -145,7 +141,7 @@ class Video extends \yii\db\ActiveRecord @@ -145,7 +141,7 @@ class Video extends \yii\db\ActiveRecord
145 } 141 }
146 //更新房间主表直播状态 142 //更新房间主表直播状态
147 $result = Yii::$app->db->createCommand() 143 $result = Yii::$app->db->createCommand()
148 - ->update('{{%room}}', ['living' => 1,'update_time'=>time()], ['room_id' => $room_id]) 144 + ->update('{{%room}}', ['living' => Params::LIVING,'update_time'=>time()], ['room_id' => $room_id])
149 ->execute(); 145 ->execute();
150 if (!$result) { 146 if (!$result) {
151 throw new \Exception('tbl_room update error'); 147 throw new \Exception('tbl_room update error');
@@ -189,40 +185,38 @@ class Video extends \yii\db\ActiveRecord @@ -189,40 +185,38 @@ class Video extends \yii\db\ActiveRecord
189 { 185 {
190 $transaction = $this->getDb()->beginTransaction(); 186 $transaction = $this->getDb()->beginTransaction();
191 try { 187 try {
192 - /*$qchannel = (new \yii\db\Query())  
193 - ->select('channel_id')  
194 - ->from('tbl_room_qchannel')  
195 - ->where(['room_id' => $room_id])  
196 - ->one();*/ 188 +
197 $video = $this->find() 189 $video = $this->find()
198 ->where(['room_id' => $room_id, 'live_end_time' => 0]) 190 ->where(['room_id' => $room_id, 'live_end_time' => 0])
199 ->orderBy(['live_start_time' => SORT_DESC]) 191 ->orderBy(['live_start_time' => SORT_DESC])
200 ->one(); 192 ->one();
201 if ($video) { 193 if ($video) {
202 - //此处有bug,channel_id必须要转成字符串,不然底层会转换成科学计数法的格式  
203 - //$ret = QcloudApiClient::self()->StopRecord(strval($qchannel['channel_id']), $video['task_id']);  
204 - //file_put_contents("/tmp/live.log",date('Y-m-d H:i:s')."|stop ".var_export($ret,true),FILE_APPEND)."\n";  
205 $room = (new \yii\db\Query()) 194 $room = (new \yii\db\Query())
206 ->select('app,title,master_id') 195 ->select('app,title,master_id')
207 ->from('tbl_room') 196 ->from('tbl_room')
208 ->where(['room_id' => $room_id]) 197 ->where(['room_id' => $room_id])
209 ->one(); 198 ->one();
210 - if (1) {//$ret['code'] == 0 199 + if (1) {
211 $video->setAttributes([ 200 $video->setAttributes([
212 'live_end_time' => time(), 201 'live_end_time' => time(),
213 ]); 202 ]);
214 if (!$video->update()) { 203 if (!$video->update()) {
215 throw new \Exception(current($this->getFirstErrors())); 204 throw new \Exception(current($this->getFirstErrors()));
216 } 205 }
217 - $living_status = 2; 206 + $updateFields = [
  207 + 'living' => Params::LIVE_END,
  208 + 'update_time' => time(),
  209 + 'unstart_sort' => 0,
  210 + 'living_sort' => 0
  211 + ];
218 //更新房间主表直播状态 212 //更新房间主表直播状态
219 $result = Yii::$app->db->createCommand() 213 $result = Yii::$app->db->createCommand()
220 - ->update('{{%room}}', ['living' => $living_status,'update_time'=>time()], ['room_id' => $room_id]) 214 + ->update('{{%room}}', $updateFields, ['room_id' => $room_id])
221 ->execute(); 215 ->execute();
222 -  
223 if (!$result) { 216 if (!$result) {
224 throw new \Exception('tbl_room update error'); 217 throw new \Exception('tbl_room update error');
225 } 218 }
  219 +
226 //该房间如果包含资讯业务线,那么要更新资讯那边状态 220 //该房间如果包含资讯业务线,那么要更新资讯那边状态
227 if(in_array(\common\config\Params::YOHONOW,explode(',',$room['app']))){ 221 if(in_array(\common\config\Params::YOHONOW,explode(',',$room['app']))){
228 $news_ret = YHNowApiReq::getInstance()->setLiveStat($room_id,0); 222 $news_ret = YHNowApiReq::getInstance()->setLiveStat($room_id,0);
@@ -8,6 +8,7 @@ use common\models\Room; @@ -8,6 +8,7 @@ use common\models\Room;
8 use common\models\Video; 8 use common\models\Video;
9 use common\models\LiveComment; 9 use common\models\LiveComment;
10 use common\models\RoomNums; 10 use common\models\RoomNums;
  11 +use common\models\Share;
11 12
12 class LivingController extends BaseController 13 class LivingController extends BaseController
13 { 14 {
@@ -61,7 +62,10 @@ class LivingController extends BaseController @@ -61,7 +62,10 @@ class LivingController extends BaseController
61 $key = __CLASS__.__FUNCTION__.'app'.$this->app; 62 $key = __CLASS__.__FUNCTION__.'app'.$this->app;
62 if (!$ret = $this->cache->get($key)){ 63 if (!$ret = $this->cache->get($key)){
63 64
64 - $ret = Room::find()->with(['master','roomNums'])->where(['and',['living'=>1],"find_in_set({$this->app},app)"])->joinWith('roomNums rn')->orderBy(['rn.online_num'=>SORT_DESC])->all(); 65 + $ret = Room::find()->with(['master','roomNums'])->where(['and',['living'=>1],"find_in_set({$this->app},app)"])
  66 + ->joinWith('roomNums rn')
  67 + ->orderBy(['living_sort'=>SORT_DESC,'rn.online_num'=>SORT_DESC])
  68 + ->all();
65 69
66 foreach ($ret as $k=>$model){ 70 foreach ($ret as $k=>$model){
67 $row = [ 71 $row = [
@@ -112,7 +116,10 @@ class LivingController extends BaseController @@ -112,7 +116,10 @@ class LivingController extends BaseController
112 $key = __CLASS__.__FUNCTION__.'app'.$this->app; 116 $key = __CLASS__.__FUNCTION__.'app'.$this->app;
113 if (!$ret = $this->cache->get($key)){ 117 if (!$ret = $this->cache->get($key)){
114 118
115 - $ret = Room::find()->with(['master'])->where(['and',['living'=>0],['!=','starting_time',0],"find_in_set({$this->app},app)"])->orderBy(['starting_time'=>SORT_ASC])->all(); 119 + $ret = Room::find()->with(['master'])
  120 + ->where(['and',['living'=>0],['!=','starting_time',0],"find_in_set({$this->app},app)"])
  121 + ->orderBy(['unstart_sort'=>SORT_DESC,'starting_time'=>SORT_ASC])
  122 + ->all();
116 123
117 foreach ($ret as $k=>$model){ 124 foreach ($ret as $k=>$model){
118 $row = [ 125 $row = [
@@ -152,7 +159,10 @@ class LivingController extends BaseController @@ -152,7 +159,10 @@ class LivingController extends BaseController
152 $key = __CLASS__.__FUNCTION__.'app'.$this->app; 159 $key = __CLASS__.__FUNCTION__.'app'.$this->app;
153 if (!$ret = $this->cache->get($key)){ 160 if (!$ret = $this->cache->get($key)){
154 161
155 - $ret = Video::find()->with(['master'])->where(['and',['status' => 1],['not', ['url' => null]],['not', ['url' => '']],"find_in_set({$this->app},app)"])->orderBy(['create_time'=>SORT_DESC])->all(); 162 + $ret = Video::find()->with(['master'])
  163 + ->where(['and',['status' => 1],['not', ['url' => null]],['not', ['url' => '']],"find_in_set({$this->app},app)"])
  164 + ->orderBy(['sort'=>SORT_DESC,'create_time'=>SORT_DESC])
  165 + ->all();
156 166
157 foreach ($ret as $k=>$model){ 167 foreach ($ret as $k=>$model){
158 $row = [ 168 $row = [
@@ -267,10 +277,9 @@ class LivingController extends BaseController @@ -267,10 +277,9 @@ class LivingController extends BaseController
267 } 277 }
268 278
269 $ret['background_pic'] = $ret['background_pic'] ? : 'http://img11.static.yhbimg.com/global/2016/08/17/18/01f17a9cd44149052482e4ee58e590cf1b.png'; 279 $ret['background_pic'] = $ret['background_pic'] ? : 'http://img11.static.yhbimg.com/global/2016/08/17/18/01f17a9cd44149052482e4ee58e590cf1b.png';
270 - $ret['share_url'] = 'http://m.yohobuy.com/activity/live/'.$room_id;  
271 - $ret['share_title'] = '有货潮流新品节直播开始啦,快来看!';  
272 - $ret['share_content'] = 'YO\'HOOD嘉年华现场火热直播中,明星潮牌等你来!';  
273 - 280 + $share = (new Share)->getLivingShare($room_id);
  281 + $ret += $share;
  282 +
274 $dependency = new \yii\caching\DbDependency(['sql' => Yii::$app->db 283 $dependency = new \yii\caching\DbDependency(['sql' => Yii::$app->db
275 ->createCommand('SELECT update_time FROM {{%room}} WHERE room_id=:room_id') 284 ->createCommand('SELECT update_time FROM {{%room}} WHERE room_id=:room_id')
276 ->bindValue(':room_id', $room_id) 285 ->bindValue(':room_id', $room_id)
@@ -320,9 +329,8 @@ class LivingController extends BaseController @@ -320,9 +329,8 @@ class LivingController extends BaseController
320 } 329 }
321 330
322 $ret['background_pic'] = 'http://img11.static.yhbimg.com/global/2016/08/17/18/01f17a9cd44149052482e4ee58e590cf1b.png'; 331 $ret['background_pic'] = 'http://img11.static.yhbimg.com/global/2016/08/17/18/01f17a9cd44149052482e4ee58e590cf1b.png';
323 - $ret['share_url'] = 'http://m.yohobuy.com/activity/live/replay/'.$video_id;  
324 - $ret['share_title'] = '有货潮流新品节直播开始啦,快来看!';  
325 - $ret['share_content'] = 'YO\'HOOD嘉年华现场火热直播中,明星潮牌等你来!'; 332 + $share = (new Share)->getVideoShare($video_id);
  333 + $ret += $share;
326 334
327 $dependency = new \yii\caching\DbDependency(['sql' => Yii::$app->db 335 $dependency = new \yii\caching\DbDependency(['sql' => Yii::$app->db
328 ->createCommand('SELECT update_time FROM {{%video}} WHERE id=:video_id') 336 ->createCommand('SELECT update_time FROM {{%video}} WHERE id=:video_id')
@@ -138,11 +138,6 @@ class RoomController extends BaseController @@ -138,11 +138,6 @@ class RoomController extends BaseController
138 $this->renderJson($retArr['code'], $retArr['messsage']); 138 $this->renderJson($retArr['code'], $retArr['messsage']);
139 } 139 }
140 140
141 - public function actionGetlivingroomid()  
142 - {  
143 - return [10000, 10001];  
144 - }  
145 -  
146 /** 141 /**
147 * 获取禁言用户列表 142 * 获取禁言用户列表
148 */ 143 */