Authored by xiaofeng.yao@yoho.cn

合并develop->test

... ... @@ -15,7 +15,7 @@ class AjaxController extends BaseController
*/
public function actionPushgoodslog()
{
$log = Yii::$app->redisIm->rpop(Parser::load('room/product/pushlog'));
$log = Yii::$app->redisIm->rpop(Yii::$app->params['cache_prefix'].'push_goods_log');
$this->renderJson(Yii::$app->params['success_code'],'',(string)$log);
}
}
... ...
... ... @@ -78,13 +78,17 @@ class SiteController extends BaseController
}
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
} else {
return $this->render('login', [
'model' => $model,
]);
if (Yii::$app->request->isPost){
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
} else {
$this->setParam('logon', false);
}
}
return $this->render('login', [
'model' => $model,
]);
}
/**
... ...
... ... @@ -70,7 +70,7 @@ class SystemController extends BaseController
public function actionVest(){
$cache_prefix = Yii::$app->params['cache_prefix'];
$imVestNums = Yii::$app->redisIm->llen($cache_prefix.':vest_users');
$imVestNums = Yii::$app->redisIm->llen($cache_prefix.'vest_users');
if(Yii::$app->request->isAjax){
set_time_limit(0);
$offset = Yii::$app->request->get('offset');
... ... @@ -86,7 +86,7 @@ class SystemController extends BaseController
'name'=>$row['name'],
'avatar'=>$row['avatar'],
];
$i = Yii::$app->redisIm->lpush($cache_prefix.':vest_users',json_encode($data));
$i = Yii::$app->redisIm->lpush($cache_prefix.'vest_users',json_encode($data));
unset($data);
}
$data = [
... ...
... ... @@ -3,6 +3,7 @@ namespace backend\controllers;
use Yii;
use common\lib\QcloudApi\Client as QcloudApiClient;
use common\components\cachekey\Parser;
/**
* Site controller
... ... @@ -12,12 +13,8 @@ class TestController extends BaseController
public function actionIndex()
{
$r = QcloudApiClient::self()->CreateRecord('16093425727657160449');
echo '<pre>';
var_export($r);
if (!$r){
var_export(QcloudApiClient::self()->error());
}
$key = Parser::load('room/list/best')->key(1);
var_dump($key);
exit;
}
}
... ...
... ... @@ -45,6 +45,7 @@ class Room extends \yii\db\ActiveRecord
[['pic', 'background_pic'], 'string', 'max' => 255],
[['room_id'], 'unique'],
[['secret'], 'unique'],
[['secret'], 'integer', 'integerOnly'=>true],
[['pic', 'background_pic'], 'required'],
];
}
... ...
<header>
<div class="headerwrapper">
<div class="header-left">
<a href="javascript:;" class="logo">
<a href="/" class="logo">
<?php if (YII_ENV == 'prod'):?>
<img src="/images/logo.png" alt="" />
<?php else:?>
<strong>开发/测试环境</strong>
<?php endif;?>
</a>
<div class="pull-right">
<a href="" class="menu-collapse">
... ...
... ... @@ -58,8 +58,8 @@ $this->title = $this->params['main_title'].'-'.$this->params['sub_title'];
<td><?=Yii::$app->params['config']['vest'][$model->vest]?></td>
<td><?=Yii::$app->params['config']['room_living'][$model->living]?></td>
<td>
真实:<?=$model->roomNums->online_num ? :0?>,
马甲:<?=$model->roomNums->vest_online_num ? :0?>
真实:<?=@$model->roomNums->online_num ? :0?>,
马甲:<?=@$model->roomNums->vest_online_num ? :0?>
</td>
<td>
... ...
... ... @@ -15,8 +15,10 @@ $this->title = 'Login';
<img src="/images/logo-primary.png" alt="Chain Logo" >
</div>
<br />
<!--<h4 class="text-center mb5">Already a Member?</h4>-->
<p class="text-center">登录到你的账户</p>
<h4 class="text-center mb5">登录到你的账户</h4>
<?php if (isset($logon) && !$logon):?>
<p class="text-center" style="color:red">登录失败</p>
<?php endif;?>
<div class="mb30"></div>
... ...
... ... @@ -111,6 +111,7 @@ a:focus {
display: inline-block;
margin-top: 5px;
float: left;
color:white;
}
.headerwrapper .header-left .menu-collapse {
... ...
... ... @@ -12,8 +12,6 @@ class Parser{
//路径
private $path;
//待替换参数
private $params;
/**
* 缓存句柄
... ... @@ -37,30 +35,34 @@ class Parser{
static $self;
if (empty($self)){
$self = new self;
//初始化缓存句柄
if (function_exists('apcu_store')){
$self->cache = Yii::createObject([
'class'=>'yii\caching\ApcCache',
'useApcu'=>true
]);
}elseif (function_exists('apc_store')){
$self->cache = Yii::createObject('yii\caching\ApcCache');
}elseif (function_exists('shm_attach')){
$self->cache = Yii::createObject('common\components\caching\ShmCache');
}else{
$self->cache = Yii::createObject('yii\caching\ArrayCache');
}
}
return $self;
}
public function __construct() {
$this->cache = Yii::createObject('yii\caching\ArrayCache');
}
/**
* 载入路径
* @param type $path
* @param type $params
* @return type
*/
static function load($path,$params = []){
static function load($path){
$self = self::self();
$self->path = $path;
if (func_num_args() > 2){
$params = func_get_args();
array_shift($params);
}
$self->params = $params;
return $self;
}
... ... @@ -68,9 +70,15 @@ class Parser{
* 获取最终键名
* @return type
*/
public function key(){
public function key($params = []){
if (func_num_args() > 1){
$params = func_get_args();
}
$path = $this->path;
$params = $this->params;
if (is_array($params)){
ksort($params);
}
$main_key = 'get'.$path.serialize($params);
if ($realkey = $this->cache->get($main_key)){
... ... @@ -93,6 +101,10 @@ class Parser{
$this->cache->set($key,$cachekey,$this->expire);
}
if (count((array)$params) != preg_match_all('/{[^}]+}/',$cachekey)){
throw new \Exception('Number of arguments not match');
}
if (is_array($params)){
if (!is_list($params)){
$dict = $list = [];
... ... @@ -125,7 +137,7 @@ class Parser{
* @return type
*/
private function addPrefix($key){
return strtr(Yii::$app->params['cache_prefix'].':'.$key,array('::'=>':'));
return rtrim(Yii::$app->params['cache_prefix'],':').':'.ltrim($key,':');
}
/**
... ...
<?php
namespace common\components\caching;
use yii\caching\Cache;
use yii\base\InvalidConfigException;
class ShmCache extends Cache
{
//memory size bytes,default 10MB
public $memSize = 10485760;
protected $shm;
/**
* Initializes this application component.
* It checks if extension required is loaded.
*/
public function init()
{
parent::init();
if (!extension_loaded('sysvshm')) {
throw new InvalidConfigException("ShmCache requires PHP sysvshm extension to be loaded.");
}
$key = ftok(__FILE__, 'p');
$this->shm = shm_attach($key,10000);
}
public function exists($key)
{
$key = $this->buildKey($key);
return shm_has_var($this->shm,$key);
}
protected function getValue($key)
{
return @shm_get_var($this->shm,$key);
}
protected function getValues($keys)
{
$results = [];
foreach ($keys as $key) {
$results[$key] = @shm_get_var($this->shm,$key);
}
return $results;
}
protected function setValue($key, $value, $duration)
{
return shm_put_var($this->shm,$key,$value);
}
protected function addValue($key, $value, $duration)
{
return shm_has_var($this->shm,$key) ? false : shm_put_var($this->shm,$key,$value);
}
protected function deleteValue($key)
{
return @shm_remove_var($this->shm,$key);
}
protected function flushValues()
{
return shm_remove($this->shm);
}
public function buildKey($key)
{
return crc32(parent::buildKey($key));
}
}
... ...
... ... @@ -69,7 +69,7 @@ return [
/**
* 默认缓存前缀
*/
'cache_prefix'=>'YOHOLive',
'cache_prefix'=>'YOHOLive:',
//成功状态
'success_code'=>200,
//失败状态
... ...
... ... @@ -59,9 +59,9 @@ class RoomNums extends \yii\db\ActiveRecord
{
$cache_prefix = Yii::$app->params['cache_prefix'];
//清在线观看数
$audience_nums = Yii::$app->redisIm->get(sprintf($cache_prefix . ":audience_nums_room_%s", $room_id));
$audience_nums = Yii::$app->redisIm->get(sprintf($cache_prefix . "audience_nums_room_%s", $room_id));
//清点赞数
$like_nums = Yii::$app->redisIm->get(sprintf($cache_prefix . ":like_numbers_room_%s", $room_id));
$like_nums = Yii::$app->redisIm->get(sprintf($cache_prefix . "like_numbers_room_%s", $room_id));
return [
'audience_nums'=>$audience_nums ? :0,
... ...
... ... @@ -163,13 +163,13 @@ class Video extends \yii\db\ActiveRecord
$cache_prefix = Yii::$app->params['cache_prefix'];
//##主播app 向弹幕服务器发送开始命令时也清除,这里也清除是为了防止弹幕服务器连不上没有清掉
//清掉在线马甲数
Yii::$app->redisIm->del(sprintf($cache_prefix . ":vestnum_%s", $room_id));
Yii::$app->redisIm->del(sprintf($cache_prefix . "vestnum_%s", $room_id));
//清在线观看数
Yii::$app->redisIm->del(sprintf($cache_prefix . ":audience_nums_room_%s", $room_id));
Yii::$app->redisIm->del(sprintf($cache_prefix . "audience_nums_room_%s", $room_id));
//清点赞数
//Yii::$app->redisIm->del(sprintf($cache_prefix . ":like_numbers_room_%s", $room_id));
//Yii::$app->redisIm->del(sprintf($cache_prefix . "like_numbers_room_%s", $room_id));
//清直播状态
Yii::$app->redisIm->del(sprintf($cache_prefix . ":play_stat_room_%s", $room_id));
Yii::$app->redisIm->del(sprintf($cache_prefix . "play_stat_room_%s", $room_id));
/*------------清除弹幕相关redis--------------*/
$transaction->commit();
return true;
... ...
... ... @@ -37,18 +37,18 @@ class InitController extends Controller
echo '请输入用户名';
return 1;
}
// 修改一个已存在用户
if (!$model = Admin::findByUsername($username)){
echo '找不到该用户';
return 1;
}
$email = $this->prompt('Email:'); // 接收Email
$password = $this->prompt('Password:'); // 接收密码
if (!$email && !$password){
echo '没有任何修改';
return 0;
}
// 修改一个已存在用户
if (!$model = Admin::findByUsername($username)){
echo '找不到该用户';
return 1;
}
if ($email){
$model->email = $email;
}
... ...
... ... @@ -96,7 +96,7 @@ class SystemController extends BaseController
'avatar'=>$row[1],
];
$cache_prefix = Yii::$app->params['cache_prefix'];
$i = Yii::$app->redisIm->lpush($cache_prefix.':vest_users',json_encode($data));
$i = Yii::$app->redisIm->lpush($cache_prefix.'vest_users',json_encode($data));
echo $i."\n";
}
echo 'done';
... ...