PlayerControl.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. /**
  118. * 获取点控列表
  119. * @return \think\response\Json
  120. * @throws \think\db\exception\DataNotFoundException
  121. * @throws \think\db\exception\DbException
  122. * @throws \think\db\exception\ModelNotFoundException
  123. */
  124. public function getPlayerControlList()
  125. {
  126. // 获取当前用户信息
  127. $userInfo = $this->getUserInfo();
  128. // 获取查询参数
  129. $page = Request::get('page', 1, 'intval');
  130. $limit = Request::get('limit', 10, 'intval');
  131. // 过滤条件
  132. // 筛选条件
  133. $filters = [
  134. // 时间筛选
  135. 'start_time' => Request::get('start_time', '', 'trim'),
  136. 'end_time' => Request::get('end_time', '', 'trim'),
  137. // 游戏筛选
  138. 'game_id' => Request::get('game_id', '', 'trim'),
  139. // 平台ID筛选
  140. 'uname' => Request::get('uname', '', 'trim'),
  141. // 玩家ID筛选
  142. 'player_id' => Request::get('user_id', '', 'trim'),
  143. // 平台昵称
  144. 'nickname' => Request::get('nickname', '', 'trim'),
  145. ];
  146. $controlWhere = [];
  147. $where = [];
  148. $isFindUserId = false;
  149. // 平台ID筛选
  150. if (!empty($filters['uname'])) {
  151. $where[] = ['uname', '=', $filters['uname']];
  152. $isFindUserId = true;
  153. }
  154. // 平台昵称筛选
  155. if (!empty($filters['nickname'])) {
  156. $where[] = ['nickname', 'like', '%' . $filters['nickname'] . '%'];
  157. $isFindUserId = true;
  158. }
  159. // 玩家id筛选
  160. if (!empty($filters['player_id'])) {
  161. $where[] = ['user_id', 'like', '%' . $filters['player_id'] . '%'];
  162. $isFindUserId = true;
  163. }
  164. if($isFindUserId) {
  165. $merchantsUserIds = MerchantsUserModel::getPlayerListByIds($userInfo['merchant_id'], $where, ['user_id']);
  166. $controlWhere[] = ['user_id', 'in', $merchantsUserIds];
  167. }
  168. if(!empty($filters['game_id'])) {
  169. $controlWhere[] = ['game_id', 'in', explode(",", $filters['game_id'])];
  170. }
  171. if(!empty($filters['start_time']) && !empty($filters['end_time'])) {
  172. $controlWhere[] = ['update_time', '>=', $filters['start_time']];
  173. $controlWhere[] = ['update_time', '<=', $filters['end_time']];
  174. }
  175. $results = PlayerControlModel::getPlayerControlList($userInfo['merchant_id'], $page, $limit, $controlWhere);
  176. $allGameList = GameModel::getGames($userInfo['merchant_id'], [], ['id', 'game_id', 'title', 'game_platform']);
  177. $gameConfig = array_column($allGameList, null, 'game_id');
  178. $player_id = array_column($results['list'], 'player_id');
  179. $userListBalance = CommonMerchantUserAndBalance::getMerchantUserBalance($player_id);
  180. $userBalanceConfig = [];
  181. foreach ($userListBalance as $item) {
  182. $userBalanceConfig[$item['user_id']] = $item['balance'];
  183. }
  184. $rtpUserList = [];
  185. foreach ($results['list'] as $item) {
  186. $player_id = $item['player_id'];
  187. if(empty($rtpUserList[$player_id])) {
  188. $rtpUserList[$player_id] = [];
  189. }
  190. $rtpUserList[$player_id][] = $item['game_id'];
  191. }
  192. $rtpConfigList = [];
  193. foreach ($rtpUserList as $player_id => $gameIds) {
  194. $temp = CommonMerchantUserAndBalance::getMerchantUserGameRtpWinBetInfo([
  195. ['user_id', '=' , $player_id],
  196. ['game_id', 'in', $gameIds],
  197. ], ['rtp','game_id']);
  198. foreach ($temp as $item) {
  199. $game_id = $item['game_id'];
  200. $rtp = $item['rtp'];
  201. $key = "{$player_id}_{$game_id}";
  202. $rtpConfigList[$key] = $rtp;
  203. }
  204. }
  205. foreach ($results['list'] as $key => $item) {
  206. $game_id = $item['game_id'];
  207. $player_id = $item['player_id'];
  208. $one_key = "{$player_id}_{$game_id}";
  209. $gameInfo = $gameConfig[$game_id] ?? [];
  210. if (!empty($gameInfo))
  211. {
  212. $gameImages = CommonUtils::getGameDefaultImage($gameInfo);
  213. }
  214. $item['game_image_url'] = $gameImages['image_url'] ?? '';
  215. $item['game_title'] = $gameInfo['title'] ?? '';
  216. $item['game_type_text'] = CommonUtils::getGameTypeConfig($gameInfo['game_platform']);
  217. $item['balance'] = CommonUtils::convertBalance($userBalanceConfig[$player_id] ?? 0, false);
  218. $item['control_rpt'] = bcdiv($item['control_rpt'], 100, 2) . "%";
  219. $item['old_rtp'] = bcdiv($item['old_rtp'], 100, 2) . "%";
  220. $item['now_rtp'] = bcdiv($rtpConfigList[$one_key] ?? 0, 100, 2) . "%";
  221. $results['list'][$key] = $item;
  222. }
  223. return json_success($results);
  224. }
  225. /**
  226. * 取消点控设置
  227. * @return \think\response\Json
  228. * @throws \think\db\exception\DataNotFoundException
  229. * @throws \think\db\exception\DbException
  230. * @throws \think\db\exception\ModelNotFoundException
  231. */
  232. public function cancelPlayerControlInfo()
  233. {
  234. $control_id = Request::post('control_id','', 'trim');
  235. if(empty($control_id)) {
  236. return json_error([], '参数错误');
  237. }
  238. PlayerControlModel::find($control_id)->delete();
  239. return json_success([],'操作成功');
  240. }
  241. }