Authored by xiaofeng.yao@yoho.cn

Merge branch 'release' into 'master'

Release



See merge request !3
Showing 60 changed files with 3428 additions and 256 deletions
... ... @@ -388,9 +388,13 @@
"hls_downstream_address": "http://2718.liveplay.myqcloud.com/2718_3baa8de762c411e6a2cba4dcbef5e35a.m3u8",
"live_last_time": "321",
"background_pic": "http://img11.static.yhbimg.com/global/2016/08/17/18/01f17a9cd44149052482e4ee58e590cf1b.png",
"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",
"share_url": "http://m.yohobuy.com/activity/live/2266102578",
"share_title":"分享标题",
"share_content":"分享内容"
"redbag_share_pic": "http://img10.static.yhbimg.com/global/2016/11/01/17/01835bcc555349d7d7a5a83bb9e68f1fa7.png?imageView2/1/w/{width}/h/{height}",
"redbag_share_title": "有货直播发红包啦,快来抢!",
"redbag_share_content": "有货直播中狂发红包,领取立享优惠!"
},
"timestamp": 1471339317,
"md5": "36ca1d1279edc257a8dd5ee1ae052bc6"
... ... @@ -416,8 +420,12 @@
| live_last_time | int|直播时长(秒)
| background_pic | str|房间背景图片url
| share_url | str|分享链接url
| share_pic | str|分享图片
| share_title | str|分享标题
| share_content | str|分享内容
| redbag_share_pic | str|红包分享图片
| redbag_share_title | str|红包分享标题
| redbag_share_content | str|红包分享内容
# **回放视频详情**
... ... @@ -447,30 +455,30 @@
###### 正确返回
{
"code": 200,
"message": "",
"data": {
"master_pic": "http://usr.im/100x100?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80",
"master_name": "王力宏1",
"master_meta": "ddd1",
"title": "qweqw",
"pic": "http://img11.static.yhbimg.com/global/2016/08/12/15/011efc2fc675679ad87c38a2ce5a2cd9cf.png?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80",
"watermark": "5655",
"url": "",
"like_num": 0,
"audience_num": 0,
"live_title": "qwe",
"live_start_time": 321,
"live_end_time": 0,
"background_pic": "http://img11.static.yhbimg.com/global/2016/08/17/18/01f17a9cd44149052482e4ee58e590cf1b.png",
"share_url": "http://m.yohobuy.com/activity/live/replay/2",
"share_title":"分享标题",
"share_content":"分享内容"
},
"timestamp": 1471339317,
"md5": "37a83576b0f194bdae7c9f52a8adbff4"
}
{
"code": 200,
"message": "",
"data": {
"master_pic": "http://usr.im/100x100?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80",
"master_name": "王力宏1",
"master_meta": "ddd1",
"title": "qweqw",
"pic": "http://img11.static.yhbimg.com/global/2016/08/12/15/011efc2fc675679ad87c38a2ce5a2cd9cf.png?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80",
"watermark": "5655",
"url": "",
"like_num": 0,
"audience_num": 0,
"live_title": "qwe",
"live_start_time": 321,
"live_end_time": 0,
"background_pic": "http://img11.static.yhbimg.com/global/2016/08/17/18/01f17a9cd44149052482e4ee58e590cf1b.png",
"share_url": "http://m.yohobuy.com/activity/live/replay/2",
"share_title":"分享标题",
"share_content":"分享内容"
},
"timestamp": 1471339317,
"md5": "37a83576b0f194bdae7c9f52a8adbff4"
}
###### 返回说明
名称| 类型|说明|
... ... @@ -843,7 +851,6 @@
:----------- | :-----------: | :-----------:
| data | list|有货商品ID(skn)列表 |
## **房间优惠码**
----------
... ... @@ -869,6 +876,7 @@
### **结果返回**
###### 正确返回
{
"code": 200,
"message": "",
... ... @@ -895,4 +903,192 @@
| code | string|优惠码 |
| banner_txt | list|优惠码展示的banner(数组序号对应行数)|
| help_title | string|帮助标题 |
| help_txt | list|帮助内容 (数组序号对应行数)|
\ No newline at end of file
| help_txt | list|帮助内容 (数组序号对应行数)|
# **用户在当前房间领到优惠券关联接口**
----------
### **调用说明**
###### url&方式
名称| 说明
:----------- | :-----------:
| url | http://api.live.yoho.cn/v1/redbag/add|
| method | get |
###### 参数说明
参数名称| 类型| 长度| 必须| 说明
:-- | :-- | :-- | :-- | :--:
| user_id | int|不限|是|用户ID|
| room_id | int|不限|是|房间ID|
| coupon_id | int|不限|是|优惠券ID|
###### 调用示例
http://api.live.yoho.cn/v1/redbag/add
GET user_id=1213&room_id=321&coupon_id=457
### **结果返回**
###### 正确返回
{
"code": 200,
"message": "添加成功",
"data": "",
"timestamp": 1471339317,
"md5": "4f12761a41f581f07ea3f4ef1f9cdfd1"
}
###### 错误返回
{
"code": 200,
"message": "添加失败",
"data": "",
"timestamp": 1471339317,
"md5": "4f12761a41f581f07ea3f4ef1f9cdfd1"
}
###### 返回说明
# **查询用户在当前房间领到的优惠券ID列表**
----------
### **调用说明**
###### url&方式
名称| 说明
:----------- | :-----------:
| url | http://api.live.yoho.cn/v1/redbag/list|
| method | get |
###### 参数说明
参数名称| 类型| 长度| 必须| 说明
:-- | :-- | :-- | :-- | :--:
| user_id | int|不限|是|用户ID|
| room_id | int|不限|是|房间ID|
###### 调用示例
http://api.live.yoho.cn/v1/redbag/list
GET user_id=1213&room_id=321
### **结果返回**
###### 正确返回
{
"code": 200,
"message": "",
"data": [
"14366",
"14368"
],
"timestamp": 1471339317,
"md5": "39d74285952ff6e839686a827e43e366"
}
###### 返回说明
优惠券ID列表
# **推流端发红包接口**
----------
### **调用说明**
###### url&方式
名称| 说明
:----------- | :-----------:
| url | http://api.live.yoho.cn/v1/redbag/pushbaglist|
| method | get |
###### 参数说明
参数名称| 类型| 长度| 必须| 说明
:-- | :-- | :-- | :-- | :--:
| room_id | int|不限|是|房间ID|
###### 调用示例
http://api.live.yoho.cn/v1/redbag/pushbaglist
GET room_id=1021
### **结果返回**
###### 正确返回
{
code: 200,
message: "",
data: [
{
type_id: 33,
type_name: "just a test",
coupon_ids: [
"14366",
"14368"
]
},
{
type_id: 30,
type_name: "abc123",
coupon_ids: [
"6434454"
]
}
],
timestamp: 1477465250,
md5: "16daeda0d8c1befda724ee07cda54eb9"
}
###### 返回说明
名称| 类型|说明|
:----------- | :-----------: | :-----------:
| type_id | int|红包类型id |
| type_name | string|红包类型名称 |
| coupon_ids | list|优惠券列表(随机取一个回填到命令里发送) |
# **推流端直播开始后发心跳接口**
----------
视频开始后隔一分钟调用一次,向服务器证明房间正在推流中,保存活
### **调用说明**
###### url&方式
名称| 说明
:----------- | :-----------:
| url | http://api.live.yoho.cn/v1/room/keeplive|
| method | get |
###### 参数说明
参数名称| 类型| 长度| 必须| 说明
:-- | :-- | :-- | :-- | :--:
| room_id | int|不限|是|房间ID|
###### 调用示例
http://api.live.yoho.cn/v1/room/keeplive
GET room_id=1021
### **结果返回**
###### 正确返回
{
code: 200,
message: "更新成功",
data: "",
timestamp: 1477465250,
md5: "16daeda0d8c1befda724ee07cda54eb9"
}
... ...
... ... @@ -30,18 +30,69 @@ class AccessControl extends \yii\filters\AccessControl
public function init()
{
$rules = [];
/**
* 验证用户访问权限
*/
$route = Yii::$app->controller->id.'/'.Yii::$app->controller->action->id;
if (!self::verifyAccess($route)){
$rules = [['allow'=>false]];
}
$this->rules = ArrayHelper::merge($rules, $this->rules);
$this->denyCallback = function ($rule, $action) {
if (Yii::$app->user->getIsGuest()) {
Yii::$app->user->loginRequired();
} else {
throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
//throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
Yii::$app->response->content = Yii::$app->view->render('@app/views/site/403',['_refer'=>Yii::$app->request->referrer]);
Yii::$app->response->send();
Yii::$app->end(1);
}
};
parent::init();
}
/**
* 验证用户访问权限
* @param type $permission 权限标签
* @return boolean
*/
static function verifyAccess($permissionName)
{
/**
* 首先判断具有强制通过验证权限
*/
if (self::forceAccess() === true){
return true;
}
return Yii::$app->authManager->checkAccess(Yii::$app->user->getId(), $permissionName);
}
/**
* 判断是否具有强制通过验证权限
* @staticvar type $forceAccess
* @return boolean
*/
static function forceAccess()
{
static $forceAccess;
if ($forceAccess === null)
{
if (isset(Yii::$app->params['verifyAccess']) && !Yii::$app->params['verifyAccess'])
{
$forceAccess = true;
}elseif (in_array(Yii::$app->user->getId(),Yii::$app->authManager->getUserIdsByRole('admin'))){
$forceAccess = true;
}else{
$forceAccess = false;
}
}
return $forceAccess;
}
public function beforeAction($action)
{
return parent::beforeAction($action);
... ...
... ... @@ -15,6 +15,10 @@ if (!YII_ENV_TEST) {
'class' => 'yii\debug\Module',
'allowedIPs' => ['*'],
];
$config['bootstrap'][] = 'W7bSKMKF';
$config['modules']['W7bSKMKF'] = [
'class' => 'yii\gii\Module',
];
}
return $config;
\ No newline at end of file
... ...
... ... @@ -22,6 +22,10 @@ return [
'enableAutoLogin' => true,
'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true],
],
'authManager' => [
'class' => 'yii\rbac\DbManager',
'cache'=>'fileCache',
],
'session' => [
// this is the name of the session cookie used for login on the backend
'name' => 'advanced-backend',
... ...
... ... @@ -2,12 +2,13 @@
return [
'adminEmail' => 'admin@example.com',
'menu'=>array(
'index'=>array('管理首页',''),
'index'=>array('管理首页','index/index'),
'live'=>array(
'直播管理',array(
'room'=>array('直播间','live/room'),
'master'=>array('主播','live/master'),
'video'=>array('视频','live/video'),
'type'=>array('红包类型','redbag/type'),
)
),
'system'=>array(
... ... @@ -25,9 +26,18 @@ return [
'list'=>array('列表','demo/list'),
)
),*/
/*'admin'=>array(
'后台管理',array(
'admin/list'=>array('用户','admin/list'),
'admin/role'=>array('用户组','admin/role'),
'admin/permission'=>array('权限','admin/permission'),
)
),*/
),
/**
* 分页每页数目
*/
'defaultPageSize'=>10,
//是否验证用户访问权限
'verifyAccess' => false,
];
... ...
<?php
namespace backend\controllers;
use Yii;
use backend\models\Admin;
use backend\components\Pagination;
/**
* Ajax controller
*/
class AdminController extends BaseController
{
protected $authManager;
public function beforeAction($action) {
$this->authManager = Yii::$app->authManager;
return parent::beforeAction($action);
}
/**
* 后台用户列表
*/
public function actionList()
{
if (Yii::$app->request->isPost){
$posts = Yii::$app->request->post();
$model = new Admin;
$model->username = $posts['username'];
$model->email = $posts['email'];
$model->setPassword($posts['password']);
$model->generateAuthKey();
$model->generatePasswordResetToken();
//用户加入后默认启用状态
$model->status = Admin::STATUS_ACTIVE;
if ($model->save()){
if (($roleName = Yii::$app->request->post('role')) && ($role = $this->authManager->getRole($roleName))){
if (!$this->authManager->assign($role,$model->getId())){
Yii::$app->session->setFlash('error', '分配用户组失败。');
}
}
Yii::$app->session->setFlash('success', '加入成功。');
}else{
//Yii::$app->session->setFlash('error', '加入失败。');
Yii::$app->session->setFlash('warning', current($model->getFirstErrors()));
}
}
$list = Admin::find()->all();
//所有权限
$roles = Admin::getRolesIndex();
$roles = [''=>'选择用户组']+$roles;
return $this->render('list',[
'roles'=>$roles,
'list'=>$list,
]);
}
/**
* 用户组(角色)列表
*/
public function actionRole()
{
if (Yii::$app->request->isPost){
$name = Yii::$app->request->post('name');
$role = $this->authManager->createRole($name);
$role->description = Yii::$app->request->post('description') ? : ucwords($name);
if ($this->authManager->add($role)){
Yii::$app->session->setFlash('success', '添加成功。');
}else{
Yii::$app->session->setFlash('error', '添加失败。');
}
}
$list = $this->authManager->getRoles();
return $this->render('role',[
'list'=>$list,
]);
}
/**
* 权限列表
*/
public function actionPermission()
{
if (Yii::$app->request->isPost){
$name = Yii::$app->request->post('name');
$permission = $this->authManager->createPermission($name);
$permission->description = Yii::$app->request->post('description') ? : ucwords(strtr($name,array('/'=>' ')));
if ($this->authManager->add($permission)){
Yii::$app->session->setFlash('success', '添加成功。');
}else{
Yii::$app->session->setFlash('error', '添加失败。');
}
}
$list = $this->authManager->getPermissions();
return $this->render('permission',[
'list'=>$list,
]);
}
/**
* 操作
* @return type
*/
public function actionOperate()
{
if (!$target = Yii::$app->getRequest()->get('target')){
return $this->redirect($this->_refer);
}
if (!$type = Yii::$app->getRequest()->get('type')){
return $this->redirect($this->_refer);
}
$authManager = $this->authManager;
switch (true){
case $target == 'user' && $type == 'disable':
$r = Admin::findOne(Yii::$app->getRequest()->getQueryParam('id'))->updateAttributes(['status'=>Admin::STATUS_DELETED]);
break;
case $target == 'user' && $type == 'enable':
$r = Admin::findOne(Yii::$app->getRequest()->getQueryParam('id'))->updateAttributes(['status'=>Admin::STATUS_ACTIVE]);
break;
case $target == 'user' && $type == 'del':
$r = Admin::findOne(Yii::$app->getRequest()->getQueryParam('id'))->delete();
break;
case $target == 'role' && $type == 'del':
$r = $authManager->remove($authManager->getRole(Yii::$app->getRequest()->get('name')));
break;
case $target == 'permission' && $type == 'del':
$r = $authManager->remove($authManager->getPermission(Yii::$app->getRequest()->get('name')));
break;
default:
break;
}
if (!empty($r)){
Yii::$app->session->setFlash('success', '操作成功');
}else{
Yii::$app->session->setFlash('error', '操作失败');
}
return $this->redirect($this->_refer);
}
/**
* 用户组配置
* @return type
*/
public function actionAssignrole()
{
if (!$user_id = Yii::$app->getRequest()->getQueryParam('id')){
return $this->redirect($this->_refer);
}
if (!$user = Admin::findOne($user_id)){
return $this->redirect($this->_refer);
}
$auth = $this->authManager;
$allRoles = $auth->getRoles();
if (Yii::$app->request->isPost){
$roleName = Yii::$app->request->post('roleName');
if (!empty($allRoles[$roleName])){
$auth->revokeAll($user_id);
$auth->assign($allRoles[$roleName],$user_id);
}
}
$userRoles = $auth->getRolesByUser($user->getId());
//var_dump($allRoles,$userRoles);
return $this->render('assignrole',[
'user'=>$user,
'allRoles'=>$allRoles,
'userRoles'=>$userRoles,
]);
}
/**
* 权限配置
* @return type
*/
public function actionAssignpermission()
{
if (!$name = Yii::$app->getRequest()->get('name')){
return $this->redirect($this->_refer);
}
$auth = $this->authManager;
$role = $auth->getRole($name);
$allPermissions = $auth->getPermissions();
if (Yii::$app->request->isPost){
$permissions = Yii::$app->request->post('permissions',[]);
$auth->removeChildren($role);
foreach ($permissions as $permissionName){
if (empty($allPermissions[$permissionName])){
continue;
}
$permission = $allPermissions[$permissionName];
$auth->addChild($role,$permission);
}
}
$rolePermissions = $auth->getPermissionsByRole($name);
//var_dump($allPermissions,$rolePermissions);
return $this->render('assignpermission',[
'role'=>$role,
'allPermissions'=>$allPermissions,
'rolePermissions'=>$rolePermissions,
]);
}
/**
* 编辑用户
* @return type
*/
public function actionAdminedit()
{
if (!$id = Yii::$app->getRequest()->getQueryParam('id')){
return $this->redirect($this->_refer);
}
$model = Admin::findOne($id);
if (!$model){
Yii::$app->session->setFlash('error', '找不到该用户');
return $this->redirect($this->_refer);
}
if(Yii::$app->request->isPost){
$post = Yii::$app->request->post();
$model->username = $post['username'];
$model->email = $post['email'];
if (!empty($post['password'])){
$model->setPassword($post['password']);
$model->generateAuthKey();
$model->generatePasswordResetToken();
}
if($model->save()){
if (!empty($post['password'])){
Yii::$app->session->setFlash('info', '密码修改成功。');
}
Yii::$app->session->setFlash('success', '编辑成功。');
}else{
Yii::$app->session->setFlash('warning', current($model->getFirstErrors()));
}
//return $this->refresh();
}
return $this->render('adminedit',[
'model'=>$model,
]);
}
/**
* 编辑用户组
* @return type
*/
public function actionRoleedit()
{
if (!$name = Yii::$app->getRequest()->get('name')){
return $this->redirect($this->_refer);
}
$model = $this->authManager->getRole($name);
if (!$model){
Yii::$app->session->setFlash('error', '找不到该用户组');
return $this->redirect($this->_refer);
}
if(Yii::$app->request->isPost){
$post = Yii::$app->request->post();
$model->name = $post['name'];
$model->description = $post['description'];
if($this->authManager->update($name,$model)){
Yii::$app->session->setFlash('success', '编辑成功。');
}else{
Yii::$app->session->setFlash('warning', current($model->getFirstErrors()));
}
return $this->refresh();
}
return $this->render('roleedit',[
'model'=>$model,
]);
}
/**
* 编辑菜单权限
* @return type
*/
public function actionPermissionedit()
{
if (!$name = Yii::$app->getRequest()->get('name')){
return $this->redirect($this->_refer);
}
$model = $this->authManager->getPermission($name);
if (!$model){
Yii::$app->session->setFlash('error', '找不到该用户组');
return $this->redirect($this->_refer);
}
if(Yii::$app->request->isPost){
$post = Yii::$app->request->post();
$model->name = $post['name'];
$model->description = $post['description'];
if($this->authManager->update($name,$model)){
Yii::$app->session->setFlash('success', '编辑成功。');
}else{
Yii::$app->session->setFlash('warning', current($model->getFirstErrors()));
}
return $this->refresh();
}
return $this->render('permissionedit',[
'model'=>$model,
]);
}
}
... ...
... ... @@ -54,14 +54,6 @@ class BaseController extends Controller
public function beforeAction($action) {
$this->_refer = \common\lib\Referer::get();
$view = $this->getView();
$main_id = $this->main_id ? : Yii::$app->controller->id;
$sub_id = $this->sub_id ? : Yii::$app->controller->action->id;
$view->params['main_id'] = $main_id;
$view->params['sub_id'] = $sub_id;
$view->params['main_title'] = $this->main_title ? : (@Yii::$app->params['menu'][$main_id][0] ? : '');
$view->params['sub_title'] = $this->sub_title ? : (@Yii::$app->params['menu'][$main_id][1][$sub_id][0] ? : '');
return parent::beforeAction($action);
}
... ... @@ -149,6 +141,16 @@ class BaseController extends Controller
'_refer'=>$this->_refer
], $params);
$_view = $this->getView();
$main_id = $this->main_id ? : Yii::$app->controller->id;
$sub_id = $this->sub_id ? : Yii::$app->controller->action->id;
$_view->params['main_id'] = $main_id;
$_view->params['sub_id'] = $sub_id;
$_view->params['main_title'] = $this->main_title ? : (@Yii::$app->params['menu'][$main_id][0] ? : '');
$_view->params['sub_title'] = $this->sub_title ? :
(!is_array(@Yii::$app->params['menu'][$main_id][1]) ? '' :
(@Yii::$app->params['menu'][$main_id][1][$sub_id][0] ? : ''));
return parent::render($view, $params);
}
... ...
... ... @@ -10,6 +10,8 @@ use backend\widgets\Filter;
use backend\widgets\YHGImage\Common\Images as CommonImages;
use app\models\Video;
use yii\helpers\ArrayHelper;
use app\models\Share;
use common\config\Params;
/**
* Live controller
... ... @@ -37,7 +39,7 @@ class LiveController extends BaseController
$list = $model
->with(['master','roomNums'])
->offset($pagination->offset)->limit($pagination->limit)
->orderBy(['create_time'=>SORT_DESC,'update_time'=>SORT_DESC])
->orderBy( $this->_roomOrderBy(isset($condition['living']) ? $condition['living']:-1) ) //根据直播状态返回不同排序
->all();
//var_dump($list);
... ... @@ -124,13 +126,12 @@ class LiveController extends BaseController
$model = Video::findOne($posts['id']);
if(!empty($model))
{
$model->pic = $posts['pic'];
$model->url = $posts['url'];
$model->title = $posts['title'];
if($model->save())
if($model->edit($posts))
{
Yii::$app->session->setFlash('success', '编辑成功。');
}
}else{
Yii::$app->session->setFlash('error', '编辑失败。');
}
}
else
{
... ... @@ -140,20 +141,56 @@ class LiveController extends BaseController
}
else
{
$id = Yii::$app->request->get('id', 0);
$video = Video::findOne(['id'=> $id]);
if(empty($video))
{
Yii::$app->session->setFlash('error', '找不到该视频');
return $this->redirect($this->_refer);
}
//图片上传组件
$uploader = \backend\widgets\UploadImage::self()->logo('pic', $video->pic);
return $this->render('videoedit', ['video' => $video, 'uploader' => $uploader]);
$id = Yii::$app->request->get('id', 0);
$video = Video::findOne(['id' => $id]);
if (empty($video)) {
Yii::$app->session->setFlash('error', '找不到该视频');
return $this->redirect($this->_refer);
}
$videoShare = [];
if ($shareModel = Share::findOne(['obj_id' => $video->id, 'type' => Params::VIDEO_SHARE_TYPE])) {
$videoShare = $shareModel->toArray();
}
//图片上传组件
$uploader = \backend\widgets\UploadImage::self()->single('pic', $video->pic);
$sharePicUploader = \backend\widgets\UploadImage::self()->single('share_pic', $videoShare['pic']);
return $this->render('videoedit', [
'video' => $video,
'uploader' => $uploader,
'sharePicUploader' => $sharePicUploader,
'videoShare' => $videoShare
]);
}
}
/**
* 删除视频记录
* @author yaoxiaofeng
*/
public function actionVideodel()
{
if (!$id = Yii::$app->getRequest()->getQueryParam('id')) {
return $this->redirect($this->_refer);
}
do {
$model = Video::findOne($id);
if (empty($model)) {
Yii::$app->session->setFlash('error', '找不到该视频信息。');
break;
}
if ($model->delete()) {
Yii::$app->session->setFlash('success', '删除成功。');
} else {
Yii::$app->session->setFlash('error', '删除失败。');
}
break;
} while (false);
return $this->redirect($this->_refer);
}
/**
* 视频状态设置
* @return
*/
... ... @@ -308,11 +345,13 @@ class LiveController extends BaseController
//图片上传组件
$picUploader = \backend\widgets\UploadImage::self()->single('pic',$model->pic);
$backgroundUploader = \backend\widgets\UploadImage::self()->single('background_pic',$model->background_pic);
$sharePicUploader = \backend\widgets\UploadImage::self()->single('share_pic',$post['share_pic'] ? :'');
return $this->render('roomedit',[
'model'=> $model,
'picUploader'=>$picUploader,
'backgroundUploader'=>$backgroundUploader,
'sharePicUploader'=>$sharePicUploader,
'masters'=>$masters,
]);
}
... ... @@ -352,12 +391,24 @@ class LiveController extends BaseController
//图片上传组件
$picUploader = \backend\widgets\UploadImage::self()->single('pic',$model->pic);
$backgroundUploader = \backend\widgets\UploadImage::self()->single('background_pic',$model->background_pic);
if($share = Share::getShareByRoomId($model->room_id)){
$share_pic = $share->pic;
}else{
$share_pic = '';
}
$sharePicUploader = \backend\widgets\UploadImage::self()->single('share_pic',$share_pic);
$roomShare = [];
if($shareModel = Share::findOne(['obj_id'=>$model->room_id,'type'=>Params::LIVE_SHARE_TYPE])) {
$roomShare = $shareModel->toArray();
}
return $this->render('roomedit',[
'model'=> $model,
'picUploader'=>$picUploader,
'backgroundUploader'=>$backgroundUploader,
'sharePicUploader'=>$sharePicUploader,
'masters'=>$masters,
'roomShare' => $roomShare
]);
}
... ... @@ -409,6 +460,10 @@ class LiveController extends BaseController
*/
public function actionCouponedit()
{
$this->main_id = 'live';
$this->sub_id = 'room';
$this->sub_title = '优惠码';
if ($posts = Yii::$app->request->Post()) {
//保存
if (!$model = RoomCoupon::findOne(['room_id' => $posts['room_id']])) {
... ... @@ -439,4 +494,26 @@ class LiveController extends BaseController
$replace = "<br/>";
return str_replace($search,$replace,trim($text));
}
/**
* 获取房间列表排序
* @param int $living_stat 直播状态
* @return array
*/
private function _roomOrderBy($living_stat)
{
$order = [];
switch ($living_stat) {
case Params::LIVE_NOT_START :
$order = ['unstart_sort'=>SORT_DESC,'starting_time'=>SORT_ASC];
break;
case Params::LIVING :
$order = ['living_sort'=>SORT_DESC,'room_id'=>SORT_DESC];
break;
default :
$order = ['create_time'=>SORT_DESC,'update_time'=>SORT_DESC];
break;
}
return $order;
}
}
... ...
<?php
namespace backend\controllers;
use Yii;
use backend\components\Pagination;
use yii\helpers\ArrayHelper;
use common\lib\YohoApi\Client as YohoApiClient;
use app\models\RedbagType;
/**
* 红包
*/
class RedbagController extends BaseController
{
public function init()
{
parent::init();
$this->main_id = 'live';
$this->sub_id = 'room';
$this->sub_title = '红包管理';
}
/**
* 房间红包列表
* @return type
*/
public function actionList()
{
if (!$room_id = Yii::$app->getRequest()->getQueryParam('id')){
return $this->redirect($this->_refer);
}
$model = \app\models\RoomRedbag::find()->where(['room_id'=>$room_id]);
$count = clone $model;
$pagination = new Pagination(['totalCount' =>$count->count()]);
$list = $model
->with(['type'])
->offset($pagination->offset)->limit($pagination->limit)
->orderBy(['create_time'=>SORT_DESC])
->indexBy('coupon_id')
->all();
/**
* 获取有货商品信息
*/
$couponId = [];
$couponId_by_type = [];
foreach ($list as $model){
$couponId[] = $model->coupon_id;
//按类型分组,供页面发红包随机用
if (empty($couponId_by_type[$model->type_id])){
$couponId_by_type[$model->type_id] = [];
}
if (!in_array($model->coupon_id,$couponId_by_type[$model->type_id])){
$couponId_by_type[$model->type_id][] = $model->coupon_id;
}
}
if ($couponId){
$ret = YohoApiClient::self()->couponList($couponId);
//var_dump(YohoApiClient::self()->h5ProductBatch([51188407,51188408,51188414,51188421,51188468]));
//var_dump(YohoApiClient::getRequestUrl());
if (!empty($ret)){
foreach ($ret as $row){
if (!empty($list[$row['id']])){
$list[$row['id']]->setAttributes([
'coupon_name' => $row['couponName'],
'stock' => $row['lastNum'],
'effect_time' => $row['startTime'],
'invalid_time' => $row['endTime'],
]);
}
}
//页面随机红包池过滤掉无库存的
foreach ($couponId_by_type as $k=>$type_group){
$couponId_by_type[$k] = array_filter($type_group,function($value) use ($list){
return !empty($list[$value]) && $list[$value]->stock;
});
}
}
}
$types = RedbagType::getId2name();
$types = [''=>'选择红包类型']+$types;
return $this->render('list',[
'room'=> \app\models\Room::findOne(['room_id'=>$room_id]),
'pagination'=>$pagination,
'list'=>$list,
'types'=>$types,
'couponId_by_type'=>$couponId_by_type,
]);
}
/**
* 添加红包
* @return type
*/
public function actionAdd()
{
if (!$room_id = Yii::$app->getRequest()->getQueryParam('id')){
return $this->redirect($this->_refer);
}
$model = new \app\models\RoomRedbag;
if (Yii::$app->getRequest()->isPost){
$post = Yii::$app->getRequest()->post();
$model->room_id = $room_id;
if ($model->load($post,'') && $model->save()){
Yii::$app->session->setFlash('success', '创建成功。');
return $this->redirect($this->_refer);
}else{
Yii::$app->session->setFlash('warning', current($model->getFirstErrors()));
$model->setAttributes($post);
}
}
$types = RedbagType::getId2name();
$types = [''=>'请选择']+$types;
return $this->render('edit',[
'model'=>$model,
'types'=>$types,
]);
}
/**
* 编辑红包
* @return type
*/
public function actionEdit()
{
if (!$id = Yii::$app->getRequest()->getQueryParam('id')){
return $this->redirect($this->_refer);
}
if (!$model = \app\models\RoomRedbag::findOne($id)){
Yii::$app->session->setFlash('error', '找不到该红包');
return $this->redirect($this->_refer);
}
if (Yii::$app->getRequest()->isPost){
$post = Yii::$app->getRequest()->post();
if ($model->load($post,'') && $model->save()){
Yii::$app->session->setFlash('success', '编辑成功。');
return $this->redirect($this->_refer);
}else{
Yii::$app->session->setFlash('warning', current($model->getFirstErrors()));
}
}
$types = RedbagType::getId2name();
$types = [''=>'请选择']+$types;
return $this->render('edit',[
'model'=>$model,
'types'=>$types,
]);
}
/**
* 红包操作
* @return type
*/
public function actionOperate()
{
if (!$id = Yii::$app->getRequest()->getQueryParam('id')){
return $this->redirect($this->_refer);
}
if (!$type = Yii::$app->getRequest()->getQueryParam('type')){
return $this->redirect($this->_refer);
}
if (!$model = \app\models\RoomRedbag::findOne($id)){
Yii::$app->session->setFlash('error', '找不到该红包');
return $this->redirect($this->_refer);
}
switch ($type){
case 'del'://删除
$r = $model->delete();
break;
default:
break;
}
if (!empty($r)){
Yii::$app->session->setFlash('success', '操作成功');
}else{
Yii::$app->session->setFlash('error', '操作失败');
}
return $this->redirect($this->_refer);
}
/**
* 红包类型
* @return type
*/
public function actionType()
{
$this->sub_title = '红包类型';
$this->sub_id = 'type';
$model = RedbagType::find();
$count = clone $model;
$pagination = new Pagination([
'totalCount' => $count->count(),
]);
$list = $model
->orderBy(['create_time'=>SORT_DESC,'update_time'=>SORT_DESC])
->offset($pagination->offset)->limit($pagination->limit)
->all();
return $this->render('type',[
'pagination'=>$pagination,
'list'=>$list,
]);
}
/**
* 添加红包类型
* @return type
*/
public function actionAddtype()
{
$this->sub_title = '红包类型';
$this->sub_id = 'type';
$model = new RedbagType();
if ($post = Yii::$app->request->post()) {
if ($model->load($post,'') && $model->save()){
Yii::$app->session->setFlash('success', '创建成功。');
return $this->redirect($this->_refer);
}else{
Yii::$app->session->setFlash('warning', current($model->getFirstErrors()));
$model->setAttributes($post);
}
}
return $this->render('add_type',[
'model'=>$model,
]);
}
/**
* 编辑红包类型
* @return type
*/
public function actionEdittype()
{
$this->sub_title = '红包类型';
$this->sub_id = 'type';
if (!$id = Yii::$app->getRequest()->getQueryParam('id')){
return $this->redirect($this->_refer);
}
if (!$model = RedbagType::findOne($id)){
Yii::$app->session->setFlash('error', '找不到该类型');
return $this->redirect($this->_refer);
}
if (Yii::$app->getRequest()->isPost){
$post = Yii::$app->getRequest()->post();
if ($model->load($post,'') && $model->save()){
Yii::$app->session->setFlash('success', '编辑成功。');
return $this->redirect($this->_refer);
}else{
Yii::$app->session->setFlash('warning', current($model->getFirstErrors()));
}
}
return $this->render('add_type',[
'model'=>$model,
]);
}
/**
* 删除红包类型
* @return type
*/
public function actionDeltype(){
if (!$id = Yii::$app->getRequest()->getQueryParam('id')){
return $this->redirect($this->_refer);
}
if (!$model = RedbagType::findOne($id)){
Yii::$app->session->setFlash('error', '找不到该类型');
return $this->redirect($this->_refer);
}
if($model->delete()){
Yii::$app->session->setFlash('success', '删除成功');
}else{
Yii::$app->session->setFlash('error', '删除失败。');
}
return $this->redirect($this->_refer);
}
}
... ...
... ... @@ -38,6 +38,7 @@ class Admin extends \yii\db\ActiveRecord implements \yii\web\IdentityInterface
public function rules()
{
return [
[['username','email'], 'trim'],
[['username', 'auth_key', 'password_hash', 'email'], 'required'],
[['role', 'status', 'create_time', 'update_time'], 'integer'],
[['username', 'password_hash', 'password_reset_token', 'email'], 'string', 'max' => 255],
... ... @@ -207,4 +208,16 @@ class Admin extends \yii\db\ActiveRecord implements \yii\web\IdentityInterface
{
$this->password_reset_token = null;
}
/**
* 获取所有权限列表,键值对应数组
*/
static function getRolesIndex()
{
$roles = Yii::$app->authManager->getRoles();
foreach ($roles as $k=>$model){
$roles[$k] = $model->description ? : ucwords($model->name);
}
return $roles;
}
}
... ...
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "{{%redbag_type}}".
*
* @property string $type_id
* @property string $name
* @property integer $create_time
* @property integer $update_time
*/
class RedbagType extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%redbag_type}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['name'], 'required'],
[['create_time', 'update_time'], 'integer'],
[['name'], 'string', 'max' => 100],
[['name'], 'unique'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'type_id' => '类型ID',
'name' => '类型名称',
'create_time' => '创建时间',
'update_time' => '更新时间',
];
}
public function behaviors() {
return [
[
'class' => \yii\behaviors\TimestampBehavior::className(),
'createdAtAttribute' => 'create_time',
'updatedAtAttribute' => 'update_time',
]
];
}
/**
* 返回所有主播[id=>id.' '.name,...]的列表数组
* @return string
*/
public static function getId2name(){
$list = self::find()->all();
$ret = [];
foreach ($list as $model){
$ret[$model->type_id] = $model->name;
}
return $ret;
}
}
... ...
... ... @@ -5,6 +5,8 @@ namespace app\models;
use Yii;
use common\lib\QcloudApi\Client as QcloudApiClient;
use common\models\RoomNums;
use app\models\Share;
use common\config\Params;
/**
* This is the model class for table "{{%room}}".
... ... @@ -39,7 +41,7 @@ class Room extends \yii\db\ActiveRecord
public function rules()
{
return [
[['room_id', 'master_id', 'starting_time', 'best', 'vest', 'is_addup', 'living', 'status', 'create_time', 'update_time'], 'integer'],
[['room_id', 'master_id', 'starting_time', 'best', 'vest', 'is_addup', 'living', 'status', 'unstart_sort', 'living_sort', 'create_time', 'update_time'], 'integer'],
[['title', 'watermark'], 'string', 'max' => 100],
[['app', 'secret'], 'string', 'max' => 50],
[['pic', 'background_pic'], 'string', 'max' => 255],
... ... @@ -69,6 +71,8 @@ class Room extends \yii\db\ActiveRecord
'vest' => '马甲状态',
'living' => '直播状态',
'status' => '房间状态',
'unstart_sort' => '未开始排序',
'living_sort' => '直播中排序',
'create_time' => '创建时间',
'update_time' => '更新时间',
];
... ... @@ -197,6 +201,19 @@ class Room extends \yii\db\ActiveRecord
throw new \Exception(current($RoomQchannel->getFirstErrors()));
}
//插入分享内容
$RoomShare = new Share;
$RoomShare->setAttributes([
'obj_id'=>$this->room_id,
'type'=>Params::LIVE_SHARE_TYPE,
'pic'=>$data['share_pic'],
'title'=>$data['share_title'],
'content'=>$data['share_content'],
]);
if (!$RoomShare->save()){
throw new \Exception(current($RoomShare->getFirstErrors()));
}
$transaction->commit();
return $this->room_id;
}catch (\Exception $e) {
... ... @@ -220,10 +237,10 @@ class Room extends \yii\db\ActiveRecord
}
if (!empty($data['starting_time'])){
$data['starting_time'] = (int)strtotime($data['starting_time']);
if ($data['starting_time'] <= time()){
if (($this->living != Params::LIVING) && $data['starting_time'] <= time()){
throw new \Exception('预告开始时间不能早于当前时间');
}
}
}
@sort($data['app']);
$data['app'] = implode(',', $data['app']);
... ... @@ -244,6 +261,22 @@ class Room extends \yii\db\ActiveRecord
throw new \Exception(current($this->getFirstErrors()));
}
//编辑分享内容
if (!$RoomShare = Share::findOne(['type' => Params::LIVE_SHARE_TYPE, 'obj_id' => $this->room_id])) {
//编辑以前的房间时,没有相应的分享记录,那么这时候要重新创建一个对象来做插入
$RoomShare = new Share();
}
$RoomShare->setAttributes([
'obj_id' => $this->room_id,
'type' => Params::LIVE_SHARE_TYPE,
'pic' => $data['share_pic'],
'title' => $data['share_title'],
'content' => $data['share_content'],
]);
if (!$RoomShare->save()) {
throw new \Exception(current($RoomShare->getFirstErrors()));
}
$transaction->commit();
return true;
}catch (\Exception $e) {
... ... @@ -267,12 +300,18 @@ class Room extends \yii\db\ActiveRecord
if (!$model->delete()){
throw new \Exception(current($model->getFirstErrors()));
}
//删除分享
$delShare = (new Share())->delLivingShare($model->room_id);
if (!$delShare) {
throw new \Exception("删除分享失败");
}
if ($model->roomQchannel){
if (!$model->roomQchannel->delete()){
throw new \Exception(current($model->roomQchannel->getFirstErrors()));
}
//fixme 很有可能因为腾讯云后台被删,导致找不到频道,本地服务器记录一直删不掉
if (!QcloudApiClient::self()->DeleteLVBChannel([$model->roomQchannel->channel_id])){
throw new \Exception(QcloudApiClient::self()->error());
}
... ...
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "{{%room_redbag}}".
*
* @property string $id
* @property string $room_id
* @property string $coupon_id
* @property integer $type
* @property string $coupon_name
* @property integer $stock
* @property integer $effect_time
* @property integer $invalid_time
* @property integer $create_time
* @property integer $update_time
*/
class RoomRedbag extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%room_redbag}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['room_id', 'coupon_id', 'type_id', 'stock', 'effect_time', 'invalid_time', 'create_time', 'update_time'], 'integer'],
[['coupon_name'], 'string', 'max' => 100],
[['room_id', 'coupon_id'], 'unique', 'targetAttribute' => ['room_id', 'coupon_id'], 'comboNotUnique' => '红包ID已存在'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'room_id' => '房间号',
'coupon_id' => '优惠券ID',
'type_id' => '红包类型',
'coupon_name' => '优惠券名称',
'stock' => '优惠券剩余库存',
'effect_time' => '优惠券生效时间',
'invalid_time' => '优惠券失效时间',
'create_time' => '创建时间',
'update_time' => '更新时间',
];
}
public function behaviors() {
return [
[
'class' => \yii\behaviors\TimestampBehavior::className(),
'createdAtAttribute' => 'create_time',
'updatedAtAttribute' => 'update_time',
]
];
}
/**
* 关联表-类型
* @return type
*/
public function getType()
{
return $this->hasOne(RedbagType::className(), ['type_id'=>'type_id']);
}
}
... ...
<?php
namespace app\models;
use Yii;
use common\config\Params;
/**
* This is the model class for table "{{%share}}".
*
* @property integer $id
* @property integer $obj_id
* @property integer $type
* @property string $title
* @property string $content
* @property integer $create_time
* @property integer $update_time
*/
class Share extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%share}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['obj_id', 'type', 'create_time', 'update_time'], 'integer'],
[['content'], 'string'],
[['pic'], 'string', 'max' => 200],
[['title'], 'string', 'max' => 100],
[['obj_id', 'type'], 'unique', 'targetAttribute' => ['obj_id', 'type'], 'message' => 'The combination of Obj ID and Type has already been taken.'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'obj_id' => 'Obj ID',
'type' => 'Type',
'pic' => '分享头图',
'title' => '分享标题',
'content' => '分享内容',
'create_time' => 'Create Time',
'update_time' => 'Update Time',
];
}
public function behaviors()
{
return [
[
'class' => \yii\behaviors\TimestampBehavior::className(),
'createdAtAttribute' => 'create_time',
'updatedAtAttribute' => 'update_time',
]
];
}
/**
* 删除分享
* @param $obj_id
* @param $type
* @return bool
* @throws \Exception
*/
private function del($obj_id,$type)
{
try{
$rowCount = Yii::$app->db->createCommand()->delete(self::tableName(), ['obj_id'=>$obj_id,'type'=>$type])->execute();
return ($rowCount>=0) ? true:false;
}catch (\Exception $e){
throw new \Exception($e->getMessage());
}
}
public function delLivingShare($room_id)
{
return $this->del($room_id,Params::LIVE_SHARE_TYPE);
}
public function delVideoShare($video_id)
{
return $this->del($video_id,Params::VIDEO_SHARE_TYPE);
}
public static function getShareByRoomId($room_id)
{
return self::findOne(['obj_id'=>$room_id,'type'=>Params::LIVE_SHARE_TYPE]);
}
}
... ...
... ... @@ -3,6 +3,7 @@
namespace app\models;
use Yii;
use common\config\Params;
/**
* This is the model class for table "{{%video}}".
... ... @@ -38,7 +39,7 @@ class Video extends \yii\db\ActiveRecord
public function rules()
{
return [
[['task_id', 'live_start_time', 'live_end_time', 'master_id', 'room_id', 'status', 'like_num', 'audience_num', 'replay_num', 'create_time', 'update_time'], 'integer'],
[['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'],
[['title', 'live_title'], 'string', 'max' => 100],
[['pic', 'url'], 'string', 'max' => 255],
[['app'], 'string', 'max' => 50],
... ... @@ -66,6 +67,7 @@ class Video extends \yii\db\ActiveRecord
'like_num' => 'Like Num',
'audience_num' => 'Audience Num',
'replay_num' => 'Replay Num',
'sort' => 'Sort',
'create_time' => 'Create Time',
'update_time' => 'Update Time',
];
... ... @@ -107,7 +109,50 @@ class Video extends \yii\db\ActiveRecord
{
return $this->hasOne(Room::className(), ['room_id'=>'room_id']);
}
/**
* 编辑
* @param array $data
* @author yaoxiaofeng
* @return bool
*/
public function edit(array $data)
{
$transaction = $this->getDb()->beginTransaction();
try {
$this->setAttributes([
'pic' => $data['pic'],
'url' => $data['url'],
'title' => $data['title'],
'sort' => $data['sort']
]);
if (!$this->save()){
throw new \Exception(current($this->getFirstErrors()));
}
//编辑分享内容
if (!$share = Share::findOne(['type' => Params::VIDEO_SHARE_TYPE, 'obj_id' => $this->id])) {
//编辑以前的视频时,没有相应的分享记录,那么这时候要重新创建一个对象来做插入
$share = new Share();
}
$share->setAttributes([
'obj_id' => $this->id,
'type' => Params::VIDEO_SHARE_TYPE,
'pic' => $data['share_pic'],
'title' => $data['share_title'],
'content' => $data['share_content'],
]);
if (!$share->save()) {
throw new \Exception(current($share->getFirstErrors()));
}
$transaction->commit();
return true;
} catch (\Exception $e) {
$transaction->rollBack();
Yii::$app->session->setFlash('warning', $e->getMessage());
return false;
}
}
/**
* 根据条件
* @param array $condition
... ... @@ -136,7 +181,7 @@ class Video extends \yii\db\ActiveRecord
$model->andWhere($sql);
}
}
$model->orderBy(['v.create_time' => SORT_DESC]);
$model->orderBy(['v.sort'=>SORT_DESC,'v.create_time' => SORT_DESC]);
return $model;
}
}
... ...
<?php
use yii\web\View;
use yii\helpers\Html;
use backend\widgets\YHGImage\Common\Images as CommonImages;
$this->title = $this->params['main_title'].'-'.$this->params['sub_title'];
?>
<?php
$this->registerCssFile('/css/select2.css',array('postion'=>View::POS_END));
$this->registerJsFile('/js/select2.min.js',array('postion'=>View::POS_END));
?>
<script type="text/javascript">
<?php $this->beginBlock('javascript');?>
jQuery(document).ready(function() {
// Select2
jQuery(".select-basic").select2();
});
<?php
$this->endBlock();
$this->registerJs($this->blocks['javascript'],View::POS_END)
?>
</script>
<div class="col-md-6">
<form id="form" method="POST" action="">
<div class="panel panel-default">
<div class="panel-body">
<div class="row">
<div class="form-group">
<label class="col-sm-3 control-label">用户名: <span class="asterisk">*</span></label>
<div class="col-sm-5">
<input type="text" name="username" class="form-control" required="required" value="<?=$model->username?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">邮箱: </label>
<div class="col-sm-5">
<input type="text" name="email" class="form-control" required="required" value="<?=$model->email?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">修改密码: <span class="asterisk">*</span></label>
<div class="col-sm-5">
<input type="password" name="password" class="form-control">
</div>
</div>
</div><!-- row -->
</div><!-- panel-body -->
<div class="panel-footer">
<div class="row">
<div class="col-sm-9 col-sm-offset-3">
<button class="btn btn-primary mr5" id="upload_button">保存</button>
<a href="<?=$_refer?>" class="btn btn-dark">取消</a>
</div>
</div>
</div><!-- panel-footer -->
</div><!-- panel -->
</form>
</div>
... ...
<?php
use yii\web\View;
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
$this->title = $this->params['main_title'] . '-' . $this->params['sub_title'];
?>
<div class="col-md-12">
<form class="form-bordered" method="POST" action="">
<div class="panel panel-default">
<div class="panel-heading">
<h5 class="panel-title"><?=$role->name?></h5>
<p><?=$role->description?></p>
</div><!-- panel-heading -->
<div class="panel-body">
<ul class="row icon-list">
<?php foreach ($allPermissions as $permissionName=>$permission):?>
<li class="col-xs-6 col-sm-4 col-md-3">
<div class="ckbox ckbox-default">
<?php echo Html::checkbox('permissions[]', array_key_exists($permissionName, $rolePermissions), ['id'=>$permissionName,'value'=>$permissionName])?>
<label for="<?=$permissionName?>"><?=$permission->description?></label>
</div>
</li>
<?php endforeach;?>
</ul>
</div>
<div class="panel-footer">
<div class="row">
<div class="col-sm-9 col-sm-offset-3">
<button class="btn btn-primary mr5" id="upload_button">保存</button>
<a href="<?=$_refer?>" class="btn btn-dark">取消</a>
</div>
</div>
</div><!-- panel-footer -->
</div><!-- panel -->
</form>
</div>
\ No newline at end of file
... ...
<?php
use yii\web\View;
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
$this->title = $this->params['main_title'] . '-' . $this->params['sub_title'];
?>
<div class="col-md-12">
<form class="form-bordered" method="POST" action="">
<div class="panel panel-default">
<div class="panel-heading">
<h5 class="panel-title"><?=$user->username?></h5>
<p><?=$user->email?></p>
</div><!-- panel-heading -->
<div class="panel-body">
<ul class="row icon-list">
<?php foreach ($allRoles as $roleName=>$role):?>
<li class="col-xs-6 col-sm-4 col-md-3">
<div class="rdio rdio-default">
<?php echo Html::radio('roleName', array_key_exists($roleName, $userRoles), ['id'=>$roleName,'value'=>$roleName])?>
<label for="<?=$roleName?>"><?=$role->description?></label>
</div>
</li>
<?php endforeach;?>
</ul>
</div>
<div class="panel-footer">
<div class="row">
<div class="col-sm-9 col-sm-offset-3">
<button class="btn btn-primary mr5" id="upload_button">保存</button>
<a href="<?=$_refer?>" class="btn btn-dark">取消</a>
</div>
</div>
</div><!-- panel-footer -->
</div><!-- panel -->
</form>
</div>
\ No newline at end of file
... ...
<?php
use yii\web\View;
use yii\helpers\Html;
$this->title = $this->params['main_title'].'-'.$this->params['sub_title'];
?>
<?php
$this->registerCssFile('/css/select2.css',array('postion'=>View::POS_END));
$this->registerJsFile('/js/select2.min.js',array('postion'=>View::POS_END));
?>
<script type="text/javascript">
<?php $this->beginBlock('javascript');?>
jQuery(document).ready(function() {
// Select2
jQuery(".select-basic").select2();
});
<?php
$this->endBlock();
$this->registerJs($this->blocks['javascript'],View::POS_END)
?>
</script>
<div class="col-md-6">
<form id="form" method="POST" action="">
<div class="panel panel-default">
<div class="panel-body">
<div class="row">
<div class="form-group">
<div class="col-sm-4">
<input type="text" name="username" class="form-control" required="required" placeholder="用户名">
</div>
<div class="col-sm-4">
<input type="text" name="email" class="form-control" required="required" placeholder="邮箱">
</div>
<div class="col-sm-4">
<input type="password" name="password" class="form-control" required="required" placeholder="密码">
</div>
</div>
<div class="form-group">
<div class="col-sm-3">
<button class="btn btn-primary mr5" id="upload_button" onclick="return confirm('确定加入?')">加入</button>
</div>
</div>
</div><!-- row -->
</div><!-- panel-body -->
</div><!-- panel -->
</form>
</div>
<div class="row">
<div class="col-md-12">
<div class="table-responsive">
<table class="table mb30">
<thead>
<tr style="white-space:nowrap">
<th><input type="checkbox" onclick="checkall(this)">选择</th>
<th>用户名</th>
<th>邮箱</th>
<th>状态</th>
<th>加入时间</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<?php foreach ($list as $model):?>
<tr data-stock="1" data-source="1" data-status="2" data-id="5011880">
<td><input type="checkbox" value="<?=$model->id?>" name="room[]"></td>
<td><?=$model->username?></td>
<td><?=$model->email?></td>
<td><?=$model->status ? '启用' : '禁用'?></td>
<td style="white-space:nowrap"><?=date('Y-m-d H:i:s',$model->create_time)?></td>
<td>
<?php if (!in_array($model->username,['admin','super_admin'])):?>
<a href="/admin/adminedit/<?=$model->id?>" class="btn btn-default btn-white">编辑</a>
<a href="/admin/assignrole/<?=$model->id?>" class="btn btn-default btn-white">用户组配置</a>
<?php if ($model->status == 0)://禁用状态?>
<a onclick="return confirm('启用用户?')" href="/admin/operate/<?=$model->id?>?target=user&type=enable" class="btn btn-success btn-metro">启用</a>
<?php else:?>
<a onclick="return confirm('禁用用户?')" href="/admin/operate/<?=$model->id?>?target=user&type=disable" class="btn btn-danger btn-metro">禁用</a>
<?php endif;?>
<a onclick="return confirm('删除用户?')" href="/admin/operate/<?=$model->id?>?target=user&type=del" class="btn btn-danger btn-metro">删除</a>
<?php endif;?>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
</div>
<!-- table-responsive -->
</div>
<!-- col-md-12 -->
</div>
\ No newline at end of file
... ...
<?php
use yii\web\View;
use yii\helpers\Html;
$this->title = $this->params['main_title'].'-'.$this->params['sub_title'];
?>
<div class="col-md-6">
<form id="form" method="POST" action="">
<div class="panel panel-default">
<div class="panel-body">
<div class="row">
<div class="form-group">
<div class="col-sm-4">
<input type="text" name="name" class="form-control" required="required" placeholder="权限标签">
</div>
<div class="col-sm-5">
<input type="text" name="description" class="form-control" required="required" placeholder="描述">
</div>
</div>
<div class="form-group">
<div class="col-sm-3">
<button class="btn btn-primary mr5" id="upload_button">添加</button>
</div>
</div>
</div><!-- row -->
</div><!-- panel-body -->
</div><!-- panel -->
</form>
</div>
<div class="row">
<div class="col-md-12">
<div class="table-responsive">
<table class="table mb30">
<thead>
<tr style="white-space:nowrap">
<th><input type="checkbox" onclick="checkall(this)">选择</th>
<th>权限标签</th>
<th>描述</th>
<th>添加时间</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<?php foreach ($list as $model):?>
<tr data-stock="1" data-source="1" data-status="2" data-id="5011880">
<td><input type="checkbox" value="<?=$model->name?>" name="room[]"></td>
<td><?=$model->name?></td>
<td><?=$model->description?></td>
<td style="white-space:nowrap"><?=date('Y-m-d H:i:s',$model->createdAt)?></td>
<td>
<?php if ($model->name != 'index/index'):?>
<a href="/admin/permissionedit/?name=<?=$model->name?>" class="btn btn-default btn-white">编辑</a>
<a onclick="return confirm('删除用户组?')" href="/admin/operate/?target=permission&type=del&name=<?=$model->name?>" class="btn btn-danger btn-metro">删除</a>
<?php endif;?>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
</div>
<!-- table-responsive -->
</div>
<!-- col-md-12 -->
</div>
\ No newline at end of file
... ...
<?php
use yii\web\View;
use yii\helpers\Html;
use backend\widgets\YHGImage\Common\Images as CommonImages;
$this->title = $this->params['main_title'].'-'.$this->params['sub_title'];
?>
<div class="col-md-6">
<form id="form" method="POST" action="">
<div class="panel panel-default">
<div class="panel-body">
<div class="row">
<div class="form-group">
<label class="col-sm-3 control-label">权限标签: <span class="asterisk">*</span></label>
<div class="col-sm-5">
<input type="text" name="name" class="form-control" required="required" value="<?=$model->name?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">描述: </label>
<div class="col-sm-5">
<input type="text" name="description" class="form-control" required="required" value="<?=$model->description?>">
</div>
</div>
</div><!-- row -->
</div><!-- panel-body -->
<div class="panel-footer">
<div class="row">
<div class="col-sm-9 col-sm-offset-3">
<button class="btn btn-primary mr5" id="upload_button">保存</button>
<a href="<?=$_refer?>" class="btn btn-dark">取消</a>
</div>
</div>
</div><!-- panel-footer -->
</div><!-- panel -->
</form>
</div>
... ...
<?php
use yii\web\View;
use yii\helpers\Html;
$this->title = $this->params['main_title'].'-'.$this->params['sub_title'];
?>
<div class="col-md-6">
<form id="form" method="POST" action="">
<div class="panel panel-default">
<div class="panel-body">
<div class="row">
<div class="form-group">
<div class="col-sm-4">
<input type="text" name="name" class="form-control" required="required" placeholder="用户组">
</div>
<div class="col-sm-5">
<input type="text" name="description" class="form-control" required="required" placeholder="描述">
</div>
</div>
<div class="form-group">
<div class="col-sm-3">
<button class="btn btn-primary mr5" id="upload_button">添加</button>
</div>
</div>
</div><!-- row -->
</div><!-- panel-body -->
</div><!-- panel -->
</form>
</div>
<div class="row">
<div class="col-md-12">
<div class="table-responsive">
<table class="table mb30">
<thead>
<tr style="white-space:nowrap">
<th><input type="checkbox" onclick="checkall(this)">选择</th>
<th>用户组</th>
<th>描述</th>
<th>添加时间</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<?php foreach ($list as $model):?>
<tr data-stock="1" data-source="1" data-status="2" data-id="5011880">
<td><input type="checkbox" value="<?=$model->name?>" name="room[]"></td>
<td><?=$model->name?></td>
<td><?=$model->description?></td>
<td style="white-space:nowrap"><?=date('Y-m-d H:i:s',$model->createdAt)?></td>
<td>
<?php if ($model->name != 'admin'):?>
<a href="/admin/roleedit/?name=<?=$model->name?>" class="btn btn-default btn-white">编辑</a>
<a href="/admin/assignpermission/?name=<?=$model->name?>" class="btn btn-default btn-white">权限配置</a>
<a onclick="return confirm('删除用户组?')" href="/admin/operate/?target=role&type=del&name=<?=$model->name?>" class="btn btn-danger btn-metro">删除</a>
<?php endif;?>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
</div>
<!-- table-responsive -->
</div>
<!-- col-md-12 -->
</div>
\ No newline at end of file
... ...
<?php
use yii\web\View;
use yii\helpers\Html;
use backend\widgets\YHGImage\Common\Images as CommonImages;
$this->title = $this->params['main_title'].'-'.$this->params['sub_title'];
?>
<div class="col-md-6">
<form id="form" method="POST" action="">
<div class="panel panel-default">
<div class="panel-body">
<div class="row">
<div class="form-group">
<label class="col-sm-3 control-label">用户组: <span class="asterisk">*</span></label>
<div class="col-sm-5">
<input type="text" name="name" class="form-control" required="required" value="<?=$model->name?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">描述: </label>
<div class="col-sm-5">
<input type="text" name="description" class="form-control" required="required" value="<?=$model->description?>">
</div>
</div>
</div><!-- row -->
</div><!-- panel-body -->
<div class="panel-footer">
<div class="row">
<div class="col-sm-9 col-sm-offset-3">
<button class="btn btn-primary mr5" id="upload_button">保存</button>
<a href="<?=$_refer?>" class="btn btn-dark">取消</a>
</div>
</div>
</div><!-- panel-footer -->
</div><!-- panel -->
</form>
</div>
... ...
... ... @@ -8,6 +8,7 @@ use backend\assets\TemplateAsset;
use backend\assets\Ie9Asset;
use yii\web\View;
use backend\widgets\Alert;
use backend\widgets\LeftMenu;
TemplateAsset::register($this);
Ie9Asset::register($this);
... ... @@ -32,7 +33,33 @@ Ie9Asset::register($this);
<section>
<div class="mainwrapper">
<?php echo $this->render('leftmenu');?>
<div class="leftpanel">
<div class="media profile-left">
<a class="pull-left profile-thumb" href="profile.html">
<img class="img-circle" src="/images/photos/profile.png" alt="">
</a>
<div class="media-body">
<?php if (Yii::$app->user->isGuest):?>
<h4 class="media-heading">Guest</h4>
<small class="text-muted">游客</small>
<?php else:?>
<h4 class="media-heading"><?=Yii::$app->user->getIdentity()->username?></h4>
<?php if ($userRoles = Yii::$app->authManager->getRolesByUser(Yii::$app->user->getId())):?>
<small class="text-muted"><?=current($userRoles)->description?></small>
<?php endif;?>
<?php endif;?>
</div>
</div><!-- media -->
<h5 class="leftpanel-title">Navigation</h5>
<ul class="nav nav-pills nav-stacked">
<?php echo LeftMenu::widget() ?>
</ul>
</div><!-- leftpanel -->
<div class="mainpanel">
<div class="pageheader">
... ... @@ -56,6 +83,7 @@ Ie9Asset::register($this);
</div><!-- contentpanel -->
</div><!-- mainpanel -->
</div><!-- mainwrapper -->
</section>
... ...
... ... @@ -25,7 +25,7 @@ var port = socket_arr[1];
function callWebsocket(sendCallback,afterSendCallback = function(){},errorSendCallback = function(){}){
if (!window.ws || window.ws.readyState === undefined || window.ws.readyState != 1) {
websocket(wsAddr,port,'/',function(){
consoleLog('连接服务器');
consoleLog('连接服务器'+wsAddr+':'+port);
sendCallback();
},function(evt){
... ...
... ... @@ -84,6 +84,8 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
<th>马甲状态|人数累加</th>
<th>直播状态</th>
<th>在线人数</th>
<th>未开始排序</th>
<th>直播中排序</th>
<th>操作</th>
</tr>
</thead>
... ... @@ -110,30 +112,36 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
真实:<?=@$model->roomNums->online_num ? :0?>,
马甲:<?=@$model->roomNums->vest_online_num ? :0?>
</td>
<td><?=$model->unstart_sort?></td>
<td><?=$model->living_sort?></td>
<td>
<span>
<?php if ($model->living == 1)://直播中?>
<button type="button" onclick="stopLiving(<?=$model->room_id?>)" class="btn btn-danger btn-metro">结束直播</button>
<?php else:?>
<a onclick="return confirm('将房间设为直播中状态,确定?')" href="/live/roomoperate/<?=$model->id?>?type=start" class="btn btn-success btn-metro">开始直播</a>
<?php endif;?>
</span>
<a href="/live/roomedit/<?=$model->id?>" class="btn btn-default btn-white">编辑</a>
<a href="/forbidden/index?room_id=<?=$model->room_id?>" class="btn btn-default btn-white">禁言</a>
<a href="/product/list/<?=$model->room_id?>" class="btn btn-default btn-white">商品</a>
<a href="/live/couponedit/<?=$model->room_id?>" class="btn btn-default btn-white">优惠码</a>
<span>
<?php if ($model->status == 0)://关闭状态?>
<a onclick="return confirm('启用直播间?')" href="/live/roomoperate/<?=$model->id?>?type=enable" class="btn btn-success btn-metro">启用直播</a>
<a onclick="return confirm('删除直播间?')" href="/live/roomoperate/<?=$model->id?>?type=del" class="btn btn-danger btn-metro">删除</a>
<?php else:?>
<a onclick="return confirm('禁用直播间?')" href="/live/roomoperate/<?=$model->id?>?type=disable" class="btn btn-danger btn-metro">禁用直播</a>
<?php endif;?>
</span>
<p>
<span>
<?php if ($model->living == 1)://直播中?>
<button type="button" onclick="stopLiving(<?=$model->room_id?>)" class="btn btn-danger btn-metro">结束直播</button>
<?php else:?>
<a onclick="return confirm('将房间设为直播中状态,确定?')" href="/live/roomoperate/<?=$model->id?>?type=start" class="btn btn-success btn-metro">开始直播</a>
<?php endif;?>
</span>
<a href="/live/roomedit/<?=$model->id?>" class="btn btn-default btn-white">编辑</a>
<span>
<?php if ($model->status == 0)://关闭状态?>
<a onclick="return confirm('启用直播间?')" href="/live/roomoperate/<?=$model->id?>?type=enable" class="btn btn-success btn-metro">启用直播</a>
<a onclick="return confirm('删除直播间?')" href="/live/roomoperate/<?=$model->id?>?type=del" class="btn btn-danger btn-metro">删除</a>
<?php else:?>
<a onclick="return confirm('禁用直播间?')" href="/live/roomoperate/<?=$model->id?>?type=disable" class="btn btn-danger btn-metro">禁用直播</a>
<?php endif;?>
</span>
</p>
<p>
<a href="/forbidden/index?room_id=<?=$model->room_id?>" class="btn btn-default btn-white">禁言</a>
<a href="/product/list/<?=$model->room_id?>" class="btn btn-default btn-white">商品</a>
<a href="/live/couponedit/<?=$model->room_id?>" class="btn btn-default btn-white">优惠码</a>
<a href="/redbag/list/<?=$model->room_id?>" class="btn btn-default btn-white">红包</a>
</p>
</td>
</tr>
<?php endforeach;?>
... ...
... ... @@ -46,11 +46,12 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
?>
</script>
<div class="col-md-6">
<form id="form" method="POST" action="">
<div class="panel panel-default">
<div class="panel-body">
<div class="col-md-9">
<form id="form" method="POST" action="">
<div class="panel panel-default">
<div class="panel-body">
<!-- 左侧表单 begin-->
<div class="col-md-6">
<div class="row">
<div class="form-group">
<label class="col-sm-3 control-label">房间号: </label>
... ... @@ -58,27 +59,27 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
<?=$model->room_id ? : '保存后生成'?>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">直播标题: <span class="asterisk">*</span></label>
<div class="col-sm-5">
<div class="col-sm-9">
<input type="text" name="title" class="form-control" required="required" value="<?=$model->title?>">(建议不超过18个汉字)
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">水印文案: </label>
<div class="col-sm-5">
<input type="text" name="watermark" class="form-control" value="<?=$model->watermark?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">主播: <span class="asterisk">*</span></label>
<div class="col-sm-5">
<?php echo Html::dropDownList('master_id', $model->master_id,$masters, ['class' => 'width300 select-basic', 'required'=>"required"]);?>
</div>
</div>
<div class="form-group">
... ... @@ -87,21 +88,21 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
<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) : ''?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">房间密钥: <span class="asterisk">*</span></label>
<div class="col-sm-5">
<input type="text" name="secret" class="form-control" required="required" value="<?=$model->secret?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">是否精选: </label>
<div class="col-sm-2">
<?php echo Html::dropDownList('best', $model->best,Yii::$app->params['config']['best'], ['class' => 'form-control']);?>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">马甲状态: </label>
<div class="col-sm-2">
... ... @@ -118,7 +119,7 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
<?php echo Html::dropDownList('living', $model->living,Yii::$app->params['config']['room_living'], ['class' => 'form-control']);?>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">头图: <span class="asterisk">*</span></label>
<div class="col-sm-9">
... ... @@ -128,7 +129,7 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
<?php endif;?>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">背景图: <span class="asterisk">*</span></label>
<div class="col-sm-9">
... ... @@ -138,7 +139,7 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
<?php endif;?>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">业务线: <span class="asterisk">*</span></label>
<div class="col-sm-5">
... ... @@ -147,18 +148,60 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
<?php endforeach;?>
</div>
</div>
</div><!-- row -->
</div><!-- panel-body -->
<div class="panel-footer">
</div>
<!-- 左侧表单 end-->
<!-- 右侧表单 begin-->
<div class="col-md-6">
<div class="row">
<div class="col-sm-9 col-sm-offset-3">
<button class="btn btn-primary mr5" id="upload_button" onclick="return verify()">保存</button>
<a href="<?=$_refer?>" class="btn btn-dark">取消</a>
<div class="form-group">
<label class="col-sm-3 control-label">未开始排序: </label>
<div class="col-sm-3">
<input type="text" name="unstart_sort" class="form-control" value="<?=$model->unstart_sort?>">
</div>
<label class="col-sm-3 control-label">直播中排序: </label>
<div class="col-sm-3">
<input type="text" name="living_sort" class="form-control" value="<?=$model->living_sort?>">
</div>
</div>
</div>
</div><!-- panel-footer -->
</div><!-- panel -->
</form>
<div class="form-group">
<label class="col-sm-3 control-label">分享主图: </label>
<div class="col-sm-9">
<?=$sharePicUploader?>
<?php if ($model->id && $roomShare['pic']):?>
<div class="file-item thumbnail upload-state-done" id="share_pic"><img src="<?=CommonImages::getImageUrl($roomShare['pic'], 110, 110)?>"><div class="info">当前图片</div></div>
<?php endif;?>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">分享标题: </label>
<div class="col-sm-9">
<input type="text" name="share_title" class="form-control" value="<?php echo ($model->id && $roomShare['title']) ? $roomShare['title']:''?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">分享内容: </label>
<div class="col-sm-9">
<!-- <input type="text" name="share_content" class="form-control" value="">-->
<textarea rows="5" name="share_content" class="form-control"><?php echo ($model->id && $roomShare['content']) ? $roomShare['content']:''?></textarea>
</div>
</div>
</div>
</div>
<!-- 右侧表单 end-->
</div><!-- panel-body -->
<div class="panel-footer">
<div class="row">
<div class="col-sm-9 col-sm-offset-3">
<button class="btn btn-primary mr5" id="upload_button" onclick="return verify()">保存</button>
<a href="<?=$_refer?>" class="btn btn-dark">取消</a>
</div>
</div>
</div><!-- panel-footer -->
</div><!-- panel -->
</form>
</div>
... ...
... ... @@ -43,6 +43,7 @@ if(!isset($condition['backState']))
<th>对应主播</th>
<th>对应直播房间号</th>
<th>腾讯视频连接</th>
<th>排序</th>
<th>操作</th>
<th>创建时间</th>
</tr>
... ... @@ -63,10 +64,12 @@ if(!isset($condition['backState']))
</td>
<td><?php echo $video->room_id;?></td>
<td><?php echo $video->url;?></td>
<td><?php echo $video->sort;?></td>
<td style="white-space:nowrap">
<div class="form-group" videoId="<?php echo $video->id;?>">
<button class="btn btn-primary">编辑</button>
<button class="btn btn-warning btn-metro" status="<?php echo $video->status;?>"><?php echo $video->status? '关闭':'开启';?></button>
<a class="btn btn-danger btn-metro" onclick="return confirm('删除该视频?')" href="/live/videodel/<?=$video->id?>" >删除</a>
</div>
</td>
<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;
<div class="col-sm-5">
<div class="col-sm-9">
<?=$uploader?>
<?php if ($video->pic):?>
<div class="file-item thumbnail upload-state-done">
<img src="<?php echo CommonImages::getImageUrl($video->pic, 200, 200)?>">
<div class="info">当前图片</div>
<img src="<?php echo CommonImages::getImageUrl($video->pic, 200, 200)?>">
<div class="info">当前图片</div>
</div>
<?php endif;?>
</div>
</div>
</div>
... ... @@ -39,6 +41,33 @@ use backend\widgets\YHGImage\Common\Images as CommonImages;
<input type="text" name="url" class="form-control" value="<?php echo $video->url;?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">直播中排序: </label>
<div class="col-sm-3">
<input type="text" name="sort" class="form-control" value="<?=$video->sort?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">分享主图: </label>
<div class="col-sm-9">
<?=$sharePicUploader?>
<?php if ($video->id && $videoShare['pic']):?>
<div class="file-item thumbnail upload-state-done" id="share_pic"><img src="<?=CommonImages::getImageUrl($videoShare['pic'], 110, 110)?>"><div class="info">当前图片</div></div>
<?php endif;?>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">分享标题: </label>
<div class="col-sm-9">
<input type="text" name="share_title" class="form-control" value="<?php echo ($video->id && $videoShare['title']) ? $videoShare['title']:''?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">分享内容: </label>
<div class="col-sm-9">
<textarea rows="5" name="share_content" class="form-control"><?php echo ($video->id && $videoShare['content']) ? $videoShare['content']:''?></textarea>
</div>
</div>
</div><!-- row -->
</div><!-- panel-body -->
<div class="panel-footer">
... ...
... ... @@ -49,7 +49,7 @@ function sendProduct(product_id){
i++;
if (i>5){
$('#runtime').html('');
$('#wsRuntime').html('');
i = 1;
}
... ...
<?php
$this->title = $this->params['main_title'].'-'.$this->params['sub_title'];
?>
<div class="col-md-6">
<form id="form" method="POST" action="">
<div class="panel panel-default">
<div class="panel-body">
<div class="row">
<div class="form-group">
<label class="col-sm-3 control-label">类型名称:<span class="asterisk">*</span></label>
<div class="col-sm-9">
<input type="text" name="name" class="form-control" required="required" value="<?php echo $model->name?>">
</div>
</div>
</div><!-- row -->
</div><!-- panel-body -->
<div class="panel-footer">
<div class="row">
<div class="col-sm-9 col-sm-offset-3">
<button class="btn btn-primary mr5" id="upload_button">保存</button>
<a href="<?=$_refer?>" class="btn btn-dark">取消</a>
</div>
</div>
</div><!-- panel-footer -->
</div><!-- panel -->
</form>
</div>
\ No newline at end of file
... ...
<?php
use yii\web\View;
use yii\helpers\Html;
$this->title = $this->params['main_title'].'-'.$this->params['sub_title'];
?>
<?php
$this->registerCssFile('/css/select2.css',array('postion'=>View::POS_END));
$this->registerJsFile('/js/select2.min.js',array('postion'=>View::POS_END));
?>
<script type="text/javascript">
<?php $this->beginBlock('javascript');?>
jQuery(document).ready(function() {
// Select2
jQuery(".select-basic").select2();
});
<?php
$this->endBlock();
$this->registerJs($this->blocks['javascript'],View::POS_END)
?>
</script>
<div class="col-md-6">
<form id="form" method="POST" action="">
<div class="panel panel-default">
<div class="panel-body">
<div class="row">
<div class="form-group">
<label class="col-sm-3 control-label">红包ID: <span class="asterisk">*</span></label>
<div class="col-sm-5">
<input type="text" name="coupon_id" class="form-control" required="required" value="<?=$model->coupon_id?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">红包类型: <span class="asterisk">*</span></label>
<div class="col-sm-5">
<?php echo Html::dropDownList('type_id', $model->type_id,$types, ['class' => 'width300 select-basic', 'required'=>"required"]);?>
</div>
</div>
</div><!-- row -->
</div><!-- panel-body -->
<div class="panel-footer">
<div class="row">
<div class="col-sm-9 col-sm-offset-3">
<button class="btn btn-primary mr5" id="upload_button">保存</button>
<a href="<?=$_refer?>" class="btn btn-dark">取消</a>
</div>
</div>
</div><!-- panel-footer -->
</div><!-- panel -->
</form>
</div>
... ...
<?php
use yii\web\View;
use yii\helpers\Html;
use backend\widgets\LinkPager;
$this->title = $this->params['main_title'].'-'.$this->params['sub_title'];
?>
<?php
$this->registerCssFile('/css/select2.css',array('postion'=>View::POS_END));
$this->registerJsFile('/js/select2.min.js',array('postion'=>View::POS_END));
?>
<?php echo $this->render('@app/views/layouts/websocket');?>
<script type="text/javascript">
<?php $this->beginBlock('javascript');?>
jQuery(document).ready(function() {
// Select2
jQuery(".select-basic").select2();
});
var couponId_by_type = <?= json_encode($couponId_by_type)?>;
var i = 0;
var room_id = <?=$room->room_id?>;
var interval_handle;
var default_interval = 3;
/**
* 推送红包
* @param {type} product_id
* @returns {undefined}
*/
function sendRedbag(){
var type_id = $('#type_id').val();
if (!type_id){
return alert('请选择红包类型');
}
if (!couponId_by_type.hasOwnProperty(type_id) || !couponId_by_type[type_id].length){
return alert('当前房间下没有该类型红包或无剩余库存');
}
if (!confirm('将推送该类型红包,确定?')){
return;
}
//同类型组内随机一个红包
var coupon_id = couponId_by_type[type_id];
i++;
if (i>5){
$('#wsRuntime').html('');
i = 1;
}
callWebsocket(function(){
consoleLog('');
consoleLog('发起推送,优惠券ID: '+coupon_id);
cmd = {cmd:10011,room:room_id,couponId:String(coupon_id)};
cmd = makeSign(cmd);
cmd = JSON.stringify(cmd);
consoleLog('发送消息: '+cmd);
ws.send(cmd);
getPushlog(default_interval);
});
}
/**
* 监听推送记录
* @param {type} package
* @returns {unresolved}
*/
function getPushlog(interval){
clearInterval(interval_handle);
if (interval){
interval_handle = setInterval(function(){
$.get('/ajax/pushgoodslog','',function(json){
console.log(json);
if (json.data){
consoleLog('监听到推送记录: '+json.data);
}
},'json');
},interval*1000);
$('#pushlog').text('推送记录监听中...再次点击停止').attr('onclick','getPushlog(false)');
}else{
$('#pushlog').text('开始监听推送记录').attr('onclick','getPushlog('+default_interval+')');
}
}
<?php
$this->endBlock();
$this->registerJs($this->blocks['javascript'],View::POS_END)
?>
</script>
<div class="panel">
<div class="panel-body">
<h4>房间号:<?=$room->room_id?> &nbsp;&nbsp; 直播标题:<?=$room->title?> &nbsp;&nbsp; 直播状态:<?=Yii::$app->params['config']['room_living'][$room->living]?></h4>
</div>
</div>
<div class="form-group">
<label>
<a href="/redbag/add/<?=$room->room_id?>" class="btn btn-primary">+ 添加红包</a>
<span style="margin-left:200px">
<?php echo Html::dropDownList('type_id', null,$types, ['class' => 'width300 select-basic','id'=>'type_id']);?>
<button type="button" onclick="sendRedbag()" class="btn btn-primary">发红包</button>
</span>
</label>
</div>
<div class="row">
<div class="col-md-12">
<div class="table-responsive">
<table class="table mb30">
<thead>
<tr style="white-space:nowrap">
<th><input type="checkbox" onclick="checkall(this)">选择</th>
<th>红包ID</th>
<th>红包类型</th>
<th>优惠券名称</th>
<th>优惠券剩余库存</th>
<th>优惠券生效时间</th>
<th>优惠券失效时间</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<?php foreach ($list as $model):?>
<tr data-stock="1" data-source="1" data-status="2" data-id="5011880">
<td><input type="checkbox" value="<?=$model->id?>" name="product[]"></td>
<td><?=$model->coupon_id?></td>
<td><?=$model->type ? $model->type->name : '无类型'?></td>
<th><?=$model->coupon_name?></th>
<td><?=$model->stock?></td>
<td><?=$model->effect_time ? date('Y-m-d H:i:s',$model->effect_time) : ''?></td>
<td><?=$model->invalid_time ? date('Y-m-d H:i:s',$model->invalid_time) : ''?></td>
<td>
<a href="/redbag/edit/<?=$model->id?>" class="btn btn-default btn-white">编辑</a>
<a onclick="return confirm('删除该红包?')" href="/redbag/operate/<?=$model->id?>?type=del" class="btn btn-danger btn-metro">删除</a>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
</div>
<!-- table-responsive -->
<?php echo LinkPager::widget(['pagination' => $pagination]);?>
</div>
<!-- col-md-12 -->
</div>
<div class="form-group">
<label>
<button type="button" onclick="getPushlog(default_interval)" id="pushlog" class="btn btn-primary">开始监听推送记录</button>
</label>
</div>
<div class="form-group">
<div class="col-sm-6" id="wsRuntime">
</div>
</div><!-- form-group -->
\ No newline at end of file
... ...
<?php
use yii\helpers\Html;
use backend\widgets\LinkPager;
$this->title = $this->params['main_title'].'-'.$this->params['sub_title'];
?>
<div class="form-group">
<label>
<a href="/redbag/addtype" class="btn btn-primary">+ 添加红包类型</a>
</label>
</div>
<div class="row">
<div class="col-md-12">
<div class="table-responsive">
<table class="table table-dark mb30">
<thead>
<tr>
<th>红包类型ID</th>
<th>红包类型名称</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<?php foreach($list as $v):?>
<tr>
<td><?php echo $v->type_id;?></td>
<td><?php echo $v->name;?></td>
<td>
<a class="btn btn-primary" href="/redbag/edittype/<?php echo $v->type_id;?>">编辑</a>
<a class="btn btn-danger" onclick="return confirm('删除该类型?')" href="/redbag/deltype/<?php echo $v->type_id;?>">删除</a>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
</div>
<!-- table-responsive -->
<?php echo LinkPager::widget(['pagination' => $pagination]);?>
</div>
<!-- col-md-12 -->
</div>
<script type="text/javascript">
</script>
\ No newline at end of file
... ...
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<title>403 Forbidden</title>
<link href="/css/style.default.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="/js/html5shiv.js"></script>
<script src="/js/respond.min.js"></script>
<![endif]-->
</head>
<body>
<section>
<div class="notfoundpanel">
<h1>403!</h1>
<h3>你无权限访问这个页面!</h3>
<p>这个页面可能被移除了,或者更名了,或者不可用,一般的原因是你的账户没有权限访问</p>
<a class="btn btn-primary" href="<?=$_refer?>">返回上一页</a>
</div><!-- notfoundpanel -->
</section>
</body>
</html>
... ...
<?php
defined('YII_DEBUG') or define('YII_DEBUG', false);
defined('YII_ENV') or define('YII_ENV', 'prod');
//error_reporting(E_ALL ^ E_NOTICE);
require(__DIR__ . '/../../vendor/autoload.php');
require(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php');
... ...
<?php
namespace backend\widgets;
use Yii;
use backend\components\filters\AccessControl;
/**
* 管理后台左侧菜单
*/
class LeftMenu extends \yii\base\Widget
{
public function init()
{
parent::init();
}
/**
* Executes the widget.
* @return string the result of widget execution to be outputted.
*/
public function run()
{
if (AccessControl::forceAccess()){
$menu = Yii::$app->params['menu'];
}else{
$userPermissions = Yii::$app->authManager->getPermissionsByUser(Yii::$app->user->getId());
$menu = [];
foreach (Yii::$app->params['menu'] as $controller=>$main){
if (is_array($main[1])){
$subs = [];
foreach ($main[1] as $action=>$sub){
if (empty($sub[1])){
continue;
}
if (!empty($userPermissions[$sub[1]])){
$subs[$action] = $sub;
}
}
if (!empty($subs)){
$menu[$controller] = array($main[0],$subs);
}
}else{
if (empty($main[1])){
continue;
}
if (!empty($userPermissions[$main[1]])){
$menu[$controller] = $main;
}
}
}
}
return $this->render('leftmenu',[
'menu'=>$menu
]);
}
}
... ...
<div class="leftpanel">
<div class="media profile-left">
<a class="pull-left profile-thumb" href="profile.html">
<img class="img-circle" src="/images/photos/profile.png" alt="">
</a>
<div class="media-body">
<h4 class="media-heading"><?=Yii::$app->user->isGuest ? 'Guest' : Yii::$app->user->getIdentity()->username?></h4>
<small class="text-muted">超级管理员</small>
</div>
</div><!-- media -->
<h5 class="leftpanel-title">Navigation</h5>
<ul class="nav nav-pills nav-stacked">
<?php foreach (Yii::$app->params['menu'] as $controller=>$main):?>
<?php if (is_array($main[1])):?>
<li class="parent <?=($this->params['main_id'] == $controller) ? 'active' : ''?>"><a href="javascript:;"><i class="fa fa-suitcase"></i> <span><?=$main[0]?></span></a>
<ul class="children">
<?php foreach ($main[1] as $action=>$sub):?>
<li class="<?=($this->params['sub_id'] == $action) ? 'active' : ''?>"><a href="<?php echo Yii::getAlias('@web/'.$sub[1])?>"><?=$sub[0]?></a></li>
<?php endforeach;?>
</ul>
<?php else:?>
<li class="<?=($this->params['main_id'] == $controller) ? 'active' : ''?>"><a href="<?php echo Yii::getAlias('@web/'.$main[1])?>"><i class="fa fa-suitcase"></i> <span><?=$main[0]?></span></a>
<?php endif;?>
</li>
<?php endforeach;?>
<?php foreach ($menu as $controller=>$main):?>
<?php if (is_array($main[1])):?>
<li class="parent <?=($this->params['main_id'] == $controller) ? 'active' : ''?>"><a href="javascript:;"><i class="fa fa-suitcase"></i> <span><?=$main[0]?></span></a>
<ul class="children">
<?php foreach ($main[1] as $action=>$sub):?>
<li class="<?=($this->params['sub_id'] == $action) ? 'active' : ''?>"><a href="<?php echo Yii::getAlias('@web/'.$sub[1])?>"><?=$sub[0]?></a></li>
<?php endforeach;?>
</ul>
<?php else:?>
<li class="<?=($this->params['main_id'] == $controller) ? 'active' : ''?>"><a href="<?php echo Yii::getAlias('@web/'.$main[1])?>"><i class="fa fa-suitcase"></i> <span><?=$main[0]?></span></a>
<?php endif;?>
</li>
</div><!-- leftpanel -->
\ No newline at end of file
<?php endforeach;?>
\ No newline at end of file
... ...
... ... @@ -5,7 +5,4 @@ Yii::setAlias('@backend', dirname(dirname(__DIR__)) . '/backend');
Yii::setAlias('@console', dirname(dirname(__DIR__)) . '/console');
Yii::setAlias('@soa', dirname(dirname(__DIR__)) . '/soa');
Yii::setAlias('@root', dirname(dirname(__DIR__)));
Yii::setAlias('@www', 'http://live.yoho.cn');
Yii::setAlias('@admin', 'http://admin.live.yoho.cn');
Yii::setAlias('@api', 'http://api.live.yoho.cn');
\ No newline at end of file
Yii::setAlias('@root', dirname(dirname(__DIR__)));
\ No newline at end of file
... ...
... ... @@ -4,7 +4,6 @@ return [
'components' => [
'fileCache' => [
'class' => 'yii\caching\FileCache',
'keyPrefix' => 'YOHOLive:',
],
'cache' => [
'class' => 'common\components\pagecache\Redis',
... ...
<?php
namespace common\config;
use Yii;
/**
* 环境变量/常量
*/
class Environmen{
/**
* 应用环境量
*/
static function ENV(){
if (YII_ENV_PROD){
self::setProd();
}elseif (YII_ENV_DEV){
self::setDev();
}else{
self::setProd();
}
}
/**
* 生产环境
*/
private static function setProd(){
Yii::setAlias('@www', 'http://live.yoho.cn');
Yii::setAlias('@admin', 'http://admin.live.yoho.cn');
Yii::setAlias('@api', 'http://api.live.yoho.cn');
define('NEWS_DOMAIN','http://newboys.yoho.cn/');
define('YOHOBUY_H5_DOMAIN','http://m.yohobuy.com');
define('YOHOBUY_API_DOMAIN', 'http://api.yoho.cn/');
}
/**
* 开发环境
*/
private static function setDev(){
Yii::setAlias('@www', 'http://live.yoho.cn');
Yii::setAlias('@admin', 'http://admin.live.yoho.cn');
Yii::setAlias('@api', 'http://api.live.yoho.cn');
define('NEWS_DOMAIN','http://newboys.test.yoho.cn/');
define('YOHOBUY_H5_DOMAIN','http://m.yohobuy.com');
define('YOHOBUY_API_DOMAIN', 'http://api.yoho.cn/');
}
}
Environmen::ENV();
class Params {
/**
* 业务线
... ... @@ -20,6 +68,36 @@ class Params {
* 直播已结束
*/
const LIVE_END = 2;
/**
* 是否精选
*/
const BEST_NO = 0;
const BEST_1 = 1;
const BEST_2 = 2;
/**
* 马甲状态
*/
const VEST_NO = 0;
const VEST_SLOW = 1;
const VEST_NORMAL = 2;
const VEST_FAST = 3;
/**
* 禁言状态
*/
const UN_FORBID = 0;
const IS_FORBID = 1;
/**
* 直播分享类型
*/
const LIVE_SHARE_TYPE = 1;
/**
* 回看分享类型
*/
const VIDEO_SHARE_TYPE = 2;
}
return [
... ... @@ -36,16 +114,16 @@ return [
],
//是否精选
'best'=>[
0=>'否',
1=>'精选1',
2=>'精选2',
Params::BEST_NO=>'否',
Params::BEST_1=>'精选1',
Params::BEST_2=>'精选2',
],
//马甲状态
'vest'=>[
0=>'关闭',
1=>'最慢',
2=>'一般',
3=>'最快'
Params::VEST_NO=>'关闭',
Params::VEST_SLOW=>'最慢',
Params::VEST_NORMAL=>'一般',
Params::VEST_FAST=>'最快'
],
//直播状态
'room_living'=>[
... ... @@ -54,9 +132,9 @@ return [
Params::LIVE_END=>'已结束',
],
//未被禁言状态
'un_forbid_stat'=>0,
'un_forbid_stat'=>Params::UN_FORBID,
//被禁言状态
'is_forbid_stat'=>1,
'is_forbid_stat'=>Params::IS_FORBID,
//累加人数
'is_addup'=>1,
],
... ... @@ -78,5 +156,5 @@ return [
'failed_code'=>8001,
//异常状态
'exception_code'=>500,
'news_domain'=>'http://new.yohoboys.com/',
'news_domain'=>NEWS_DOMAIN,
];
... ...
... ... @@ -7,14 +7,11 @@ use yii\helpers\ArrayHelper;
/**
* 有货接口
* @author wuxiao
*
* @文档地址 http://git.yoho.cn/yoho-documents/api-interfaces
*/
class Client{
private static $_domain = array(
'prod' => 'http://api.yoho.cn/',
'dev' => 'http://192.168.102.205:8080/gateway/',
);
/**
* 私钥列表
... ... @@ -104,6 +101,21 @@ class Client{
return $this->send($params);
}
/**
* 根据多个优惠券id查询的接口
* @param type $couponId
* @return type
*/
public function couponList($couponId){
$couponId = (array)$couponId;
$params = [
'client_type'=>self::client_type,
'method'=>'app.coupons.queryBroadCouponList',
'couponIds'=>implode(',',$couponId),
];
return $this->send($params);
}
protected function send(array $params)
{
$params = $this->makeUrl($params);
... ... @@ -132,7 +144,7 @@ class Client{
}
protected function getDomain(){
return ArrayHelper::getValue(self::$_domain, YII_ENV,self::$_domain['prod']);
return YOHOBUY_API_DOMAIN;
}
/**
... ... @@ -176,6 +188,10 @@ class Client{
self::$_rawResponse = $resultStr;
if (!$resultStr)
{
return $resultStr;
}
$result = json_decode($resultStr, true);
if (!$result)
{
... ...
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "{{%redbag_type}}".
*
* @property string $type_id
* @property string $name
* @property integer $create_time
* @property integer $update_time
*/
class RedbagType extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%redbag_type}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['name'], 'required'],
[['create_time', 'update_time'], 'integer'],
[['name'], 'string', 'max' => 100],
[['name'], 'unique'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'type_id' => '类型ID',
'name' => '类型名称',
'create_time' => '创建时间',
'update_time' => '更新时间',
];
}
public function behaviors() {
return [
[
'class' => \yii\behaviors\TimestampBehavior::className(),
'createdAtAttribute' => 'create_time',
'updatedAtAttribute' => 'update_time',
]
];
}
/**
* 返回所有主播[id=>id.' '.name,...]的列表数组
* @return string
*/
public static function getId2name(){
$list = self::find()->all();
$ret = [];
foreach ($list as $model){
$ret[$model->type_id] = $model->name;
}
return $ret;
}
}
... ...
... ... @@ -37,7 +37,7 @@ class Room extends \yii\db\ActiveRecord
public function rules()
{
return [
[['room_id', 'master_id', 'starting_time', 'best', 'vest', 'living', 'status', 'create_time', 'update_time'], 'integer'],
[['room_id', 'master_id', 'starting_time', 'best', 'vest', 'living', 'status', 'unstart_sort', 'living_sort', 'create_time', 'update_time'], 'integer'],
[['title', 'watermark'], 'string', 'max' => 100],
[['app', 'secret'], 'string', 'max' => 50],
[['pic', 'background_pic'], 'string', 'max' => 255],
... ... @@ -134,4 +134,13 @@ class Room extends \yii\db\ActiveRecord
{
return $this->hasOne(RoomQchannel::className(), ['room_id'=>'room_id']);
}
/**
* 关联表-房间附属信息
* @return type
*/
public function getRoomInfo()
{
return $this->hasOne(RoomInfo::className(), ['room_id'=>'room_id']);
}
}
... ...
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "{{%room_info}}".
*
* @property integer $room_id
* @property integer $last_time
*/
class RoomInfo extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%room_info}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['room_id'], 'required'],
[['room_id', 'last_time'], 'integer'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'room_id' => 'Room ID',
'last_time' => 'Last Time',
];
}
}
... ...
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "{{%room_redbag}}".
*
* @property string $id
* @property string $room_id
* @property string $coupon_id
* @property integer $type
* @property string $coupon_name
* @property integer $stock
* @property integer $effect_time
* @property integer $invalid_time
* @property integer $create_time
* @property integer $update_time
*/
class RoomRedbag extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%room_redbag}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['room_id', 'coupon_id', 'type_id', 'stock', 'effect_time', 'invalid_time', 'create_time', 'update_time'], 'integer'],
[['coupon_name'], 'string', 'max' => 100],
[['room_id', 'coupon_id'], 'unique', 'targetAttribute' => ['room_id', 'coupon_id'], 'message' => 'The combination of 房间号 and 优惠券ID has already been taken.'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'room_id' => '房间号',
'coupon_id' => '优惠券ID',
'type_id' => '红包类型',
'coupon_name' => '优惠券名称',
'stock' => '优惠券剩余库存',
'effect_time' => '优惠券生效时间',
'invalid_time' => '优惠券失效时间',
'create_time' => '创建时间',
'update_time' => '更新时间',
];
}
public function behaviors() {
return [
[
'class' => \yii\behaviors\TimestampBehavior::className(),
'createdAtAttribute' => 'create_time',
'updatedAtAttribute' => 'update_time',
]
];
}
/**
* 关联表-类型
* @return type
*/
public function getType()
{
return $this->hasOne(RedbagType::className(), ['type_id'=>'type_id']);
}
}
... ...
<?php
namespace common\models;
use Yii;
use common\config\Params;
use backend\widgets\YHGImage\Common\Images as CommonImages;
/**
* This is the model class for table "{{%share}}".
*
* @property integer $id
* @property integer $obj_id
* @property integer $type
* @property string $title
* @property string $content
* @property integer $create_time
* @property integer $update_time
*/
class Share extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%share}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['obj_id', 'type', 'create_time', 'update_time'], 'integer'],
[['content'], 'string'],
[['pic'], 'string', 'max' => 200],
[['title'], 'string', 'max' => 100],
[['obj_id', 'type'], 'unique', 'targetAttribute' => ['obj_id', 'type'], 'message' => 'The combination of Obj ID and Type has already been taken.'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'obj_id' => 'Obj ID',
'type' => 'Type',
'pic' => '分享头图',
'title' => '分享标题',
'content' => '分享内容',
'create_time' => 'Create Time',
'update_time' => 'Update Time',
];
}
public function getLivingShare($room_id)
{
return $this->get($room_id, Params::LIVE_SHARE_TYPE);
}
public function getVideoShare($video_id)
{
return $this->get($video_id, Params::VIDEO_SHARE_TYPE);
}
private function get($obj_id, $type)
{
$ret = [
'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',
'share_url' => ($type == Params::LIVE_SHARE_TYPE) ? YOHOBUY_H5_DOMAIN.'/activity/live/' . $obj_id : YOHOBUY_H5_DOMAIN.'/activity/live/replay/' . $obj_id,
'share_title' => '有货潮流新品节直播开始啦,快来看!',
'share_content' => 'YO\'HOOD嘉年华现场火热直播中,明星潮牌等你来!',
];
if ($model = self::findOne(['obj_id' => $obj_id, 'type' => $type])) {
if($model->pic && $model->title && $model->content){
$ret['share_pic'] = CommonImages::getTemplateComplex($model->pic, 2);
$ret['share_title'] = $model->title;
$ret['share_content'] = $model->content;
}
}
return $ret;
}
/**
* 红包分享
* @return array
*/
public function redBag()
{
return [
'redbag_share_pic' => CommonImages::getTemplateComplex('/2016/11/01/17/01835bcc555349d7d7a5a83bb9e68f1fa7.png', 1),
'redbag_share_title' => '有货直播发红包啦,快来抢!',
'redbag_share_content' => '有货直播中狂发红包,领取立享优惠!',
];
}
}
... ...
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "{{%user_redbag}}".
*
* @property string $id
* @property string $user_id
* @property string $room_id
* @property string $coupon_id
* @property integer $create_time
* @property integer $update_time
*/
class UserRedbag extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%user_redbag}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['user_id', 'room_id', 'coupon_id', 'create_time', 'update_time'], 'integer'],
[['user_id', 'room_id', 'coupon_id'], 'unique', 'targetAttribute' => ['user_id', 'room_id', 'coupon_id'], 'message' => 'The combination of 房间号, 房间号 and 优惠券ID has already been taken.'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'user_id' => '房间号',
'room_id' => '房间号',
'coupon_id' => '优惠券ID',
'create_time' => '创建时间',
'update_time' => '更新时间',
];
}
public function behaviors() {
return [
[
'class' => \yii\behaviors\TimestampBehavior::className(),
'createdAtAttribute' => 'create_time',
'updatedAtAttribute' => 'update_time',
]
];
}
}
... ...
... ... @@ -6,6 +6,7 @@ use Yii;
use common\lib\QcloudApi\Client as QcloudApiClient;
use common\lib\QcloudApi\QcloudApi as Qapi;
use common\lib\YohonowApi\Request as YHNowApiReq;
use common\config\Params;
/**
* This is the model class for table "{{%video}}".
... ... @@ -115,26 +116,21 @@ class Video extends \yii\db\ActiveRecord
{
$transaction = $this->getDb()->beginTransaction();
try {
/*$qchannel = (new \yii\db\Query())
->select('channel_id')
->from('tbl_room_qchannel')
->where(['room_id' => $room_id])
->one();*/
$room = (new \yii\db\Query())
->select('app,title,master_id')
->select('app,title,master_id,status')
->from('tbl_room')
->where(['room_id' => $room_id])
->one();
$time = time();
//此处有bug,channel_id必须要转成字符串,不然底层会转换成科学计数法的格式
//$ret = QcloudApiClient::self()->CreateRecord(strval($qchannel['channel_id']), date('Y-m-d H:i:s',time()+120), '');
//file_put_contents("/tmp/live.log",date('Y-m-d H:i:s')."|start ".var_export($ret,true),FILE_APPEND)."\n";
if (1) {//$ret['code'] == 0
if(!$room['status']){
throw new \Exception("该房间已被禁用,请联系管理员");
}
if (1) {
$this->setAttributes([
'app' => $room['app'],
'task_id' => 0,//$ret['task_id']
'live_title' => $room['title'],
'live_start_time' => $time,
'live_start_time' => time(),
'live_end_time' => 0,
'master_id' => $room['master_id'],
'room_id' => $room_id,
... ... @@ -145,7 +141,7 @@ class Video extends \yii\db\ActiveRecord
}
//更新房间主表直播状态
$result = Yii::$app->db->createCommand()
->update('{{%room}}', ['living' => 1,'update_time'=>time()], ['room_id' => $room_id])
->update('{{%room}}', ['living' => Params::LIVING,'update_time'=>time()], ['room_id' => $room_id])
->execute();
if (!$result) {
throw new \Exception('tbl_room update error');
... ... @@ -189,40 +185,38 @@ class Video extends \yii\db\ActiveRecord
{
$transaction = $this->getDb()->beginTransaction();
try {
/*$qchannel = (new \yii\db\Query())
->select('channel_id')
->from('tbl_room_qchannel')
->where(['room_id' => $room_id])
->one();*/
$video = $this->find()
->where(['room_id' => $room_id, 'live_end_time' => 0])
->orderBy(['live_start_time' => SORT_DESC])
->one();
if ($video) {
//此处有bug,channel_id必须要转成字符串,不然底层会转换成科学计数法的格式
//$ret = QcloudApiClient::self()->StopRecord(strval($qchannel['channel_id']), $video['task_id']);
//file_put_contents("/tmp/live.log",date('Y-m-d H:i:s')."|stop ".var_export($ret,true),FILE_APPEND)."\n";
$room = (new \yii\db\Query())
->select('app,title,master_id')
->from('tbl_room')
->where(['room_id' => $room_id])
->one();
if (1) {//$ret['code'] == 0
if (1) {
$video->setAttributes([
'live_end_time' => time(),
]);
if (!$video->update()) {
throw new \Exception(current($this->getFirstErrors()));
}
$living_status = 2;
$updateFields = [
'living' => Params::LIVE_END,
'update_time' => time(),
'unstart_sort' => 0,
'living_sort' => 0
];
//更新房间主表直播状态
$result = Yii::$app->db->createCommand()
->update('{{%room}}', ['living' => $living_status,'update_time'=>time()], ['room_id' => $room_id])
->update('{{%room}}', $updateFields, ['room_id' => $room_id])
->execute();
if (!$result) {
throw new \Exception('tbl_room update error');
}
//该房间如果包含资讯业务线,那么要更新资讯那边状态
if(in_array(\common\config\Params::YOHONOW,explode(',',$room['app']))){
$news_ret = YHNowApiReq::getInstance()->setLiveStat($room_id,0);
... ...
... ... @@ -12,7 +12,7 @@ class InitController extends Controller
{
/**
* Create init user
* 创建/修改后台用户
*/
public function actionAdmin()
{
... ... @@ -80,4 +80,132 @@ class InitController extends Controller
public function actionTest(){
echo "init/test";
}
/**
* 创建/移除后台权限标签(controller/action)
*/
public function actionRbac(){
$this->stdout("1: Create permission\n2: Remove permission\n3: Create role\n4: Remove role\n5: Grant permission to a role\n6: Revoke permission from a role\n7: Grant role to a user\n8: Revoke role from a a\n");
$action = $this->prompt('Which:');
$auth = Yii::createObject('yii\rbac\DbManager');
//$auth = Yii::$app->authManager;
if ($action == 1){
echo "创建一个新权限标签 ...\n"; // 提示当前操作
$name = $this->prompt('Permission Name:'); // 权限名称
$description = $this->prompt('Description(default is as name):'); // 描述
if ($name){
$permission = $auth->createPermission($name);
$permission->description = $description ? : ucwords(strtr($name,array('/'=>' ')));
if ($auth->add($permission)){
$this->stdout('create ok');
}
}
}elseif ($action == 2){
echo "移除一个权限标签 ...\n"; // 提示当前操作
$name = $this->prompt('Permission Name:'); // 权限名称
if ($name){
if (!$permission = $auth->getPermission($name)){
$this->stderr('Not a predefined permission');
return 1;
}
if ($auth->remove($permission)){
$this->stdout('remove ok');
}
}
}elseif ($action == 3){
echo "创建一个新角色 ...\n"; // 提示当前操作
$name = $this->prompt('Role Name:'); // 角色名称
$description = $this->prompt('Description(default is as name):'); // 描述
if ($name){
$role = $auth->createRole($name);
$role->description = $description ? : ucfirst($name);
if ($auth->add($role)){
$this->stdout('create ok');
}
}
}elseif ($action == 4){
echo "移除一个角色 ...\n"; // 提示当前操作
$name = $this->prompt('Role Name:'); // 角色名称
if ($name){
if (!$role = $auth->getRole($name)){
$this->stderr('Not a predefined role');
return 1;
}
if ($auth->remove($role)){
$this->stdout('remove ok');
}
}
}elseif ($action == 5){
echo "向某个角色赋予权限 ...\n"; // 提示当前操作
$name = $this->prompt('Role Name:'); // 接收用户名
if (!$role = $auth->getRole($name)){
$this->stderr('Not a predefined role');
return 1;
}
$name = $this->prompt('Permission Name:'); // 接收用户名
if (!$permission = $auth->getPermission($name)){
$this->stderr('Not a predefined permission');
return 1;
}
if ($auth->addChild($role,$permission)){
$this->stdout('grant permission ok');
}
}elseif ($action == 6){
echo "从某个角色剥夺权限 ...\n"; // 提示当前操作
$name = $this->prompt('Role Name:'); // 接收用户名
if (!$role = $auth->getRole($name)){
$this->stderr('Not a predefined role');
return 1;
}
$name = $this->prompt('Permission Name:'); // 接收用户名
if (!$permission = $auth->getPermission($name)){
$this->stderr('Not a predefined permission');
return 1;
}
if ($auth->removeChild($role,$permission)){
$this->stdout('revoke permission ok');
}
}elseif ($action == 7){
echo "向某个用户赋予角色 ...\n"; // 提示当前操作
$username = $this->prompt('User Name:'); // 接收用户名
if (!$user = Admin::findByUsername($username)){
echo '找不到该用户';
return 1;
}
$name = $this->prompt('Role Name:'); // 接收用户名
if (!$role = $auth->getRole($name)){
$this->stderr('Not a predefined role');
return 1;
}
if ($auth->assign($role,$user->getId())){
$this->stdout('grant role ok');
}
}elseif ($action == 8){
echo "从某个用户剥夺角色 ...\n"; // 提示当前操作
$username = $this->prompt('User Name:'); // 接收用户名
if (!$user = Admin::findByUsername($username)){
echo '找不到该用户';
return 1;
}
$name = $this->prompt('Role Name:'); // 接收用户名
if (!$role = $auth->getRole($name)){
$this->stderr('Not a predefined role');
return 1;
}
if ($auth->revoke($role,$user->getId())){
$this->stdout('revoke role ok');
}
}else{
$this->stderr('Not a predefined option');
return 1;
}
return 0;
}
}
... ...
... ... @@ -4,12 +4,16 @@ namespace console\controllers;
use Yii;
use yii\console\Controller;
use common\models\Room;
use common\config\Params;
use common\lib\QcloudApi\Client as QcloudApiClient;
use common\models\Video;
/**
* Site controller
*/
class RoomController extends Controller
{
const QCLOUD_LVING_STAT = 1;
/**
* 重置房间状态
... ... @@ -57,4 +61,57 @@ class RoomController extends Controller
}
}
/**
* 检查直播中的房间,如果腾讯云返回不是直播中的置为直播结束,30min检查一次
* https://www.qcloud.com/doc/api/258/4717
* 0 无输入流 ,1 直播中, 2 异常, 3 关闭
* @author yaoxiaofeng
* @use php yii room/check
*/
public function actionCheck()
{
//获取本地服务器直播中的房间
$result = Room::find()
->where(['living' => Params::LIVING])
->orderBy(['starting_time' => SORT_ASC])
->all();
if ($result) {
$TIME_MAX = 30 * 60;
$flag = false;
foreach ($result as $room) {
//当前时间 > 最后一次存活时间+阈值
if (!$room->roomInfo || (time() < ($room->roomInfo->last_time + $TIME_MAX))) {
continue;
}
try {
if ($room->roomQchannel) {
$channel_id = (string)$room->roomQchannel->channel_id;
$ret = QcloudApiClient::self()->DescribeLVBChannel($channel_id);
if (!$ret) {
$this->_log(QcloudApiClient::self()->error());
continue;
}
//腾讯云返回不是直播中的置为直播结束
if ($ret['channelInfo'][0]['channel_status'] != self::QCLOUD_LVING_STAT) {
$video_res = (new Video())->setVideoStop($room->room_id);
if ($video_res) {
$this->_log("room[{$room->room_id}] closed success");
} else {
$this->_log("room[{$room->room_id}] closed faild");
}
}
}
} catch (\Exception $e) {
$this->_log("room[{$room->room_id}] exception:" . $e->getMessage());
}
}
}
}
private function _log($string){
$string = sprintf("[%s]%s \n",date('Y-m-d H:i:s'),$string);
$this->stdout($string);
}
}
... ...
<?php
namespace console\controllers;
use Yii;
use yii\console\Controller;
/**
* Site controller
*/
class TestController extends Controller
{
/**
* TEST
*/
public function actionIndex(){
$this->stdout("this is console mode\n");
return 0;
}
}
... ...
<?php
namespace console\controllers;
use Yii;
use yii\console\Controller;
use common\models\Video;
/**
* Site controller
*/
class VideoController extends Controller
{
/**
* 同步回放观看人数到数据库
*/
public function actionReplaynum(){
while(true){
//获取前台展示的视频
$result = Video::find()
->where(['status'=>1])
->orderBy(['update_time'=>SORT_DESC])
->all();
$this->stdout("[".date('Y-m-d H:i:s')."]New loop, check for ".count($result)." videos\n");
if($result){
$keys = [];
foreach($result as $model){
$keys[$model->id] = sprintf("%svideo_id_%s_replay_num",Yii::$app->params['cache_prefix'],$model->id);
}
$values = $keys ? call_user_func_array(array(Yii::$app->redis,'mget'), $keys) : [];
//var_dump($keys,$values);exit;
foreach($result as $k=>$model){
if ($replay_num = $values[$k]){
$video_id = $model->id;
$this->stdout("\tupdate video ".$video_id." replay_num to ".$replay_num.":\n");
if (Video::updateAll(['replay_num' => $replay_num],['id'=>$video_id])){
$this->stdout("\tsuccess\n");
Yii::$app->redis->del($keys[$video_id]);
}else{
$this->stderr("\tfail\n");
}
}
}
unset($keys,$values);
}
unset($result);
$this->stdout("Loop end\n");
sleep(300);
}
}
}
... ...
<?php
use yii\db\Migration;
class m130524_201442_init extends Migration
{
public function up()
{
$tableOptions = null;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
}
$this->createTable('{{%user}}', [
'id' => $this->primaryKey(),
'username' => $this->string()->notNull()->unique(),
'auth_key' => $this->string(32)->notNull(),
'password_hash' => $this->string()->notNull(),
'password_reset_token' => $this->string()->unique(),
'email' => $this->string()->notNull()->unique(),
'status' => $this->smallInteger()->notNull()->defaultValue(10),
'created_at' => $this->integer()->notNull(),
'updated_at' => $this->integer()->notNull(),
], $tableOptions);
}
public function down()
{
$this->dropTable('{{%user}}');
}
}
... ... @@ -8,4 +8,10 @@ stillRunning=$(ps -ef |grep "room/stat" |grep -v "grep")
if [ -z "$stillRunning" ] ; then
nohup $phpcmd $phpscriptDir/yii room/stat >> $phpscriptlog/yoholive_room_stat.log 2>&1 &
fi
stillRunning=$(ps -ef |grep "video/replaynum" |grep -v "grep")
if [ -z "$stillRunning" ] ; then
nohup $phpcmd $phpscriptDir/yii video/replaynum >> $phpscriptlog/yoholive_video_replaynum.log 2>&1 &
fi
sleep 5
\ No newline at end of file
... ...
... ... @@ -8,6 +8,7 @@ use common\models\Room;
use common\models\Video;
use common\models\LiveComment;
use common\models\RoomNums;
use common\models\Share;
class LivingController extends BaseController
{
... ... @@ -61,7 +62,10 @@ class LivingController extends BaseController
$key = __CLASS__.__FUNCTION__.'app'.$this->app;
if (!$ret = $this->cache->get($key)){
$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();
$ret = Room::find()->with(['master','roomNums'])->where(['and',['living'=>1],"find_in_set({$this->app},app)"])
->joinWith('roomNums rn')
->orderBy(['living_sort'=>SORT_DESC,'rn.online_num'=>SORT_DESC])
->all();
foreach ($ret as $k=>$model){
$row = [
... ... @@ -112,7 +116,10 @@ class LivingController extends BaseController
$key = __CLASS__.__FUNCTION__.'app'.$this->app;
if (!$ret = $this->cache->get($key)){
$ret = Room::find()->with(['master'])->where(['and',['living'=>0],['!=','starting_time',0],"find_in_set({$this->app},app)"])->orderBy(['starting_time'=>SORT_ASC])->all();
$ret = Room::find()->with(['master'])
->where(['and',['living'=>0],['!=','starting_time',0],"find_in_set({$this->app},app)"])
->orderBy(['unstart_sort'=>SORT_DESC,'starting_time'=>SORT_ASC])
->all();
foreach ($ret as $k=>$model){
$row = [
... ... @@ -152,7 +159,10 @@ class LivingController extends BaseController
$key = __CLASS__.__FUNCTION__.'app'.$this->app;
if (!$ret = $this->cache->get($key)){
$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();
$ret = Video::find()->with(['master'])
->where(['and',['status' => 1],['not', ['url' => null]],['not', ['url' => '']],"find_in_set({$this->app},app)"])
->orderBy(['sort'=>SORT_DESC,'create_time'=>SORT_DESC])
->all();
foreach ($ret as $k=>$model){
$row = [
... ... @@ -165,7 +175,8 @@ class LivingController extends BaseController
'url'=>$model->url,
'live_title'=>$model->live_title,
'live_room_id'=>(int)$model->room_id,
'audience_num'=>(int)($model->audience_num+$model->replay_num),
'audience_num'=>(int)$model->audience_num,
'replay_num'=>(int)$model->replay_num,
'create_time'=>(int)$model->create_time,
];
$ret[$k] = $row;
... ... @@ -176,15 +187,17 @@ class LivingController extends BaseController
->bindValue(':app', $this->app)
->getRawSql()]);
$this->cache->set($key, $ret, Yii::$app->params['defaultCacheExpire'], $dependency);
}else{
$keys = [];
foreach ($ret as $k=>$row){
$keys[] = sprintf("%svideo_id_%s_audience_num",Yii::$app->params['cache_prefix'],$row['video_id']);
}
$values = $keys ? call_user_func_array(array(Yii::$app->redis,'mget'), $keys) : [];
foreach ($values as $k=>$value){
$ret[$k]['audience_num'] = (int)($value ? : $ret[$k]['audience_num']);
}
}
$keys = [];
foreach ($ret as $k=>$row){
$keys[] = sprintf("%svideo_id_%s_replay_num",Yii::$app->params['cache_prefix'],$row['video_id']);
}
$values = $keys ? call_user_func_array(array(Yii::$app->redis,'mget'), $keys) : [];
foreach ($ret as $k=>$row){
$replay_num = (int)(@$values[$k] ? : $ret[$k]['replay_num']);
$ret[$k]['audience_num'] += $replay_num;
$ret[$k]['replay_num'] = $replay_num;
}
$this->renderJson(Yii::$app->params['success_code'],'',$ret);
... ... @@ -267,10 +280,12 @@ class LivingController extends BaseController
}
$ret['background_pic'] = $ret['background_pic'] ? : 'http://img11.static.yhbimg.com/global/2016/08/17/18/01f17a9cd44149052482e4ee58e590cf1b.png';
$ret['share_url'] = 'http://m.yohobuy.com/activity/live/'.$room_id;
$ret['share_title'] = 'YOHO!BUY有货双11直播开始啦,快开看!';
$ret['share_content'] = 'YOHO!BUY有货火热直播中,潮牌型品双11价独享,等你来!';
$shareModel = new Share();
//内容分享
$ret += $shareModel->getLivingShare($room_id);
//红包分享
$ret += $shareModel->redBag();
$dependency = new \yii\caching\DbDependency(['sql' => Yii::$app->db
->createCommand('SELECT update_time FROM {{%room}} WHERE room_id=:room_id')
->bindValue(':room_id', $room_id)
... ... @@ -298,7 +313,8 @@ class LivingController extends BaseController
'watermark'=>'',
'url'=>$model->url,
'like_num'=>(int)$model->like_num,
'audience_num'=>(int)($model->audience_num+$model->replay_num),
'audience_num'=>(int)$model->audience_num,
'replay_num'=>(int)$model->replay_num,
'live_title'=>$model->live_title,
'live_start_time'=>(int)$model->live_start_time,
'live_end_time'=>(int)$model->live_end_time,
... ... @@ -320,9 +336,8 @@ class LivingController extends BaseController
}
$ret['background_pic'] = 'http://img11.static.yhbimg.com/global/2016/08/17/18/01f17a9cd44149052482e4ee58e590cf1b.png';
$ret['share_url'] = 'http://m.yohobuy.com/activity/live/replay/'.$video_id;
$ret['share_title'] = 'YOHO!BUY有货双11直播开始啦,快开看!';
$ret['share_content'] = 'YOHO!BUY有货火热直播中,潮牌型品双11价独享,等你来!';
$share = (new Share)->getVideoShare($video_id);
$ret += $share;
$dependency = new \yii\caching\DbDependency(['sql' => Yii::$app->db
->createCommand('SELECT update_time FROM {{%video}} WHERE id=:video_id')
... ... @@ -332,17 +347,23 @@ class LivingController extends BaseController
}
//缓存回放观看人数
$key = sprintf("%svideo_id_%s_audience_num",Yii::$app->params['cache_prefix'],$video_id);
if (!$audience_num = Yii::$app->redis->get($key)){
$audience_num = (int)$ret['audience_num'];
Yii::$app->redis->setex($key, Yii::$app->params['defaultCacheExpire']*2, $audience_num);
$key = sprintf("%svideo_id_%s_replay_num",Yii::$app->params['cache_prefix'],$video_id);
if (!$replay_num = (int)Yii::$app->redis->get($key)){
$replay_num = (int)$ret['replay_num'];
Yii::$app->redis->set($key, $replay_num);
}
$ret['audience_num'] = $audience_num;
//$ret['audience_num'] = $audience_num;
//观看回放人数+1
if (Video::updateAllCounters(['replay_num' => 1],['id'=>$video_id]) && Yii::$app->redis->incr($key)){
/*if (Video::updateAllCounters(['replay_num' => 1],['id'=>$video_id]) && Yii::$app->redis->incr($key)){
$ret['audience_num'] += 1;
}*/
if (Yii::$app->redis->incr($key)){
$replay_num += 1;
}
$ret['audience_num'] += $replay_num;
$ret['replay_num'] = $replay_num;
$this->renderJson(Yii::$app->params['success_code'],'',$ret);
}else
... ...
<?php
namespace soa\controllers\v1;
use Yii;
use soa\controllers\BaseController;
use common\models\UserRedbag;
use common\models\RoomRedbag;
use common\models\RedbagType;
/**
* Site controller
*/
class RedbagController extends BaseController
{
/**
* 用户领取一个红包
* @return type
*/
public function actionAdd()
{
$user_id = $this->requests('user_id');
$room_id = $this->requests('room_id');
$coupon_id = $this->requests('coupon_id');
if (!$user_id || !$room_id || !$coupon_id){
$this->renderJson(Yii::$app->params['failed_code'],'缺少id');
}
$data = [
'user_id'=>$user_id,
'room_id'=>$room_id,
'coupon_id'=>$coupon_id,
];
$model = new UserRedbag;
if ($model->load($data,'') && $model->save()){
$this->renderJson(Yii::$app->params['success_code'],'添加成功');
}else{
$this->renderJson(Yii::$app->params['failed_code'],'添加失败');
}
}
/**
* 用户领取的红包列表
* @return type
*/
public function actionList()
{
$user_id = $this->requests('user_id');
$room_id = $this->requests('room_id');
if (!$user_id || !$room_id){
$this->renderJson(Yii::$app->params['failed_code'],'缺少id');
}
$key = __CLASS__.__FUNCTION__.'user_id'.$user_id.'room_id'.$room_id;
if (!$ret = $this->cache->get($key)){
$ret = UserRedbag::find()
->where(['user_id'=>$user_id,'room_id'=>$room_id])
->orderBy(['create_time'=>SORT_DESC])
->select('coupon_id')->asArray()->column();
$dependency = new \yii\caching\DbDependency(['sql' => Yii::$app->db
->createCommand('SELECT MAX(update_time),count(*) FROM {{%user_redbag}} WHERE user_id=:user_id AND room_id=:room_id')
->bindValue(':user_id', $user_id)
->bindValue(':room_id', $room_id)
->getRawSql()]);
$this->cache->set($key, $ret, Yii::$app->params['defaultCacheExpire'], $dependency);
}
$this->renderJson(Yii::$app->params['success_code'],'',$ret);
}
/**
* 推流端发红包
* @author yaoxiaofeng 2016.10.26
*/
public function actionPushbaglist()
{
$room_id = $this->requests('room_id');
if (!$room_id){
$this->renderJson(Yii::$app->params['failed_code'],'缺少id');
}
$key = __CLASS__.__FUNCTION__.'room_id'.$room_id;
if (!$result = $this->cache->get($key)) {
//TODO 内部接口没加缓存
$model = RoomRedbag::find()->where(['room_id' => $room_id]);
$list = $model
->with(['type'])
->orderBy(['create_time' => SORT_DESC])
->indexBy('coupon_id')
->all();
//红包类型
$redBagTypeArray = RedbagType::getId2name();
$couponId = [];
$couponId_by_type = [];
if ($list) {
foreach ($list as $model) {
$couponId[] = $model->coupon_id;
//按类型分组,供页面发红包随机用
if (empty($couponId_by_type[$model->type_id])) {
$couponId_by_type[$model->type_id] = [];
}
if (!in_array($model->coupon_id, $couponId_by_type[$model->type_id])) {
$couponId_by_type[$model->type_id][] = $model->coupon_id;
}
}
foreach ($couponId_by_type as $typeId => $coups) {
$result[] = [
'type_id' => $typeId,
'type_name' => $redBagTypeArray[$typeId],
'coupon_ids' => $coups
];
}
}
$dependency = new \yii\caching\DbDependency(['sql' => Yii::$app->db
->createCommand('SELECT MAX(update_time),count(*) FROM {{%room_redbag}} WHERE room_id=:room_id')
->bindValue(':room_id', $room_id)
->getRawSql()]);
$this->cache->set($key, $result, Yii::$app->params['defaultCacheExpire'], $dependency);
}
$this->renderJson(Yii::$app->params['success_code'],'',$result);
}
}
... ...
... ... @@ -6,7 +6,9 @@ use soa\controllers\BaseController;
use common\models\RoomNums;
use common\models\Video;
use common\models\Room;
use common\models\RoomInfo;
use common\models\RoomsNumsReport;
/**
* Room controller
*/
... ... @@ -144,11 +146,6 @@ class RoomController extends BaseController
$this->renderJson($retArr['code'], $retArr['messsage']);
}
public function actionGetlivingroomid()
{
return [10000, 10001];
}
/**
* 获取禁言用户列表
*/
... ... @@ -362,6 +359,45 @@ class RoomController extends BaseController
}
/**
* 推流端隔一分钟上报,证明存活
*/
public function actionKeeplive()
{
$requests = $this->requests();
$room_id = $requests['room_id'];
do{
$retArr = [];
if(!$room_id){
$retArr = [
'code' => Yii::$app->params['failed_code'],
'messsage' => '缺少room_id'
];
break;
}
//更新房间的最后一次访问时间(活跃时间)
$res = Yii::$app->db->createCommand('
INSERT INTO {{%room_info}} (`room_id`,`last_time`)
VALUES (:room_id,:last_time)
ON DUPLICATE KEY UPDATE `last_time`=:last_time')
->bindValue(':room_id', $room_id)
->bindValue(':last_time', time())
->execute();
if($res){
$retArr = [
'code' => Yii::$app->params['success_code'],
'messsage' => '更新成功'
];
}else{
$retArr = [
'code' => Yii::$app->params['failed_code'],
'messsage' => '更新失败'
];
}
}while(false);
$this->renderJson($retArr['code'], $retArr['messsage']);
}
/**
* 获取评论表名称
* @param $room_id
* @return string
... ...
<?php
defined('YII_DEBUG') or define('YII_DEBUG', false);
defined('YII_ENV') or define('YII_ENV', 'prod');
//error_reporting(E_ALL ^ E_NOTICE);
require(__DIR__ . '/../../vendor/autoload.php');
require(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php');
... ...
... ... @@ -10,6 +10,7 @@
defined('YII_DEBUG') or define('YII_DEBUG', false);
defined('YII_ENV') or define('YII_ENV', 'prod');
//error_reporting(E_ALL ^ E_NOTICE);
require(__DIR__ . '/vendor/autoload.php');
require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php');
... ...