|
@@ -1,15 +1,16 @@
|
|
|
package com.zanxiang.game.back.serve.utils;
|
|
|
|
|
|
+import com.github.sd4324530.jtuple.Tuple2;
|
|
|
+import com.github.sd4324530.jtuple.Tuples;
|
|
|
import com.zanxiang.game.back.serve.pojo.entity.GameBackPolicy;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.math.RoundingMode;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Random;
|
|
|
import java.util.function.Function;
|
|
|
|
|
|
public class BackPolicyUtil {
|
|
|
- private static final long[] RECHARGE_LEVEL = {8 * 100L, 50 * 100L, 98 * 100L, 198 * 100L, 328 * 100L, 649 * 100L, 998 * 100L, 2998 * 100L};
|
|
|
+ private static final long[] RECHARGE_LEVEL = {12 * 100L, 30 * 100L, 50 * 100L, 98 * 100L, 198 * 100L, 328 * 100L, 649 * 100L, 998 * 100L, 2998 * 100L};
|
|
|
|
|
|
static {
|
|
|
Arrays.sort(RECHARGE_LEVEL);
|
|
@@ -45,7 +46,7 @@ public class BackPolicyUtil {
|
|
|
* @param lastBackFunction 在指定最近订单数量内是否有订单回传过
|
|
|
* @return <是否回传, 回传金额>
|
|
|
*/
|
|
|
- public static boolean backOrder(GameBackPolicy gameBackPolicy, long rechargeMoney, Function<Integer, Boolean> lastBackFunction) {
|
|
|
+ public static boolean backOrder(GameBackPolicy gameBackPolicy, long rechargeMoney, Function<Integer, Integer> lastBackFunction) {
|
|
|
if (null == gameBackPolicy) {
|
|
|
return true;
|
|
|
}
|
|
@@ -61,9 +62,12 @@ public class BackPolicyUtil {
|
|
|
if (percentage == null || percentage.compareTo(BigDecimal.ONE) >= 0) {
|
|
|
return true;
|
|
|
}
|
|
|
- // 平均每 [backUnit] 笔订单上报一笔
|
|
|
- int backUnit = BigDecimal.ONE.divide(percentage, 0, RoundingMode.HALF_UP).intValue();
|
|
|
- if (lastBackFunction.apply(backUnit)) {
|
|
|
+ int backRate = percentage.multiply(BigDecimal.TEN).intValue();
|
|
|
+ Tuple2<Integer, Integer> temp = approximate(backRate, 10);
|
|
|
+ backRate = temp.first;
|
|
|
+ int backUnit = temp.second;
|
|
|
+ int backCount = lastBackFunction.apply(backUnit);
|
|
|
+ if (backCount >= backRate) {
|
|
|
// 之前有订单上报过,这笔订单不上报了
|
|
|
return false;
|
|
|
} else {
|
|
@@ -71,6 +75,23 @@ public class BackPolicyUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private static Tuple2<Integer, Integer> approximate(int molecular, int denominator) {
|
|
|
+ if (molecular % denominator == 0) {
|
|
|
+ int temp = molecular / denominator;
|
|
|
+ return Tuples.tuple(temp, temp);
|
|
|
+ }
|
|
|
+ int model = 2;
|
|
|
+ do {
|
|
|
+ if (molecular % model == 0 && denominator % model == 0) {
|
|
|
+ molecular = molecular / model;
|
|
|
+ denominator = denominator / model;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ model++;
|
|
|
+ } while (model <= denominator / 2);
|
|
|
+ return Tuples.tuple(molecular, denominator);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 降档
|
|
|
*/
|