|
@@ -0,0 +1,76 @@
|
|
|
+package com.minpay.common.service.impl;
|
|
|
+
|
|
|
+import com.minpay.common.bean.DrawDto;
|
|
|
+import com.minpay.common.exception.BusinessCodeException;
|
|
|
+import com.minpay.common.service.IDrawService;
|
|
|
+import com.minpay.common.service.IPublicService;
|
|
|
+import com.minpay.common.util.CommonUtil;
|
|
|
+import com.startup.minpay.frame.exception.MINBusinessException;
|
|
|
+import com.startup.minpay.frame.service.base.Service;
|
|
|
+import com.startup.minpay.frame.target.MINComponent;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 中奖计算
|
|
|
+ * @author xubaohai
|
|
|
+ */
|
|
|
+@MINComponent
|
|
|
+public class DrawServiceImpl implements IDrawService {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 幸运购的玩法
|
|
|
+ * @param payAmt 支付金额(元)
|
|
|
+ * @param orderId 订单号
|
|
|
+ * @param payOrderId 第三方支付订单号
|
|
|
+ * @throws BusinessCodeException 系统异常
|
|
|
+ * @throws MINBusinessException 框架异常
|
|
|
+ */
|
|
|
+ public List<DrawDto> xingyunDraw(String payAmt, String orderId, String payOrderId,
|
|
|
+ String shouhuojiNo, List<DrawDto> drawDtoList) throws BusinessCodeException, MINBusinessException {
|
|
|
+ System.out.println("参与商品的数量:" + drawDtoList.size());
|
|
|
+ boolean isDraw = false;
|
|
|
+ payAmt = CommonUtil.divide(payAmt, String.valueOf(drawDtoList.size()));
|
|
|
+ System.out.println("每个商品的抽奖价格:" + payAmt);
|
|
|
+ String amtFen = CommonUtil.multiply(payAmt, "100");
|
|
|
+ BigDecimal big2 = new BigDecimal(amtFen);
|
|
|
+ amtFen = big2.setScale(0, BigDecimal.ROUND_HALF_DOWN).toString();
|
|
|
+ // 参与计算的随机数
|
|
|
+ String useOrderId = orderId;
|
|
|
+ // 第三方支付订单号不为空
|
|
|
+ if(CommonUtil.isNotEmpty(payOrderId)) {
|
|
|
+ // 支付宝的支付订单号,取后10位+34 进行计算。(加的这个数字,总后台可以更改,或者在系统里面每次随机从1-99选择一个数字加进去)
|
|
|
+ String suijishu = Service.lookup(IPublicService.class).getSysParValue("ZHONGJIANG_SUIJISHU");
|
|
|
+ useOrderId = CommonUtil.add(payOrderId, suijishu);
|
|
|
+ BigDecimal bigUse = new BigDecimal(useOrderId);
|
|
|
+ useOrderId = bigUse.setScale(0, BigDecimal.ROUND_HALF_DOWN).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ // TODO 汇率,获取机器的汇率
|
|
|
+ String huilv = "40";
|
|
|
+ // 汇率百分比
|
|
|
+ String huilvBaiFenBi = CommonUtil.divide(huilv, "100");
|
|
|
+ String mu = CommonUtil.multiply(amtFen, huilvBaiFenBi);
|
|
|
+ BigDecimal big = new BigDecimal(mu);
|
|
|
+ String muVal = big.setScale(0, BigDecimal.ROUND_HALF_DOWN).toString();
|
|
|
+ System.out.println("需要减去的汇率:" + muVal);
|
|
|
+ // 需要获取的范围
|
|
|
+ int jisuanAmtFen = Integer.parseInt(amtFen) - Integer.parseInt(muVal);
|
|
|
+ System.out.println("随机数范围:" + jisuanAmtFen);
|
|
|
+ for(DrawDto drawDto : drawDtoList) {
|
|
|
+ String chouJiangFen = CommonUtil.multiply(drawDto.getChouJiangAmt(), "100");
|
|
|
+ BigDecimal bigChouJiangFen = new BigDecimal(chouJiangFen);
|
|
|
+ chouJiangFen = bigChouJiangFen.setScale(0, BigDecimal.ROUND_HALF_DOWN).toString();
|
|
|
+ // 余数
|
|
|
+ int yushu = Integer.parseInt(useOrderId) % Integer.parseInt(chouJiangFen);
|
|
|
+ System.out.println("货到号:" + drawDto.getHuodaoNo() + ", 余数:" + yushu);
|
|
|
+ if(yushu > 1 && yushu < jisuanAmtFen) {
|
|
|
+ drawDto.setDraw(true);
|
|
|
+ }
|
|
|
+ System.out.println("货到号:" + drawDto.getHuodaoNo() + ", 是否中奖:" + drawDto.isDraw());
|
|
|
+ }
|
|
|
+ return drawDtoList;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|