Authored by wuxiao

Merge branch 'wuxiao' into feature/redmine13762

# Conflicts:
#	backend/views/live/room.php
... ... @@ -842,3 +842,97 @@
名称| 类型|说明|
:----------- | :-----------: | :-----------:
| data | list|有货商品ID(skn)列表 |
# **用户在当前房间领到优惠券关联接口**
----------
### **调用说明**
###### 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列表
\ No newline at end of file
... ...
... ... @@ -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
... ...
... ... @@ -8,6 +8,7 @@ return [
'room'=>array('直播间','live/room'),
'master'=>array('主播','live/master'),
'video'=>array('视频','live/video'),
'type'=>array('红包类型','redbag/type'),
)
),
'system'=>array(
... ...
... ... @@ -54,15 +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 ? :
(!is_array(@Yii::$app->params['menu'][$main_id][1]) ? '' :
(@Yii::$app->params['menu'][$main_id][1][$sub_id][0] ? : ''));
return parent::beforeAction($action);
}
... ... @@ -150,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);
}
... ...
<?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);
}
}
... ...
<?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;
}
}
... ...
<?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'], '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']);
}
}
... ...
... ... @@ -116,6 +116,7 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
<td><?=$model->living_sort?></td>
<td>
<p>
<span>
<?php if ($model->living == 1)://直播中?>
<button type="button" onclick="stopLiving(<?=$model->room_id?>)" class="btn btn-danger btn-metro">结束直播</button>
... ... @@ -126,10 +127,6 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
<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>
<span>
<?php if ($model->status == 0)://关闭状态?>
<a onclick="return confirm('启用直播间?')" href="/live/roomoperate/<?=$model->id?>?type=enable" class="btn btn-success btn-metro">启用直播</a>
... ... @@ -138,6 +135,15 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
<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="/redbag/list/<?=$model->room_id?>" class="btn btn-default btn-white">红包</a>
</p>
</td>
</tr>
<?php endforeach;?>
... ...
<?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][array_rand(couponId_by_type[type_id])];
i++;
if (i>5){
$('#runtime').html('');
i = 1;
}
callWebsocket(function(){
consoleLog('');
consoleLog('发起推送,优惠券ID: '+coupon_id);
cmd = {cmd:10011,room:room_id,skn: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
... ...
... ... @@ -7,6 +7,8 @@ use yii\helpers\ArrayHelper;
/**
* 有货接口
* @author wuxiao
*
* @文档地址 http://git.yoho.cn/yoho-documents/api-interfaces
*/
class Client{
... ... @@ -104,6 +106,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);
... ... @@ -176,6 +193,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 "{{%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',
]
];
}
}
... ...
<?php
namespace soa\controllers\v1;
use Yii;
use soa\controllers\BaseController;
use common\models\UserRedbag;
/**
* 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);
}
}
... ...