diff --git a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/Final/AppletCouponType.java b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/Final/AppletCouponType.java index a380fe9..40d5d52 100644 --- a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/Final/AppletCouponType.java +++ b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/Final/AppletCouponType.java @@ -1,4 +1,9 @@ package org.jeecg.modules.applet.Final; public class AppletCouponType { + + public static final String MANUAL = "0"; + public static final String NEW_USER = "1";//新用户自动领取 + + } diff --git a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiLoginService.java b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiLoginService.java index 418a326..fac2fe9 100644 --- a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiLoginService.java +++ b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiLoginService.java @@ -11,15 +11,19 @@ import org.jeecg.common.system.util.JwtUtil; import org.jeecg.common.system.vo.AppletUser; import org.jeecg.common.api.IAppletUserService; import org.jeecg.common.util.RedisUtil; +import org.jeecg.modules.applet.Final.AppletCouponType; import org.jeecg.modules.applet.Final.LoginType; import org.jeecg.modules.common.wxUtils.WxHttpClientUtil; import org.jeecg.modules.common.wxUtils.WxHttpUtils; +import org.jeecg.modules.demo.appletCoupon.entity.AppletCoupon; +import org.jeecg.modules.demo.appletCoupon.service.IAppletCouponService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import java.util.Date; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -42,6 +46,9 @@ public class AppletApiLoginService { @Autowired private RedisUtil redisUtil; + @Autowired + private IAppletCouponService appletCouponService; + private JSONObject openLogin(String code, String type){ log.info("开始小程序登录,code: {}", code); // 调用微信API获取openid和session_key @@ -236,6 +243,9 @@ public class AppletApiLoginService { // 保存到数据库 appletUserService.save(user); log.info("创建小程序用户成功: {}", user.getName()); + + appletCouponService.distributeCouponByType(AppletCouponType.NEW_USER, user.getId()); + } else { log.info("找到已存在的小程序用户: {}", user.getName()); } diff --git a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletCoupon/entity/AppletCoupon.java b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletCoupon/entity/AppletCoupon.java index 62e893c..3b65565 100644 --- a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletCoupon/entity/AppletCoupon.java +++ b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletCoupon/entity/AppletCoupon.java @@ -33,49 +33,75 @@ import lombok.experimental.Accessors; public class AppletCoupon implements Serializable { private static final long serialVersionUID = 1L; - /**主键*/ - @TableId(type = IdType.ASSIGN_ID) + /** + * 主键 + */ + @TableId(type = IdType.ASSIGN_ID) @Schema(description = "主键") private java.lang.String id; - /**创建人*/ + /** + * 创建人 + */ @Schema(description = "创建人") private java.lang.String createBy; - /**创建日期*/ - @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") - @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + /** + * 创建日期 + */ + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @Schema(description = "创建日期") private java.util.Date createTime; - /**更新人*/ + /** + * 更新人 + */ @Schema(description = "更新人") private java.lang.String updateBy; - /**更新日期*/ - @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") - @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + /** + * 更新日期 + */ + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @Schema(description = "更新日期") private java.util.Date updateTime; - /**所属部门*/ + /** + * 所属部门 + */ @Schema(description = "所属部门") private java.lang.String sysOrgCode; - /**优惠券名称*/ - @Excel(name = "优惠券名称", width = 15) + /** + * 优惠券名称 + */ + @Excel(name = "优惠券名称", width = 15) @Schema(description = "优惠券名称") private java.lang.String name; - /**面额*/ - @Excel(name = "面额", width = 15) + /** + * 面额 + */ + @Excel(name = "面额", width = 15) @Schema(description = "面额") private java.math.BigDecimal money; - /**有效期*/ - @Excel(name = "有效期", width = 20, format = "yyyy-MM-dd HH:mm:ss") - @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") - @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + /** + * 有效期 + */ + @Excel(name = "有效期", width = 20, format = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @Schema(description = "有效期") private java.util.Date endTime; - /**发放数量*/ - @Excel(name = "发放数量", width = 15) + /** + * 发放数量 + */ + @Excel(name = "发放数量", width = 15) @Schema(description = "发放数量") private java.lang.Integer count; - /**已使用数量*/ - @Excel(name = "已使用数量", width = 15) + /** + * 已使用数量 + */ + @Excel(name = "已使用数量", width = 15) @Schema(description = "已使用数量") private java.lang.Integer quantityused; -} + + @Dict(dicCode = "applet_discount_coupon_type") + private java.lang.String type; + +} \ No newline at end of file diff --git a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletCoupon/service/IAppletCouponService.java b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletCoupon/service/IAppletCouponService.java index ca6109d..5489fa6 100644 --- a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletCoupon/service/IAppletCouponService.java +++ b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletCoupon/service/IAppletCouponService.java @@ -19,6 +19,14 @@ public interface IAppletCouponService extends IService { */ void distributeCoupon(String couponId, String userIds); + + /** + * 优惠券根据类型批量发放 + * @param type 优惠券类型 + * @param userIds 用户ID列表,为空表示发放给所有用户 + */ + void distributeCouponByType(String type, String userIds); + /** * 优惠券核销 * @param recordId 优惠券记录ID diff --git a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletCoupon/service/impl/AppletCouponServiceImpl.java b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletCoupon/service/impl/AppletCouponServiceImpl.java index 4b424d2..a44ad4a 100644 --- a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletCoupon/service/impl/AppletCouponServiceImpl.java +++ b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletCoupon/service/impl/AppletCouponServiceImpl.java @@ -1,6 +1,7 @@ package org.jeecg.modules.demo.appletCoupon.service.impl; import org.jeecg.common.exception.JeecgBootException; +import org.jeecg.modules.applet.Final.AppletCouponType; import org.jeecg.modules.demo.appletCoupon.entity.AppletCoupon; import org.jeecg.modules.demo.appletCoupon.mapper.AppletCouponMapper; import org.jeecg.modules.demo.appletCoupon.service.IAppletCouponService; @@ -86,6 +87,17 @@ public class AppletCouponServiceImpl extends ServiceImpl list = lambdaQuery() + .eq(AppletCoupon::getType, type) + .list(); + for (AppletCoupon coupon : list){ + distributeCoupon(coupon.getId(), userIds); + } + } + @Override @Transactional(rollbackFor = Exception.class) public AppletCouponRecord useCoupon(String recordId, String userId) { diff --git a/jeecgboot-vue3/src/views/applet/coupon/AppletCoupon.data.ts b/jeecgboot-vue3/src/views/applet/coupon/AppletCoupon.data.ts index 2ed723b..153d1d4 100644 --- a/jeecgboot-vue3/src/views/applet/coupon/AppletCoupon.data.ts +++ b/jeecgboot-vue3/src/views/applet/coupon/AppletCoupon.data.ts @@ -15,6 +15,11 @@ export const columns: BasicColumn[] = [ align:"center", dataIndex: 'money' }, + { + title: '优惠券类型', + align:"center", + dataIndex: 'type_dictText' + }, { title: '有效期', align:"center", @@ -46,6 +51,15 @@ export const formSchema: FormSchema[] = [ field: 'money', component: 'InputNumber', }, + { + label: '优惠券类型', + field: 'type', + component: 'JDictSelectTag', + componentProps: { + dictCode: 'applet_discount_coupon_type', + type: 'radio', + }, + }, { label: '有效期', field: 'endTime', @@ -78,9 +92,10 @@ export const formSchema: FormSchema[] = [ export const superQuerySchema = { name: {title: '优惠券名称',order: 0,view: 'text', type: 'string',}, money: {title: '面额',order: 1,view: 'number', type: 'number',}, - endTime: {title: '有效期',order: 2,view: 'datetime', type: 'string',}, - count: {title: '发放数量',order: 3,view: 'text', type: 'string',}, - quantityused: {title: '已使用数量',order: 4,view: 'text', type: 'string',}, + type: {title: '优惠券类型',order: 2,view: 'list', type: 'string',dictCode: 'applet_discount_coupon_type',}, + endTime: {title: '有效期',order: 3,view: 'datetime', type: 'string',}, + count: {title: '发放数量',order: 4,view: 'text', type: 'string',}, + quantityused: {title: '已使用数量',order: 5,view: 'text', type: 'string',}, }; /** diff --git a/jeecgboot-vue3/src/views/applet/course-page/AppletCoursePageList.vue b/jeecgboot-vue3/src/views/applet/course-page/AppletCoursePageList.vue index 9e582a4..ca583a3 100644 --- a/jeecgboot-vue3/src/views/applet/course-page/AppletCoursePageList.vue +++ b/jeecgboot-vue3/src/views/applet/course-page/AppletCoursePageList.vue @@ -24,15 +24,8 @@
- +