| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- 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.minpay.db.table.mapper.VmOrderInfMapper;
- import com.minpay.db.table.mapper.VmProEquRelMapper;
- import com.minpay.db.table.model.VmOrderDetails;
- import com.minpay.db.table.model.VmOrderInf;
- import com.minpay.db.table.model.VmProEquRel;
- import com.minpay.shouhuo.deliveryaction.DeliveryAction;
- import com.startup.minpay.frame.exception.MINBusinessException;
- import com.startup.minpay.frame.service.base.IMINDataBaseService;
- 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;
- }
- public List<DrawDto> orderDrawGame(VmOrderInf orderInf, VmProEquRel proEquRel, VmOrderDetails vmOrderDetails) throws BusinessCodeException, MINBusinessException {
- //获取累计金额
- String accumulatedAmount = proEquRel.getAccumulatedAmount();
- //获取中奖范围
- String drawAmount = proEquRel.getDrawAmount();
- //订单金额
- String orderAmt = orderInf.getOrderAmt();
- //计算当前累计金额
- String amt = CommonUtil.add(accumulatedAmount,orderAmt);
- String[] drawAmountStr = drawAmount.split("-");
- //开始金额
- String startAmt = drawAmountStr[0];
- //结束金额
- String endAmt = drawAmountStr[0];
- List<DrawDto> drawDtoList = null;
- DrawDto drawDto = new DrawDto();
- drawDto.setHuodaoNo(proEquRel.getId());
- drawDto.setOrderId(orderInf.getId());
- drawDto.setOrderDetailsId(vmOrderDetails.getDetailsId());
- //在范围内中奖
- if(Double.parseDouble(startAmt) <= Double.parseDouble(amt) && Double.parseDouble(amt) >= Double.parseDouble(endAmt)){
- //重置货道累计金额
- proEquRel.setAccumulatedAmount("0");
- drawDto.setDraw(true);
- }else{
- drawDto.setDraw(false);
- if(Double.parseDouble(amt) > Double.parseDouble(endAmt)){
- //追加累计金额
- proEquRel.setAccumulatedAmount("0");
- }else{
- //追加累计金额
- proEquRel.setAccumulatedAmount(amt);
- }
- }
- Service.lookup(IMINDataBaseService.class)
- .getMybatisMapper(VmProEquRelMapper.class)
- .updateByPrimaryKeySelective(proEquRel);
- //todo 更新 订单表, 订单详情表,提货表
- return drawDtoList;
- }
- }
|