提交 1d77c6b5 作者: zhenjie

订单优化、购物车缺陷修复

上级 71c0169a
......@@ -23,4 +23,6 @@ public interface UavCartDao {
List<Integer> countList(Integer userAccountId);
List<UavCartCompanyDO> list(Integer begin, Integer pageSize, Integer userAccountId);
UavCartDO countMallGoodsSku(UavCartDO uavCartDO);
}
......@@ -41,6 +41,13 @@ public class UavCartServiceImpl implements UavCartService {
@Override
public ResultBody addCart(UavCartVO uavCartVO) {
UavCartDO uavCartDO = new UavCartDO(uavCartVO);
// 查询购物车中是否有一样的商品规格,有则数量+1,无则直接添加数据。
UavCartDO uavCartDO1 = uavCartDao.countMallGoodsSku(uavCartDO);
if (uavCartDO1 != null) {
uavCartDO1.setOrderNum(uavCartDO1.getOrderNum() + 1);
uavCartDao.updateUavCart(uavCartDO1);
return ResultBody.success();
}
uavCartDao.addCart(uavCartDO);
return ResultBody.success();
}
......
......@@ -93,32 +93,11 @@ public class UavOrderServiceImpl implements UavOrderService {
if (CollectionUtils.isEmpty(param.getSkuVOS())){
return ResultBody.error("至少选择一个规格!");
}
MallGoodsVO mallGoodsVO = null;
try {
mallGoodsVO = pmsClient.mallGoodsDetails(param.getMallGoodsId());
// 检验商品是否在卖
if (mallGoodsVO == null || !mallGoodsVO.getShelfStatus().equals(1)){
return ResultBody.error("商品已下架");
}
// 找到对应的规格
for (UavOrderSkuVO skuVO : param.getSkuVOS()) {
Boolean flag = false;
for (PriceStockVO priceStockVO : mallGoodsVO.getPriceStock()) {
if (skuVO.getProductSpec().equals(priceStockVO.getProductSpec())) {
// 获取最新的规格单价
skuVO.setUnitPrice(priceStockVO.getSalePrice());
flag = true;
break;
}
}
if (!flag){
return ResultBody.error("选择规格不存在");
}
}
}catch (Exception e){
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
e.printStackTrace();
ResultBody<MallGoodsVO> checkRes = this.verifyMallGoods(param);
if (!checkRes.getCode().equals(ResultEnum.SUCCESS.getResultCode())) {
return checkRes;
}
MallGoodsVO mallGoodsVO = checkRes.getResult();
String orderNo = CodeUtil.uavOrderCode();
BigDecimal orderTotalAmount = BigDecimal.ZERO;
BigDecimal otherAmount = BigDecimal.ZERO;
......@@ -214,6 +193,36 @@ public class UavOrderServiceImpl implements UavOrderService {
return ResultBody.success(uavOrderDO.buildUavOrderDTO());
}
private ResultBody<MallGoodsVO> verifyMallGoods(AddUavOrderVO param) {
MallGoodsVO mallGoodsVO = null;
try {
mallGoodsVO = pmsClient.mallGoodsDetails(param.getMallGoodsId());
// 检验商品是否在卖
if (mallGoodsVO == null || !mallGoodsVO.getShelfStatus().equals(1)){
return ResultBody.error("商品已下架");
}
// 找到对应的规格
for (UavOrderSkuVO skuVO : param.getSkuVOS()) {
Boolean flag = false;
for (PriceStockVO priceStockVO : mallGoodsVO.getPriceStock()) {
if (skuVO.getProductSpec().equals(priceStockVO.getProductSpec())) {
// 获取最新的规格单价
skuVO.setUnitPrice(priceStockVO.getSalePrice());
flag = true;
break;
}
}
if (!flag){
return ResultBody.error("选择规格不存在");
}
}
}catch (Exception e){
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
e.printStackTrace();
}
return ResultBody.success(mallGoodsVO);
}
@Override
public ResultBody detail(Integer id, BaseAccountDTO baseAccountDTO) throws Exception {
UavOrderDO uavOrderDO = uavOrderDao.detail(id);
......
......@@ -79,4 +79,11 @@
group by third_back_user_account_id
limit #{begin}, #{pageSize}
</select>
<select id="countMallGoodsSku" resultType="com.mmc.oms.entity.uav.UavCartDO" parameterType="com.mmc.oms.entity.uav.UavCartDO">
select <include refid="cart_column"/>
from uav_cart
where third_back_user_account_id = #{thirdBackUserAccountId} and user_account_id = #{userAccountId} and is_deleted = 0
and mall_goods_id = #{mallGoodsId} and product_spec = #{productSpec}
</select>
</mapper>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论