PlatformService.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. namespace App\Game\Services;
  3. use App\Facade\TableName;
  4. use App\Util;
  5. use Illuminate\Support\Facades\Redis;
  6. use Illuminate\Support\Facades\DB;
  7. class PlatformService
  8. {
  9. public static function platformBet($platform, $game, $bet, $uid)
  10. {
  11. self::platformAllBet($platform, $bet);
  12. self::platformDayBet($platform, $bet);
  13. if ($game)
  14. self::platformSubDayBet($platform, $game, $bet);
  15. if ($bet > 0) {
  16. self::platformDayPlay($platform, $uid);
  17. if ($game)
  18. self::platformSubDayPlay($platform, $game, $uid);
  19. }
  20. return true;
  21. }
  22. public static function platformWin($UserID, $platform, $game, $win, $bet, $score = 0, $addScore = true)
  23. {
  24. self::userPlatformWin($platform, $UserID, $win - $bet);
  25. $time = time();
  26. $strUniqueCode = "$platform|$game";
  27. $gameid = ['atmosfera' => 81, 'betby' => 80, 'PP' => 83,'pp' => 83, 'pg' => 84, 'only' => 85, 'aviatrix' => 86,'luckystreak'=>87][$platform] . (is_numeric($game) ? $game : 0);
  28. $lBeforeScore = $score - $win;
  29. $lChangeScore = $win - $bet;
  30. try {
  31. $dbh = DB::connection()->getPdo();
  32. $stmt = $dbh->prepare("exec QPTreasureDB.dbo.GSP_GR_RecordScoreInfo $UserID,$lBeforeScore,$lChangeScore,$gameid,0,'$strUniqueCode'");
  33. $stmt->execute();
  34. } catch (\Exception $exception) {
  35. Util::WriteLog('pw', $exception->getMessage() . "\nexec QPTreasureDB.dbo.GSP_GR_RecordScoreInfo $UserID,$lBeforeScore,$lChangeScore,$gameid,0,'$strUniqueCode'");
  36. }
  37. // if($win<=0){
  38. // return false;
  39. // }
  40. if ($addScore && $win > 0) {
  41. DB::connection('write')->table('QPTreasureDB.dbo.GameScoreInfo')->where('UserID', $UserID)->increment('Score', $win);
  42. }
  43. if ($bet) {
  44. // $addDraw = $win-$bet;
  45. $addDraw = floor($bet / 5);
  46. //用户输赢数据
  47. // 增加可提额度
  48. if ($totalData = DB::table(TableName::QPRecordDB() . 'RecordUserTotalStatistics')->where('UserID', $UserID)->exists()) {
  49. // if($totalData->DrawBase+$addDraw>$score){
  50. // $addDraw = max($score - $totalData->DrawBase,0);
  51. // }
  52. // DB::table(TableName::QPRecordDB() . 'RecordUserTotalStatistics')->where('UserID', $UserID)->increment('DrawBase', $addDraw);
  53. DB::table(TableName::QPRecordDB() . 'RecordUserTotalStatistics')->where('UserID', $UserID)->increment('DrawBase', $addDraw);
  54. DB::table(TableName::QPRecordDB() . 'RecordUserTotalStatistics')->where('UserID', $UserID)->increment('TotalBet', $bet);
  55. } else {
  56. // DB::table(TableName::QPRecordDB() . 'RecordUserTotalStatistics')->insert(['UserID' => $UserID, 'DrawBase' => $addDraw]);
  57. DB::table(TableName::QPRecordDB() . 'RecordUserTotalStatistics')->insert(['UserID' => $UserID, 'DrawBase' => $addDraw, 'TotalBet' => $bet]);
  58. }
  59. // $draw_base = intval(($win-$bet) * 0.08);
  60. $draw_base = intval(($win - $bet) * 0.1);
  61. if ($draw_base > 0)
  62. DB::table(TableName::QPRecordDB() . 'RecordUserTotalStatistics')->where('UserID', $UserID)->increment('Revenue', $draw_base);
  63. }
  64. if ($win <= 0) {
  65. return false;
  66. }
  67. self::platformAllWin($platform, $win);
  68. self::platformDayWin($platform, $win);
  69. self::platformSubDayWin($platform, $game, $win);
  70. return true;
  71. }
  72. /**
  73. * 总下注
  74. * @param $platform
  75. * @param $bet
  76. * @return void
  77. */
  78. ###########平台总数据##################
  79. public static function platformAllBet($platform, $bet)
  80. {
  81. $key = 'platform_' . $platform . '_bet';
  82. return self::incrementOrSet($key, $bet);
  83. }
  84. public static function platformAllWin($platform, $win)
  85. {
  86. $key = 'platform_' . $platform . '_win';
  87. return self::incrementOrSet($key, $win);
  88. }
  89. ###########平台每天数据################
  90. public static function platformDayBet($platform, $bet)
  91. {
  92. $key = 'platform_' . $platform . '_bet_' . date('Ymd');
  93. return self::incrementOrSet($key, $bet, 86400 * 2);
  94. }
  95. public static function platformDayWin($platform, $win)
  96. {
  97. $key = 'platform_' . $platform . '_win_' . date('Ymd');
  98. return self::incrementOrSet($key, $win, 86400 * 2);
  99. }
  100. public static function platformDayPlay($platform, $uid)
  101. {
  102. $playKey = 'platform_' . $platform . '_play_' . $uid . '_' . date('Ymd');
  103. if (!Redis::exists($playKey)) {
  104. Redis::set($playKey, 1);
  105. Redis::expire($playKey, 86400 * 2);
  106. $key = 'platform_' . $platform . '_play_' . date('Ymd');
  107. self::incrementOrSet($key, 1, 86400 * 2);
  108. }
  109. return true;
  110. }
  111. ###########平台子游戏每天数据################
  112. public static function platformSubDayBet($platform, $game, $bet)
  113. {
  114. $key = 'platform_' . $platform . '_' . $game . '_bet_' . date('Ymd');
  115. return self::incrementOrSet($key, $bet, 86400 * 2);
  116. }
  117. public static function platformSubDayWin($platform, $game, $win)
  118. {
  119. $key = 'platform_' . $platform . '_' . $game . '_win_' . date('Ymd');
  120. return self::incrementOrSet($key, $win, 86400 * 2);
  121. }
  122. public static function platformSubDayPlay($platform, $game, $uid)
  123. {
  124. $playKey = 'platform_' . $platform . '_' . $game . '_play_' . $uid . '_' . date('Ymd');
  125. if (!Redis::exists($playKey)) {
  126. Redis::set($playKey, 1);
  127. Redis::expire($playKey, 86400 * 2);
  128. $key = 'platform_' . $platform . '_' . $game . '_play_' . date('Ymd');
  129. self::incrementOrSet($key, 1, 86400 * 2);
  130. }
  131. return true;
  132. }
  133. public static function userPlatformWin($platform, $uid, $win)
  134. {
  135. $dkey = 'platform_' . $platform . '_' . $uid . '_win_' . date('Ymd');
  136. self::incrementOrSet($dkey, $win, 86400 * 2);
  137. $key = 'platform_' . $platform . '_' . $uid . '_win';
  138. self::incrementOrSet($key, $win);
  139. return true;
  140. }
  141. public static function incrementOrSet($key, $value, $expired = 0)
  142. {
  143. // 使用 Redis::exists 检查键是否存在
  144. if (Redis::exists($key)) {
  145. // 键存在,使用 Redis::incrby 增加相应的数值(如果 $value 是负数,则减少)
  146. Redis::incrby($key, $value);
  147. } else {
  148. // 键不存在,使用 Redis::set 设置为当前值
  149. Redis::set($key, $value);
  150. if ($expired) {
  151. Redis::expire($key, $expired);
  152. }
  153. }
  154. // 返回当前键的值
  155. return Redis::get($key);
  156. }
  157. }