| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?php
- namespace app\controller;
- use app\BaseController;
- use app\common\CommonUtils;
- use app\model\GameModel;
- use app\model\MerchantsUserModel;
- use app\model\PlayerControlModel;
- use think\facade\Request;
- class PlayerControl extends BaseController
- {
- /**
- * 添加或更新 点控设置
- * {"account_ids":["115"],"game_ids":[1],"rtp":9900,"max_win_multi":500,"auto_cancel_rtp":100,"agent_id":6027,"win_pro":-1}
- */
- public function updatePlayerControl()
- {
- $userInfo = $this->request->userInfo;
- $data = Request::param([
- 'account_ids' => "",
- 'game_ids' => "",
- 'rtp' => 0,
- 'max_win_multi' => 0,
- 'auto_cancel_rtp' => 0
- ]);
- // 判断RTP
- if(empty($data['rtp'])) {
- return json_error([], 'RTP错误');
- }
- $account_ids = $data['account_ids'] ?? "";
- $game_ids = $data['game_ids'] ?? "";
- // 游戏平台ID和游戏ID不能为空
- if(empty($account_ids) || empty($game_ids)) {
- return json_error([], '平台ID和游戏ID不能为空');
- }
- $account_ids = explode(",", $account_ids);
- $game_ids = explode(",", $game_ids);
- $unameList = [];
- foreach ($account_ids as $account_id) {
- $account_id = trim($account_id);
- if(!empty($account_id)) {
- $unameList[] = $account_id;
- }
- }
- $gameList = [];
- foreach ($game_ids as $game_id) {
- $game_id = trim($game_id);
- if(!empty($game_id)) {
- $gameList[] = $game_id;
- }
- }
- // 过滤掉 游戏平台ID和游戏ID不能为空
- if(empty($unameList) || empty($gameList)) {
- return json_error([], '平台ID和游戏ID不能为空');
- }
- $allGameList = GameModel::getGames($userInfo['merchant_id']);
- $gameIds = array_column($allGameList, 'game_id');
- $emptyIds = [];
- foreach ($gameList as $gameId) {
- if(!in_array($gameId, $gameIds)) {
- $emptyIds[] = $gameId;
- }
- }
- if(!empty($emptyIds)) {
- return json_error([], "不存在游戏:" . implode(", ", $emptyIds));
- }
- $merchantsUserList = MerchantsUserModel::getPlayerListByIds($userInfo['merchant_id'], $unameList);
- $merchantsUserList = array_column($merchantsUserList, null, 'uname');
- $merchantsUserIds = array_column($merchantsUserList, 'user_id');
- $userBalanceList = MerchantUserAndBalance::getMerchantUserBalance($merchantsUserIds);
- $userBalanceList = array_column($userBalanceList, null, 'user_id');
- foreach ($account_ids as $accountId) {
- $merchantsUserInfo = $merchantsUserList[$accountId] ?? [];
- if(empty($merchantsUserInfo)) {
- continue;
- }
- foreach ($game_ids as $gameId) {
- $user_id = $merchantsUserInfo['user_id'];
- $info = PlayerControlModel::getPlayerControlInfo($userInfo['merchant_id'], $user_id, $gameId);
- $balanceInfo = $userBalanceList[$user_id] ?? [];
- if(!empty($info)) {
- // 需要更新
- $info->control_rpt = bcmul( $data['rtp'], 100);
- $info->auto_cancel_rtp = bcmul($data['auto_cancel_rtp'], 100);
- $info->max_win_multi = $data['max_win_multi'];
- $info->save();
- $message = "update";
- }else {
- $item = [
- 'app_id' => $userInfo['merchant_id'],
- 'user_id' => $userInfo['user_id'],
- 'player_id' => $merchantsUserInfo['user_id'],// 玩家id
- 'game_id' => $gameId,
- 'control_rpt' => bcmul( $data['rtp'], 100),
- 'auto_cancel_rtp' => bcmul($data['auto_cancel_rtp'], 100), // 达到RTP值取消
- 'max_win_multi' => $data['max_win_multi'], // 最高倍数
- 'control_balance' => CommonUtils::convertBalance( $balanceInfo['balance'], false), // 设置时点控那刻当前余额
- ];
- PlayerControlModel::create($item);
- }
- }
- }
- return json_success([],'操作成功');
- }
- }
|