list.php
5.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?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?> 直播标题:<?=$room->title?> 直播状态:<?=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 -->