|
|
@@ -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,12 @@ 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 List<String> noChekGoodsTemp = List.of("Apple One", "Youtube", "Spotify");
|
|
|
|
|
|
@Transactional(rollbackFor = Throwable.class)
|
|
|
@@ -622,7 +630,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)) {
|
|
|
@@ -1238,7 +1246,7 @@ 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();
|
|
|
@@ -2484,7 +2492,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("现金卡不能与其他优惠叠加使用");
|
|
|
@@ -2662,6 +2670,103 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
//存在余额
|
|
|
deductBalancePayOrderMoney(orderDon, balance, user);
|
|
|
+ //存在银河币
|
|
|
+ deductGalaxyCoinPayOrderMoney(orderDon, sku, galaxyCoin, user);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void deductGalaxyCoinPayOrderMoney(OrderDon orderDon, GoodsDonSku sku, 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.getGalaxyCoin().divide(galaxyCoinPayConfigDto.getMoney());
|
|
|
+ //此次使用抵扣金额
|
|
|
+ BigDecimal thisDeductMoney = toUseGalaxyCoin.multiply(deductMoneyEachCoin);
|
|
|
+ //该笔平台最高可抵扣金额
|
|
|
+ BigDecimal maxDeductMoney = sku.getPrice().multiply(galaxyCoinPayConfigDto.getMaxRate());
|
|
|
+ if (thisDeductMoney.compareTo(maxDeductMoney) > 0) {
|
|
|
+ thisDeductMoney = maxDeductMoney;
|
|
|
+ //此时需要扣除的银河币
|
|
|
+ subGalxyCoin = thisDeductMoney.divide(deductMoneyEachCoin);
|
|
|
+ }
|
|
|
+ if (orderDon.getMoney().compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ orderDon.setType(OrderDon.Type.GALAXY_COIN);
|
|
|
+ }
|
|
|
+ //银河币抵扣
|
|
|
+ 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) {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 +2931,17 @@ 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);
|
|
|
}
|
|
|
+ //银河币使用记录
|
|
|
+ OrderDonGalaxyCoinRecord orderDonGalaxyCoinRecord = orderDonGalaxyCoinRecordMapper.selectOne(Wrappers.lambdaQuery(OrderDonGalaxyCoinRecord.class)
|
|
|
+ .eq(OrderDonGalaxyCoinRecord::getOrderNo, orderDon.getOrderNo())
|
|
|
+ .last("limit 1"));
|
|
|
+ if (orderDonGalaxyCoinRecord != null) {
|
|
|
+ //使用记录
|
|
|
+ userGalaxyCoinService.recordUseRecord(orderDon.getId(), orderDon.getUserId(), orderDonGalaxyCoinRecord.getGalaxyCoin(), PointsRecordConst.ORDER);
|
|
|
+ orderDonGalaxyCoinRecord.setRefundGalaxyCoin(orderDonGalaxyCoinRecord.getGalaxyCoin());
|
|
|
+ orderDonGalaxyCoinRecord.setOrderId(orderDon.getId());
|
|
|
+ orderDonGalaxyCoinRecordMapper.updateById(orderDonGalaxyCoinRecord);
|
|
|
+ }
|
|
|
|
|
|
TASK_POOL.execute(() -> {
|
|
|
try {
|
|
|
@@ -2962,6 +3078,9 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ //银河币返回
|
|
|
+ returnGalaxyCoin(orderDon);
|
|
|
}
|
|
|
|
|
|
private void handleUserMirrorSHopOrderDon(OrderDon orderDon) throws Exception {
|
|
|
@@ -3446,6 +3565,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));
|
|
|
@@ -4807,4 +4930,29 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private 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.sendGalaxyCoinRecord(userId, retrunGalaxyCoin.intValue(), PointsRecordConst.ORDER_CASHBACK, false);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("发送用户:{}银河币points:{}错误:{}", userId, retrunGalaxyCoin, StringUtil.getErrorText(e));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|