list.php
4.49 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
<?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->registerJsFile('/js/php.js',array('postion'=>View::POS_END));
?>
<script type="text/javascript">
<?php $this->beginBlock('javascript');?>
var i = 0;
var room_id = <?=$room->room_id?>;
/**
* 推送商品
* @param {type} product_id
* @returns {undefined}
*/
function sendProduct(product_id){
if (!confirm('将推送该商品,确定?')){
return;
}
i++;
if (i>5){
$('#runtime').html('');
i = 1;
}
consoleLog('');
if (!window.ws || window.ws.readyState === undefined || window.ws.readyState != 1) {
websocket('192.168.102.17',9501,'/',function(){
consoleLog('连接服务器');
_sendProduct(product_id);
},function(evt){
consoleLog('收到消息: '+evt.data);
},function(){
consoleLog('连接已关闭');
},function(){
consoleLog('有错误出现');
});
}else{
_sendProduct(product_id);
}
}
function _sendProduct(product_id){
consoleLog('发送推送,商品ID: '+product_id);
cmd = {cmd:10001,room:room_id,skn:product_id};
cmd['secret'] = makeSign(cmd);
delete(cmd['private_key']);
cmd = JSON.stringify(cmd);
consoleLog('发送消息: '+cmd);
ws.send(cmd);
//ws.send('{"cmd":"10001","skn":"123","room":"3","secret":"72c1f9eb60b761d3078294e3e8318fc0"}');
}
/**
* 页面打印发送记录
* @param {type} msg
* @returns {undefined}
*/
function consoleLog(msg){
$('#runtime').append(' '+msg+'<br />');
}
/**
* 密钥生成
* @param {type} package
* @returns {unresolved}
*/
function makeSign(package){
package['private_key'] = 'a85bb0674e08986c6b115d5e3a4884fa';
package = ksort(package);
packageList = [];
for (key in package){
packageList.push(trim(key + '=' + package[key]));
}
return strtolower(md5(implode('&', packageList)));
}
<?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="/product/add/<?=$room->room_id?>" class="btn btn-primary">+ 添加商品</a>
</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>
</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->product_id?></td>
<th><?=$model->product_name?></th>
<th><?=$model->sales_price?></th>
<td><?=$model->sort?></td>
<td>
<a href="/product/edit/<?=$model->id?>" class="btn btn-default btn-white">编辑</a>
<a onclick="return confirm('删除该商品?')" href="/product/operate/<?=$model->id?>?type=del" class="btn btn-danger btn-metro">删除</a>
<a onclick="sendProduct(<?=$model->product_id?>)" href="javascript:;" 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">
<div class="col-sm-6" id="runtime">
</div>
</div><!-- form-group -->