var getData = function () { if(typeof moment !== 'function' || moment === null){ var scripts = [ '/templates/linkmarket/js/moment/moment-with-locales.min.js', '/templates/linkmarket/js/moment/moment-timezone-with-data.min.js', ]; var loadJs = new jsLoader(scripts); loadJs.loadScripts(function (){ parseDataLottery(); }) }else{ parseDataLottery(); } }; var parseDataLottery = function (){ var realTimeUrl = checkOffsetTime(); var lottery_id = $('#lottery_id').val(); if (realTimeUrl !== '') { var activeTabs = []; $(document).find('ul.tabs > li.active').each(function (e) { var id = $(this).attr('data-id'); if (id !== undefined && id !== null) { activeTabs.push(id); } }); $.ajax({ url: realTimeUrl, type: "get", dataType: "html", timeout: 3000, success: function (response) { // Render if (lottery_id === undefined || lottery_id === null) { var data = JSON.parse(response); lottery_id = data['lotteryInfo']['id']; var html = ''; html += '
'; html += '
'; html += renderLottery(data, lottery_id); html += renderLotteryMessage(data); html += renderLotteryByNumber(data); html += '
'; html += '
'; var location = 0; if (data['lotteryInfo']['id'] == 1) { location = 1; } if (data['lotteryInfo']['id'] == 6) { location = 2; } if (data['lotteryInfo']['id'] == 5) { location = 3; } if (location !== 0) { $('#result_' + location).html($(html).find('#result_' + location).html()); $('#message_' + location).html($(html).find('#message_' + location).html()); $('#detail_' + location).html($(html).find('#detail_' + location).html()); } if ($('#realtime-notification').length === 0) { var notification = '
' + data['message'] + '
'; $('.block-results').prepend(notification); } else { $('#realtime-notification').html(data['message']); } } else if (lottery_id == 1 || lottery_id == 6 || lottery_id == 5) { var data = JSON.parse(response); var html = ''; html += '
'; html += '
'; html += renderLottery(data, lottery_id); html += renderLotteryMessage(data); html += renderLotteryByNumber(data); html += '
'; html += '
'; if ($('#realtime-lottery').length === 0) { $('.block-results').prepend($(html).find('#realtime-lottery')); $(html).find('ul.tabs > li.active').each(function (e) { var id = $(this).attr('data-id'); if (id !== undefined && id !== null) { activeTabs.push(id); } }); } else { var location = 0; if (data['lotteryInfo']['id'] == 1) { location = 1; } if (data['lotteryInfo']['id'] == 6) { location = 2; } if (data['lotteryInfo']['id'] == 5) { location = 3; } $('#result_' + location).html($(html).find('#result_' + location).html()); $('#message_' + location).html($(html).find('#message_' + location).html()); $('#detail_' + location).html($(html).find('#detail_' + location).html()); } if ($('#realtime-notification').length === 0) { var notification = '
' + data['message'] + '
'; $('.block-results').prepend(notification); } else { $('#realtime-notification').html(data['message']); } } else { $('#realtime-update').html(response); } // Check tab $(document).find('ul.tabs > li').each(function (e) { $(this).removeClass('active'); }); $(document).find('div.tabs-contents > div').each(function (e) { $(this).removeClass('active'); }); for (var i = 0; i < activeTabs.length; i++) { $(document).find('ul.tabs > li[data-id=' + activeTabs[i] + ']').trigger('click'); } }, error: function (jqXHR, textStatus, errorThrown) { }, complete: function () { } }); } } var renderLottery = function (data, lotteryID) { var id = data['id']; var location_id = data['lotteryInfo']['location']; var date = moment(data['currentDate'], "YYYY-MM-DD"); var html = ''; html += ''; html += ''; html += ''; if (lotteryID == 5 || lotteryID == 6) { html += ''; html += ''; html += ''; html += ''; for (var prize_id = Object.keys(data['prizes']).length; prize_id >= 1; prize_id--) { var prize = data['prizes'][prize_id]; if (prize['quantity_of_number'][location_id] > 0) { html += ''; html += ''; html += ''; html += ''; } } } else { for (var prize_id in data['prizes']) { var prize = data['prizes'][prize_id]; if (prize['quantity_of_number'][location_id] > 0) { if (prize['quantity_of_number'][id] != 7) { html += ''; html += ''; html += ''; html += ''; } else { html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; } } } } html += ''; html += '
'; html += '

Xổ số ' + data['lotteryInfo']['name'] + ' ' + date.lang('vi').format('dddd') + ' ' + date.format('DD-MM-YYYY') + '

'; html += '
Giải'; html += '
'; for (var detailID in data['detailLottery']) { html += '' + data['detailLottery'][detailID]['name'] + ''; } html += '
'; html += '
' + prize['name'] + ''; html += '
' for (var i = 0; i < prize['quantity_of_number'][location_id]; i++) { for (var detailID in data['detailLottery']) { var number = ''; if (data['numbers'][detailID] !== undefined && data['numbers'][detailID][prize_id] !== undefined && data['numbers'][detailID][prize_id][i] !== undefined) { number = data['numbers'][detailID][prize_id][i]; } if (number != '') { html += '' + number + ''; } else { html += 'Chờ kết quả'; } } } html += '
'; html += '
' + prize['name'] + ''; html += '
' for (var i = 0; i < prize['quantity_of_number'][location_id]; i++) { var number = ''; if (data['numbers'][lotteryID] !== undefined && data['numbers'][lotteryID][prize_id] !== undefined && data['numbers'][lotteryID][prize_id][i] !== undefined) { number = data['numbers'][lotteryID][prize_id][i]; } if (number != '') { html += '' + number + ''; } else { html += 'Chờ kết quả'; } } html += '
'; html += '
' + prize['name'] + ''; html += '
' for (var i = 0; i < 4; i++) { var number = ''; if (data['numbers'][lotteryID] !== undefined && data['numbers'][lotteryID][prize_id] !== undefined && data['numbers'][lotteryID][prize_id][i] !== undefined) { number = data['numbers'][lotteryID][prize_id][i]; } if (number != '') { html += '' + number + ''; } else { html += 'Chờ kết quả'; } } html += '
'; html += '
' + prize['name'] + ''; html += '
' for (var i = 4; i < 7; i++) { var number = ''; if (data['numbers'][lotteryID] !== undefined && data['numbers'][lotteryID][prize_id] !== undefined && data['numbers'][lotteryID][prize_id][i] !== undefined) { number = data['numbers'][lotteryID][prize_id][i]; } if (number != '') { html += '' + number + ''; } else { html += 'Chờ kết quả'; } } html += '
'; html += '
'; html += '
'; html += '
'; html += ''; html += ''; html += ''; html += '
'; html += ''; html += '
'; return html; } var renderLotteryMessage = function (data) { var location_id = data['lotteryInfo']['location']; var html = ''; html += '
'; if (data['detailLottery'] !== undefined && data['detailLottery'] !== null) { for (var key in data['detailLottery']) { html += '
'; html += 'Soạn: ' html += '' + data['detailLottery'][key]['onlineMessage'] + ''; html += ' gửi '; html += '8210'; html += ' nhận ngay kết quả '; html += '' + data['detailLottery'][key]['name'] + ''; html += ' sớm nhất!'; html += '
'; } } html += '
'; return html; } var renderLotteryByNumber = function (data) { var date = moment(data['currentDate'], "YYYY-MM-DD"); var location_id = data['lotteryInfo']['location']; var html = ''; html += '
'; // Render tab var i = 0; html += ''; // End render tab // Render tab content html += '
'; var i = 0; if (data['detailLottery'] !== undefined && data['detailLottery'] !== null) { for (var key in data['detailLottery']) { var detail = data['detailLottery'][key]; var directLottery = data['directLottery'][key]; var firstNumber = data['firstNumber'][key]; var lastNumber = data['lastNumber'][key]; html += '
'; // Render direct html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; var rowCount = 2; if (key == 1) { rowCount = 3; } for (var row = 0; row < rowCount; row++) { html += ''; html += ''; html += ''; } html += ''; html += '
Lô tô ' + detail['name'] + ' ' + date.lang('vi').format('dddd') + ' ' + date.format('DD-MM-YYYY') + '
'; html += '
'; for (var j = 0; j < 9; j++) { var index = row * 9 + j; var number = ''; var className = ''; if (directLottery != undefined && directLottery[index] !== undefined) { if (directLottery[index].includes('*') != false) { className = 'special-prize'; number = directLottery[index].replace('*', ''); } else { number = directLottery[index]; } } else { number = '-'; } html += '' + number + ''; } html += '
'; html += '
'; // Render by number html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; for (var index = 0; index <= 9; index++) { html += ''; html += ''; html += ''; } html += ''; html += '
'; html += '
'; html += 'Đầu'; html += 'Lô tô'; html += 'Đuôi'; html += 'Lô tô'; html += '
'; html += '
'; html += '
'; html += '' + index + ''; html += ''; if (firstNumber !== undefined && firstNumber[index] !== undefined && firstNumber[index].length > 0) { var text = ''; for (var j = 0; j < firstNumber[index].length; j++) { number = firstNumber[index][j].replace('*', ''); text += number + '; '; } html += text; } else { html += '-'; } html += ''; html += '' + index + ''; html += ''; if (lastNumber !== undefined && lastNumber[index] !== undefined && lastNumber[index].length > 0) { var text = ''; for (var j = 0; j < lastNumber[index].length; j++) { number = lastNumber[index][j].replace('*', ''); text += number + '; '; } html += text; } else { html += '-'; } html += ''; html += '
'; html += '
'; // End html += '
'; i++; } } html += '
'; // End render tab content html += '
'; return html; } var checkOffsetTime = function () { var d = new Date(); var url = ''; var lottery_id = $('#lottery_id').val(); var startTimeOffset = $('#startTime').val(); var endTimeOffset = $('#endTime').val(); var currentTime = moment().utc(); var currentDate = moment.tz('Asia/Ho_Chi_Minh').format('YYYY-MM-DD'); if (startTimeOffset == undefined || endTimeOffset == undefined) { // Check Southern var startTime = moment.tz(currentDate + " " + "16:10:00", "Asia/Ho_Chi_Minh").utc(); var endTime = moment.tz(currentDate + " " + "16:45:00", "Asia/Ho_Chi_Minh").utc(); if (startTime <= currentTime && currentTime <= endTime) { url = '/realtime/mien-nam.html?t=' + d.getTime(); } // Check Central var startTime = moment.tz(currentDate + " " + "17:10:00", "Asia/Ho_Chi_Minh").utc(); var endTime = moment.tz(currentDate + " " + "17:40:00", "Asia/Ho_Chi_Minh").utc(); if (startTime <= currentTime && currentTime <= endTime) { url = '/realtime/mien-trung.html?t=' + d.getTime(); } // Check Northern var startTime = moment.tz(currentDate + " " + "18:10:00", "Asia/Ho_Chi_Minh").utc(); var endTime = moment.tz(currentDate + " " + "18:40:00", "Asia/Ho_Chi_Minh").utc(); if (startTime <= currentTime && currentTime <= endTime) { url = '/realtime/mien-bac.html?t=' + d.getTime(); } } else { var startTime = moment.tz(currentDate + " " + startTimeOffset, "Asia/Ho_Chi_Minh").add(-5, 'minutes').utc(); var endTime = moment.tz(currentDate + " " + endTimeOffset, "Asia/Ho_Chi_Minh").utc(); if (startTime <= currentTime && currentTime <= endTime) { if (lottery_id == 1) { url = '/realtime/mien-bac.html?t=' + d.getTime(); } else if (lottery_id == 6) { url = '/realtime/mien-nam.html?t=' + d.getTime(); } else if (lottery_id == 5) { url = '/realtime/mien-trung.html?t=' + d.getTime(); } else { url = "/?com=lottery&ctr=lotteryresult&act=result&id=" + lottery_id + "&ajax=1"; } } } return url; }; $(document).ready(function () { setInterval(getData, 3000); });