|
@@ -1,5 +1,16 @@
|
|
|
package com.chelvc.cloud.vehicle.server.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.chelvc.cloud.vehicle.api.service.UserInviteService;
|
|
|
+import com.chelvc.cloud.vehicle.server.dao.OmsOrderMapper;
|
|
|
+import com.chelvc.cloud.vehicle.server.entity.OmsOrder;
|
|
|
+import com.chelvc.cloud.vehicle.server.service.*;
|
|
|
+import com.chelvc.framework.common.exception.ResourceUnavailableException;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
import java.io.BufferedInputStream;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.FileNotFoundException;
|
|
@@ -15,22 +26,6 @@ import java.security.cert.X509Certificate;
|
|
|
import java.util.Date;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
-import com.chelvc.cloud.vehicle.api.service.UserInviteService;
|
|
|
-import com.chelvc.cloud.vehicle.server.dao.OmsOrderMapper;
|
|
|
-import com.chelvc.cloud.vehicle.server.entity.OmsOrder;
|
|
|
-import com.chelvc.cloud.vehicle.server.service.AssetService;
|
|
|
-import com.chelvc.cloud.vehicle.server.service.BalanceDetailService;
|
|
|
-import com.chelvc.cloud.vehicle.server.service.OrderHandleService;
|
|
|
-import com.chelvc.cloud.vehicle.server.service.PlatformProfitRatioService;
|
|
|
-import com.chelvc.cloud.vehicle.server.service.UserProfitRatioService;
|
|
|
-import com.chelvc.framework.common.exception.ResourceUnavailableException;
|
|
|
-import lombok.RequiredArgsConstructor;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-
|
|
|
@Service
|
|
|
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
|
|
public class OderHandleServiceImpl implements OrderHandleService {
|
|
@@ -40,6 +35,8 @@ public class OderHandleServiceImpl implements OrderHandleService {
|
|
|
private final PlatformProfitRatioService platformProfitRatioService;
|
|
|
private final AssetService assetService;
|
|
|
private final BalanceDetailService balanceDetailService;
|
|
|
+ private final CurrencyRecordService currencyRecordService;
|
|
|
+ private final IOmsOrderOperateHistoryService omsOrderOperateHistoryService;
|
|
|
|
|
|
@Override
|
|
|
public void orderPay(Long orderId) {
|
|
@@ -71,7 +68,6 @@ public class OderHandleServiceImpl implements OrderHandleService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
public void handleOrder(OmsOrder omsOrder) {
|
|
|
omsOrder.setStatus(4);
|
|
|
omsOrder.setConfirmStatus(1);
|
|
@@ -81,6 +77,7 @@ public class OderHandleServiceImpl implements OrderHandleService {
|
|
|
if (i != 1) {
|
|
|
throw new ResourceUnavailableException("处理失败");
|
|
|
}
|
|
|
+ Long orderId = omsOrder.getId();
|
|
|
//分佣逻辑=====================================
|
|
|
//实际支付金额
|
|
|
BigDecimal payAmount = omsOrder.getPayAmount();
|
|
@@ -115,9 +112,44 @@ public class OderHandleServiceImpl implements OrderHandleService {
|
|
|
}
|
|
|
//商家应得金额
|
|
|
BigDecimal operateAmount = payAmount.subtract(platformAmount);
|
|
|
- BigDecimal surplusAmount = assetService.updateAsset(0, operateAmount, merchantId, 2);
|
|
|
+ //记录流水--------------------------
|
|
|
+ //商家流水
|
|
|
+ BigDecimal merchantDeduct = BigDecimal.ZERO; //扣税
|
|
|
+ BigDecimal merchantRealityAmount = operateAmount.subtract(merchantDeduct);
|
|
|
+ BigDecimal surplusAmount = assetService.updateAsset(0, merchantRealityAmount, merchantId, 2, 1);
|
|
|
+ currencyRecordService.recordFlow(merchantId, 2, 0, orderId, userId, 0, operateAmount, merchantDeduct, merchantRealityAmount);
|
|
|
+ //记录商家余额明细
|
|
|
balanceDetailService.recordFlow(omsOrder.getId(), 2, merchantId, operateAmount, surplusAmount, 0, 1, userId);
|
|
|
- BigDecimal platformSurplusAmount = assetService.updateAsset(1, operateAmount, 1L, 0);
|
|
|
+ //邀请用户---分得佣金
|
|
|
+ if (userAmount.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ platformAmount = platformAmount.subtract(userAmount);
|
|
|
+ BigDecimal deduct = BigDecimal.ZERO; //扣税
|
|
|
+ BigDecimal realityAmount = userAmount.subtract(deduct);
|
|
|
+ //更新用户资产
|
|
|
+ assetService.updateAsset(0, realityAmount, inviteUserId, 1, 1);
|
|
|
+ //邀请用户流水
|
|
|
+ currencyRecordService.recordFlow(inviteUserId, 1, 0, orderId, userId, 1, userAmount, deduct, realityAmount);
|
|
|
+ }
|
|
|
+ //邀请商家---分得佣金
|
|
|
+ if (merchantAmount.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ platformAmount = platformAmount.subtract(merchantAmount);
|
|
|
+ BigDecimal deduct = BigDecimal.ZERO; //扣税
|
|
|
+ BigDecimal realityAmount = merchantAmount.subtract(deduct);
|
|
|
+ //更新用户资产
|
|
|
+ assetService.updateAsset(0, realityAmount, inviteMerchantId, 1, 1);
|
|
|
+ //邀请商家流水
|
|
|
+ currencyRecordService.recordFlow(inviteMerchantId, 1, 0, orderId, userId, 2, merchantAmount, deduct, realityAmount);
|
|
|
+ }
|
|
|
+ //平台流水
|
|
|
+ BigDecimal deduct = BigDecimal.ZERO; //扣税
|
|
|
+ BigDecimal platformRealityAmount = platformAmount.subtract(deduct);
|
|
|
+ //更新平台资产
|
|
|
+ assetService.updatePlatformAsset(platformRealityAmount, payAmount);
|
|
|
+ //平台流水
|
|
|
+ currencyRecordService.recordFlow(1L, 0, 0, orderId, userId, 3, platformAmount, deduct, platformRealityAmount);
|
|
|
+
|
|
|
+ omsOrderOperateHistoryService.insertOmsOrderOperateHistory(omsOrder.getId(), userId, omsOrder.getStatus());
|
|
|
+ /*BigDecimal platformSurplusAmount = assetService.updateAsset(1, operateAmount, 1L, 0);
|
|
|
balanceDetailService.recordFlow(omsOrder.getId(), 0, 1L, operateAmount, platformSurplusAmount, 1, 1,
|
|
|
merchantId);
|
|
|
//邀请用户---分得佣金
|
|
@@ -137,16 +169,17 @@ public class OderHandleServiceImpl implements OrderHandleService {
|
|
|
BigDecimal platformSurplusAmount2 = assetService.updateAsset(1, merchantAmount, 1L, 0);
|
|
|
balanceDetailService.recordFlow(omsOrder.getId(), 0, 1L, merchantAmount, platformSurplusAmount2, 1, 1,
|
|
|
inviteMerchantId);
|
|
|
- }
|
|
|
+ }*/
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
public void paySuccess(OmsOrder order) {
|
|
|
omsOrderMapper.updateById(order);
|
|
|
- BigDecimal surplusAmount = assetService.updateAsset(0, order.getPayAmount(), 1L, 0);
|
|
|
+ assetService.updateAsset(0, order.getPayAmount(), 1L, 0, 2);
|
|
|
+ omsOrderOperateHistoryService.insertOmsOrderOperateHistory(order.getId(), order.getUserId(), order.getStatus());
|
|
|
+ /* BigDecimal surplusAmount = assetService.updateAsset(0, order.getPayAmount(), 1L, 0);
|
|
|
balanceDetailService.recordFlow(order.getId(), 0, 1L, order.getPayAmount(), surplusAmount, 0, 1,
|
|
|
- order.getUserId());
|
|
|
+ order.getUserId());*/
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|