添加部分下单接口

This commit is contained in:
zhh 2018-08-30 17:27:58 +08:00
parent b33f396d53
commit c9831e0288
8 changed files with 161 additions and 45 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?PowerDesigner AppLocale="UTF16" ID="{7BB41C87-EFE8-409A-A86E-B1C3FCE34F8C}" Label="" LastModificationDate="1535612418" Name="mall" Objects="1025" Symbols="127" Target="MySQL 5.0" Type="{CDE44E21-9669-11D1-9914-006097355D9B}" signature="PDM_DATA_MODEL_XML" version="16.5.0.3982"?> <?PowerDesigner AppLocale="UTF16" ID="{7BB41C87-EFE8-409A-A86E-B1C3FCE34F8C}" Label="" LastModificationDate="1535615091" Name="mall" Objects="1025" Symbols="127" Target="MySQL 5.0" Type="{CDE44E21-9669-11D1-9914-006097355D9B}" signature="PDM_DATA_MODEL_XML" version="16.5.0.3982"?>
<!-- do not edit this file --> <!-- do not edit this file -->
<Model xmlns:a="attribute" xmlns:c="collection" xmlns:o="object"> <Model xmlns:a="attribute" xmlns:c="collection" xmlns:o="object">
@ -4937,8 +4937,8 @@ DESTINATION 0 新宋体,8,N</a:FontList>
<o:ReferenceSymbol Id="o116"> <o:ReferenceSymbol Id="o116">
<a:CreationDate>1522226272</a:CreationDate> <a:CreationDate>1522226272</a:CreationDate>
<a:ModificationDate>1522399075</a:ModificationDate> <a:ModificationDate>1522399075</a:ModificationDate>
<a:Rect>((-31175,47728), (83441,113756))</a:Rect> <a:Rect>((-38306,47728), (83441,113756))</a:Rect>
<a:ListOfPoints>((83041,113356),(83041,50658),(-30550,50658),(-30550,48128))</a:ListOfPoints> <a:ListOfPoints>((83041,113356),(83041,94555),(-37681,94555),(-37681,48128))</a:ListOfPoints>
<a:CornerStyle>1</a:CornerStyle> <a:CornerStyle>1</a:CornerStyle>
<a:ArrowStyle>1</a:ArrowStyle> <a:ArrowStyle>1</a:ArrowStyle>
<a:LineColor>12615680</a:LineColor> <a:LineColor>12615680</a:LineColor>
@ -5113,8 +5113,8 @@ DESTINATION 0 新宋体,8,N</a:FontList>
<o:ReferenceSymbol Id="o139"> <o:ReferenceSymbol Id="o139">
<a:CreationDate>1522389232</a:CreationDate> <a:CreationDate>1522389232</a:CreationDate>
<a:ModificationDate>1522398872</a:ModificationDate> <a:ModificationDate>1522398872</a:ModificationDate>
<a:Rect>((28232,58216), (43845,60017))</a:Rect> <a:Rect>((33605,58216), (43845,60017))</a:Rect>
<a:ListOfPoints>((28632,59617),(28632,58841),(43445,58841))</a:ListOfPoints> <a:ListOfPoints>((34005,59617),(34005,58841),(43445,58841))</a:ListOfPoints>
<a:CornerStyle>1</a:CornerStyle> <a:CornerStyle>1</a:CornerStyle>
<a:ArrowStyle>1</a:ArrowStyle> <a:ArrowStyle>1</a:ArrowStyle>
<a:LineColor>12615680</a:LineColor> <a:LineColor>12615680</a:LineColor>
@ -6918,7 +6918,7 @@ LABL 0 新宋体,8,N</a:FontList>
</o:TableSymbol> </o:TableSymbol>
<o:TableSymbol Id="o247"> <o:TableSymbol Id="o247">
<a:CreationDate>1522398032</a:CreationDate> <a:CreationDate>1522398032</a:CreationDate>
<a:ModificationDate>1522398627</a:ModificationDate> <a:ModificationDate>1535615091</a:ModificationDate>
<a:IconMode>-1</a:IconMode> <a:IconMode>-1</a:IconMode>
<a:Rect>((22716,17129), (36336,22677))</a:Rect> <a:Rect>((22716,17129), (36336,22677))</a:Rect>
<a:LineColor>12615680</a:LineColor> <a:LineColor>12615680</a:LineColor>
@ -13949,11 +13949,11 @@ LABL 0 新宋体,8,N</a:FontList>
</o:Table> </o:Table>
<o:Table Id="o248"> <o:Table Id="o248">
<a:ObjectID>C1DCA2EA-AC28-420C-BFEF-FFE7F5644910</a:ObjectID> <a:ObjectID>C1DCA2EA-AC28-420C-BFEF-FFE7F5644910</a:ObjectID>
<a:Name>ums_intergration_consume_setting</a:Name> <a:Name>ums_integration_consume_setting</a:Name>
<a:Code>ums_intergration_consume_setting</a:Code> <a:Code>ums_integration_consume_setting</a:Code>
<a:CreationDate>1522398032</a:CreationDate> <a:CreationDate>1522398032</a:CreationDate>
<a:Creator>zhenghong</a:Creator> <a:Creator>zhenghong</a:Creator>
<a:ModificationDate>1522398305</a:ModificationDate> <a:ModificationDate>1535615091</a:ModificationDate>
<a:Modifier>zhenghong</a:Modifier> <a:Modifier>zhenghong</a:Modifier>
<a:Comment>积分消费设置</a:Comment> <a:Comment>积分消费设置</a:Comment>
<a:TotalSavingCurrency/> <a:TotalSavingCurrency/>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?PowerDesigner AppLocale="UTF16" ID="{7BB41C87-EFE8-409A-A86E-B1C3FCE34F8C}" Label="" LastModificationDate="1535615091" Name="mall" Objects="1025" Symbols="127" Target="MySQL 5.0" Type="{CDE44E21-9669-11D1-9914-006097355D9B}" signature="PDM_DATA_MODEL_XML" version="16.5.0.3982"?> <?PowerDesigner AppLocale="UTF16" ID="{7BB41C87-EFE8-409A-A86E-B1C3FCE34F8C}" Label="" LastModificationDate="1535619079" Name="mall" Objects="1025" Symbols="127" Target="MySQL 5.0" Type="{CDE44E21-9669-11D1-9914-006097355D9B}" signature="PDM_DATA_MODEL_XML" version="16.5.0.3982"?>
<!-- do not edit this file --> <!-- do not edit this file -->
<Model xmlns:a="attribute" xmlns:c="collection" xmlns:o="object"> <Model xmlns:a="attribute" xmlns:c="collection" xmlns:o="object">
@ -7979,9 +7979,10 @@ LABL 0 新宋体,8,N</a:FontList>
<a:Code>stock</a:Code> <a:Code>stock</a:Code>
<a:CreationDate>1521709829</a:CreationDate> <a:CreationDate>1521709829</a:CreationDate>
<a:Creator>zhenghong</a:Creator> <a:Creator>zhenghong</a:Creator>
<a:ModificationDate>1521709932</a:ModificationDate> <a:ModificationDate>1535619079</a:ModificationDate>
<a:Modifier>zhenghong</a:Modifier> <a:Modifier>zhenghong</a:Modifier>
<a:Comment>库存</a:Comment> <a:Comment>库存</a:Comment>
<a:DefaultValue>0</a:DefaultValue>
<a:DataType>int</a:DataType> <a:DataType>int</a:DataType>
</o:Column> </o:Column>
<o:Column Id="o327"> <o:Column Id="o327">
@ -8071,9 +8072,10 @@ LABL 0 新宋体,8,N</a:FontList>
<a:Code>lock_stock</a:Code> <a:Code>lock_stock</a:Code>
<a:CreationDate>1534927865</a:CreationDate> <a:CreationDate>1534927865</a:CreationDate>
<a:Creator>zhenghong</a:Creator> <a:Creator>zhenghong</a:Creator>
<a:ModificationDate>1534927909</a:ModificationDate> <a:ModificationDate>1535619073</a:ModificationDate>
<a:Modifier>zhenghong</a:Modifier> <a:Modifier>zhenghong</a:Modifier>
<a:Comment>锁定库存</a:Comment> <a:Comment>锁定库存</a:Comment>
<a:DefaultValue>0</a:DefaultValue>
<a:DataType>int</a:DataType> <a:DataType>int</a:DataType>
</o:Column> </o:Column>
</c:Columns> </c:Columns>

