From e82597d5268d71cb5a4e903b07d7f588150c5a91 Mon Sep 17 00:00:00 2001 From: xuhy <3313886187@qq.com> Date: 星期二, 17 十二月 2024 14:12:28 +0800 Subject: [PATCH] 小程序 --- applet/src/main/java/com/jilongda/applet/controller/TCouponReceiveController.java | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 55 insertions(+), 2 deletions(-) diff --git a/applet/src/main/java/com/jilongda/applet/controller/TCouponReceiveController.java b/applet/src/main/java/com/jilongda/applet/controller/TCouponReceiveController.java index 48f2d8f..6ca9fc1 100644 --- a/applet/src/main/java/com/jilongda/applet/controller/TCouponReceiveController.java +++ b/applet/src/main/java/com/jilongda/applet/controller/TCouponReceiveController.java @@ -1,9 +1,23 @@ package com.jilongda.applet.controller; -import org.springframework.web.bind.annotation.RequestMapping; +import com.jilongda.applet.model.TCoupon; +import com.jilongda.applet.model.TCouponReceive; +import com.jilongda.applet.query.TCouponQuery; +import com.jilongda.applet.service.TCouponReceiveService; +import com.jilongda.applet.service.TCouponService; +import com.jilongda.applet.service.TStoreService; +import com.jilongda.applet.utils.LoginInfoUtil; +import com.jilongda.applet.vo.TCouponReceiveVO; +import com.jilongda.common.basic.ApiResult; +import com.jilongda.common.basic.PageInfo; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; -import org.springframework.web.bind.annotation.RestController; +import java.time.LocalDateTime; +import java.util.Objects; /** * <p> @@ -13,9 +27,48 @@ * @author 无关风月 * @since 2024-12-09 */ +@Api(tags = "优惠券记录") @RestController @RequestMapping("/t-coupon-receive") public class TCouponReceiveController { + @Autowired + private TCouponReceiveService tCouponReceiveService; + @Autowired + private TCouponService couponService; + @Autowired + private LoginInfoUtil loginInfoUtil; + @ApiOperation(value = "优惠券列表") + @PostMapping(value = "/pageList") + public ApiResult pageList(@RequestBody TCouponQuery query) { + Integer userId = loginInfoUtil.getUserId(); + query.setUserId(userId); + PageInfo<TCouponReceiveVO> page = tCouponReceiveService.pageList(query); + return ApiResult.success(page); + } + + @ApiOperation(value = "扫码领取优惠券;优惠券id") + @GetMapping(value = "/getCoupons") + public ApiResult getCoupons(@RequestParam Integer id) { + Integer userId = loginInfoUtil.getUserId(); + + // 查询优惠券信息 + TCoupon coupon = couponService.getById(id); + if(Objects.isNull(coupon)){ + return ApiResult.failed("优惠券不存在"); + } + + TCouponReceive tCouponReceive = new TCouponReceive(); + tCouponReceive.setUserId(userId); + tCouponReceive.setCouponId(id); + tCouponReceive.setType(4); + tCouponReceive.setAmount(coupon.getAmount()); + tCouponReceive.setStoreId(coupon.getStoreId()); + tCouponReceive.setEndTime(LocalDateTime.now().plusDays(coupon.getTime())); + tCouponReceive.setAmountCondition(coupon.getAmountCondition()); + tCouponReceive.setStatus(1); + tCouponReceiveService.save(tCouponReceive); + return ApiResult.success(); + } } -- Gitblit v1.7.1