积分专区的实现
This commit is contained in:
@@ -38,5 +38,9 @@ public interface PmsProductMapper {
|
||||
|
||||
PmsProduct getProductInfoById(Long id);
|
||||
|
||||
PmsProduct getProductByOrderSn(String orderSn);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -921,4 +921,14 @@
|
||||
where ppfr.product_id=#{id,jdbcType=BIGINT} limit 1
|
||||
</select>
|
||||
|
||||
<select id="getProductByOrderSn" resultMap="BaseResultMap">
|
||||
SELECT p.*
|
||||
FROM pms_product p
|
||||
WHERE p.product_sn = (
|
||||
SELECT oi.product_sn
|
||||
FROM oms_order_item oi
|
||||
WHERE oi.order_sn = #{orderSn}
|
||||
LIMIT 1
|
||||
)
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -315,39 +315,39 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
||||
OrderResult orderResult = new OrderResult();
|
||||
OmsOrder order = orderMapper.selectByPrimaryKey(orderId);
|
||||
//删除状态:0->未删除;1->已删除
|
||||
if (order != null && order.getMemberId().equals(loginMember.getId()) && order.getDeleteStatus() == 0) {
|
||||
if(order != null && order.getMemberId().equals(loginMember.getId()) && order.getDeleteStatus() == 0) {
|
||||
orderResult.setOrderId(order.getId());
|
||||
orderResult.setOrderSn(order.getOrderSn());
|
||||
orderResult.setCreateTime(order.getCreateTime());
|
||||
orderResult.setPayAmount(order.getPayAmount());
|
||||
orderResult.setOrderStatus(order.getStatus());
|
||||
orderResult.setDeliveryType(order.getDeliveryType());
|
||||
if (order.getStatus() == 0) {
|
||||
if(order.getStatus() == 0) {
|
||||
orderResult.setOrderStatusName("待付款");
|
||||
if (order.getPayType() != null && order.getPayType() == 3) {
|
||||
if(order.getPayType() != null && order.getPayType() == 3) {
|
||||
orderResult.setOrderStatusName("已付款待审核");
|
||||
}
|
||||
}
|
||||
if (order.getStatus() == 1) {
|
||||
if(order.getStatus() == 1) {
|
||||
orderResult.setOrderStatusName("待发货");
|
||||
}
|
||||
if (order.getStatus() == 2) {
|
||||
if(order.getStatus() == 2) {
|
||||
// 提货方式:0->自提;1->物流
|
||||
if (order.getDeliveryType() == 0) {
|
||||
if(order.getDeliveryType() == 0) {
|
||||
orderResult.setOrderStatusName("待提货");
|
||||
} else {
|
||||
orderResult.setOrderStatusName("待收货");
|
||||
}
|
||||
}
|
||||
if (order.getStatus() == 3) {
|
||||
if(order.getStatus() == 3) {
|
||||
orderResult.setOrderStatusName("交易完成");
|
||||
if (order.getCommentTime() == null) {
|
||||
if(order.getCommentTime() == null) {
|
||||
orderResult.setCommentStatus(0); //未评价
|
||||
} else {
|
||||
orderResult.setCommentStatus(1); //已评价
|
||||
}
|
||||
}
|
||||
if (order.getStatus() == 4) {
|
||||
if(order.getStatus() == 4) {
|
||||
orderResult.setOrderStatusName("交易关闭");
|
||||
orderResult.setOrderStatus(4);
|
||||
}
|
||||
@@ -357,7 +357,18 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
||||
orderResult.setDeliveryCompany(order.getDeliveryCompany());
|
||||
orderResult.setDeliverySn(order.getDeliverySn());
|
||||
orderResult.setPaymentTime(order.getPaymentTime());
|
||||
|
||||
// 获取商品信息,判断是否是积分专区商品
|
||||
PmsProduct product = productMapper.getProductByOrderSn((order.getOrderSn()));
|
||||
boolean isPointsExchangeStatus = product != null && product.getPointsExchangeStatus() == 1;
|
||||
|
||||
//支付类型: 0->未支付;1->支付宝;2->微信; 3->线下支付; 4->积分支付
|
||||
//判断是否为积分专区商品
|
||||
if(isPointsExchangeStatus) {
|
||||
orderResult.setPayType(4); // 设置为积分支付
|
||||
orderResult.setPayTypeName("积分支付");
|
||||
}else {
|
||||
// 如果不是积分兑换专区商品,则继续使用其他支付方式
|
||||
if (order.getPayType() != null) {
|
||||
orderResult.setPayType(order.getPayType());
|
||||
if (order.getPayType() == 0) {
|
||||
@@ -387,17 +398,18 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
||||
orderResult.setPayType(0);
|
||||
orderResult.setPayTypeName("未支付");
|
||||
}
|
||||
}
|
||||
|
||||
orderResult.setDeliveryTime(order.getDeliveryTime());
|
||||
orderResult.setReceiveTime(order.getReceiveTime());
|
||||
orderResult.setCommentTime(order.getCommentTime());
|
||||
|
||||
//0->不开发票;1->电子发票;2->纸质发票
|
||||
if (order.getBillType() != null) {
|
||||
if(order.getBillType() != null) {
|
||||
orderResult.setBillType(order.getBillType());
|
||||
if (order.getBillType() == 1) {
|
||||
if(order.getBillType() == 1) {
|
||||
orderResult.setBillTypeName("电子发票");
|
||||
} else if (order.getBillType() == 2) {
|
||||
} else if(order.getBillType() == 2) {
|
||||
orderResult.setBillTypeName("纸质发票");
|
||||
} else {
|
||||
orderResult.setBillTypeName("不开发票");
|
||||
@@ -423,7 +435,7 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
||||
OrderItemResult orderItemResult = null;
|
||||
orderResult.setProductsNum(orderItemList.size());
|
||||
List<OrderItemResult> orderItemResultList = new ArrayList<>();
|
||||
for (OmsOrderItem orderItem : orderItemList) {
|
||||
for(OmsOrderItem orderItem : orderItemList) {
|
||||
orderItemResult = new OrderItemResult();
|
||||
orderItemResult.setOrderId(order.getId());
|
||||
orderItemResult.setOrderSn(order.getOrderSn());
|
||||
@@ -702,55 +714,58 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
||||
/**
|
||||
* 直接购买,根据提交信息生成订单
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
/**
|
||||
* 创建订单
|
||||
*/
|
||||
public CommonResult createOrder(OrderParam orderParam) {
|
||||
//orderParam.setSkuId(98L);
|
||||
if (orderParam.getSkuId() == null) {
|
||||
if(orderParam.getSkuId() == null) {
|
||||
return CommonResult.validateFailed("商品SKU不能为空");
|
||||
}
|
||||
|
||||
if (orderParam.getDeliveryType() == null || (orderParam.getDeliveryType() != 0 && orderParam.getDeliveryType() != 1)) {
|
||||
if(orderParam.getDeliveryType() == null || (orderParam.getDeliveryType() != 0 && orderParam.getDeliveryType() != 1) ) {
|
||||
return CommonResult.validateFailed("提货方式不能为空");
|
||||
}
|
||||
|
||||
if (orderParam.getMemberReceiveAddressId() == null) {
|
||||
if(orderParam.getMemberReceiveAddressId() == null) {
|
||||
return CommonResult.validateFailed("会员收货地址不能为空");
|
||||
}
|
||||
|
||||
UmsMemberReceiveAddress address = memberReceiveAddressMapper.selectOneById(orderParam.getMemberReceiveAddressId());
|
||||
if (address == null) {
|
||||
if(address == null) {
|
||||
return CommonResult.validateFailed("未查询到会员收货地址");
|
||||
}
|
||||
if (orderParam.getQuantity() == null) {
|
||||
if(orderParam.getQuantity() == null) {
|
||||
return CommonResult.validateFailed("商品数量不能为空");
|
||||
}
|
||||
if (orderParam.getQuantity() <= 0) {
|
||||
if(orderParam.getQuantity() <= 0) {
|
||||
return CommonResult.validateFailed("商品数量错误");
|
||||
}
|
||||
PmsSkuStock skuStock = skuStockMapper.selectByPrimaryKey(orderParam.getSkuId());
|
||||
if (skuStock == null) {
|
||||
if(skuStock == null) {
|
||||
return CommonResult.validateFailed("未查询到商品信息");
|
||||
}
|
||||
|
||||
PmsProduct product = new PmsProduct();
|
||||
|
||||
// 判断商品是否属于积分兑换区
|
||||
boolean isPointsExchangeStatus = product.getPointsExchangeStatus() == 1;
|
||||
|
||||
//判断商品是否都有库存 (库存 - 锁定库存 = 真实库存)
|
||||
if ((skuStock.getStock() - skuStock.getLockStock()) < orderParam.getQuantity()) {
|
||||
return CommonResult.validateFailed("库存不足,无法下单");
|
||||
}
|
||||
|
||||
//根据商品id查询商品信息
|
||||
PmsProduct product = productMapper.selectByPrimaryKey(skuStock.getProductId());
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
if (product != null) {
|
||||
if(product != null) {
|
||||
|
||||
UmsMember member = memberMapper.selectByPrimaryKey(memberService.getCurrentMember().getId());
|
||||
|
||||
BigDecimal discount = commonService.getDiscount(member.getId());
|
||||
BigDecimal price = new BigDecimal(skuStock.getPrice().doubleValue());
|
||||
if (discount != null) {
|
||||
if(discount != null) {
|
||||
price = skuStock.getPrice().multiply(discount).setScale(2, BigDecimal.ROUND_HALF_UP);
|
||||
}
|
||||
|
||||
@@ -758,7 +773,25 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
||||
BigDecimal zero = new BigDecimal(0);
|
||||
totalAmount = price.multiply(new BigDecimal(orderParam.getQuantity()));
|
||||
|
||||
if (orderParam.getIntegration() == null) {
|
||||
// 如果是积分兑换区商品
|
||||
if (isPointsExchangeStatus) {
|
||||
// 直接使用积分支付,不进行实际支付金额的处理
|
||||
BigDecimal integrationAmount = totalAmount;
|
||||
// 确保会员有足够的积分
|
||||
if (member.getIntegration() < integrationAmount.intValue()) {
|
||||
return CommonResult.validateFailed("积分不足,无法兑换");
|
||||
}
|
||||
|
||||
// 冻结会员积分
|
||||
member.setIntegration(member.getIntegration() - integrationAmount.intValue()); // 扣除积分
|
||||
member.setFreeze(member.getFreeze().add(new BigDecimal(integrationAmount.intValue()))); // 冻结积分
|
||||
memberMapper.updateByPrimaryKey(member);
|
||||
|
||||
totalAmount = zero; // 设置支付金额为零
|
||||
orderParam.setIntegration(integrationAmount); // 设置积分金额
|
||||
}
|
||||
|
||||
if(orderParam.getIntegration() == null) {
|
||||
orderParam.setIntegration(zero);
|
||||
}
|
||||
|
||||
@@ -767,7 +800,7 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
||||
//flag = -1,表示integration小于0;flag = 0,表示integration等于0;flag = 1,表示integration大于0;
|
||||
//int integerationFlag = orderParam.getIntegration().compareTo(new BigDecimal(0)); //mcoo
|
||||
int integerationFlag = 0;
|
||||
if (integerationFlag == 1) {
|
||||
if(integerationFlag == 1) {
|
||||
int flag = member.getBalance().compareTo(orderParam.getIntegration());
|
||||
//flag = -1,表示balance小于integration;flag = 0,表示balance等于integration;flag = 1,表示balance大于integration;
|
||||
/*if(flag == -1) {
|
||||
@@ -775,9 +808,9 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
||||
}*/
|
||||
}
|
||||
|
||||
while (true) {
|
||||
while(true) {
|
||||
long time = System.currentTimeMillis() + RedisLock.TIMEOUT;
|
||||
if (redisLock.lock(String.valueOf(skuStock.getProductId()), String.valueOf(time))) {
|
||||
if(redisLock.lock(String.valueOf(skuStock.getProductId()), String.valueOf(time))) {
|
||||
|
||||
//重新查询获取最新的数据
|
||||
skuStock = skuStockMapper.selectByPrimaryKey(orderParam.getSkuId());
|
||||
@@ -798,13 +831,14 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
||||
//生成订单信息
|
||||
OmsOrder order = new OmsOrder();
|
||||
order.setTotalAmount(totalAmount); // 订单总金额
|
||||
if (integerationFlag == 1) {
|
||||
order.setIntegrationAmount(orderParam.getIntegration() == null ? zero : orderParam.getIntegration());
|
||||
if(integerationFlag == 1) {
|
||||
int flag = orderParam.getIntegration().compareTo(totalAmount);
|
||||
BigDecimal integeration = new BigDecimal(0);
|
||||
//flag = -1,表示integration小于totalAmount;flag = 0,表示integration等于totalAmount;flag = 1,表示integration大于totalAmount;
|
||||
//如果传入的积分小于实际支付金额,用实际支付金额减去抵扣积分。
|
||||
//如果传入的积分等于或者大于实际支付金额,表示全额抵扣
|
||||
if (flag == -1) {
|
||||
if(flag == -1) {
|
||||
order.setPayAmount(totalAmount.subtract(orderParam.getIntegration())); //实际支付金额
|
||||
order.setIntegrationAmount(orderParam.getIntegration());
|
||||
integeration = orderParam.getIntegration();
|
||||
@@ -837,6 +871,7 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
||||
order.setModifyTime(date);
|
||||
order.setMemberUsername(member.getUsername());
|
||||
order.setFreightAmount(zero); //运费
|
||||
order.setPayType(isPointsExchangeStatus ? 4 : 0); // payType为4代表积分支付
|
||||
order.setPromotionAmount(zero); //促销优化金额(促销价、满减、阶梯价)
|
||||
order.setCouponAmount(zero);
|
||||
order.setDiscountAmount(zero);
|
||||
|
||||
Reference in New Issue
Block a user