Authored by 陈轩

fix 拼手气 coin显示逻辑

@@ -103,6 +103,7 @@ exports.crazyLuck = (req, res, next) => { @@ -103,6 +103,7 @@ exports.crazyLuck = (req, res, next) => {
103 pageStyle: 'vip-day game', 103 pageStyle: 'vip-day game',
104 isLuck: true, 104 isLuck: true,
105 coin: coins && coins.data && (coins.data.total > 9999 ? (coins.data.total / 10000).toFixed(2) + '万' : coins.data.total), 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,
106 joinNum: joinNum && joinNum.data || 0, 107 joinNum: joinNum && joinNum.data || 0,
107 }); 108 });
108 })().catch(next); 109 })().catch(next);
@@ -198,7 +199,11 @@ exports.luckResult = (req, res, next) => { @@ -198,7 +199,11 @@ exports.luckResult = (req, res, next) => {
198 // 得出 中奖结果 199 // 得出 中奖结果
199 let result = yield vipDayModel.addPrizeLog(uid, prize_type); 200 let result = yield vipDayModel.addPrizeLog(uid, prize_type);
200 201
201 - Object.assign(result, { coin: coin - cost }); 202 + if (result.code !== 200) {
  203 + return result;
  204 + }
  205 +
  206 + Object.assign(result, { coin: coin - cost + result.data });
202 return result; 207 return result;
203 }); 208 });
204 209
@@ -41,5 +41,6 @@ @@ -41,5 +41,6 @@
41 </div> 41 </div>
42 42
43 <script> 43 <script>
  44 + var coin = {{coinNum}};
44 var joinNum = {{joinNum}}; 45 var joinNum = {{joinNum}};
45 </script> 46 </script>
@@ -19,6 +19,7 @@ var Game = function(elem, config) { @@ -19,6 +19,7 @@ var Game = function(elem, config) {
19 // 注入 19 // 注入
20 this.awards = null; 20 this.awards = null;
21 this.success = $.noop; 21 this.success = $.noop;
  22 + this.onstart = $.noop;
22 23
23 $.extend(this, config); 24 $.extend(this, config);
24 25
@@ -38,6 +39,7 @@ Game.prototype.bindEvents = function() { @@ -38,6 +39,7 @@ Game.prototype.bindEvents = function() {
38 } 39 }
39 40
40 self.canPlay = false; 41 self.canPlay = false;
  42 + self.onstart();
41 self.getResult() 43 self.getResult()
42 .done(function(res) { 44 .done(function(res) {
43 var awardIndex; 45 var awardIndex;
@@ -49,6 +49,7 @@ function getAwards($container) { @@ -49,6 +49,7 @@ function getAwards($container) {
49 49
50 50
51 $(function() { 51 $(function() {
  52 + var gCoin = window.coin;
52 var $coin = $('#my-coin'); 53 var $coin = $('#my-coin');
53 var $awardsModal = $('#js-awards'); 54 var $awardsModal = $('#js-awards');
54 var $playerNum = $('#player-num'); 55 var $playerNum = $('#player-num');
@@ -65,12 +66,20 @@ $(function() { @@ -65,12 +66,20 @@ $(function() {
65 $playerNum.text(window.joinNum); 66 $playerNum.text(window.joinNum);
66 } 67 }
67 68
  69 + function setCoins(count) {
  70 + $coin.text(coinNumReadable(count));
  71 + }
  72 +
68 setInterval(function() { 73 setInterval(function() {
69 var up = Math.floor(Math.random() * 5); 74 var up = Math.floor(Math.random() * 5);
70 75
71 upPlayers(up); 76 upPlayers(up);
72 }, 5000); 77 }, 5000);
73 78
  79 + game.onstart = function() {
  80 + setCoins(gCoin - 20);
  81 + };
  82 +
74 game.success = function(score, coin) { 83 game.success = function(score, coin) {
75 var content = score === 0 ? '很遗憾您没有中奖,继续加油哦~' : '<p class="primary">恭喜你获得<span class="award">' + score + '</span>个有货币,请到【我的奖品】中查收</p>'; 84 var content = score === 0 ? '很遗憾您没有中奖,继续加油哦~' : '<p class="primary">恭喜你获得<span class="award">' + score + '</span>个有货币,请到【我的奖品】中查收</p>';
76 85
@@ -79,7 +88,7 @@ $(function() { @@ -79,7 +88,7 @@ $(function() {
79 content: content 88 content: content
80 }); 89 });
81 90
82 - $coin.text(coinNumReadable(coin)); 91 + setCoins(gCoin = coin);
83 upPlayers(1); 92 upPlayers(1);
84 }; 93 };
85 94