feat: 霸王餐优惠券使用
This commit is contained in:
@@ -83,5 +83,40 @@ public interface TableConstant {
|
||||
}
|
||||
}
|
||||
|
||||
class ActivateOutRecord {
|
||||
@Getter
|
||||
public enum Type {
|
||||
// 满减
|
||||
FULL_REDUCTION(1),
|
||||
// 商品
|
||||
PRODUCT(2);
|
||||
private final Integer value;
|
||||
|
||||
Type(Integer value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public boolean equalsVals(Integer value) {
|
||||
return Objects.equals(this.value, value);
|
||||
}
|
||||
}
|
||||
@Getter
|
||||
public enum Status {
|
||||
CREATE("create"),
|
||||
CANCEL("cancel"),
|
||||
// 商品
|
||||
CLOSED("closed");
|
||||
private final String value;
|
||||
|
||||
Status(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public boolean equalsVals(String value) {
|
||||
return this.value.equals(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -126,8 +126,9 @@ public class TbOrderInfo implements Serializable {
|
||||
private BigDecimal seatAmount;
|
||||
private BigDecimal pointsDiscountAmount;
|
||||
private Integer pointsNum;
|
||||
private String couponIdList;
|
||||
private BigDecimal couponDiscountAmount;
|
||||
// 用户优惠券id
|
||||
private String activateInInfoList;
|
||||
private BigDecimal activateInDiscountAmount;
|
||||
|
||||
|
||||
//根据状态返回 需付款 已付款 未付款 已退
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user