每日使用限量
This commit is contained in:
parent
f01ccf65ce
commit
b1e5427561
|
|
@ -43,8 +43,6 @@ public class ACouponController {
|
||||||
private MkShopCouponRecordService couponRecordService;
|
private MkShopCouponRecordService couponRecordService;
|
||||||
@DubboReference
|
@DubboReference
|
||||||
private ShopSyncService shopSyncService;
|
private ShopSyncService shopSyncService;
|
||||||
@Resource
|
|
||||||
private CouponTask couponTask;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页
|
* 分页
|
||||||
|
|
@ -204,11 +202,4 @@ public class ACouponController {
|
||||||
public CzgResult<List<UserCouponVo>> findCoupon(@RequestParam Long shopUserId, @RequestParam(required = false) Integer type, @RequestParam(required = false) Integer isFood) {
|
public CzgResult<List<UserCouponVo>> findCoupon(@RequestParam Long shopUserId, @RequestParam(required = false) Integer type, @RequestParam(required = false) Integer isFood) {
|
||||||
return CzgResult.success(shopCouponService.findCoupon(StpKit.USER.getShopId(), shopUserId, type, isFood));
|
return CzgResult.success(shopCouponService.findCoupon(StpKit.USER.getShopId(), shopUserId, type, isFood));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("/testTask")
|
|
||||||
public CzgResult<Void> getCouponGiftPage() {
|
|
||||||
couponTask.deliver();
|
|
||||||
return CzgResult.success();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ import org.apache.dubbo.config.annotation.DubboReference;
|
||||||
import org.apache.dubbo.config.annotation.DubboService;
|
import org.apache.dubbo.config.annotation.DubboService;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.LocalTime;
|
import java.time.LocalTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
@ -293,65 +294,18 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
|
||||||
//券id 券使用描述
|
//券id 券使用描述
|
||||||
Map<Long, JSONObject> coupons = new HashMap<>();
|
Map<Long, JSONObject> coupons = new HashMap<>();
|
||||||
for (UserCouponVo tbUserCouponVo : tbUserCouponVos) {
|
for (UserCouponVo tbUserCouponVo : tbUserCouponVos) {
|
||||||
int maxShow = 5;
|
//填充优惠券使用描述 每人每日使用限量校验
|
||||||
if ("only".equals(tbUserCouponVo.getUseShopType())) {
|
|
||||||
ShopInfo shopInfo = shopInfoService.getById(tbUserCouponVo.getShopId());
|
|
||||||
tbUserCouponVo.setUseShops("仅本店:" + shopInfo.getShopName());
|
|
||||||
} else if ("all".equals(tbUserCouponVo.getUseShopType())) {
|
|
||||||
tbUserCouponVo.setUseShops("所有门店");
|
|
||||||
} else if ("custom".equals(tbUserCouponVo.getUseShopType())) {
|
|
||||||
if (StrUtil.isNotBlank(tbUserCouponVo.getUseShops())) {
|
|
||||||
QueryWrapper queryWrapper = QueryWrapper.create().select(ShopInfo::getShopName)
|
|
||||||
.in(ShopInfo::getId, Arrays.stream(tbUserCouponVo.getUseShops().split(",")).map(Long::parseLong).toList())
|
|
||||||
.eq(ShopInfo::getStatus, 1);
|
|
||||||
List<String> shopNames = shopInfoService.listAs(queryWrapper, String.class);
|
|
||||||
if (CollUtil.isNotEmpty(shopNames)) {
|
|
||||||
StringBuilder result = new StringBuilder();
|
|
||||||
for (int i = 0; i < shopNames.size(); i++) {
|
|
||||||
if (i > 0) {
|
|
||||||
result.append(",");
|
|
||||||
}
|
|
||||||
result.append(shopNames.get(i));
|
|
||||||
if (i == maxShow - 1 && i != shopNames.size() - 1) {
|
|
||||||
result.append("...");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tbUserCouponVo.setUseShops(result.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!coupons.containsKey(tbUserCouponVo.getCouponId())) {
|
if (!coupons.containsKey(tbUserCouponVo.getCouponId())) {
|
||||||
setCouponInfo(coupons, tbUserCouponVo, null, week, formatter);
|
setCouponInfo(coupons, tbUserCouponVo, week, formatter, shopUserId);
|
||||||
}
|
}
|
||||||
|
//填充使用门店
|
||||||
|
setUseShop(tbUserCouponVo);
|
||||||
|
//填充使用/门槛商品
|
||||||
|
setFoods(tbUserCouponVo);
|
||||||
JSONObject couponJson = coupons.get(tbUserCouponVo.getCouponId());
|
JSONObject couponJson = coupons.get(tbUserCouponVo.getCouponId());
|
||||||
tbUserCouponVo.setUseRestrictions(couponJson.getString("useRestrictions"));
|
|
||||||
tbUserCouponVo.setUse(couponJson.getBoolean("isUse"));
|
tbUserCouponVo.setUse(couponJson.getBoolean("isUse"));
|
||||||
if (tbUserCouponVo.getType() == 1 || tbUserCouponVo.getType() == 2 || tbUserCouponVo.getType() == 3
|
tbUserCouponVo.setUseRestrictions(couponJson.getString("useRestrictions"));
|
||||||
|| tbUserCouponVo.getType() == 4 || tbUserCouponVo.getType() == 6) {
|
tbUserCouponVo.setNoUseRestrictions(couponJson.getString("noUseRestrictions"));
|
||||||
if (StrUtil.isNotBlank(tbUserCouponVo.getFoods()) && !",".equals(tbUserCouponVo.getFoods())) {
|
|
||||||
List<Long> couponFoodIds = Arrays.stream(tbUserCouponVo.getFoods().split(",")).map(Long::parseLong).toList();
|
|
||||||
if (CollUtil.isNotEmpty(couponFoodIds)) {
|
|
||||||
List<Product> list = productService.list(new QueryWrapper()
|
|
||||||
.in(Product::getId, couponFoodIds).eq(Product::getIsDel, 0));
|
|
||||||
// log.info("优惠券商品列表:{}", list);
|
|
||||||
if (CollUtil.isEmpty(list)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (tbUserCouponVo.getType() == 1 || tbUserCouponVo.getType() == 3) {
|
|
||||||
tbUserCouponVo.setThresholdFoods(JSON.parseObject(JSON.toJSONString(list), new TypeReference<>() {
|
|
||||||
}));
|
|
||||||
} else {
|
|
||||||
tbUserCouponVo.setUseFoods(JSON.parseObject(JSON.toJSONString(list), new TypeReference<>() {
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
String foods = list.stream().map(Product::getName).collect(Collectors.joining(","));
|
|
||||||
tbUserCouponVo.setFoods(foods);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
tbUserCouponVo.setFoods("全部商品");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
tbUserCouponVos.sort(Comparator.comparing(UserCouponVo::isUse).reversed());
|
tbUserCouponVos.sort(Comparator.comparing(UserCouponVo::isUse).reversed());
|
||||||
return tbUserCouponVos;
|
return tbUserCouponVos;
|
||||||
|
|
@ -396,6 +350,7 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
|
||||||
return recordService.updateChain()
|
return recordService.updateChain()
|
||||||
.set(MkShopCouponRecord::getStatus, 1)
|
.set(MkShopCouponRecord::getStatus, 1)
|
||||||
.set(MkShopCouponRecord::getTargetId, orderId)
|
.set(MkShopCouponRecord::getTargetId, orderId)
|
||||||
|
.set(MkShopCouponRecord::getUseTime, LocalDateTime.now())
|
||||||
.eq(MkShopCouponRecord::getShopUserId, shopUserId)
|
.eq(MkShopCouponRecord::getShopUserId, shopUserId)
|
||||||
.in(MkShopCouponRecord::getId, ids).update();
|
.in(MkShopCouponRecord::getId, ids).update();
|
||||||
}
|
}
|
||||||
|
|
@ -448,16 +403,87 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
|
||||||
return resultList;
|
return resultList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setCouponInfo(Map<Long, JSONObject> coupons, UserCouponVo tbUserCouponVo, BigDecimal amount, String week, DateTimeFormatter formatter) {
|
|
||||||
JSONObject json = new JSONObject();
|
/**
|
||||||
|
* 设置优惠券使用门店
|
||||||
|
*/
|
||||||
|
private void setUseShop(UserCouponVo tbUserCouponVo) {
|
||||||
|
int maxShow = 5;
|
||||||
|
if ("only".equals(tbUserCouponVo.getUseShopType())) {
|
||||||
|
ShopInfo shopInfo = shopInfoService.getById(tbUserCouponVo.getShopId());
|
||||||
|
tbUserCouponVo.setUseShops("仅本店:" + shopInfo.getShopName());
|
||||||
|
} else if ("all".equals(tbUserCouponVo.getUseShopType())) {
|
||||||
|
tbUserCouponVo.setUseShops("所有门店");
|
||||||
|
} else if ("custom".equals(tbUserCouponVo.getUseShopType())) {
|
||||||
|
if (StrUtil.isNotBlank(tbUserCouponVo.getUseShops())) {
|
||||||
|
QueryWrapper queryWrapper = QueryWrapper.create().select(ShopInfo::getShopName)
|
||||||
|
.in(ShopInfo::getId, Arrays.stream(tbUserCouponVo.getUseShops().split(",")).map(Long::parseLong).toList())
|
||||||
|
.eq(ShopInfo::getStatus, 1);
|
||||||
|
List<String> shopNames = shopInfoService.listAs(queryWrapper, String.class);
|
||||||
|
if (CollUtil.isNotEmpty(shopNames)) {
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
for (int i = 0; i < shopNames.size(); i++) {
|
||||||
|
if (i > 0) {
|
||||||
|
result.append(",");
|
||||||
|
}
|
||||||
|
result.append(shopNames.get(i));
|
||||||
|
if (i == maxShow - 1 && i != shopNames.size() - 1) {
|
||||||
|
result.append("...");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tbUserCouponVo.setUseShops(result.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 填充使用/门槛商品
|
||||||
|
*/
|
||||||
|
private void setFoods(UserCouponVo tbUserCouponVo) {
|
||||||
|
if (tbUserCouponVo.getType() == 1 || tbUserCouponVo.getType() == 2 || tbUserCouponVo.getType() == 3
|
||||||
|
|| tbUserCouponVo.getType() == 4 || tbUserCouponVo.getType() == 6) {
|
||||||
|
if (StrUtil.isNotBlank(tbUserCouponVo.getFoods()) && !",".equals(tbUserCouponVo.getFoods())) {
|
||||||
|
List<Long> couponFoodIds = Arrays.stream(tbUserCouponVo.getFoods().split(",")).map(Long::parseLong).toList();
|
||||||
|
if (CollUtil.isNotEmpty(couponFoodIds)) {
|
||||||
|
List<Product> list = productService.list(new QueryWrapper()
|
||||||
|
.in(Product::getId, couponFoodIds).eq(Product::getIsDel, 0));
|
||||||
|
// log.info("优惠券商品列表:{}", list);
|
||||||
|
if (CollUtil.isEmpty(list)) {
|
||||||
|
tbUserCouponVo.setFoods("");
|
||||||
|
} else {
|
||||||
|
if (tbUserCouponVo.getType() == 1 || tbUserCouponVo.getType() == 3) {
|
||||||
|
tbUserCouponVo.setThresholdFoods(JSON.parseObject(JSON.toJSONString(list), new TypeReference<>() {
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
tbUserCouponVo.setUseFoods(JSON.parseObject(JSON.toJSONString(list), new TypeReference<>() {
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
String foods = list.stream().map(Product::getName).collect(Collectors.joining(","));
|
||||||
|
tbUserCouponVo.setFoods(foods);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tbUserCouponVo.setFoods("全部商品");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 过滤优惠券可用时间段 每人每日使用限量校验
|
||||||
|
* 填充优惠券Json信息
|
||||||
|
* {
|
||||||
|
* "isUse": true,
|
||||||
|
* "useRestrictions": "10:00到12:00可用",
|
||||||
|
* "noUseRestrictions": "不在可用时间范围内"
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
private void setCouponInfo(Map<Long, JSONObject> coupons, UserCouponVo tbUserCouponVo, String week, DateTimeFormatter formatter, Long shopUserId) {
|
||||||
boolean isUse = true;
|
boolean isUse = true;
|
||||||
ShopCoupon tbShopCoupon = getById(tbUserCouponVo.getCouponId());
|
ShopCoupon tbShopCoupon = getById(tbUserCouponVo.getCouponId());
|
||||||
StringBuilder useRestrictions = new StringBuilder("每天 ");
|
StringBuilder useRestrictions = new StringBuilder("每天 ");
|
||||||
if (amount != null && tbShopCoupon.getCouponType().equals(1)) {
|
String noUseRestrictions = "";
|
||||||
if (amount.compareTo(tbShopCoupon.getFullAmount()) < 0) {
|
|
||||||
isUse = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (StrUtil.isNotBlank(tbShopCoupon.getUseDays())) {
|
if (StrUtil.isNotBlank(tbShopCoupon.getUseDays())) {
|
||||||
String[] split = tbShopCoupon.getUseDays().split(",");
|
String[] split = tbShopCoupon.getUseDays().split(",");
|
||||||
if (split.length != 7) {
|
if (split.length != 7) {
|
||||||
|
|
@ -465,7 +491,7 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
|
||||||
useRestrictions = new StringBuilder(tbShopCoupon.getUseDays() + " ");
|
useRestrictions = new StringBuilder(tbShopCoupon.getUseDays() + " ");
|
||||||
}
|
}
|
||||||
if (!tbShopCoupon.getUseDays().contains(week)) {
|
if (!tbShopCoupon.getUseDays().contains(week)) {
|
||||||
tbUserCouponVo.setNoUseRestrictions("不在可用时间范围内");
|
noUseRestrictions = "不在可用时间范围内";
|
||||||
isUse = false;
|
isUse = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -475,15 +501,15 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
|
||||||
LocalTime endTime = tbShopCoupon.getUseEndTime().toLocalTime();
|
LocalTime endTime = tbShopCoupon.getUseEndTime().toLocalTime();
|
||||||
if (currentTime.isBefore(startTime)) {
|
if (currentTime.isBefore(startTime)) {
|
||||||
if (startTime.isBefore(endTime)) {
|
if (startTime.isBefore(endTime)) {
|
||||||
tbUserCouponVo.setNoUseRestrictions("不在可用时间范围内");
|
noUseRestrictions = "不在可用时间范围内";
|
||||||
isUse = false;
|
isUse = false;
|
||||||
} else if (currentTime.isAfter(endTime)) {
|
} else if (currentTime.isAfter(endTime)) {
|
||||||
tbUserCouponVo.setNoUseRestrictions("不在可用时间范围内");
|
noUseRestrictions = "不在可用时间范围内";
|
||||||
isUse = false;
|
isUse = false;
|
||||||
}
|
}
|
||||||
} else if (startTime.isBefore(endTime)) {
|
} else if (startTime.isBefore(endTime)) {
|
||||||
if (currentTime.isAfter(endTime)) {
|
if (currentTime.isAfter(endTime)) {
|
||||||
tbUserCouponVo.setNoUseRestrictions("不在可用时间范围内");
|
noUseRestrictions = "不在可用时间范围内";
|
||||||
isUse = false;
|
isUse = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -493,8 +519,22 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
|
||||||
useRestrictions.append("全时段");
|
useRestrictions.append("全时段");
|
||||||
}
|
}
|
||||||
useRestrictions.append(" 可用");
|
useRestrictions.append(" 可用");
|
||||||
|
if (tbUserCouponVo.getUseLimit() != -10086) {
|
||||||
|
long useCount = recordService.count(new QueryWrapper()
|
||||||
|
.eq(MkShopCouponRecord::getCouponId, tbUserCouponVo.getCouponId())
|
||||||
|
.eq(MkShopCouponRecord::getShopUserId, shopUserId)
|
||||||
|
.ge(MkShopCouponRecord::getUseTime, LocalDate.now().atTime(LocalTime.MIN))
|
||||||
|
.le(MkShopCouponRecord::getUseTime, LocalDate.now().atTime(LocalTime.MAX))
|
||||||
|
.eq(MkShopCouponRecord::getStatus, 1));
|
||||||
|
if (useCount >= tbUserCouponVo.getUseLimit()) {
|
||||||
|
isUse = false;
|
||||||
|
noUseRestrictions = "已达使用限量" + tbUserCouponVo.getUseLimit() + "张";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
json.put("isUse", isUse);
|
json.put("isUse", isUse);
|
||||||
json.put("useRestrictions", useRestrictions);
|
json.put("useRestrictions", useRestrictions);
|
||||||
|
json.put("noUseRestrictions", noUseRestrictions);
|
||||||
|
|
||||||
coupons.put(tbUserCouponVo.getCouponId(), json);
|
coupons.put(tbUserCouponVo.getCouponId(), json);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue