巧妙的新訂單提醒功能
阿新 • • 發佈:2018-05-31
sta 不能 auto function 手機 tel avi 是否 true
人不能時刻盯著屏幕,需要提醒。
或者語音提醒,或者短信提醒。短信提醒成本高,二是手機馬上被塞滿。
通過JS定時刷新,調取接口,巧妙的解決了這個問題。
定時去數據庫查詢,最近一天,是否有已支付,未處理的訂單,如果有的話,播放音頻文件。
音頻文件可以去網上找。叮咚,你有新訂單,請及時處理。
巧妙的運用JS,生成靈活的音頻模塊,並播放,有點意思。
var func = function (){ $.ajax({ type:'POST', url:'/admin.php/Order/get_new_order', dataType:'json', success:function(data){ console.log(JSON.stringify(data)); if(data.errno == 0) { playSound(); } } }); } var playSound = function () { var borswer = window.navigator.userAgent.toLowerCase(); if ( borswer.indexOf( "ie" ) >= 0 ) { //IE內核瀏覽器 var strEmbed = '<embed name="embedPlay" src="/admin/image/voice.mp3" autostart="true" hidden="true" loop="false"></embed>'; if ( $( "body" ).find( "embed" ).length <= 0 ) $( "body" ).append( strEmbed ); var embed = document.embedPlay; //瀏覽器不支持 audion,則使用 embed 播放 embed.volume = 100; //embed.play();這個不需要 } else { //非IE內核瀏覽器 var strAudio = "<audio id='audioPlay' src='/admin/image/voice.mp3' hidden='true'>"; if($("#audioPlay").length<=0){ $( "body" ).append( strAudio ); } var audio = document.getElementById( "audioPlay" ); //瀏覽器支持 audio audio.play(); } } //主動調用 setInterval("func()", 30000);
巧妙的新訂單提醒功能