GameImproveUserRtp.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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. $info->round_count = 0;
  88. if($info->evaluation_period != 5) {
  89. $info->round_status = 1;
  90. $info->open_status_time = time();
  91. }else {
  92. if(time() >= $info->custom_time_start) {
  93. $info->round_status = 1;
  94. }
  95. if(time() >= $info->custom_time_end) {
  96. $info->round_status = 2;
  97. }
  98. $info->open_status_time = $info->custom_time_start;
  99. }
  100. $info->save();
  101. }else {
  102. // 添加
  103. $item = [
  104. 'app_id' => $userInfo['merchant_id'],
  105. 'user_id' => $userInfo['user_id'],
  106. 'player_id' => $merchantsUserInfo['user_id'],// 玩家id
  107. 'effective_count' => $data['effective_count'],
  108. 'evaluation_period' => $data['evaluation_period'],
  109. 'net_income' => $data['net_income'],
  110. 'trigger_interval_rounds' => $data['trigger_interval_rounds'],
  111. 'turnover_multiple' => $data['turnover_multiple'],
  112. 'custom_time_start' => !empty($custom_time_start) ? strtotime($custom_time_start) : 0,
  113. 'custom_time_end' => !empty($custom_time_end) ? strtotime($custom_time_end) : 0,
  114. 'old_rtp' => $merchantsUserInfo['rtp'],
  115. 'control_balance' => CommonUtils::convertBalance( $balanceInfo['balance'], false), // 设置时点控那刻当前余额
  116. ];
  117. if($item['evaluation_period'] != 5) {
  118. $item['round_status'] = 1;
  119. $item['open_status_time'] = time();
  120. }else {
  121. if(time() >= $item['custom_time_start']) {
  122. $item['round_status'] = 1;
  123. }
  124. if(time() >= $item['custom_time_end']) {
  125. $item['round_status'] = 2;
  126. }
  127. $item['open_status_time'] = $item['custom_time_start'];
  128. }
  129. GameImproveUserRtpModel::create($item);
  130. }
  131. }
  132. return json_success([],'操作成功');
  133. }
  134. /**
  135. * 获取列表数据
  136. * @return \think\response\Json
  137. * @throws \think\db\exception\DataNotFoundException
  138. * @throws \think\db\exception\DbException
  139. * @throws \think\db\exception\ModelNotFoundException
  140. */
  141. public function getGameImproveUserList()
  142. {
  143. // 获取当前用户信息
  144. $userInfo = $this->getUserInfo();
  145. // 获取查询参数
  146. $page = Request::get('page', 1, 'intval');
  147. $limit = Request::get('limit', 10, 'intval');
  148. // 过滤条件
  149. // 筛选条件
  150. $filters = [
  151. // 时间筛选
  152. 'start_time' => Request::get('start_time', '', 'trim'),
  153. 'end_time' => Request::get('end_time', '', 'trim'),
  154. // 平台ID筛选
  155. 'uname' => Request::get('uname', '', 'trim'),
  156. // 玩家ID筛选
  157. 'player_id' => Request::get('user_id', '', 'trim'),
  158. // 平台昵称
  159. 'nickname' => Request::get('nickname', '', 'trim'),
  160. 'status' => Request::get('status', '', 'trim'),
  161. ];
  162. $is_end = Request::get('is_end_time', 0);
  163. $controlWhere = [];
  164. $controlWhere[] = ['user_id', '=', $userInfo['user_id']];
  165. $where = [];
  166. $isFindUserId = false;
  167. // 平台ID筛选
  168. if (!empty($filters['uname'])) {
  169. $where[] = ['uname', '=', $filters['uname']];
  170. $isFindUserId = true;
  171. }
  172. // 平台昵称筛选
  173. if (!empty($filters['nickname'])) {
  174. $where[] = ['nickname', 'like', '%' . $filters['nickname'] . '%'];
  175. $isFindUserId = true;
  176. }
  177. // 玩家id筛选
  178. if (!empty($filters['player_id'])) {
  179. $where[] = ['user_id', 'like', '%' . $filters['player_id'] . '%'];
  180. $isFindUserId = true;
  181. }
  182. if($isFindUserId) {
  183. $merchantsUserIds = MerchantsUserModel::getPlayerListByIds($userInfo['merchant_id'], $where, ['user_id']);
  184. $controlWhere[] = ['user_id', 'in', array_column($merchantsUserIds, 'user_id')];
  185. }
  186. if(!empty($filters['start_time']) && !empty($filters['end_time'])) {
  187. $controlWhere[] = ['update_time', '>=', strtotime($filters['start_time'] . " 00:00:00")];
  188. $controlWhere[] = ['update_time', '<=', strtotime($filters['end_time'] . " 23:59:59")];
  189. }
  190. if(in_array($filters['status'], ['0','1'])) {
  191. $controlWhere[] = ['status', '=', $filters['status']];
  192. }else {
  193. if(!$is_end) {
  194. $controlWhere[] = ['status', '=', 1];
  195. }
  196. }
  197. $results = GameImproveUserRtpModel::getImproveUserRtpList($userInfo['merchant_id'], $page, $limit, $controlWhere);
  198. $player_ids = array_column($results['list'], 'player_id');
  199. $playerConfig = CommonMerchantUserAndBalance::getMerchantUser($player_ids, ['user_id','uname','nickname', 'rtp']);
  200. $playerConfig = array_column($playerConfig, null, 'user_id');
  201. $userListBalance = CommonMerchantUserAndBalance::getMerchantUserBalance($player_ids);
  202. $userBalanceConfig = [];
  203. foreach ($userListBalance as $item) {
  204. $userBalanceConfig[$item['user_id']] = $item['balance'];
  205. }
  206. foreach ($results['list'] as $key => $item) {
  207. $player_id = $item['player_id'];
  208. $playerInfo = $playerConfig[$player_id] ?? [];
  209. $item['balance'] = CommonUtils::convertBalance($userBalanceConfig[$player_id] ?? 0, false);
  210. $item['bet_amount'] = CommonUtils::convertBalance($item['bet_amount'] ?? 0, false);
  211. $item['total_win_amount'] = CommonUtils::convertBalance($item['total_win_amount'] ?? 0, false);
  212. $item['old_rtp'] = bcdiv($item['old_rtp'], 100, 2) . "%";
  213. $item['now_rtp'] = bcdiv($playerInfo['rtp'] ?? 0, 100, 2) . "%";
  214. $item['status_text'] = $item['status'] == 1 ? '生效中' : "已结束";
  215. $item['evaluation_period_text'] = [
  216. '1' => '每日',
  217. '2' => '每周',
  218. '3' => '每月',
  219. '4' => '终生',
  220. '5' => '自定义时间'
  221. ][$item['evaluation_period']] ?? "";
  222. $item['start_end_time'] = "-";
  223. if(!empty($item['end_time'])) {
  224. $item['start_end_time'] = $item['create_time'] . ' ~ ' . date('Y-m-d H:i:s', $item['end_time']);
  225. }
  226. $playerInfo = $playerConfig[$player_id] ?? [];
  227. $item['uname'] = $playerInfo['uname'] ?? '';
  228. $item['nickname'] = $playerInfo['nickname'] ?? '';
  229. $adminInfo = UserModel::find($item['user_id']);
  230. $item['admin_name'] = "";
  231. if(!empty($adminInfo)) {
  232. $item['admin_name'] = $adminInfo['nick_name'] ?? '';
  233. }
  234. if(!empty($item['end_time'])) {
  235. $item['end_time'] = date('Y-m-d H:i:s', $item['end_time']);
  236. }
  237. if(!empty($item['custom_time_start']) && !empty($item['custom_time_end'])) {
  238. $item['custom_time_start'] = date('Y-m-d H:i:s', $item['custom_time_start']);
  239. $item['custom_time_end'] = date('Y-m-d H:i:s', $item['custom_time_end']);
  240. }
  241. $results['list'][$key] = $item;
  242. }
  243. return json_success($results);
  244. }
  245. /**
  246. * 取消指定RTP提升
  247. * @return \think\response\Json
  248. * @throws \think\db\exception\DataNotFoundException
  249. * @throws \think\db\exception\DbException
  250. * @throws \think\db\exception\ModelNotFoundException
  251. */
  252. public function cancelGameImproveUserRtp()
  253. {
  254. $userInfo = $this->getUserInfo();
  255. $id = Request::post('id','', 'trim');
  256. if(empty($id)) {
  257. return json_error([], '参数错误');
  258. }
  259. $info = GameImproveUserRtpModel::where(['user_id' => $userInfo['user_id'], 'id' => $id])->find();
  260. if(empty($info)) {
  261. return json_error([], '参数错误');
  262. }
  263. if(!empty($info)) {
  264. $info->end_time = time();
  265. $info->status = 0;
  266. $info->save();
  267. }
  268. return json_success([],'操作成功');
  269. }
  270. /**
  271. * 一键取消全部点控
  272. * @return \think\response\Json
  273. */
  274. public function cancelAllGameImproveUserRtp()
  275. {
  276. $userInfo = $this->getUserInfo();
  277. GameImproveUserRtpModel::where(['user_id' => $userInfo['user_id'], 'status' => 1])->save(['status' => 0, 'end_time' => time()]);
  278. return json_success([],'操作成功');
  279. }
  280. }