PlayerControl.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. $emptyUnameList = [];
  40. foreach ($account_ids as $account_id) {
  41. $account_id = trim($account_id);
  42. if(!empty($account_id) && is_int($account_id)) {
  43. $unameList[] = $account_id;
  44. }else {
  45. $emptyUnameList[] = $account_id;
  46. }
  47. }
  48. if(!empty($emptyUnameList)) {
  49. return json_error([], '不存在玩家:' . implode(",", $emptyUnameList));
  50. }
  51. $gameList = [];
  52. foreach ($game_ids as $game_id) {
  53. $game_id = trim($game_id);
  54. if(!empty($game_id)) {
  55. $gameList[] = $game_id;
  56. }
  57. }
  58. // 过滤掉 游戏平台ID和游戏ID不能为空
  59. if(empty($unameList) || empty($gameList)) {
  60. return json_error([], '平台ID和游戏ID不能为空');
  61. }
  62. $allGameList = GameModel::getGames($userInfo['merchant_id']);
  63. $gameIds = array_column($allGameList, 'game_id');
  64. $emptyIds = [];
  65. foreach ($gameList as $gameId) {
  66. if(!in_array($gameId, $gameIds)) {
  67. $emptyIds[] = $gameId;
  68. }
  69. }
  70. if(!empty($emptyIds)) {
  71. return json_error([], "不存在游戏:" . implode(", ", $emptyIds));
  72. }
  73. $merchantsUserList = MerchantsUserModel::getPlayerListByIds($userInfo['merchant_id'], [
  74. ['uname', 'in', $unameList]
  75. ]);
  76. $merchantsUserList = array_column($merchantsUserList, null, 'uname');
  77. $merchantsUserIds = array_column($merchantsUserList, 'user_id');
  78. $userBalanceList = CommonMerchantUserAndBalance::getMerchantUserBalance($merchantsUserIds);
  79. $userBalanceList = array_column($userBalanceList, null, 'user_id');
  80. foreach ($account_ids as $accountId) {
  81. $merchantsUserInfo = $merchantsUserList[$accountId] ?? [];
  82. if(empty($merchantsUserInfo)) {
  83. continue;
  84. }
  85. $user_id = $merchantsUserInfo['user_id'];
  86. $rtpGameLIst = CommonMerchantUserAndBalance::getMerchantUserGameRtpWinBetInfo([
  87. ['user_id', '=' , $user_id],
  88. ['game_id', 'in', $gameIds],
  89. ], ['rtp','game_id']);
  90. $gameRtp = [];
  91. foreach ($rtpGameLIst as $item) {
  92. $gameRtp[$item['game_id']] = $item['rtp'];
  93. }
  94. foreach ($game_ids as $gameId) {
  95. $old_rtp = $gameRtp[$gameId] ?? 0;
  96. $info = PlayerControlModel::getPlayerControlInfo($userInfo['merchant_id'], $user_id, $gameId);
  97. $balanceInfo = $userBalanceList[$user_id] ?? [];
  98. if(!empty($info)) {
  99. // 需要更新
  100. $info->control_rpt = bcmul( $data['rtp'], 100);
  101. $info->auto_cancel_rtp = bcmul($data['auto_cancel_rtp'], 100);
  102. $info->max_win_multi = $data['max_win_multi'];
  103. $info->old_rtp = $old_rtp;
  104. $info->save();
  105. }else {
  106. $item = [
  107. 'app_id' => $userInfo['merchant_id'],
  108. 'user_id' => $userInfo['user_id'],
  109. 'player_id' => $merchantsUserInfo['user_id'],// 玩家id
  110. 'game_id' => $gameId,
  111. 'old_rtp' => $old_rtp,
  112. 'control_rpt' => bcmul( $data['rtp'], 100),
  113. 'auto_cancel_rtp' => bcmul($data['auto_cancel_rtp'], 100), // 达到RTP值取消
  114. 'max_win_multi' => $data['max_win_multi'], // 最高倍数
  115. 'control_balance' => CommonUtils::convertBalance( $balanceInfo['balance'], false), // 设置时点控那刻当前余额
  116. ];
  117. PlayerControlModel::create($item);
  118. }
  119. }
  120. }
  121. return json_success([],'操作成功');
  122. }
  123. /**
  124. * 获取点控列表
  125. * @return \think\response\Json
  126. * @throws \think\db\exception\DataNotFoundException
  127. * @throws \think\db\exception\DbException
  128. * @throws \think\db\exception\ModelNotFoundException
  129. */
  130. public function getPlayerControlList()
  131. {
  132. // 获取当前用户信息
  133. $userInfo = $this->getUserInfo();
  134. // 获取查询参数
  135. $page = Request::get('page', 1, 'intval');
  136. $limit = Request::get('limit', 10, 'intval');
  137. // 过滤条件
  138. // 筛选条件
  139. $filters = [
  140. // 时间筛选
  141. 'start_time' => Request::get('start_time', '', 'trim'),
  142. 'end_time' => Request::get('end_time', '', 'trim'),
  143. // 游戏筛选
  144. 'game_id' => Request::get('game_id', '', 'trim'),
  145. // 平台ID筛选
  146. 'uname' => Request::get('uname', '', 'trim'),
  147. // 玩家ID筛选
  148. 'player_id' => Request::get('user_id', '', 'trim'),
  149. // 平台昵称
  150. 'nickname' => Request::get('nickname', '', 'trim'),
  151. ];
  152. $controlWhere = [];
  153. $where = [];
  154. $isFindUserId = false;
  155. // 平台ID筛选
  156. if (!empty($filters['uname'])) {
  157. $where[] = ['uname', '=', $filters['uname']];
  158. $isFindUserId = true;
  159. }
  160. // 平台昵称筛选
  161. if (!empty($filters['nickname'])) {
  162. $where[] = ['nickname', 'like', '%' . $filters['nickname'] . '%'];
  163. $isFindUserId = true;
  164. }
  165. // 玩家id筛选
  166. if (!empty($filters['player_id'])) {
  167. $where[] = ['user_id', 'like', '%' . $filters['player_id'] . '%'];
  168. $isFindUserId = true;
  169. }
  170. if($isFindUserId) {
  171. $merchantsUserIds = MerchantsUserModel::getPlayerListByIds($userInfo['merchant_id'], $where, ['user_id']);
  172. $controlWhere[] = ['user_id', 'in', $merchantsUserIds];
  173. }
  174. if(!empty($filters['game_id'])) {
  175. $controlWhere[] = ['game_id', 'in', explode(",", $filters['game_id'])];
  176. }
  177. if(!empty($filters['start_time']) && !empty($filters['end_time'])) {
  178. $controlWhere[] = ['update_time', '>=', $filters['start_time']];
  179. $controlWhere[] = ['update_time', '<=', $filters['end_time']];
  180. }
  181. $controlWhere[] = ['status', '=', 1];
  182. $results = PlayerControlModel::getPlayerControlList($userInfo['merchant_id'], $page, $limit, $controlWhere);
  183. $allGameList = GameModel::getGames($userInfo['merchant_id'], [], ['id', 'game_id', 'title', 'game_platform']);
  184. $gameConfig = array_column($allGameList, null, 'game_id');
  185. $player_id = array_column($results['list'], 'player_id');
  186. $userListBalance = CommonMerchantUserAndBalance::getMerchantUserBalance($player_id);
  187. $userBalanceConfig = [];
  188. foreach ($userListBalance as $item) {
  189. $userBalanceConfig[$item['user_id']] = $item['balance'];
  190. }
  191. $rtpUserList = [];
  192. foreach ($results['list'] as $item) {
  193. $player_id = $item['player_id'];
  194. if(empty($rtpUserList[$player_id])) {
  195. $rtpUserList[$player_id] = [];
  196. }
  197. $rtpUserList[$player_id][] = $item['game_id'];
  198. }
  199. $rtpConfigList = [];
  200. foreach ($rtpUserList as $player_id => $gameIds) {
  201. $temp = CommonMerchantUserAndBalance::getMerchantUserGameRtpWinBetInfo([
  202. ['user_id', '=' , $player_id],
  203. ['game_id', 'in', $gameIds],
  204. ], ['rtp','game_id']);
  205. foreach ($temp as $item) {
  206. $game_id = $item['game_id'];
  207. $rtp = $item['rtp'];
  208. $key = "{$player_id}_{$game_id}";
  209. $rtpConfigList[$key] = $rtp;
  210. }
  211. }
  212. foreach ($results['list'] as $key => $item) {
  213. $game_id = $item['game_id'];
  214. $player_id = $item['player_id'];
  215. $one_key = "{$player_id}_{$game_id}";
  216. $gameInfo = $gameConfig[$game_id] ?? [];
  217. if (!empty($gameInfo))
  218. {
  219. $gameImages = CommonUtils::getGameDefaultImage($gameInfo);
  220. }
  221. $item['game_image_url'] = $gameImages['image_url'] ?? '';
  222. $item['game_title'] = $gameInfo['title'] ?? '';
  223. $item['game_type_text'] = CommonUtils::getGameTypeConfig($gameInfo['game_platform']);
  224. $item['balance'] = CommonUtils::convertBalance($userBalanceConfig[$player_id] ?? 0, false);
  225. $item['control_rpt'] = bcdiv($item['control_rpt'], 100, 2) . "%";
  226. $item['old_rtp'] = bcdiv($item['old_rtp'], 100, 2) . "%";
  227. $item['now_rtp'] = bcdiv($rtpConfigList[$one_key] ?? 0, 100, 2) . "%";
  228. $results['list'][$key] = $item;
  229. }
  230. return json_success($results);
  231. }
  232. /**
  233. * 取消点控设置
  234. * @return \think\response\Json
  235. * @throws \think\db\exception\DataNotFoundException
  236. * @throws \think\db\exception\DbException
  237. * @throws \think\db\exception\ModelNotFoundException
  238. */
  239. public function cancelPlayerControlInfo()
  240. {
  241. $control_id = Request::post('control_id','', 'trim');
  242. if(empty($control_id)) {
  243. return json_error([], '参数错误');
  244. }
  245. $info = PlayerControlModel::find($control_id);
  246. if(!empty($info)) {
  247. $info->status = 0;
  248. $info->save();
  249. }
  250. return json_success([],'操作成功');
  251. }
  252. }