View File

@ -2,11 +2,13 @@ package com.macro.mall.portal.controller;
import com.macro.mall.portal.domain.CommonResult; import com.macro.mall.portal.domain.CommonResult;
import com.macro.mall.portal.domain.ConfirmOrderResult; import com.macro.mall.portal.domain.ConfirmOrderResult;
import com.macro.mall.portal.domain.OrderParam;
import com.macro.mall.portal.service.OmsPortalOrderService; import com.macro.mall.portal.service.OmsPortalOrderService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
@ -22,10 +24,17 @@ public class OmsPortalOrderController {
@Autowired @Autowired
private OmsPortalOrderService portalOrderService; private OmsPortalOrderService portalOrderService;
@ApiOperation("根据购物车信息生成确认单信息") @ApiOperation("根据购物车信息生成确认单信息")
@RequestMapping(value = "confirmOrder",method = RequestMethod.POST) @RequestMapping(value = "/generateConfirmOrder",method = RequestMethod.POST)
@ResponseBody @ResponseBody
public Object confirmOrder(){ public Object generateConfirmOrder(){
ConfirmOrderResult confirmOrderResult = portalOrderService.generateConfirmOrder(); ConfirmOrderResult confirmOrderResult = portalOrderService.generateConfirmOrder();
return new CommonResult().success(confirmOrderResult); return new CommonResult().success(confirmOrderResult);
} }
@ApiOperation("根据购物车信息生成订单")
@RequestMapping(value = "/generateOrder",method = RequestMethod.POST)
@ResponseBody
public Object generateOrder(@RequestBody OrderParam orderParam){
return portalOrderService.generateOrder(orderParam);
}
} }

