GoldLogic.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <?php
  2. namespace App\Http\logic\admin;
  3. use App\Http\helper\HttpCurl;
  4. use App\Http\helper\NumConfig;
  5. use App\Http\logic\api\BaseApiLogic;
  6. use Illuminate\Support\Facades\DB;
  7. class GoldLogic extends BaseApiLogic
  8. {
  9. // 同步库存
  10. public function sync_stock($serverID)
  11. {
  12. $admin = session('admin');
  13. $account = $admin->account ?: '';
  14. $password = $admin->password ?: '';
  15. if (empty($serverID)) {
  16. $this->error = '缺少参数游戏ID';
  17. return false;
  18. }
  19. $url = config('transfer.stock')['url'] . 'getStock';
  20. $data = [
  21. 'accounts' => $account,
  22. 'passworld' => $password,
  23. 'serverID' => $serverID
  24. ];
  25. $build_query = $url . '?' . http_build_query($data);
  26. $json_decode = (new HttpCurl())->curl_get($build_query);
  27. $output = !empty($json_decode) ? \GuzzleHttp\json_decode($json_decode, true) : '';
  28. if (is_array($output)) {
  29. if ($output['code'] != 200) {
  30. $this->error = $output['msg'];
  31. return false;
  32. }
  33. if ($serverID != $output['data']['server_id']) {
  34. $this->error = '游戏ID错误';
  35. return false;
  36. }
  37. $output['data']['stock'] = number_float($output['data']['stock'] / NumConfig::NUM_VALUE);
  38. $output['data']['revenue'] = number_float($output['data']['revenue'] / NumConfig::NUM_VALUE);
  39. $data = $output['data'];
  40. return apiReturnSuc($data);
  41. } else {
  42. $this->error = '更新库存失败';
  43. return false;
  44. }
  45. }
  46. // 更新库存
  47. public function update_stock($serverID,$score)
  48. {
  49. $admin = session('admin');
  50. $account = $admin->account ?: '';
  51. $password = $admin->password ?: '';
  52. if (empty($serverID)) {
  53. $this->error = '缺少参数游戏ID';
  54. return false;
  55. }
  56. $url = config('transfer.stock')['url'] . 'addStock';
  57. $data = [
  58. 'accounts' => $account,
  59. 'passworld' => $password,
  60. 'serverid' => $serverID,
  61. 'score' => $score
  62. ];
  63. $build_query = $url . '?' . http_build_query($data);
  64. $json_decode = (new HttpCurl())->curl_get($build_query);
  65. if (empty($json_decode)) {
  66. $this->error = '服务端更新库存失败!';
  67. return false;
  68. }
  69. $output = \GuzzleHttp\json_decode($json_decode, true);
  70. if (is_array($output)) {
  71. if ($output['code'] != 200) {
  72. $this->error = $output['msg'];
  73. return false;
  74. }
  75. if ($serverID != $output['data']['server_id']) {
  76. $this->error = '游戏ID错误';
  77. return false;
  78. }
  79. $data = $output['data'];
  80. return $data;
  81. } else {
  82. $this->error = '更新库存失败';
  83. return false;
  84. }
  85. }
  86. /**
  87. * 游戏控制
  88. * @param array $where // 搜索条件
  89. * @param array $ServerIDs // 试玩场搜索条件
  90. * @param bool $demo true=>试玩场 false => 正式场
  91. * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|\Illuminate\Pagination\LengthAwarePaginator\
  92. */
  93. public function gameConfigList($where, $ServerIDs, $demo = false)
  94. {
  95. $filed = ['gi.GameID', 'gi.ServerID as gi_ServerID', 'gri.Nullity','gi.ServerName', 'gi.RoomStock', 'ki.KindName', 'ki.KindID', 'si.*'];
  96. // 试玩场
  97. $sql = DB::connection('read')->table('QPPlatformDB.dbo.GameRoomInfo as gi')
  98. ->join('QPPlatformDB.dbo.GameRoomInfo as gri', function ($join){
  99. $join->on('gi.ServerID', 'gri.ServerID');
  100. });
  101. $list = $sql
  102. ->leftJoin('QPPlatformDB.dbo.GameKindItem as ki', 'ki.GameID', '=', 'gi.GameID')
  103. ->leftJoin('QPTreasureDB.dbo.StockConfigInfo as si', 'gi.ServerID', 'si.ServerID')
  104. ->select($filed)
  105. ->where($where)
  106. ->whereIn('gi.GameID',$ServerIDs)
  107. ->orderBy('gi.GameID', 'asc')
  108. ->orderBy('gi.ServerName', 'asc')
  109. ->paginate(10);
  110. $allRevenue = DB::connection('read')->table('QPRecordDB.dbo.RecordGameInfo')->selectRaw('ServerID,sum(Revenue) as Revenue')->groupBy('ServerID')->pluck('Revenue', 'ServerID')->toArray();
  111. foreach ($list as &$val) {
  112. $ServerID = $val->gi_ServerID;
  113. // 房间累计税收
  114. $Revenue = 0;
  115. if (array_key_exists($ServerID, $allRevenue)) {
  116. $Revenue = $allRevenue[$ServerID];
  117. }
  118. $val->Revenue = number_float($Revenue / 100);
  119. // 当前触发概率
  120. $to_arr = explode(';', rtrim($val->RoomStock, ';'));
  121. // 暗税
  122. $darkRevenue = (isset($to_arr[0]) && !empty($to_arr[0]) && $val->GameID == 1005) ? explode(':', $to_arr[1])[1] : 0;
  123. if (isset($to_arr[0]) && !empty($to_arr[0])) {
  124. $stock = explode(':', $to_arr[0])[1];
  125. } else {
  126. $stock = 0;
  127. }
  128. $val->RoomStock = number_float($stock / 100);
  129. $val->darkRevenue = number_float($darkRevenue / 100);
  130. /*
  131. * 库存 / 档位
  132. * 大于0 倍数 * 输基础概率值 + 输的初始概率值 比较最大输的值 取最小
  133. * 等于 0
  134. * 小于0 倍数 * 赢基础概率值 + 赢的初始概率值 比较最大赢的值 取最小
  135. * */
  136. // 取反
  137. if ($stock < 0) {
  138. $stock1 = -$stock;
  139. } else {
  140. $stock1 = $stock;
  141. }
  142. if ($val->BaseScore && $stock1 > $val->BaseScore) {
  143. $res = floor($stock / $val->BaseScore);
  144. switch ($res) {
  145. case $res > 0:
  146. $lost = $res * $val->LostBasePercent + $val->LostInitPercent;
  147. if ($lost > $val->LostMaxPercent) {
  148. $val->gailv = $val->LostMaxPercent;
  149. } else {
  150. $val->gailv = $lost;
  151. }
  152. break;
  153. case $res == 0:
  154. $val->gailv = 0;
  155. break;
  156. case $res < 0:
  157. $win = -$res * $val->WinBasePercent + $val->WinInitPercent;
  158. if ($win > $val->WinMaxPercent) {
  159. $val->gailv = $val->WinMaxPercent;
  160. } else {
  161. $val->gailv = $win;
  162. }
  163. }
  164. $val->gailv = number_float($val->gailv);
  165. } else {
  166. $val->gailv = '';
  167. }
  168. $val->BaseScore = $val->BaseScore > 0 ? number_float($val->BaseScore / 100) : '';
  169. }
  170. return $list;
  171. }
  172. }