feat: 订单

pull/1121/head
梁宇奇 2025-04-24 22:54:47 +08:00
parent 7f8d71b9a8
commit 7acc9aa9a0
10 changed files with 275 additions and 9 deletions

View File

@ -33,6 +33,10 @@ public class InternalAccount extends SimpleEntity {
* *
*/ */
private String transactionPassword; private String transactionPassword;
/**
*
*/
private String phoneNumber;
/** /**
* *
*/ */

View File

@ -33,6 +33,10 @@ public class InternalAccountDTO {
* *
*/ */
private String transactionPassword; private String transactionPassword;
/**
*
*/
private String phoneNumber;
/** /**
* *
*/ */

View File

@ -12,9 +12,9 @@ import lombok.Getter;
public enum EFinBillSrcType { public enum EFinBillSrcType {
STORE_ORDER_PAID(1, "代发订单支付"), STORE_ORDER_PAID(1, "代发订单支付"),
STORE_ORDER_COMPLETED(2, "代发订单完成"), STORE_ORDER_COMPLETED(2, "档口代发订单"),
WITHDRAW(3, "提现"), WITHDRAW(3, "提现"),
STORE_ORDER_REFUND(4, "代发订单退款"), STORE_ORDER_REFUND(4, "档口代发退货"),
; ;
private final Integer value; private final Integer value;

View File

@ -5,6 +5,7 @@ import com.ruoyi.xkt.dto.order.StoreOrderExt;
import com.ruoyi.xkt.enums.EPayChannel; import com.ruoyi.xkt.enums.EPayChannel;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List;
/** /**
* @author liangyq * @author liangyq
@ -29,6 +30,16 @@ public interface IFinanceBillService {
*/ */
FinanceBillExt createOrderCompletedTransferBill(StoreOrderExt orderExt); FinanceBillExt createOrderCompletedTransferBill(StoreOrderExt orderExt);
/**
*
*
*
* @param orderExt
* @param afterSaleOrderExts
* @return
*/
FinanceBillExt createOrderCompletedTransferBill(StoreOrderExt orderExt, List<StoreOrderExt> afterSaleOrderExts);
/** /**
* *
* *

View File

@ -72,7 +72,8 @@ public interface IInternalAccountService {
* *
* *
* @param id ID * @param id ID
* @param phoneNumber
* @param transactionPassword md5 * @param transactionPassword md5
*/ */
void setTransactionPassword(Long id, String transactionPassword); void setTransactionPassword(Long id, String phoneNumber, String transactionPassword);
} }

View File

@ -128,6 +128,15 @@ public interface IStoreOrderService {
*/ */
StoreOrderExt receiptOrder(Long storeOrderId, Long operatorId); StoreOrderExt receiptOrder(Long storeOrderId, Long operatorId);
/**
*
*
* @param storeOrderId
* @param operatorId
* @return
*/
StoreOrderExt completeOrder(Long storeOrderId, Long operatorId);
/** /**
* *
* *

View File

@ -104,7 +104,7 @@ public class AccountServiceImpl implements IAccountService {
//TODO 验证码 //TODO 验证码
InternalAccount internalAccount = internalAccountService.getAccountAndCheck(transactionPasswordSet.getStoreId(), InternalAccount internalAccount = internalAccountService.getAccountAndCheck(transactionPasswordSet.getStoreId(),
EAccountOwnerType.STORE); EAccountOwnerType.STORE);
internalAccountService.setTransactionPassword(internalAccount.getId(), internalAccountService.setTransactionPassword(internalAccount.getId(), transactionPasswordSet.getPhoneNumber(),
SecureUtil.md5(transactionPasswordSet.getTransactionPassword())); SecureUtil.md5(transactionPasswordSet.getTransactionPassword()));
return getStoreAccountInfo(transactionPasswordSet.getStoreId()); return getStoreAccountInfo(transactionPasswordSet.getStoreId());
} }

View File

@ -1,12 +1,15 @@
package com.ruoyi.xkt.service.impl; package com.ruoyi.xkt.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil; import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.Assert;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.text.CharSequenceUtil; import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.NumberUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.constant.Constants; import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.SimpleEntity;
import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.bean.BeanValidators; import com.ruoyi.common.utils.bean.BeanValidators;
import com.ruoyi.xkt.domain.FinanceBill; import com.ruoyi.xkt.domain.FinanceBill;
@ -21,19 +24,21 @@ import com.ruoyi.xkt.mapper.FinanceBillMapper;
import com.ruoyi.xkt.service.IExternalAccountService; import com.ruoyi.xkt.service.IExternalAccountService;
import com.ruoyi.xkt.service.IFinanceBillService; import com.ruoyi.xkt.service.IFinanceBillService;
import com.ruoyi.xkt.service.IInternalAccountService; import com.ruoyi.xkt.service.IInternalAccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList; import java.util.*;
import java.util.Date; import java.util.function.Function;
import java.util.List; import java.util.stream.Collectors;
/** /**
* @author liangyq * @author liangyq
* @date 2025-04-08 21:14 * @date 2025-04-08 21:14
*/ */
@Slf4j
@Service @Service
public class FinanceBillServiceImpl implements IFinanceBillService { public class FinanceBillServiceImpl implements IFinanceBillService {
@ -69,6 +74,9 @@ public class FinanceBillServiceImpl implements IFinanceBillService {
bill.setInputExternalAccountId(payChannel.getPlatformExternalAccountId()); bill.setInputExternalAccountId(payChannel.getPlatformExternalAccountId());
bill.setBusinessAmount(orderExt.getOrder().getTotalAmount()); bill.setBusinessAmount(orderExt.getOrder().getTotalAmount());
bill.setTransAmount(orderExt.getOrder().getRealTotalAmount()); bill.setTransAmount(orderExt.getOrder().getRealTotalAmount());
bill.setRemark(CharSequenceUtil.format("档口代发订单{}双,共计{}元",
orderExt.getOrder().getGoodsQuantity(),
orderExt.getOrder().getRealTotalAmount().toPlainString()));
bill.setVersion(0L); bill.setVersion(0L);
bill.setDelFlag(Constants.UNDELETED); bill.setDelFlag(Constants.UNDELETED);
financeBillMapper.insert(bill); financeBillMapper.insert(bill);
@ -123,6 +131,9 @@ public class FinanceBillServiceImpl implements IFinanceBillService {
bill.setOutputInternalAccountId(Constants.PLATFORM_INTERNAL_ACCOUNT_ID); bill.setOutputInternalAccountId(Constants.PLATFORM_INTERNAL_ACCOUNT_ID);
bill.setBusinessAmount(orderExt.getOrder().getTotalAmount()); bill.setBusinessAmount(orderExt.getOrder().getTotalAmount());
bill.setTransAmount(orderExt.getOrder().getRealTotalAmount()); bill.setTransAmount(orderExt.getOrder().getRealTotalAmount());
bill.setRemark(CharSequenceUtil.format("档口代发订单{}双,共计{}元",
orderExt.getOrder().getGoodsQuantity(),
orderExt.getOrder().getRealTotalAmount().toPlainString()));
bill.setVersion(0L); bill.setVersion(0L);
bill.setDelFlag(Constants.UNDELETED); bill.setDelFlag(Constants.UNDELETED);
financeBillMapper.insert(bill); financeBillMapper.insert(bill);
@ -154,6 +165,118 @@ public class FinanceBillServiceImpl implements IFinanceBillService {
return new FinanceBillExt(bill, billDetails); return new FinanceBillExt(bill, billDetails);
} }
@Transactional(rollbackFor = Exception.class)
@Override
public FinanceBillExt createOrderCompletedTransferBill(StoreOrderExt orderExt,
List<StoreOrderExt> afterSaleOrderExts) {
Assert.notNull(orderExt);
FinanceBill bill = new FinanceBill();
bill.setBillNo(generateBillNo(EFinBillType.TRANSFER));
bill.setBillType(EFinBillType.TRANSFER.getValue());
//直接标记成功
bill.setBillStatus(EFinBillStatus.SUCCESS.getValue());
bill.setSrcType(EFinBillSrcType.STORE_ORDER_COMPLETED.getValue());
bill.setSrcId(orderExt.getOrder().getId());
bill.setRelType(EFinBillRelType.STORE_ORDER.getValue());
bill.setRelId(orderExt.getOrder().getId());
//业务唯一键
String businessUniqueKey = "STORE_ORDER_COMPLETED_" + orderExt.getOrder().getId();
bill.setBusinessUniqueKey(businessUniqueKey);
Long inputInternalAccountId = internalAccountService.getAccountAndCheck(orderExt.getOrder().getStoreId(),
EAccountOwnerType.STORE).getId();
bill.setInputInternalAccountId(inputInternalAccountId);
bill.setOutputInternalAccountId(Constants.PLATFORM_INTERNAL_ACCOUNT_ID);
List<String> afterSaleBillUks = new ArrayList<>(afterSaleOrderExts.size());
Map<Long, StoreOrderDetail> afterSaleOrderDetailMap = new HashMap<>();
for (StoreOrderExt afterSaleOrderExt : afterSaleOrderExts) {
afterSaleBillUks.add("STORE_ORDER_REFUND_" + afterSaleOrderExt.getOrder().getId());
for (StoreOrderDetail afterSaleOrderDetail : CollUtil.emptyIfNull(afterSaleOrderExt.getOrderDetails())) {
afterSaleOrderDetailMap.put(afterSaleOrderDetail.getRefundOrderDetailId(), afterSaleOrderDetail);
}
}
Map<Long, FinanceBill> refundPaymentBillMap = MapUtil.empty();
Map<Long, FinanceBillDetail> refundPaymentBillDetailMap = MapUtil.empty();
if (CollUtil.isNotEmpty(afterSaleBillUks)) {
refundPaymentBillMap = financeBillMapper.selectList(
Wrappers.lambdaQuery(FinanceBill.class)
.in(FinanceBill::getBusinessUniqueKey, afterSaleBillUks)
.eq(SimpleEntity::getDelFlag, Constants.UNDELETED))
.stream()
.collect(Collectors.toMap(SimpleEntity::getId, Function.identity()));
Assert.notEmpty(refundPaymentBillMap);
refundPaymentBillDetailMap = financeBillDetailMapper.selectList(
Wrappers.lambdaQuery(FinanceBillDetail.class)
.in(FinanceBillDetail::getFinanceBillId, refundPaymentBillMap.keySet())
.eq(SimpleEntity::getDelFlag, Constants.UNDELETED)).stream()
.collect(Collectors.toMap(FinanceBillDetail::getRelId, Function.identity()));
}
BigDecimal businessAmount = BigDecimal.ZERO;
BigDecimal transAmount = BigDecimal.ZERO;
Integer goodsQuantity = 0;
List<FinanceBillDetail> billDetails = new ArrayList<>(orderExt.getOrderDetails().size());
for (StoreOrderDetail orderDetail : orderExt.getOrderDetails()) {
FinanceBillDetail billDetail = new FinanceBillDetail();
billDetail.setRelType(EFinBillDetailRelType.STORE_ORDER_DETAIL.getValue());
billDetail.setRelId(orderDetail.getId());
billDetail.setBusinessAmount(orderDetail.getTotalAmount());
billDetail.setTransAmount(orderDetail.getRealTotalAmount());
goodsQuantity += orderDetail.getGoodsQuantity();
billDetail.setDelFlag(Constants.UNDELETED);
billDetails.add(billDetail);
StoreOrderDetail afterSaleOrderDetail = afterSaleOrderDetailMap.get(orderDetail.getId());
if (afterSaleOrderDetail != null
&& EPayStatus.PAID.getValue().equals(afterSaleOrderDetail.getPayStatus())) {
//扣除已退款部分数量
goodsQuantity -= afterSaleOrderDetail.getGoodsQuantity();
//退款单据
FinanceBillDetail refundPaymentBillDetail = refundPaymentBillDetailMap
.get(afterSaleOrderDetail.getId());
Assert.notNull(refundPaymentBillDetail);
FinanceBill refundPaymentBill = refundPaymentBillMap
.get(refundPaymentBillDetail.getFinanceBillId());
Assert.notNull(refundPaymentBill);
Assert.isTrue(EFinBillStatus.SUCCESS.getValue().equals(refundPaymentBill.getBillStatus()));
//扣除已退款部分金额
billDetail.setBusinessAmount(NumberUtil.sub(billDetail.getBusinessAmount(),
refundPaymentBillDetail.getBusinessAmount()));
billDetail.setTransAmount(NumberUtil.sub(billDetail.getTransAmount(),
refundPaymentBillDetail.getTransAmount()));
}
businessAmount = NumberUtil.add(businessAmount, billDetail.getBusinessAmount());
transAmount = NumberUtil.add(transAmount, billDetail.getTransAmount());
}
if (NumberUtil.equals(BigDecimal.ZERO, transAmount)) {
log.info("订单[{}]已全部退款,完成时不再创建转移单", orderExt.getOrder().getId());
return null;
}
bill.setBusinessAmount(businessAmount);
bill.setTransAmount(transAmount);
bill.setRemark(CharSequenceUtil.format("档口代发订单{}双,共计{}元", goodsQuantity,
transAmount.toPlainString()));
bill.setVersion(0L);
bill.setDelFlag(Constants.UNDELETED);
financeBillMapper.insert(bill);
for (FinanceBillDetail billDetail : billDetails) {
billDetail.setFinanceBillId(bill.getId());
financeBillDetailMapper.insert(billDetail);
}
TransInfo transInfo = TransInfo.builder()
.srcBillId(bill.getId())
.srcBillType(bill.getBillType())
.transAmount(bill.getTransAmount())
.transTime(new Date())
.handlerId(null)
.remark("订单完成")
.build();
//内部账户
internalAccountService.addTransDetail(Constants.PLATFORM_INTERNAL_ACCOUNT_ID, transInfo,
ELoanDirection.CREDIT, EEntryStatus.FINISH);
internalAccountService.addTransDetail(inputInternalAccountId, transInfo,
ELoanDirection.DEBIT, EEntryStatus.FINISH);
return new FinanceBillExt(bill, billDetails);
}
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public FinanceBillExt createRefundOrderPaymentBill(StoreOrderExt orderExt) { public FinanceBillExt createRefundOrderPaymentBill(StoreOrderExt orderExt) {
@ -174,12 +297,16 @@ public class FinanceBillServiceImpl implements IFinanceBillService {
//售后订单金额以明细为准 //售后订单金额以明细为准
BigDecimal businessAmount = BigDecimal.ZERO; BigDecimal businessAmount = BigDecimal.ZERO;
BigDecimal transferAmount = BigDecimal.ZERO; BigDecimal transferAmount = BigDecimal.ZERO;
Integer goodsQuantity = 0;
for (StoreOrderDetail orderDetail : orderExt.getOrderDetails()) { for (StoreOrderDetail orderDetail : orderExt.getOrderDetails()) {
businessAmount = NumberUtil.add(businessAmount, orderDetail.getTotalAmount()); businessAmount = NumberUtil.add(businessAmount, orderDetail.getTotalAmount());
transferAmount = NumberUtil.add(transferAmount, orderDetail.getRealTotalAmount()); transferAmount = NumberUtil.add(transferAmount, orderDetail.getRealTotalAmount());
goodsQuantity += orderDetail.getGoodsQuantity();
} }
bill.setBusinessAmount(businessAmount); bill.setBusinessAmount(businessAmount);
bill.setTransAmount(transferAmount); bill.setTransAmount(transferAmount);
bill.setRemark(CharSequenceUtil.format("档口代发退货{}双,共计{}元", goodsQuantity,
transferAmount.toPlainString()));
bill.setVersion(0L); bill.setVersion(0L);
bill.setDelFlag(Constants.UNDELETED); bill.setDelFlag(Constants.UNDELETED);
financeBillMapper.insert(bill); financeBillMapper.insert(bill);
@ -220,6 +347,14 @@ public class FinanceBillServiceImpl implements IFinanceBillService {
if (!BeanValidators.exists(financeBill)) { if (!BeanValidators.exists(financeBill)) {
throw new ServiceException(CharSequenceUtil.format("售后订单[{}]对应付款单不存在", storeOrderId)); throw new ServiceException(CharSequenceUtil.format("售后订单[{}]对应付款单不存在", storeOrderId));
} }
if (!EFinBillStatus.PROCESSING.getValue().equals(financeBill.getBillStatus())) {
throw new ServiceException(CharSequenceUtil.format("付款单[{}]状态异常", financeBill.getId()));
}
financeBill.setBillStatus(EFinBillStatus.SUCCESS.getValue());
int r = financeBillMapper.updateById(financeBill);
if (r == 0) {
throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG);
}
//内部账户入账 //内部账户入账
internalAccountService.entryTransDetail(financeBill.getId(), EFinBillType.of(financeBill.getBillType())); internalAccountService.entryTransDetail(financeBill.getId(), EFinBillType.of(financeBill.getBillType()));
} }
@ -249,6 +384,7 @@ public class FinanceBillServiceImpl implements IFinanceBillService {
bill.setOutputExternalAccountId(payChannel.getPlatformExternalAccountId()); bill.setOutputExternalAccountId(payChannel.getPlatformExternalAccountId());
bill.setBusinessAmount(amount); bill.setBusinessAmount(amount);
bill.setTransAmount(amount); bill.setTransAmount(amount);
bill.setRemark(CharSequenceUtil.format("账户提现{}元", amount.toPlainString()));
bill.setVersion(0L); bill.setVersion(0L);
bill.setDelFlag(Constants.UNDELETED); bill.setDelFlag(Constants.UNDELETED);
financeBillMapper.insert(bill); financeBillMapper.insert(bill);
@ -280,6 +416,14 @@ public class FinanceBillServiceImpl implements IFinanceBillService {
if (!BeanValidators.exists(financeBill)) { if (!BeanValidators.exists(financeBill)) {
throw new ServiceException(CharSequenceUtil.format("提现付款单[{}]不存在", financeBillId)); throw new ServiceException(CharSequenceUtil.format("提现付款单[{}]不存在", financeBillId));
} }
if (!EFinBillStatus.PROCESSING.getValue().equals(financeBill.getBillStatus())) {
throw new ServiceException(CharSequenceUtil.format("付款单[{}]状态异常", financeBill.getId()));
}
financeBill.setBillStatus(EFinBillStatus.SUCCESS.getValue());
int r = financeBillMapper.updateById(financeBill);
if (r == 0) {
throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG);
}
//内部账户入账 //内部账户入账
internalAccountService.entryTransDetail(financeBill.getId(), EFinBillType.of(financeBill.getBillType())); internalAccountService.entryTransDetail(financeBill.getId(), EFinBillType.of(financeBill.getBillType()));
//外部账户入账 //外部账户入账

View File

@ -235,11 +235,13 @@ public class InternalAccountServiceImpl implements IInternalAccountService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public void setTransactionPassword(Long id, String transactionPassword) { public void setTransactionPassword(Long id, String phoneNumber, String transactionPassword) {
Assert.notNull(id); Assert.notNull(id);
Assert.notEmpty(phoneNumber);
Assert.notEmpty(transactionPassword); Assert.notEmpty(transactionPassword);
InternalAccount update = new InternalAccount(); InternalAccount update = new InternalAccount();
update.setId(id); update.setId(id);
update.setPhoneNumber(phoneNumber);
update.setTransactionPassword(transactionPassword); update.setTransactionPassword(transactionPassword);
internalAccountMapper.updateById(update); internalAccountMapper.updateById(update);
} }

View File

@ -784,6 +784,14 @@ public class StoreOrderServiceImpl implements IStoreOrderService {
throw new ServiceException(CharSequenceUtil.format("订单[{}]当前状态无法确认收货", throw new ServiceException(CharSequenceUtil.format("订单[{}]当前状态无法确认收货",
order.getOrderNo())); order.getOrderNo()));
} }
//存在售后订单
long afterSaleOrderCount = storeOrderMapper.selectCount(Wrappers.lambdaQuery(StoreOrder.class)
.eq(StoreOrder::getRefundOrderId, storeOrderId)
.eq(SimpleEntity::getDelFlag, Constants.UNDELETED));
if (afterSaleOrderCount > 0) {
throw new ServiceException(CharSequenceUtil.format("订单[{}]存在售后,无法确认收货",
order.getOrderNo()));
}
//订单->已完成 //订单->已完成
order.setOrderStatus(EOrderStatus.COMPLETED.getValue()); order.setOrderStatus(EOrderStatus.COMPLETED.getValue());
int orderSuccess = storeOrderMapper.updateById(order); int orderSuccess = storeOrderMapper.updateById(order);
@ -802,7 +810,7 @@ public class StoreOrderServiceImpl implements IStoreOrderService {
order.getOrderNo())); order.getOrderNo()));
} }
//订单明细->已完成 //订单明细->已完成
orderDetail.setDetailStatus(EOrderStatus.SHIPPED.getValue()); orderDetail.setDetailStatus(EOrderStatus.COMPLETED.getValue());
int orderDetailSuccess = storeOrderDetailMapper.updateById(orderDetail); int orderDetailSuccess = storeOrderDetailMapper.updateById(orderDetail);
if (orderDetailSuccess == 0) { if (orderDetailSuccess == 0) {
throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG); throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG);
@ -818,6 +826,89 @@ public class StoreOrderServiceImpl implements IStoreOrderService {
return orderExt; return orderExt;
} }
@Transactional(rollbackFor = Exception.class)
@Override
public StoreOrderExt completeOrder(Long storeOrderId, Long operatorId) {
StoreOrder order = getAndBaseCheck(storeOrderId);
if (!EOrderStatus.PENDING_SHIPMENT.getValue().equals(order.getOrderStatus())
&& !EOrderStatus.SHIPPED.getValue().equals(order.getOrderStatus())) {
throw new ServiceException(CharSequenceUtil.format("订单[{}]当前状态无法完成",
order.getOrderNo()));
}
//售后订单
List<StoreOrder> afterSaleOrderList = storeOrderMapper.selectList(Wrappers.lambdaQuery(StoreOrder.class)
.eq(StoreOrder::getRefundOrderId, storeOrderId)
.eq(SimpleEntity::getDelFlag, Constants.UNDELETED));
List<StoreOrderExt> afterSaleOrderExts = new ArrayList<>(afterSaleOrderList.size());
if (afterSaleOrderList.size() > 0) {
List<Long> afterSaleOrderIds = afterSaleOrderList.stream().map(SimpleEntity::getId)
.collect(Collectors.toList());
Map<Long, List<StoreOrderDetail>> afterSaleOrderDetailGroupMap = storeOrderDetailMapper.selectList(
Wrappers.lambdaQuery(StoreOrderDetail.class)
.in(StoreOrderDetail::getStoreOrderId, afterSaleOrderIds)
.eq(SimpleEntity::getDelFlag, Constants.UNDELETED))
.stream()
.filter(o -> {
if (!EOrderStatus.AFTER_SALE_COMPLETED.getValue().equals(o.getDetailStatus())) {
throw new ServiceException(CharSequenceUtil.format("订单明细[{}]未完成售后",
o.getId()));
}
if (EPayStatus.PAYING.getValue().equals(o.getPayStatus())) {
throw new ServiceException(CharSequenceUtil.format("订单明细[{}]未完成售后",
o.getId()));
}
return true;
})
.collect(Collectors.groupingBy(StoreOrderDetail::getStoreOrderId));
for (StoreOrder afterSaleOrder : afterSaleOrderList) {
List<StoreOrderDetail> afterSaleOrderDetailList = afterSaleOrderDetailGroupMap
.get(afterSaleOrder.getId());
afterSaleOrderExts.add(new StoreOrderExt(afterSaleOrder, afterSaleOrderDetailList));
if (!EOrderStatus.AFTER_SALE_COMPLETED.getValue().equals(afterSaleOrder.getOrderStatus())) {
throw new ServiceException(CharSequenceUtil.format("订单[{}]未完成售后",
afterSaleOrder.getOrderNo()));
}
//售后订单更新一次,触发乐观锁
int r = storeOrderMapper.updateById(afterSaleOrder);
if (r == 0) {
throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG);
}
}
}
//订单->已完成
order.setOrderStatus(EOrderStatus.COMPLETED.getValue());
int orderSuccess = storeOrderMapper.updateById(order);
if (orderSuccess == 0) {
throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG);
}
List<StoreOrderDetail> orderDetails = storeOrderDetailMapper.selectList(
Wrappers.lambdaQuery(StoreOrderDetail.class)
.eq(StoreOrderDetail::getStoreOrderId, order.getId())
.eq(SimpleEntity::getDelFlag, Constants.UNDELETED));
List<Long> orderDetailIdList = new ArrayList<>(orderDetails.size());
for (StoreOrderDetail orderDetail : orderDetails) {
if (!EOrderStatus.PENDING_SHIPMENT.getValue().equals(order.getOrderStatus())
&& !EOrderStatus.SHIPPED.getValue().equals(order.getOrderStatus())) {
throw new ServiceException(CharSequenceUtil.format("订单明细[{}]当前状态无法确认收货",
order.getOrderNo()));
}
//订单明细->已完成
orderDetail.setDetailStatus(EOrderStatus.COMPLETED.getValue());
int orderDetailSuccess = storeOrderDetailMapper.updateById(orderDetail);
if (orderDetailSuccess == 0) {
throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG);
}
orderDetailIdList.add(orderDetail.getId());
}
//操作记录
addOperationRecords(order.getId(), EOrderAction.COMPLETE, orderDetailIdList, EOrderAction.COMPLETE,
"确认收货", operatorId, new Date());
StoreOrderExt orderExt = new StoreOrderExt(order, orderDetails);
//创建转移单
financeBillService.createOrderCompletedTransferBill(orderExt, afterSaleOrderExts);
return orderExt;
}
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public StoreOrderExt createAfterSaleOrder(StoreOrderAfterSaleDTO afterSaleDTO) { public StoreOrderExt createAfterSaleOrder(StoreOrderAfterSaleDTO afterSaleDTO) {