feat: 霸王餐优惠券使用

This commit is contained in:
2024-10-29 10:16:40 +08:00
parent ea025bd023
commit 2c27e96d92
3 changed files with 69 additions and 7 deletions

View File

@@ -16,6 +16,7 @@ import com.chaozhanggui.system.cashierservice.entity.dto.MemberInDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.OrderPayDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.ReturnGroupOrderDto;
import com.chaozhanggui.system.cashierservice.entity.dto.ShopEatTypeInfoDTO;
import com.chaozhanggui.system.cashierservice.entity.vo.ActivateInInfoVO;
import com.chaozhanggui.system.cashierservice.entity.vo.ShopUserListVo;
import com.chaozhanggui.system.cashierservice.entity.vo.TbUserCouponVo;
import com.chaozhanggui.system.cashierservice.exception.MsgException;
@@ -57,6 +58,7 @@ import java.math.RoundingMode;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
@Service
@Slf4j
@@ -415,22 +417,26 @@ public class PayService {
throw new MsgException("存在不可用优惠券");
}
ArrayList<Integer> couponIdList = new ArrayList<>();
ArrayList<ActivateInInfoVO> activateInInfoVOS = new ArrayList<>();
for (Integer couponId : payDTO.getCouponIds()) {
TbUserCouponVo userCouponVo = userCouponList.stream().filter(item -> item.getCouponId().equals(couponId)).findFirst().orElse(null);
if (userCouponVo == null) {
throw new MsgException("存在不可用优惠券");
}
couponIdList.add(userCouponVo.getCouponId());
ActivateInInfoVO activateInInfoVO = new ActivateInInfoVO()
.setId(userCouponVo.getId())
.setCouponId(userCouponVo.getCouponId())
.setNum(1);
activateInInfoVOS.add(activateInInfoVO);
}
List<TbShopCoupon> tbShopCoupons = mpShopCouponMapper.selectBatchIds(couponIdList);
List<TbShopCoupon> tbShopCoupons = mpShopCouponMapper.selectBatchIds(activateInInfoVOS.stream().map(ActivateInInfoVO::getCouponId).collect(Collectors.toList()));
if (tbShopCoupons.size() != payDTO.getCouponIds().size()) {
throw new MsgException("存在不可用优惠券");
}
// 设置优惠券信息
orderInfo.setCouponIdList(JSONObject.toJSONString(couponIdList));
orderInfo.setActivateInInfoList(JSONObject.toJSONString(activateInInfoVOS));
orderInfo.setUserCouponAmount(BigDecimal.valueOf(tbShopCoupons.stream().map(TbShopCoupon::getDiscountAmount).reduce(0, Integer::sum)));
}
@@ -1038,7 +1044,6 @@ public class PayService {
}
memberIn.setAmount(payAmount);
memberIn.setUserId(Integer.valueOf(tbShopUser.getUserId()));
memberIn.setCode(tbShopUser.getCode());
@@ -1530,11 +1535,32 @@ public class PayService {
if (TableConstant.OrderInfo.Status.CLOSED.getValue().equals(orderInfo.getStatus())) {
log.error("订单状态异常: {}", orderInfo);
}
Integer shopId = Integer.valueOf(orderInfo.getShopId());
// 销毁使用的优惠券
if (StrUtil.isNotBlank(orderInfo.getActivateInInfoList())) {
ArrayList<TbActivateOutRecord> activateOutRecords = new ArrayList<>();
JSONArray activateInfoList = JSONObject.parseArray(orderInfo.getActivateInInfoList());
activateInfoList.forEach(item -> {
ActivateInInfoVO infoVO = (ActivateInInfoVO) item;
TbActivateOutRecord tbActivateOutRecord = new TbActivateOutRecord();
tbActivateOutRecord.setShopId(shopId);
tbActivateOutRecord.setGiveId(infoVO.getId());
tbActivateOutRecord.setVipUserId(Integer.valueOf(orderInfo.getUserId()));
tbActivateOutRecord.setType(TableConstant.ActivateOutRecord.Type.FULL_REDUCTION.getValue());
tbActivateOutRecord.setUseNum(infoVO.getNum());
tbActivateOutRecord.setStatus(TableConstant.ActivateOutRecord.Status.CLOSED.getValue());
tbActivateOutRecord.setCreateTime(DateUtil.date());
activateOutRecords.add(tbActivateOutRecord);
});
shopCouponService.use(shopId, orderInfo.getId(), Integer.valueOf(orderInfo.getUserId()), activateOutRecords);
}
// 更改订单状态
orderSuccessPay(orderInfo, payType, payOrderNo);
}
}
public String fstMemberInSuccess(String payOrderNO, String tradeNo, String payType) {
TbMemberIn memberIn = tbMemberInMapper.selectByOrderNo(payOrderNO);
if (ObjectUtil.isEmpty(memberIn)) {