From b046963a423bf01b14bb5b6e20c598fb79d9e063 Mon Sep 17 00:00:00 2001 From: 18650502300 <18650502300@163.com> Date: Tue, 3 Sep 2024 15:54:11 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E4=BC=98=E6=83=A0=E5=88=B8=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/app/AppController.java | 5 +++ .../controller/app/AppVerifyController.java | 40 ++++++++++++------ .../system/EtCouponClaimLogController.java | 20 ++++----- .../controller/system/SysLoginController.java | 4 ++ .../common/constant/ServiceConstants.java | 21 ++++++++++ .../common/core/domain/entity/AsUser.java | 23 ++++++++++ .../com/ruoyi/common/utils/DateUtils.java | 34 +++++++++++++++ .../com/ruoyi/system/domain/EtCoupon.java | 15 +++++-- ...uponClaimLog.java => EtCouponUserLog.java} | 13 +++++- .../system/mapper/EtCouponClaimLogMapper.java | 16 +++---- .../service/IEtCouponClaimLogService.java | 16 +++---- .../impl/EtCouponClaimLogServiceImpl.java | 24 +++++------ .../service/impl/EtCouponServiceImpl.java | 42 ++++++++++++++----- .../java/com/ruoyi/system/task/EtTask.java | 33 +++++++++++++++ .../resources/mapper/system/AsUserMapper.xml | 10 ++++- .../mapper/system/EtCouponClaimLogMapper.xml | 22 +++++----- .../mapper/system/EtCouponMapper.xml | 38 ++++++++++------- 17 files changed, 281 insertions(+), 95 deletions(-) rename electripper-system/src/main/java/com/ruoyi/system/domain/{EtCouponClaimLog.java => EtCouponUserLog.java} (81%) diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppController.java index 991c215..cfc72b3 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppController.java @@ -686,6 +686,11 @@ public class AppController extends BaseController @GetMapping("/couponList") public AjaxResult list(EtCoupon etCoupon) { + if(etCoupon.getType().contains(",")){ + String[] typeList = etCoupon.getType().split(","); + etCoupon.setTypeList(typeList); + etCoupon.setType(null); + } List list = etCouponService.selectEtCouponList(etCoupon); return success(list); } diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppVerifyController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppVerifyController.java index 1358c84..2b4f5b9 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppVerifyController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppVerifyController.java @@ -1299,31 +1299,45 @@ public class AppVerifyController extends BaseController } /** - * 根据用户搜索优惠券 + * 我的骑行卡(未使用) */ @GetMapping("/getCouponListByUserId") - public AjaxResult list(Long userId) + public AjaxResult getCouponListByUserId(Long userId) { logger.info("根据用户搜索优惠券:【userId="+userId+"】"); - EtCouponClaimLog etCouponClaimLog = new EtCouponClaimLog(); - etCouponClaimLog.setUserId(userId); - etCouponClaimLog.setStatus(ServiceConstants.COUPON_STATUS_UNUSED); - etCouponClaimLog.setStatusList(new String[]{ServiceConstants.COUPON_STATUS_UNUSED, ServiceConstants.COUPON_STATUS_EXPIRED}); - List list = etCouponClaimLogService.selectEtCouponClaimLogList(etCouponClaimLog); + EtCouponUserLog etCouponUserLog = new EtCouponUserLog(); + etCouponUserLog.setUserId(userId); + etCouponUserLog.setStatus(ServiceConstants.COUPON_STATUS_UNUSED); + etCouponUserLog.setStatusList(new String[]{ServiceConstants.COUPON_STATUS_UNUSED, ServiceConstants.COUPON_STATUS_EXPIRED}); + List list = etCouponClaimLogService.selectEtCouponClaimLogList(etCouponUserLog); return success(list); } /** - * 优惠券使用记录 + * 优惠券使用记录(已使用) */ @GetMapping("/getCouponUsageRecord") public AjaxResult getCouponUsageRecord(Long userId) { - logger.info("优惠券使用记录:【userId="+userId+"】"); - EtCouponClaimLog etCouponClaimLog = new EtCouponClaimLog(); - etCouponClaimLog.setUserId(userId); - etCouponClaimLog.setStatus(ServiceConstants.COUPON_STATUS_USED); - List list = etCouponClaimLogService.selectEtCouponClaimLogList(etCouponClaimLog); + logger.info("【优惠券使用记录(已使用)】:【userId="+userId+"】"); + EtCouponUserLog etCouponUserLog = new EtCouponUserLog(); + etCouponUserLog.setUserId(userId); + etCouponUserLog.setStatus(ServiceConstants.COUPON_STATUS_USED); + List list = etCouponClaimLogService.selectEtCouponClaimLogList(etCouponUserLog); + return success(list); + } + + /** + * 优惠券购买记录 + */ + @GetMapping("/couponBuyRecord") + public AjaxResult couponBuyRecord(Long userId) + { + logger.info("【优惠券购买记录】:【userId="+userId+"】"); + EtCouponUserLog etCouponUserLog = new EtCouponUserLog(); + etCouponUserLog.setUserId(userId); + etCouponUserLog.setGainMethod(ServiceConstants.COUPON_GAIN_METHOD_BUY); + List list = etCouponClaimLogService.selectEtCouponClaimLogList(etCouponUserLog); return success(list); } diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtCouponClaimLogController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtCouponClaimLogController.java index b640aee..cf3f065 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtCouponClaimLogController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtCouponClaimLogController.java @@ -16,7 +16,7 @@ import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.enums.BusinessType; -import com.ruoyi.system.domain.EtCouponClaimLog; +import com.ruoyi.system.domain.EtCouponUserLog; import com.ruoyi.system.service.IEtCouponClaimLogService; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.core.page.TableDataInfo; @@ -39,10 +39,10 @@ public class EtCouponClaimLogController extends BaseController */ @PreAuthorize("@ss.hasPermi('system:claimLog:list')") @GetMapping("/list") - public TableDataInfo list(EtCouponClaimLog etCouponClaimLog) + public TableDataInfo list(EtCouponUserLog etCouponUserLog) { startPage(); - List list = etCouponClaimLogService.selectEtCouponClaimLogList(etCouponClaimLog); + List list = etCouponClaimLogService.selectEtCouponClaimLogList(etCouponUserLog); return getDataTable(list); } @@ -52,10 +52,10 @@ public class EtCouponClaimLogController extends BaseController @PreAuthorize("@ss.hasPermi('system:claimLog:export')") @Log(title = "优惠券领取记录", businessType = BusinessType.EXPORT) @PostMapping("/export") - public void export(HttpServletResponse response, EtCouponClaimLog etCouponClaimLog) + public void export(HttpServletResponse response, EtCouponUserLog etCouponUserLog) { - List list = etCouponClaimLogService.selectEtCouponClaimLogList(etCouponClaimLog); - ExcelUtil util = new ExcelUtil(EtCouponClaimLog.class); + List list = etCouponClaimLogService.selectEtCouponClaimLogList(etCouponUserLog); + ExcelUtil util = new ExcelUtil(EtCouponUserLog.class); util.exportExcel(response, list, "优惠券领取记录数据"); } @@ -75,9 +75,9 @@ public class EtCouponClaimLogController extends BaseController @PreAuthorize("@ss.hasPermi('system:claimLog:add')") @Log(title = "优惠券领取记录", businessType = BusinessType.INSERT) @PostMapping - public AjaxResult add(@RequestBody EtCouponClaimLog etCouponClaimLog) + public AjaxResult add(@RequestBody EtCouponUserLog etCouponUserLog) { - return toAjax(etCouponClaimLogService.insertEtCouponClaimLog(etCouponClaimLog)); + return toAjax(etCouponClaimLogService.insertEtCouponClaimLog(etCouponUserLog)); } /** @@ -86,9 +86,9 @@ public class EtCouponClaimLogController extends BaseController @PreAuthorize("@ss.hasPermi('system:claimLog:edit')") @Log(title = "优惠券领取记录", businessType = BusinessType.UPDATE) @PutMapping - public AjaxResult edit(@RequestBody EtCouponClaimLog etCouponClaimLog) + public AjaxResult edit(@RequestBody EtCouponUserLog etCouponUserLog) { - return toAjax(etCouponClaimLogService.updateEtCouponClaimLog(etCouponClaimLog)); + return toAjax(etCouponClaimLogService.updateEtCouponClaimLog(etCouponUserLog)); } /** diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java index ac1bae9..1a948ec 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java @@ -16,6 +16,7 @@ import com.ruoyi.framework.web.service.SysLoginService; import com.ruoyi.framework.web.service.SysPermissionService; import com.ruoyi.system.mapper.AsUserMapper; import com.ruoyi.system.service.IAsUserService; +import com.ruoyi.system.service.IEtCouponClaimLogService; import com.ruoyi.system.service.ISysDeptService; import com.ruoyi.system.service.ISysMenuService; import lombok.extern.slf4j.Slf4j; @@ -56,6 +57,9 @@ public class SysLoginController @Resource private AsUserMapper asUserMapper; + @Autowired + private IEtCouponClaimLogService etCouponClaimLogService; + /** * 登录方法 diff --git a/electripper-common/src/main/java/com/ruoyi/common/constant/ServiceConstants.java b/electripper-common/src/main/java/com/ruoyi/common/constant/ServiceConstants.java index da4dd33..168eff4 100644 --- a/electripper-common/src/main/java/com/ruoyi/common/constant/ServiceConstants.java +++ b/electripper-common/src/main/java/com/ruoyi/common/constant/ServiceConstants.java @@ -718,5 +718,26 @@ public class ServiceConstants { /**----------------------------优惠券状态end----------------------------*/ + /**----------------------------优惠券类型start----------------------------*/ + /** 类型:1-时间卡;2-贵宾卡;3-折扣卡;4-抵用券 + /** + * 1-时间卡 + */ + public static final String COUPON_TYPE_TIME_CARD = "1"; + /** + * 2-贵宾卡 + */ + public static final String COUPON_TYPE_VIP_CARD = "2"; + /** + * 3-折扣卡 + */ + public static final String COUPON_TYPE_DISCOUNT_CARD = "3"; + /** + * 4-抵用券 + */ + public static final String COUPON_TYPE_VOUCHER = "4"; + + /**----------------------------优惠券类型end----------------------------*/ + } diff --git a/electripper-common/src/main/java/com/ruoyi/common/core/domain/entity/AsUser.java b/electripper-common/src/main/java/com/ruoyi/common/core/domain/entity/AsUser.java index 874e585..eee6f2a 100644 --- a/electripper-common/src/main/java/com/ruoyi/common/core/domain/entity/AsUser.java +++ b/electripper-common/src/main/java/com/ruoyi/common/core/domain/entity/AsUser.java @@ -1,5 +1,6 @@ package com.ruoyi.common.core.domain.entity; +import com.fasterxml.jackson.annotation.JsonFormat; import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.annotation.Excel.ColumnType; import com.ruoyi.common.annotation.Excel.Type; @@ -118,6 +119,28 @@ public class AsUser extends BaseEntity /** appId*/ public String appId; + /** 会员类型 : 0-无会员,1-普通会员,2-贵宾会员 */ + public String vipType; + + /** 有效时间 */ + private Date expirationTime; + + public String getVipType() { + return vipType; + } + + public void setVipType(String vipType) { + this.vipType = vipType; + } + + public Date getExpirationTime() { + return expirationTime; + } + + public void setExpirationTime(Date expirationTime) { + this.expirationTime = expirationTime; + } + public String getAppId() { return appId; } diff --git a/electripper-common/src/main/java/com/ruoyi/common/utils/DateUtils.java b/electripper-common/src/main/java/com/ruoyi/common/utils/DateUtils.java index 8ad0186..c56ddbe 100644 --- a/electripper-common/src/main/java/com/ruoyi/common/utils/DateUtils.java +++ b/electripper-common/src/main/java/com/ruoyi/common/utils/DateUtils.java @@ -334,4 +334,38 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils // 判断是否大于 60,000 毫秒(1 分钟) return difference > 60_000; } + + /** + * 根据有效期单位和有效期值,返回一个加上固定多少单位的时间 + * + * @param startDate 起始日期 + * @param validityUnit 有效期单位:day-天;week-周;month-月;quarter-季度;year-年 + * @param validityValue 有效期值 + * @return 加上有效期后的时间 + */ + public static Date addValidity(Date startDate, String validityUnit, Integer validityValue) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(startDate); + + switch (validityUnit.toLowerCase()) { + case "day": // 天 + calendar.add(Calendar.DAY_OF_MONTH, validityValue); + break; + case "week": // 周 + calendar.add(Calendar.WEEK_OF_YEAR, validityValue); + break; + case "month": // 月 + calendar.add(Calendar.MONTH, validityValue); + break; + case "quarter": // 季度 + calendar.add(Calendar.MONTH, validityValue * 3); + break; + case "year": // 年 + calendar.add(Calendar.YEAR, validityValue); + break; + default: + throw new IllegalArgumentException("无效的有效期单位: " + validityUnit); + } + return calendar.getTime(); // 返回新的时间 + } } diff --git a/electripper-system/src/main/java/com/ruoyi/system/domain/EtCoupon.java b/electripper-system/src/main/java/com/ruoyi/system/domain/EtCoupon.java index 297b9a4..8b6a914 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/domain/EtCoupon.java +++ b/electripper-system/src/main/java/com/ruoyi/system/domain/EtCoupon.java @@ -23,6 +23,9 @@ public class EtCoupon extends BaseEntity /** 优惠券id */ private Long couponId; + /** 名称 */ + private String name; + /** 类型 */ @Excel(name = "类型") private String type; @@ -63,9 +66,9 @@ public class EtCoupon extends BaseEntity @Excel(name = "描述") private String desc; - /** 零食价 */ - @Excel(name = "零食价") - private BigDecimal snackPrice; + /** 零售价 */ + @Excel(name = "零售价") + private BigDecimal retailPrice; /** 有效期值 */ @Excel(name = "有效期值") @@ -74,4 +77,10 @@ public class EtCoupon extends BaseEntity /** 有效期单位 */ @Excel(name = "有效期单位") private String validityUnit; + + /** 类型列表 */ + private String[] typeList; + + /** 是否热门:0-非热门;1-热门 */ + private String isHot; } diff --git a/electripper-system/src/main/java/com/ruoyi/system/domain/EtCouponClaimLog.java b/electripper-system/src/main/java/com/ruoyi/system/domain/EtCouponUserLog.java similarity index 81% rename from electripper-system/src/main/java/com/ruoyi/system/domain/EtCouponClaimLog.java rename to electripper-system/src/main/java/com/ruoyi/system/domain/EtCouponUserLog.java index 768ce09..c7c118e 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/domain/EtCouponClaimLog.java +++ b/electripper-system/src/main/java/com/ruoyi/system/domain/EtCouponUserLog.java @@ -6,16 +6,17 @@ import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.core.domain.BaseEntity; import lombok.Data; +import java.math.BigDecimal; import java.util.Date; /** - * 优惠券领取记录对象 et_coupon_user_log + * 我的优惠券对象 et_coupon_user_log * * @author qzz * @date 2024-08-08 */ @Data -public class EtCouponClaimLog extends BaseEntity +public class EtCouponUserLog extends BaseEntity { private static final long serialVersionUID = 1L; @@ -42,6 +43,14 @@ public class EtCouponClaimLog extends BaseEntity @Excel(name = "优惠券") private Long couponId; + /** 优惠券名称 */ + @Excel(name = "优惠券名称") + private String couponName; + + /** 零售价 */ + @Excel(name = "零售价") + private BigDecimal retailPrice; + /** 获取方式:claim-领取;buy-购买;issue-下发 */ @Excel(name = "获取方式:claim-领取;buy-购买;issue-下发") private String gainMethod; diff --git a/electripper-system/src/main/java/com/ruoyi/system/mapper/EtCouponClaimLogMapper.java b/electripper-system/src/main/java/com/ruoyi/system/mapper/EtCouponClaimLogMapper.java index c179742..f088396 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/mapper/EtCouponClaimLogMapper.java +++ b/electripper-system/src/main/java/com/ruoyi/system/mapper/EtCouponClaimLogMapper.java @@ -1,7 +1,7 @@ package com.ruoyi.system.mapper; import java.util.List; -import com.ruoyi.system.domain.EtCouponClaimLog; +import com.ruoyi.system.domain.EtCouponUserLog; /** * 优惠券领取记录Mapper接口 @@ -17,31 +17,31 @@ public interface EtCouponClaimLogMapper * @param claimId 优惠券领取记录主键 * @return 优惠券领取记录 */ - public EtCouponClaimLog selectEtCouponClaimLogByLogId(Long claimId); + public EtCouponUserLog selectEtCouponClaimLogByLogId(Long claimId); /** * 查询优惠券领取记录列表 * - * @param etCouponClaimLog 优惠券领取记录 + * @param etCouponUserLog 优惠券领取记录 * @return 优惠券领取记录集合 */ - public List selectEtCouponClaimLogList(EtCouponClaimLog etCouponClaimLog); + public List selectEtCouponClaimLogList(EtCouponUserLog etCouponUserLog); /** * 新增优惠券领取记录 * - * @param etCouponClaimLog 优惠券领取记录 + * @param etCouponUserLog 优惠券领取记录 * @return 结果 */ - public int insertEtCouponClaimLog(EtCouponClaimLog etCouponClaimLog); + public int insertEtCouponClaimLog(EtCouponUserLog etCouponUserLog); /** * 修改优惠券领取记录 * - * @param etCouponClaimLog 优惠券领取记录 + * @param etCouponUserLog 优惠券领取记录 * @return 结果 */ - public int updateEtCouponClaimLog(EtCouponClaimLog etCouponClaimLog); + public int updateEtCouponClaimLog(EtCouponUserLog etCouponUserLog); /** * 删除优惠券领取记录 diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/IEtCouponClaimLogService.java b/electripper-system/src/main/java/com/ruoyi/system/service/IEtCouponClaimLogService.java index 061c84d..c87b693 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/IEtCouponClaimLogService.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/IEtCouponClaimLogService.java @@ -1,7 +1,7 @@ package com.ruoyi.system.service; import java.util.List; -import com.ruoyi.system.domain.EtCouponClaimLog; +import com.ruoyi.system.domain.EtCouponUserLog; /** * 优惠券领取记录Service接口 @@ -17,31 +17,31 @@ public interface IEtCouponClaimLogService * @param claimId 优惠券领取记录主键 * @return 优惠券领取记录 */ - public EtCouponClaimLog selectEtCouponClaimLogByLogId(Long claimId); + public EtCouponUserLog selectEtCouponClaimLogByLogId(Long claimId); /** * 查询优惠券领取记录列表 * - * @param etCouponClaimLog 优惠券领取记录 + * @param etCouponUserLog 优惠券领取记录 * @return 优惠券领取记录集合 */ - public List selectEtCouponClaimLogList(EtCouponClaimLog etCouponClaimLog); + public List selectEtCouponClaimLogList(EtCouponUserLog etCouponUserLog); /** * 新增优惠券领取记录 * - * @param etCouponClaimLog 优惠券领取记录 + * @param etCouponUserLog 优惠券领取记录 * @return 结果 */ - public int insertEtCouponClaimLog(EtCouponClaimLog etCouponClaimLog); + public int insertEtCouponClaimLog(EtCouponUserLog etCouponUserLog); /** * 修改优惠券领取记录 * - * @param etCouponClaimLog 优惠券领取记录 + * @param etCouponUserLog 优惠券领取记录 * @return 结果 */ - public int updateEtCouponClaimLog(EtCouponClaimLog etCouponClaimLog); + public int updateEtCouponClaimLog(EtCouponUserLog etCouponUserLog); /** * 批量删除优惠券领取记录 diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtCouponClaimLogServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtCouponClaimLogServiceImpl.java index 5f5d5dc..46a65ee 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtCouponClaimLogServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtCouponClaimLogServiceImpl.java @@ -5,7 +5,7 @@ import com.ruoyi.common.utils.DateUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.system.mapper.EtCouponClaimLogMapper; -import com.ruoyi.system.domain.EtCouponClaimLog; +import com.ruoyi.system.domain.EtCouponUserLog; import com.ruoyi.system.service.IEtCouponClaimLogService; /** @@ -27,7 +27,7 @@ public class EtCouponClaimLogServiceImpl implements IEtCouponClaimLogService * @return 优惠券领取记录 */ @Override - public EtCouponClaimLog selectEtCouponClaimLogByLogId(Long claimId) + public EtCouponUserLog selectEtCouponClaimLogByLogId(Long claimId) { return etCouponClaimLogMapper.selectEtCouponClaimLogByLogId(claimId); } @@ -35,38 +35,38 @@ public class EtCouponClaimLogServiceImpl implements IEtCouponClaimLogService /** * 查询优惠券领取记录列表 * - * @param etCouponClaimLog 优惠券领取记录 + * @param etCouponUserLog 优惠券领取记录 * @return 优惠券领取记录 */ @Override - public List selectEtCouponClaimLogList(EtCouponClaimLog etCouponClaimLog) + public List selectEtCouponClaimLogList(EtCouponUserLog etCouponUserLog) { - return etCouponClaimLogMapper.selectEtCouponClaimLogList(etCouponClaimLog); + return etCouponClaimLogMapper.selectEtCouponClaimLogList(etCouponUserLog); } /** * 新增优惠券领取记录 * - * @param etCouponClaimLog 优惠券领取记录 + * @param etCouponUserLog 优惠券领取记录 * @return 结果 */ @Override - public int insertEtCouponClaimLog(EtCouponClaimLog etCouponClaimLog) + public int insertEtCouponClaimLog(EtCouponUserLog etCouponUserLog) { - etCouponClaimLog.setCreateTime(DateUtils.getNowDate()); - return etCouponClaimLogMapper.insertEtCouponClaimLog(etCouponClaimLog); + etCouponUserLog.setCreateTime(DateUtils.getNowDate()); + return etCouponClaimLogMapper.insertEtCouponClaimLog(etCouponUserLog); } /** * 修改优惠券领取记录 * - * @param etCouponClaimLog 优惠券领取记录 + * @param etCouponUserLog 优惠券领取记录 * @return 结果 */ @Override - public int updateEtCouponClaimLog(EtCouponClaimLog etCouponClaimLog) + public int updateEtCouponClaimLog(EtCouponUserLog etCouponUserLog) { - return etCouponClaimLogMapper.updateEtCouponClaimLog(etCouponClaimLog); + return etCouponClaimLogMapper.updateEtCouponClaimLog(etCouponUserLog); } /** diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtCouponServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtCouponServiceImpl.java index 62e20ca..b8222b1 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtCouponServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtCouponServiceImpl.java @@ -1,5 +1,6 @@ package com.ruoyi.system.service.impl; +import java.util.Date; import java.util.List; import cn.hutool.core.util.ObjectUtil; @@ -135,16 +136,35 @@ public class EtCouponServiceImpl implements IEtCouponService * */ // 1. 插入一条记录,et_coupon_user_log 获取方式是购买 AsUser asUser = userMapper.selectUserById(userId); + if(ObjectUtil.isNull(asUser)){ + throw new ServiceException("用户【"+userId+"】不存在"); + } EtCoupon etCoupon = etCouponMapper.selectEtCouponByCouponId(couponId); - EtCouponClaimLog etCouponClaimLog = new EtCouponClaimLog(); - etCouponClaimLog.setCouponId(couponId); - etCouponClaimLog.setUserId(userId); - etCouponClaimLog.setUserName(asUser.getUserName()); - etCouponClaimLog.setCreateTime(DateUtils.getNowDate()); - etCouponClaimLog.setGainMethod(ServiceConstants.COUPON_GAIN_METHOD_BUY); - etCouponClaimLog.setAreaId(etCoupon.getAreaId()); - etCouponClaimLog.setAreaName(etCoupon.getAreaName()); - int i1 = etCouponClaimLogMapper.insertEtCouponClaimLog(etCouponClaimLog); + if(ObjectUtil.isNull(etCoupon)){ + throw new ServiceException("优惠券【"+couponId+"】不存在"); + } + EtCouponUserLog etCouponUserLog = new EtCouponUserLog(); + etCouponUserLog.setCouponId(couponId); + etCouponUserLog.setUserId(userId); + etCouponUserLog.setUserName(asUser.getUserName()); + etCouponUserLog.setCreateTime(DateUtils.getNowDate()); + etCouponUserLog.setGainMethod(ServiceConstants.COUPON_GAIN_METHOD_BUY); + etCouponUserLog.setAreaId(etCoupon.getAreaId()); + etCouponUserLog.setAreaName(etCoupon.getAreaName()); + etCouponUserLog.setExpirationTime(DateUtils.addValidity(new Date(),etCoupon.getValidityUnit(),etCoupon.getValidityValue())); + if(ServiceConstants.COUPON_TYPE_TIME_CARD.equals(etCoupon.getType()) || ServiceConstants.COUPON_TYPE_VIP_CARD.equals(etCoupon.getType())){ + AsUser asUser1 = new AsUser(userId); + asUser1.setVipType(etCoupon.getType()); + Date expirationTime; + if(ObjectUtil.isNull(asUser.getExpirationTime())){ + expirationTime = DateUtils.getNowDate(); + }else{ + expirationTime = asUser.getExpirationTime(); + } + asUser1.setExpirationTime(DateUtils.addValidity(expirationTime,etCoupon.getValidityUnit(),etCoupon.getValidityValue())); + int updateUser = userMapper.updateUser(asUser1); + } + int i1 = etCouponClaimLogMapper.insertEtCouponClaimLog(etCouponUserLog); if(i1 == 0){ throw new ServiceException("保存优惠券领取记录失败"); } @@ -175,8 +195,8 @@ public class EtCouponServiceImpl implements IEtCouponService /** 订单类型 1骑行 2预约 3套餐 4押金 根据类型不同下单的参数也不同,不同的参数有: 金额、类型、rule_id(套餐id)*/ etOrder.setArea(etCoupon.getAreaName()); etOrder.setType(ServiceConstants.ORDER_TYPE_COUPON); - etOrder.setTotalFee(etCoupon.getSnackPrice()); - etOrder.setPayFee(etCoupon.getSnackPrice()); + etOrder.setTotalFee(etCoupon.getRetailPrice()); + etOrder.setPayFee(etCoupon.getRetailPrice()); return etOrder; } } diff --git a/electripper-system/src/main/java/com/ruoyi/system/task/EtTask.java b/electripper-system/src/main/java/com/ruoyi/system/task/EtTask.java index e1920f7..1266d1d 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/task/EtTask.java +++ b/electripper-system/src/main/java/com/ruoyi/system/task/EtTask.java @@ -94,6 +94,9 @@ public class EtTask { @Autowired private IEtModelService etModelService; + @Autowired + private EtCouponClaimLogMapper etCouponClaimLogMapper; + /** * 1.启动时判断是否有未取消预约的订单 @@ -692,4 +695,34 @@ public class EtTask { return parts; } + + /** + * 判断优惠券是否过期 + * + */ + public void couponIsExpires(){ + log.info("-------------------【定时任务】判断优惠券是否过期---开始----------------"); + EtCouponUserLog etCouponUserLog = new EtCouponUserLog(); + etCouponUserLog.setStatus(ServiceConstants.COUPON_STATUS_UNUSED); + List couponUserLogs = etCouponClaimLogMapper.selectEtCouponClaimLogList(etCouponUserLog); + // 获取当前时间 + Date currentTime = new Date(); + for(EtCouponUserLog couponLog :couponUserLogs){ + // 获取优惠券的过期时间 + Date expirationTime = couponLog.getExpirationTime(); + // 判断优惠券是否过期 + if (expirationTime != null && expirationTime.before(currentTime)) { + // 如果过期,更新状态为已过期 + couponLog.setStatus(ServiceConstants.COUPON_STATUS_EXPIRED); + // 更新到数据库 + int result = etCouponClaimLogMapper.updateEtCouponClaimLog(couponLog); + if (result > 0) { + log.info("优惠券ID: {} 已过期,状态已更新为 EXPIRED", couponLog.getCouponId()); + } else { + log.warn("优惠券ID: {} 更新状态失败", couponLog.getCouponId()); + } + } + } + log.info("-------------------【定时任务】判断优惠券是否过期---结束----------------"); + } } diff --git a/electripper-system/src/main/resources/mapper/system/AsUserMapper.xml b/electripper-system/src/main/resources/mapper/system/AsUserMapper.xml index 60e9a8e..6c0978b 100644 --- a/electripper-system/src/main/resources/mapper/system/AsUserMapper.xml +++ b/electripper-system/src/main/resources/mapper/system/AsUserMapper.xml @@ -35,13 +35,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + select u.user_id, u.user_name, u.real_name, u.id_card, u.nick_name, u.email, u.avatar, u.phonenumber, u.balance, u.birthday, u.password, u.pay_password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,u.wxopenid, - u.is_sign,u.role,u.sys_user_id,u.area_id,u.is_authentication,u.app_name,u.appid + u.is_sign,u.role,u.sys_user_id,u.area_id,u.is_authentication,u.app_name,u.appid,u.vip_type,u.expiration_time from et_user u @@ -200,6 +202,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" is_authentication, app_name, appid, + vip_type, + expiration_time, create_time )values( #{userId}, @@ -224,6 +228,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{isAuthentication}, #{appName}, #{appId}, + #{vipType}, + #{expirationTime}, sysdate() ) @@ -254,6 +260,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" is_authentication = #{isAuthentication}, app_name = #{appName}, appid = #{appId}, + vip_type = #{vipType}, + expiration_time = #{expirationTime}, update_time = sysdate() where user_id = #{userId} diff --git a/electripper-system/src/main/resources/mapper/system/EtCouponClaimLogMapper.xml b/electripper-system/src/main/resources/mapper/system/EtCouponClaimLogMapper.xml index f1a2ea7..e6d7d9f 100644 --- a/electripper-system/src/main/resources/mapper/system/EtCouponClaimLogMapper.xml +++ b/electripper-system/src/main/resources/mapper/system/EtCouponClaimLogMapper.xml @@ -4,7 +4,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - + @@ -19,7 +19,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select log_id, area_id, user_id, coupon_id, create_time, gain_method, status, expiration_time from et_coupon_user_log - select l.log_id, l.area_id, @@ -30,24 +30,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" l.coupon_id, l.create_time, l.gain_method, - l.expiration_time + l.expiration_time, + c.name couponName, + c.type, + c.retail_price retailPrice from et_coupon_user_log l left join et_operating_area a on a.area_id = l.area_id left join et_user u on u.user_id = l.user_id + left join et_coupon c on c.coupon_id = l.coupon_id and l.area_id like concat('%', #{areaId}, '%') and a.area_name like concat('%', #{areaName}, '%') and l.user_id = #{userId} and u.user_name = #{userName} - and u.gain_method = #{gainMethod} + and l.gain_method = #{gainMethod} and l.status = #{status} and l.coupon_id like concat('%', #{couponId}, '%') - - AND o.status IN - - #{item} - - @@ -56,7 +54,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where log_id = #{logId} - + insert into et_coupon_user_log area_id, @@ -78,7 +76,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + update et_coupon_user_log area_id = #{areaId}, diff --git a/electripper-system/src/main/resources/mapper/system/EtCouponMapper.xml b/electripper-system/src/main/resources/mapper/system/EtCouponMapper.xml index 40ba337..0e975b7 100644 --- a/electripper-system/src/main/resources/mapper/system/EtCouponMapper.xml +++ b/electripper-system/src/main/resources/mapper/system/EtCouponMapper.xml @@ -6,10 +6,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + - @@ -17,22 +17,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + + - select coupon_id, type, discount_percent, area_id, user_id, discount_amount, create_time, validity_value, validity_unit, status, limit_num, `desc`, snack_price from et_coupon + select coupon_id, name, type, discount_percent, area_id, discount_amount, create_time, validity_value, validity_unit, status, limit_num, `desc`, retail_price, is_hot from et_coupon @@ -66,10 +71,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" insert into et_coupon + name, type, discount_percent, area_id, - user_id, discount_amount, create_time, validity_value, @@ -77,13 +82,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" status, limit_num, desc, - snack_price, + retail_price, + is_hot, + #{name}, #{type}, #{discountPercent}, #{areaId}, - #{userId}, #{discountAmount}, #{createTime}, #{validityValue}, @@ -91,17 +97,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{status}, #{limitNum}, #{desc}, - #{snackPrice}, + #{retailPrice}, + #{isHot}, update et_coupon + name = #{name}, type = #{type}, discount_percent = #{discountPercent}, area_id = #{areaId}, - user_id = #{userId}, discount_amount = #{discountAmount}, create_time = #{createTime}, validity_value = #{validityValue}, @@ -109,7 +116,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" status = #{status}, limit_num = #{limitNum}, desc = #{desc}, - snack_price = #{snackPrice}, + retail_price = #{retailPrice}, + is_hot = #{isHot}, where coupon_id = #{couponId}