|
|
@@ -25,6 +25,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.cyksj.common.EnvCommonService;
|
|
|
import com.cyksj.common.constant.Constant;
|
|
|
+import com.cyksj.common.constant.PointsRecordConst;
|
|
|
import com.cyksj.common.constant.TaskTypeEnum;
|
|
|
import com.cyksj.common.constant.TransferConstant;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
@@ -77,6 +78,7 @@ import com.cyksj.model.manage.views.UpgradeOrderDetailView;
|
|
|
import com.cyksj.model.request.*;
|
|
|
import com.cyksj.model.views.*;
|
|
|
import com.cyksj.redis.RedisService;
|
|
|
+import com.cyksj.service.coin.UserGalaxyCoinService;
|
|
|
import com.cyksj.service.corp.WxCorpOps;
|
|
|
import com.cyksj.service.coupon.CouponFontService;
|
|
|
import com.cyksj.service.distribute.UserBusinessFrontService;
|
|
|
@@ -370,6 +372,14 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
|
|
|
private final GoodsClickUserOrderRecordMapper goodsClickUserOrderRecordMapper;
|
|
|
|
|
|
+ private final UserGalaxyCoinService userGalaxyCoinService;
|
|
|
+
|
|
|
+ private final OrderDonGalaxyCoinRecordMapper orderDonGalaxyCoinRecordMapper;
|
|
|
+
|
|
|
+ private final UserGalaxyCoinRecordMapper userGalaxyCoinRecordMapper;
|
|
|
+
|
|
|
+ private final OrderDonGalaxyCoinRenewRelateMapper orderDonGalaxyCoinRenewRelateMapper;
|
|
|
+
|
|
|
private final List<String> noChekGoodsTemp = List.of("Apple One", "Youtube", "Spotify");
|
|
|
|
|
|
@Transactional(rollbackFor = Throwable.class)
|
|
|
@@ -622,7 +632,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
if (sku != null) {
|
|
|
//扣除使用优惠券、余额的订单金额
|
|
|
- deductOrderMoney(orderDon, couponUser, payRequest.getBalance(), user, sku.getPrice(), goodsDon, payRequest.getGcCash(), payRequest.getGcpIds(), payRequest.getIsAcReduce(), subsidyId);
|
|
|
+ deductOrderMoney(orderDon, couponUser, payRequest.getBalance(), user, sku.getPrice(), goodsDon, payRequest.getGcCash(), payRequest.getGcpIds(), payRequest.getIsAcReduce(), subsidyId, sku, payRequest.getGalaxyCoin());
|
|
|
}
|
|
|
|
|
|
if (isSpecificPrice && (orderDon.getMoney().compareTo(BigDecimal.ZERO) == 0 || orderDon.getMoney().compareTo(specificPrice) != 0)) {
|
|
|
@@ -643,6 +653,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
this.saveOrUpdate(orderDon);
|
|
|
|
|
|
Long orderId = orderDon.getId();
|
|
|
+ //使用银河币记录
|
|
|
+ userGalaxyCoinService.handleUserGalaxyCoinOrderNotify(orderDon.getId(), orderDon.getUserId(), orderDon.getOrderNo(), OrderDonGalaxyCoinRecord.Source.ordinary);
|
|
|
Long fUid = orderDon.getUserId();
|
|
|
if (orderDon.getIsDp() != null && orderDon.getIsDp()) {
|
|
|
//保存订单优惠加购规格 关系
|
|
|
@@ -798,6 +810,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
recordUserMirrorShopOrderRelate(orderId, payRequest.getUserId(), payRequest.getCmt(), payRequest.getCustomId());
|
|
|
//记录用户环境下单数据
|
|
|
recordEnvTypeOrderRelate(orderId, payRequest.getGoodsId(), payRequest.getEnvType());
|
|
|
+ //记录银河币新入口续费数据
|
|
|
+ recordOrderDonGalaxyCoinRenewRelate(orderId, payRequest.getRenewSource());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -841,6 +855,14 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void recordOrderDonGalaxyCoinRenewRelate(Long orderId, OrderPayRequest.RenewSource renewSource) {
|
|
|
+ if (renewSource != null && renewSource == OrderPayRequest.RenewSource.galaxyCoin) {
|
|
|
+ OrderDonGalaxyCoinRenewRelate orderDonGalaxyCoinRenewRelate = new OrderDonGalaxyCoinRenewRelate();
|
|
|
+ orderDonGalaxyCoinRenewRelate.setOrderId(orderId);
|
|
|
+ orderDonGalaxyCoinRenewRelateMapper.insert(orderDonGalaxyCoinRenewRelate);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private Boolean checkIsNeedGroupsRelation(GoodsDon goodsDon) {
|
|
|
if (goodsDon.getType() == 1) {
|
|
|
//礼品卡特殊类型不需要车票
|
|
|
@@ -1057,7 +1079,16 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
//返还余额
|
|
|
if (orderDon.getBalance().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
- userBenefitsService.addUserBalance(orderDon.getUserId(), orderDon.getBalance(), null, null, null, null, false);
|
|
|
+ userBenefitsService.addUserBalance(orderDon.getUserId(), orderDon.getBalance(), UserBalanceSourceRecord.Source.order_close, null, orderId, UserBalanceSourceRecord.Source.order_close.getDesc(), true);
|
|
|
+ }
|
|
|
+
|
|
|
+ //返回银河币
|
|
|
+ UserGalaxyCoinRecord userGalaxyCoinRecord = userGalaxyCoinRecordMapper.selectOne(Wrappers.lambdaQuery(UserGalaxyCoinRecord.class)
|
|
|
+ .eq(UserGalaxyCoinRecord::getOrderId, orderDon.getId())
|
|
|
+ .eq(UserGalaxyCoinRecord::getSource, OrderDonGalaxyCoinRecord.Source.ordinary.ordinal())
|
|
|
+ .last("limit 1"));
|
|
|
+ if (userGalaxyCoinRecord != null) {
|
|
|
+ userGalaxyCoinService.sendOrderGalaxyCloseOrder(orderDon.getId(), orderDon.getUserId(), userGalaxyCoinRecord.getGalaxyCoin().abs(), OrderDonGalaxyCoinRecord.Source.ordinary);
|
|
|
}
|
|
|
|
|
|
//是否是礼品卡 现金支付订单
|
|
|
@@ -1207,7 +1238,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
//续费订单
|
|
|
orderDon.setOrderType(2);
|
|
|
orderDon.setStatus(OrderDon.Status.noPayment);
|
|
|
- orderDon.setUserId(relation.getUserId());
|
|
|
+ orderDon.setUserId(userId);
|
|
|
//续费后 是否需要更换车票
|
|
|
if (isChangeTicket) {
|
|
|
orderDon.setIsChangeTicket(isChangeTicket);
|
|
|
@@ -1238,10 +1269,12 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
orderDon.setMoney(sku.getPrice().multiply(discount));
|
|
|
}
|
|
|
//扣除使用优惠券、余额的订单金额
|
|
|
- deductOrderMoney(orderDon, couponUser, payRequest.getBalance(), user, sku.getPrice(), goodsDon, payRequest.getGcCash(), payRequest.getGcpIds(), false, null);
|
|
|
+ deductOrderMoney(orderDon, couponUser, payRequest.getBalance(), user, sku.getPrice(), goodsDon, payRequest.getGcCash(), payRequest.getGcpIds(), false, null, sku, payRequest.getGalaxyCoin());
|
|
|
this.saveOrUpdate(orderDon);
|
|
|
|
|
|
Long orderId = orderDon.getId();
|
|
|
+ //使用银河币记录
|
|
|
+ userGalaxyCoinService.handleUserGalaxyCoinOrderNotify(orderDon.getId(), orderDon.getUserId(), orderDon.getOrderNo(), OrderDonGalaxyCoinRecord.Source.ordinary);
|
|
|
//礼品卡现金使用记录
|
|
|
if (CollUtil.isNotEmpty(orderDon.getGcUseRecords())) {
|
|
|
orderDon.getGcUseRecords().forEach(data -> {
|
|
|
@@ -2484,7 +2517,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
/**
|
|
|
* 使用优惠营销 订单金额抵扣
|
|
|
*/
|
|
|
- public void deductOrderMoney(OrderDon orderDon, CouponUser couponUser, BigDecimal balance, User user, BigDecimal skuMoney, GoodsDon goodsDon, BigDecimal gcCash, List<Long> gcpIds, Boolean isAcReduce, Long subsidyId) throws Exception {
|
|
|
+ public void deductOrderMoney(OrderDon orderDon, CouponUser couponUser, BigDecimal balance, User user, BigDecimal skuMoney, GoodsDon goodsDon, BigDecimal gcCash, List<Long> gcpIds, Boolean isAcReduce, Long subsidyId, GoodsDonSku sku, BigDecimal galaxyCoin) throws Exception {
|
|
|
Integer goodsType = goodsDon.getType();
|
|
|
if (gcCash != null && gcCash.compareTo(BigDecimal.ZERO) > 0 && couponUser != null && (balance != null && balance.compareTo(BigDecimal.ZERO) > 0)) {
|
|
|
throw BusinessRuntimeException.getInstance("现金卡不能与其他优惠叠加使用");
|
|
|
@@ -2660,10 +2693,112 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if (goodsDon.getIsThirdGoods()) {
|
|
|
return;
|
|
|
}
|
|
|
+ //存在银河币
|
|
|
+ deductGalaxyCoinPayOrderMoney(orderDon, sku.getPrice(), galaxyCoin, user);
|
|
|
//存在余额
|
|
|
deductBalancePayOrderMoney(orderDon, balance, user);
|
|
|
}
|
|
|
|
|
|
+ public void deductGalaxyCoinPayOrderMoney(OrderDon orderDon, BigDecimal renewSkuDiscountPrice, BigDecimal toUseGalaxyCoin, User user) {
|
|
|
+ //存在银河币
|
|
|
+ if (toUseGalaxyCoin != null && toUseGalaxyCoin.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ BigDecimal userGalaxyCoin = user.getGalaxyCoin();
|
|
|
+ if (userGalaxyCoin.compareTo(toUseGalaxyCoin) < 0) {
|
|
|
+ throw BusinessRuntimeException.getInstance("您的银河币不足!");
|
|
|
+ }
|
|
|
+ BigDecimal orderMoney = orderDon.getMoney();
|
|
|
+ //订单金额不大于0
|
|
|
+ if (orderMoney.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //去掉余额 多出的部分
|
|
|
+ BigDecimal subGalxyCoin = toUseGalaxyCoin;
|
|
|
+ SysConfig galaxyCoinPayConfig = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class)
|
|
|
+ .eq(SysConfig::getSysKey, Constant.GALAXY_COIN_PAY_DEDUCT_KEY).last("limit 1"));
|
|
|
+ GalaxyCoinPayConfigDto galaxyCoinPayConfigDto = null;
|
|
|
+ if (galaxyCoinPayConfig != null && StrUtil.isNotEmpty(galaxyCoinPayConfig.getSysValue())) {
|
|
|
+ try {
|
|
|
+ galaxyCoinPayConfigDto = Jsons.parseObject(galaxyCoinPayConfig.getSysValue(), GalaxyCoinPayConfigDto.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+ if (galaxyCoinPayConfigDto == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("银河币抵扣系统错误,请联系客服");
|
|
|
+ }
|
|
|
+ //每个银河币可抵扣金额
|
|
|
+ BigDecimal deductMoneyEachCoin = galaxyCoinPayConfigDto.getMoney().divide(galaxyCoinPayConfigDto.getGalaxyCoin());
|
|
|
+ //此次使用抵扣金额
|
|
|
+ BigDecimal thisDeductMoney = toUseGalaxyCoin.multiply(deductMoneyEachCoin);
|
|
|
+ //该笔平台最高可抵扣金额
|
|
|
+ BigDecimal maxDeductMoney = renewSkuDiscountPrice.multiply(galaxyCoinPayConfigDto.getMaxRate());
|
|
|
+ if (thisDeductMoney.compareTo(maxDeductMoney) > 0) {
|
|
|
+ thisDeductMoney = maxDeductMoney;
|
|
|
+ }
|
|
|
+ //此次使用的银河币超过订单金额
|
|
|
+ if (thisDeductMoney.compareTo(orderMoney) > 0) {
|
|
|
+ thisDeductMoney = orderMoney;
|
|
|
+ }
|
|
|
+ //此时需要扣除的银河币
|
|
|
+ subGalxyCoin = thisDeductMoney.divide(deductMoneyEachCoin);
|
|
|
+ //银河币抵扣
|
|
|
+ List<UserGalaxyCoinRecord> availableGalaxyCoinList = userGalaxyCoinRecordMapper.selectList(Wrappers.lambdaQuery(UserGalaxyCoinRecord.class)
|
|
|
+ .eq(UserGalaxyCoinRecord::getUserId, orderDon.getUserId())
|
|
|
+ .eq(UserGalaxyCoinRecord::getIsUsed, Boolean.FALSE)
|
|
|
+ .gt(UserGalaxyCoinRecord::getExpiryTime, DateTime.now())
|
|
|
+ .gt(UserGalaxyCoinRecord::getRemainGalaxyCoin, 0));
|
|
|
+ //需要使用的银河币
|
|
|
+ BigDecimal userFinalUseGalaxyCoin = subGalxyCoin;
|
|
|
+ for (UserGalaxyCoinRecord galaxyCoinRecord : availableGalaxyCoinList) {
|
|
|
+ if (userFinalUseGalaxyCoin.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ BigDecimal remainGalaxyCoin = galaxyCoinRecord.getRemainGalaxyCoin();
|
|
|
+ Long galaxyCoinRecordId = galaxyCoinRecord.getId();
|
|
|
+ //扣完
|
|
|
+ if (remainGalaxyCoin.compareTo(userFinalUseGalaxyCoin) == 0) {
|
|
|
+ //完全抵扣
|
|
|
+ deductUserGalaxyCoin(galaxyCoinRecordId, remainGalaxyCoin, remainGalaxyCoin, true);
|
|
|
+ userFinalUseGalaxyCoin = BigDecimal.ZERO;
|
|
|
+ } else if (remainGalaxyCoin.compareTo(userFinalUseGalaxyCoin) < 0) {
|
|
|
+ //不足以抵扣
|
|
|
+ deductUserGalaxyCoin(galaxyCoinRecordId, remainGalaxyCoin, remainGalaxyCoin, true);
|
|
|
+ userFinalUseGalaxyCoin = userFinalUseGalaxyCoin.subtract(remainGalaxyCoin);
|
|
|
+ } else if (remainGalaxyCoin.compareTo(userFinalUseGalaxyCoin) > 0) {
|
|
|
+ //足以抵扣
|
|
|
+ deductUserGalaxyCoin(galaxyCoinRecordId, userFinalUseGalaxyCoin, remainGalaxyCoin, false);
|
|
|
+ userFinalUseGalaxyCoin = BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //最终消耗的银河币需要为0 大于0则说明抵扣失败
|
|
|
+ if (userFinalUseGalaxyCoin.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ throw BusinessRuntimeException.getInstance("您的银河币不足!");
|
|
|
+ }
|
|
|
+ //扣除银河币 是否成功
|
|
|
+ Integer success = userMapper.subUserGalaxyCoin(user.getId(), subGalxyCoin, userGalaxyCoin);
|
|
|
+ if (success != 1) throw BusinessRuntimeException.getInstance("您的银河币不足!");
|
|
|
+ //记录使用详情
|
|
|
+ OrderDonGalaxyCoinRecord orderDonGalaxyCoinRecord = new OrderDonGalaxyCoinRecord();
|
|
|
+ orderDonGalaxyCoinRecord.setUserId(user.getId());
|
|
|
+ orderDonGalaxyCoinRecord.setOrderNo(orderDon.getOrderNo());
|
|
|
+ orderDonGalaxyCoinRecord.setGalaxyCoin(subGalxyCoin);
|
|
|
+ orderDonGalaxyCoinRecord.setDeductMoney(thisDeductMoney);
|
|
|
+ orderDonGalaxyCoinRecordMapper.insert(orderDonGalaxyCoinRecord);
|
|
|
+ orderDon.setMoney(orderMoney.subtract(thisDeductMoney));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void deductUserGalaxyCoin(Long galaxyCoinRecordId, BigDecimal deductGalaxyCoin, BigDecimal remainGalaxyCoin, boolean isUsed) {
|
|
|
+ Integer update = userGalaxyCoinRecordMapper.update(null, Wrappers.lambdaUpdate(UserGalaxyCoinRecord.class)
|
|
|
+ .set(UserGalaxyCoinRecord::getRemainGalaxyCoin, remainGalaxyCoin.subtract(deductGalaxyCoin))
|
|
|
+ .set(isUsed, UserGalaxyCoinRecord::getIsUsed, isUsed)
|
|
|
+ .eq(UserGalaxyCoinRecord::getId, galaxyCoinRecordId)
|
|
|
+ .eq(UserGalaxyCoinRecord::getIsUsed, Boolean.FALSE)
|
|
|
+ .eq(UserGalaxyCoinRecord::getRemainGalaxyCoin, remainGalaxyCoin));
|
|
|
+ if (update == 0) {
|
|
|
+ throw BusinessRuntimeException.getInstance("银河币抵扣异常,请刷新页面重试");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 生成用户使用折扣链接记录
|
|
|
*/
|
|
|
@@ -2826,6 +2961,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if (orderDon.getBalance().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
userBenefitsService.recordBalanceBySource(orderDon.getUserId(), orderDon.getBalance().negate(), UserBalanceSourceRecord.Source.payment, orderDon.getId(), goodsDon.getTitle() + UserBalanceSourceRecord.Source.payment.getDesc(), null, null);
|
|
|
}
|
|
|
+ //是否需要返回银河币
|
|
|
+ AtomicBoolean isNeedReturnGalaxyCoin = new AtomicBoolean(Boolean.TRUE);
|
|
|
|
|
|
TASK_POOL.execute(() -> {
|
|
|
try {
|
|
|
@@ -2874,6 +3011,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
giftCardUserPayRecord(giftCardOrderRelate.getGcPayDetail(), orderDon);
|
|
|
}
|
|
|
}
|
|
|
+ isNeedReturnGalaxyCoin.set(Boolean.FALSE);
|
|
|
}
|
|
|
//下级渠道目标额达标 提成金额发放
|
|
|
sendSubDistributeRewards(orderDon);
|
|
|
@@ -2962,6 +3100,11 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ //银河币返回
|
|
|
+ if (isNeedReturnGalaxyCoin.get()) {
|
|
|
+ returnGalaxyCoin(orderDon);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void handleUserMirrorSHopOrderDon(OrderDon orderDon) throws Exception {
|
|
|
@@ -3446,6 +3589,10 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
//存在余额
|
|
|
if (balance != null && balance.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
BigDecimal money = orderDon.getMoney();
|
|
|
+ //订单金额不大于0
|
|
|
+ if (money.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
//去掉余额 多出的部分
|
|
|
BigDecimal subBalance = balance;
|
|
|
orderDon.setMoney(money.subtract(subBalance));
|
|
|
@@ -3869,10 +4016,12 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
upgradeOrderDon.setMoney(payRequest.getDonMoney());
|
|
|
upgradeOrderDon.setStatus(UpgradeOrderDon.Status.noPayment);
|
|
|
upgradeOrderDon.setType(UpgradeOrderDon.Type.ALI_PAY);
|
|
|
+ deductUpgradeBalancePayOrderMoney(upgradeOrderDon, payRequest,user);
|
|
|
upgradeOrderDonMapper.insert(upgradeOrderDon);
|
|
|
|
|
|
- deductUpgradeBalancePayOrderMoney(upgradeOrderDon, payRequest.getBalance(),user);
|
|
|
Long orderId = upgradeOrderDon.getId();
|
|
|
+ //使用银河币记录
|
|
|
+ userGalaxyCoinService.handleUserGalaxyCoinOrderNotify(upgradeOrderDon.getId(), upgradeOrderDon.getUserId(), upgradeOrderDon.getOrderNo(), OrderDonGalaxyCoinRecord.Source.upgrade);
|
|
|
if (upgradeOrderDon.getMoney().compareTo(BigDecimal.ZERO) == 0) {
|
|
|
upgradeOrderDon = upgradeOrderDonMapper.selectById(orderId);
|
|
|
unifiedHandlerUpgradeOrderNotify(upgradeOrderDon, upgradePackage);
|
|
|
@@ -3887,7 +4036,12 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- public void deductUpgradeBalancePayOrderMoney(UpgradeOrderDon orderDon, BigDecimal balance, User user) {
|
|
|
+ public void deductUpgradeBalancePayOrderMoney(UpgradeOrderDon orderDon, OrderPayRequest payRequest, User user) {
|
|
|
+ BigDecimal galaxyCoin = payRequest.getGalaxyCoin();
|
|
|
+ //存在银河币
|
|
|
+ deductGalaxyCoinPayUpgradeOrderMoney(orderDon, orderDon.getMoney(), galaxyCoin, user);
|
|
|
+
|
|
|
+ BigDecimal balance = payRequest.getBalance();
|
|
|
//存在余额
|
|
|
if (balance != null && balance.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
BigDecimal money = orderDon.getMoney();
|
|
|
@@ -4071,6 +4225,34 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ //银河币返回
|
|
|
+ returnUpgradeGalaxyCoin(orderDon);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void returnUpgradeGalaxyCoin(UpgradeOrderDon orderDon) {
|
|
|
+ if (orderDon.getMoney().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ Long userId = orderDon.getUserId();
|
|
|
+ BigDecimal money = orderDon.getMoney();
|
|
|
+ SysConfig galaxyCoinConsumeReturnRateConfig = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class)
|
|
|
+ .eq(SysConfig::getSysKey, Constant.GALAXY_COIN_CONSUME_RETURN_RATE_KEY)
|
|
|
+ .last("limit 1"));
|
|
|
+ BigDecimal retrunGalaxyCoin = BigDecimal.ZERO;
|
|
|
+ if (galaxyCoinConsumeReturnRateConfig != null && StrUtil.isNotEmpty(galaxyCoinConsumeReturnRateConfig.getSysValue())) {
|
|
|
+ try {
|
|
|
+ GalaxyCoinConsumeRateDto galaxyCoinConsumeRateDto = Jsons.parseObject(galaxyCoinConsumeReturnRateConfig.getSysValue(), GalaxyCoinConsumeRateDto.class);
|
|
|
+ BigDecimal moneyAvg = galaxyCoinConsumeRateDto.getMoney();
|
|
|
+ //返回银河币倍数
|
|
|
+ BigDecimal number = money.divide(moneyAvg, 0, RoundingMode.DOWN);;
|
|
|
+ retrunGalaxyCoin = number.multiply(galaxyCoinConsumeRateDto.getGalaxyCoin());
|
|
|
+ //发送银河币并记录
|
|
|
+ userGalaxyCoinService.sendOrderCashback(orderDon.getId(), userId, retrunGalaxyCoin.intValue(), PointsRecordConst.ORDER_CASHBACK, OrderDonGalaxyCoinRecord.Source.upgrade);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("发送用户:{}银河币points:{}套餐升级错误:{}", userId, retrunGalaxyCoin, StringUtil.getErrorText(e));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -4104,6 +4286,14 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if (orderDon.getBalance().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
userBenefitsService.addUserBalance(orderDon.getUserId(), orderDon.getBalance(), null, null, null, null, false);
|
|
|
}
|
|
|
+ //返回银河币
|
|
|
+ UserGalaxyCoinRecord userGalaxyCoinRecord = userGalaxyCoinRecordMapper.selectOne(Wrappers.lambdaQuery(UserGalaxyCoinRecord.class)
|
|
|
+ .eq(UserGalaxyCoinRecord::getOrderId, orderDon.getId())
|
|
|
+ .eq(UserGalaxyCoinRecord::getSource, OrderDonGalaxyCoinRecord.Source.upgrade.ordinal())
|
|
|
+ .last("limit 1"));
|
|
|
+ if (userGalaxyCoinRecord != null) {
|
|
|
+ userGalaxyCoinService.sendOrderGalaxyCloseOrder(orderDon.getId(), orderDon.getUserId(), userGalaxyCoinRecord.getGalaxyCoin().abs(), OrderDonGalaxyCoinRecord.Source.upgrade);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -4239,6 +4429,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
//虚拟商品订单,是否是分销订单
|
|
|
setDistributeOrderMark(orderDon, goodsDon.getType(), user.getId());
|
|
|
|
|
|
+ //存在银河币
|
|
|
+ deductGalaxyCoinPayOrderMoney(orderDon, discountPrice, payRequest.getGalaxyCoin(), user);
|
|
|
//存在余额
|
|
|
deductBalancePayOrderMoney(orderDon, payRequest.getBalance(), user);
|
|
|
|
|
|
@@ -4246,6 +4438,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
//记录续费升级的规格
|
|
|
recordRenewOrderDon(orderDon, renewUpgradePackage, groupsTrips);
|
|
|
Long orderId = orderDon.getId();
|
|
|
+ //使用银河币记录
|
|
|
+ userGalaxyCoinService.handleUserGalaxyCoinOrderNotify(orderDon.getId(), orderDon.getUserId(), orderDon.getOrderNo(), OrderDonGalaxyCoinRecord.Source.ordinary);
|
|
|
if (orderDon.getMoney().compareTo(BigDecimal.ZERO) == 0) {
|
|
|
orderDon = orderDonMapper.selectById(orderId);
|
|
|
unifiedHandlerOrderNotify(orderDon, goodsDon, renewSku);
|
|
|
@@ -4255,8 +4449,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
closeOrder(orderId, null);
|
|
|
});
|
|
|
}
|
|
|
- //记录用户镜像店铺订单
|
|
|
- recordUserMirrorShopOrderRelate(orderDon.getId(), payRequest.getUserId(), payRequest.getCmt(), payRequest.getCustomId());
|
|
|
+ //统一处理订单记录操作
|
|
|
+ unifiedHandlerOrderRecordFunc(orderId, payRequest);
|
|
|
|
|
|
//记录镜像过期车票 续费订单关联
|
|
|
if (groupsRelation.getExpiryTime() != null && groupsRelation.getExpiryTime().compareTo(DateTime.now()) <= 0) {
|
|
|
@@ -4345,6 +4539,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
//续费订单
|
|
|
orderDon.setOrderType(2);
|
|
|
}
|
|
|
+ //订单实际支付金额
|
|
|
+ BigDecimal orderDonMoney = orderDon.getMoney();
|
|
|
if (orderDon.getMoney().compareTo(BigDecimal.ZERO) < 0) {
|
|
|
throw BusinessRuntimeException.getInstance("订单金额错误");
|
|
|
}
|
|
|
@@ -4373,6 +4569,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
//虚拟商品订单,是否是分销订单
|
|
|
setDistributeOrderMark(orderDon, goodsDon.getType(), user.getId());
|
|
|
}
|
|
|
+ //存在银河币
|
|
|
+ deductGalaxyCoinPayOrderMoney(orderDon, orderDonMoney, orderPayRequest.getGalaxyCoin(), user);
|
|
|
BigDecimal balance = orderPayRequest.getBalance();
|
|
|
//存在余额
|
|
|
deductBalancePayOrderMoney(orderDon, balance, user);
|
|
|
@@ -4380,6 +4578,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
//设置订单支付商品信息
|
|
|
setOrderDonPayTile(null, null, null, orderDon, goodsDon, sku, null);
|
|
|
this.saveOrUpdate(orderDon);
|
|
|
+ //使用银河币记录
|
|
|
+ userGalaxyCoinService.handleUserGalaxyCoinOrderNotify(orderDon.getId(), orderDon.getUserId(), orderDon.getOrderNo(), OrderDonGalaxyCoinRecord.Source.ordinary);
|
|
|
if (orderDon.getStatus() == OrderDon.Status.noPayment) {
|
|
|
jobManager.addJob(EXPIRY_TIME, () -> {
|
|
|
closeOrder(orderDon.getId(), null);
|
|
|
@@ -4807,4 +5007,119 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public void returnGalaxyCoin(OrderDon orderDon) {
|
|
|
+ if (orderDon.getMoney().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ Long userId = orderDon.getUserId();
|
|
|
+ BigDecimal money = orderDon.getMoney();
|
|
|
+ SysConfig galaxyCoinConsumeReturnRateConfig = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class)
|
|
|
+ .eq(SysConfig::getSysKey, Constant.GALAXY_COIN_CONSUME_RETURN_RATE_KEY)
|
|
|
+ .last("limit 1"));
|
|
|
+ BigDecimal retrunGalaxyCoin = BigDecimal.ZERO;
|
|
|
+ if (galaxyCoinConsumeReturnRateConfig != null && StrUtil.isNotEmpty(galaxyCoinConsumeReturnRateConfig.getSysValue())) {
|
|
|
+ try {
|
|
|
+ GalaxyCoinConsumeRateDto galaxyCoinConsumeRateDto = Jsons.parseObject(galaxyCoinConsumeReturnRateConfig.getSysValue(), GalaxyCoinConsumeRateDto.class);
|
|
|
+ BigDecimal moneyAvg = galaxyCoinConsumeRateDto.getMoney();
|
|
|
+ //返回银河币倍数
|
|
|
+ BigDecimal number = money.divide(moneyAvg, 0, RoundingMode.DOWN);
|
|
|
+ retrunGalaxyCoin = number.multiply(galaxyCoinConsumeRateDto.getGalaxyCoin());
|
|
|
+ //发送银河币并记录
|
|
|
+ userGalaxyCoinService.sendOrderCashback(orderDon.getId(), userId, retrunGalaxyCoin.intValue(), PointsRecordConst.ORDER_CASHBACK, OrderDonGalaxyCoinRecord.Source.ordinary);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("发送用户:{}银河币points:{}错误:{}", userId, retrunGalaxyCoin, StringUtil.getErrorText(e));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void deductGalaxyCoinPayUpgradeOrderMoney(UpgradeOrderDon orderDon, BigDecimal discountPrice, BigDecimal toUseGalaxyCoin, User user) {
|
|
|
+ //存在银河币
|
|
|
+ if (toUseGalaxyCoin != null && toUseGalaxyCoin.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ BigDecimal userGalaxyCoin = user.getGalaxyCoin();
|
|
|
+ if (userGalaxyCoin.compareTo(toUseGalaxyCoin) < 0) {
|
|
|
+ throw BusinessRuntimeException.getInstance("您的银河币不足!");
|
|
|
+ }
|
|
|
+ BigDecimal orderMoney = orderDon.getMoney();
|
|
|
+ //订单金额不大于0
|
|
|
+ if (orderMoney.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //去掉余额 多出的部分
|
|
|
+ BigDecimal subGalxyCoin;
|
|
|
+ SysConfig galaxyCoinPayConfig = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class)
|
|
|
+ .eq(SysConfig::getSysKey, Constant.GALAXY_COIN_PAY_DEDUCT_KEY).last("limit 1"));
|
|
|
+ GalaxyCoinPayConfigDto galaxyCoinPayConfigDto = null;
|
|
|
+ if (galaxyCoinPayConfig != null && StrUtil.isNotEmpty(galaxyCoinPayConfig.getSysValue())) {
|
|
|
+ try {
|
|
|
+ galaxyCoinPayConfigDto = Jsons.parseObject(galaxyCoinPayConfig.getSysValue(), GalaxyCoinPayConfigDto.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+ if (galaxyCoinPayConfigDto == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("银河币抵扣系统错误,请联系客服");
|
|
|
+ }
|
|
|
+ //每个银河币可抵扣金额
|
|
|
+ BigDecimal deductMoneyEachCoin = galaxyCoinPayConfigDto.getMoney().divide(galaxyCoinPayConfigDto.getGalaxyCoin());
|
|
|
+ //此次使用抵扣金额
|
|
|
+ BigDecimal thisDeductMoney = toUseGalaxyCoin.multiply(deductMoneyEachCoin);
|
|
|
+ //该笔平台最高可抵扣金额
|
|
|
+ BigDecimal maxDeductMoney = discountPrice.multiply(galaxyCoinPayConfigDto.getMaxRate());
|
|
|
+ if (thisDeductMoney.compareTo(maxDeductMoney) > 0) {
|
|
|
+ thisDeductMoney = maxDeductMoney;
|
|
|
+ }
|
|
|
+ //此次使用的银河币超过订单金额
|
|
|
+ if (thisDeductMoney.compareTo(orderMoney) > 0) {
|
|
|
+ thisDeductMoney = orderMoney;
|
|
|
+ }
|
|
|
+ //此时需要扣除的银河币
|
|
|
+ subGalxyCoin = thisDeductMoney.divide(deductMoneyEachCoin);
|
|
|
+ //银河币抵扣
|
|
|
+ List<UserGalaxyCoinRecord> availableGalaxyCoinList = userGalaxyCoinRecordMapper.selectList(Wrappers.lambdaQuery(UserGalaxyCoinRecord.class)
|
|
|
+ .eq(UserGalaxyCoinRecord::getUserId, orderDon.getUserId())
|
|
|
+ .eq(UserGalaxyCoinRecord::getIsUsed, Boolean.FALSE)
|
|
|
+ .gt(UserGalaxyCoinRecord::getExpiryTime, DateTime.now())
|
|
|
+ .gt(UserGalaxyCoinRecord::getRemainGalaxyCoin, 0));
|
|
|
+ //需要使用的银河币
|
|
|
+ BigDecimal userFinalUseGalaxyCoin = subGalxyCoin;
|
|
|
+ for (UserGalaxyCoinRecord galaxyCoinRecord : availableGalaxyCoinList) {
|
|
|
+ if (userFinalUseGalaxyCoin.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ BigDecimal remainGalaxyCoin = galaxyCoinRecord.getRemainGalaxyCoin();
|
|
|
+ Long galaxyCoinRecordId = galaxyCoinRecord.getId();
|
|
|
+ //扣完
|
|
|
+ if (remainGalaxyCoin.compareTo(userFinalUseGalaxyCoin) == 0) {
|
|
|
+ //完全抵扣
|
|
|
+ deductUserGalaxyCoin(galaxyCoinRecordId, remainGalaxyCoin, remainGalaxyCoin, true);
|
|
|
+ userFinalUseGalaxyCoin = BigDecimal.ZERO;
|
|
|
+ } else if (remainGalaxyCoin.compareTo(userFinalUseGalaxyCoin) < 0) {
|
|
|
+ //不足以抵扣
|
|
|
+ deductUserGalaxyCoin(galaxyCoinRecordId, remainGalaxyCoin, remainGalaxyCoin, true);
|
|
|
+ userFinalUseGalaxyCoin = userFinalUseGalaxyCoin.subtract(remainGalaxyCoin);
|
|
|
+ } else if (remainGalaxyCoin.compareTo(userFinalUseGalaxyCoin) > 0) {
|
|
|
+ //足以抵扣
|
|
|
+ deductUserGalaxyCoin(galaxyCoinRecordId, userFinalUseGalaxyCoin, remainGalaxyCoin, false);
|
|
|
+ userFinalUseGalaxyCoin = BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //最终消耗的银河币需要为0 大于0则说明抵扣失败
|
|
|
+ if (userFinalUseGalaxyCoin.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ throw BusinessRuntimeException.getInstance("您的银河币不足!");
|
|
|
+ }
|
|
|
+ //扣除银河币 是否成功
|
|
|
+ Integer success = userMapper.subUserGalaxyCoin(user.getId(), subGalxyCoin, userGalaxyCoin);
|
|
|
+ if (success != 1) throw BusinessRuntimeException.getInstance("您的银河币不足!");
|
|
|
+ //记录使用详情
|
|
|
+ OrderDonGalaxyCoinRecord orderDonGalaxyCoinRecord = new OrderDonGalaxyCoinRecord();
|
|
|
+ orderDonGalaxyCoinRecord.setUserId(user.getId());
|
|
|
+ orderDonGalaxyCoinRecord.setOrderNo(orderDon.getOrderNo());
|
|
|
+ orderDonGalaxyCoinRecord.setGalaxyCoin(subGalxyCoin);
|
|
|
+ orderDonGalaxyCoinRecord.setDeductMoney(thisDeductMoney);
|
|
|
+ //套餐升级来源
|
|
|
+ orderDonGalaxyCoinRecord.setSource(OrderDonGalaxyCoinRecord.Source.upgrade.ordinal());
|
|
|
+ orderDonGalaxyCoinRecordMapper.insert(orderDonGalaxyCoinRecord);
|
|
|
+ orderDon.setMoney(orderMoney.subtract(thisDeductMoney));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|