From 989259de7e0315f2c35c082282285e37df22970f Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Sun, 7 Apr 2019 02:01:38 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E5=90=8E=E7=AB=AF=EF=BC=9A=E4=BC=98?= =?UTF-8?q?=E6=83=A0=E5=8A=B5=E9=A2=86=E5=8F=96=E7=9B=B8=E5=85=B3=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/framework/util/DateUtil.java | 3 + ...oller.java => AdminsCouponController.java} | 64 +++++------ ...roller.java => UsersBannerController.java} | 4 +- .../users/UsersCouponController.java | 52 +++++++++ .../convert/CouponCardConvert.java | 21 ++++ .../convert/CouponTemplateConvert.java | 4 + .../vo/admins/AdminsCouponTemplateVO.java | 6 +- .../vo/users/UsersCouponCardVO.java | 55 ++++++++++ .../vo/users/UsersCouponTemplateVO.java | 54 +++++++++ .../mall/promotion/api/CouponService.java | 2 + .../mall/promotion/api/bo/CouponCardBO.java | 103 ++++++++++++++++++ .../api/constant/CouponCardStatusEnum.java | 45 ++++++++ .../api/constant/CouponCardTakeTypeEnum.java | 44 ++++++++ .../api/constant/PromotionErrorCodeEnum.java | 1 + .../biz/convert/CouponCardConvert.java | 25 +++++ .../promotion/biz/dao/CouponCardMapper.java | 22 ++++ .../biz/dataobject/CouponCardDO.java | 12 +- .../biz/service/CouponServiceImpl.java | 57 +++++++++- .../resources/mapper/CouponCardMapper.xml | 92 ++++++++++++++++ 19 files changed, 620 insertions(+), 46 deletions(-) rename promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/{AdminsCouponTemplateController.java => AdminsCouponController.java} (72%) rename promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/{UsersProductCategoryController.java => UsersBannerController.java} (96%) create mode 100644 promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersCouponController.java create mode 100644 promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/convert/CouponCardConvert.java create mode 100644 promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/users/UsersCouponCardVO.java create mode 100644 promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/users/UsersCouponTemplateVO.java create mode 100644 promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/constant/CouponCardStatusEnum.java create mode 100644 promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/constant/CouponCardTakeTypeEnum.java create mode 100644 promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/convert/CouponCardConvert.java create mode 100644 promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/CouponCardMapper.java create mode 100644 promotion/promotion-service-impl/src/main/resources/mapper/CouponCardMapper.xml diff --git a/common/common-framework/src/main/java/cn/iocoder/common/framework/util/DateUtil.java b/common/common-framework/src/main/java/cn/iocoder/common/framework/util/DateUtil.java index e0f92c8fa..3219252f0 100644 --- a/common/common-framework/src/main/java/cn/iocoder/common/framework/util/DateUtil.java +++ b/common/common-framework/src/main/java/cn/iocoder/common/framework/util/DateUtil.java @@ -26,6 +26,9 @@ public class DateUtil { * @return 计算后的日志 */ public static Date addDate(Date date, int field, int amount) { + if (amount == 0) { + return date; + } Calendar c = Calendar.getInstance(); if (date != null) { c.setTime(date); diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsCouponTemplateController.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsCouponController.java similarity index 72% rename from promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsCouponTemplateController.java rename to promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsCouponController.java index ce277c738..589564ebb 100644 --- a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsCouponTemplateController.java +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsCouponController.java @@ -25,7 +25,7 @@ import java.util.Date; @RestController @RequestMapping("admins/coupon") @Api("优惠劵(码)模块") -public class AdminsCouponTemplateController { +public class AdminsCouponController { @Reference(validation = "true") private CouponService couponService; @@ -39,12 +39,12 @@ public class AdminsCouponTemplateController { @ApiImplicitParam(name = "pageNo", value = "页码,从 1 开始", example = "1"), @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, example = "10"), }) - public CommonResult page(@RequestParam(value = "type", required = false) Integer type, - @RequestParam(value = "title", required = false) String title, - @RequestParam(value = "status", required = false) Integer status, - @RequestParam(value = "preferentialType", required = false) Integer preferentialType, - @RequestParam(value = "pageNo", defaultValue = "0") Integer pageNo, - @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { + public CommonResult templatePage(@RequestParam(value = "type", required = false) Integer type, + @RequestParam(value = "title", required = false) String title, + @RequestParam(value = "status", required = false) Integer status, + @RequestParam(value = "preferentialType", required = false) Integer preferentialType, + @RequestParam(value = "pageNo", defaultValue = "0") Integer pageNo, + @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { CommonResult result = couponService.getCouponTemplatePage(new CouponTemplatePageDTO() .setType(type).setTitle(title).setStatus(status).setPreferentialType(preferentialType) .setPageNo(pageNo).setPageSize(pageSize)); @@ -71,24 +71,24 @@ public class AdminsCouponTemplateController { @ApiImplicitParam(name = "percentOff", value = "折扣百分比", example = "当 preferentialType 为折扣卷时,非空"), @ApiImplicitParam(name = "discountPriceLimit", value = "折扣上限", example = "当 preferentialType 为折扣卷时,非空"), }) - public CommonResult add(@RequestParam(value = "title") String title, - @RequestParam(value = "description", required = false) String description, - @RequestParam(value = "quota") Integer quota, - @RequestParam(value = "total", required = false) Integer total, - @RequestParam(value = "priceAvailable") Integer priceAvailable, - @RequestParam(value = "rangeType") Integer rangeType, - @RequestParam(value = "rangeValues", required = false) String rangeValues, - @RequestParam(value = "dateType") Integer dateType, - @DateTimeFormat(pattern = "yyyy-MM-dd") + public CommonResult templateCardAdd(@RequestParam(value = "title") String title, + @RequestParam(value = "description", required = false) String description, + @RequestParam(value = "quota") Integer quota, + @RequestParam(value = "total", required = false) Integer total, + @RequestParam(value = "priceAvailable") Integer priceAvailable, + @RequestParam(value = "rangeType") Integer rangeType, + @RequestParam(value = "rangeValues", required = false) String rangeValues, + @RequestParam(value = "dateType") Integer dateType, + @DateTimeFormat(pattern = "yyyy-MM-dd") @RequestParam(value = "validStartTime", required = false) Date validStartTime, - @DateTimeFormat(pattern = "yyyy-MM-dd") + @DateTimeFormat(pattern = "yyyy-MM-dd") @RequestParam(value = "validEndTime", required = false) Date validEndTime, - @RequestParam(value = "fixedBeginTerm", required = false) Integer fixedBeginTerm, - @RequestParam(value = "fixedEndTerm", required = false) Integer fixedEndTerm, - @RequestParam(value = "preferentialType") Integer preferentialType, - @RequestParam(value = "priceOff", required = false) Integer priceOff, - @RequestParam(value = "percentOff", required = false) Integer percentOff, - @RequestParam(value = "discountPriceLimit", required = false) Integer discountPriceLimit) { + @RequestParam(value = "fixedBeginTerm", required = false) Integer fixedBeginTerm, + @RequestParam(value = "fixedEndTerm", required = false) Integer fixedEndTerm, + @RequestParam(value = "preferentialType") Integer preferentialType, + @RequestParam(value = "priceOff", required = false) Integer priceOff, + @RequestParam(value = "percentOff", required = false) Integer percentOff, + @RequestParam(value = "discountPriceLimit", required = false) Integer discountPriceLimit) { // 创建 CouponCardTemplateAddDTO 对象 validStartTime = DateUtil.getDayBegin(validStartTime); // 开始时间,以当前 00:00:00 为准 validEndTime = DateUtil.getDayBegin(validEndTime); // 结束时间,以当前 25:59:59 为准 @@ -116,13 +116,13 @@ public class AdminsCouponTemplateController { @ApiImplicitParam(name = "rangeType", value = "可用范围的类型", required = true, example = "参见 CouponTemplateRangeTypeEnum 枚举"), @ApiImplicitParam(name = "rangeValues", value = "指定商品 / 分类列表,使用逗号分隔商品编号"), }) - public CommonResult update(@RequestParam(value = "id") Integer id, - @RequestParam(value = "title") String title, - @RequestParam(value = "description", required = false) String description, - @RequestParam(value = "quota") Integer quota, - @RequestParam(value = "total", required = false) Integer total, - @RequestParam(value = "rangeType") Integer rangeType, - @RequestParam(value = "rangeValues", required = false) String rangeValues) { + public CommonResult templateCardUpdate(@RequestParam(value = "id") Integer id, + @RequestParam(value = "title") String title, + @RequestParam(value = "description", required = false) String description, + @RequestParam(value = "quota") Integer quota, + @RequestParam(value = "total", required = false) Integer total, + @RequestParam(value = "rangeType") Integer rangeType, + @RequestParam(value = "rangeValues", required = false) String rangeValues) { // 创建 CouponCardTemplateAddDTO 对象 CouponCardTemplateUpdateDTO couponCardTemplateUpdateDTO = new CouponCardTemplateUpdateDTO() .setId(id) @@ -138,8 +138,8 @@ public class AdminsCouponTemplateController { @ApiImplicitParam(name = "id", value = "Banner 编号", required = true, example = "1"), @ApiImplicitParam(name = "status", value = "状态。1 - 开启;2 - 禁用", required = true, example = "1"), }) - public CommonResult updateStatus(@RequestParam("id") Integer id, - @RequestParam("status") Integer status) { + public CommonResult templateUpdateStatus(@RequestParam("id") Integer id, + @RequestParam("status") Integer status) { return couponService.updateCouponTemplateStatus(AdminSecurityContextHolder.getContext().getAdminId(), id, status); } diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersProductCategoryController.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersBannerController.java similarity index 96% rename from promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersProductCategoryController.java rename to promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersBannerController.java index fd7e8463e..eb436bb4d 100644 --- a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersProductCategoryController.java +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersBannerController.java @@ -19,7 +19,7 @@ import java.util.List; @RestController @RequestMapping("users/banner") @Api("Banner 模块") -public class UsersProductCategoryController { +public class UsersBannerController { @Reference(validation = "true") private BannerService bannerService; @@ -35,4 +35,4 @@ public class UsersProductCategoryController { return CommonResult.success(BannerConvert.INSTANCE.convertList(result)); } -} \ No newline at end of file +} diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersCouponController.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersCouponController.java new file mode 100644 index 000000000..4dc623315 --- /dev/null +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersCouponController.java @@ -0,0 +1,52 @@ +package cn.iocoder.mall.promotion.application.controller.users; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.promotion.api.CouponService; +import cn.iocoder.mall.promotion.api.bo.CouponCardBO; +import cn.iocoder.mall.promotion.api.bo.CouponTemplateBO; +import cn.iocoder.mall.promotion.application.convert.CouponCardConvert; +import cn.iocoder.mall.promotion.application.convert.CouponTemplateConvert; +import cn.iocoder.mall.promotion.application.vo.users.UsersCouponCardVO; +import cn.iocoder.mall.promotion.application.vo.users.UsersCouponTemplateVO; +import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder; +import com.alibaba.dubbo.config.annotation.Reference; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("admins/coupon") +@Api("优惠劵(码)模块") +public class UsersCouponController { + + @Reference(validation = "true") + private CouponService couponService; + + // ========== 优惠劵(码)模板 ========== + + @GetMapping("/template/get") + @ApiOperation(value = "优惠劵(码)模板信息") + @ApiImplicitParam(name = "id", value = "优惠劵(码)模板编号", required = true, example = "10") + public CommonResult templateGet(@RequestParam("id") Integer id) { + CouponTemplateBO template = couponService.getCouponTemplate(id).getData(); + return CommonResult.success(CouponTemplateConvert.INSTANCE.convert2(template)); + } + + // ========== 优惠劵 ========== + + @GetMapping("/card/add") + @ApiOperation(value = "领取优惠劵") + @ApiImplicitParam(name = "templateId", value = "优惠劵(码)模板编号", required = true, example = "10") + public CommonResult cardAdd(@RequestParam("templateId") Integer templateId) { + CommonResult result = couponService.addCouponCard(UserSecurityContextHolder.getContext().getUserId(), templateId); + return CouponCardConvert.INSTANCE.convert(result); + } + + // ========== 优惠码 ========== + + +} diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/convert/CouponCardConvert.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/convert/CouponCardConvert.java new file mode 100644 index 000000000..3ec4d00f2 --- /dev/null +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/convert/CouponCardConvert.java @@ -0,0 +1,21 @@ +package cn.iocoder.mall.promotion.application.convert; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.promotion.api.bo.CouponCardBO; +import cn.iocoder.mall.promotion.application.vo.users.UsersCouponCardVO; +import org.mapstruct.Mapper; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface CouponCardConvert { + + CouponCardConvert INSTANCE = Mappers.getMapper(CouponCardConvert.class); + + @Mappings({}) + CommonResult convert(CommonResult result); +// +// @Mappings({}) +// List convertList2(List banners); + +} diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/convert/CouponTemplateConvert.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/convert/CouponTemplateConvert.java index 17a1c896d..e1fc03972 100644 --- a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/convert/CouponTemplateConvert.java +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/convert/CouponTemplateConvert.java @@ -5,6 +5,7 @@ import cn.iocoder.mall.promotion.api.bo.CouponTemplateBO; import cn.iocoder.mall.promotion.api.bo.CouponTemplatePageBO; import cn.iocoder.mall.promotion.application.vo.admins.AdminsCouponTemplatePageVO; import cn.iocoder.mall.promotion.application.vo.admins.AdminsCouponTemplateVO; +import cn.iocoder.mall.promotion.application.vo.users.UsersCouponTemplateVO; import org.mapstruct.Mapper; import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; @@ -28,6 +29,9 @@ public interface CouponTemplateConvert { @Mappings({}) List convertList(List templates); + @Mappings({}) + UsersCouponTemplateVO convert2(CouponTemplateBO template); + // // @Mappings({}) // List convertList2(List banners); diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/admins/AdminsCouponTemplateVO.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/admins/AdminsCouponTemplateVO.java index e956506cd..cc5663ad1 100644 --- a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/admins/AdminsCouponTemplateVO.java +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/admins/AdminsCouponTemplateVO.java @@ -59,7 +59,7 @@ public class AdminsCouponTemplateVO { // ========== 使用规则 END ========== // ========== 使用效果 BEGIN ========== - @ApiModelProperty(value = "优惠类型", example = "参见 CouponTemplatePreferentialTypeEnum 枚举") + @ApiModelProperty(value = "优惠类型", required = true, example = "参见 CouponTemplatePreferentialTypeEnum 枚举") private Integer preferentialType; @ApiModelProperty(value = "折扣百分比") private Integer percentOff; @@ -70,11 +70,11 @@ public class AdminsCouponTemplateVO { // ========== 使用效果 END ========== // ========== 统计信息 BEGIN ========== - @ApiModelProperty(value = "折扣上限", required = true) + @ApiModelProperty(value = "领取优惠券的次数", required = true) private Integer statFetchNum; // ========== 统计信息 END ========== - @ApiModelProperty(value = "折扣上限", required = true) + @ApiModelProperty(value = "创建时间", required = true) private Date createTime; } diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/users/UsersCouponCardVO.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/users/UsersCouponCardVO.java new file mode 100644 index 000000000..ba3a6363e --- /dev/null +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/users/UsersCouponCardVO.java @@ -0,0 +1,55 @@ +package cn.iocoder.mall.promotion.application.vo.users; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.util.Date; + +/** + * 优惠劵 VO + */ +@Data +@Accessors(chain = true) +public class UsersCouponCardVO { + + // ========== 基本信息 BEGIN ========== + @ApiModelProperty(value = "优惠劵编号", required = true, example = "1") + private Integer id; + @ApiModelProperty(value = "模板编号,自增唯一", required = true, example = "1") + private Integer templateId; + @ApiModelProperty(value = "优惠码状态", required = true, example = "参见 CouponCardStatusEnum 枚举") + private Integer status; + + // ========== 基本信息 END ========== + + // ========== 使用规则 BEGIN ========== + @ApiModelProperty(value = "固定日期-生效开始时间", required = true) + private Date validStartTime; + @ApiModelProperty(value = "固定日期-生效结束时间", required = true) + private Date validEndTime; + // ========== 使用规则 END ========== + + // ========== 使用效果 BEGIN ========== + @ApiModelProperty(value = "优惠类型", required = true, example = "参见 CouponTemplatePreferentialTypeEnum 枚举") + private Integer preferentialType; + @ApiModelProperty(value = "折扣百分比") + private Integer percentOff; + @ApiModelProperty(value = "优惠金额,单位:分") + private Integer priceOff; + @ApiModelProperty(value = "折扣上限") + private Integer discountPriceLimit; + // ========== 使用效果 END ========== + + // ========== 使用情况 BEGIN ========== + /** + * 是否使用 + */ + @ApiModelProperty(value = "是否使用", required = true) + private Boolean used; + + // TODO 芋艿,后续要加优惠劵的使用日志,因为下单后,可能会取消。 + + // ========== 使用情况 END ========== + +} diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/users/UsersCouponTemplateVO.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/users/UsersCouponTemplateVO.java new file mode 100644 index 000000000..c664d348b --- /dev/null +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/users/UsersCouponTemplateVO.java @@ -0,0 +1,54 @@ +package cn.iocoder.mall.promotion.application.vo.users; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.util.Date; + +@ApiModel("CouponTemplate VO") +@Data +@Accessors(chain = true) +public class UsersCouponTemplateVO { + + // ========== 基本信息 BEGIN ========== + @ApiModelProperty(value = "模板编号,自增唯一", required = true, example = "1") + private Integer id; + @ApiModelProperty(value = "标题", required = true, example = "优惠劵牛逼") + private String title; + @ApiModelProperty(value = "优惠码状态", required = true, example = "参见 CouponTemplateStatusEnum 枚举") + private Integer status; + // ========== 领取规则 END ========== + + // ========== 使用规则 BEGIN ========== + @ApiModelProperty(value = "是否设置满多少金额可用,单位:分", required = true, example = "0-不限制;大于0-多少金额可用") + private Integer priceAvailable; + @ApiModelProperty(value = "可用范围的类型", required = true, example = "参见 CouponTemplateRangeTypeEnum 枚举") + private Integer rangeType; + @ApiModelProperty(value = "指定商品 / 分类列表,使用逗号分隔商品编号", example = "参见 CouponTemplateRangeTypeEnum 枚举") + private String rangeValues; + @ApiModelProperty(value = "生效日期类型", example = "参见 CouponTemplateDateTypeEnum 枚举") + private Integer dateType; + @ApiModelProperty(value = "固定日期-生效开始时间") + private Date validStartTime; + @ApiModelProperty(value = "固定日期-生效结束时间") + private Date validEndTime; + @ApiModelProperty(value = "领取日期-开始天数", example = "例如,0-当天;1-次天") + private Integer fixedStartTerm; + @ApiModelProperty(value = "领取日期-结束天数") + private Integer fixedEndTerm; + // ========== 使用规则 END ========== + + // ========== 使用效果 BEGIN ========== + @ApiModelProperty(value = "优惠类型", required = true, example = "参见 CouponTemplatePreferentialTypeEnum 枚举") + private Integer preferentialType; + @ApiModelProperty(value = "折扣百分比") + private Integer percentOff; + @ApiModelProperty(value = "优惠金额,单位:分") + private Integer priceOff; + @ApiModelProperty(value = "折扣上限") + private Integer discountPriceLimit; + // ========== 使用效果 END ========== + +} diff --git a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/CouponService.java b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/CouponService.java index 01f22c3bd..2c867cd4f 100644 --- a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/CouponService.java +++ b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/CouponService.java @@ -12,6 +12,8 @@ public interface CouponService { // ========== 优惠劵(码)模板 ========== + CommonResult getCouponTemplate(Integer couponTemplateId); + CommonResult getCouponTemplatePage(CouponTemplatePageDTO couponTemplatePageDTO); /** diff --git a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/bo/CouponCardBO.java b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/bo/CouponCardBO.java index 30182fa94..00fa60e31 100644 --- a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/bo/CouponCardBO.java +++ b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/bo/CouponCardBO.java @@ -3,10 +3,113 @@ package cn.iocoder.mall.promotion.api.bo; import lombok.Data; import lombok.experimental.Accessors; +import java.util.Date; + /** * 优惠劵 BO */ @Data @Accessors(chain = true) public class CouponCardBO { + + // ========== 基本信息 BEGIN ========== + /** + * 优惠劵编号 + */ + private Integer id; + /** + * 优惠劵(码)分组编号 + */ + private Integer templateId; +// /** +// * 核销码 +// */ +// private String verifyCode; + /** + * 优惠码状态 + * + * 1-未使用 + * 2-已使用 + * 3-已失效 + */ + private Integer status; + + // ========== 基本信息 END ========== + + // ========== 领取情况 BEGIN ========== + /** + * 用户编号 + */ + private Integer userId; + /** + * 领取类型 + * + * 1 - 用户主动领取 + * 2 - 后台自动发放 + */ + private Integer takeType; + // ========== 领取情况 END ========== + + // ========== 使用规则 BEGIN ========== + /** + * 生效开始时间 + */ + private Date validStartTime; + /** + * 生效结束时间 + */ + private Date validEndTime; + // ========== 使用规则 END ========== + + // ========== 使用效果 BEGIN ========== + /** + * 优惠类型 + * + * 1-代金卷 + * 2-折扣卷 + */ + private Integer preferentialType; + /** + * 折扣 + */ + private Integer percentOff; + /** + * 优惠金额,单位:分。 + */ + private Integer priceOff; + /** + * 折扣上限,仅在 {@link #preferentialType} 等于 2 时生效。 + * + * 例如,折扣上限为 20 元,当使用 8 折优惠券,订单金额为 1000 元时,最高只可折扣 20 元,而非 80 元。 + */ + private Integer discountPriceLimit; + // ========== 使用效果 END ========== + + // ========== 使用情况 BEGIN ========== + /** + * 是否使用 + */ + private Boolean used; + /** + * 使用订单号 + */ + private Integer usedOrderId; + /** + * 订单中优惠面值,单位:分 + */ + private Integer usedPrice; + /** + * 使用时间 + */ + private Date usedTime; + + // TODO 芋艿,后续要加优惠劵的使用日志,因为下单后,可能会取消。 + + // ========== 使用情况 END ========== + + /** + * 创建时间 + */ + private Date createTime; + } diff --git a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/constant/CouponCardStatusEnum.java b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/constant/CouponCardStatusEnum.java new file mode 100644 index 000000000..0f1079438 --- /dev/null +++ b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/constant/CouponCardStatusEnum.java @@ -0,0 +1,45 @@ +package cn.iocoder.mall.promotion.api.constant; + +import cn.iocoder.common.framework.core.IntArrayValuable; + +import java.util.Arrays; + +/** + * 优惠劵状态枚举 + */ +public enum CouponCardStatusEnum implements IntArrayValuable { + + UNUSED(1, "未使用"), + USED(2, "已使用"), + EXPIRE(3, "已过期"), + ; + + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CouponCardStatusEnum::getValue).toArray(); + + /** + * 值 + */ + private final Integer value; + /** + * 名字 + */ + private final String name; + + CouponCardStatusEnum(Integer value, String name) { + this.value = value; + this.name = name; + } + + public Integer getValue() { + return value; + } + + public String getName() { + return name; + } + + @Override + public int[] array() { + return ARRAYS; + } +} diff --git a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/constant/CouponCardTakeTypeEnum.java b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/constant/CouponCardTakeTypeEnum.java new file mode 100644 index 000000000..020f3fbb0 --- /dev/null +++ b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/constant/CouponCardTakeTypeEnum.java @@ -0,0 +1,44 @@ +package cn.iocoder.mall.promotion.api.constant; + +import cn.iocoder.common.framework.core.IntArrayValuable; + +import java.util.Arrays; + +/** + * 优惠劵领取方式 + */ +public enum CouponCardTakeTypeEnum implements IntArrayValuable { + + BY_USER(1, "用户主动领取"), + BY_ADMIN(2, "已使用"), + ; + + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CouponCardTakeTypeEnum::getValue).toArray(); + + /** + * 值 + */ + private final Integer value; + /** + * 名字 + */ + private final String name; + + CouponCardTakeTypeEnum(Integer value, String name) { + this.value = value; + this.name = name; + } + + public Integer getValue() { + return value; + } + + public String getName() { + return name; + } + + @Override + public int[] array() { + return ARRAYS; + } +} diff --git a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/constant/PromotionErrorCodeEnum.java b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/constant/PromotionErrorCodeEnum.java index aa40e719e..999b663f2 100644 --- a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/constant/PromotionErrorCodeEnum.java +++ b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/constant/PromotionErrorCodeEnum.java @@ -21,6 +21,7 @@ public enum PromotionErrorCodeEnum { PRODUCT_TEMPLATE_NOT_CARD(1006002001, "不是优惠劵模板"), PRODUCT_TEMPLATE_NOT_CODE(1006002002, "不是优惠码模板"), PRODUCT_TEMPLATE_TOTAL_CAN_NOT_REDUCE(1006002003, "优惠劵(码)模板的发放数量不能减小"), + PRODUCT_TEMPLATE_STATUS_NOT_ENABLE(1006002004, "优惠劵模板(码)未开启"), ; diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/convert/CouponCardConvert.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/convert/CouponCardConvert.java new file mode 100644 index 000000000..81b211446 --- /dev/null +++ b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/convert/CouponCardConvert.java @@ -0,0 +1,25 @@ +package cn.iocoder.mall.promotion.biz.convert; + +import cn.iocoder.mall.promotion.api.bo.CouponCardBO; +import cn.iocoder.mall.promotion.biz.dataobject.CouponCardDO; +import org.mapstruct.Mapper; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +@Mapper +public interface CouponCardConvert { + + CouponCardConvert INSTANCE = Mappers.getMapper(CouponCardConvert.class); + +// @Mappings({}) +// CouponCardBO convertToBO(CouponCardDO banner); +// + @Mappings({}) + List convertToBO(List cardList); + + @Mappings({}) + CouponCardBO convert(CouponCardDO card); + +} diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/CouponCardMapper.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/CouponCardMapper.java new file mode 100644 index 000000000..8560c2e7c --- /dev/null +++ b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/CouponCardMapper.java @@ -0,0 +1,22 @@ +package cn.iocoder.mall.promotion.biz.dao; + +import cn.iocoder.mall.promotion.biz.dataobject.CouponCardDO; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface CouponCardMapper { + + CouponCardDO selectById(@Param("id") Integer id); + + List selectListByPage(@Param("status") Integer status); + + Integer selectCountByPage(@Param("status") Integer status); + + void insert(CouponCardDO couponCardDO); + + int update(CouponCardDO couponCardDO); + +} diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dataobject/CouponCardDO.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dataobject/CouponCardDO.java index 5223c8d74..45569cf1d 100644 --- a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dataobject/CouponCardDO.java +++ b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dataobject/CouponCardDO.java @@ -53,11 +53,11 @@ public class CouponCardDO extends BaseDO { // ========== 使用规则 BEGIN ========== /** - * 固定日期-生效开始时间 + * 生效开始时间 */ private Date validStartTime; /** - * 固定日期-生效结束时间 + * 生效结束时间 */ private Date validEndTime; // ========== 使用规则 END ========== @@ -73,7 +73,7 @@ public class CouponCardDO extends BaseDO { /** * 折扣 */ - private Double percentOff; + private Integer percentOff; /** * 优惠金额,单位:分。 */ @@ -87,14 +87,10 @@ public class CouponCardDO extends BaseDO { // ========== 使用效果 END ========== // ========== 使用情况 BEGIN ========== - /** - * 是否使用 - */ - private Boolean used; /** * 使用订单号 */ - private String usedOrderId; + private Integer usedOrderId; /** * 订单中优惠面值,单位:分 */ diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/CouponServiceImpl.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/CouponServiceImpl.java index 270feaeaf..5cd78f229 100644 --- a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/CouponServiceImpl.java +++ b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/CouponServiceImpl.java @@ -1,6 +1,7 @@ package cn.iocoder.mall.promotion.biz.service; import cn.iocoder.common.framework.constant.SysErrorCodeEnum; +import cn.iocoder.common.framework.util.DateUtil; import cn.iocoder.common.framework.util.ServiceExceptionUtil; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.promotion.api.CouponService; @@ -9,12 +10,17 @@ import cn.iocoder.mall.promotion.api.bo.CouponTemplateBO; import cn.iocoder.mall.promotion.api.bo.CouponTemplatePageBO; import cn.iocoder.mall.promotion.api.constant.*; import cn.iocoder.mall.promotion.api.dto.*; +import cn.iocoder.mall.promotion.biz.convert.CouponCardConvert; import cn.iocoder.mall.promotion.biz.convert.CouponTemplateConvert; +import cn.iocoder.mall.promotion.biz.convert.CouponTemplateConvertImpl; +import cn.iocoder.mall.promotion.biz.dao.CouponCardMapper; import cn.iocoder.mall.promotion.biz.dao.CouponTemplateMapper; +import cn.iocoder.mall.promotion.biz.dataobject.CouponCardDO; import cn.iocoder.mall.promotion.biz.dataobject.CouponTemplateDO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.Calendar; import java.util.Date; @Service // 实际上不用添加。添加的原因是,必须 Spring 报错提示 @@ -23,9 +29,17 @@ public class CouponServiceImpl implements CouponService { @Autowired private CouponTemplateMapper couponTemplateMapper; + @Autowired + private CouponCardMapper couponCardMapper; // ========== 优惠劵(码)模板 ========== + @Override + public CommonResult getCouponTemplate(Integer couponTemplateId) { + CouponTemplateDO template = couponTemplateMapper.selectById(couponTemplateId); + return CommonResult.success(CouponTemplateConvertImpl.INSTANCE.convert(template)); + } + @Override public CommonResult getCouponTemplatePage(CouponTemplatePageDTO couponTemplatePageDTO) { CouponTemplatePageBO couponTemplatePageBO = new CouponTemplatePageBO(); @@ -163,7 +177,37 @@ public class CouponServiceImpl implements CouponService { @Override public CommonResult addCouponCard(Integer userId, Integer couponTemplateId) { - return null; + // 校验 CouponCardTemplate 存在 + CouponTemplateDO template = couponTemplateMapper.selectById(couponTemplateId); + if (template == null) { + return ServiceExceptionUtil.error(PromotionErrorCodeEnum.PRODUCT_TEMPLATE_NOT_EXISTS.getCode()); + } + // 校验 CouponCardTemplate 是 CARD + if (!CouponTemplateTypeEnum.CARD.getValue().equals(template.getType())) { + return ServiceExceptionUtil.error(PromotionErrorCodeEnum.PRODUCT_TEMPLATE_NOT_CARD.getCode()); + } + // 校验 CouponCardTemplate 状态是否开启 + if (!CouponTemplateStatusEnum.ENABLE.getValue().equals(template.getStatus())) { + return ServiceExceptionUtil.error(PromotionErrorCodeEnum.PRODUCT_TEMPLATE_STATUS_NOT_ENABLE.getCode()); + } + // 创建优惠劵 + // 1. 基本信息 + 领取情况 + CouponCardDO card = new CouponCardDO() + .setTemplateId(couponTemplateId) + .setStatus(CouponCardStatusEnum.UNUSED.getValue()) + .setUserId(userId) + .setTakeType(CouponCardTakeTypeEnum.BY_USER.getValue()); // TODO 需要改 + // 2. 使用规则 + setCouponCardValidTime(card, template); + // 3. 使用效果 + card.setPreferentialType(template.getPreferentialType()) + .setPriceOff(template.getPriceOff()) + .setPercentOff(template.getPercentOff()).setDiscountPriceLimit(template.getDiscountPriceLimit()); + // 保存优惠劵模板到数据库 + card.setCreateTime(new Date()); + couponCardMapper.insert(card); + // 返回成功 + return CommonResult.success(CouponCardConvert.INSTANCE.convert(card)); } @Override @@ -176,6 +220,17 @@ public class CouponServiceImpl implements CouponService { return null; } + private void setCouponCardValidTime(CouponCardDO card, CouponTemplateDO template) { + if (CouponTemplateDateTypeEnum.FIXED_DATE.getValue().equals(template.getDateType())) { + card.setValidStartTime(template.getValidStartTime()).setValidEndTime(template.getValidEndTime()); + } else if (CouponTemplateDateTypeEnum.FIXED_TERM.getValue().equals(template.getDateType())) { + Date validStartTime = DateUtil.getDayBegin(new Date()); + card.setValidStartTime(DateUtil.addDate(validStartTime, Calendar.DAY_OF_YEAR, template.getFixedStartTerm())); + Date validEndTime = DateUtil.getDayEnd(card.getValidStartTime()); + card.setValidEndTime(DateUtil.addDate(validEndTime, Calendar.DAY_OF_YEAR, template.getFixedEndTerm() - 1)); + } + } + // ========== 优惠码 ========== @Override diff --git a/promotion/promotion-service-impl/src/main/resources/mapper/CouponCardMapper.xml b/promotion/promotion-service-impl/src/main/resources/mapper/CouponCardMapper.xml new file mode 100644 index 000000000..1082ebe80 --- /dev/null +++ b/promotion/promotion-service-impl/src/main/resources/mapper/CouponCardMapper.xml @@ -0,0 +1,92 @@ + + + + + + id, template_id, status, user_id, take_type, + valid_start_time, valid_end_time, preferential_type, percent_off, price_off, + discount_price_limit, used_order_id, used_price, used_time, + create_time + + + + + + + + + + + + + + + + + + + + + + + + + + + INSERT INTO coupon_card ( + template_id, status, user_id, take_type, + valid_start_time, valid_end_time, preferential_type, percent_off, price_off, + discount_price_limit, used_order_id, used_price, used_time, + create_time + ) VALUES ( + #{templateId}, #{status}, #{userId}, #{takeType}, + #{validStartTime}, #{validEndTime}, #{preferentialType}, #{percentOff}, #{priceOff}, + #{discountPriceLimit}, #{usedOrderId}, #{usedPrice}, #{usedTime}, + #{createTime} + ) + + + + UPDATE coupon_card + + + status = #{status}, + + + used_order_id = #{usedOrderId}, + + + used_price = #{usedPrice}, + + + used_time = #{usedTime}, + + + WHERE id = #{id} + + + From 6cee744ec19072326d6b3bf93ce0323b688751ae Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Sun, 7 Apr 2019 02:34:45 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E5=89=8D=E7=AB=AF=EF=BC=9A=E4=BC=98?= =?UTF-8?q?=E6=83=A0=E5=8A=B5=E9=A2=86=E5=8F=96=E7=95=8C=E9=9D=A2=EF=BC=88?= =?UTF-8?q?=E6=9C=AA=E5=AE=8C=E6=88=90=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mobile-web/src/api/promotion.js | 10 +++++++--- mobile-web/src/config/request.js | 12 ++++++++++-- mobile-web/src/config/router.js | 7 +++++++ mobile-web/src/page/coupon/fetch.vue | 9 +++++++++ mobile-web/src/page/page/index.vue | 6 +++--- .../controller/users/UsersBannerController.java | 1 + 6 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 mobile-web/src/page/coupon/fetch.vue diff --git a/mobile-web/src/api/promotion.js b/mobile-web/src/api/promotion.js index c44ea1106..4b74b1b7a 100644 --- a/mobile-web/src/api/promotion.js +++ b/mobile-web/src/api/promotion.js @@ -4,7 +4,7 @@ import request from "../config/request"; export function getBannerList() { return request({ - url: 'promotion-api/users/banner/list', + url: '/promotion-api/users/banner/list', method: 'get', }); } @@ -13,7 +13,11 @@ export function getBannerList() { export function getProductRecommendList() { return request({ - url: 'promotion-api/users/product_recommend/list', + url: '/promotion-api/users/product_recommend/list', method: 'get', }); -} \ No newline at end of file +} + +// Coupon Template + +// Coupon Card diff --git a/mobile-web/src/config/request.js b/mobile-web/src/config/request.js index 55b4cdc30..29027aea4 100644 --- a/mobile-web/src/config/request.js +++ b/mobile-web/src/config/request.js @@ -15,6 +15,10 @@ const serviceRouter = function(requestUrl) { prefix: '/user-api', target: 'http://127.0.0.1:18082/user-api', }, + '/promotion-api': { + prefix: '/promotion-api', + target: 'http://127.0.0.1:18085/promotion-api', + }, }; const configProd = { @@ -26,6 +30,10 @@ const serviceRouter = function(requestUrl) { prefix: '/user-api', target: 'http://127.0.0.1:18082/user-api', }, + '/promotion-api': { + prefix: '/promotion-api', + target: 'http://127.0.0.1:18085/promotion-api', + }, }; if (process.env.NODE_ENV == 'development') { @@ -117,8 +125,8 @@ service.interceptors.request.use( const { target, prefix } = serviceRouter(config.url) let url = config.url = config.url.replace(`${prefix}`, target); // TODO 芋艿,这些 url 不用增加认证 token 。可能这么写,有点脏,后面看看咋优化下。 - if (url.indexOf('user-api/users/passport/mobile/send_register_code') != -1 - || url.indexOf('user-api/users/passport/mobile/register') != -1) { + if (url.indexOf('user-api/users/passport/mobile/send_register_code') !== -1 + || url.indexOf('user-api/users/passport/mobile/register') !== -1) { return config; } diff --git a/mobile-web/src/config/router.js b/mobile-web/src/config/router.js index df0b54a61..f519f6f19 100644 --- a/mobile-web/src/config/router.js +++ b/mobile-web/src/config/router.js @@ -185,6 +185,13 @@ const routes = [ title: '分类' } }, + { + path: '/coupon/fetch', + component: () => import('../page/coupon/fetch'), + meta: { + title: '优惠劵领取' + } + } ]; // add route path diff --git a/mobile-web/src/page/coupon/fetch.vue b/mobile-web/src/page/coupon/fetch.vue new file mode 100644 index 000000000..03165896a --- /dev/null +++ b/mobile-web/src/page/coupon/fetch.vue @@ -0,0 +1,9 @@ + + + diff --git a/mobile-web/src/page/page/index.vue b/mobile-web/src/page/page/index.vue index d50465234..75f2669a3 100644 --- a/mobile-web/src/page/page/index.vue +++ b/mobile-web/src/page/page/index.vue @@ -65,9 +65,9 @@ export default { } }, created:function(){ - GetPage().then(response=>{ - this.page=response; - }); + // GetPage().then(response=>{ + // this.page=response; + // }); }, mounted: function() { // 加载 Banner diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersBannerController.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersBannerController.java index eb436bb4d..7a3f68164 100644 --- a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersBannerController.java +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersBannerController.java @@ -36,3 +36,4 @@ public class UsersBannerController { } } + From 315dec741fce87947c3a7dd2ac632743f9a7a516 Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Sun, 7 Apr 2019 22:00:12 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=89=8D=E7=AB=AF=EF=BC=9A=E4=BC=98?= =?UTF-8?q?=E6=83=A0=E5=8A=B5=E9=A2=86=E5=8F=96=E7=95=8C=E9=9D=A2=EF=BC=88?= =?UTF-8?q?=E5=AE=8C=E6=88=90=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mobile-web/src/api/promotion.js | 20 +++++++ mobile-web/src/api/user.js | 6 +-- mobile-web/src/page/coupon/fetch.vue | 53 +++++++++++++++++-- .../application/config/MVCConfiguration.java | 31 +++++++---- .../users/UsersCouponController.java | 11 ++-- .../api/constant/PromotionErrorCodeEnum.java | 3 +- .../promotion/biz/dao/CouponCardMapper.java | 3 ++ .../biz/dao/CouponTemplateMapper.java | 2 + .../biz/service/CouponServiceImpl.java | 15 ++++++ .../resources/mapper/CouponCardMapper.xml | 14 +++++ .../resources/mapper/CouponTemplateMapper.xml | 7 +++ .../application/config/MVCConfiguration.java | 2 +- .../user/api/dto/UserAccessLogAddDTO.java | 3 +- 13 files changed, 145 insertions(+), 25 deletions(-) diff --git a/mobile-web/src/api/promotion.js b/mobile-web/src/api/promotion.js index 4b74b1b7a..37a96ff50 100644 --- a/mobile-web/src/api/promotion.js +++ b/mobile-web/src/api/promotion.js @@ -20,4 +20,24 @@ export function getProductRecommendList() { // Coupon Template +export function getCouponTemplate(id) { + return request({ + url: '/promotion-api/users/coupon/template/get', + method: 'get', + params: { + id, + } + }); +} + +export function doAddCouponCard(templateId) { + return request({ + url: '/promotion-api/users/coupon/card/add', + method: 'post', + params: { + templateId, + } + }); +} + // Coupon Card diff --git a/mobile-web/src/api/user.js b/mobile-web/src/api/user.js index d0f768ddf..f9c7ec30e 100644 --- a/mobile-web/src/api/user.js +++ b/mobile-web/src/api/user.js @@ -81,7 +81,7 @@ export function getUserInfo() { export function doUserUpdateNickname(nickname) { return request({ - url: 'user-api/users/user/update_nickname', + url: '/user-api/users/user/update_nickname', method: 'post', params: { nickname, @@ -91,7 +91,7 @@ export function doUserUpdateNickname(nickname) { export function doPassportMobileRegister(mobile, code) { return request({ - url: 'user-api/users/passport/mobile/register', + url: '/user-api/users/passport/mobile/register', method: 'post', params: { mobile, @@ -102,7 +102,7 @@ export function doPassportMobileRegister(mobile, code) { export function doPassportMobileSendRegisterCode(mobile) { return request({ - url: 'user-api/users/passport/mobile/send_register_code', + url: '/user-api/users/passport/mobile/send_register_code', method: 'post', params: { mobile, diff --git a/mobile-web/src/page/coupon/fetch.vue b/mobile-web/src/page/coupon/fetch.vue index 03165896a..ceff598e7 100644 --- a/mobile-web/src/page/coupon/fetch.vue +++ b/mobile-web/src/page/coupon/fetch.vue @@ -1,9 +1,54 @@ diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/config/MVCConfiguration.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/config/MVCConfiguration.java index 6474ea705..b7ee655c4 100644 --- a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/config/MVCConfiguration.java +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/config/MVCConfiguration.java @@ -2,6 +2,11 @@ package cn.iocoder.mall.promotion.application.config; import cn.iocoder.common.framework.config.GlobalExceptionHandler; import cn.iocoder.common.framework.servlet.CorsFilter; +import cn.iocoder.mall.admin.sdk.interceptor.AdminAccessLogInterceptor; +import cn.iocoder.mall.admin.sdk.interceptor.AdminSecurityInterceptor; +import cn.iocoder.mall.user.sdk.interceptor.UserAccessLogInterceptor; +import cn.iocoder.mall.user.sdk.interceptor.UserSecurityInterceptor; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -14,23 +19,31 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @EnableWebMvc @Configuration @Import(value = {GlobalExceptionHandler.class, // 统一全局返回 -// AdminSecurityInterceptor.class + AdminSecurityInterceptor.class, UserAccessLogInterceptor.class, + UserSecurityInterceptor.class, AdminAccessLogInterceptor.class, }) public class MVCConfiguration implements WebMvcConfigurer { // @Autowired // private UserSecurityInterceptor securityInterceptor; -// @Autowired -// private AdminSecurityInterceptor adminSecurityInterceptor; -// @Autowired -// private AdminAccessLogInterceptor adminAccessLogInterceptor; + @Autowired + private UserSecurityInterceptor userSecurityInterceptor; + @Autowired + private UserAccessLogInterceptor userAccessLogInterceptor; + @Autowired + private AdminSecurityInterceptor adminSecurityInterceptor; + @Autowired + private AdminAccessLogInterceptor adminAccessLogInterceptor; // @Override public void addInterceptors(InterceptorRegistry registry) { -// registry.addInterceptor(securityInterceptor).addPathPatterns("/user/**", "/admin/**"); // 只拦截我们定义的接口 -// registry.addInterceptor(adminAccessLogInterceptor).addPathPatterns("/admins/**"); -// registry.addInterceptor(adminSecurityInterceptor).addPathPatterns("/admins/**"); + // 用户 + registry.addInterceptor(userAccessLogInterceptor).addPathPatterns("/users/**"); + registry.addInterceptor(userSecurityInterceptor).addPathPatterns("/users/**"); // 只拦截我们定义的接口 + // 管理员 + registry.addInterceptor(adminAccessLogInterceptor).addPathPatterns("/admins/**"); + registry.addInterceptor(adminSecurityInterceptor).addPathPatterns("/admins/**"); } @Override @@ -48,4 +61,4 @@ public class MVCConfiguration implements WebMvcConfigurer { return registrationBean; } -} \ No newline at end of file +} diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersCouponController.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersCouponController.java index 4dc623315..fcf5eb157 100644 --- a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersCouponController.java +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersCouponController.java @@ -8,18 +8,16 @@ import cn.iocoder.mall.promotion.application.convert.CouponCardConvert; import cn.iocoder.mall.promotion.application.convert.CouponTemplateConvert; import cn.iocoder.mall.promotion.application.vo.users.UsersCouponCardVO; import cn.iocoder.mall.promotion.application.vo.users.UsersCouponTemplateVO; +import cn.iocoder.mall.user.sdk.annotation.PermitAll; import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder; import com.alibaba.dubbo.config.annotation.Reference; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController -@RequestMapping("admins/coupon") +@RequestMapping("users/coupon") @Api("优惠劵(码)模块") public class UsersCouponController { @@ -31,6 +29,7 @@ public class UsersCouponController { @GetMapping("/template/get") @ApiOperation(value = "优惠劵(码)模板信息") @ApiImplicitParam(name = "id", value = "优惠劵(码)模板编号", required = true, example = "10") + @PermitAll public CommonResult templateGet(@RequestParam("id") Integer id) { CouponTemplateBO template = couponService.getCouponTemplate(id).getData(); return CommonResult.success(CouponTemplateConvert.INSTANCE.convert2(template)); @@ -38,7 +37,7 @@ public class UsersCouponController { // ========== 优惠劵 ========== - @GetMapping("/card/add") + @PostMapping("/card/add") @ApiOperation(value = "领取优惠劵") @ApiImplicitParam(name = "templateId", value = "优惠劵(码)模板编号", required = true, example = "10") public CommonResult cardAdd(@RequestParam("templateId") Integer templateId) { diff --git a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/constant/PromotionErrorCodeEnum.java b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/constant/PromotionErrorCodeEnum.java index 999b663f2..af574195b 100644 --- a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/constant/PromotionErrorCodeEnum.java +++ b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/constant/PromotionErrorCodeEnum.java @@ -22,7 +22,8 @@ public enum PromotionErrorCodeEnum { PRODUCT_TEMPLATE_NOT_CODE(1006002002, "不是优惠码模板"), PRODUCT_TEMPLATE_TOTAL_CAN_NOT_REDUCE(1006002003, "优惠劵(码)模板的发放数量不能减小"), PRODUCT_TEMPLATE_STATUS_NOT_ENABLE(1006002004, "优惠劵模板(码)未开启"), - + PRODUCT_TEMPLATE_TOTAL_NOT_ENOUGH(1006002005, "优惠劵(码)模板的发放量不足"), + PRODUCT_TEMPLATE_CARD_ADD_EXCEED_QUOTA(1006002006, "优惠劵领取到达上限"), ; private final int code; diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/CouponCardMapper.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/CouponCardMapper.java index 8560c2e7c..78df37962 100644 --- a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/CouponCardMapper.java +++ b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/CouponCardMapper.java @@ -15,6 +15,9 @@ public interface CouponCardMapper { Integer selectCountByPage(@Param("status") Integer status); + int selectCountByUserIdAndTemplateId(@Param("userId") Integer userId, + @Param("templateId") Integer templateId); + void insert(CouponCardDO couponCardDO); int update(CouponCardDO couponCardDO); diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/CouponTemplateMapper.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/CouponTemplateMapper.java index 7bf2f1639..23195949c 100644 --- a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/CouponTemplateMapper.java +++ b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/CouponTemplateMapper.java @@ -27,4 +27,6 @@ public interface CouponTemplateMapper { int update(CouponTemplateDO couponTemplate); + int updateStatFetchNumIncr(@Param("id") Integer id); + } diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/CouponServiceImpl.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/CouponServiceImpl.java index 5cd78f229..490057175 100644 --- a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/CouponServiceImpl.java +++ b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/CouponServiceImpl.java @@ -19,6 +19,7 @@ import cn.iocoder.mall.promotion.biz.dataobject.CouponCardDO; import cn.iocoder.mall.promotion.biz.dataobject.CouponTemplateDO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.Calendar; import java.util.Date; @@ -176,6 +177,7 @@ public class CouponServiceImpl implements CouponService { // ========== 优惠劵 ========== @Override + @Transactional public CommonResult addCouponCard(Integer userId, Integer couponTemplateId) { // 校验 CouponCardTemplate 存在 CouponTemplateDO template = couponTemplateMapper.selectById(couponTemplateId); @@ -190,6 +192,19 @@ public class CouponServiceImpl implements CouponService { if (!CouponTemplateStatusEnum.ENABLE.getValue().equals(template.getStatus())) { return ServiceExceptionUtil.error(PromotionErrorCodeEnum.PRODUCT_TEMPLATE_STATUS_NOT_ENABLE.getCode()); } + // 校验 CouponCardTemplate 是否到达可领取的上限 + if (template.getStatFetchNum() > template.getTotal()) { + return ServiceExceptionUtil.error(PromotionErrorCodeEnum.PRODUCT_TEMPLATE_TOTAL_NOT_ENOUGH.getCode()); + } + // 校验单人可领取优惠劵是否到达上限 + if (couponCardMapper.selectCountByUserIdAndTemplateId(userId, couponTemplateId) > template.getQuota()) { + return ServiceExceptionUtil.error(PromotionErrorCodeEnum.PRODUCT_TEMPLATE_CARD_ADD_EXCEED_QUOTA.getCode()); + } + // 增加优惠劵已领取量 + int updateTemplateCount = couponTemplateMapper.updateStatFetchNumIncr(couponTemplateId); + if (updateTemplateCount == 0) { // 超过 CouponCardTemplate 发放量 + return ServiceExceptionUtil.error(PromotionErrorCodeEnum.PRODUCT_TEMPLATE_CARD_ADD_EXCEED_QUOTA.getCode()); + } // 创建优惠劵 // 1. 基本信息 + 领取情况 CouponCardDO card = new CouponCardDO() diff --git a/promotion/promotion-service-impl/src/main/resources/mapper/CouponCardMapper.xml b/promotion/promotion-service-impl/src/main/resources/mapper/CouponCardMapper.xml index 1082ebe80..670822568 100644 --- a/promotion/promotion-service-impl/src/main/resources/mapper/CouponCardMapper.xml +++ b/promotion/promotion-service-impl/src/main/resources/mapper/CouponCardMapper.xml @@ -56,6 +56,20 @@ + + INSERT INTO coupon_card ( template_id, status, user_id, take_type, diff --git a/promotion/promotion-service-impl/src/main/resources/mapper/CouponTemplateMapper.xml b/promotion/promotion-service-impl/src/main/resources/mapper/CouponTemplateMapper.xml index 8a4938ded..3f323a821 100644 --- a/promotion/promotion-service-impl/src/main/resources/mapper/CouponTemplateMapper.xml +++ b/promotion/promotion-service-impl/src/main/resources/mapper/CouponTemplateMapper.xml @@ -149,4 +149,11 @@ WHERE id = #{id} + + UPDATE coupon_template + SET stat_fetch_Num = stat_fetch_Num + 1 + WHERE id = #{id} + AND total > stat_fetch_Num + + diff --git a/user/user-application/src/main/java/cn/iocoder/mall/user/application/config/MVCConfiguration.java b/user/user-application/src/main/java/cn/iocoder/mall/user/application/config/MVCConfiguration.java index 6ac5b0a5c..ac6ff8cbc 100644 --- a/user/user-application/src/main/java/cn/iocoder/mall/user/application/config/MVCConfiguration.java +++ b/user/user-application/src/main/java/cn/iocoder/mall/user/application/config/MVCConfiguration.java @@ -49,4 +49,4 @@ public class MVCConfiguration implements WebMvcConfigurer { return registrationBean; } -} \ No newline at end of file +} diff --git a/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/dto/UserAccessLogAddDTO.java b/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/dto/UserAccessLogAddDTO.java index 1b50edb8a..015ce0d01 100644 --- a/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/dto/UserAccessLogAddDTO.java +++ b/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/dto/UserAccessLogAddDTO.java @@ -4,6 +4,7 @@ import lombok.Data; import lombok.experimental.Accessors; import javax.validation.constraints.NotNull; +import java.io.Serializable; import java.util.Date; /** @@ -11,7 +12,7 @@ import java.util.Date; */ @Data @Accessors(chain = true) -public class UserAccessLogAddDTO { +public class UserAccessLogAddDTO implements Serializable { /** * 用户编号 - 空 From 92ed97faed632a8aa11f592a955e030c6673eaac Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Sun, 7 Apr 2019 22:40:28 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=90=8E=E7=AB=AF=EF=BC=9A=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=BC=98=E6=83=A0=E5=8A=B5=E5=88=86=E9=A1=B5=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mobile-web/src/config/env.js | 10 +++---- .../admins/AdminsCouponController.java | 3 ++ .../users/UsersCouponController.java | 20 +++++++++++++ .../convert/CouponCardConvert.java | 6 ++++ .../vo/users/UsersCouponCardPageVO.java | 20 +++++++++++++ .../mall/promotion/api/CouponService.java | 3 ++ .../promotion/api/bo/CouponCardPageBO.java | 24 +++++++++++++++ .../promotion/api/dto/CouponCardPageDTO.java | 29 +++++++++++++++++++ .../promotion/biz/dao/CouponCardMapper.java | 8 +++-- .../biz/service/CouponServiceImpl.java | 15 ++++++++++ .../resources/mapper/CouponCardMapper.xml | 6 ++++ 11 files changed, 137 insertions(+), 7 deletions(-) create mode 100644 promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/users/UsersCouponCardPageVO.java create mode 100644 promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/bo/CouponCardPageBO.java create mode 100644 promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/dto/CouponCardPageDTO.java diff --git a/mobile-web/src/config/env.js b/mobile-web/src/config/env.js index c8859f77d..a8e7df4aa 100644 --- a/mobile-web/src/config/env.js +++ b/mobile-web/src/config/env.js @@ -1,12 +1,12 @@ /** * 配置编译环境和线上环境之间的切换 - * + * * baseUrl: 域名地址 * routerMode: 路由模式 * dataSources:数据源 */ -let baseUrl = ''; +let baseUrl = ''; let routerMode = 'hash'; let dataSources='local';//local=本地,其他值代表非本地 @@ -20,11 +20,11 @@ if (!process.env.NODE_ENV || process.env.NODE_ENV == 'development') { // baseUrl = 'http://127.0.0.1'; // baseUrl = 'http://180.167.213.26:18099'; -dataSources = 'remote'; -// dataSources = 'local'; +// dataSources = 'remote'; +dataSources = 'local'; export { baseUrl, routerMode, dataSources, -} \ No newline at end of file +} diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsCouponController.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsCouponController.java index 589564ebb..7bb9f199f 100644 --- a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsCouponController.java +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsCouponController.java @@ -35,7 +35,10 @@ public class AdminsCouponController { @GetMapping("/template/page") @ApiOperation(value = "优惠劵(码)模板分页") @ApiImplicitParams({ + @ApiImplicitParam(name = "type", value = "类型", example = "参考 CouponTemplateTypeEnum 枚举"), @ApiImplicitParam(name = "title", value = "标题,模糊匹配", example = "活动 A"), + @ApiImplicitParam(name = "status", value = "状态", example = "参考 CouponTemplateStatusEnum 枚举"), + @ApiImplicitParam(name = "preferentialType", value = "优惠类型", example = "参考 CouponTemplatePreferentialTypeEnum 枚举"), @ApiImplicitParam(name = "pageNo", value = "页码,从 1 开始", example = "1"), @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, example = "10"), }) diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersCouponController.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersCouponController.java index fcf5eb157..ba8011eac 100644 --- a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersCouponController.java +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersCouponController.java @@ -3,9 +3,12 @@ package cn.iocoder.mall.promotion.application.controller.users; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.promotion.api.CouponService; import cn.iocoder.mall.promotion.api.bo.CouponCardBO; +import cn.iocoder.mall.promotion.api.bo.CouponCardPageBO; import cn.iocoder.mall.promotion.api.bo.CouponTemplateBO; +import cn.iocoder.mall.promotion.api.dto.CouponCardPageDTO; import cn.iocoder.mall.promotion.application.convert.CouponCardConvert; import cn.iocoder.mall.promotion.application.convert.CouponTemplateConvert; +import cn.iocoder.mall.promotion.application.vo.users.UsersCouponCardPageVO; import cn.iocoder.mall.promotion.application.vo.users.UsersCouponCardVO; import cn.iocoder.mall.promotion.application.vo.users.UsersCouponTemplateVO; import cn.iocoder.mall.user.sdk.annotation.PermitAll; @@ -13,6 +16,7 @@ import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder; import com.alibaba.dubbo.config.annotation.Reference; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.*; @@ -37,6 +41,22 @@ public class UsersCouponController { // ========== 优惠劵 ========== + @GetMapping("/card/page") + @ApiOperation(value = "优惠劵分页") + @ApiImplicitParams({ + @ApiImplicitParam(name = "status", value = "状态", example = "参考 CouponCardStatusEnum 枚举"), + @ApiImplicitParam(name = "pageNo", value = "页码,从 1 开始", example = "1"), + @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, example = "10"), + }) + public CommonResult cardPage(@RequestParam(value = "status", required = false) Integer status, + @RequestParam(value = "pageNo", defaultValue = "0") Integer pageNo, + @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { + CommonResult result = couponService.getCouponCardPage(new CouponCardPageDTO() + .setStatus(status).setUserId(UserSecurityContextHolder.getContext().getUserId()) + .setPageNo(pageNo).setPageSize(pageSize)); + return CouponCardConvert.INSTANCE.convert2(result); + } + @PostMapping("/card/add") @ApiOperation(value = "领取优惠劵") @ApiImplicitParam(name = "templateId", value = "优惠劵(码)模板编号", required = true, example = "10") diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/convert/CouponCardConvert.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/convert/CouponCardConvert.java index 3ec4d00f2..2a676dba7 100644 --- a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/convert/CouponCardConvert.java +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/convert/CouponCardConvert.java @@ -2,6 +2,8 @@ package cn.iocoder.mall.promotion.application.convert; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.promotion.api.bo.CouponCardBO; +import cn.iocoder.mall.promotion.api.bo.CouponCardPageBO; +import cn.iocoder.mall.promotion.application.vo.users.UsersCouponCardPageVO; import cn.iocoder.mall.promotion.application.vo.users.UsersCouponCardVO; import org.mapstruct.Mapper; import org.mapstruct.Mappings; @@ -14,6 +16,10 @@ public interface CouponCardConvert { @Mappings({}) CommonResult convert(CommonResult result); + + @Mappings({}) + CommonResult convert2(CommonResult result); + // // @Mappings({}) // List convertList2(List banners); diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/users/UsersCouponCardPageVO.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/users/UsersCouponCardPageVO.java new file mode 100644 index 000000000..cd12eca5d --- /dev/null +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/users/UsersCouponCardPageVO.java @@ -0,0 +1,20 @@ +package cn.iocoder.mall.promotion.application.vo.users; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.util.List; + +@ApiModel("优惠劵分页 VO") +@Data +@Accessors(chain = true) +public class UsersCouponCardPageVO { + + @ApiModelProperty(value = "优惠劵数组") + private List list; + @ApiModelProperty(value = "优惠劵总数") + private Integer total; + +} diff --git a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/CouponService.java b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/CouponService.java index 2c867cd4f..7101a8db5 100644 --- a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/CouponService.java +++ b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/CouponService.java @@ -3,6 +3,7 @@ package cn.iocoder.mall.promotion.api; import cn.iocoder.common.framework.validator.InEnum; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.promotion.api.bo.CouponCardBO; +import cn.iocoder.mall.promotion.api.bo.CouponCardPageBO; import cn.iocoder.mall.promotion.api.bo.CouponTemplateBO; import cn.iocoder.mall.promotion.api.bo.CouponTemplatePageBO; import cn.iocoder.mall.promotion.api.constant.CouponTemplateStatusEnum; @@ -61,6 +62,8 @@ public interface CouponService { // ========== 优惠劵 ========== + CommonResult getCouponCardPage(CouponCardPageDTO couponCardPageDTO); + /** * 基于优惠劵模板,领取优惠劵 * diff --git a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/bo/CouponCardPageBO.java b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/bo/CouponCardPageBO.java new file mode 100644 index 000000000..44150c24a --- /dev/null +++ b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/bo/CouponCardPageBO.java @@ -0,0 +1,24 @@ +package cn.iocoder.mall.promotion.api.bo; + +import lombok.Data; +import lombok.experimental.Accessors; + +import java.util.List; + +/** + * 优惠劵分页 BO + */ +@Data +@Accessors(chain = true) +public class CouponCardPageBO { + + /** + * 优惠劵数组 + */ + private List list; + /** + * 总量 + */ + private Integer total; + +} diff --git a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/dto/CouponCardPageDTO.java b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/dto/CouponCardPageDTO.java new file mode 100644 index 000000000..8b76b3290 --- /dev/null +++ b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/dto/CouponCardPageDTO.java @@ -0,0 +1,29 @@ +package cn.iocoder.mall.promotion.api.dto; + +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotNull; + +/** + * 优惠劵分页 DTO + */ +@Data +@Accessors(chain = true) +public class CouponCardPageDTO { + + /** + * 用户编号 + */ + private Integer userId; + /** + * 状态 + */ + private Integer status; + + @NotNull(message = "页码不能为空") + private Integer pageNo; + @NotNull(message = "每页条数不能为空") + private Integer pageSize; + +} diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/CouponCardMapper.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/CouponCardMapper.java index 78df37962..af4b697ec 100644 --- a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/CouponCardMapper.java +++ b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/CouponCardMapper.java @@ -11,9 +11,13 @@ public interface CouponCardMapper { CouponCardDO selectById(@Param("id") Integer id); - List selectListByPage(@Param("status") Integer status); + List selectListByPage(@Param("userId") Integer userId, + @Param("status") Integer status, + @Param("offset") Integer offset, + @Param("limit") Integer limit); - Integer selectCountByPage(@Param("status") Integer status); + Integer selectCountByPage(@Param("userId") Integer userId, + @Param("status") Integer status); int selectCountByUserIdAndTemplateId(@Param("userId") Integer userId, @Param("templateId") Integer templateId); diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/CouponServiceImpl.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/CouponServiceImpl.java index 490057175..96098ffa1 100644 --- a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/CouponServiceImpl.java +++ b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/CouponServiceImpl.java @@ -6,6 +6,7 @@ import cn.iocoder.common.framework.util.ServiceExceptionUtil; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.promotion.api.CouponService; import cn.iocoder.mall.promotion.api.bo.CouponCardBO; +import cn.iocoder.mall.promotion.api.bo.CouponCardPageBO; import cn.iocoder.mall.promotion.api.bo.CouponTemplateBO; import cn.iocoder.mall.promotion.api.bo.CouponTemplatePageBO; import cn.iocoder.mall.promotion.api.constant.*; @@ -176,6 +177,20 @@ public class CouponServiceImpl implements CouponService { // ========== 优惠劵 ========== + @Override + public CommonResult getCouponCardPage(CouponCardPageDTO couponCardPageDTO) { + CouponCardPageBO pageBO = new CouponCardPageBO(); + // 查询分页数据 + int offset = (couponCardPageDTO.getPageNo() - 1) * couponCardPageDTO.getPageSize(); + pageBO.setList(CouponCardConvert.INSTANCE.convertToBO(couponCardMapper.selectListByPage( + couponCardPageDTO.getUserId(), couponCardPageDTO.getStatus(), + offset, couponCardPageDTO.getPageSize()))); + // 查询分页总数 + pageBO.setTotal(couponCardMapper.selectCountByPage( + couponCardPageDTO.getUserId(), couponCardPageDTO.getStatus())); + return CommonResult.success(pageBO); + } + @Override @Transactional public CommonResult addCouponCard(Integer userId, Integer couponTemplateId) { diff --git a/promotion/promotion-service-impl/src/main/resources/mapper/CouponCardMapper.xml b/promotion/promotion-service-impl/src/main/resources/mapper/CouponCardMapper.xml index 670822568..2242bbb67 100644 --- a/promotion/promotion-service-impl/src/main/resources/mapper/CouponCardMapper.xml +++ b/promotion/promotion-service-impl/src/main/resources/mapper/CouponCardMapper.xml @@ -38,6 +38,9 @@ FROM coupon_card + + AND user_id = #{userId} + AND status = #{status} @@ -50,6 +53,9 @@ COUNT(1) FROM coupon_card + + AND user_id = #{userId} + AND status = #{status} From 235da59f70f6a51b3cd0d213530ac00ab4f57d32 Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Mon, 8 Apr 2019 21:47:23 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E5=89=8D=E7=AB=AF=EF=BC=9A=E4=BC=98?= =?UTF-8?q?=E6=83=A0=E5=8A=B5=E5=88=97=E8=A1=A8=20=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=EF=BC=9A=E5=A2=9E=E5=8A=A0=E8=B7=AF=E7=94=B1=E7=9A=84=E8=AE=A4?= =?UTF-8?q?=E8=AF=81=E6=8B=A6=E6=88=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mobile-web/src/api/promotion.js | 12 + mobile-web/src/config/env.js | 4 +- mobile-web/src/config/router.js | 18 +- mobile-web/src/main.js | 10 +- mobile-web/src/page/account/phonelogin.vue | 5 +- mobile-web/src/page/user/coupon/list.vue | 271 +++++++++++------- mobile-web/src/utils/date.js | 15 + .../order/api/dto/OrderCreateItemDTO.java | 5 + .../mall/order/api/dto/OrderDeliveryDTO.java | 5 + .../order/api/dto/OrderItemDeletedDTO.java | 5 + .../order/api/dto/OrderItemUpdateDTO.java | 5 + .../api/dto/OrderLogisticsUpdateDTO.java | 5 + .../mall/order/api/dto/OrderQueryDTO.java | 5 + .../order/api/dto/OrderReturnCreateDTO.java | 5 + .../vo/users/UsersCouponCardVO.java | 4 + .../mall/promotion/api/bo/CouponCardBO.java | 8 + .../constant/CouponTemplateStatusEnum.java | 4 +- .../biz/dataobject/CouponCardDO.java | 12 + .../biz/dataobject/CouponCodeDO.java | 2 + .../biz/dataobject/CouponTemplateDO.java | 25 +- .../biz/scheduler/CouponCardExpireJob.java | 9 + .../biz/service/CouponServiceImpl.java | 2 + .../resources/mapper/CouponCardMapper.xml | 12 +- 23 files changed, 321 insertions(+), 127 deletions(-) create mode 100644 mobile-web/src/utils/date.js create mode 100644 promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/scheduler/CouponCardExpireJob.java diff --git a/mobile-web/src/api/promotion.js b/mobile-web/src/api/promotion.js index 37a96ff50..6917997b1 100644 --- a/mobile-web/src/api/promotion.js +++ b/mobile-web/src/api/promotion.js @@ -41,3 +41,15 @@ export function doAddCouponCard(templateId) { } // Coupon Card + +export function getCouponPage(status, pageNo, pageSize) { + return request({ + url: '/promotion-api/users/coupon/card/page', + method: 'get', + params: { + status, + pageNo, + pageSize + } + }); +} diff --git a/mobile-web/src/config/env.js b/mobile-web/src/config/env.js index a8e7df4aa..ab335a08f 100644 --- a/mobile-web/src/config/env.js +++ b/mobile-web/src/config/env.js @@ -20,8 +20,8 @@ if (!process.env.NODE_ENV || process.env.NODE_ENV == 'development') { // baseUrl = 'http://127.0.0.1'; // baseUrl = 'http://180.167.213.26:18099'; -// dataSources = 'remote'; -dataSources = 'local'; +dataSources = 'remote'; +// dataSources = 'local'; export { baseUrl, diff --git a/mobile-web/src/config/router.js b/mobile-web/src/config/router.js index f519f6f19..d9bfa06e5 100644 --- a/mobile-web/src/config/router.js +++ b/mobile-web/src/config/router.js @@ -1,6 +1,8 @@ import Vue from 'vue'; import Router from 'vue-router'; +import { getAccessToken } from '../utils/cache'; + Vue.use(Router); const routes = [ @@ -84,7 +86,8 @@ const routes = [ path: '/user/coupon', component: () => import('../page/user/coupon/list'), meta: { - title: '我的优惠券' + title: '我的优惠券', + requireAuth: true, } }, { @@ -202,10 +205,23 @@ routes.forEach(route => { const router = new Router({ routes }); router.beforeEach((to, from, next) => { + // 判断是否需要认证 + const requireAuth = to.meta && to.meta.requireAuth; + if (requireAuth) { + if (!getAccessToken()) { // 未登陆 + next({ + path: '/login', + query: {redirect: to.fullPath} // 将跳转的路由path作为参数,登录成功后跳转到该路由 + }); + return; + } + } + // 处理标题 const title = to.meta && to.meta.title; if (title) { document.title = title; } + // 继续路由 next(); }); diff --git a/mobile-web/src/main.js b/mobile-web/src/main.js index ff8d752cb..9577aa1c7 100644 --- a/mobile-web/src/main.js +++ b/mobile-web/src/main.js @@ -7,6 +7,8 @@ import VueLazyload from 'vue-lazyload' import components from './config/components.js'; import { Dialog } from 'vant'; +import { formatDate } from './utils/date.js'; + Vue.use(components); Vue.use(VueLazyload); @@ -16,4 +18,10 @@ new Vue({ router, el: '#app', render: h => h(App) -}); \ No newline at end of file +}); + +Vue.filter('formatDate', function(date, pattern) { + if (date) { + return formatDate(date, pattern); + } +}); diff --git a/mobile-web/src/page/account/phonelogin.vue b/mobile-web/src/page/account/phonelogin.vue index 866404bcf..6fe20cb64 100644 --- a/mobile-web/src/page/account/phonelogin.vue +++ b/mobile-web/src/page/account/phonelogin.vue @@ -73,8 +73,9 @@ export default { message: '登陆成功', beforeClose: function (action, done) { done(); - // TODO 芋艿,先暂时不做 callback - that.$router.push('/user/index'); + // TODO 芋艿,简单的 callback 后续完善 + let redirect = that.$route.query.redirect || '/user/index'; + that.$router.push(redirect); } }); }); diff --git a/mobile-web/src/page/user/coupon/list.vue b/mobile-web/src/page/user/coupon/list.vue index ba2ed7e3e..044ba9a69 100644 --- a/mobile-web/src/page/user/coupon/list.vue +++ b/mobile-web/src/page/user/coupon/list.vue @@ -6,7 +6,7 @@ center clearable placeholder="请输入优惠码" - + v-model="couponCode" > 兑换 @@ -16,41 +16,50 @@
    -
  • +
  • -
    - {{item.Sign}} - {{item.Coupon}} - {{item.Sign}} +
    + + {{item.priceOff / 100}} +
    +
    + {{item.percentOff / 10.0}} +
    - {{item.Condition}} + 满 {{item.priceAvailable}} 元可用
    - {{item.Name}}
    + {{item.title}}
    - {{item.BeginDate}}-{{item.EndDate}} - + {{item.validStartTime | formatDate('yyyy-MM-dd')}} + ~ {{item.validEndTime | formatDate('yyyy-MM-dd')}}
    立即使用
    -
    - 详细信息 - -
    -
    + + + + + + + + + + +
    {{item.Info}}
    @@ -62,32 +71,35 @@
      -
    • +
    • -
      - {{item.Sign}} - {{item.Coupon}} - {{item.Sign}} +
      + + {{item.priceOff / 100}} +
      +
      + {{item.percentOff / 10.0}} +
      - {{item.Condition}} + 满 {{item.priceAvailable}} 元可用
      - {{item.Name}}
      + {{item.title}}
      - {{item.BeginDate}}-{{item.EndDate}} - + {{item.validStartTime | formatDate('yyyy-MM-dd')}} + ~ {{item.validEndTime | formatDate('yyyy-MM-dd')}}
      @@ -97,34 +109,37 @@
        - + -
      • +
      • -
        - {{item.Sign}} - {{item.Coupon}} - {{item.Sign}} +
        + + {{item.priceOff / 100}} +
        +
        + {{item.percentOff / 10.0}} +
        - {{item.Condition}} + 满 {{item.priceAvailable}} 元可用
        - {{item.Name}}
        + {{item.title}}
        - {{item.BeginDate}}-{{item.EndDate}} - + {{item.validStartTime | formatDate('yyyy-MM-dd')}} + ~ {{item.validEndTime | formatDate('yyyy-MM-dd')}}
        @@ -138,83 +153,131 @@