From b1deabc7c14fc196b1f13441afeb3afbc5320f0b Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Sat, 30 Aug 2025 11:41:37 +0800 Subject: [PATCH] =?UTF-8?q?feat(pricing):=20=E6=96=B0=E5=A2=9E=E6=89=93?= =?UTF-8?q?=E5=8D=B0=E5=B0=8F=E7=A5=A8=E5=92=8C=E6=9F=A5=E8=AF=A2=E5=88=B8?= =?UTF-8?q?=E7=A0=81=E6=89=B9=E6=AC=A1=E9=85=8D=E7=BD=AE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 AppClaimController 控制器处理移动设备端的领券请求 - 实现 ClaimReq 和 ClaimResp 模型类用于领券请求和响应 - 在 VoucherPrintService 接口中新增打印小票方法 - 在VoucherPrintServiceImpl 中实现打印小票和查询券码批次配置的逻辑 - 更新 PriceVoucherBatchConfigMapper 接口和 XML 文件,添加查询券码批次配置的方法 --- .../controller/mobile/AppClaimController.java | 89 +++++++++++ .../basic/model/mobile/claim/ClaimReq.java | 12 ++ .../basic/model/mobile/claim/ClaimResp.java | 13 ++ .../pricing/dto/req/VoucherPrintReq.java | 2 + .../pricing/dto/resp/VoucherPrintResp.java | 1 + .../mapper/PriceVoucherBatchConfigMapper.java | 7 + .../pricing/service/VoucherPrintService.java | 2 + .../service/impl/VoucherPrintServiceImpl.java | 140 ++++++++++++++++-- .../mapper/PriceVoucherBatchConfigMapper.xml | 84 +++++++++++ 9 files changed, 337 insertions(+), 13 deletions(-) create mode 100644 src/main/java/com/ycwl/basic/controller/mobile/AppClaimController.java create mode 100644 src/main/java/com/ycwl/basic/model/mobile/claim/ClaimReq.java create mode 100644 src/main/java/com/ycwl/basic/model/mobile/claim/ClaimResp.java create mode 100644 src/main/resources/mapper/PriceVoucherBatchConfigMapper.xml diff --git a/src/main/java/com/ycwl/basic/controller/mobile/AppClaimController.java b/src/main/java/com/ycwl/basic/controller/mobile/AppClaimController.java new file mode 100644 index 0000000..a9cd6d6 --- /dev/null +++ b/src/main/java/com/ycwl/basic/controller/mobile/AppClaimController.java @@ -0,0 +1,89 @@ +package com.ycwl.basic.controller.mobile; + +import com.ycwl.basic.model.mobile.claim.ClaimReq; +import com.ycwl.basic.model.mobile.claim.ClaimResp; +import com.ycwl.basic.model.pc.face.entity.FaceEntity; +import com.ycwl.basic.pricing.dto.CouponClaimRequest; +import com.ycwl.basic.pricing.dto.CouponClaimResult; +import com.ycwl.basic.pricing.dto.req.VoucherPrintReq; +import com.ycwl.basic.pricing.dto.resp.VoucherPrintResp; +import com.ycwl.basic.pricing.service.ICouponService; +import com.ycwl.basic.pricing.service.VoucherPrintService; +import com.ycwl.basic.repository.FaceRepository; +import com.ycwl.basic.repository.ScenicRepository; +import com.ycwl.basic.util.ScenicConfigManager; +import com.ycwl.basic.utils.ApiResponse; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api/mobile/claim/v1") +@AllArgsConstructor +public class AppClaimController { + private final FaceRepository faceRepository; + private final ScenicRepository scenicRepository; + private final VoucherPrintService voucherPrintService; + private final ICouponService couponService; + + + @PostMapping("tryClaim") + public ApiResponse tryClaim(@RequestBody ClaimReq req) { + FaceEntity face = faceRepository.getFace(req.getFaceId()); + if (face == null) { + return ApiResponse.fail("请选择人脸"); + } + ClaimResp claimResp = new ClaimResp(); + ScenicConfigManager scenicConfig = scenicRepository.getScenicConfigManager(face.getScenicId()); + if (Boolean.TRUE.equals(scenicConfig.getBoolean("voucher_enable"))) { + // 可以领券 + VoucherPrintResp voucherPrintResp = voucherPrintService.queryPrintedVoucher(face.getId()); + if (voucherPrintResp == null) { + // 打印 + voucherPrintResp = voucherPrintService.printVoucherTicket(new VoucherPrintReq(face.getId(), req.getMorphId(), face.getScenicId())); + } + if (voucherPrintResp != null) { + claimResp.setHasCoupon(false); + claimResp.setHasPrint(true); + claimResp.setHasPrint(voucherPrintResp.getPrintStatus() == 1); + claimResp.setPrintCode(voucherPrintResp.getCode()); + claimResp.setPrintType(voucherPrintResp.getType()); + return ApiResponse.success(claimResp); + } + } + if (Boolean.TRUE.equals(scenicConfig.getBoolean("booking_enable"))) { + VoucherPrintResp voucherPrintResp = voucherPrintService.queryPrintedVoucher(face.getId()); + if (voucherPrintResp == null) { + // 打印 + voucherPrintResp = voucherPrintService.printBookingTicket(new VoucherPrintReq(face.getId(), req.getMorphId(), face.getScenicId())); + } + if (voucherPrintResp != null) { + claimResp.setHasCoupon(false); + claimResp.setHasPrint(true); + claimResp.setHasPrint(voucherPrintResp.getPrintStatus() == 1); + claimResp.setPrintCode(voucherPrintResp.getCode()); + claimResp.setPrintType(voucherPrintResp.getType()); + return ApiResponse.success(claimResp); + } + } + if (req.getType() != null) { + // 第几次进入 + Integer couponId = scenicConfig.getInteger("coupon_id_for_type_" + req.getType()); + if (couponId != null) { + // 可以领券 + CouponClaimRequest request = new CouponClaimRequest(face.getMemberId(), Long.valueOf(couponId)); + CouponClaimResult claimResult = couponService.claimCoupon(request); + if (claimResult.isSuccess()) { + // 领到了 + claimResp.setHasCoupon(true); + claimResp.setCouponDesc(scenicConfig.getString("coupon_desc_for_type_" + req.getType(), "专属折扣券")); + claimResp.setCouponCountdown(scenicConfig.getString("coupon_countdown_for_type_" + req.getType(), "送你优惠,保存美好!")); + return ApiResponse.success(claimResp); + } + } + } + return ApiResponse.fail("异常"); + } +} diff --git a/src/main/java/com/ycwl/basic/model/mobile/claim/ClaimReq.java b/src/main/java/com/ycwl/basic/model/mobile/claim/ClaimReq.java new file mode 100644 index 0000000..047a07e --- /dev/null +++ b/src/main/java/com/ycwl/basic/model/mobile/claim/ClaimReq.java @@ -0,0 +1,12 @@ +package com.ycwl.basic.model.mobile.claim; + +import lombok.Data; + +@Data +public class ClaimReq { + private Long faceId; + // 扫码进入的推客ID + private Long morphId; + // 通知进入的type + private Integer type; +} diff --git a/src/main/java/com/ycwl/basic/model/mobile/claim/ClaimResp.java b/src/main/java/com/ycwl/basic/model/mobile/claim/ClaimResp.java new file mode 100644 index 0000000..8fb772f --- /dev/null +++ b/src/main/java/com/ycwl/basic/model/mobile/claim/ClaimResp.java @@ -0,0 +1,13 @@ +package com.ycwl.basic.model.mobile.claim; + +import lombok.Data; + +@Data +public class ClaimResp { + private Boolean hasPrint; + private String printType; + private String printCode; + private Boolean hasCoupon; + private String couponDesc; + private String couponCountdown; +} diff --git a/src/main/java/com/ycwl/basic/pricing/dto/req/VoucherPrintReq.java b/src/main/java/com/ycwl/basic/pricing/dto/req/VoucherPrintReq.java index dcfe54e..06f9336 100644 --- a/src/main/java/com/ycwl/basic/pricing/dto/req/VoucherPrintReq.java +++ b/src/main/java/com/ycwl/basic/pricing/dto/req/VoucherPrintReq.java @@ -1,11 +1,13 @@ package com.ycwl.basic.pricing.dto.req; +import lombok.AllArgsConstructor; import lombok.Data; /** * 打印小票请求 */ @Data +@AllArgsConstructor public class VoucherPrintReq { private Long faceId; diff --git a/src/main/java/com/ycwl/basic/pricing/dto/resp/VoucherPrintResp.java b/src/main/java/com/ycwl/basic/pricing/dto/resp/VoucherPrintResp.java index 4a9e552..1909c96 100644 --- a/src/main/java/com/ycwl/basic/pricing/dto/resp/VoucherPrintResp.java +++ b/src/main/java/com/ycwl/basic/pricing/dto/resp/VoucherPrintResp.java @@ -14,6 +14,7 @@ public class VoucherPrintResp { * 流水号 */ private String code; + private String type; /** * 券码 diff --git a/src/main/java/com/ycwl/basic/pricing/mapper/PriceVoucherBatchConfigMapper.java b/src/main/java/com/ycwl/basic/pricing/mapper/PriceVoucherBatchConfigMapper.java index 566f65d..7b5925a 100644 --- a/src/main/java/com/ycwl/basic/pricing/mapper/PriceVoucherBatchConfigMapper.java +++ b/src/main/java/com/ycwl/basic/pricing/mapper/PriceVoucherBatchConfigMapper.java @@ -44,4 +44,11 @@ public interface PriceVoucherBatchConfigMapper extends BaseMapper"; - content += "赠品兑换码"; + content += ""+voucherPrintResp.getCode()+""; + content += ""+voucherPrintResp.getType()+""; content += "有效期:"+sdf2.format(new Date())+""; - FeiETicketPrinter.doPrint("550519002", content, 1); +// FeiETicketPrinter.doPrint("550519002", content, 1); + log.info("打印完成->内容:\n{}", content); } } \ No newline at end of file diff --git a/src/main/resources/mapper/PriceVoucherBatchConfigMapper.xml b/src/main/resources/mapper/PriceVoucherBatchConfigMapper.xml new file mode 100644 index 0000000..4575abd --- /dev/null +++ b/src/main/resources/mapper/PriceVoucherBatchConfigMapper.xml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + id, batch_name, scenic_id, broker_id, discount_type, discount_value, + total_count, used_count, claimed_count, status, create_time, update_time, + create_by, update_by, deleted, deleted_at + + + + + + + + UPDATE price_voucher_batch_config + SET claimed_count = claimed_count + #{increment}, + update_time = NOW() + WHERE id = #{batchId} + AND deleted = 0 + + + + + UPDATE price_voucher_batch_config + SET used_count = used_count + #{increment}, + update_time = NOW() + WHERE id = #{batchId} + AND deleted = 0 + + + + + + + + + \ No newline at end of file