You've already forked FrameTour-BE
Merge branch 'refs/heads/price_inquery'
This commit is contained in:
@@ -7,6 +7,7 @@ import com.ycwl.basic.pricing.dto.CouponClaimRequest;
|
|||||||
import com.ycwl.basic.pricing.dto.CouponClaimResult;
|
import com.ycwl.basic.pricing.dto.CouponClaimResult;
|
||||||
import com.ycwl.basic.pricing.dto.req.VoucherPrintReq;
|
import com.ycwl.basic.pricing.dto.req.VoucherPrintReq;
|
||||||
import com.ycwl.basic.pricing.dto.resp.VoucherPrintResp;
|
import com.ycwl.basic.pricing.dto.resp.VoucherPrintResp;
|
||||||
|
import com.ycwl.basic.pricing.enums.CouponType;
|
||||||
import com.ycwl.basic.pricing.service.ICouponService;
|
import com.ycwl.basic.pricing.service.ICouponService;
|
||||||
import com.ycwl.basic.pricing.service.VoucherPrintService;
|
import com.ycwl.basic.pricing.service.VoucherPrintService;
|
||||||
import com.ycwl.basic.repository.FaceRepository;
|
import com.ycwl.basic.repository.FaceRepository;
|
||||||
@@ -19,6 +20,9 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/mobile/claim/v1")
|
@RequestMapping("/api/mobile/claim/v1")
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@@ -80,6 +84,24 @@ public class AppClaimController {
|
|||||||
if (claimResult.isSuccess()) {
|
if (claimResult.isSuccess()) {
|
||||||
// 领到了
|
// 领到了
|
||||||
claimResp.setHasCoupon(true);
|
claimResp.setHasCoupon(true);
|
||||||
|
switch (claimResult.getCoupon().getCouponType()) {
|
||||||
|
case CouponType.PERCENTAGE:
|
||||||
|
claimResp.setCouponType("折扣优惠券");
|
||||||
|
claimResp.setCouponDesc("打" + (BigDecimal.valueOf(1).setScale(2, RoundingMode.HALF_UP).subtract(claimResult.getCoupon().getDiscountValue())).multiply(BigDecimal.valueOf(10)) + "折");
|
||||||
|
break;
|
||||||
|
case CouponType.FIXED_AMOUNT:
|
||||||
|
if (claimResult.getCoupon().getMinAmount().compareTo(BigDecimal.ZERO) > 0) {
|
||||||
|
claimResp.setCouponType("满减优惠券");
|
||||||
|
claimResp.setCouponDesc("满" + claimResult.getCoupon().getMinAmount() + "减" + claimResult.getCoupon().getDiscountValue());
|
||||||
|
} else {
|
||||||
|
claimResp.setCouponType("直减优惠券");
|
||||||
|
claimResp.setCouponDesc("直减" + claimResult.getCoupon().getDiscountValue());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
claimResp.setCouponType("普通优惠券");
|
||||||
|
break;
|
||||||
|
}
|
||||||
claimResp.setCouponDesc(scenicConfig.getString("coupon_desc_for_type_" + req.getType(), "专属折扣券"));
|
claimResp.setCouponDesc(scenicConfig.getString("coupon_desc_for_type_" + req.getType(), "专属折扣券"));
|
||||||
claimResp.setCouponCountdown(scenicConfig.getString("coupon_countdown_for_type_" + req.getType(), "送你优惠,保存美好!"));
|
claimResp.setCouponCountdown(scenicConfig.getString("coupon_countdown_for_type_" + req.getType(), "送你优惠,保存美好!"));
|
||||||
return ApiResponse.success(claimResp);
|
return ApiResponse.success(claimResp);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ public class ClaimResp {
|
|||||||
private String printType;
|
private String printType;
|
||||||
private String printCode;
|
private String printCode;
|
||||||
private Boolean hasCoupon;
|
private Boolean hasCoupon;
|
||||||
|
private String couponType;
|
||||||
private String couponDesc;
|
private String couponDesc;
|
||||||
private String couponCountdown;
|
private String couponCountdown;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.ycwl.basic.pricing.dto;
|
package com.ycwl.basic.pricing.dto;
|
||||||
|
|
||||||
import com.ycwl.basic.pricing.entity.PriceCouponClaimRecord;
|
import com.ycwl.basic.pricing.entity.PriceCouponClaimRecord;
|
||||||
|
import com.ycwl.basic.pricing.entity.PriceCouponConfig;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -55,16 +56,18 @@ public class CouponClaimResult {
|
|||||||
* 景区ID
|
* 景区ID
|
||||||
*/
|
*/
|
||||||
private String scenicId;
|
private String scenicId;
|
||||||
|
private PriceCouponConfig coupon;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建成功结果
|
* 创建成功结果
|
||||||
*/
|
*/
|
||||||
public static CouponClaimResult success(PriceCouponClaimRecord record, String couponName) {
|
public static CouponClaimResult success(PriceCouponClaimRecord record, PriceCouponConfig coupon) {
|
||||||
CouponClaimResult result = new CouponClaimResult();
|
CouponClaimResult result = new CouponClaimResult();
|
||||||
|
result.coupon = coupon;
|
||||||
result.success = true;
|
result.success = true;
|
||||||
result.claimRecordId = record.getId();
|
result.claimRecordId = record.getId();
|
||||||
result.couponId = record.getCouponId();
|
result.couponId = record.getCouponId();
|
||||||
result.couponName = couponName;
|
result.couponName = coupon.getCouponName();
|
||||||
result.claimTime = record.getClaimTime();
|
result.claimTime = record.getClaimTime();
|
||||||
result.userId = record.getUserId();
|
result.userId = record.getUserId();
|
||||||
result.scenicId = record.getScenicId();
|
result.scenicId = record.getScenicId();
|
||||||
|
|||||||
@@ -274,7 +274,7 @@ public class CouponServiceImpl implements ICouponService {
|
|||||||
request.getUserId(), request.getCouponId(), claimRecord.getId());
|
request.getUserId(), request.getCouponId(), claimRecord.getId());
|
||||||
|
|
||||||
// 10. 返回成功结果
|
// 10. 返回成功结果
|
||||||
return CouponClaimResult.success(claimRecord, coupon.getCouponName());
|
return CouponClaimResult.success(claimRecord, coupon);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("领取优惠券失败: userId={}, couponId={}",
|
log.error("领取优惠券失败: userId={}, couponId={}",
|
||||||
|
|||||||
@@ -137,10 +137,83 @@ public class VoucherUsageServiceImpl implements IVoucherUsageService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<VoucherUsageStatsResp> getBatchUsageStats(Long batchId) {
|
public List<VoucherUsageStatsResp> getBatchUsageStats(Long batchId) {
|
||||||
// 这里可以实现批次统计,暂时返回空列表
|
if (batchId == null) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 查询批次配置
|
||||||
|
PriceVoucherBatchConfig batchConfig = batchConfigMapper.selectById(batchId);
|
||||||
|
if (batchConfig == null || batchConfig.getDeleted() == 1) {
|
||||||
|
log.warn("批次配置不存在或已删除: batchId={}", batchId);
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询该批次下的所有券码
|
||||||
|
List<PriceVoucherCode> voucherCodes = voucherCodeMapper.selectByBatchId(batchId);
|
||||||
|
if (voucherCodes == null || voucherCodes.isEmpty()) {
|
||||||
|
log.info("批次下无券码数据: batchId={}", batchId);
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<VoucherUsageStatsResp> statsList = new ArrayList<>();
|
||||||
|
|
||||||
|
for (PriceVoucherCode voucherCode : voucherCodes) {
|
||||||
|
if (voucherCode.getDeleted() == 1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
VoucherUsageStatsResp stats = new VoucherUsageStatsResp();
|
||||||
|
stats.setVoucherCodeId(voucherCode.getId());
|
||||||
|
stats.setVoucherCode(voucherCode.getCode());
|
||||||
|
stats.setBatchId(batchConfig.getId());
|
||||||
|
stats.setBatchName(batchConfig.getBatchName());
|
||||||
|
stats.setScenicId(voucherCode.getScenicId());
|
||||||
|
stats.setStatus(voucherCode.getStatus());
|
||||||
|
|
||||||
|
// 设置状态名称
|
||||||
|
VoucherCodeStatus statusEnum = VoucherCodeStatus.getByCode(voucherCode.getStatus());
|
||||||
|
if (statusEnum != null) {
|
||||||
|
stats.setStatusName(statusEnum.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置使用次数相关信息
|
||||||
|
Integer currentUseCount = voucherCode.getCurrentUseCount() != null ?
|
||||||
|
voucherCode.getCurrentUseCount() : 0;
|
||||||
|
stats.setCurrentUseCount(currentUseCount);
|
||||||
|
stats.setMaxUseCount(batchConfig.getMaxUseCount());
|
||||||
|
stats.setMaxUsePerUser(batchConfig.getMaxUsePerUser());
|
||||||
|
stats.setUseIntervalHours(batchConfig.getUseIntervalHours());
|
||||||
|
|
||||||
|
// 计算是否还能使用
|
||||||
|
boolean canUseMore = true;
|
||||||
|
if (batchConfig.getMaxUseCount() != null) {
|
||||||
|
canUseMore = currentUseCount < batchConfig.getMaxUseCount();
|
||||||
|
}
|
||||||
|
stats.setCanUseMore(canUseMore);
|
||||||
|
|
||||||
|
// 计算剩余使用次数
|
||||||
|
if (batchConfig.getMaxUseCount() != null) {
|
||||||
|
int remaining = batchConfig.getMaxUseCount() - currentUseCount;
|
||||||
|
stats.setRemainingUseCount(Math.max(0, remaining));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取使用记录数
|
||||||
|
List<PriceVoucherUsageRecord> usageRecords = usageRecordMapper.selectByVoucherCodeId(voucherCode.getId());
|
||||||
|
stats.setTotalUsageRecords(usageRecords != null ? usageRecords.size() : 0);
|
||||||
|
|
||||||
|
// 格式化最后使用时间
|
||||||
|
if (voucherCode.getLastUsedTime() != null) {
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
stats.setLastUsedTime(sdf.format(voucherCode.getLastUsedTime()));
|
||||||
|
}
|
||||||
|
|
||||||
|
statsList.add(stats);
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("批次统计完成: batchId={}, 券码数量={}", batchId, statsList.size());
|
||||||
|
return statsList;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void recordVoucherUsage(String voucherCode, Long faceId, String orderId,
|
public void recordVoucherUsage(String voucherCode, Long faceId, String orderId,
|
||||||
BigDecimal discountAmount, String remark) {
|
BigDecimal discountAmount, String remark) {
|
||||||
|
|||||||
Reference in New Issue
Block a user