GameControlAutoRTPConfig.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace app\controller;
  3. use app\BaseController;
  4. use app\model\GameControlAutoRTPConfigModel;
  5. use think\facade\Request;
  6. class GameControlAutoRTPConfig extends BaseController
  7. {
  8. /**
  9. * 更新自动RTP配置
  10. */
  11. public function updateAutoRTPConfig()
  12. {
  13. $float_rate = Request::post('float_rate',0, 'intval');
  14. $new_user_number = Request::post('new_user_number',0, 'intval');
  15. $rtp_kill_data = Request::post('rtp_kill_data',[]);
  16. if( empty($float_rate) || empty($new_user_number) || empty($rtp_kill_data)){
  17. return json_error([],'参数错误');
  18. }
  19. if(count($rtp_kill_data) > 10) {
  20. return json_error([],'玩家RTP区间不能超过10个');
  21. }
  22. $userInfo = $this->getUserInfo();
  23. $info = GameControlAutoRTPConfigModel::where(['app_id' => $userInfo['merchant_id']])->find();
  24. if(empty($info)){
  25. return json_error([],'参数错误');
  26. }
  27. $info->float_rate = bcmul( $float_rate , 100) * 1;
  28. $info->new_user_number = $new_user_number;
  29. foreach ($rtp_kill_data as $idx => $item) {
  30. $item['new'] = ($item['new'] ?? 0) * 100;
  31. $item['old'] = ($item['old'] ?? 0) * 100;
  32. $rtp_kill_data[$idx] = $item;
  33. }
  34. $info->rtp_kill_data = json_encode( $rtp_kill_data);
  35. $info->save();
  36. return json_success([]);
  37. }
  38. /**
  39. * 获取自动RTP配置
  40. * @return \think\response\Json
  41. */
  42. public function getAutoRTPConfigInfo()
  43. {
  44. $userInfo = $this->getUserInfo();
  45. $autoRtpConfig = GameControlAutoRTPConfigModel::getAutoRTPConfigInfo($userInfo['merchant_id']);
  46. if(empty($autoRtpConfig)){
  47. return json_success([
  48. 'total' => 0,
  49. 'list' => []
  50. ]);
  51. }
  52. return json_success([
  53. 'total' => 1,
  54. 'list' => [$autoRtpConfig]
  55. ]);
  56. }
  57. /**
  58. * 更新自动RTP配置状态
  59. * @return \think\response\Json
  60. * @throws \think\db\exception\DataNotFoundException
  61. * @throws \think\db\exception\DbException
  62. * @throws \think\db\exception\ModelNotFoundException
  63. */
  64. public function updateAutoRTPStatus()
  65. {
  66. $status = Request::post("status", 0, "trim");
  67. $id = Request::post("id", 0, "trim");
  68. if(empty($id)){
  69. return json_error([],'参数错误');
  70. }
  71. $info = GameControlAutoRTPConfigModel::find($id);
  72. if(empty($info)){
  73. return json_error([],'参数错误');
  74. }
  75. $info->status = $status;
  76. $info->save();
  77. return json_success();
  78. }
  79. }