GameImproveUserRtp.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <?php
  2. namespace app\controller;
  3. use app\BaseController;
  4. use app\common\CommonMerchantUserAndBalance;
  5. use app\common\CommonUtils;
  6. use app\model\GameImproveUserRtpModel;
  7. use app\model\MerchantsUserModel;
  8. use app\model\UserModel;
  9. use think\facade\Request;
  10. class GameImproveUserRtp extends BaseController
  11. {
  12. /**
  13. * 添加或更新 {"uname":"115","net_income":100,"turnover_multiple":5,"evaluation_period":4,"effective_count":6,"trigger_interval_rounds":300}
  14. * evaluation_period 1 = 每日 2 = 每周 3 = 每月 4 = 终生 5 = 自定义时间
  15. * custom_time_end custom_time_start
  16. */
  17. public function updateGameImproveUserRtp(){
  18. $userInfo = $this->getUserInfo();
  19. $data = Request::param([
  20. 'uname' => "",
  21. 'net_income' => 100, // 设定玩家在游戏内盈利值达到后关闭功能
  22. 'turnover_multiple' => 5, //达到设定流水倍数关闭提升状态
  23. 'evaluation_period' => 4, // 系统控制的触发周期选择
  24. 'effective_count' => 1, //周期内可被系统控制的次数
  25. 'trigger_interval_rounds' => 300, // 每次系统控制间隔局数
  26. // 'custom_time_start' => '',
  27. // 'custom_time_end' => '',
  28. ], 'post', 'trim');
  29. foreach ($data as $k => $v) {
  30. if(empty($v)) {
  31. return json_error([], '参数错误');
  32. }
  33. }
  34. $custom_time_start = Request::post('custom_time_start', '', 'trim');
  35. $custom_time_end = Request::post('custom_time_end', '', 'trim');
  36. if($data['evaluation_period'] == 5) {
  37. if(empty($custom_time_start) || empty($custom_time_end)) {
  38. return json_error([], '参数错误');
  39. }
  40. }
  41. $account_ids = explode(",", $data['uname']);
  42. $unameList = [];
  43. $emptyUnameList = [];
  44. foreach ($account_ids as $account_id) {
  45. $account_id = trim($account_id);
  46. if(!empty($account_id) && preg_match("/^[1-9]\d*$/", $account_id)) {
  47. $unameList[] = $account_id;
  48. }else {
  49. $emptyUnameList[] = $account_id;
  50. }
  51. }
  52. if(!empty($emptyUnameList)) {
  53. return json_error([], '不存在玩家:' . implode(",", $emptyUnameList));
  54. }
  55. // 过滤掉 游戏平台ID和游戏ID不能为空
  56. if(empty($unameList)) {
  57. return json_error([], '平台ID不能为空');
  58. }
  59. $merchantsUserList = MerchantsUserModel::getPlayerListByIds($userInfo['merchant_id'], [
  60. ['uname', 'in', $unameList]
  61. ]);
  62. $merchantsUserList = array_column($merchantsUserList, null, 'uname');
  63. $merchantsUserIds = array_column($merchantsUserList, 'user_id');
  64. $userBalanceList = CommonMerchantUserAndBalance::getMerchantUserBalance($merchantsUserIds);
  65. $userBalanceList = array_column($userBalanceList, null, 'user_id');
  66. foreach ($account_ids as $accountId) {
  67. $merchantsUserInfo = $merchantsUserList[$accountId] ?? [];
  68. if(empty($merchantsUserInfo)) {
  69. continue;
  70. }
  71. $user_id = $merchantsUserInfo['user_id'];
  72. $info = GameImproveUserRtpModel::getImproveUserRtpInfo([
  73. 'app_id' => $userInfo['merchant_id'],
  74. 'player_id' => $user_id,
  75. 'status' => 1
  76. ]);
  77. $balanceInfo = $userBalanceList[$user_id] ?? [];
  78. if(!empty($info)) {
  79. // 更新
  80. $info->effective_count = $data['effective_count'];
  81. $info->evaluation_period = $data['evaluation_period'];
  82. $info->net_income = $data['net_income'];
  83. $info->trigger_interval_rounds = $data['trigger_interval_rounds'];
  84. $info->turnover_multiple = $data['turnover_multiple'];
  85. $info->custom_time_start = !empty($custom_time_start) ? strtotime($custom_time_start) : 0;
  86. $info->custom_time_end = !empty($custom_time_end) ? strtotime($custom_time_end) : 0;
  87. if($info->evaluation_period != 5) {
  88. $info->round_status = 1;
  89. $info->open_status_time = time();
  90. }else {
  91. if(time() >= $info->custom_time_start) {
  92. $info->round_status = 1;
  93. }
  94. if(time() >= $info->custom_time_end) {
  95. $info->round_status = 2;
  96. }
  97. $info->open_status_time = $info->custom_time_start;
  98. }
  99. $info->save();
  100. }else {
  101. // 添加
  102. $item = [
  103. 'app_id' => $userInfo['merchant_id'],
  104. 'user_id' => $userInfo['user_id'],
  105. 'player_id' => $merchantsUserInfo['user_id'],// 玩家id
  106. 'effective_count' => $data['effective_count'],
  107. 'evaluation_period' => $data['evaluation_period'],
  108. 'net_income' => $data['net_income'],
  109. 'trigger_interval_rounds' => $data['trigger_interval_rounds'],
  110. 'turnover_multiple' => $data['turnover_multiple'],
  111. 'custom_time_start' => !empty($custom_time_start) ? strtotime($custom_time_start) : 0,
  112. 'custom_time_end' => !empty($custom_time_end) ? strtotime($custom_time_end) : 0,
  113. 'old_rtp' => $merchantsUserInfo['rtp'],
  114. 'control_balance' => CommonUtils::convertBalance( $balanceInfo['balance'], false), // 设置时点控那刻当前余额
  115. ];
  116. if($item['evaluation_period'] != 5) {
  117. $item['round_status'] = 1;
  118. $item['open_status_time'] = time();
  119. }else {
  120. if(time() >= $item['custom_time_start']) {
  121. $item['round_status'] = 1;
  122. }
  123. if(time() >= $item['custom_time_end']) {
  124. $item['round_status'] = 2;
  125. }
  126. $item['open_status_time'] = $item['custom_time_start'];
  127. }
  128. GameImproveUserRtpModel::create($item);
  129. }
  130. }
  131. return json_success([],'操作成功');
  132. }
  133. /**
  134. * 获取列表数据
  135. * @return \think\response\Json
  136. * @throws \think\db\exception\DataNotFoundException
  137. * @throws \think\db\exception\DbException
  138. * @throws \think\db\exception\ModelNotFoundException
  139. */
  140. public function getGameImproveUserList()
  141. {
  142. // 获取当前用户信息
  143. $userInfo = $this->getUserInfo();
  144. // 获取查询参数
  145. $page = Request::get('page', 1, 'intval');
  146. $limit = Request::get('limit', 10, 'intval');
  147. // 过滤条件
  148. // 筛选条件
  149. $filters = [
  150. // 时间筛选
  151. 'start_time' => Request::get('start_time', '', 'trim'),
  152. 'end_time' => Request::get('end_time', '', 'trim'),
  153. // 平台ID筛选
  154. 'uname' => Request::get('uname', '', 'trim'),
  155. // 玩家ID筛选
  156. 'player_id' => Request::get('user_id', '', 'trim'),
  157. // 平台昵称
  158. 'nickname' => Request::get('nickname', '', 'trim'),
  159. 'status' => Request::get('status', '', 'trim'),
  160. ];
  161. $is_end = Request::get('is_end_time', 0);
  162. $controlWhere = [];
  163. $controlWhere[] = ['user_id', '=', $userInfo['user_id']];
  164. $where = [];
  165. $isFindUserId = false;
  166. // 平台ID筛选
  167. if (!empty($filters['uname'])) {
  168. $where[] = ['uname', '=', $filters['uname']];
  169. $isFindUserId = true;
  170. }
  171. // 平台昵称筛选
  172. if (!empty($filters['nickname'])) {
  173. $where[] = ['nickname', 'like', '%' . $filters['nickname'] . '%'];
  174. $isFindUserId = true;
  175. }
  176. // 玩家id筛选
  177. if (!empty($filters['player_id'])) {
  178. $where[] = ['user_id', 'like', '%' . $filters['player_id'] . '%'];
  179. $isFindUserId = true;
  180. }
  181. if($isFindUserId) {
  182. $merchantsUserIds = MerchantsUserModel::getPlayerListByIds($userInfo['merchant_id'], $where, ['user_id']);
  183. $controlWhere[] = ['user_id', 'in', array_column($merchantsUserIds, 'user_id')];
  184. }
  185. if(!empty($filters['start_time']) && !empty($filters['end_time'])) {
  186. $controlWhere[] = ['update_time', '>=', strtotime($filters['start_time'] . " 00:00:00")];
  187. $controlWhere[] = ['update_time', '<=', strtotime($filters['end_time'] . " 23:59:59")];
  188. }
  189. if(in_array($filters['status'], ['0','1'])) {
  190. $controlWhere[] = ['status', '=', $filters['status']];
  191. }else {
  192. if(!$is_end) {
  193. $controlWhere[] = ['status', '=', 1];
  194. }
  195. }
  196. $results = GameImproveUserRtpModel::getImproveUserRtpList($userInfo['merchant_id'], $page, $limit, $controlWhere);
  197. $player_ids = array_column($results['list'], 'player_id');
  198. $playerConfig = CommonMerchantUserAndBalance::getMerchantUser($player_ids, ['user_id','uname','nickname', 'rtp']);
  199. $playerConfig = array_column($playerConfig, null, 'user_id');
  200. $userListBalance = CommonMerchantUserAndBalance::getMerchantUserBalance($player_ids);
  201. $userBalanceConfig = [];
  202. foreach ($userListBalance as $item) {
  203. $userBalanceConfig[$item['user_id']] = $item['balance'];
  204. }
  205. foreach ($results['list'] as $key => $item) {
  206. $player_id = $item['player_id'];
  207. $playerInfo = $playerConfig[$player_id] ?? [];
  208. $item['balance'] = CommonUtils::convertBalance($userBalanceConfig[$player_id] ?? 0, false);
  209. $item['bet_amount'] = CommonUtils::convertBalance($item['bet_amount'] ?? 0, false);
  210. $item['total_win_amount'] = CommonUtils::convertBalance($item['total_win_amount'] ?? 0, false);
  211. $item['old_rtp'] = bcdiv($item['old_rtp'], 100, 2) . "%";
  212. $item['now_rtp'] = bcdiv($playerInfo['rtp'] ?? 0, 100, 2) . "%";
  213. $item['status_text'] = $item['status'] == 1 ? '生效中' : "已结束";
  214. $item['evaluation_period_text'] = [
  215. '1' => '每日',
  216. '2' => '每周',
  217. '3' => '每月',
  218. '4' => '终生',
  219. '5' => '自定义时间'
  220. ][$item['evaluation_period']] ?? "";
  221. $item['start_end_time'] = "-";
  222. if(!empty($item['end_time'])) {
  223. $item['start_end_time'] = $item['create_time'] . ' ~ ' . date('Y-m-d H:i:s', $item['end_time']);
  224. }
  225. $playerInfo = $playerConfig[$player_id] ?? [];
  226. $item['uname'] = $playerInfo['uname'] ?? '';
  227. $item['nickname'] = $playerInfo['nickname'] ?? '';
  228. $adminInfo = UserModel::find($item['user_id']);
  229. $item['admin_name'] = "";
  230. if(!empty($adminInfo)) {
  231. $item['admin_name'] = $adminInfo['nick_name'] ?? '';
  232. }
  233. if(!empty($item['end_time'])) {
  234. $item['end_time'] = date('Y-m-d H:i:s', $item['end_time']);
  235. }
  236. if(!empty($item['custom_time_start']) && !empty($item['custom_time_end'])) {
  237. $item['custom_time_start'] = date('Y-m-d H:i:s', $item['custom_time_start']);
  238. $item['custom_time_end'] = date('Y-m-d H:i:s', $item['custom_time_end']);
  239. }
  240. $results['list'][$key] = $item;
  241. }
  242. return json_success($results);
  243. }
  244. /**
  245. * 取消指定RTP提升
  246. * @return \think\response\Json
  247. * @throws \think\db\exception\DataNotFoundException
  248. * @throws \think\db\exception\DbException
  249. * @throws \think\db\exception\ModelNotFoundException
  250. */
  251. public function cancelGameImproveUserRtp()
  252. {
  253. $userInfo = $this->getUserInfo();
  254. $id = Request::post('id','', 'trim');
  255. if(empty($id)) {
  256. return json_error([], '参数错误');
  257. }
  258. $info = GameImproveUserRtpModel::where(['user_id' => $userInfo['user_id'], 'id' => $id])->find();
  259. if(empty($info)) {
  260. return json_error([], '参数错误');
  261. }
  262. if(!empty($info)) {
  263. $info->end_time = time();
  264. $info->status = 0;
  265. $info->save();
  266. }
  267. return json_success([],'操作成功');
  268. }
  269. /**
  270. * 一键取消全部点控
  271. * @return \think\response\Json
  272. */
  273. public function cancelAllGameImproveUserRtp()
  274. {
  275. $userInfo = $this->getUserInfo();
  276. GameImproveUserRtpModel::where(['user_id' => $userInfo['user_id'], 'status' => 1])->save(['status' => 0, 'end_time' => time()]);
  277. return json_success([],'操作成功');
  278. }
  279. }