Authored by wuxiao

房间红包推送

... ... @@ -47,8 +47,17 @@ class RedbagController extends BaseController
* 获取有货商品信息
*/
$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);
... ... @@ -68,12 +77,24 @@ class RedbagController extends BaseController
}
}
}
//页面随机红包池过滤掉无库存的
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,
]);
}
... ...
... ... @@ -5,11 +5,23 @@ 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;
... ... @@ -20,11 +32,21 @@ var default_interval = 3;
* @param {type} product_id
* @returns {undefined}
*/
function sendRedbag(coupon_id){
if (!confirm('将推送该红包,确定?')){
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('');
... ... @@ -83,7 +105,10 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
<div class="form-group">
<label>
<a href="/redbag/add/<?=$room->room_id?>" class="btn btn-primary">+ 添加红包</a>
<button type="button" onclick="sendRedbag()" class="btn btn-primary" style="margin-left:200px">发红包</button>
<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>
... ... @@ -94,9 +119,9 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
<thead>
<tr style="white-space:nowrap">
<th><input type="checkbox" onclick="checkall(this)">选择</th>
<th>优惠券ID</th>
<th>红包ID</th>
<th>红包类型</th>
<th>优惠券名称</th>
<th>类型</th>
<th>优惠券剩余库存</th>
<th>优惠券生效时间</th>
<th>优惠券失效时间</th>
... ... @@ -108,9 +133,8 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
<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>
<th><?=$model->coupon_name?></th>
<th><?=$model->type_id?></th>
<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>
... ...