View File

@ -13,7 +13,8 @@ public class CartPromotionItem extends OmsCartItem{
private String promotionMessage; private String promotionMessage;
//促销活动减去的金额针对每个商品 //促销活动减去的金额针对每个商品
private BigDecimal reduceAmount; private BigDecimal reduceAmount;
//商品的真实库存剩余库存-锁定库存
private Integer realStock;
public String getPromotionMessage() { public String getPromotionMessage() {
return promotionMessage; return promotionMessage;
} }
@ -29,4 +30,12 @@ public class CartPromotionItem extends OmsCartItem{
public void setReduceAmount(BigDecimal reduceAmount) { public void setReduceAmount(BigDecimal reduceAmount) {
this.reduceAmount = reduceAmount; this.reduceAmount = reduceAmount;
} }
public Integer getRealStock() {
return realStock;
}
public void setRealStock(Integer realStock) {
this.realStock = realStock;
}
} }

View File

@ -0,0 +1,48 @@
package com.macro.mall.portal.domain;
/**
* 生成订单时传入的参数
* Created by macro on 2018/8/30.
*/
public class OrderParam {
//收货地址id
private Long memberReceiveAddressId;
//优惠券id
private Long couponId;
//使用的积分数
private Integer useIngegration;
//支付方式
private Integer payType;
public Long getMemberReceiveAddressId() {
return memberReceiveAddressId;
}
public void setMemberReceiveAddressId(Long memberReceiveAddressId) {
this.memberReceiveAddressId = memberReceiveAddressId;
}
public Long getCouponId() {
return couponId;
}
public void setCouponId(Long couponId) {
this.couponId = couponId;
}
public Integer getUseIngegration() {
return useIngegration;
}
public void setUseIngegration(Integer useIngegration) {
this.useIngegration = useIngegration;
}
public Integer getPayType() {
return payType;
}
public void setPayType(Integer payType) {
this.payType = payType;
}
}

