Showing
6 changed files
with
54 additions
and
14 deletions
| @@ -6,6 +6,15 @@ const vipDayModel = require('../models/vipDay'); | @@ -6,6 +6,15 @@ const vipDayModel = require('../models/vipDay'); | ||
| 6 | const auth = require('../../passport/models/auth-helper'); | 6 | const auth = require('../../passport/models/auth-helper'); |
| 7 | const co = require('bluebird').coroutine; | 7 | const co = require('bluebird').coroutine; |
| 8 | 8 | ||
| 9 | + | ||
| 10 | +function humanNum_wan(num) { | ||
| 11 | + if (num > 9999) { | ||
| 12 | + num = (num / 10000).toFixed(2) + '万' | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + return num; | ||
| 16 | +} | ||
| 17 | + | ||
| 9 | exports.beforeIn = (req, res, next) => { | 18 | exports.beforeIn = (req, res, next) => { |
| 10 | // 将APP登录状态正常化 | 19 | // 将APP登录状态正常化 |
| 11 | if (req.yoho.isApp && req.query.uid) { | 20 | if (req.yoho.isApp && req.query.uid) { |
| @@ -78,11 +87,14 @@ exports.crazyWheel = (req, res, next) => { | @@ -78,11 +87,14 @@ exports.crazyWheel = (req, res, next) => { | ||
| 78 | } | 87 | } |
| 79 | 88 | ||
| 80 | vipDayModel.getJoinNum(1).then(result => { | 89 | vipDayModel.getJoinNum(1).then(result => { |
| 90 | + let joins = result && result.data || 0; | ||
| 91 | + | ||
| 81 | res.render('vip_day/crazy_wheel', { | 92 | res.render('vip_day/crazy_wheel', { |
| 82 | title: '疯狂大转盘', | 93 | title: '疯狂大转盘', |
| 83 | pageStyle: 'vip-day game', | 94 | pageStyle: 'vip-day game', |
| 84 | isWheel: true, | 95 | isWheel: true, |
| 85 | - joinNum: result && result.data || 0, | 96 | + joins: humanNum_wan(joins), |
| 97 | + joinNum: joins | ||
| 86 | }); | 98 | }); |
| 87 | }); | 99 | }); |
| 88 | }; | 100 | }; |
| @@ -98,13 +110,17 @@ exports.crazyLuck = (req, res, next) => { | @@ -98,13 +110,17 @@ exports.crazyLuck = (req, res, next) => { | ||
| 98 | let coins = yield vipDayModel.getCoins(uid); | 110 | let coins = yield vipDayModel.getCoins(uid); |
| 99 | let joinNum = yield vipDayModel.getJoinNum(2); | 111 | let joinNum = yield vipDayModel.getJoinNum(2); |
| 100 | 112 | ||
| 113 | + coins = (coins && coins.data && coins.data.total) || 0; | ||
| 114 | + joinNum = (joinNum && joinNum.data) || 0 | ||
| 115 | + | ||
| 101 | res.render('vip_day/crazy_luck', { | 116 | res.render('vip_day/crazy_luck', { |
| 102 | title: '拼手气', | 117 | title: '拼手气', |
| 103 | pageStyle: 'vip-day game', | 118 | pageStyle: 'vip-day game', |
| 104 | isLuck: true, | 119 | isLuck: true, |
| 105 | - coin: coins && coins.data && (coins.data.total > 9999 ? (coins.data.total / 10000).toFixed(2) + '万' : coins.data.total), | ||
| 106 | - coinNum: (coins && coins.data && coins.data.total) || 0, | ||
| 107 | - joinNum: joinNum && joinNum.data || 0, | 120 | + coins: humanNum_wan(coins), |
| 121 | + coinNum: coins, | ||
| 122 | + joins: humanNum_wan(joinNum), | ||
| 123 | + joinNum: joinNum, | ||
| 108 | }); | 124 | }); |
| 109 | })().catch(next); | 125 | })().catch(next); |
| 110 | }; | 126 | }; |
| @@ -6,14 +6,14 @@ | @@ -6,14 +6,14 @@ | ||
| 6 | <div class="my-icon-label"> | 6 | <div class="my-icon-label"> |
| 7 | <i class="small-icon"></i><span>我的有货币</span> | 7 | <i class="small-icon"></i><span>我的有货币</span> |
| 8 | </div> | 8 | </div> |
| 9 | - <span id="my-coin" class="game-val game-rect">{{coin}}</span> | 9 | + <span id="my-coin" class="game-val game-rect">{{coins}}</span> |
| 10 | </div> | 10 | </div> |
| 11 | <div class="info-item"> | 11 | <div class="info-item"> |
| 12 | <button id="my-award" class="game-btn my-award" type="button" data-toggle="ymodal" data-target="#js-awards">我的奖品</button> | 12 | <button id="my-award" class="game-btn my-award" type="button" data-toggle="ymodal" data-target="#js-awards">我的奖品</button> |
| 13 | </div> | 13 | </div> |
| 14 | <div class="info-item player-num"> | 14 | <div class="info-item player-num"> |
| 15 | <div> | 15 | <div> |
| 16 | - 已有:<span id="player-num" class="player-num-val">{{joinNum}}</span>人 | 16 | + 已有:<span id="player-num" class="player-num-val">{{joins}}</span>人 |
| 17 | </div> | 17 | </div> |
| 18 | <span>参加抽奖</span> | 18 | <span>参加抽奖</span> |
| 19 | </div> | 19 | </div> |
| @@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
| 3 | {{> vip_day/game-main}} | 3 | {{> vip_day/game-main}} |
| 4 | <div class="info"> | 4 | <div class="info"> |
| 5 | <div class="info-item"> | 5 | <div class="info-item"> |
| 6 | - 已有<span class="game-val game-rect">{{joinNum}}</span>人参与抽奖 | 6 | + 已有<span class="game-val game-rect" id="js-join-num">{{joins}}</span>人参与抽奖 |
| 7 | </div> | 7 | </div> |
| 8 | </div> | 8 | </div> |
| 9 | <div class="explain"> | 9 | <div class="explain"> |
| @@ -16,3 +16,7 @@ | @@ -16,3 +16,7 @@ | ||
| 16 | </div> | 16 | </div> |
| 17 | </div> | 17 | </div> |
| 18 | </div> | 18 | </div> |
| 19 | + | ||
| 20 | +<script> | ||
| 21 | + var joinNum = {{joinNum}}; | ||
| 22 | +</script> |
| @@ -18,7 +18,7 @@ var Game = function(elem, config) { | @@ -18,7 +18,7 @@ var Game = function(elem, config) { | ||
| 18 | 18 | ||
| 19 | // 注入 | 19 | // 注入 |
| 20 | this.awards = null; | 20 | this.awards = null; |
| 21 | - this.success = $.noop; | 21 | + this.onsuccess = $.noop; |
| 22 | this.onstart = $.noop; | 22 | this.onstart = $.noop; |
| 23 | 23 | ||
| 24 | $.extend(this, config); | 24 | $.extend(this, config); |
| @@ -50,7 +50,7 @@ Game.prototype.bindEvents = function() { | @@ -50,7 +50,7 @@ Game.prototype.bindEvents = function() { | ||
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | awardIndex = self.awards.indexOf(res.data) + 1; | 52 | awardIndex = self.awards.indexOf(res.data) + 1; |
| 53 | - self._anim(awardIndex, self.onsuccess, res.coin); | 53 | + self._anim(awardIndex, res.coin); |
| 54 | }) | 54 | }) |
| 55 | .fail(function(error) { | 55 | .fail(function(error) { |
| 56 | tip.show(error.message); | 56 | tip.show(error.message); |
| @@ -63,7 +63,7 @@ Game.prototype.getResult = function() { | @@ -63,7 +63,7 @@ Game.prototype.getResult = function() { | ||
| 63 | return $.post(this.url); | 63 | return $.post(this.url); |
| 64 | }; | 64 | }; |
| 65 | 65 | ||
| 66 | -Game.prototype._anim = function(stopLocation, success, coin) { | 66 | +Game.prototype._anim = function(stopLocation, coin) { |
| 67 | var self = this; | 67 | var self = this; |
| 68 | var s1 = this.s + stopLocation - this.location + 1; | 68 | var s1 = this.s + stopLocation - this.location + 1; |
| 69 | var startTime = Date.now(); | 69 | var startTime = Date.now(); |
| @@ -86,7 +86,6 @@ Game.prototype._anim = function(stopLocation, success, coin) { | @@ -86,7 +86,6 @@ Game.prototype._anim = function(stopLocation, success, coin) { | ||
| 86 | console.log(newLocation); | 86 | console.log(newLocation); |
| 87 | 87 | ||
| 88 | setActive(newLocation); | 88 | setActive(newLocation); |
| 89 | - | ||
| 90 | 89 | ||
| 91 | if (p >= 1.0) { | 90 | if (p >= 1.0) { |
| 92 | p = 1; | 91 | p = 1; |
| @@ -94,7 +93,7 @@ Game.prototype._anim = function(stopLocation, success, coin) { | @@ -94,7 +93,7 @@ Game.prototype._anim = function(stopLocation, success, coin) { | ||
| 94 | setActive(stopLocation); // 保证落在正确的位置 | 93 | setActive(stopLocation); // 保证落在正确的位置 |
| 95 | self.timer = null; | 94 | self.timer = null; |
| 96 | self.location = stopLocation; | 95 | self.location = stopLocation; |
| 97 | - self.success(self.awards[stopLocation - 1], coin); | 96 | + self.onsuccess(self.awards[stopLocation - 1], coin); |
| 98 | 97 | ||
| 99 | self.canPlay = true; | 98 | self.canPlay = true; |
| 100 | } | 99 | } |
| @@ -82,7 +82,7 @@ $(function() { | @@ -82,7 +82,7 @@ $(function() { | ||
| 82 | } | 82 | } |
| 83 | }; | 83 | }; |
| 84 | 84 | ||
| 85 | - game.success = function(score, coin) { | 85 | + game.onsuccess = function(score, coin) { |
| 86 | var content = score === 0 ? '很遗憾您没有中奖,继续加油哦~' : '<p class="primary">恭喜你获得<span class="award">' + score + '</span>个有货币,请到【我的奖品】中查收</p>'; | 86 | var content = score === 0 ? '很遗憾您没有中奖,继续加油哦~' : '<p class="primary">恭喜你获得<span class="award">' + score + '</span>个有货币,请到【我的奖品】中查收</p>'; |
| 87 | 87 | ||
| 88 | $.yAlert({ | 88 | $.yAlert({ |
| @@ -9,13 +9,34 @@ window.$ = $; | @@ -9,13 +9,34 @@ window.$ = $; | ||
| 9 | 9 | ||
| 10 | $(function() { | 10 | $(function() { |
| 11 | var $gameNotify = $('#js-game-notify'); | 11 | var $gameNotify = $('#js-game-notify'); |
| 12 | + var $playerNum = $('#js-join-num'); | ||
| 12 | var game = new Game('#js-stage', { | 13 | var game = new Game('#js-stage', { |
| 13 | url: '/activity/vip-day/crazy-wheel/award.json?app_version=1&uid=' + yoho.getUid(), | 14 | url: '/activity/vip-day/crazy-wheel/award.json?app_version=1&uid=' + yoho.getUid(), |
| 14 | awards: [50, 5, 10, 100, 20, 28, 1, 80] | 15 | awards: [50, 5, 10, 100, 20, 28, 1, 80] |
| 15 | }); | 16 | }); |
| 16 | 17 | ||
| 17 | - game.success = function(score) { | 18 | + function numReadable(num) { |
| 19 | + if (num > 9999) { | ||
| 20 | + num = (num / 10000).toFixed(2) + '万'; | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + return num; | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + function upPlayers(up) { | ||
| 27 | + window.joinNum += up; | ||
| 28 | + $playerNum.text(numReadable(window.joinNum)); | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + setInterval(function() { | ||
| 32 | + var up = Math.floor(Math.random() * 5); | ||
| 33 | + | ||
| 34 | + upPlayers(up); | ||
| 35 | + }, 5000); | ||
| 36 | + | ||
| 37 | + game.onsuccess = function(score) { | ||
| 18 | console.log(score); | 38 | console.log(score); |
| 39 | + upPlayers(1); | ||
| 19 | $.yAlert({ | 40 | $.yAlert({ |
| 20 | class: 'vipday-game-alert', | 41 | class: 'vipday-game-alert', |
| 21 | content: '<p class="primary">恭喜你获得<span class="award">' + score + '</span>元优惠券,请到【我的-优惠券】中查收奖品</p>' | 42 | content: '<p class="primary">恭喜你获得<span class="award">' + score + '</span>元优惠券,请到【我的-优惠券】中查收奖品</p>' |
-
Please register or login to post a comment