订单页优惠券查询
This commit is contained in:
@@ -2,6 +2,8 @@ package cn.ysk.cashier.dto;
|
|||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class CouponDto {
|
public class CouponDto {
|
||||||
private Integer shopId;
|
private Integer shopId;
|
||||||
@@ -9,4 +11,5 @@ public class CouponDto {
|
|||||||
//-1已过期 1未使用 2已使用
|
//-1已过期 1未使用 2已使用
|
||||||
private Integer status;
|
private Integer status;
|
||||||
private Integer orderId;
|
private Integer orderId;
|
||||||
|
private BigDecimal amount;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -235,70 +235,24 @@ public class TbShopCouponServiceImpl extends ServiceImpl<TbShopCouponMapper, TbS
|
|||||||
public ResponseEntity<Object> find(CouponDto param) {
|
public ResponseEntity<Object> find(CouponDto param) {
|
||||||
TbShopUser tbShopUser = shopUserRepository.selectByUserIdAndShopId(param.getUserId().toString(), param.getShopId().toString());
|
TbShopUser tbShopUser = shopUserRepository.selectByUserIdAndShopId(param.getUserId().toString(), param.getShopId().toString());
|
||||||
if (param.getOrderId() != null) {
|
if (param.getOrderId() != null) {
|
||||||
TbOrderInfo tbOrderInfo = orderInfoRepository.findById(param.getOrderId()).orElse(null);
|
List<TbUserCouponVo> tbUserCouponVos = inRecordMapper.queryByVipIdAndShopId(tbShopUser.getId(), param.getShopId());
|
||||||
if (tbOrderInfo != null) {
|
if (CollectionUtil.isNotEmpty(tbUserCouponVos)) {
|
||||||
List<TbOrderDetail> tbOrderDetails = orderDetailRepository.searchDetailByOrderId(param.getOrderId());
|
String week = DateUtil.dayOfWeekEnum(new Date()).toChinese("周");
|
||||||
Set<Integer> pros = tbOrderDetails.stream().map(TbOrderDetail::getProductId).collect(Collectors.toSet());
|
LocalTime now = LocalTime.now();
|
||||||
if (CollectionUtil.isNotEmpty(tbOrderDetails)) {
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
|
||||||
List<TbUserCouponVo> tbUserCouponVos = inRecordMapper.queryByVipIdAndShopId(tbShopUser.getId(), param.getShopId());
|
|
||||||
if (CollectionUtil.isNotEmpty(tbUserCouponVos)) {
|
|
||||||
String week = DateUtil.dayOfWeekEnum(new Date()).toChinese("周");
|
|
||||||
LocalTime now = LocalTime.now();
|
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
|
|
||||||
|
|
||||||
//券id 券使用描述
|
//券id 券使用描述
|
||||||
Map<Integer, JsonObject> coupons = new HashMap<>();
|
Map<Integer, JsonObject> coupons = new HashMap<>();
|
||||||
for (TbUserCouponVo tbUserCouponVo : tbUserCouponVos) {
|
for (TbUserCouponVo tbUserCouponVo : tbUserCouponVos) {
|
||||||
if (!coupons.containsKey(tbUserCouponVo.getCouponId())) {
|
if (!coupons.containsKey(tbUserCouponVo.getCouponId())) {
|
||||||
JsonObject json = new JsonObject();
|
setCouponInfo(coupons, tbUserCouponVo, null, week ,now, formatter);
|
||||||
boolean isUse = true;
|
|
||||||
TbShopCoupon tbShopCoupon = tbShopCouponmapper.selectById(tbUserCouponVo.getCouponId());
|
|
||||||
StringBuilder useRestrictions = new StringBuilder("每天 ");
|
|
||||||
if (tbShopCoupon.getType().equals(1)) {
|
|
||||||
if (tbOrderInfo.getOrderAmount().compareTo(tbShopCoupon.getFullAmount()) < 0) {
|
|
||||||
isUse = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (StringUtils.isNotBlank(tbShopCoupon.getUserDays())) {
|
|
||||||
String[] split = tbShopCoupon.getUserDays().split(",");
|
|
||||||
if (split.length != 7) {
|
|
||||||
useRestrictions = new StringBuilder(tbShopCoupon.getUserDays() + " ");
|
|
||||||
}
|
|
||||||
if (!tbShopCoupon.getUserDays().contains(week)) {
|
|
||||||
isUse = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (tbShopCoupon.getUseTimeType().equals("custom")) {
|
|
||||||
if (now.isBefore(tbShopCoupon.getUseStartTime()) || now.isAfter(tbShopCoupon.getUseEndTime())) {
|
|
||||||
isUse = false;
|
|
||||||
}
|
|
||||||
useRestrictions.append(
|
|
||||||
tbShopCoupon.getUseStartTime().format(formatter)
|
|
||||||
+ "-"
|
|
||||||
+ tbShopCoupon.getUseEndTime().format(formatter));
|
|
||||||
} else {
|
|
||||||
useRestrictions.append("全时段");
|
|
||||||
}
|
|
||||||
useRestrictions.append(" 可用");
|
|
||||||
json.addProperty("isUse", isUse);
|
|
||||||
json.addProperty("useRestrictions", useRestrictions.toString());
|
|
||||||
|
|
||||||
coupons.put(tbUserCouponVo.getCouponId(), json);
|
|
||||||
}
|
|
||||||
JsonObject couponJson = coupons.get(tbUserCouponVo.getCouponId());
|
|
||||||
tbUserCouponVo.setUseRestrictions(couponJson.get("useRestrictions").toString());
|
|
||||||
if (tbUserCouponVo.getType().equals(1)) {
|
|
||||||
tbUserCouponVo.setUse(couponJson.get("isUse").getAsBoolean());
|
|
||||||
} else if (tbUserCouponVo.getType().equals(2) && couponJson.get("isUse").getAsBoolean()) {
|
|
||||||
if (!pros.contains(tbUserCouponVo.getProId())) {
|
|
||||||
tbUserCouponVo.setUse(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tbUserCouponVos.sort(Comparator.comparing(TbUserCouponVo::isUse).reversed().thenComparing(TbUserCouponVo::getExpireTime));
|
|
||||||
return new ResponseEntity<>(tbUserCouponVos, HttpStatus.OK);
|
|
||||||
}
|
}
|
||||||
|
JsonObject couponJson = coupons.get(tbUserCouponVo.getCouponId());
|
||||||
|
tbUserCouponVo.setUseRestrictions(couponJson.get("useRestrictions").toString());
|
||||||
|
tbUserCouponVo.setUse(couponJson.get("isUse").getAsBoolean());
|
||||||
}
|
}
|
||||||
|
tbUserCouponVos.sort(Comparator.comparing(TbUserCouponVo::isUse).reversed().thenComparing(TbUserCouponVo::getExpireTime));
|
||||||
|
return new ResponseEntity<>(tbUserCouponVos, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
@@ -321,7 +275,7 @@ public class TbShopCouponServiceImpl extends ServiceImpl<TbShopCouponMapper, TbS
|
|||||||
TbShopShareRecord shareRecord = shareRecordService.getById(inRecord.getSourceActId());
|
TbShopShareRecord shareRecord = shareRecordService.getById(inRecord.getSourceActId());
|
||||||
if (shareRecord != null && shareRecord.getMethod().equals("use")) {
|
if (shareRecord != null && shareRecord.getMethod().equals("use")) {
|
||||||
shareRecord.setStatus(3);
|
shareRecord.setStatus(3);
|
||||||
shareRecordService.give(shareRecord,shareRecord.getInvitedId());
|
shareRecordService.give(shareRecord, shareRecord.getInvitedId());
|
||||||
shareRecordService.updateById(shareRecord);
|
shareRecordService.updateById(shareRecord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -414,7 +368,7 @@ public class TbShopCouponServiceImpl extends ServiceImpl<TbShopCouponMapper, TbS
|
|||||||
productCoupon.add(item);
|
productCoupon.add(item);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return new HashMap<String, Object>(){{
|
return new HashMap<String, Object>() {{
|
||||||
put("fullReductionCoupon", fullReductionCoupon);
|
put("fullReductionCoupon", fullReductionCoupon);
|
||||||
put("productCoupon", productCoupon);
|
put("productCoupon", productCoupon);
|
||||||
}};
|
}};
|
||||||
|
|||||||
Reference in New Issue
Block a user