Created
July 30, 2017 17:54
-
-
Save nosalvage/ff08e52b973ec61b2381431e3cf4422f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('starter.controllers', []) | |
.controller('AppCtrl', function($scope, $ionicHistory, $ionicSideMenuDelegate, $state, $rootScope, totoData, utils, lstorage) { | |
$rootScope.marketInfo = { | |
items: [] | |
}; | |
var uid = lstorage.get("uid"); | |
var tournaments; | |
var liveMatches; | |
// $scope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams){ | |
// if(toState.name == "app.line"){ | |
// $ionicHistory.clearCache().then(function(){ | |
// $state.go('login'); | |
// }); | |
// $ionicHistory.clearHistory(); | |
// console.log(toState); | |
// } | |
// }); | |
$scope.logout = function(){ | |
if($ionicSideMenuDelegate.isOpenLeft()){ | |
$ionicSideMenuDelegate.toggleLeft(); | |
} | |
$state.go('app.login'); | |
$rootScope.isAuth = false; | |
lstorage.remove("isRemember"); | |
lstorage.remove("uid"); | |
$ionicHistory.nextViewOptions({ | |
disableBack: true | |
}); | |
console.log($rootScope.isAuth); | |
}; | |
$scope.goToLine = function(){ | |
utils.showLoad(); | |
totoData.getPrematchTournaments().then(function(res){ | |
utils.hideLoad(); | |
tournaments = res.tournaments; | |
$scope.sportid = $rootScope.sports[0].id; | |
$scope.sports = $rootScope.sports; | |
$scope.matches = _ | |
.chain(tournaments) | |
.groupBy('sportname') | |
.map(function(value, key) { | |
return { | |
type: key, | |
matches: value | |
} | |
}) | |
.value(); | |
$ionicHistory.nextViewOptions({ | |
disableBack: true | |
}); | |
utils.hideLoad(); | |
$state.go("app.line", {data: $scope.matches}); | |
}, function(err){ | |
utils.hideLoad(); | |
utils.showAlert("Ошибка соединения!"); | |
}); | |
}; | |
$scope.goToLive = function(){ | |
utils.showLoad(); | |
totoData.getLiveMatches().then(function(res){ | |
liveMatches = res.matches; | |
return $rootScope.sports; | |
}, function(err){ | |
console.log(err); | |
utils.showAlert("Ошибка соединения!"); | |
utils.hideLoad(); | |
}).then(function(sports){ | |
$scope.sportid = sports[0].id; | |
$scope.sports = sports; | |
var fmatches = liveMatches.map(function(match){ | |
match.time = match.dtm.split(" ")[1].substring(0, match.dtm.split(" ")[1].lastIndexOf(':')); | |
return match; | |
}); | |
$scope.matches = _ | |
.chain(fmatches) | |
.groupBy('tournname') | |
.map(function(value, key) { | |
return { | |
type: key, | |
matches: value | |
} | |
}) | |
.value(); | |
console.log($scope.matches); | |
$ionicHistory.nextViewOptions({ | |
disableBack: true | |
}); | |
utils.hideLoad(); | |
$state.go("app.live", {data: $scope.matches}); | |
}, function(err){ | |
utils.hideLoad(); | |
utils.showAlert("Ошибка соединения!"); | |
}); | |
}; | |
$scope.clearCoupon = function(){ | |
console.log($rootScope.betInfo); | |
totoData.deletePos("", 0, $rootScope.betInfo.kuponid, uid).then(function(res){ | |
console.log(res); | |
$rootScope.selections = res.selections; | |
//$rootScope.betInfo = res.betInfo; | |
//console.log($rootScope.betInfo); | |
$rootScope.marketInfo.items = []; | |
}, function(err){ | |
console.log(err); | |
}); | |
}; | |
$scope.doBet = function(){ | |
$state.go('app.newbet'); | |
}; | |
$scope.removeFromCoupon = function(selCount, kuponid, index, selection){ | |
console.log(selection); | |
utils.showLoad(); | |
var sels = $rootScope.selections.split(" ! "); | |
var pos = sels.indexOf(selection); | |
totoData.deletePos($rootScope.selections, pos, kuponid, uid).then(function(res){ | |
console.log(res); | |
$rootScope.selections = res.selections; | |
$rootScope.betInfo = res.betInfo; | |
for(var i = 0; i < $rootScope.betInfo.bettypes.length; i++){ | |
if($rootScope.betInfo.bettypes[i].isSelected){ | |
$scope.betType = $rootScope.betInfo.bettypes[i].value; | |
} | |
} | |
$rootScope.betInfo.errors = res.betInfo.errors.filter(function(error){ | |
return !error.isSelectionError; | |
}); | |
console.log($rootScope.betInfo); | |
$rootScope.marketInfo.items.splice(index, 1); | |
utils.hideLoad(); | |
}, function(err){ | |
console.log(err); | |
utils.hideLoad(); | |
utils.showAlert("Ошибка соединения!"); | |
}); | |
}; | |
$scope.$on('addMarket', function(e, marketInfo){ | |
$rootScope.marketInfo.items.push(marketInfo); | |
console.log($rootScope.marketInfo); | |
}); | |
}) | |
.controller('mainCtrl', function($scope){ | |
}) | |
.controller('newBetCtrl', function($scope, $rootScope, $timeout, $ionicHistory, $state, utils, lstorage, totoData){ | |
console.log($rootScope.betInfo.bettypes); | |
$scope.betParams = { | |
sums: [], | |
totalsum: 0 | |
}; | |
var uid = lstorage.get("uid"); | |
$scope.isAgree = false; | |
var mLabels = ['Янв', 'Фев', 'Мар', 'Апр', 'Май', 'Июн', 'Июл', 'Авг', 'Сен', 'Окт', 'Ноя', 'Дек']; | |
$scope.warnings = [{ | |
text: "Всегда", | |
value: "always" | |
}, { | |
text: "Если уменьшился", | |
value: "only_down" | |
}, { | |
text: "Не предупреждать", | |
value: "never" | |
}]; | |
$scope.warning = $scope.warnings[0].value; | |
$scope.totsum = 0; | |
$scope.totalsum = 0; | |
function add(a, b) { | |
return a + b; | |
} | |
$scope.changeTotSum = function(sum, index){ | |
console.log($rootScope); | |
if($scope.betParams.sums.length > 1){ | |
$scope.betParams.totalsum = $scope.betParams.sums.reduce(add, 0); | |
}else{ | |
$scope.betParams.totalsum = sum; | |
} | |
}; | |
$scope.removeFromCoupon = function(selCount, kuponid, index, selection){ | |
utils.showLoad(); | |
var sels = $rootScope.selections.split(" ! "); | |
var pos = sels.indexOf(selection); | |
totoData.deletePos($rootScope.selections, pos, kuponid, uid).then(function(res){ | |
console.log(res); | |
utils.hideLoad(); | |
$rootScope.selections = res.selections; | |
$rootScope.betInfo = res.betInfo; | |
for(var i = 0; i < $rootScope.betInfo.bettypes.length; i++){ | |
if($rootScope.betInfo.bettypes[i].isSelected){ | |
$scope.betType = $rootScope.betInfo.bettypes[i].value; | |
} | |
} | |
$rootScope.betInfo.errors = res.betInfo.errors.filter(function(error){ | |
return error.isSelectionError; | |
}); | |
console.log($rootScope.betInfo); | |
$rootScope.marketInfo.items.splice(index, 1); | |
}, function(err){ | |
utils.hideLoad(); | |
utils.showAlert("Ошибка соединения!"); | |
console.log(err); | |
}); | |
}; | |
function gen_kuponid(){ | |
return Math.floor(Math.random() * (900000000)) + 100000000; | |
} | |
$scope.agreeBet = function(){ | |
$scope.isAgree = true; | |
}; | |
$scope.replaceBet = function(betParams, betType, warning, totsum, doit, nAttempt){ | |
// nAttempt = 0 (null) - первый заход в функцию | |
// nAttempt = 1 - второй заход в функцию (после ожидания 5 секнд для лайв ставок) | |
// nAttempt = -1 - третий (аварийный) заход в функцию (если второй заход не принес успешной попытки) | |
var sums = betParams.sums.join(" ! "); | |
console.log(totsum); | |
if(nAttempt==null) nAttempt = 0; | |
utils.showLoad(); | |
// на всякий случай инициализация kuponid | |
if($rootScope.betInfo.kuponid==null || $rootScope.betInfo.kuponid==0) $rootScope.betInfo.kuponid = gen_kuponid(); | |
totoData.replaceBet(uid, $rootScope.selections, $rootScope.betInfo.kuponid, totsum, sums, warning, betType, doit).then(function(res){ | |
// Если уже две неудачные попытки | |
if((doit==1)&&(res.betInfo.delayed==1)&&(nAttempt==-1)){ | |
// ошибка связи, возможно ставка была принята | |
utils.hideLoad(); | |
utils.showAlert('Возможно ставка уже принята'); | |
return; | |
} | |
// Еще секундочка | |
if((doit==1)&&(res.betInfo.delayed==1)&&(nAttempt==1)){ | |
setTimeout(function (){ $scope.replaceBet(betParams, betType, warning, totsum, doit, -1); },1000 ); | |
return; | |
} | |
// Вторая попытка | |
if((doit==1)&&(res.betInfo.delayed==1)&&(nAttempt==0)){ | |
setTimeout( | |
function (){ $scope.replaceBet(betParams, betType, warning, totsum, doit, 1); },res.betInfo.delaytime | |
); | |
return; | |
} | |
utils.hideLoad(); | |
console.log(res); | |
// Запрос завершился успешно, либо выводим что ставка принята | |
// либо показываем ставку со списком ошибок | |
$rootScope.selections = res.selections; | |
$rootScope.selections2 = res.selections2; | |
$rootScope.betInfo = res.betInfo; | |
console.log($rootScope.betInfo); | |
$rootScope.bettype1 = $rootScope.betInfo.bettypes.filter(function(item){ | |
return item.value === $rootScope.betInfo.bettype; | |
}); | |
console.log($rootScope.bettype1); | |
$rootScope.betInfo.kuponid = gen_kuponid(); // теперь у нас новый купон, старый успешно отработал | |
if(res.betInfo.done==1){ | |
console.log('Успех!'); | |
$rootScope.marketInfo.items = []; | |
console.log(res.betSelections); | |
for(var i = 0; i < res.betSelections.length; i++){ | |
var match = res.betSelections[i].dtm.split(" ")[0]; | |
var time = res.betSelections[i].dtm.split(" ")[1]; | |
var ftime = time.substring(0, time.lastIndexOf(':')); | |
var smatch = match.split("-"); | |
smatch[1] = parseInt(smatch[1]) - 1; | |
console.log(smatch); | |
console.log(match); | |
res.betSelections[i].dtm = smatch[2] + ' ' + mLabels[smatch[1]] + ' ' + ftime; | |
$rootScope.SucItems = res.betSelections; | |
console.log(res.betSelections[i].dtm); | |
} | |
console.log(res.betSelections); | |
$ionicHistory.nextViewOptions({ | |
disableBack: true | |
}); | |
$state.go('app.bet-success'); | |
utils.showAlert("Успех!", "Ваша ставка принята"); | |
}else{ | |
console.log('Провал!'); | |
// показываем экран ставки с ошибками | |
} | |
}, function(err){ | |
utils.showAlert("Ошибка связи при приеме ставки! " + err); | |
utils.hideLoad(); | |
}); | |
}; | |
$scope.typeChange = function(betType, betParams, warning, totsum){ | |
$scope.betParams.totalsum = 0; | |
var nAttempt = 0; | |
var doit = 0; | |
var sums = betParams.sums.join(" ! "); | |
console.log(totsum); | |
if(nAttempt==null) nAttempt = 0; | |
utils.showLoad(); | |
// на всякий случай инициализация kuponid | |
if($rootScope.betInfo.kuponid==null || $rootScope.betInfo.kuponid==0) $rootScope.betInfo.kuponid = gen_kuponid(); | |
totoData.replaceBet(uid, $rootScope.selections, $rootScope.betInfo.kuponid, totsum, sums, warning, betType, 0).then(function(res){ | |
// Если уже две неудачные попытки | |
if((doit==1)&&(res.betInfo.delayed==1)&&(nAttempt==-1)){ | |
// ошибка связи, возможно ставка была принята | |
utils.hideLoad(); | |
utils.showAlert('Возможно ставка уже принята'); | |
return; | |
} | |
// Еще секундочка | |
if((doit==1)&&(res.betInfo.delayed==1)&&(nAttempt==1)){ | |
setTimeout(function (){ $scope.replaceBet(betParams, betType, warning, totsum, doit, -1); },1000 ); | |
return; | |
} | |
// Вторая попытка | |
if((doit==1)&&(res.betInfo.delayed==1)&&(nAttempt==0)){ | |
setTimeout( | |
function (){ $scope.replaceBet(betParams, betType, warning, totsum, doit, 1); },res.betInfo.delaytime | |
); | |
return; | |
} | |
utils.hideLoad(); | |
console.log(res); | |
// Запрос завершился успешно, либо выводим что ставка принята | |
// либо показываем ставку со списком ошибок | |
$rootScope.selections = res.selections; | |
$rootScope.selections2 = res.selections2; | |
$rootScope.betInfo = res.betInfo; | |
console.log($rootScope.betInfo); | |
$rootScope.bettype1 = $rootScope.betInfo.bettypes.filter(function(item){ | |
return item.value === $rootScope.betInfo.bettype; | |
}); | |
console.log($rootScope.bettype1); | |
$rootScope.betInfo.kuponid = gen_kuponid(); // теперь у нас новый купон, старый успешно отработал | |
if(res.betInfo.done==1){ | |
console.log('Успех!'); | |
$rootScope.marketInfo.items = []; | |
console.log(res.betSelections); | |
for(var i = 0; i < res.betSelections.length; i++){ | |
var match = res.betSelections[i].dtm.split(" ")[0]; | |
var time = res.betSelections[i].dtm.split(" ")[1]; | |
var ftime = time.substring(0, time.lastIndexOf(':')); | |
var smatch = match.split("-"); | |
smatch[1] = parseInt(smatch[1]) - 1; | |
console.log(smatch); | |
console.log(match); | |
res.betSelections[i].dtm = smatch[2] + ' ' + mLabels[smatch[1]] + ' ' + ftime; | |
$rootScope.SucItems = res.betSelections; | |
console.log(res.betSelections[i].dtm); | |
} | |
console.log(res.betSelections); | |
$ionicHistory.nextViewOptions({ | |
disableBack: true | |
}); | |
$state.go('app.bet-success'); | |
utils.showAlert("Успех!", "Ваша ставка принята"); | |
}else{ | |
console.log('Провал!'); | |
// показываем экран ставки с ошибками | |
} | |
}, function(err){ | |
utils.showAlert("Ошибка связи при приеме ставки! " + err); | |
utils.hideLoad(); | |
}); | |
if(betType === null){ | |
$timeout(function(){ | |
$scope.betType = $rootScope.betInfo.bettypes[0].value; | |
console.log($scope.betType); | |
}, 100); | |
} | |
}; | |
for(var i = 0; i < $rootScope.betInfo.bettypes.length; i++){ | |
if($rootScope.betInfo.bettypes[i].isSelected){ | |
$scope.betType = $rootScope.betInfo.bettypes[i].value; | |
} | |
} | |
}) | |
.controller('betSuccessCtrl', function($scope, $rootScope){ | |
}) | |
.controller('liveBetCtrl', function($scope, $rootScope, $ionicLoading, $state, $interval, totoData, utils, lstorage){ | |
var id = $state.params.id; | |
var time_getLiveMatchInfo = $rootScope.time_getLiveMatchInfo; | |
var time_getLiveMatches = $rootScope.time_getLiveMatches; | |
var mLabels = ['Янв', 'Фев', 'Мар', 'Апр', 'Май', 'Июн', 'Июл', 'Авг', 'Сен', 'Окт', 'Ноя', 'Дек']; | |
var time_getLiveMatchInfo = $rootScope.time_getLiveMatchInfo; | |
var market; | |
var marketInfo = {}; | |
$rootScope.selections = undefined; | |
function timestamp(){ | |
return Math.floor(Date.now() / 1000); | |
} | |
$scope.doBet = function(odd, outcome){ | |
if(lstorage.get("uid")){ | |
console.log(odd); | |
var selId; | |
market = odd.oddstype + "_" + odd.islive + "_" + odd.specialtextvalue + "_" + outcome.outcome + "_" + outcome.kf; | |
console.log(market); | |
utils.showLoad(); | |
totoData.addKf($rootScope.selections, odd.matchid, odd.islive, outcome.kf, market, lstorage.get("uid")).then(function(res){ | |
if(res.errcode){ | |
$ionicLoading.show({ template: res.errtext, noBackdrop: true, duration: 1000 }); | |
}else{ | |
utils.hideLoad(); | |
var selection = res.selections.split(" ! "); | |
$rootScope.selections = res.selections; | |
selId = res.betInfo.selection_count - 1; | |
$rootScope.betInfo = res.betInfo; | |
console.log(res); | |
$rootScope.betInfo.errors = res.betInfo.errors.filter(function(error){ | |
return !error.isSelectionError; | |
}); | |
marketInfo = { | |
selection: selection[selection.length - 1], | |
kuponid: res.betInfo.kuponid, | |
selection_count: res.betInfo.selection_count, | |
totkoef: res.betInfo.totkoef, | |
general_error_count: res.betInfo.general_error_count, | |
errors: res.betInfo.errors, | |
max: res.betSelections[selId].max, | |
new_kf: res.betSelections[selId].new_kf, | |
kf_changed: res.betSelections[selId].kf_changed, | |
sum: res.betSelections[selId].sum, | |
tournname: res.betSelections[selId].tournname, | |
team1: res.betSelections[selId].team1, | |
team2: res.betSelections[selId].team2, | |
dtm: res.betSelections[selId].dtm, | |
kf: res.betSelections[selId].kf, | |
pari_text: res.betSelections[selId].pari_text | |
} | |
$ionicLoading.show({ template: 'Коэффициент добавлен!', noBackdrop: true, duration: 300 }); | |
$rootScope.$broadcast('addMarket', marketInfo); | |
} | |
}, function(err){ | |
utils.hideLoad(); | |
utils.showAlert("Ошибка соединения!"); | |
}); | |
}else{ | |
utils.showAlert("Ошибка!", "Пожалуйста авторизуйтесь"); | |
} | |
}; | |
// totoData.getConfig().then(function(res){ | |
// time_getLiveMatchInfo = res.refrTime_getLiveMatchInfo; | |
// }, function(err){ | |
// alert(err); | |
// }); | |
utils.showLoad(); | |
totoData.getLiveMatchInfo(id).then(function(res){ | |
var smatch = res.dtm.split(" "); | |
var fsmatch = smatch[0].split("-"); | |
var mIndex = parseInt(fsmatch[1]) - 1; | |
res.time = res.dtm.split(" ")[1].substring(0, res.dtm.split(" ")[1].lastIndexOf(':')); | |
res.month = fsmatch[1] + ' ' + mLabels[mIndex]; | |
$scope.matchInfo = res; | |
console.log(res); | |
utils.hideLoad(); | |
}, function(err){ | |
utils.hideLoad(); | |
utils.showAlert("Ошибка соединения!"); | |
}); | |
}) | |
.controller('lineCtrl', function($scope, $rootScope, $state, $ionicHistory, $timeout, totoData, utils){ | |
var sports = []; | |
var flags = {}; | |
var flags2 = {}; | |
var flags3 = {}; | |
var sportIds = []; | |
$scope.times = [{ | |
id: 0, | |
name: "Любое время" | |
}, { | |
id: 2, | |
name: "На 2 часа" | |
}, | |
{ | |
id: 4, | |
name: "На 4 часов" | |
},{ | |
id: 6, | |
name: "На 6 часов" | |
},{ | |
id: 12, | |
name: "На 12 часов" | |
},{ | |
id: 24, | |
name: "На 24 часов" | |
}]; | |
$scope.time = $scope.times[0].id; | |
var tours; | |
var mLabels = ['Янв', 'Фев', 'Мар', 'Апр', 'Май', 'Июн', 'Июл', 'Авг', 'Сен', 'Окт', 'Ноя', 'Дек']; | |
$scope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams){ | |
if(fromState.name == "app.line-matches"){ | |
//$scope.ischecked = false; | |
//sportIds = []; | |
console.log('timeout'); | |
var check = document.querySelectorAll("input.ng-not-empty"); | |
for(var i = 0; i < check.length; i++){ | |
check[i].checked = false; | |
} | |
console.log(check); | |
}else if(fromState.name == "app.line"){ | |
console.log('asdasd'); | |
}else{ | |
// utils.showLoad(); | |
// totoData.getPrematchTournaments().then(function(res){ | |
// console.log(res); | |
// tours = res.tournaments; | |
// return $rootScope.sports; | |
// }, function(err){ | |
// console.log(err); | |
// utils.hideLoad(); | |
// }).then(function(sports){ | |
// console.log(sports); | |
// $scope.sportid = sports[0].id; | |
// $scope.sports = sports; | |
// $scope.matches = _ | |
// .chain(tours) | |
// .groupBy('sportname') | |
// .map(function(value, key) { | |
// return { | |
// type: key, | |
// matches: value | |
// } | |
// }) | |
// .value(); | |
// console.log($scope.matches); | |
// utils.hideLoad(); | |
// }, function(err){ | |
// utils.hideLoad(); | |
// console.log(err); | |
// }); | |
} | |
}); | |
Array.prototype.remove = function() { | |
var what, a = arguments, L = a.length, ax; | |
while (L && this.length) { | |
what = a[--L]; | |
while ((ax = this.indexOf(what)) !== -1) { | |
this.splice(ax, 1); | |
} | |
} | |
return this; | |
}; | |
$scope.checkSport = function(id, ischecked){ | |
console.log(id); | |
console.log(ischecked); | |
if(ischecked){ | |
sportIds.push(id); | |
}else{ | |
sportIds.remove(id); | |
} | |
console.log(sportIds); | |
}; | |
$scope.changeSport = function(sportid, time){ | |
sportIds = []; | |
utils.showLoad(); | |
$scope.sportid = sportid; | |
$scope.time = time; | |
console.log(sportid); | |
console.log(time); | |
totoData.getPrematchTournaments(sportid, time).then(function(data){ | |
$scope.matches = _ | |
.chain(data.tournaments) | |
.groupBy('sportname') | |
.map(function(value, key) { | |
return { | |
type: key, | |
matches: value | |
} | |
}) | |
.value(); | |
console.log(data); | |
utils.hideLoad(); | |
}, function(err){ | |
utils.hideLoad(); | |
utils.showAlert("Ошибка соединения!"); | |
}); | |
}; | |
$scope.changeTime = function(sportid, time){ | |
utils.showLoad(); | |
console.log(sportid); | |
console.log(time); | |
totoData.getPrematchTournaments(sportid, time).then(function(data){ | |
$scope.matches = _ | |
.chain(data.tournaments) | |
.groupBy('sportname') | |
.map(function(value, key) { | |
return { | |
type: key, | |
matches: value | |
} | |
}) | |
.value(); | |
console.log($scope.matches); | |
utils.hideLoad(); | |
}, function(err){ | |
utils.hideLoad(); | |
utils.showAlert("Ошибка соединения!"); | |
}); | |
}; | |
$scope.showMatch = function(){ | |
var ids = sportIds.toString(); | |
sportIds = []; | |
console.log(ids); | |
if(ids == ""){ | |
utils.showAlert("Вы не выбрали спорт"); | |
}else{ | |
utils.showLoad(); | |
totoData.getPrematchMatches(ids).then(function(data){ | |
var fmatches = data.matches.map(function(match){ | |
var smatch = match.dtm.split(" "); | |
var fsmatch = smatch[0].split("-"); | |
var mIndex = parseInt(fsmatch[1]) - 1; | |
match.time = match.dtm.split(" ")[1].substring(0, match.dtm.split(" ")[1].lastIndexOf(':')); | |
match.month = fsmatch[1] + ' ' + mLabels[mIndex]; | |
return match; | |
}); | |
$scope.matches1 = _ | |
.chain(fmatches) | |
.groupBy('tournamentname') | |
.map(function(value, key) { | |
return { | |
type: key, | |
matches: value | |
} | |
}) | |
.value(); | |
utils.hideLoad(); | |
$state.go('app.line-matches', {data: $scope.matches1}); | |
}, function(err){ | |
utils.hideLoad(); | |
utils.showAlert("Ошибка соединения!"); | |
}); | |
} | |
}; | |
$scope.matches = $state.params.data; | |
}) | |
.controller('lineMatchesCtrl', function($scope, $state, totoData, utils){ | |
//var ids = $state.params.ids || "4254"; | |
var mLabels = ['Янв', 'Фев', 'Мар', 'Апр', 'Май', 'Июн', 'Июл', 'Авг', 'Сен', 'Окт', 'Ноя', 'Дек']; | |
$scope.matches1 = $state.params.data; | |
console.log($scope.matches1); | |
$scope.pressMatchHandle = function(id){ | |
utils.showLoad(); | |
totoData.getPrematchMatchInfo(id).then(function(res){ | |
var smatch = res.dtm.split(" "); | |
var fsmatch = smatch[0].split("-"); | |
var mIndex = parseInt(fsmatch[1]) - 1; | |
res.time = res.dtm.split(" ")[1].substring(0, res.dtm.split(" ")[1].lastIndexOf(':')); | |
res.month = fsmatch[1] + ' ' + mLabels[mIndex]; | |
$scope.matchInfo = res; | |
$state.go('app.line-bet', {id: id, data: res}); | |
utils.hideLoad(); | |
}, function(err){ | |
utils.hideLoad(); | |
utils.showAlert("Ошибка соединения!"); | |
}); | |
}; | |
}) | |
.controller('lineBetCtrl', function($scope, $rootScope, $ionicLoading, $state, totoData, lstorage, utils){ | |
var matchId = $state.params.id || "207137"; | |
var mLabels = ['Янв', 'Фев', 'Мар', 'Апр', 'Май', 'Июн', 'Июл', 'Авг', 'Сен', 'Окт', 'Ноя', 'Дек']; | |
var time_getLiveMatchInfo = $rootScope.time_getLiveMatchInfo; | |
var time_getLiveMatches = $rootScope.time_getLiveMatches; | |
function timestamp(){ | |
return Math.floor(Date.now() / 1000); | |
} | |
var updateFunc = function(){ | |
if($state.current.name === 'app.line-bet'){ | |
if(time_getLiveMatches == -1){ | |
utils.hideLoad(); | |
return; | |
}; | |
time_getLiveMatches = -1; | |
totoData.getLiveMatches(0).then(function(data){ | |
if($scope.sportid){ | |
var filterMatches = data.matches.filter(function(match){ | |
return match.sportid === $scope.sportid; | |
}); | |
var fmatches = filterMatches.map(function(match){ | |
match.time = match.dtm.split(" ")[1].substring(0, match.dtm.split(" ")[1].lastIndexOf(':')); | |
return match; | |
}); | |
}else{ | |
var fmatches = data.matches.map(function(match){ | |
match.time = match.dtm.split(" ")[1].substring(0, match.dtm.split(" ")[1].lastIndexOf(':')); | |
return match; | |
}); | |
} | |
$scope.matches = _ | |
.chain(fmatches) | |
.groupBy('tournname') | |
.map(function(value, key) { | |
return { | |
type: key, | |
matches: value | |
} | |
}) | |
.value(); | |
utils.hideLoad(); | |
time_getLiveMatches = timestamp(); | |
console.log($scope.matches); | |
}, function(err){ | |
utils.hideLoad(); | |
$interval.stop(update); | |
time_getLiveMatches = timestamp(); | |
utils.showAlert("Ошибка соединения!"); | |
}); | |
} | |
}; | |
$scope.refreshLineInfo = function(){ | |
utils.showLoad(); | |
updateFunc(); | |
}; | |
$scope.doBet = function(odd, outcome){ | |
if(lstorage.get("uid")){ | |
console.log(odd); | |
var selId; | |
market = odd.oddstype + "_" + odd.islive + "_" + odd.specialtextvalue + "_" + outcome.outcome + "_" + outcome.kf; | |
console.log(market); | |
utils.showLoad(); | |
totoData.addKf($rootScope.selections, odd.matchid, odd.islive, outcome.kf, market, lstorage.get("uid")).then(function(res){ | |
if(res.errcode){ | |
$ionicLoading.show({ template: res.errtext, noBackdrop: true, duration: 1000 }); | |
}else{ | |
var selection = res.selections.split(" ! "); | |
$rootScope.selections = res.selections; | |
selId = res.betInfo.selection_count - 1; | |
$rootScope.betInfo = res.betInfo; | |
$rootScope.betInfo.errors = res.betInfo.errors.filter(function(error){ | |
return !error.isSelectionError; | |
}); | |
utils.hideLoad(); | |
$ionicLoading.show({ template: 'Коэффициент добавлен!', noBackdrop: true, duration: 300 }); | |
$rootScope.$broadcast('addMarket', marketInfo); | |
} | |
}, function(err){ | |
utils.hideLoad(); | |
utils.showAlert("Ошибка соединения!"); | |
console.log(err); | |
}); | |
}else{ | |
utils.showAlert("Ошибка!", "Пожалуйста авторизуйтесь"); | |
} | |
}; | |
$scope.matchInfo = $state.params.data; | |
console.log($state.params); | |
}) | |
.controller('liveCtrl', function($scope, $rootScope, $q, $interval, $state, totoData, utils){ | |
var sports = []; | |
var flags = {}; | |
var flags2 = {}; | |
var time_getLiveMatchInfo = $rootScope.time_getLiveMatchInfo; | |
var time_getLiveMatches = $rootScope.time_getLiveMatches; | |
function timestamp(){ | |
return Math.floor(Date.now() / 1000); | |
} | |
// totoData.getConfig().then(function(res){ | |
// console.log(res); | |
// time_getLiveMatchInfo = res.refrTime_getLiveMatchInfo; | |
// time_getLiveMatches = res.refrTime_getLiveMatches; | |
// }, function(err){ | |
// alert(err); | |
// }); | |
$scope.changeSport = function(sportid){ | |
utils.showLoad(); | |
$scope.sportid = sportid; | |
totoData.getLiveMatches(sportid).then(function(data){ | |
console.log(sportid); | |
if(sportid){ | |
var filterMatches = data.matches.filter(function(match){ | |
return match.sportid === sportid; | |
}); | |
var fmatches = filterMatches.map(function(match){ | |
match.time = match.dtm.split(" ")[1].substring(0, match.dtm.split(" ")[1].lastIndexOf(':')); | |
return match; | |
}); | |
}else{ | |
var fmatches = data.matches.map(function(match){ | |
match.time = match.dtm.split(" ")[1].substring(0, match.dtm.split(" ")[1].lastIndexOf(':')); | |
return match; | |
}); | |
} | |
$scope.matches = _ | |
.chain(fmatches) | |
.groupBy('tournname') | |
.map(function(value, key) { | |
return { | |
type: key, | |
matches: value | |
} | |
}) | |
.value(); | |
console.log($scope.matches); | |
utils.hideLoad(); | |
}, function(err){ | |
utils.hideLoad(); | |
utils.showAlert("Ошибка соединения!"); | |
}); | |
}; | |
$scope.goToMatchInfo = function(matchid){ | |
console.log(matchid); | |
$state.go('app.live-bet', {id: matchid}); | |
}; | |
// var liveMatches; | |
// utils.showLoad(); | |
// totoData.getLiveMatches().then(function(res){ | |
// liveMatches = res.matches; | |
// return $rootScope.sports; | |
// }, function(err){ | |
// console.log(err); | |
// utils.hideLoad(); | |
// }).then(function(sports){ | |
// console.log(sports); | |
// $scope.sportid = sports[0].id; | |
// $scope.sports = sports; | |
// var fmatches = liveMatches.map(function(match){ | |
// match.time = match.dtm.split(" ")[1].substring(0, match.dtm.split(" ")[1].lastIndexOf(':')); | |
// return match; | |
// }); | |
// $scope.matches = _ | |
// .chain(fmatches) | |
// .groupBy('tournname') | |
// .map(function(value, key) { | |
// return { | |
// type: key, | |
// matches: value | |
// } | |
// }) | |
// .value(); | |
// console.log($scope.matches); | |
// utils.hideLoad(); | |
// }); | |
$scope.$on('$stateChangeSuccess', function(e, toState, toParams, fromState, fromParams){ | |
console.log(typeof update); | |
console.log(fromState); | |
if(toState.name !== 'app.live' && toState.name !== 'app.live-bet'){ | |
if(angular.isDefined(update)){ | |
$interval.cancel(update); | |
} | |
console.log('live-bet'); | |
} | |
console.log('leave'); | |
}); | |
var update = $interval(function(){ | |
if($state.current.name === 'app.live'){ | |
if(time_getLiveMatches == -1) return; | |
if(timestamp() - time_getLiveMatches < 14) return; | |
time_getLiveMatches = -1; | |
totoData.getLiveMatches(0).then(function(data){ | |
if($scope.sportid){ | |
var filterMatches = data.matches.filter(function(match){ | |
return match.sportid === $scope.sportid; | |
}); | |
var fmatches = filterMatches.map(function(match){ | |
match.time = match.dtm.split(" ")[1].substring(0, match.dtm.split(" ")[1].lastIndexOf(':')); | |
return match; | |
}); | |
}else{ | |
var fmatches = data.matches.map(function(match){ | |
match.time = match.dtm.split(" ")[1].substring(0, match.dtm.split(" ")[1].lastIndexOf(':')); | |
return match; | |
}); | |
} | |
$scope.matches = _ | |
.chain(fmatches) | |
.groupBy('tournname') | |
.map(function(value, key) { | |
return { | |
type: key, | |
matches: value | |
} | |
}) | |
.value(); | |
time_getLiveMatches = timestamp(); | |
console.log($scope.matches); | |
}, function(err){ | |
$interval.stop(update); | |
time_getLiveMatches = timestamp(); | |
utils.showAlert("Ошибка соединения!"); | |
}); | |
} | |
}, 1000); | |
// var updateFunc = ; | |
}) | |
.controller('loginCtrl', function($scope, $q, $state, $rootScope, $translate, $ionicHistory, $rootScope, utils, totoData, lstorage) { | |
console.log($rootScope.isAuth); | |
$scope.languages = [ | |
{ | |
id: "ru", | |
name: "Русский" | |
}, | |
{ | |
id: "en", | |
name: "Английский" | |
}, | |
{ | |
id: "kz", | |
name: "Казахский" | |
} | |
]; | |
$scope.lang = $translate.proposedLanguage() || $translate.use(); | |
$scope.changeLang = function(lang){ | |
$translate.use(lang); | |
}; | |
$scope.goToReg = function(){ | |
utils.showLoad(); | |
var one = totoData.getCountries(); | |
var two = totoData.getRegions(); | |
$q.all([one, two]).then(function(data){ | |
console.log('ura'); | |
$state.go('app.register1'); | |
utils.hideLoad(); | |
}, function(err){ | |
utils.hideLoad(); | |
utils.showAlert("Ошибка соединения"); | |
console.log(err); | |
}); | |
}; | |
$scope.login = function(loginData) { | |
console.log(loginData); | |
if(loginData){ | |
utils.showLoad(); | |
totoData.auth(loginData.user, loginData.pass, $rootScope.hwid).then(function(data){ | |
utils.hideLoad(); | |
console.log(data); | |
if(data.errcode){ | |
utils.showAlert("Ошибка авторизации", data.errtext); | |
}else{ | |
$ionicHistory.nextViewOptions({ | |
disableBack: true | |
}); | |
$rootScope.isAuth = true; | |
$state.go('app.main', {}, {reload: true}); | |
//lstorage.set("dtm", new Date().getTime()); | |
//lstorage.set("session_mins", data.session_minutes); | |
if(loginData.isRemembered){ | |
lstorage.set("isRemember", true); | |
} | |
lstorage.set("uid", data.uid); | |
//lstorage.set("flname", data.name1 + ' ' + data.name2); | |
} | |
}, function(err){ | |
utils.hideLoad(); | |
utils.showAlert("Ошибка соединения"); | |
}); | |
}else{ | |
utils.showAlert("Вы не ввели данные"); | |
} | |
}; | |
}) | |
.controller('forget1Ctrl', function($scope, $state, $ionicHistory, utils, totoData) { | |
$scope.forget1 = function(fdata){ | |
utils.showLoad(); | |
if(typeof fdata !== 'undefined'){ | |
console.log(fdata); | |
fdata.action = "forgotPassword"; | |
fdata.stage = 1; | |
fdata.stage_try = 2; | |
totoData.forgotPassword(fdata).then(function(data){ | |
utils.hideLoad(); | |
console.log(data); | |
$scope.data = data; | |
if(!data.fail){ | |
console.log('success'); | |
$state.go('app.forget2', {data: fdata}); | |
} | |
}, function(err){ | |
utils.hideLoad(); | |
utils.showAlert("Ошибка соединения"); | |
}); | |
}else{ | |
utils.hideLoad(); | |
utils.showAlert("Ошибка!", "Вы не ввели данные"); | |
} | |
}; | |
$scope.$on("$ionicView.afterLeave", function () { | |
$ionicHistory.clearCache(); | |
}); | |
}) | |
.controller('forget2Ctrl', function($scope, $rootScope, $ionicHistory, $state, utils, totoData) { | |
$scope.fdata = $state.params.data; | |
$rootScope.startWatch(); | |
document.addEventListener('onSMSArrive', function(e){ | |
var data = e.data; | |
if(data.body.indexOf('TOTOBET.INFO') >= 0){ | |
$scope.fdata.smscode = parseInt(data.body.replace(/\D/g,'')); | |
$scope.$apply(); | |
} | |
}); | |
$scope.back = function(){ | |
$ionicHistory.goBack(); | |
}; | |
$scope.forget2 = function(fdata){ | |
utils.showLoad(); | |
if(typeof fdata !== 'undefined'){ | |
console.log(fdata); | |
fdata.action = "forgotPassword"; | |
fdata.stage = 2; | |
fdata.stage_try = 3; | |
totoData.forgotPassword(fdata).then(function(data){ | |
utils.hideLoad(); | |
console.log(data); | |
$scope.data = data; | |
if(!data.fail){ | |
console.log('success'); | |
$rootScope.stopWatch(); | |
$state.go('app.forget3', {data: fdata}); | |
} | |
}, function(err){ | |
utils.hideLoad(); | |
utils.showAlert("Ошибка соединения"); | |
}); | |
}else{ | |
utils.hideLoad(); | |
utils.showAlert("Ошибка!", "Вы не ввели данные"); | |
} | |
}; | |
}) | |
.controller('forget3Ctrl', function($scope, $state, $ionicHistory, totoData, utils) { | |
$scope.fdata = $state.params.data; | |
$scope.back = function(){ | |
$ionicHistory.goBack(); | |
}; | |
$scope.forget3 = function(fdata){ | |
utils.showLoad(); | |
if(typeof fdata !== 'undefined'){ | |
console.log(fdata); | |
fdata.action = "forgotPassword"; | |
fdata.stage = 3; | |
fdata.stage_try = 4; | |
totoData.forgotPassword(fdata).then(function(data){ | |
utils.hideLoad(); | |
console.log(data); | |
$scope.data = data; | |
if(!data.fail){ | |
console.log('success'); | |
$state.go('app.login'); | |
$ionicHistory.clearCache(); | |
$ionicHistory.nextViewOptions({ | |
disableBack: true | |
}); | |
utils.showAlert("Доступ к счету восстановлен!"); | |
} | |
}, function(err){ | |
utils.hideLoad(); | |
utils.showAlert("Ошибка соединения"); | |
}); | |
}else{ | |
utils.hideLoad(); | |
utils.showAlert("Ошибка!", "Вы не ввели данные"); | |
} | |
}; | |
}) | |
.controller('register1Ctrl', function($scope, $state, $q, $ionicHistory, totoData, utils) { | |
$scope.user = {}; | |
utils.showLoad(); | |
var one = totoData.getCountries(); | |
var two = totoData.getRegions(); | |
$q.all([one, two]).then(function(data){ | |
console.log('ura'); | |
$scope.user.countryid = data[0].countries[0].id; | |
$scope.countries = data[0].countries; | |
$scope.user.region = data[1].regions[0].id; | |
$scope.regions = data[1].regions; | |
utils.hideLoad(); | |
}, function(err){ | |
utils.hideLoad(); | |
$ionicHistory.nextViewOptions({ | |
disableAnimate: true, | |
disableBack: true | |
}); | |
$state.go('app.login'); | |
utils.showAlert("Ошибка соединения"); | |
console.log(err); | |
}); | |
$scope.signup1 = function(user){ | |
console.log(user); | |
utils.showLoad(); | |
if(typeof user !== 'undefined'){ | |
user.action = "registerCustomer"; | |
user.stage = 1; | |
user.stage_try = 2; | |
if(user.name1){ | |
user.name1 = user.name1.toUpperCase(); | |
} | |
if(user.name2){ | |
user.name2 = user.name2.toUpperCase(); | |
} | |
if(user.name3){ | |
user.name3 = user.name3.toUpperCase(); | |
} | |
if(user.codeword){ | |
user.codeword = user.codeword.toUpperCase(); | |
} | |
console.log(user); | |
totoData.registerCustomer(user).then(function(data){ | |
utils.hideLoad(); | |
user.tempid = data.tempid; | |
console.log(user); | |
$scope.data = data; | |
if(!data.fail){ | |
console.log('success'); | |
$state.go('app.register2', {data: user, validData: data}); | |
} | |
}, function(err){ | |
utils.hideLoad(); | |
utils.showAlert("Ошибка соединения"); | |
}); | |
}else{ | |
utils.hideLoad(); | |
utils.showAlert("Ошибка!", "Вы не ввели данные"); | |
} | |
}; | |
$scope.$on("$ionicView.afterLeave", function () { | |
$ionicHistory.clearCache(); | |
}); | |
}) | |
.controller('register2Ctrl', function($scope, $state, $ionicHistory, utils, totoData) { | |
$scope.data = $state.params.data; | |
$scope.validData = $state.params.validData; | |
totoData.getRegions().then(function(data){ | |
for(var i = 0; i < data.regions.length; i++){ | |
if($scope.data.region === data.regions[i].id){ | |
$scope.regionName = data.regions[i].name; | |
} | |
} | |
}, function(err){ | |
utils.showAlert("Ошибка соединения"); | |
}); | |
$scope.signup2 = function(user){ | |
utils.showLoad(); | |
user.action = "registerCustomer"; | |
user.stage = 2; | |
user.stage_try = 3; | |
console.log(user); | |
totoData.registerCustomer(user).then(function(data){ | |
utils.hideLoad(); | |
user.tempid = data.tempid; | |
console.log(data); | |
if(!data.fail){ | |
console.log('success'); | |
$state.go('app.register3', {data: user}); | |
} | |
}, function(err){ | |
utils.hideLoad(); | |
utils.showAlert("Ошибка соединения"); | |
}); | |
}; | |
$scope.back = function(){ | |
$ionicHistory.goBack(); | |
}; | |
}) | |
.controller('register3Ctrl', function($scope, $state, $ionicHistory, $rootScope, utils, totoData) { | |
$scope.user = $state.params.data; | |
$rootScope.startWatch(); | |
document.addEventListener('onSMSArrive', function(e){ | |
var data = e.data; | |
if(data.body.indexOf('TOTOBET.INFO') >= 0){ | |
$scope.user.smscode = parseInt(data.body.replace(/\D/g,'')); | |
$scope.$apply(); | |
} | |
}); | |
console.log($scope.user); | |
$scope.signup3 = function(user){ | |
utils.showLoad(); | |
user.action = "registerCustomer"; | |
user.stage = 3; | |
user.stage_try = 4; | |
console.log(user); | |
totoData.registerCustomer(user).then(function(data){ | |
utils.hideLoad(); | |
$scope.data = data; | |
console.log(data); | |
if(!data.fail){ | |
console.log('success'); | |
$rootScope.stopWatch(); | |
$state.go('app.register4', {data: user}); | |
} | |
}, function(err){ | |
utils.hideLoad(); | |
utils.showAlert("Ошибка соединения"); | |
}); | |
}; | |
$scope.back = function(){ | |
$ionicHistory.goBack(); | |
}; | |
}) | |
.controller('register4Ctrl', function($scope, $state, $ionicHistory, utils, totoData) { | |
$scope.user = $state.params.data; | |
console.log($scope.user); | |
$scope.signup4 = function(user){ | |
utils.showLoad(); | |
user.action = "registerCustomer"; | |
user.stage = 4; | |
user.stage_try = 5; | |
console.log(user); | |
totoData.registerCustomer(user).then(function(data){ | |
utils.hideLoad(); | |
$scope.data = data; | |
console.log(data); | |
if(!data.fail){ | |
console.log('success'); | |
$ionicHistory.clearCache(); | |
$ionicHistory.nextViewOptions({ | |
disableBack: true | |
}); | |
$state.go("app.login"); | |
utils.showAlert("Вы успешно зарегистрированы!", "Ваш номер счета - "+ data.id + " (отправлен на ваш телефон) \n Теперь Вы можете войти в систему."); | |
} | |
}, function(err){ | |
utils.hideLoad(); | |
utils.showAlert("Ошибка соединения"); | |
}); | |
}; | |
$scope.back = function(){ | |
$ionicHistory.goBack(); | |
}; | |
}) | |
.controller('register5Ctrl', function($scope, $state, $ionicHistory) { | |
$scope.back = function(){ | |
$ionicHistory.goBack(); | |
}; | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment