|
@@ -56,12 +56,12 @@ import com.sckw.order.model.vo.res.UnitInfoDetailRes;
|
|
|
import com.sckw.order.repository.KwoTradeOrderUnitRepository;
|
|
import com.sckw.order.repository.KwoTradeOrderUnitRepository;
|
|
|
import com.sckw.payment.api.dubbo.PayCenterDubboService;
|
|
import com.sckw.payment.api.dubbo.PayCenterDubboService;
|
|
|
import com.sckw.payment.api.dubbo.PaymentDubboService;
|
|
import com.sckw.payment.api.dubbo.PaymentDubboService;
|
|
|
-import com.sckw.payment.api.feign.OfflineWalletFeignService;
|
|
|
|
|
import com.sckw.payment.api.model.WalletFreeze;
|
|
import com.sckw.payment.api.model.WalletFreeze;
|
|
|
|
|
+import com.sckw.payment.api.feign.PaymentFeignService;
|
|
|
import com.sckw.payment.api.model.constant.ChannelEnum;
|
|
import com.sckw.payment.api.model.constant.ChannelEnum;
|
|
|
import com.sckw.payment.api.model.dto.WalletDto;
|
|
import com.sckw.payment.api.model.dto.WalletDto;
|
|
|
-import com.sckw.payment.api.model.dto.WalletFreezeDto;
|
|
|
|
|
import com.sckw.payment.api.model.dto.common.R;
|
|
import com.sckw.payment.api.model.dto.common.R;
|
|
|
|
|
+import com.sckw.payment.api.model.feign.WalletPrepaidDto;
|
|
|
import com.sckw.product.api.dubbo.GoodsInfoService;
|
|
import com.sckw.product.api.dubbo.GoodsInfoService;
|
|
|
import com.sckw.product.api.model.AddressInfoDetail;
|
|
import com.sckw.product.api.model.AddressInfoDetail;
|
|
|
import com.sckw.product.api.model.GoodsDetail;
|
|
import com.sckw.product.api.model.GoodsDetail;
|
|
@@ -140,8 +140,8 @@ public class KwoTradeOrderService {
|
|
|
@DubboReference(version = "1.0.0", group = "design", check = false, timeout = 6000)
|
|
@DubboReference(version = "1.0.0", group = "design", check = false, timeout = 6000)
|
|
|
protected RemoteFleetService remoteFleetService;
|
|
protected RemoteFleetService remoteFleetService;
|
|
|
|
|
|
|
|
- @Autowired(required = false)
|
|
|
|
|
- private OfflineWalletFeignService offlineWalletFeignService;
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private PaymentFeignService paymentFeignService;
|
|
|
|
|
|
|
|
private final KwoTradeOrderMapper kwoTradeOrderMapper;
|
|
private final KwoTradeOrderMapper kwoTradeOrderMapper;
|
|
|
private final StreamBridge streamBridge;
|
|
private final StreamBridge streamBridge;
|
|
@@ -2082,8 +2082,6 @@ public class KwoTradeOrderService {
|
|
|
TradeContractResDto tradeContractResDto = checkPara(tradeOrderParam, order, goodsById);
|
|
TradeContractResDto tradeContractResDto = checkPara(tradeOrderParam, order, goodsById);
|
|
|
|
|
|
|
|
// ====== 下单前校验 start ======
|
|
// ====== 下单前校验 start ======
|
|
|
- // 1. 验证线下钱包预付余额是否足够,不足则提示"线下钱包预付余额不足"
|
|
|
|
|
- checkWallet(order);
|
|
|
|
|
|
|
|
|
|
// 2. 验证商品是否开启库存(amount不为null代表已开启库存,null代表无限库存无需验证)
|
|
// 2. 验证商品是否开启库存(amount不为null代表已开启库存,null代表无限库存无需验证)
|
|
|
if (goodsById.getAmount() != null && goodsById.getAmount().compareTo(tradeOrderParam.getAmount()) < 0) {
|
|
if (goodsById.getAmount() != null && goodsById.getAmount().compareTo(tradeOrderParam.getAmount()) < 0) {
|
|
@@ -2092,10 +2090,6 @@ public class KwoTradeOrderService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 4. 记录钱包金额账数据,类型为冻结,备注为"贸易订单号:xxx 下单冻结"
|
|
|
|
|
- // TODO: 后续对接外部系统,记录钱包流水
|
|
|
|
|
- // recordWalletTransaction(buyEntId, order.getPrice(), "冻结", "贸易订单号:" + order.getTOrderNo() + " 下单冻结");
|
|
|
|
|
-
|
|
|
|
|
// 5. 验证贸易合同限量采购,若为限量采购则校验剩余可采购数量并扣减本次下单量
|
|
// 5. 验证贸易合同限量采购,若为限量采购则校验剩余可采购数量并扣减本次下单量
|
|
|
GoodsInfoDto contractGoodsInfo = tradeContractResDto.getGoodsInfoDto();
|
|
GoodsInfoDto contractGoodsInfo = tradeContractResDto.getGoodsInfoDto();
|
|
|
if (contractGoodsInfo.getAmount() != null && contractGoodsInfo.getAmount().compareTo(BigDecimal.ZERO) > 0) {
|
|
if (contractGoodsInfo.getAmount() != null && contractGoodsInfo.getAmount().compareTo(BigDecimal.ZERO) > 0) {
|
|
@@ -2108,17 +2102,14 @@ public class KwoTradeOrderService {
|
|
|
}
|
|
}
|
|
|
// ====== 下单前校验 end ======
|
|
// ====== 下单前校验 end ======
|
|
|
|
|
|
|
|
- WalletFreeze walletFreeze = new WalletFreeze();
|
|
|
|
|
- walletFreeze.setOrderNo(order.getTOrderNo());
|
|
|
|
|
- walletFreeze.setMoney(order.getPrice());
|
|
|
|
|
-
|
|
|
|
|
//商品地址信息
|
|
//商品地址信息
|
|
|
AddressInfoDetail goodsAddress = goodsInfoService.getGoodsAddress(tradeOrderParam.getGoodsId());
|
|
AddressInfoDetail goodsAddress = goodsInfoService.getGoodsAddress(tradeOrderParam.getGoodsId());
|
|
|
if (Objects.isNull(goodsAddress)) {
|
|
if (Objects.isNull(goodsAddress)) {
|
|
|
throw new BusinessException("商品发货地址信息不存在");
|
|
throw new BusinessException("商品发货地址信息不存在");
|
|
|
}
|
|
}
|
|
|
|
|
+ order.setSettlement(tradeContractResDto.getSettlement());
|
|
|
kwoTradeOrderMapper.insert(order);//贸易订单
|
|
kwoTradeOrderMapper.insert(order);//贸易订单
|
|
|
- walletFreeze.setTTradeOrderId(order.getId());
|
|
|
|
|
|
|
+// walletFreeze.setTTradeOrderId(order.getId());
|
|
|
|
|
|
|
|
GoodsInfoDto goodsInfoDto = tradeContractResDto.getGoodsInfoDto();//贸易合同,下合同关联的商品信息
|
|
GoodsInfoDto goodsInfoDto = tradeContractResDto.getGoodsInfoDto();//贸易合同,下合同关联的商品信息
|
|
|
KwoTradeOrderGoods kwoTradeOrderGoods = new KwoTradeOrderGoods();
|
|
KwoTradeOrderGoods kwoTradeOrderGoods = new KwoTradeOrderGoods();
|
|
@@ -2222,74 +2213,42 @@ public class KwoTradeOrderService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
List<TradeContractUnitDto> unitList = tradeContractResDto.getUnitList();
|
|
List<TradeContractUnitDto> unitList = tradeContractResDto.getUnitList();
|
|
|
- WalletFreezeDto freezeDto = new WalletFreezeDto();
|
|
|
|
|
List<KwoTradeOrderUnit> list = new ArrayList<>();
|
|
List<KwoTradeOrderUnit> list = new ArrayList<>();
|
|
|
|
|
+ WalletPrepaidDto walletFreeze = new WalletPrepaidDto();
|
|
|
|
|
+ walletFreeze.setOrderNo(String.valueOf(order.getId()));
|
|
|
|
|
+ walletFreeze.setTradeAmount(order.getPrice());
|
|
|
unitList.forEach(e -> {
|
|
unitList.forEach(e -> {
|
|
|
KwoTradeOrderUnit unit = BeanUtil.copyProperties(e, KwoTradeOrderUnit.class);
|
|
KwoTradeOrderUnit unit = BeanUtil.copyProperties(e, KwoTradeOrderUnit.class);
|
|
|
unit.setId(new IdWorker(1).nextId());
|
|
unit.setId(new IdWorker(1).nextId());
|
|
|
unit.setTOrderId(order.getId()).setTOrderNo(order.getTOrderNo()).setTopEntId(e.getEntId());
|
|
unit.setTOrderId(order.getId()).setTOrderNo(order.getTOrderNo()).setTopEntId(e.getEntId());
|
|
|
unit.setUnitType(StrUtil.equals(e.getUnitType(), "1") ? "2" : "1");//贸易合同和订单的单位类型相反
|
|
unit.setUnitType(StrUtil.equals(e.getUnitType(), "1") ? "2" : "1");//贸易合同和订单的单位类型相反
|
|
|
if (StrUtil.equals(unit.getUnitType(), "1")) {
|
|
if (StrUtil.equals(unit.getUnitType(), "1")) {
|
|
|
- walletFreeze.setBuyEntId(unit.getEntId());
|
|
|
|
|
- freezeDto.setProEntId(unit.getEntId());
|
|
|
|
|
|
|
+// walletFreeze.setBuyEntId(unit.getEntId());
|
|
|
|
|
+ walletFreeze.setProEntId(unit.getEntId());
|
|
|
}
|
|
}
|
|
|
if (StrUtil.equals(unit.getUnitType(), "2")) {
|
|
if (StrUtil.equals(unit.getUnitType(), "2")) {
|
|
|
- walletFreeze.setSaleEntId(unit.getEntId());
|
|
|
|
|
- freezeDto.setSupEntId(unit.getEntId());
|
|
|
|
|
|
|
+// walletFreeze.setSaleEntId(unit.getEntId());
|
|
|
|
|
+ walletFreeze.setSupEntId(unit.getEntId());
|
|
|
}
|
|
}
|
|
|
list.add(unit);
|
|
list.add(unit);
|
|
|
});
|
|
});
|
|
|
kwoTradeOrderUnitService.insertBatch(list);
|
|
kwoTradeOrderUnitService.insertBatch(list);
|
|
|
//钱包
|
|
//钱包
|
|
|
- BaseResult<Boolean> booleanBaseResult = paymentDubboService.freezeMoney(walletFreeze);
|
|
|
|
|
- if (booleanBaseResult.getCode() != 60200) {
|
|
|
|
|
- throw new BusinessException(booleanBaseResult.getMessage());
|
|
|
|
|
- }
|
|
|
|
|
- // 3. 线下钱包扣减预付余额、增加冻结金额
|
|
|
|
|
- walletFreeze(tradeOrderParam, order,freezeDto);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// BaseResult<Boolean> booleanBaseResult = paymentDubboService.freezeMoney(walletFreeze);
|
|
|
|
|
+ BaseResult<Object> freezeBaseResult = new BaseResult<>();
|
|
|
|
|
+ if(Objects.equals(tradeContractResDto.getSettlement(),1)){
|
|
|
|
|
+ // todo 普通结算冻结
|
|
|
|
|
|
|
|
- private void walletFreeze(TradeOrderParam tradeOrderParam, KwoTradeOrder order,WalletFreezeDto freezeDto) {
|
|
|
|
|
- if (offlineWalletFeignService == null) {
|
|
|
|
|
- throw new BusinessException("线下钱包服务未配置,无法执行冻结操作");
|
|
|
|
|
|
|
+ }else if(Objects.equals(tradeContractResDto.getSettlement(),2)){
|
|
|
|
|
+ //预付制结算冻结
|
|
|
|
|
+ walletFreeze.setOrderType(4);
|
|
|
|
|
+ walletFreeze.setTradeType(4);
|
|
|
|
|
+ walletFreeze.setRemark("贸易订单号:"+walletFreeze.getOrderNo()+",下单冻结");
|
|
|
|
|
+ freezeBaseResult = paymentFeignService.updatePrepaidBalance(walletFreeze);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- freezeDto.setFreezeAmount(tradeOrderParam.getAmount());
|
|
|
|
|
- freezeDto.setOrderNo(order.getTOrderNo());
|
|
|
|
|
-
|
|
|
|
|
- BaseResult<Boolean> balanceResult;
|
|
|
|
|
- try {
|
|
|
|
|
- balanceResult = offlineWalletFeignService.freezeBalance(freezeDto);
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("线下钱包扣减预付余额、增加冻结金额异常", e);
|
|
|
|
|
- throw new BusinessException("线下钱包扣减预付余额、增加冻结金额异常");
|
|
|
|
|
- }
|
|
|
|
|
- if (balanceResult == null || balanceResult.getCode() != HttpStatus.SUCCESS_CODE) {
|
|
|
|
|
- throw new BusinessException("线下钱包扣减预付余额、增加冻结金额失败");
|
|
|
|
|
- }
|
|
|
|
|
- Boolean aBoolean = balanceResult.getData();
|
|
|
|
|
- if (!Boolean.TRUE.equals(aBoolean)) {
|
|
|
|
|
- throw new BusinessException("线下钱包扣减预付余额、增加冻结金额失败");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private void checkWallet(KwoTradeOrder order) {
|
|
|
|
|
- if (offlineWalletFeignService == null) {
|
|
|
|
|
- throw new BusinessException("线下钱包服务未配置,无法查询余额");
|
|
|
|
|
- }
|
|
|
|
|
- BaseResult<BigDecimal> balanceResult;
|
|
|
|
|
- try {
|
|
|
|
|
- balanceResult = offlineWalletFeignService.queryPrepaidBalance(LoginUserHolder.getEntId());
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("查询线下钱包服务异常", e);
|
|
|
|
|
- throw new BusinessException("查询线下钱包服务异常,请稍后再试");
|
|
|
|
|
- }
|
|
|
|
|
- if (balanceResult == null || balanceResult.getCode() != HttpStatus.SUCCESS_CODE) {
|
|
|
|
|
- throw new BusinessException("查询线下钱包预付余额失败,请稍后再试");
|
|
|
|
|
- }
|
|
|
|
|
- BigDecimal prepaidBalance = balanceResult.getData();
|
|
|
|
|
- if (prepaidBalance == null || prepaidBalance.compareTo(order.getPrice()) < 0) {
|
|
|
|
|
- throw new BusinessException("线下钱包预付余额不足");
|
|
|
|
|
|
|
+ if (freezeBaseResult.getCode() != 60200) {
|
|
|
|
|
+ throw new BusinessException(freezeBaseResult.getMessage());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -2311,7 +2270,7 @@ public class KwoTradeOrderService {
|
|
|
TradeContractResDto tradeContractResDto = remoteContractService.queryTradeContract(param.getTradeContractId(), param.getGoodsId());
|
|
TradeContractResDto tradeContractResDto = remoteContractService.queryTradeContract(param.getTradeContractId(), param.getGoodsId());
|
|
|
// 1. 线下钱包加回预付余额、减冻结金额
|
|
// 1. 线下钱包加回预付余额、减冻结金额
|
|
|
List<TradeContractUnitDto> unitList = tradeContractResDto.getUnitList();
|
|
List<TradeContractUnitDto> unitList = tradeContractResDto.getUnitList();
|
|
|
- WalletFreezeDto freezeDto = new WalletFreezeDto();
|
|
|
|
|
|
|
+ WalletPrepaidDto freezeDto = new WalletPrepaidDto();
|
|
|
unitList.forEach(e -> {
|
|
unitList.forEach(e -> {
|
|
|
KwoTradeOrderUnit unit = BeanUtil.copyProperties(e, KwoTradeOrderUnit.class);
|
|
KwoTradeOrderUnit unit = BeanUtil.copyProperties(e, KwoTradeOrderUnit.class);
|
|
|
unit.setId(new IdWorker(1).nextId());
|
|
unit.setId(new IdWorker(1).nextId());
|
|
@@ -2324,15 +2283,13 @@ public class KwoTradeOrderService {
|
|
|
freezeDto.setSupEntId(unit.getEntId());
|
|
freezeDto.setSupEntId(unit.getEntId());
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
- freezeDto.setFreezeAmount(param.getFreezeAmount());
|
|
|
|
|
- freezeDto.setOrderNo(order.getTOrderNo());
|
|
|
|
|
-
|
|
|
|
|
- if (offlineWalletFeignService == null) {
|
|
|
|
|
- throw new BusinessException("线下钱包服务未配置,无法执行解冻操作");
|
|
|
|
|
- }
|
|
|
|
|
- BaseResult<Boolean> balanceResult;
|
|
|
|
|
|
|
+ freezeDto.setOrderNo(String.valueOf(order.getId()));
|
|
|
|
|
+ freezeDto.setOrderType(4);
|
|
|
|
|
+ freezeDto.setTradeType(5);
|
|
|
|
|
+ freezeDto.setRemark("贸易订单号:"+freezeDto.getOrderNo()+",撤销订单");
|
|
|
|
|
+ BaseResult<Object> balanceResult;
|
|
|
try {
|
|
try {
|
|
|
- balanceResult = offlineWalletFeignService.unfreezeBalance(freezeDto);
|
|
|
|
|
|
|
+ balanceResult = paymentFeignService.updatePrepaidBalance(freezeDto);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.error("线下钱包扣减预付余额、增加冻结金额异常", e);
|
|
log.error("线下钱包扣减预付余额、增加冻结金额异常", e);
|
|
|
throw new BusinessException("线下钱包扣减预付余额、增加冻结金额异常");
|
|
throw new BusinessException("线下钱包扣减预付余额、增加冻结金额异常");
|
|
@@ -2340,24 +2297,11 @@ public class KwoTradeOrderService {
|
|
|
if (balanceResult == null || balanceResult.getCode() != HttpStatus.SUCCESS_CODE) {
|
|
if (balanceResult == null || balanceResult.getCode() != HttpStatus.SUCCESS_CODE) {
|
|
|
throw new BusinessException("线下钱包扣减预付余额、增加冻结金额失败");
|
|
throw new BusinessException("线下钱包扣减预付余额、增加冻结金额失败");
|
|
|
}
|
|
}
|
|
|
- Boolean aBoolean = balanceResult.getData();
|
|
|
|
|
|
|
+ Boolean aBoolean = (Boolean) balanceResult.getData();
|
|
|
if (!Boolean.TRUE.equals(aBoolean)) {
|
|
if (!Boolean.TRUE.equals(aBoolean)) {
|
|
|
throw new BusinessException("线下钱包扣减预付余额、增加冻结金额失败");
|
|
throw new BusinessException("线下钱包扣减预付余额、增加冻结金额失败");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 2. 记录钱包金额账数据,类型为解冻,备注为"贸易订单号:xxx 撤销订单"
|
|
|
|
|
- // TODO: 后续对接外部系统,记录钱包流水
|
|
|
|
|
- // recordWalletTransaction(buyEntId, order.getPrice(), "解冻", "贸易订单号:" + order.getTOrderNo() + " 撤销订单");
|
|
|
|
|
-
|
|
|
|
|
- // 线上钱包解冻
|
|
|
|
|
- WalletFreeze walletFreeze = new WalletFreeze();
|
|
|
|
|
- walletFreeze.setTTradeOrderId(order.getId());
|
|
|
|
|
- walletFreeze.setOrderNo(order.getTOrderNo());
|
|
|
|
|
- BaseResult<Boolean> unfreezeResult = paymentDubboService.unfreezeMoney(walletFreeze);
|
|
|
|
|
- if (unfreezeResult.getCode() != 60200) {
|
|
|
|
|
- throw new BusinessException(unfreezeResult.getMessage());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
// 3. 贸易合同该商品有采购数量,则更新采购数量(加回本单总量)
|
|
// 3. 贸易合同该商品有采购数量,则更新采购数量(加回本单总量)
|
|
|
KwoTradeOrderGoods orderGoods = kwoTradeOrderGoodsService.getByOrderId(order.getId());
|
|
KwoTradeOrderGoods orderGoods = kwoTradeOrderGoodsService.getByOrderId(order.getId());
|
|
|
KwoTradeOrderContract orderContract = kwoTradeOrderContractService.getByOrderId(order.getId());
|
|
KwoTradeOrderContract orderContract = kwoTradeOrderContractService.getByOrderId(order.getId());
|
|
@@ -2397,12 +2341,36 @@ public class KwoTradeOrderService {
|
|
|
if (Objects.isNull(goodsInfoDto)) {
|
|
if (Objects.isNull(goodsInfoDto)) {
|
|
|
throw new BusinessException("当前贸易订单不存在交易商品");
|
|
throw new BusinessException("当前贸易订单不存在交易商品");
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ //结算方式校验余额
|
|
|
|
|
+ BigDecimal orderAmount = NumberUtil.mul(tradeOrderParam.getAmount(), goodsInfoDto.getPrice());
|
|
|
|
|
+ Integer settlement = tradeContractResDto.getSettlement();
|
|
|
|
|
+ if(Objects.equals(settlement, 1)){
|
|
|
|
|
+ // todo 普通结算
|
|
|
|
|
+
|
|
|
|
|
+ }else {
|
|
|
|
|
+ //预付制结算
|
|
|
|
|
+ BaseResult<BigDecimal> prepaidBalanceResult = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ prepaidBalanceResult = paymentFeignService.queryPrepaidBalance(goodsById.getSupplyEntId());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("查询线下钱包服务异常", e);
|
|
|
|
|
+ throw new BusinessException("查询线下钱包服务异常,请稍后再试");
|
|
|
|
|
+ }
|
|
|
|
|
+ if(prepaidBalanceResult.getCode() == HttpStatus.SUCCESS_CODE){
|
|
|
|
|
+ if(orderAmount.compareTo(prepaidBalanceResult.getData()) > 0){
|
|
|
|
|
+ throw new BusinessException("当前贸易订单金额大于可用预付余额");
|
|
|
|
|
+ }
|
|
|
|
|
+ }else{
|
|
|
|
|
+ throw new BusinessException("查询对应供应商预付余额失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
tradeOrderParam.setTradeContractNo(tradeContractResDto.getContractNo());
|
|
tradeOrderParam.setTradeContractNo(tradeContractResDto.getContractNo());
|
|
|
order.setUnit(goodsById.getUnit());
|
|
order.setUnit(goodsById.getUnit());
|
|
|
order.setPickupType(String.valueOf(tradeContractResDto.getConsignment()));//来源于合同约束的托运方式
|
|
order.setPickupType(String.valueOf(tradeContractResDto.getConsignment()));//来源于合同约束的托运方式
|
|
|
order.setDeliveryType("");
|
|
order.setDeliveryType("");
|
|
|
order.setTrading(String.valueOf(tradeContractResDto.getSigningWay()));//签约方式
|
|
order.setTrading(String.valueOf(tradeContractResDto.getSigningWay()));//签约方式
|
|
|
- order.setPrice(NumberUtil.mul(tradeOrderParam.getAmount(), goodsInfoDto.getPrice()));//总金额
|
|
|
|
|
|
|
+ order.setPrice(orderAmount);//总金额
|
|
|
order.setActualAmount(new BigDecimal("0"));
|
|
order.setActualAmount(new BigDecimal("0"));
|
|
|
order.setAssociateStatement(0);
|
|
order.setAssociateStatement(0);
|
|
|
order.setLoadAmount(new BigDecimal("0"));
|
|
order.setLoadAmount(new BigDecimal("0"));
|
|
@@ -2452,10 +2420,24 @@ public class KwoTradeOrderService {
|
|
|
|
|
|
|
|
if (Objects.equals(tradeOrderAuditParam.getStatus(), 2)) {
|
|
if (Objects.equals(tradeOrderAuditParam.getStatus(), 2)) {
|
|
|
//钱包退回金额
|
|
//钱包退回金额
|
|
|
- WalletFreeze walletFreeze = new WalletFreeze();
|
|
|
|
|
- walletFreeze.setTTradeOrderId(kwoTradeOrder.getId());
|
|
|
|
|
- walletFreeze.setOrderNo(kwoTradeOrder.getTOrderNo());
|
|
|
|
|
- BaseResult<Boolean> booleanBaseResult = paymentDubboService.unfreezeMoney(walletFreeze);
|
|
|
|
|
|
|
+ WalletPrepaidDto walletFreeze = new WalletPrepaidDto();
|
|
|
|
|
+// walletFreeze.setTTradeOrderId(kwoTradeOrder.getId());
|
|
|
|
|
+ walletFreeze.setOrderNo(String.valueOf(kwoTradeOrder.getId()));
|
|
|
|
|
+ walletFreeze.setProEntId(unitMap.get(String.valueOf(CooperateTypeEnum.PURCHASER.getCode())).getEntId());
|
|
|
|
|
+ walletFreeze.setSupEntId(unitMap.get(String.valueOf(CooperateTypeEnum.SUPPLIER.getCode())).getEntId());
|
|
|
|
|
+ walletFreeze.setOrderType(4);
|
|
|
|
|
+ walletFreeze.setTradeType(5);
|
|
|
|
|
+ walletFreeze.setRemark("贸易订单:"+walletFreeze.getOrderNo()+",审核拒绝解冻");
|
|
|
|
|
+// BaseResult<Boolean> booleanBaseResult = paymentDubboService.unfreezeMoney(walletFreeze);
|
|
|
|
|
+
|
|
|
|
|
+ BaseResult<Object> booleanBaseResult = new BaseResult<>();
|
|
|
|
|
+ if(Objects.equals(kwoTradeOrder.getSettlement(),1)){
|
|
|
|
|
+ // todo 普通结算解冻结
|
|
|
|
|
+
|
|
|
|
|
+ }else if(Objects.equals(kwoTradeOrder.getSettlement(),2)){
|
|
|
|
|
+ //预付制结算解冻
|
|
|
|
|
+ booleanBaseResult = paymentFeignService.updatePrepaidBalance(walletFreeze);
|
|
|
|
|
+ }
|
|
|
if (booleanBaseResult.getCode() != 60200) {
|
|
if (booleanBaseResult.getCode() != 60200) {
|
|
|
throw new BusinessException(booleanBaseResult.getMessage());
|
|
throw new BusinessException(booleanBaseResult.getMessage());
|
|
|
}
|
|
}
|
|
@@ -2558,8 +2540,8 @@ public class KwoTradeOrderService {
|
|
|
logisticInfo.setAcceptCompany("");
|
|
logisticInfo.setAcceptCompany("");
|
|
|
logisticInfo.setPrice(d.getTransportPrice());
|
|
logisticInfo.setPrice(d.getTransportPrice());
|
|
|
logisticInfo.setPriceType(0L);
|
|
logisticInfo.setPriceType(0L);
|
|
|
- logisticInfo.setAmount(new BigDecimal("0"));
|
|
|
|
|
- logisticInfo.setAmountUnit("");
|
|
|
|
|
|
|
+ logisticInfo.setAmount(kwoTradeOrder.getAmount());
|
|
|
|
|
+ logisticInfo.setAmountUnit(kwoTradeOrder.getUnit());
|
|
|
logisticInfo.setLoss(new BigDecimal("0"));
|
|
logisticInfo.setLoss(new BigDecimal("0"));
|
|
|
logisticInfo.setPayment(0L);
|
|
logisticInfo.setPayment(0L);
|
|
|
logisticInfo.setSigningWay(0);
|
|
logisticInfo.setSigningWay(0);
|
|
@@ -2589,8 +2571,8 @@ public class KwoTradeOrderService {
|
|
|
logisticInfo.setAcceptCompany("");
|
|
logisticInfo.setAcceptCompany("");
|
|
|
logisticInfo.setPrice(d.getTransportPrice());
|
|
logisticInfo.setPrice(d.getTransportPrice());
|
|
|
logisticInfo.setPriceType(0L);
|
|
logisticInfo.setPriceType(0L);
|
|
|
- logisticInfo.setAmount(new BigDecimal("0"));
|
|
|
|
|
- logisticInfo.setAmountUnit("");
|
|
|
|
|
|
|
+ logisticInfo.setAmount(kwoTradeOrder.getAmount());
|
|
|
|
|
+ logisticInfo.setAmountUnit(kwoTradeOrder.getUnit());
|
|
|
logisticInfo.setLoss(new BigDecimal("0"));
|
|
logisticInfo.setLoss(new BigDecimal("0"));
|
|
|
logisticInfo.setPayment(0L);
|
|
logisticInfo.setPayment(0L);
|
|
|
logisticInfo.setSigningWay(0);
|
|
logisticInfo.setSigningWay(0);
|
|
@@ -2618,8 +2600,8 @@ public class KwoTradeOrderService {
|
|
|
logisticInfo.setAcceptCompany(d.getFirmName());
|
|
logisticInfo.setAcceptCompany(d.getFirmName());
|
|
|
logisticInfo.setPrice(d.getTransportPrice());
|
|
logisticInfo.setPrice(d.getTransportPrice());
|
|
|
logisticInfo.setPriceType(0L);
|
|
logisticInfo.setPriceType(0L);
|
|
|
- logisticInfo.setAmount(new BigDecimal("0"));
|
|
|
|
|
- logisticInfo.setAmountUnit("");
|
|
|
|
|
|
|
+ logisticInfo.setAmount(kwoTradeOrder.getAmount());
|
|
|
|
|
+ logisticInfo.setAmountUnit(kwoTradeOrder.getUnit());
|
|
|
logisticInfo.setLoss(new BigDecimal("0"));
|
|
logisticInfo.setLoss(new BigDecimal("0"));
|
|
|
logisticInfo.setPayment(0L);
|
|
logisticInfo.setPayment(0L);
|
|
|
logisticInfo.setSigningWay(0);
|
|
logisticInfo.setSigningWay(0);
|
|
@@ -2798,6 +2780,7 @@ public class KwoTradeOrderService {
|
|
|
*/
|
|
*/
|
|
|
public Object settleOrder(TradeOrderSettleParam tradeOrderSettleParam) {
|
|
public Object settleOrder(TradeOrderSettleParam tradeOrderSettleParam) {
|
|
|
KwoTradeOrder kwoTradeOrder = new KwoTradeOrder();
|
|
KwoTradeOrder kwoTradeOrder = new KwoTradeOrder();
|
|
|
|
|
+ KwoTradeOrder kwoTradeOrderDB = kwoTradeOrderMapper.selectOne(new LambdaQueryWrapper<KwoTradeOrder>().eq(KwoTradeOrder::getId, tradeOrderSettleParam.getId()).eq(KwoTradeOrder::getDelFlag, 0));
|
|
|
List<KwtLogisticsOrderVO> logisticOrderList = transportRemoteService.getLogisticOrderList(new OrderFinishParam(tradeOrderSettleParam.getId()));
|
|
List<KwtLogisticsOrderVO> logisticOrderList = transportRemoteService.getLogisticOrderList(new OrderFinishParam(tradeOrderSettleParam.getId()));
|
|
|
if (CollUtil.isNotEmpty(logisticOrderList)) {
|
|
if (CollUtil.isNotEmpty(logisticOrderList)) {
|
|
|
if (logisticOrderList.stream().allMatch(d -> Objects.equals(d.getStatus(), LogisticsOrderV1Enum.NEARING_COMPLETION.getCode()))) {
|
|
if (logisticOrderList.stream().allMatch(d -> Objects.equals(d.getStatus(), LogisticsOrderV1Enum.NEARING_COMPLETION.getCode()))) {
|
|
@@ -2821,9 +2804,59 @@ public class KwoTradeOrderService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
kwoTradeOrderMapper.updateById(kwoTradeOrder);
|
|
kwoTradeOrderMapper.updateById(kwoTradeOrder);
|
|
|
|
|
+ calculatePrepaidBalance(kwoTradeOrderDB);
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private void calculatePrepaidBalance(KwoTradeOrder kwoTradeOrder){
|
|
|
|
|
+ if(Objects.equals(kwoTradeOrder.getStatus(),TradeOrderStatusEnum.SUCCESS.getCode())){
|
|
|
|
|
+ //贸易订单已完结,计算预付余额
|
|
|
|
|
+ if(Objects.equals(kwoTradeOrder.getSettlement(),1)){
|
|
|
|
|
+ //todo 普通结算
|
|
|
|
|
+
|
|
|
|
|
+ }else if(Objects.equals(kwoTradeOrder.getSettlement(),2)){
|
|
|
|
|
+ //预付制模式
|
|
|
|
|
+ //1解冻运费
|
|
|
|
|
+ List<KwoTradeOrderUnit> orderUnits = kwoTradeOrderUnitService.getByOrderId(kwoTradeOrder.getId());
|
|
|
|
|
+ if (CollUtil.isEmpty(orderUnits)) {
|
|
|
|
|
+ throw new BusinessException("贸易订单企业信息不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<String, KwoTradeOrderUnit> unitMap = orderUnits.stream().collect(Collectors.toMap(KwoTradeOrderUnit::getUnitType, e -> e, (a, b) -> a));
|
|
|
|
|
+ if (unitMap.keySet().size() < 2) {
|
|
|
|
|
+ throw new BusinessException("贸易订单企业信息缺失");
|
|
|
|
|
+ }
|
|
|
|
|
+ //钱包退回金额
|
|
|
|
|
+ WalletPrepaidDto unFreezePrepaidDto = new WalletPrepaidDto();
|
|
|
|
|
+ unFreezePrepaidDto.setOrderNo(String.valueOf(kwoTradeOrder.getId()));
|
|
|
|
|
+ unFreezePrepaidDto.setProEntId(unitMap.get(String.valueOf(CooperateTypeEnum.PURCHASER.getCode())).getEntId());
|
|
|
|
|
+ unFreezePrepaidDto.setSupEntId(unitMap.get(String.valueOf(CooperateTypeEnum.SUPPLIER.getCode())).getEntId());
|
|
|
|
|
+ unFreezePrepaidDto.setOrderType(4);
|
|
|
|
|
+ unFreezePrepaidDto.setTradeType(5);
|
|
|
|
|
+ unFreezePrepaidDto.setRemark("贸易订单:"+unFreezePrepaidDto.getOrderNo()+",");
|
|
|
|
|
+ BaseResult<Object> unFreezeResult = paymentFeignService.updatePrepaidBalance(unFreezePrepaidDto);
|
|
|
|
|
+ if(unFreezeResult.getCode()!= HttpStatus.SUCCESS_CODE){
|
|
|
|
|
+ log.error("贸易订单号:{},订单完结解冻失败,异常信息为:{}",unFreezePrepaidDto.getOrderNo(),unFreezeResult.getMessage());
|
|
|
|
|
+ throw new BusinessException("贸易订单号:"+unFreezePrepaidDto.getOrderNo()+",订单完结解冻失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ //2计算订单金额
|
|
|
|
|
+ WalletPrepaidDto consumePrepaidDto = new WalletPrepaidDto();
|
|
|
|
|
+ unFreezePrepaidDto.setOrderNo(String.valueOf(kwoTradeOrder.getId()));
|
|
|
|
|
+ unFreezePrepaidDto.setProEntId(unitMap.get(String.valueOf(CooperateTypeEnum.PURCHASER.getCode())).getEntId());
|
|
|
|
|
+ unFreezePrepaidDto.setSupEntId(unitMap.get(String.valueOf(CooperateTypeEnum.SUPPLIER.getCode())).getEntId());
|
|
|
|
|
+ unFreezePrepaidDto.setOrderType(4);
|
|
|
|
|
+ unFreezePrepaidDto.setTradeType(6);
|
|
|
|
|
+ consumePrepaidDto.setTradeAmount(kwoTradeOrder.getPrice());
|
|
|
|
|
+ consumePrepaidDto.setRemark("贸易订单号:"+consumePrepaidDto.getOrderNo()+",订单完结消费");
|
|
|
|
|
+ BaseResult<Object> consumeResult = paymentFeignService.updatePrepaidBalance(consumePrepaidDto);
|
|
|
|
|
+ if(consumeResult.getCode()!= HttpStatus.SUCCESS_CODE){
|
|
|
|
|
+ log.error("贸易订单号:{},订单完结消费失败,异常信息为:{}",consumePrepaidDto.getOrderNo(),consumeResult.getMessage());
|
|
|
|
|
+ throw new BusinessException("贸易订单号:"+consumePrepaidDto.getOrderNo()+",订单完结消费失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public void updateOrderAmount(TradeOrderSettlePara tradeOrderSettlePara) {
|
|
public void updateOrderAmount(TradeOrderSettlePara tradeOrderSettlePara) {
|
|
|
if (Objects.isNull(tradeOrderSettlePara.getTOrderId())) {
|
|
if (Objects.isNull(tradeOrderSettlePara.getTOrderId())) {
|
|
|
throw new BusinessException("订单id不能为空");
|
|
throw new BusinessException("订单id不能为空");
|