Commit 464a76a2 by wuwenlong

computer order price service dev;

parent 50b2df96
package share.common.enums;
/**
* @Author wwl
* @Date 2023/10/19 16:13
*/
public enum CouponStatusEnum {
NORMAL(0,"正常"),
USED(1,"已使用"),
EXPIRED(2,"已过期");
private Integer value;
private String name;
CouponStatusEnum(Integer value, String name) {
this.value = value;
this.name = name;
}
public Integer getValue() {
return value;
}
public String getName() {
return name;
}
}
package share.common.enums;
import java.util.ArrayList;
import java.util.List;
/**
* @Author wwl
* @Date 2023/10/19 17:06
*/
public enum CouponTypeEnum {
DISCOUNT(1,"1","折扣券"),
CASH(2,"2","满减券(现金券)"),
DURATION(3,"3","时长券");
private Integer code;
private String value;
private String name;
CouponTypeEnum(Integer code, String value, String name) {
this.code = code;
this.value = value;
this.name = name;
}
public Integer getCode(){
return code;
}
public String getValue() {
return value;
}
public String getName() {
return name;
}
public static CouponTypeEnum getType(String value){
for (CouponTypeEnum type : CouponTypeEnum.values()) {
if (type.getValue().equals(value)) {
return type;
}
}
return null;
}
}
package share.common.utils; package share.common.utils;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.LocalDate; import java.time.LocalDate;
...@@ -148,6 +150,14 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils ...@@ -148,6 +150,14 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
} }
/** /**
* 计算相差小时(保留一位小数)
*/
public static BigDecimal differentHour(Date beforeDate, Date afterDate)
{
return BigDecimal.valueOf((afterDate.getTime() - beforeDate.getTime())).divide(BigDecimal.valueOf(1000 * 3600),1,BigDecimal.ROUND_HALF_UP);
}
/**
* 计算时间差 * 计算时间差
* *
* @param endDate 最后时间 * @param endDate 最后时间
...@@ -191,4 +201,9 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils ...@@ -191,4 +201,9 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
ZonedDateTime zdt = localDateTime.atZone(ZoneId.systemDefault()); ZonedDateTime zdt = localDateTime.atZone(ZoneId.systemDefault());
return Date.from(zdt.toInstant()); return Date.from(zdt.toInstant());
} }
public static void main(String[] args) {
Date now = new Date();
System.out.println(differentHour(DateUtils.parseDate("2023-10-19 16:40"),now));
}
} }
package share.web.controller.system; package share.web.controller.system;
import java.util.List; import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import share.common.annotation.Log;
import share.common.core.controller.BaseController; import share.common.core.controller.BaseController;
import share.common.core.domain.AjaxResult; import share.common.core.domain.AjaxResult;
import share.common.enums.BusinessType; import share.common.core.domain.R;
import share.common.core.redis.RedisUtil;
import share.common.utils.JsonConvertUtil;
import share.system.domain.SOrder; import share.system.domain.SOrder;
import share.system.domain.vo.MyRecord;
import share.system.request.CreateOrderRequest;
import share.system.request.OrderComputedPriceRequest;
import share.system.response.ComputedOrderPriceResponse;
import share.system.service.ISOrderService; import share.system.service.ISOrderService;
import share.common.utils.poi.ExcelUtil;
import share.common.core.page.TableDataInfo; import share.common.core.page.TableDataInfo;
/** /**
...@@ -27,17 +26,20 @@ import share.common.core.page.TableDataInfo; ...@@ -27,17 +26,20 @@ import share.common.core.page.TableDataInfo;
* @author ruoyi * @author ruoyi
* @date 2023-10-09 * @date 2023-10-09
*/ */
@Slf4j
@RestController @RestController
@RequestMapping("/system/order") @RequestMapping("/front/order")
public class SOrderController extends BaseController public class SOrderController extends BaseController
{ {
@Autowired @Autowired
private ISOrderService sOrderService; private ISOrderService sOrderService;
@Autowired
private RedisUtil redisUtil;
/** /**
* 查询订单列表 * 查询订单列表
*/ */
@PreAuthorize("@ss.hasPermi('system:order:list')")
@GetMapping("/list") @GetMapping("/list")
public TableDataInfo list(SOrder sOrder) public TableDataInfo list(SOrder sOrder)
{ {
...@@ -46,23 +48,10 @@ public class SOrderController extends BaseController ...@@ -46,23 +48,10 @@ public class SOrderController extends BaseController
return getDataTable(list); return getDataTable(list);
} }
/**
* 导出订单列表
*/
@PreAuthorize("@ss.hasPermi('system:order:export')")
@Log(title = "订单", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, SOrder sOrder)
{
List<SOrder> list = sOrderService.selectSOrderList(sOrder);
ExcelUtil<SOrder> util = new ExcelUtil<SOrder>(SOrder.class);
util.exportExcel(response, list, "订单数据");
}
/** /**
* 获取订单详细信息 * 获取订单详细信息
*/ */
@PreAuthorize("@ss.hasPermi('system:order:query')")
@GetMapping(value = "/{id}") @GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id) public AjaxResult getInfo(@PathVariable("id") Long id)
{ {
...@@ -70,35 +59,31 @@ public class SOrderController extends BaseController ...@@ -70,35 +59,31 @@ public class SOrderController extends BaseController
} }
/** /**
* 新增订 *
*/ */
@PreAuthorize("@ss.hasPermi('system:order:add')") @ApiOperation(value = "下单")
@Log(title = "订单", businessType = BusinessType.INSERT) @RequestMapping(value = "/creat", method = RequestMethod.POST)
@PostMapping public R<MyRecord> createOrder(@RequestBody @Validated CreateOrderRequest request) {
public AjaxResult add(@RequestBody SOrder sOrder) if("1".equals(redisUtil.frontInOutLogSwitch())) {
{ log.info("SOrderController method preOrder 入参 {}", JsonConvertUtil.write2JsonStr(request));
return toAjax(sOrderService.insertSOrder(sOrder)); }
MyRecord record = sOrderService.createOrder(request);
if("1".equals(redisUtil.frontInOutLogSwitch())) {
log.info("SOrderController method preOrder 出参 {}", JsonConvertUtil.write2JsonStr(record));
}
return R.ok(record);
} }
/**
* 修改订单
*/
@PreAuthorize("@ss.hasPermi('system:order:edit')")
@Log(title = "订单", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody SOrder sOrder)
{
return toAjax(sOrderService.updateSOrder(sOrder));
}
/** /**
* 删除订单 * 根据参数计算订单价格
*/ */
@PreAuthorize("@ss.hasPermi('system:order:remove')") @ApiOperation(value = "计算订单价格")
@Log(title = "订单", businessType = BusinessType.DELETE) @RequestMapping(value = "/computed/price", method = RequestMethod.POST)
@DeleteMapping("/{ids}") public R<ComputedOrderPriceResponse> computedPrice(@Validated @RequestBody OrderComputedPriceRequest request) {
public AjaxResult remove(@PathVariable Long[] ids) log.info("StoreOrderController method computedPrice 入参 {}", JsonConvertUtil.write2JsonStr(request));
{ ComputedOrderPriceResponse response = sOrderService.computedOrderPrice(request);
return toAjax(sOrderService.deleteSOrderByIds(ids)); log.info("StoreOrderController method computedPrice 出参 {}", JsonConvertUtil.write2JsonStr(response));
return R.ok(response);
} }
} }
...@@ -102,34 +102,4 @@ public class SConsumerCoupon extends BaseEntity ...@@ -102,34 +102,4 @@ public class SConsumerCoupon extends BaseEntity
@Excel(name = "更新时间", width = 30, dateFormat = "yyyy-MM-dd") @Excel(name = "更新时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date deleteTime; private Date deleteTime;
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("consumerId", getConsumerId())
.append("couponId", getCouponId())
.append("couponCode", getCouponCode())
.append("name", getName())
.append("couponType", getCouponType())
.append("maxDuration", getMaxDuration())
.append("duration", getDuration())
.append("minPrice", getMinPrice())
.append("subPrice", getSubPrice())
.append("sourceType", getSourceType())
.append("platformType", getPlatformType())
.append("startDate", getStartDate())
.append("endDate", getEndDate())
.append("useDate", getUseDate())
.append("useStatus", getUseStatus())
.append("isDelete", getIsDelete())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("deleteBy", getDeleteBy())
.append("deleteTime", getDeleteTime())
.append("remark", getRemark())
.toString();
}
} }
package share.system.domain; package share.system.domain;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import share.common.annotation.Excel; import share.common.annotation.Excel;
import share.common.core.domain.BaseEntity; import share.common.core.domain.BaseEntity;
import java.math.BigDecimal;
/** /**
* 房间对象 s_room * 房间对象 s_room
* *
* @author ruoyi * @author ruoyi
* @date 2023-10-12 * @date 2023-10-12
*/ */
@Data
public class SRoom extends BaseEntity public class SRoom extends BaseEntity
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
...@@ -48,7 +52,7 @@ public class SRoom extends BaseEntity ...@@ -48,7 +52,7 @@ public class SRoom extends BaseEntity
/** 房间单价(默认单位:元/小时) */ /** 房间单价(默认单位:元/小时) */
@Excel(name = "房间单价(默认单位:元/小时)") @Excel(name = "房间单价(默认单位:元/小时)")
private Integer price; private BigDecimal price;
/** 门锁编码(接入第三方使用) */ /** 门锁编码(接入第三方使用) */
@Excel(name = "门锁编码(接入第三方使用)") @Excel(name = "门锁编码(接入第三方使用)")
...@@ -70,155 +74,4 @@ public class SRoom extends BaseEntity ...@@ -70,155 +74,4 @@ public class SRoom extends BaseEntity
@Excel(name = "其他可能硬件接入参数(备用2)") @Excel(name = "其他可能硬件接入参数(备用2)")
private String params2; private String params2;
public void setId(Long id)
{
this.id = id;
}
public Long getId()
{
return id;
}
public void setStoreId(Long storeId)
{
this.storeId = storeId;
}
public Long getStoreId()
{
return storeId;
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void setRoomType(String roomType)
{
this.roomType = roomType;
}
public String getRoomType()
{
return roomType;
}
public void setImages(String images)
{
this.images = images;
}
public String getImages()
{
return images;
}
public void setFacilities(String facilities)
{
this.facilities = facilities;
}
public String getFacilities()
{
return facilities;
}
public void setInfo(String info)
{
this.info = info;
}
public String getInfo()
{
return info;
}
public void setStatus(String status)
{
this.status = status;
}
public String getStatus()
{
return status;
}
public void setPrice(Integer price)
{
this.price = price;
}
public Integer getPrice()
{
return price;
}
public void setDoorLockCode(String doorLockCode)
{
this.doorLockCode = doorLockCode;
}
public String getDoorLockCode()
{
return doorLockCode;
}
public void setElectricControlCode(String electricControlCode)
{
this.electricControlCode = electricControlCode;
}
public String getElectricControlCode()
{
return electricControlCode;
}
public void setPassword(String password)
{
this.password = password;
}
public String getPassword()
{
return password;
}
public void setParams1(String params1)
{
this.params1 = params1;
}
public String getParams1()
{
return params1;
}
public void setParams2(String params2)
{
this.params2 = params2;
}
public String getParams2()
{
return params2;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("storeId", getStoreId())
.append("name", getName())
.append("roomType", getRoomType())
.append("images", getImages())
.append("facilities", getFacilities())
.append("info", getInfo())
.append("status", getStatus())
.append("price", getPrice())
.append("doorLockCode", getDoorLockCode())
.append("electricControlCode", getElectricControlCode())
.append("password", getPassword())
.append("params1", getParams1())
.append("params2", getParams2())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("remark", getRemark())
.toString();
}
} }
...@@ -7,6 +7,8 @@ import org.apache.commons.lang3.builder.ToStringBuilder; ...@@ -7,6 +7,8 @@ import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import share.common.core.domain.BaseEntity; import share.common.core.domain.BaseEntity;
import java.math.BigDecimal;
/** /**
* 房间对象 s_room * 房间对象 s_room
* *
...@@ -56,7 +58,7 @@ public class SRoomVo extends BaseEntity ...@@ -56,7 +58,7 @@ public class SRoomVo extends BaseEntity
/** 房间单价(默认单位:元/小时) */ /** 房间单价(默认单位:元/小时) */
@ApiModelProperty(value = "房间单价(默认单位:元/小时)") @ApiModelProperty(value = "房间单价(默认单位:元/小时)")
private Integer price; private BigDecimal price;
/** 门锁编码(接入第三方使用) */ /** 门锁编码(接入第三方使用) */
@ApiModelProperty(value = "门锁编码(接入第三方使用)") @ApiModelProperty(value = "门锁编码(接入第三方使用)")
......
package share.system.request;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotBlank;
import java.util.Date;
/**
* @Author wwl
* @Date 2023/10/19 14:56
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="CreateOrderRequest对象", description="下单请求对象")
public class CreateOrderRequest {
@ApiModelProperty(value = "门店ID", required = true)
@NotBlank(message = "门店ID不能为空")
private Long storeId;
@ApiModelProperty(value = "房间ID", required = true)
@NotBlank(message = "房间ID不能为空")
private Long roomId;
@ApiModelProperty(value = "优惠券id")
private Integer couponId;
@ApiModelProperty(value = "订单类型(0:订房订单,1:续房订单,2:充值订单)", required = true)
@NotBlank(message = "订单类型不能为空")
private Integer orderType;
/** 预约开始时间 */
@ApiModelProperty(value = "预约开始时间 yyyy-MM-dd HH:mm", required = true)
@NotBlank(message = "预约开始时间不能为空")
private Date preStartDate;
/** 预约结束时间 */
@ApiModelProperty(value = "预约结束时间 yyyy-MM-dd HH:mm", required = true)
@NotBlank(message = "预约结束时间不能为空")
private Date preEndDate;
}
package share.system.request;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotBlank;
import java.util.Date;
/**
* @Author wwl
* @Date 2023/10/19 15:34
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="OrderComputedPriceRequest对象", description="计算订单价格请求对象")
public class OrderComputedPriceRequest {
@ApiModelProperty(value = "门店ID", required = true)
@NotBlank(message = "门店ID不能为空")
private Long storeId;
@ApiModelProperty(value = "房间ID", required = true)
@NotBlank(message = "房间ID不能为空")
private Long roomId;
@ApiModelProperty(value = "优惠券id")
private Integer couponId;
@ApiModelProperty(value = "订单类型(0:订房订单,1:续房订单,2:充值订单)", required = true)
@NotBlank(message = "订单类型不能为空")
private Integer orderType;
/** 预约开始时间 */
@ApiModelProperty(value = "预约开始时间 yyyy-MM-dd HH:mm", required = true)
@NotBlank(message = "预约开始时间不能为空")
private Date preStartDate;
/** 预约结束时间 */
@ApiModelProperty(value = "预约结束时间 yyyy-MM-dd HH:mm", required = true)
@NotBlank(message = "预约结束时间不能为空")
private Date preEndDate;
}
package share.system.response;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/**
* @Author wwl
* @Date 2023/10/19 15:35
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="ComputedOrderPriceResponse对象", description="计算订单价格响应对象")
public class ComputedOrderPriceResponse implements Serializable {
private static final long serialVersionUID = 7282892323898493847L;
@ApiModelProperty(value = "优惠券优惠金额")
private BigDecimal couponFee;
@ApiModelProperty(value = "实际支付金额")
private BigDecimal payFee;
@ApiModelProperty(value = "商品总金额")
private BigDecimal totalFee;
}
...@@ -5,6 +5,10 @@ import java.util.List; ...@@ -5,6 +5,10 @@ import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import share.system.domain.SOrder; import share.system.domain.SOrder;
import share.system.domain.vo.MyRecord;
import share.system.request.CreateOrderRequest;
import share.system.request.OrderComputedPriceRequest;
import share.system.response.ComputedOrderPriceResponse;
/** /**
* 订单Service接口 * 订单Service接口
...@@ -70,4 +74,18 @@ public interface ISOrderService extends IService<SOrder> ...@@ -70,4 +74,18 @@ public interface ISOrderService extends IService<SOrder>
* @return * @return
*/ */
List<SOrder> listByRoomInfo(Long storeId, Long roomId, Date day); List<SOrder> listByRoomInfo(Long storeId, Long roomId, Date day);
/**
* 订单预下单
* @param request 预下单请求参数
* @return PreOrderResponse
*/
MyRecord createOrder(CreateOrderRequest request);
/**
* 计算订单价格
* @param request 计算订单价格请求对象
* @return ComputedOrderPriceResponse
*/
ComputedOrderPriceResponse computedOrderPrice(OrderComputedPriceRequest request);
} }
...@@ -60,10 +60,10 @@ public class RoomStatusServiceImpl implements RoomStatusService { ...@@ -60,10 +60,10 @@ public class RoomStatusServiceImpl implements RoomStatusService {
RoomStatusVo vo = new RoomStatusVo(); RoomStatusVo vo = new RoomStatusVo();
Integer lockInt = Integer.parseInt(lock); Integer lockInt = Integer.parseInt(lock);
String timeHour = ""; String timeHour = "";
if(Integer.compare(lockInt,new Integer(10)) == 0){ if(Integer.compare(lockInt,new Integer(10)) == -1){
timeHour = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD,day) + "0"+lock; timeHour = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD,day) + " 0" + lock;
}else{ }else{
timeHour = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD,day) + lock; timeHour = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD,day) + " " + lock;
} }
vo.setStoreId(store.getId()); vo.setStoreId(store.getId());
vo.setRoomId(roomId); vo.setRoomId(roomId);
...@@ -149,5 +149,4 @@ public class RoomStatusServiceImpl implements RoomStatusService { ...@@ -149,5 +149,4 @@ public class RoomStatusServiceImpl implements RoomStatusService {
} }
} }
} }
package share.system.service.impl; package share.system.service.impl;
import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
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.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import share.common.enums.CouponStatusEnum;
import share.common.enums.CouponTypeEnum;
import share.common.exception.base.BaseException;
import share.common.utils.DateUtil;
import share.common.utils.DateUtils; import share.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import share.system.domain.SConsumer;
import share.system.domain.SConsumerCoupon;
import share.system.domain.SRoom;
import share.system.domain.vo.MyRecord;
import share.system.mapper.SOrderMapper; import share.system.mapper.SOrderMapper;
import share.system.domain.SOrder; import share.system.domain.SOrder;
import share.system.request.CreateOrderRequest;
import share.system.request.OrderComputedPriceRequest;
import share.system.response.ComputedOrderPriceResponse;
import share.system.service.ISConsumerCouponService;
import share.system.service.ISOrderService; import share.system.service.ISOrderService;
import share.system.service.ISRoomService;
import share.system.service.SConsumerService;
/** /**
* 订单Service业务层处理 * 订单Service业务层处理
...@@ -25,6 +45,15 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper,SOrder> implemen ...@@ -25,6 +45,15 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper,SOrder> implemen
@Autowired @Autowired
private SOrderMapper sOrderMapper; private SOrderMapper sOrderMapper;
@Autowired
private SConsumerService sConsumerService;
@Autowired
private ISConsumerCouponService consumerCouponService;
@Autowired
private ISRoomService roomService;
/** /**
* 查询订单 * 查询订单
* *
...@@ -111,4 +140,79 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper,SOrder> implemen ...@@ -111,4 +140,79 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper,SOrder> implemen
queryWrapper.last("ORDER BY IFNULL(start_date,pre_start_date) "); queryWrapper.last("ORDER BY IFNULL(start_date,pre_start_date) ");
return list(queryWrapper); return list(queryWrapper);
} }
@Override
public MyRecord createOrder(CreateOrderRequest request) {
return null;
}
/**
* 计算订单价格
* @param request 计算订单价格请求对象
* @return ComputedOrderPriceResponse
*/
@Override
public ComputedOrderPriceResponse computedOrderPrice(OrderComputedPriceRequest request) {
SConsumer user = sConsumerService.getSConsumer();
return computedPrice(request, user);
}
private BigDecimal computeTotalPrice(BigDecimal unitPrice, Date startTime, Date endTime){
return DateUtils.differentHour(startTime,endTime).multiply(unitPrice);
}
private ComputedOrderPriceResponse computedPrice(OrderComputedPriceRequest request, SConsumer user) {
// 计算各种价格
ComputedOrderPriceResponse priceResponse = new ComputedOrderPriceResponse();
SRoom room = roomService.getById(request.getRoomId());
BigDecimal totalPrice = computeTotalPrice(room.getPrice(),request.getPreStartDate(),request.getPreEndDate());
priceResponse.setTotalFee(totalPrice);
// 计算优惠券金额
if (ObjectUtil.isNull(request.getCouponId()) || request.getCouponId() <= 0) {
priceResponse.setCouponFee(BigDecimal.ZERO);
} else {
// 判断优惠券是否可以使用
SConsumerCoupon consumerCoupon = consumerCouponService.getById(request.getCouponId());
computedCouponPrice(priceResponse,user,consumerCoupon);
}
return priceResponse;
}
/**
* 计算使用优惠券后的订单金额
*/
private void computedCouponPrice(ComputedOrderPriceResponse priceResponse, SConsumer user, SConsumerCoupon consumerCoupon){
if (ObjectUtil.isNull(consumerCoupon) || !consumerCoupon.getCouponId().equals(user.getId())) {
throw new BaseException("优惠券领取记录不存在!");
}
if (CouponStatusEnum.USED.getValue().compareTo(Integer.parseInt(consumerCoupon.getUseStatus())) == 0) {
throw new BaseException("此优惠券已使用!");
}
if (CouponStatusEnum.EXPIRED.getValue().compareTo(Integer.parseInt(consumerCoupon.getUseStatus())) == 0) {
throw new BaseException("此优惠券已失效!");
}
//判断是否在使用时间内
Date date = DateUtil.nowDateTime();
if (date.compareTo(consumerCoupon.getEndDate()) > 0) {
throw new BaseException("此优惠券已经失效了");
}
CouponTypeEnum couponType = CouponTypeEnum.getType(consumerCoupon.getCouponType());
switch (couponType){
case DISCOUNT://TODO 折扣券
break;
case CASH://现金券
//判断优惠券最小使用金额
if (consumerCoupon.getMinPrice().compareTo(priceResponse.getTotalFee()) > 0) {
throw new BaseException("总金额小于优惠券最小使用金额");
}
priceResponse.setCouponFee(consumerCoupon.getSubPrice());
priceResponse.setPayFee(priceResponse.getTotalFee().subtract(consumerCoupon.getSubPrice()));
break;
case DURATION://TODO 时长券
break;
default:
break;
}
}
} }
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