PlayerControl.php 4.3 KB

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