Răsfoiți Sursa

MerchantUserAndBalanceModel

ssvfdn 3 luni în urmă
părinte
comite
27c15510d2

+ 111 - 0
app/controller/PlayerControl.php

@@ -0,0 +1,111 @@
+<?php
+
+namespace app\controller;
+
+use app\BaseController;
+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' => -1,
+            'auto_cancel_rtp' => -1
+        ]);
+
+        // 判断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');
+
+        foreach ($account_ids as $accountId) {
+            $merchantsUserInfo = $merchantsUserList[$accountId] ?? [];
+            if(empty($merchantsUserInfo)) {
+                continue;
+            }
+            foreach ($game_ids as $gameId) {
+                $info = PlayerControlModel::getPlayerControlInfo($userInfo['merchant_id'], $merchantsUserInfo['user_id'], $gameId);
+                if(!empty($info)) {
+                    // 需要更新
+                    $item =  [
+                        'control_rpt' => $data['rtp'],
+                        'auto_cancel_rtp' => $data['auto_cancel_rtp'], // 达到RTP值取消
+                        'max_win_multi' => $data['max_win_multi'], // 最高倍数
+                    ];
+                }else {
+                    $item =  [
+                        'app_id' => $userInfo['merchant_id'],
+                        'user_id' => $userInfo['user_id'],
+                        'player_id' => $merchantsUserInfo['user_id'],// 玩家id
+                        'game_id' => $gameId,
+                        'control_rpt' => $data['rtp'],
+                        'auto_cancel_rtp' => $data['auto_cancel_rtp'], // 达到RTP值取消
+                        'max_win_multi' => $data['max_win_multi'], // 最高倍数
+                        'control_balance' => $merchantsUserInfo['balance'], // 设置时点控那刻当前余额
+                    ];
+                }
+                print_r($item);
+            }
+        }
+        return json_success([],'操作成功');
+    }
+}

+ 9 - 32
app/model/GameBetGameModel.php

