Commit d0b07205 by caiyt

订单明细拆分问题修复

parent a314c3c7
...@@ -180,28 +180,33 @@ public class OrderServiceImpl implements IOrderService { ...@@ -180,28 +180,33 @@ public class OrderServiceImpl implements IOrderService {
orderDetail.setCreatedAt(new Date()); orderDetail.setCreatedAt(new Date());
orderDetail.setUpdatedAt(new Date()); orderDetail.setUpdatedAt(new Date());
orderDetail.setMachineId(machineId); orderDetail.setMachineId(machineId);
BigDecimal amountShould = orderDetail.getAmountShould(); BigDecimal amountShould = orderDetail.getAmountShould();
BigDecimal couponAmount = orderDetail.getCouponAmount(); BigDecimal couponAmount = orderDetail.getCouponAmount();
if (couponAmount == null) {
couponAmount = BigDecimal.ZERO;
}
BigDecimal realAmount = orderDetail.getRealAmount(); BigDecimal realAmount = orderDetail.getRealAmount();
BigDecimal amountShouldUnit = amountShould.divide(new BigDecimal(orderDetail.getNum()), 2, BigDecimal.ROUND_HALF_UP);
orderDetail.setAmountShould(amountShouldUnit);
BigDecimal couponAmountUnit = couponAmount.divide(new BigDecimal(orderDetail.getNum()), 2, BigDecimal.ROUND_HALF_UP);
orderDetail.setCouponAmount(couponAmountUnit);
BigDecimal realAmountUnit = realAmount.divide(new BigDecimal(orderDetail.getNum()), 2, BigDecimal.ROUND_HALF_UP);
orderDetail.setRealAmount(realAmountUnit);
int skuNum = orderDetail.getNum(); int skuNum = orderDetail.getNum();
BigDecimal amountShouldUnit = amountShould.divide(new BigDecimal(skuNum), 2, BigDecimal.ROUND_HALF_UP);
BigDecimal couponAmountUnit = couponAmount.divide(new BigDecimal(skuNum), 2, BigDecimal.ROUND_HALF_UP);
BigDecimal realAmountUnit = realAmount.divide(new BigDecimal(skuNum), 2, BigDecimal.ROUND_HALF_UP);
for (int i = 1; i <= skuNum; i++) { for (int i = 1; i <= skuNum; i++) {
if (i == orderDetail.getNum()) {
OrderDetail orderDetailLst = new OrderDetail(); OrderDetail orderDetailLst = new OrderDetail();
BeanUtils.copyProperties(orderDetail, orderDetailLst); BeanUtils.copyProperties(orderDetail, orderDetailLst);
orderDetailLst.setNum(1);
if (i == skuNum) {
orderDetailLst.setAmountShould(amountShould.subtract(amountShouldUnit.multiply(new BigDecimal(i - 1)))); orderDetailLst.setAmountShould(amountShould.subtract(amountShouldUnit.multiply(new BigDecimal(i - 1))));
orderDetailLst.setCouponAmount(couponAmount.subtract(couponAmountUnit.multiply(new BigDecimal(i - 1)))); orderDetailLst.setCouponAmount(couponAmount.subtract(couponAmountUnit.multiply(new BigDecimal(i - 1))));
orderDetailLst.setRealAmount(realAmount.subtract(realAmountUnit.multiply(new BigDecimal(i - 1)))); orderDetailLst.setRealAmount(realAmount.subtract(realAmountUnit.multiply(new BigDecimal(i - 1))));
detailsSave.add(orderDetailLst);
} else { } else {
orderDetail.setNum(1); orderDetailLst.setAmountShould(amountShouldUnit);
detailsSave.add(orderDetail); orderDetailLst.setCouponAmount(couponAmountUnit);
orderDetailLst.setRealAmount(realAmountUnit);
} }
detailsSave.add(orderDetailLst);
} }
} }
order.setOrderDetails(detailsSave); order.setOrderDetails(detailsSave);
......
...@@ -115,7 +115,7 @@ ...@@ -115,7 +115,7 @@
</trim> </trim>
</insert> </insert>
<insert id="insertBatch"> <insert id="insertBatch" useGeneratedKeys="true" keyProperty="id">
INSERT INTO order_detail ( order_id, goods_id, goods_name, machine_id, num, unit_price, ori_amount, INSERT INTO order_detail ( order_id, goods_id, goods_name, machine_id, num, unit_price, ori_amount,
amount_should, coupon_amount, real_amount, spec_rule_detail, spec_rule_ids, sku_id, goods_category, created_at, amount_should, coupon_amount, real_amount, spec_rule_detail, spec_rule_ids, sku_id, goods_category, created_at,
refund_id, refund_time, updated_at ) VALUES refund_id, refund_time, updated_at ) VALUES
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment