feat(订单): 添加订单模式字段并实现会员模式逻辑

添加订单模式字段(mode)用于区分不同业务场景
实现会员模式(模式3)的特殊处理逻辑,包括:
- 订单提交时设置商品价格为格口价格
- 订单完成时更新格口租赁状态
- 退货审批时自动审批会员模式订单
This commit is contained in:
dzq 2025-06-28 14:50:40 +08:00
parent bab1a171bf
commit 04fd224005
4 changed files with 57 additions and 20 deletions

View File

@ -290,6 +290,12 @@ public class ReturnApprovalApplicationService {
orderGoodsModel.setStatus(2); // 6表示已完成退货
orderGoodsModel.updateById();
if (orderGoodsModel.getMode()!= null && orderGoodsModel.getMode().equals(3)) {
// 模式为3需要更新柜子格口状态
CabinetCellEntity cell = cabinetCellService.getById(orderGoodsModel.getCellId());
cell.setIsRented(0);
cell.updateById();
} else {
// 更新商品库存
GoodsModel goodsModel = goodsModelFactory.loadById(orderGoodsModel.getGoodsId());
goodsModel.setStock(goodsModel.getStock() + orderGoodsModel.getQuantity());
@ -300,6 +306,7 @@ public class ReturnApprovalApplicationService {
cabinetCellModel.setStock(cabinetCellModel.getStock() + orderGoodsModel.getQuantity());
cabinetCellModel.updateById();
}
}
/**
@ -729,6 +736,15 @@ public class ReturnApprovalApplicationService {
orderGoodsModel.setStatus(5);
orderGoodsModel.updateById();
if (orderGoods.getMode() != null && orderGoods.getMode().equals(3)) {
UpdateReturnApprovalCommand approveCommand = new UpdateReturnApprovalCommand();
approveCommand.setCorpid(command.getCorpid());
approveCommand.setApprovalId(returnApprovalModel.getApprovalId());
approveCommand.setReturnAmount(orderGoods.getTotalAmount());
approveCommand.setAuditName("自动审批");
approveCommand.setAuditRemark("自动审批");
approveApproval(approveCommand);
} else {
GoodsModel goodsModel = goodsModelFactory.loadById(orderGoods.getGoodsId());
// 如果商品免审批则自动审批
if (goodsModel.getAutoApproval().equals(1)) {
@ -740,6 +756,7 @@ public class ReturnApprovalApplicationService {
approveCommand.setAuditRemark("自动审批");
approveApproval(approveCommand);
}
}
// 发送审核消息
try {

View File

@ -182,6 +182,7 @@ public class OrderApplicationService {
orderModel.setUserid(command.getQyUserid());
orderModel.setName(command.getName());
orderModel.setIsDeductStock(0);
orderModel.setMode(command.getMode());
orderModel.insert();
goodsList.forEach(goods -> {
@ -326,13 +327,19 @@ public class OrderApplicationService {
goodsModel.setUpdateTime(new Date());
goodsModel.setDeleted(false);
CabinetCellEntity cabinetCellEntity = cabinetCellService.getById(goodsModel.getCellId());
if (orderModel.getMode() != null && orderModel.getMode().equals(3)) {
goodsModel.setPrice(cabinetCellEntity.getCellPrice());
goodsModel.setTotalAmount(cabinetCellEntity.getCellPrice());
} else {
// 计算商品金额并验证库存
goodsModel.calculateTotal();
goodsModel.validateQuantity();
CabinetCellEntity cabinetCellEntity = cabinetCellService.getById(goodsModel.getCellId());
if (cabinetCellEntity == null || cabinetCellEntity.getStock() < goodsModel.getQuantity()) {
throw new ApiException(ErrorCode.FAILED, "柜子库存不足");
}
}
// 保存订单商品
goodsModel.insert();

View File

@ -31,6 +31,9 @@ public class SubmitOrderCommand {
@ApiModelProperty("联系电话")
private String mobile;
@ApiModelProperty("运行模式0-支付模式 1-审批模式 2-借还模式 3-会员模式 4-耗材模式)")
private Integer mode;
@ApiModelProperty("企业微信用户ID或汇邦云用户ID")
private String qyUserid;

View File

@ -10,6 +10,7 @@ import com.agileboot.domain.cabinet.cell.db.CabinetCellService;
import com.agileboot.domain.shop.goods.db.ShopGoodsEntity;
import com.agileboot.domain.shop.goods.db.ShopGoodsService;
import com.agileboot.domain.shop.order.db.ShopOrderEntity;
import com.agileboot.domain.shop.order.db.ShopOrderGoodsEntity;
import com.agileboot.domain.shop.order.db.ShopOrderGoodsService;
import com.agileboot.domain.shop.order.db.ShopOrderService;
import java.math.BigDecimal;
@ -98,12 +99,21 @@ public class OrderModel extends ShopOrderEntity {
this.updateById();
if (!isDeductStock) {
orderGoodsService.selectByOrderId(this.getOrderId()).forEach(orderGoods -> {
List<ShopOrderGoodsEntity> orderGoodsList = orderGoodsService.selectByOrderId(this.getOrderId());
if (this.getMode() != null && this.getMode().equals(3)) {
for (ShopOrderGoodsEntity orderGoods : orderGoodsList) {
CabinetCellEntity cell = cabinetCellService.getById(orderGoods.getCellId());
cell.setIsRented(1);
cell.updateById();
}
} else {
orderGoodsList.forEach(orderGoods -> {
// 扣减库存
deductGoodsStock(orderGoods.getGoodsId(), orderGoods.getQuantity(), orderGoods.getCellId());
});
}
}
}
public void handleRefundSuccess() {
// 更新订单状态