Authored by 陈轩

fix

... ... @@ -6,6 +6,15 @@ const vipDayModel = require('../models/vipDay');
const auth = require('../../passport/models/auth-helper');
const co = require('bluebird').coroutine;
function humanNum_wan(num) {
if (num > 9999) {
num = (num / 10000).toFixed(2) + '万'
}
return num;
}
exports.beforeIn = (req, res, next) => {
// 将APP登录状态正常化
if (req.yoho.isApp && req.query.uid) {
... ... @@ -78,11 +87,14 @@ exports.crazyWheel = (req, res, next) => {
}
vipDayModel.getJoinNum(1).then(result => {
let joins = result && result.data || 0;
res.render('vip_day/crazy_wheel', {
title: '疯狂大转盘',
pageStyle: 'vip-day game',
isWheel: true,
joinNum: result && result.data || 0,
joins: humanNum_wan(joins),
joinNum: joins
});
});
};
... ... @@ -98,13 +110,17 @@ exports.crazyLuck = (req, res, next) => {
let coins = yield vipDayModel.getCoins(uid);
let joinNum = yield vipDayModel.getJoinNum(2);
coins = (coins && coins.data && coins.data.total) || 0;
joinNum = (joinNum && joinNum.data) || 0
res.render('vip_day/crazy_luck', {
title: '拼手气',
pageStyle: 'vip-day game',
isLuck: true,
coin: coins && coins.data && (coins.data.total > 9999 ? (coins.data.total / 10000).toFixed(2) + '万' : coins.data.total),
coinNum: (coins && coins.data && coins.data.total) || 0,
joinNum: joinNum && joinNum.data || 0,
coins: humanNum_wan(coins),
coinNum: coins,
joins: humanNum_wan(joinNum),
joinNum: joinNum,
});
})().catch(next);
};
... ...
... ... @@ -6,14 +6,14 @@
<div class="my-icon-label">
<i class="small-icon"></i><span>我的有货币</span>
</div>
<span id="my-coin" class="game-val game-rect">{{coin}}</span>
<span id="my-coin" class="game-val game-rect">{{coins}}</span>
</div>
<div class="info-item">
<button id="my-award" class="game-btn my-award" type="button" data-toggle="ymodal" data-target="#js-awards">我的奖品</button>
</div>
<div class="info-item player-num">
<div>
已有:<span id="player-num" class="player-num-val">{{joinNum}}</span>
已有:<span id="player-num" class="player-num-val">{{joins}}</span>
</div>
<span>参加抽奖</span>
</div>
... ...
... ... @@ -3,7 +3,7 @@
{{> vip_day/game-main}}
<div class="info">
<div class="info-item">
已有<span class="game-val game-rect">{{joinNum}}</span>人参与抽奖
已有<span class="game-val game-rect" id="js-join-num">{{joins}}</span>人参与抽奖
</div>
</div>
<div class="explain">
... ... @@ -16,3 +16,7 @@
</div>
</div>
</div>
<script>
var joinNum = {{joinNum}};
</script>
... ...
... ... @@ -18,7 +18,7 @@ var Game = function(elem, config) {
// 注入
this.awards = null;
this.success = $.noop;
this.onsuccess = $.noop;
this.onstart = $.noop;
$.extend(this, config);
... ... @@ -50,7 +50,7 @@ Game.prototype.bindEvents = function() {
}
awardIndex = self.awards.indexOf(res.data) + 1;
self._anim(awardIndex, self.onsuccess, res.coin);
self._anim(awardIndex, res.coin);
})
.fail(function(error) {
tip.show(error.message);
... ... @@ -63,7 +63,7 @@ Game.prototype.getResult = function() {
return $.post(this.url);
};
Game.prototype._anim = function(stopLocation, success, coin) {
Game.prototype._anim = function(stopLocation, coin) {
var self = this;
var s1 = this.s + stopLocation - this.location + 1;
var startTime = Date.now();
... ... @@ -86,7 +86,6 @@ Game.prototype._anim = function(stopLocation, success, coin) {
console.log(newLocation);
setActive(newLocation);
if (p >= 1.0) {
p = 1;
... ... @@ -94,7 +93,7 @@ Game.prototype._anim = function(stopLocation, success, coin) {
setActive(stopLocation); // 保证落在正确的位置
self.timer = null;
self.location = stopLocation;
self.success(self.awards[stopLocation - 1], coin);
self.onsuccess(self.awards[stopLocation - 1], coin);
self.canPlay = true;
}
... ...
... ... @@ -82,7 +82,7 @@ $(function() {
}
};
game.success = function(score, coin) {
game.onsuccess = function(score, coin) {
var content = score === 0 ? '很遗憾您没有中奖,继续加油哦~' : '<p class="primary">恭喜你获得<span class="award">' + score + '</span>个有货币,请到【我的奖品】中查收</p>';
$.yAlert({
... ...
... ... @@ -9,13 +9,34 @@ window.$ = $;
$(function() {
var $gameNotify = $('#js-game-notify');
var $playerNum = $('#js-join-num');
var game = new Game('#js-stage', {
url: '/activity/vip-day/crazy-wheel/award.json?app_version=1&uid=' + yoho.getUid(),
awards: [50, 5, 10, 100, 20, 28, 1, 80]
});
game.success = function(score) {
function numReadable(num) {
if (num > 9999) {
num = (num / 10000).toFixed(2) + '万';
}
return num;
}
function upPlayers(up) {
window.joinNum += up;
$playerNum.text(numReadable(window.joinNum));
}
setInterval(function() {
var up = Math.floor(Math.random() * 5);
upPlayers(up);
}, 5000);
game.onsuccess = function(score) {
console.log(score);
upPlayers(1);
$.yAlert({
class: 'vipday-game-alert',
content: '<p class="primary">恭喜你获得<span class="award">' + score + '</span>元优惠券,请到【我的-优惠券】中查收奖品</p>'
... ...