@@ -135,17 +135,9 @@ class GameBetGameModel extends Model
         
         if (!empty($userIds)) {
             // 获取用户信息
-            $users = self::table('tp_merchants_user')
-                ->whereIn('user_id', $userIds)
-                ->field(['user_id', 'nickname'])
-                ->select()
-                ->toArray();
+            $users = MerchantUserAndBalanceModel::getMerchantUser($userIds);
             // 获取用户余额    
-            $userBanlance = self::table('tp_merchants_user_balance')
-                ->whereIn('user_id', $userIds)
-                ->field(['user_id', 'balance'])
-                ->select()
-                ->toArray();
+            $userBanlance = MerchantUserAndBalanceModel::getMerchantUserBalance($userIds);
 
             $users = array_column($users, null, 'user_id');
             $userBanlance = array_column($userBanlance, null, 'user_id');
@@ -212,18 +204,11 @@ class GameBetGameModel extends Model
         $userIds = array_column($list, 'user_id');
         
         if (!empty($userIds)) {
+
             // 获取用户信息
-            $users = self::table('tp_merchants_user')
-                ->whereIn('user_id', $userIds)
-                ->field(['user_id', 'nickname'])
-                ->select()
-                ->toArray();
-            // 获取用户余额    
-            $userBanlance = self::table('tp_merchants_user_balance')
-                ->whereIn('user_id', $userIds)
-                ->field(['user_id', 'balance'])
-                ->select()
-                ->toArray();
+            $users = MerchantUserAndBalanceModel::getMerchantUser($userIds);
+            // 获取用户余额
+            $userBanlance = MerchantUserAndBalanceModel::getMerchantUserBalance($userIds);
 
             $users = array_column($users, null, 'user_id');
             $userBanlance = array_column($userBanlance, null, 'user_id');
@@ -290,17 +275,9 @@ class GameBetGameModel extends Model
         
         if (!empty($userIds)) {
             // 获取用户信息
-            $users = self::table('tp_merchants_user')
-                ->whereIn('user_id', $userIds)
-                ->field(['user_id', 'nickname'])
-                ->select()
-                ->toArray();
-            // 获取用户余额    
-            $userBanlance = self::table('tp_merchants_user_balance')
-                ->whereIn('user_id', $userIds)
-                ->field(['user_id', 'balance'])
-                ->select()
-                ->toArray();
+            $users = MerchantUserAndBalanceModel::getMerchantUser($userIds);
+            // 获取用户余额
+            $userBanlance = MerchantUserAndBalanceModel::getMerchantUserBalance($userIds);
 
             $users = array_column($users, null, 'user_id');
             $userBanlance = array_column($userBanlance, null, 'user_id');

+ 43 - 0
app/model/MerchantUserAndBalanceModel.php

@@ -0,0 +1,43 @@
+<?php
+
+namespace app\model;
+
+use think\Model;
+
+class MerchantUserAndBalanceModel extends Model
+{
+
+    /**
+     * 批量获取用户余额
+     * @param $userIds
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function getMerchantUserBalance($userIds, $field = ['user_id', 'balance']) {
+        $query = self::table('tp_merchants_user_balance')->whereIn('user_id', $userIds);
+        if(!empty($field)) {
+            $query = $query->field($field);
+        }
+        return $query->select()->toArray();
+    }
+
+    /**
+     * 批量获取用户信息
+     * @param $userIds
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function getMerchantUser($userIds, $field = ['user_id', 'nickname'])
+    {
+        $query = self::table('tp_merchants_user')->whereIn('user_id', $userIds);
+        if(!empty($field)){
+            $query = $query->field($field);
+        }
+        return $query->select()->toArray();
+    }
+
+}

+ 12 - 0
app/model/MerchantsUserModel.php

@@ -93,6 +93,18 @@ class MerchantsUserModel extends Model
         return $disabledMap[$disabled] ?? '未知';
     }
 
+    /**
+     * 通过unameList批量获取指定平台用户详情
+     * @param $merchantId
+     * @param $unameList
+     * @return mixed
+     */
+    public static function getPlayerListByIds($merchantId, $unameList = [])
+    {
+        $query = self::where('app_id', $merchantId);
+        return $query->whereIn('uname', $unameList)->select()->toArray();
+    }
+
     /**
      * 根据商户ID获取玩家列表
      */

+ 91 - 0
app/model/PlayerControlModel.php

@@ -0,0 +1,91 @@
+<?php
+
+namespace app\model;
+use think\Model;
+class PlayerControlModel extends Model
+{
+    // 设置表名
+    protected $name = 'player_control';
+
+    protected $connection = 'fortue_tiger';
+
+    // 设置主键
+    protected $pk = 'control_id';
+    // 设置自动时间戳
+    protected $autoWriteTimestamp = 'int';
+
+    // 设置字段类型
+    protected $type = [
+        'control_id' => 'int',
+        'app_id' => 'int', // 商户ID
+        'user_id' => 'int', // 用户ID
+        'player_id' => 'int', // 玩家ID
+        'game_id' => 'string', // 游戏ID
+        'control_rpt' => 'int', // 设置的RTP值
+        'auto_cancel_rtp' => 'int', // 达到此RTP解除点控
+        'max_win_multi' => 'int', // 赢取倍数限制
+        'control_balance' => 'decimal', // 设置时点控那刻当前余额
+        'create_time' => 'int',
+        'update_time' => 'int',
+    ];
+
+    /**
+     * 获取点控详情
+     * @param $merchantId
+     * @param $uname
+     * @param $game_id
+     * @return mixed
+     */
+    public static function getPlayerControlInfo($merchantId, $player_id, $game_id)
+    {
+        return self::where(['app_id' => $merchantId, 'player_id' => $player_id, 'game_id' => $game_id])->find();
+    }
+
+    /**
+     * 根据商户ID获取玩家列表
+     */
+    public static function getPlayerControlList($merchantId, $page = 1, $limit = 10, $filters = [])
+    {
+        $wheres = [];
+        $wheres[] = ['app_id', '=', $merchantId];
+        // 应用过滤条件
+        if (!empty($filters['uname'])) {
+            $wheres[] = ['uname', 'like', '%' . $filters['uname'] . '%'];
+        }
+        if (!empty($filters['nickname'])) {
+            $wheres[] = ['nickname', 'like', '%' . $filters['nickname'] . '%'];
+        }
+        if (!empty($filters['user_id'])) {
+            $wheres[] = ['user_id', '=', $filters['user_id']];
+        }
+        if(!empty($filters['game_id'])) {
+            $wheres[] = ['game_id', 'in', $filters['game_id']];
+        }
+
+        $query = self::where($wheres);
+        $order = $filters['order'] ?? 'create_time';
+        $sort = $filters['sort'] ?? 'desc';
+        $query->order($order, $sort);
+
+        // 获取总数
+        $total = $query->count();
+        // 获取列表
+        $list = $query->page($page, $limit)->select()->toArray();
+
+        return [
+            'list' => $list,
+            'total' => $total,
+            'page' => $page,
+            'limit' => $limit
+        ];
+    }
+
+    /**
+     * 创建角色
+     * @param array $data 角色数据
+     */
+    public static function updatePlayerControl(array $data)
+    {
+        self:create($data);
+    }
+}

+ 5 - 0
route/app.php

@@ -58,6 +58,11 @@ Route::group('game', function () {
     Route::get('export', 'Game/export');
 })->middleware([\app\middleware\AuthMiddleware::class, \app\middleware\BehaviorLogMiddleware::class]);
 
+Route::group('player_control', function () {
+    Route::post('update', 'PlayerControl/updatePlayerControl');
+})->middleware([\app\middleware\AuthMiddleware::class, \app\middleware\BehaviorLogMiddleware::class]);
+
+
 // 登录日志相关路由
 Route::group('login_log', function () {
     Route::get('list', 'LoginLog/list');

+ 0 - 0
runtime/.gitignore