|
|
@@ -1,6 +1,5 @@
|
|
|
package com.gree.mall.miniapp.logic.order;
|
|
|
|
|
|
-import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
@@ -15,7 +14,8 @@ import com.gree.mall.miniapp.bean.goods.GoodsMaterialStockDTO;
|
|
|
import com.gree.mall.miniapp.bean.order.*;
|
|
|
import com.gree.mall.miniapp.bean.user.CurrentCompanyWechat;
|
|
|
import com.gree.mall.miniapp.bean.workorder.PgOrderSettleNormBean;
|
|
|
-import com.gree.mall.miniapp.commonmapper.*;
|
|
|
+import com.gree.mall.miniapp.commonmapper.AppMapper;
|
|
|
+import com.gree.mall.miniapp.commonmapper.CategoryMapper;
|
|
|
import com.gree.mall.miniapp.constant.Constant;
|
|
|
import com.gree.mall.miniapp.enums.*;
|
|
|
import com.gree.mall.miniapp.enums.base.BaseEnum;
|
|
|
@@ -162,6 +162,10 @@ public class OrderLogic {
|
|
|
UserCompanyCreditLogic userCompanyCreditLogic;
|
|
|
@Resource
|
|
|
NoticeLogic noticeLogic;
|
|
|
+ @Resource
|
|
|
+ UserLevelRelaService userLevelRelaService;
|
|
|
+ @Resource
|
|
|
+ UserLevelGoodsService userLevelGoodsService;
|
|
|
|
|
|
/**
|
|
|
* 立即购买
|
|
|
@@ -286,6 +290,14 @@ public class OrderLogic {
|
|
|
OrderDetail orderDetail = new OrderDetail();
|
|
|
|
|
|
orderDetail.setPayAmount(goodsSecPrice.multiply(new BigDecimal(buyGood.getNum())));
|
|
|
+ orderDetail.setTotalPrice(goodsSecPrice.multiply(new BigDecimal(buyGood.getNum())));
|
|
|
+
|
|
|
+ // 如果会员等级商品规格价格大于0
|
|
|
+ if (StringUtils.isNotBlank(buyGood.getUseUserLevelGoodsId())
|
|
|
+ && buyGood.getGoodsSpecNewPrice().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ orderDetail.setPayAmount(buyGood.getGoodsSpecNewPrice().multiply(new BigDecimal(buyGood.getNum())));
|
|
|
+ orderDetail.setTotalPrice(buyGood.getGoodsSpecNewPrice().multiply(new BigDecimal(buyGood.getNum())));
|
|
|
+ }
|
|
|
|
|
|
orderDetail.setOrderId(orderId);
|
|
|
orderDetail.setGoodsId(goodsId);
|
|
|
@@ -308,7 +320,6 @@ public class OrderLogic {
|
|
|
}
|
|
|
orderDetail.setPrice(goodsSecPrice);
|
|
|
orderDetail.setNum(buyGood.getNum());
|
|
|
- orderDetail.setTotalPrice(goodsSecPrice.multiply(new BigDecimal(buyGood.getNum())));
|
|
|
orderDetail.setImgUrl(goodsSpec.getImgUrl());
|
|
|
orderDetail.setCreateTime(curDate);
|
|
|
orderDetail.setIsVr(goods.getIsVr());
|
|
|
@@ -329,13 +340,28 @@ public class OrderLogic {
|
|
|
orderDetail.setSmallNumber(goodsSpec.getSmallId());
|
|
|
orderDetail.setSmallName(goodsSpec.getSmallName());
|
|
|
orderDetail.setFlag(1);
|
|
|
+ orderDetail.setUseUserLevelGoodsId(buyGood.getUseUserLevelGoodsId());
|
|
|
+ orderDetail.setGoodsSpecNewPrice(buyGood.getGoodsSpecNewPrice());
|
|
|
+ orderDetail.setGoodsSpecNewFirstFee(buyGood.getGoodsSpecNewFirstFee());
|
|
|
+ orderDetail.setGoodsSpecNewContinueFee(buyGood.getGoodsSpecNewContinueFee());
|
|
|
|
|
|
// BigDecimal freightAmountItem = Objects.nonNull(userAddress) ? this.getFreightAmountItem(userAddress.getProvince(), userAddress.getCity(), userAddress.getArea(), buyGood, currentCompanyWechat) : BigDecimal.valueOf(0);
|
|
|
BigDecimal freightAmountItem = orderInfo.getTakeGoodsType().equals(TakeGoodsTypeEnum.Z.getKey()) ? BigDecimal.valueOf(0) : goodsSpec.getFirstFee();
|
|
|
+ // 如果有会员等级首件运费
|
|
|
+ if (StringUtils.isNotBlank(orderDetail.getUseUserLevelGoodsId())
|
|
|
+ && orderDetail.getGoodsSpecNewFirstFee().compareTo(BigDecimal.ZERO) >= 0) {
|
|
|
+ freightAmountItem = orderDetail.getGoodsSpecNewFirstFee();
|
|
|
+ }
|
|
|
// 邮寄方式计算次件运费金额
|
|
|
if (orderInfo.getTakeGoodsType().equals(TakeGoodsTypeEnum.Y.getKey()) && orderDetail.getNum() > 1) {
|
|
|
int surplusNum = orderDetail.getNum() - 1;
|
|
|
- BigDecimal continueAmountItem = new BigDecimal(surplusNum).multiply(goodsSpec.getContinueFee());
|
|
|
+ BigDecimal continueFee = goodsSpec.getContinueFee();
|
|
|
+ // 如果有会员等级续件运费
|
|
|
+ if (StringUtils.isNotBlank(orderDetail.getUseUserLevelGoodsId())
|
|
|
+ && orderDetail.getGoodsSpecNewContinueFee().compareTo(BigDecimal.ZERO) >= 0) {
|
|
|
+ continueFee = orderDetail.getGoodsSpecNewContinueFee();
|
|
|
+ }
|
|
|
+ BigDecimal continueAmountItem = new BigDecimal(surplusNum).multiply(continueFee);
|
|
|
freightAmountItem = freightAmountItem.add(continueAmountItem);
|
|
|
}
|
|
|
orderDetail.setFreight(freightAmountItem);
|
|
|
@@ -1019,10 +1045,10 @@ public class OrderLogic {
|
|
|
* 确认订单内容
|
|
|
*/
|
|
|
public OrderAckBean ackOrder2(OrderBuyBean orderBuyBean, HttpServletRequest request) throws RemoteServiceException, InterruptedException {
|
|
|
-
|
|
|
//购买人
|
|
|
String userId = CommonUtils.getUserId(request);
|
|
|
User user = userService.getById(userId);
|
|
|
+
|
|
|
//总的商品金额
|
|
|
BigDecimal totalAmount = new BigDecimal(0);
|
|
|
//总的商品数量
|
|
|
@@ -1066,12 +1092,28 @@ public class OrderLogic {
|
|
|
ackGoodsBean.setOrgPrice(goods.getOrgGoodsPrice());
|
|
|
ackGoodsBean.setSecKillId(buyGood.getSecKillId());
|
|
|
ackGoodsBean.setPromotionGroupId(buyGood.getPromotionGroupId());
|
|
|
+ ackGoodsBean.setUseUserLevelGoodsId(buyGood.getUseUserLevelGoodsId());
|
|
|
+ ackGoodsBean.setGoodsSpecNewPrice(buyGood.getGoodsSpecNewPrice());
|
|
|
+ ackGoodsBean.setGoodsSpecNewFirstFee(buyGood.getGoodsSpecNewFirstFee());
|
|
|
+ ackGoodsBean.setGoodsSpecNewContinueFee(buyGood.getGoodsSpecNewContinueFee());
|
|
|
|
|
|
BigDecimal freightAmountItem = goodsSpec.getFirstFee();
|
|
|
+ // 如果有会员等级首件运费
|
|
|
+ if (StringUtils.isNotBlank(ackGoodsBean.getUseUserLevelGoodsId())
|
|
|
+ && ackGoodsBean.getGoodsSpecNewFirstFee().compareTo(BigDecimal.ZERO) >= 0) {
|
|
|
+ freightAmountItem = ackGoodsBean.getGoodsSpecNewFirstFee();
|
|
|
+ }
|
|
|
// 邮寄方式计算次件运费金额
|
|
|
if (buyGood.getNum() > 1) {
|
|
|
int surplusNum = buyGood.getNum() - 1;
|
|
|
- BigDecimal continueAmountItem = new BigDecimal(surplusNum).multiply(goodsSpec.getContinueFee());
|
|
|
+ BigDecimal continueFee = goodsSpec.getContinueFee();
|
|
|
+ // 如果有会员等级续件运费
|
|
|
+ if (StringUtils.isNotBlank(ackGoodsBean.getUseUserLevelGoodsId())
|
|
|
+ && ackGoodsBean.getGoodsSpecNewContinueFee().compareTo(BigDecimal.ZERO) >= 0) {
|
|
|
+ continueFee = ackGoodsBean.getGoodsSpecNewContinueFee();
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal continueAmountItem = new BigDecimal(surplusNum).multiply(continueFee);
|
|
|
freightAmountItem = freightAmountItem.add(continueAmountItem);
|
|
|
}
|
|
|
totalFreight = totalFreight.add(freightAmountItem);
|
|
|
@@ -1114,9 +1156,28 @@ public class OrderLogic {
|
|
|
* @param user
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<BuyGood> supplyBuyBoods(OrderBuyBean orderBuyBean,User user) throws InterruptedException {
|
|
|
+ public List<BuyGood> supplyBuyBoods(OrderBuyBean orderBuyBean,User user) {
|
|
|
+ final CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat();
|
|
|
List<BuyGood> buyGoods = orderBuyBean.getBuyGoods();
|
|
|
|
|
|
+ // 检查是否有会员等级
|
|
|
+ final UserLevelRela userLevelRela = userLevelRelaService.lambdaQuery()
|
|
|
+ .eq(UserLevelRela::getCompanyWechatId, currentCompanyWechat.getCurrentCompanyWechatId())
|
|
|
+ .eq(UserLevelRela::getUserId, user.getUserId())
|
|
|
+ .one();
|
|
|
+
|
|
|
+ // 获取会员等级商品规格
|
|
|
+ Map<String, UserLevelGoods> userLevelGoodsMap = null;
|
|
|
+ if (Objects.nonNull(userLevelRela)) {
|
|
|
+ List<UserLevelGoods> userLevelGoodsList = userLevelGoodsService.lambdaQuery()
|
|
|
+ .eq(UserLevelGoods::getUserLevelId, userLevelRela.getUserLevelId())
|
|
|
+ .list();
|
|
|
+ if (CollectionUtil.isNotEmpty(userLevelGoodsList)) {
|
|
|
+ userLevelGoodsMap = userLevelGoodsList.stream()
|
|
|
+ .collect(Collectors.toMap(v -> v.getGoodsId() + v.getGoodsSpecId() + v.getGoodsSpecCode(), Function.identity()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
for(BuyGood buyGood : buyGoods){
|
|
|
Goods goods = goodsLogic.getGoodsById(buyGood.getGoodsId());
|
|
|
final GoodsDetail goodsDetail = goodsLogic.getGoodsDetailById(buyGood.getGoodsId());
|
|
|
@@ -1124,6 +1185,7 @@ public class OrderLogic {
|
|
|
if (goods == null || goodsSpec == null) {
|
|
|
throw new RemoteServiceException("商品不存在,请重新添加");
|
|
|
}
|
|
|
+
|
|
|
GoodsBean goodsBean = new GoodsBean();
|
|
|
BeanUtils.copyProperties(goods, goodsBean);
|
|
|
goodsBean.setImgUrl(goodsDetail.getImgUrl());
|
|
|
@@ -1134,12 +1196,25 @@ public class OrderLogic {
|
|
|
buyGood.setGoodsSpec(goodsSpec);
|
|
|
buyGood.setOrgPrice(goodsSpec.getOrgPrice());
|
|
|
buyGood.setPrice(goodsSpec.getPrice());
|
|
|
+ // 检查是否有会员等级商品规格
|
|
|
+ if (CollectionUtil.isNotEmpty(userLevelGoodsMap)
|
|
|
+ && userLevelGoodsMap.containsKey(goods.getGoodsId() + goodsSpec.getGoodsSpecId() + goodsSpec.getGoodsCode())) {
|
|
|
+ final UserLevelGoods userLevelGoods = userLevelGoodsMap.get(goods.getGoodsId() + goodsSpec.getGoodsSpecId() + goodsSpec.getGoodsCode());
|
|
|
+ buyGood.setGoodsSpecNewPrice(userLevelGoods.getGoodsSpecNewPrice());
|
|
|
+ buyGood.setGoodsSpecNewFirstFee(userLevelGoods.getGoodsSpecNewFirstFee());
|
|
|
+ buyGood.setGoodsSpecNewContinueFee(userLevelGoods.getGoodsSpecNewContinueFee());
|
|
|
+ buyGood.setUseUserLevelGoodsId(userLevelGoods.getUserLevelId());
|
|
|
+ }
|
|
|
}
|
|
|
return buyGoods;
|
|
|
}
|
|
|
|
|
|
//获取商品小计金额
|
|
|
private BigDecimal getChildTotalPrice(AckGoodsBean ackGoodsBean){
|
|
|
+ if (StringUtils.isNotBlank(ackGoodsBean.getUseUserLevelGoodsId())
|
|
|
+ && ackGoodsBean.getGoodsSpecNewPrice().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ return ackGoodsBean.getGoodsSpecNewPrice().multiply(new BigDecimal(ackGoodsBean.getNum()));
|
|
|
+ }
|
|
|
return ackGoodsBean.getPrice().multiply(new BigDecimal(ackGoodsBean.getNum()));
|
|
|
}
|
|
|
|