View File

@ -1,6 +1,9 @@
package com.macro.mall.portal.service; package com.macro.mall.portal.service;
import com.macro.mall.portal.domain.CommonResult;
import com.macro.mall.portal.domain.ConfirmOrderResult; import com.macro.mall.portal.domain.ConfirmOrderResult;
import com.macro.mall.portal.domain.OrderParam;
import org.springframework.transaction.annotation.Transactional;
/** /**
* 前台订单管理Service * 前台订单管理Service
@ -11,4 +14,10 @@ public interface OmsPortalOrderService {
* 根据用户购物车信息生成确认单信息 * 根据用户购物车信息生成确认单信息
*/ */
ConfirmOrderResult generateConfirmOrder(); ConfirmOrderResult generateConfirmOrder();
/**
* 根据提交信息生成订单
*/
@Transactional
CommonResult generateOrder(OrderParam orderParam);
} }

View File

@ -1,12 +1,9 @@
package com.macro.mall.portal.service.impl; package com.macro.mall.portal.service.impl;
import com.macro.mall.mapper.PmsSkuStockMapper;
import com.macro.mall.mapper.UmsIntegrationConsumeSettingMapper; import com.macro.mall.mapper.UmsIntegrationConsumeSettingMapper;
import com.macro.mall.model.UmsIntegrationConsumeSetting; import com.macro.mall.model.*;
import com.macro.mall.model.UmsMember; import com.macro.mall.portal.domain.*;
import com.macro.mall.model.UmsMemberReceiveAddress;
import com.macro.mall.portal.domain.CartPromotionItem;
import com.macro.mall.portal.domain.ConfirmOrderResult;
import com.macro.mall.portal.domain.SmsCouponHistoryDetail;
import com.macro.mall.portal.service.*; import com.macro.mall.portal.service.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -30,6 +27,8 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
private UmsMemberCouponService memberCouponService; private UmsMemberCouponService memberCouponService;
@Autowired @Autowired
private UmsIntegrationConsumeSettingMapper integrationConsumeSettingMapper; private UmsIntegrationConsumeSettingMapper integrationConsumeSettingMapper;
@Autowired
private PmsSkuStockMapper skuStockMapper;
@Override @Override
public ConfirmOrderResult generateConfirmOrder() { public ConfirmOrderResult generateConfirmOrder() {
ConfirmOrderResult result = new ConfirmOrderResult(); ConfirmOrderResult result = new ConfirmOrderResult();
@ -54,6 +53,50 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
return result; return result;
} }
@Override
public CommonResult generateOrder(OrderParam orderParam) {
//获取购物车及优惠信息
UmsMember currentMember = memberService.getCurrentMember();
List<CartPromotionItem> cartPromotionItemList = cartItemService.listPromotion(currentMember.getId());
//判断购物车中商品是否都有库存
if(!hasStock(cartPromotionItemList)){
return new CommonResult().failed("库存不足,无法下单");
}
//判断优惠券是否可用
//可用情况下分摊到可用商品中
//判断积分是否可用
//可用情况下分摊到可用商品中
//进行库存锁定
lockStock(cartPromotionItemList);
//计算运费
//根据商品合计运费活动优惠优惠券积分计算应付金额
//转化为订单信息并插入数据库
return null;
}
/**
* 锁定下单商品的所有库存
*/
private void lockStock(List<CartPromotionItem> cartPromotionItemList) {
for (CartPromotionItem cartPromotionItem : cartPromotionItemList) {
PmsSkuStock skuStock = skuStockMapper.selectByPrimaryKey(cartPromotionItem.getProductSkuId());
skuStock.setLockStock(skuStock.getStock()+cartPromotionItem.getQuantity());
skuStockMapper.updateByPrimaryKeySelective(skuStock);
}
}
/**
* 判断下单商品是否都有库存
*/
private boolean hasStock(List<CartPromotionItem> cartPromotionItemList) {
for (CartPromotionItem cartPromotionItem : cartPromotionItemList) {
if(cartPromotionItem.getRealStock()<=0){
return false;
}
}
return true;
}
/** /**
* 计算购物车中商品的价格 * 计算购物车中商品的价格
*/ */

