Commit 787e98b0 by wuwenlong

pack activity dev;

parent fdf6859e
package share.common.enums;
import share.common.utils.StringUtils;
/**
* @Author wwl
* @Date 2023/10/20 10:57
*/
public enum BuyTypeEnum {
TIME(1,"time","小时模式"),
PACK(2,"pack","套餐模式");
private Integer code;
private String value;
private String name;
BuyTypeEnum(Integer code, String value, String name) {
this.code = code;
this.value = value;
this.name = name;
}
public static BuyTypeEnum getEnumByCode(Integer code){
for (BuyTypeEnum type : BuyTypeEnum.values()) {
if (type.code.compareTo(code)==0) {
return type;
}
}
return null;
}
public static BuyTypeEnum getEnumByValue(String value){
if(StringUtils.isNotBlank(value)) {
for (BuyTypeEnum type : BuyTypeEnum.values()) {
if (StringUtils.equals(type.value, value)) {
return type;
}
}
}
return null;
}
public Integer getCode(){
return code;
}
public String getValue() {
return value;
}
public String getName() {
return name;
}
}
......@@ -71,7 +71,7 @@ public class OrderPayServiceImpl implements OrderPayService {
sOrder.setOutTradeNo(unifiedorder.get("outTradeNo"));
orderService.updateById(sOrder);
response.setJsConfig(vo);
return null;
return response;
}
......
......@@ -4,23 +4,16 @@ import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import share.common.constant.Constants;
import share.common.constant.PayConstants;
import share.common.core.redis.RedisUtil;
import share.common.enums.*;
import share.common.exception.base.BaseException;
......@@ -30,15 +23,10 @@ import share.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import share.common.utils.bean.BeanUtils;
import share.system.domain.SConsumer;
import share.system.domain.SConsumerCoupon;
import share.system.domain.SRoom;
import share.system.domain.*;
import share.system.domain.vo.FrontTokenComponent;
import share.system.domain.vo.MyRecord;
import share.system.domain.vo.SRoomVo;
import share.system.domain.vo.WxPayJsResultVo;
import share.system.mapper.SOrderMapper;
import share.system.domain.SOrder;
import share.system.request.CreateOrderRequest;
import share.system.request.OrderComputedPriceRequest;
import share.system.request.OrderRefundRequest;
......@@ -78,6 +66,9 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper,SOrder> implemen
private OrderPayService orderPayService;
@Autowired
private IPackService packService;
@Autowired
private RedisUtil redisUtil;
/**
......@@ -187,7 +178,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper,SOrder> implemen
sOrder.setPayStatus(YesNoEnum.yes.getIndex());
}else {
response = orderPayService.payment(sOrder);
// 加入自动未支付自动取消队列 TODO 自动取消定时任务待开发
// 加入自动未支付自动取消队列
redisUtil.lPush(Constants.ORDER_AUTO_CANCEL_KEY, sOrder.getOrderNo());
}
save(sOrder);
......@@ -414,7 +405,18 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper,SOrder> implemen
// 计算各种价格
ComputedOrderPriceResponse priceResponse = new ComputedOrderPriceResponse();
SRoom room = roomService.getById(request.getRoomId());
BigDecimal totalPrice = computeTotalPrice(room.getPrice(),request.getPreStartDate(),request.getPreEndDate());
BigDecimal totalPrice;
BuyTypeEnum buyTypeEnum = BuyTypeEnum.getEnumByCode(request.getBuyType());
switch (buyTypeEnum){
case TIME://小时模式
totalPrice = computeTotalPrice(room.getPrice(), request.getPreStartDate(), request.getPreEndDate());
break;
case PACK://套餐模式
totalPrice = computeTotalPrice(request.getPackId());
break;
default:
throw new BaseException("购买方式类型异常!");
}
priceResponse.setTotalFee(totalPrice);
// 计算优惠券金额
if (ObjectUtil.isNull(request.getCouponId()) || request.getCouponId() <= 0) {
......@@ -428,6 +430,14 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper,SOrder> implemen
return priceResponse;
}
private BigDecimal computeTotalPrice(Long packId) {
SPack pack = packService.getById(packId);
if(Objects.isNull(pack)){
throw new BaseException("计算订单金额套餐ID异常!");
}
return pack.getPrice();
}
/**
* 计算使用优惠券后的订单金额
*/
......@@ -450,6 +460,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper,SOrder> implemen
switch (couponType){
case DISCOUNT://TODO 折扣券
break;
case PACKAGE://套餐券
case CASH://现金券
//判断优惠券最小使用金额
if (consumerCoupon.getMinPrice().compareTo(priceResponse.getTotalFee()) > 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment