GameControlAutoRTPConfigModel.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace app\model;
  3. use think\Model;
  4. class GameControlAutoRTPConfigModel extends Model
  5. {
  6. // 设置表名
  7. protected $name = 'control_auto_rtp_config';
  8. protected $connection = 'fortue_tiger';
  9. // 设置主键
  10. protected $pk = 'id';
  11. // 设置自动时间戳
  12. protected $autoWriteTimestamp = 'int';
  13. // 设置字段类型
  14. protected $type = [
  15. 'id' => 'int',
  16. 'app_id' => 'int', // 商户ID
  17. 'new_user_number' => 'int', // 定义新手玩家的游戏局数
  18. 'float_rate' => 'int', // 玩家RTP高于游戏设定RTP进入系统判断
  19. 'rtp_check' => 'int', // 游戏内统计数据周期
  20. 'rtp_float' => 'int', // 玩家RTP上下限的误差范围
  21. 'status' => 'int', // 状态 1 正常,0 取消
  22. 'rtp_kill_data' => 'string', // 配置列表
  23. 'create_time' => 'int',
  24. 'update_time' => 'int',
  25. ];
  26. /**
  27. * 初始化 生成默认配置
  28. * @param $appId
  29. * @return array
  30. */
  31. public static function initCreateData($appId) {
  32. $form = [
  33. 'app_id' => $appId,
  34. 'new_user_number' => 150,
  35. 'float_rate' => 15 * 100,
  36. 'rtp_check' => 10,
  37. 'rtp_float' => 2.5 * 100,
  38. 'status' => 1,
  39. 'rtp_kill_data' => [
  40. ['new' => 0, 'old' => 5000,], // defaultRtpValue * 100 + float_rate ~ defaultRtpValue * 100 + float_rate + (rtp_float * 2)
  41. ['new' => 500, 'old' => 5000],
  42. ['new' => 1000, 'old' => 5000],
  43. ['new' => 1500, 'old' => 5000],
  44. ['new' => 2000, 'old' => 5000],
  45. ['new' => 2000, 'old' => 5000],
  46. ['new' => 2000, 'old' => 6000],
  47. ['new' => 2000, 'old' => 7000],
  48. ['new' => 2000, 'old' => 8000],
  49. ['new' => 2000, 'old' => 9000],
  50. ]
  51. ];
  52. $form['rtp_kill_data'] = json_encode($form['rtp_kill_data']);
  53. self::create($form);
  54. return $form;
  55. }
  56. public static function getAutoRtpConfigInfo($app_id, $defaultRtp = null)
  57. {
  58. $info = self::where(['app_id' => $app_id])->find();
  59. if(empty($info)) {
  60. return null;
  61. }
  62. $info = $info->toArray();
  63. $info['rtp_kill_data'] = json_decode($info['rtp_kill_data'], true);
  64. $diff_rtp = $info['rtp_float'] * 2;
  65. $rtp = ($defaultRtp ?? $GLOBALS['defaultRTPValue']) * 100;
  66. foreach ($info['rtp_kill_data'] as $idx => $item) {
  67. // $start = $rtp + ($diff_rtp * $idx) + $info['float_rate'];
  68. // $end = $start + $diff_rtp;
  69. $item['new'] = bcdiv($item['new'], 100, 2) * 1;
  70. $item['old'] = bcdiv($item['old'], 100, 2) * 1;
  71. $info['rtp_kill_data'][$idx] = $item;
  72. }
  73. $info['float_rate'] = bcdiv($info['float_rate'], 100, 2) * 1;
  74. $info['rtp_float'] = bcdiv($info['rtp_float'], 100, 2) * 1;
  75. $info['default_rtp'] = bcdiv($rtp, 100, 2) * 1;
  76. return $info;
  77. }
  78. }