|
@@ -3,12 +3,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 com.zanxiang.module.util.NumberUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.RandomUtils;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Objects;
|
|
|
import java.util.function.Function;
|
|
|
|
|
|
+@Slf4j
|
|
|
public class BackPolicyUtil {
|
|
|
private static final long[] RECHARGE_LEVEL = {12 * 100L, 30 * 100L, 50 * 100L, 98 * 100L, 198 * 100L, 328 * 100L, 649 * 100L, 998 * 100L, 2998 * 100L};
|
|
|
|
|
@@ -24,8 +28,9 @@ public class BackPolicyUtil {
|
|
|
* @param lastBackFunction 在指定最近订单数量内是否有订单回传过
|
|
|
* @return <是否回传, 回传金额>
|
|
|
*/
|
|
|
- public static boolean backOrder(GameBackPolicy gameBackPolicy, long rechargeMoney, FirstOrder firstOrder, Function<Integer, Integer> lastBackFunction) {
|
|
|
+ public static boolean backOrder(String orderId, GameBackPolicy gameBackPolicy, long rechargeMoney, FirstOrder firstOrder, Function<Integer, Integer> lastBackFunction) {
|
|
|
if (null == gameBackPolicy) {
|
|
|
+ log.error("订单 id[{}]通过回传策略[null]判断后,是否回传:{}.", orderId, true);
|
|
|
return true;
|
|
|
}
|
|
|
Integer firstType;
|
|
@@ -73,14 +78,22 @@ public class BackPolicyUtil {
|
|
|
String[] temp = backRate.split(":");
|
|
|
int backCount = Integer.parseInt(temp[0]);
|
|
|
int ignoreCount = Integer.parseInt(temp[1]);
|
|
|
+ if (backCount == 0) {
|
|
|
+ log.error("订单 id[{}]通过回传策略[{}]判断后,是否回传:{}.", orderId, gameBackPolicy.getId(), false);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
if (ignoreCount == 0) {
|
|
|
+ log.error("订单 id[{}]通过回传策略[{}]判断后,是否回传:{}.", orderId, gameBackPolicy.getId(), true);
|
|
|
return true;
|
|
|
}
|
|
|
int isBackCount = lastBackFunction.apply(backCount + ignoreCount - 1);
|
|
|
+ log.error("订单 id[{}]通过回传策略[{}]判断后,是否回传:{}.", orderId, gameBackPolicy.getId(), (isBackCount < backCount));
|
|
|
return isBackCount < backCount;
|
|
|
} else if (Objects.equals(backType, GameBackPolicy.POLICY_TYPE_RANDOM_RATE)) {
|
|
|
// 随机概率回传
|
|
|
- return RandomUtils.nextInt(0, 100) <= Integer.parseInt(backRate);
|
|
|
+ boolean isBack = RandomUtils.nextInt(0, 100) <= NumberUtil.multiply100(new BigDecimal(backRate)).intValue();
|
|
|
+ log.error("订单 id[{}]通过回传策略[{}]判断后,是否回传:{}.", orderId, gameBackPolicy.getId(), isBack);
|
|
|
+ return isBack;
|
|
|
} else {
|
|
|
throw new RuntimeException("回传策略[" + gameBackPolicy.getId() + "]配置错误,未知的回传类型:" + backType);
|
|
|
}
|