PlayerControl.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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'], [
  68. ['uname', 'in', $unameList]
  69. ]);
  70. $merchantsUserList = array_column($merchantsUserList, null, 'uname');
  71. $merchantsUserIds = array_column($merchantsUserList, 'user_id');
  72. $userBalanceList = CommonMerchantUserAndBalance::getMerchantUserBalance($merchantsUserIds);
  73. $userBalanceList = array_column($userBalanceList, null, 'user_id');
  74. foreach ($account_ids as $accountId) {
  75. $merchantsUserInfo = $merchantsUserList[$accountId] ?? [];
  76. if(empty($merchantsUserInfo)) {
  77. continue;
  78. }
  79. $user_id = $merchantsUserInfo['user_id'];
  80. $rtpGameLIst = CommonMerchantUserAndBalance::getMerchantUserGameRtpWinBetInfo([
  81. ['user_id', '=' , $user_id],
  82. ['game_id', 'in', $gameIds],
  83. ], ['rtp','game_id']);
  84. $gameRtp = [];
  85. foreach ($rtpGameLIst as $item) {
  86. $gameRtp[$item['game_id']] = $item['rtp'];
  87. }
  88. foreach ($game_ids as $gameId) {
  89. $old_rtp = $gameRtp[$gameId] ?? 0;
  90. $info = PlayerControlModel::getPlayerControlInfo($userInfo['merchant_id'], $user_id, $gameId);
  91. $balanceInfo = $userBalanceList[$user_id] ?? [];
  92. if(!empty($info)) {
  93. // 需要更新
  94. $info->control_rpt = bcmul( $data['rtp'], 100);
  95. $info->auto_cancel_rtp = bcmul($data['auto_cancel_rtp'], 100);
  96. $info->max_win_multi = $data['max_win_multi'];
  97. $info->old_rtp = $old_rtp;
  98. $info->save();
  99. }else {
  100. $item = [
  101. 'app_id' => $userInfo['merchant_id'],
  102. 'user_id' => $userInfo['user_id'],
  103. 'player_id' => $merchantsUserInfo['user_id'],// 玩家id
  104. 'game_id' => $gameId,
  105. 'old_rtp' => $old_rtp,
  106. 'control_rpt' => bcmul( $data['rtp'], 100),
  107. 'auto_cancel_rtp' => bcmul($data['auto_cancel_rtp'], 100), // 达到RTP值取消
  108. 'max_win_multi' => $data['max_win_multi'], // 最高倍数
  109. 'control_balance' => CommonUtils::convertBalance( $balanceInfo['balance'], false), // 设置时点控那刻当前余额
  110. ];
  111. PlayerControlModel::create($item);
  112. }
  113. }
  114. }
  115. return json_success([],'操作成功');
  116. }
  117. public function getPlayerControlList()
  118. {
  119. // 获取当前用户信息
  120. $userInfo = $this->getUserInfo();
  121. // 获取查询参数
  122. $page = Request::get('page', 1, 'intval');
  123. $limit = Request::get('limit', 10, 'intval');
  124. // 过滤条件
  125. // 筛选条件
  126. $filters = [
  127. // 时间筛选
  128. 'start_time' => Request::get('start_time', '', 'trim'),
  129. 'end_time' => Request::get('end_time', '', 'trim'),
  130. // 游戏筛选
  131. 'game_id' => Request::get('game_id', '', 'trim'),
  132. // 平台ID筛选
  133. 'uname' => Request::get('uname', '', 'trim'),
  134. // 玩家ID筛选
  135. 'player_id' => Request::get('user_id', '', 'trim'),
  136. // 平台昵称
  137. 'nickname' => Request::get('nickname', '', 'trim'),
  138. ];
  139. $controlWhere = [];
  140. $where = [];
  141. $isFindUserId = false;
  142. // 平台ID筛选
  143. if (!empty($filters['uname'])) {
  144. $where[] = ['uname', '=', $filters['uname']];
  145. $isFindUserId = true;
  146. }
  147. // 平台昵称筛选
  148. if (!empty($filters['nickname'])) {
  149. $where[] = ['nickname', 'like', '%' . $filters['nickname'] . '%'];
  150. $isFindUserId = true;
  151. }
  152. // 玩家id筛选
  153. if (!empty($filters['player_id'])) {
  154. $where[] = ['user_id', 'like', '%' . $filters['player_id'] . '%'];
  155. $isFindUserId = true;
  156. }
  157. if($isFindUserId) {
  158. $merchantsUserIds = MerchantsUserModel::getPlayerListByIds($userInfo['merchant_id'], $where, ['user_id']);
  159. $controlWhere[] = ['user_id', 'in', $merchantsUserIds];
  160. }
  161. if(!empty($filters['game_id'])) {
  162. $controlWhere[] = ['game_id', 'in', explode(",", $filters['game_id'])];
  163. }
  164. if(!empty($filters['start_time']) && !empty($filters['end_time'])) {
  165. $controlWhere[] = ['update_time', '>=', $filters['start_time']];
  166. $controlWhere[] = ['update_time', '<=', $filters['end_time']];
  167. }
  168. $results = PlayerControlModel::getPlayerControlList($userInfo['merchant_id'], $page, $limit, $controlWhere);
  169. $allGameList = GameModel::getGames($userInfo['merchant_id'], [], ['id', 'game_id', 'title', 'game_platform']);
  170. $gameConfig = array_column($allGameList, null, 'game_id');
  171. $player_id = array_column($results['list'], 'player_id');
  172. $userListBalance = CommonMerchantUserAndBalance::getMerchantUserBalance($player_id);
  173. $userBalanceConfig = [];
  174. foreach ($userListBalance as $item) {
  175. $userBalanceConfig[$item['user_id']] = $item['balance'];
  176. }
  177. $rtpUserList = [];
  178. foreach ($results['list'] as $item) {
  179. $player_id = $item['player_id'];
  180. if(empty($rtpUserList[$player_id])) {
  181. $rtpUserList[$player_id] = [];
  182. }
  183. $rtpUserList[$player_id][] = $item['game_id'];
  184. }
  185. $rtpConfigList = [];
  186. foreach ($rtpUserList as $player_id => $gameIds) {
  187. $temp = CommonMerchantUserAndBalance::getMerchantUserGameRtpWinBetInfo([
  188. ['user_id', '=' , $player_id],
  189. ['game_id', 'in', $gameIds],
  190. ], ['rtp','game_id']);
  191. foreach ($temp as $item) {
  192. $game_id = $item['game_id'];
  193. $rtp = $item['rtp'];
  194. $key = "{$player_id}_{$game_id}";
  195. $rtpConfigList[$key] = $rtp;
  196. }
  197. }
  198. foreach ($results['list'] as $key => $item) {
  199. $game_id = $item['game_id'];
  200. $player_id = $item['player_id'];
  201. $one_key = "{$player_id}_{$game_id}";
  202. $gameInfo = $gameConfig[$game_id] ?? [];
  203. if (!empty($gameInfo))
  204. {
  205. $gameImages = CommonUtils::getGameDefaultImage($gameInfo);
  206. }
  207. $item['game_image_url'] = $gameImages['image_url'] ?? '';
  208. $item['game_title'] = $gameInfo['title'] ?? '';
  209. $item['game_type_text'] = CommonUtils::getGameTypeConfig($gameInfo['game_platform']);
  210. $item['balance'] = CommonUtils::convertBalance($userBalanceConfig[$player_id] ?? 0, false);
  211. $item['control_rpt'] = bcdiv($item['control_rpt'], 100, 2) . "%";
  212. $item['old_rtp'] = bcdiv($item['old_rtp'], 100, 2) . "%";
  213. $item['now_rtp'] = bcdiv($rtpConfigList[$one_key] ?? 0, 100, 2) . "%";
  214. $results['list'][$key] = $item;
  215. }
  216. return json_success($results);
  217. }
  218. }