PlayerControl.php 4.4 KB

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