PlayerControl.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace app\controller;
  3. use app\BaseController;
  4. use app\model\GameModel;
  5. use app\model\MerchantsUserModel;
  6. use app\model\PlayerControlModel;
  7. use think\facade\Request;
  8. class PlayerControl extends BaseController
  9. {
  10. /**
  11. * 添加或更新 点控设置
  12. * {"account_ids":["115"],"game_ids":[1],"rtp":9900,"max_win_multi":500,"auto_cancel_rtp":100,"agent_id":6027,"win_pro":-1}
  13. */
  14. public function updatePlayerControl()
  15. {
  16. $userInfo = $this->request->userInfo;
  17. $data = Request::param([
  18. 'account_ids' => "",
  19. 'game_ids' => "",
  20. 'rtp' => 0,
  21. 'max_win_multi' => -1,
  22. 'auto_cancel_rtp' => -1
  23. ]);
  24. // 判断RTP
  25. if(empty($data['rtp'])) {
  26. return json_error([], 'RTP错误');
  27. }
  28. $account_ids = $data['account_ids'] ?? "";
  29. $game_ids = $data['game_ids'] ?? "";
  30. // 游戏平台ID和游戏ID不能为空
  31. if(empty($account_ids) || empty($game_ids)) {
  32. return json_error([], '平台ID和游戏ID不能为空');
  33. }
  34. $account_ids = explode(",", $account_ids);
  35. $game_ids = explode(",", $game_ids);
  36. $unameList = [];
  37. foreach ($account_ids as $account_id) {
  38. $account_id = trim($account_id);
  39. if(!empty($account_id)) {
  40. $unameList[] = $account_id;
  41. }
  42. }
  43. $gameList = [];
  44. foreach ($game_ids as $game_id) {
  45. $game_id = trim($game_id);
  46. if(!empty($game_id)) {
  47. $gameList[] = $game_id;
  48. }
  49. }
  50. // 过滤掉 游戏平台ID和游戏ID不能为空
  51. if(empty($unameList) || empty($gameList)) {
  52. return json_error([], '平台ID和游戏ID不能为空');
  53. }
  54. $allGameList = GameModel::getGames($userInfo['merchant_id']);
  55. $gameIds = array_column($allGameList, 'game_id');
  56. $emptyIds = [];
  57. foreach ($gameList as $gameId) {
  58. if(!in_array($gameId, $gameIds)) {
  59. $emptyIds[] = $gameId;
  60. }
  61. }
  62. if(!empty($emptyIds)) {
  63. return json_error([], "不存在游戏:" . implode(", ", $emptyIds));
  64. }
  65. $merchantsUserList = MerchantsUserModel::getPlayerListByIds($userInfo['merchant_id'], $unameList);
  66. $merchantsUserList = array_column($merchantsUserList, null, 'uname');
  67. foreach ($account_ids as $accountId) {
  68. $merchantsUserInfo = $merchantsUserList[$accountId] ?? [];
  69. if(empty($merchantsUserInfo)) {
  70. continue;
  71. }
  72. foreach ($game_ids as $gameId) {
  73. $info = PlayerControlModel::getPlayerControlInfo($userInfo['merchant_id'], $merchantsUserInfo['user_id'], $gameId);
  74. if(!empty($info)) {
  75. // 需要更新
  76. $item = [
  77. 'control_rpt' => $data['rtp'],
  78. 'auto_cancel_rtp' => $data['auto_cancel_rtp'], // 达到RTP值取消
  79. 'max_win_multi' => $data['max_win_multi'], // 最高倍数
  80. ];
  81. }else {
  82. $item = [
  83. 'app_id' => $userInfo['merchant_id'],
  84. 'user_id' => $userInfo['user_id'],
  85. 'player_id' => $merchantsUserInfo['user_id'],// 玩家id
  86. 'game_id' => $gameId,
  87. 'control_rpt' => $data['rtp'],
  88. 'auto_cancel_rtp' => $data['auto_cancel_rtp'], // 达到RTP值取消
  89. 'max_win_multi' => $data['max_win_multi'], // 最高倍数
  90. 'control_balance' => $merchantsUserInfo['balance'], // 设置时点控那刻当前余额
  91. ];
  92. }
  93. print_r($item);
  94. }
  95. }
  96. return json_success([],'操作成功');
  97. }
  98. }