View File

@ -45,8 +45,10 @@ public class OmsPromotionServiceImpl implements OmsPromotionService {
BeanUtils.copyProperties(item,cartPromotionItem); BeanUtils.copyProperties(item,cartPromotionItem);
cartPromotionItem.setPromotionMessage("单品促销"); cartPromotionItem.setPromotionMessage("单品促销");
//商品原价-促销价 //商品原价-促销价
BigDecimal originalPrice = getOriginalPrice(promotionProduct, item.getProductSkuId()); PmsSkuStock skuStock = getOriginalPrice(promotionProduct, item.getProductSkuId());
cartPromotionItem.setReduceAmount(originalPrice.subtract(getSinglePromotionPrice(promotionProduct, item.getProductSkuId()))); BigDecimal originalPrice = skuStock.getPrice();
cartPromotionItem.setReduceAmount(originalPrice.subtract(skuStock.getPromotionPrice()));
cartPromotionItem.setRealStock(skuStock.getStock()-skuStock.getLockStock());
cartPromotionItemList.add(cartPromotionItem); cartPromotionItemList.add(cartPromotionItem);
} }
} else if (promotionType == 3) { } else if (promotionType == 3) {
@ -60,13 +62,15 @@ public class OmsPromotionServiceImpl implements OmsPromotionService {
String message = getLadderPromotionMessage(ladder); String message = getLadderPromotionMessage(ladder);
cartPromotionItem.setPromotionMessage(message); cartPromotionItem.setPromotionMessage(message);
//商品原价-折扣金额*商品原价 //商品原价-折扣金额*商品原价
BigDecimal originalPrice = getOriginalPrice(promotionProduct, item.getProductSkuId()); PmsSkuStock skuStock = getOriginalPrice(promotionProduct,item.getProductSkuId());
BigDecimal originalPrice = skuStock.getPrice();
BigDecimal reduceAmount = originalPrice.subtract(ladder.getDiscount().multiply(originalPrice)); BigDecimal reduceAmount = originalPrice.subtract(ladder.getDiscount().multiply(originalPrice));
cartPromotionItem.setReduceAmount(reduceAmount); cartPromotionItem.setReduceAmount(reduceAmount);
cartPromotionItem.setRealStock(skuStock.getStock()-skuStock.getLockStock());
cartPromotionItemList.add(cartPromotionItem); cartPromotionItemList.add(cartPromotionItem);
} }
}else{ }else{
handleNoReduce(cartPromotionItemList,itemList); handleNoReduce(cartPromotionItemList,itemList,promotionProduct);
} }
} else if (promotionType == 4) { } else if (promotionType == 4) {
//满减 //满减
@ -79,17 +83,19 @@ public class OmsPromotionServiceImpl implements OmsPromotionService {
String message = getFullReductionPromotionMessage(fullReduction); String message = getFullReductionPromotionMessage(fullReduction);
cartPromotionItem.setPromotionMessage(message); cartPromotionItem.setPromotionMessage(message);
//(商品原价/总价)*满减金额 //(商品原价/总价)*满减金额
BigDecimal originalPrice = getOriginalPrice(promotionProduct, item.getProductSkuId()); PmsSkuStock skuStock= getOriginalPrice(promotionProduct, item.getProductSkuId());
BigDecimal originalPrice = skuStock.getPrice();
BigDecimal reduceAmount = originalPrice.divide(totalAmount,RoundingMode.HALF_EVEN).multiply(fullReduction.getReducePrice()); BigDecimal reduceAmount = originalPrice.divide(totalAmount,RoundingMode.HALF_EVEN).multiply(fullReduction.getReducePrice());
cartPromotionItem.setReduceAmount(reduceAmount); cartPromotionItem.setReduceAmount(reduceAmount);
cartPromotionItem.setRealStock(skuStock.getStock()-skuStock.getLockStock());
cartPromotionItemList.add(cartPromotionItem); cartPromotionItemList.add(cartPromotionItem);
} }
}else{ }else{
handleNoReduce(cartPromotionItemList,itemList); handleNoReduce(cartPromotionItemList,itemList,promotionProduct);
} }
} else { } else {
//无优惠 //无优惠
handleNoReduce(cartPromotionItemList, itemList); handleNoReduce(cartPromotionItemList, itemList,promotionProduct);
} }
} }
return cartPromotionItemList; return cartPromotionItemList;
@ -142,12 +148,14 @@ public class OmsPromotionServiceImpl implements OmsPromotionService {
/** /**
* 对没满足优惠条件的商品进行处理 * 对没满足优惠条件的商品进行处理
*/ */
private void handleNoReduce(List<CartPromotionItem> cartPromotionItemList, List<OmsCartItem> itemList) { private void handleNoReduce(List<CartPromotionItem> cartPromotionItemList, List<OmsCartItem> itemList,PromotionProduct promotionProduct) {
for (OmsCartItem item : itemList) { for (OmsCartItem item : itemList) {
CartPromotionItem cartPromotionItem = new CartPromotionItem(); CartPromotionItem cartPromotionItem = new CartPromotionItem();
BeanUtils.copyProperties(item,cartPromotionItem); BeanUtils.copyProperties(item,cartPromotionItem);
cartPromotionItem.setPromotionMessage("无优惠"); cartPromotionItem.setPromotionMessage("无优惠");
cartPromotionItem.setReduceAmount(new BigDecimal(0)); cartPromotionItem.setReduceAmount(new BigDecimal(0));
PmsSkuStock skuStock = getOriginalPrice(promotionProduct,item.getProductSkuId());
cartPromotionItem.setRealStock(skuStock.getStock()-skuStock.getLockStock());
cartPromotionItemList.add(cartPromotionItem); cartPromotionItemList.add(cartPromotionItem);
} }
} }
@ -221,31 +229,19 @@ public class OmsPromotionServiceImpl implements OmsPromotionService {
for (OmsCartItem item : itemList) { for (OmsCartItem item : itemList) {
//计算出商品原价 //计算出商品原价
PromotionProduct promotionProduct = getPromotionProductById(item.getProductId(), promotionProductList); PromotionProduct promotionProduct = getPromotionProductById(item.getProductId(), promotionProductList);
BigDecimal price = getOriginalPrice(promotionProduct,item.getProductSkuId()); PmsSkuStock skuStock = getOriginalPrice(promotionProduct,item.getProductSkuId());
amount = amount.add(price.multiply(new BigDecimal(item.getQuantity()))); amount = amount.add(skuStock.getPrice().multiply(new BigDecimal(item.getQuantity())));
} }
return amount; return amount;
} }
/**
* 获取商品的单品促销价格
*/
private BigDecimal getSinglePromotionPrice(PromotionProduct promotionProduct, Long productSkuId) {
for (PmsSkuStock skuStock : promotionProduct.getSkuStockList()) {
if (productSkuId.equals(skuStock.getId()) ) {
return skuStock.getPromotionPrice();
}
}
return null;
}
/** /**
* 获取商品的原价 * 获取商品的原价
*/ */
private BigDecimal getOriginalPrice(PromotionProduct promotionProduct, Long productSkuId) { private PmsSkuStock getOriginalPrice(PromotionProduct promotionProduct, Long productSkuId) {
for (PmsSkuStock skuStock : promotionProduct.getSkuStockList()) { for (PmsSkuStock skuStock : promotionProduct.getSkuStockList()) {
if (productSkuId.equals(skuStock.getId())) { if (productSkuId.equals(skuStock.getId())) {
return skuStock.getPrice(); return skuStock;
} }
} }
return null; return null;