...
|
...
|
@@ -15,27 +15,15 @@ var room_id = <?=$room->room_id?>; |
|
|
var interval_handle;
|
|
|
var default_interval = 3;
|
|
|
/**
|
|
|
* 推送商品
|
|
|
* @param {type} product_id
|
|
|
* websocket推送指令
|
|
|
* @returns {undefined}
|
|
|
*/
|
|
|
function sendProduct(product_id){
|
|
|
if (!confirm('将推送该商品,确定?')){
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
i++;
|
|
|
if (i>5){
|
|
|
$('#runtime').html('');
|
|
|
i = 1;
|
|
|
}
|
|
|
consoleLog('');
|
|
|
|
|
|
function callWebsocket(callback){
|
|
|
if (!window.ws || window.ws.readyState === undefined || window.ws.readyState != 1) {
|
|
|
websocket('192.168.102.17',9501,'/',function(){
|
|
|
consoleLog('连接服务器');
|
|
|
|
|
|
_sendProduct(product_id);
|
|
|
callback();
|
|
|
},function(evt){
|
|
|
consoleLog('收到消息: '+evt.data);
|
|
|
data = JSON.parse(evt.data);
|
...
|
...
|
@@ -50,40 +38,85 @@ function sendProduct(product_id){ |
|
|
consoleLog('有错误出现');
|
|
|
});
|
|
|
}else{
|
|
|
_sendProduct(product_id);
|
|
|
callback();
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
|
* 推送商品列表刷新指令
|
|
|
* @param {type} product_id
|
|
|
* @returns {undefined}
|
|
|
*/
|
|
|
function refreshProduct(){
|
|
|
if (!confirm('将推送商品列表刷新指令,确定?')){
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
callWebsocket(function(){
|
|
|
consoleLog('');
|
|
|
consoleLog('发起推送商品列表刷新指令');
|
|
|
|
|
|
cmd = {cmd:18,room:room_id,msg:'',refresh:'Y'};
|
|
|
cmd['secret'] = makeSign(cmd);
|
|
|
delete(cmd['private_key']);
|
|
|
|
|
|
cmd = JSON.stringify(cmd);
|
|
|
consoleLog('发送消息: '+cmd);
|
|
|
ws.send(cmd);
|
|
|
getPushlog(default_interval);
|
|
|
});
|
|
|
}
|
|
|
function _sendProduct(product_id){
|
|
|
consoleLog('发起推送,商品ID: '+product_id);
|
|
|
/**
|
|
|
* 推送商品
|
|
|
* @param {type} product_id
|
|
|
* @returns {undefined}
|
|
|
*/
|
|
|
function sendProduct(product_id){
|
|
|
if (!confirm('将推送该商品,确定?')){
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
cmd = {cmd:10001,room:room_id,skn:product_id};
|
|
|
cmd['secret'] = makeSign(cmd);
|
|
|
delete(cmd['private_key']);
|
|
|
i++;
|
|
|
if (i>5){
|
|
|
$('#runtime').html('');
|
|
|
i = 1;
|
|
|
}
|
|
|
|
|
|
callWebsocket(function(){
|
|
|
consoleLog('');
|
|
|
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);
|
|
|
getPushlog(default_interval);
|
|
|
});
|
|
|
|
|
|
cmd = JSON.stringify(cmd);
|
|
|
consoleLog('发送消息: '+cmd);
|
|
|
ws.send(cmd);
|
|
|
//ws.send('{"cmd":"10001","skn":"123","room":"3","secret":"72c1f9eb60b761d3078294e3e8318fc0"}');
|
|
|
//ws.close();
|
|
|
getPushlog(default_interval);
|
|
|
}
|
|
|
/**
|
|
|
*
|
|
|
* 监听推送记录
|
|
|
* @param {type} package
|
|
|
* @returns {unresolved}
|
|
|
*/
|
|
|
function getPushlog(interval){
|
|
|
clearInterval(interval_handle);
|
|
|
interval_handle = setInterval(function(){
|
|
|
$.get('/ajax/pushgoodslog','',function(json){
|
|
|
console.log(json);
|
|
|
if (json.data){
|
|
|
consoleLog('监听到推送记录: '+json.data);
|
|
|
}
|
|
|
},'json');
|
|
|
},interval*1000);
|
|
|
$('#pushlog').text('推送记录监听中...');
|
|
|
|
|
|
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+')');
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
|
* 页面打印发送记录
|
...
|
...
|
@@ -170,6 +203,7 @@ $this->registerJs($this->blocks['javascript'],View::POS_END) |
|
|
<div class="form-group">
|
|
|
<label>
|
|
|
<button type="button" onclick="getPushlog(default_interval)" id="pushlog" class="btn btn-primary">开始监听推送记录</button>
|
|
|
<button type="button" onclick="refreshProduct()" class="btn btn-primary">推送商品列表刷新指令</button>
|
|
|
</label>
|
|
|
</div>
|
|
|
|
...
|
...
|
|