Authored by xiaofeng.yao@yoho.cn

Merge branch 'master' into feature/redmine13762

Conflicts:
	README.md
	backend/views/live/room.php
	soa/controllers/v1/LivingController.php
... ... @@ -843,6 +843,60 @@
:----------- | :-----------: | :-----------:
| data | list|有货商品ID(skn)列表 |
## **房间优惠码**
----------
### **调用说明**
###### url&方式
名称| 说明
:----------- | :-----------:
| url | http://api.live.yoho.cn/v1/coupon/detail |
| method | get |
###### 参数说明
参数名称| 类型| 长度| 必须| 说明
:-- | :-- | :-- | :-- | :--:
| room_id | int|不限|是|直播房间ID|
###### 调用示例
http://api.live.yoho.cn/v1/coupon/detail
GET room_id=1023
### **结果返回**
###### 正确返回
{
"code": 200,
"message": "",
"data": {
"code": "YOHO5201",
"banner_txt": [
"满500减100",
"结算时输入#优惠码#"
],
"help_title": "帮助标题",
"help_txt": [
"1、帮助内容",
"2、帮助内容",
"3、帮助内容"
]
},
"timestamp": 1476690220,
"md5": "11b76069e20852fa002ccadd06d0b6ca"
}
###### 返回说明
名称| 类型|说明|
:----------- | :-----------: | :-----------:
| code | string|优惠码 |
| banner_txt | list|优惠码展示的banner(数组序号对应行数)|
| help_title | string|帮助标题 |
| help_txt | list|帮助内容 (数组序号对应行数)|
# **用户在当前房间领到优惠券关联接口**
----------
... ... @@ -898,7 +952,6 @@
----------
### **调用说明**
###### url&方式
名称| 说明
... ... @@ -917,12 +970,10 @@
http://api.live.yoho.cn/v1/redbag/list
GET user_id=1213&room_id=321
### **结果返回**
###### 正确返回
{
"code": 200,
"message": "",
... ... @@ -937,6 +988,7 @@
###### 返回说明
优惠券ID列表
# **推流端发红包接口**
----------
... ... @@ -994,4 +1046,5 @@
:----------- | :-----------: | :-----------:
| type_id | int|红包类型id |
| type_name | string|红包类型名称 |
| coupon_ids | list|优惠券列表(随机取一个回填到命令里发送) |
\ No newline at end of file
| coupon_ids | list|优惠券列表(随机取一个回填到命令里发送) |
... ...
... ... @@ -4,6 +4,7 @@ namespace backend\controllers;
use Yii;
use app\models\Master;
use app\models\Room;
use app\models\RoomCoupon;
use backend\components\Pagination;
use backend\widgets\Filter;
use backend\widgets\YHGImage\Common\Images as CommonImages;
... ... @@ -447,4 +448,41 @@ class LiveController extends BaseController
return $this->redirect($this->_refer);
}
/**
* 优惠码
* @return type
*/
public function actionCouponedit()
{
if ($posts = Yii::$app->request->Post()) {
//保存
if (!$model = RoomCoupon::findOne(['room_id' => $posts['room_id']])) {
$model = new RoomCoupon();
$model->room_id = $posts['room_id'];
}
$model->code = $posts['code'];
$model->banner_txt = $this->_beautifyText($posts['banner_txt']);
$model->help_title = trim($posts['help_title']);
$model->help_txt = $this->_beautifyText($posts['help_txt']);
// var_dump($this->_beautifyText($model->help_txt));exit;
if ($model->save()) {
Yii::$app->session->setFlash('success', '保存成功。');
} else {
Yii::$app->session->setFlash('error', '保存失败。');
}
return $this->refresh();
} else {
//编辑页面
$room_id = Yii::$app->getRequest()->getQueryParam('id',0);
$coupon = RoomCoupon::findOne(['room_id' => $room_id]);
return $this->render('couponedit', ['coupon' => $coupon, 'room_id'=>$room_id]);
}
}
private function _beautifyText($text){
$search = ["\r\n","\r","\n"];
$replace = "<br/>";
return str_replace($search,$replace,trim($text));
}
}
... ...
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "{{%room_coupon}}".
*
* @property integer $room_id
* @property string $code
* @property string $banner_txt
* @property string $help_title
* @property string $help_txt
*/
class RoomCoupon extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%room_coupon}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['room_id'], 'required'],
[['room_id', 'create_time', 'update_time'], 'integer'],
[['banner_txt', 'help_txt'], 'string'],
[['code'], 'string', 'max' => 50],
[['help_title'], 'string', 'max' => 100],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'room_id' => 'Room ID',
'code' => 'Code',
'banner_txt' => 'Banner Txt',
'help_title' => 'Help Title',
'help_txt' => 'Help Txt',
'create_time' => 'Create Time',
'update_time' => 'Update Time',
];
}
public function behaviors()
{
return [
[
'class' => \yii\behaviors\TimestampBehavior::className(),
'createdAtAttribute' => 'create_time',
'updatedAtAttribute' => 'update_time',
]
];
}
}
... ...
<?php
use yii\web\View;
use yii\helpers\Html;
$this->title = $this->params['main_title'].'-'.$this->params['sub_title'];
?>
<?php echo $this->render('@app/views/layouts/websocket');?>
<script type="text/javascript">
<?php $this->beginBlock('javascript');?>
var i = 0;
var room_id = <?=$room_id?>;
var interval_handle;
var default_interval = 3;
/**
* 推送优惠券刷新指令
* @returns {undefined}
*/
function refreshCoupon(){
if (!confirm('将推送商品列表刷新指令,确定?')){
return;
}
callWebsocket(function(){
consoleLog('');
consoleLog('发起推送商品列表刷新指令');
cmd = {cmd:10003,room:room_id,msg:'',refresh:'Y'};
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+')');
}
}
//预览优惠券元素
function preview() {
var code = $("input[name=code]").val();
var banner_txt = $("textarea[name=banner_txt]").val();
var find = /#code#/g;
var replace = "<b class='coupon-code'>["+code+"]</b>";
banner_txt = banner_txt.replace(find,replace);
var help_title = $("input[name=help_title]").val();
help_txt = $("textarea[name=help_txt]").val();
help_title = "<h4>"+help_title+"</h4>";
$("#coupon_preview").html(banner_txt+help_title+help_txt);
}
<?php
$this->endBlock();
$this->registerJs($this->blocks['javascript'],View::POS_END)
?>
</script>
<style>
.coupon-code {color: #fcc800}
</style>
<div class="row">
<div class="col-md-6">
<form id="form" method="POST" action="">
<input type="hidden" name="room_id" value="<?=$room_id?>">
<div class="panel panel-default">
<div class="panel-body">
<div class="row">
<div class="form-group">
<label class="col-sm-3 control-label">优惠码(金色字体): </label>
<div class="col-sm-5">
<input type="text" name="code" class="form-control" value="<?=$coupon->code?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">固定显示内容: </label>
<div class="col-sm-9">
<textarea name="banner_txt" class="form-control" rows="10" cols="50"><?=$coupon->banner_txt?></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">帮助弹框-标题: </label>
<div class="col-sm-9">
<input type="text" name="help_title" class="form-control" value="<?=$coupon->help_title?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">帮助弹框-内容: </label>
<div class="col-sm-9">
<textarea name="help_txt" class="form-control" rows="10" cols="50"><?=$coupon->help_txt?></textarea>
</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">保存</button>
<a href="<?=$_refer?>" class="btn btn-dark mr5">取消</a>
<a class="btn btn-dark" onclick="preview()">预览</a>
</div>
</div>
</div><!-- panel-footer -->
</div><!-- panel -->
</form>
</div>
<div class="col-md-6">
<p>Notice:优惠码替换占位符用<code>#code#</code>,换行符用<code>&lt;br/&gt;</code></p>
<div class="panel panel-default">
<div class="panel-heading">
<h4>预览</h4>
</div>
<div class="panel-body">
<div id="coupon_preview">
</div>
</div>
</div>
</div>
</div>
<div class="form-group">
<label>
<button type="button" onclick="getPushlog(default_interval)" id="pushlog" class="btn btn-primary">开始监听推送记录</button>
</label>
<label>
<button type="button" onclick="refreshCoupon()" class="btn btn-primary">推送优惠码刷新指令</button>
</label>
</div>
<div class="form-group">
<div class="col-sm-6" id="wsRuntime">
</div>
</div>
... ...
... ... @@ -136,12 +136,10 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
<?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>
... ...
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "{{%room_coupon}}".
*
* @property integer $room_id
* @property string $code
* @property string $banner_txt
* @property string $help_title
* @property string $help_txt
*/
class RoomCoupon extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%room_coupon}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['room_id'], 'required'],
[['room_id', 'create_time', 'update_time'], 'integer'],
[['banner_txt', 'help_txt'], 'string'],
[['code'], 'string', 'max' => 50],
[['help_title'], 'string', 'max' => 100],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'room_id' => 'Room ID',
'code' => 'Code',
'banner_txt' => 'Banner Txt',
'help_title' => 'Help Title',
'help_txt' => 'Help Txt',
'create_time' => 'Create Time',
'update_time' => 'Update Time',
];
}
}
... ...
<?php
namespace soa\controllers\v1;
use Yii;
use soa\controllers\BaseController;
use common\models\RoomCoupon;
/**
* Site controller
*/
class CouponController extends BaseController
{
/**
* 房间优惠券
* @return type
*/
public function actionDetail()
{
if (!$room_id = $this->requests('room_id')) {
$this->renderJson(Yii::$app->params['failed_code'], '缺少房间号');
}
$key = __CLASS__ . __FUNCTION__ . 'room_id' . $room_id;
if (!$ret = $this->cache->get($key)) {
if (!$model = RoomCoupon::findOne(['room_id' => $room_id])) {
$this->renderJson(Yii::$app->params['failed_code'], '找不到该房间优惠码信息');
}
$ret = [
'code' => $model->code,
'banner_txt' => array_filter( explode('<br/>', $model->banner_txt) ),
'help_title' => $model->help_title,
'help_txt' => array_filter( explode('<br/>', $model->help_txt) ),
];
$dependency = new \yii\caching\DbDependency(['sql' => Yii::$app->db
->createCommand('SELECT MAX(update_time) FROM {{%room_coupon}} WHERE room_id=:room_id limit 1')
->bindValue(':room_id', $room_id)
->getRawSql()]);
$this->cache->set($key, $ret, Yii::$app->params['defaultCacheExpire'], $dependency);
}
$this->renderJson(Yii::$app->params['success_code'], '', $ret);
}
}
... ...