Explorar o código

20240704 邀请会员

lwhhszx hai 1 ano
pai
achega
05fcb32a07
Modificáronse 20 ficheiros con 253 adicións e 52 borrados
  1. 1 1
      src/main/java/com/example/xiaoshiweixinback/business/exception/BusinessException.java
  2. 2 2
      src/main/java/com/example/xiaoshiweixinback/business/exception/ExceptionEnum.java
  3. 1 0
      src/main/java/com/example/xiaoshiweixinback/controller/VoucherManageController.java
  4. 6 6
      src/main/java/com/example/xiaoshiweixinback/domain/DiscountStrategy.java
  5. 41 0
      src/main/java/com/example/xiaoshiweixinback/domain/AssoActivityVoucher.java
  6. 1 0
      src/main/java/com/example/xiaoshiweixinback/domain/AssoPersonVoucher.java
  7. 1 1
      src/main/java/com/example/xiaoshiweixinback/domain/Voucher.java
  8. 1 1
      src/main/java/com/example/xiaoshiweixinback/entity/assoPersonVoucher/SendVoucherToPersonVO.java
  9. 5 0
      src/main/java/com/example/xiaoshiweixinback/factorys/goodFactory/GoodVipService.java
  10. 1 0
      src/main/java/com/example/xiaoshiweixinback/factorys/goodFactory/GoodVoucherService.java
  11. 20 0
      src/main/java/com/example/xiaoshiweixinback/mapper/ActivityMapper.java
  12. 18 0
      src/main/java/com/example/xiaoshiweixinback/mapper/AssoActivityVoucherMapper.java
  13. 0 18
      src/main/java/com/example/xiaoshiweixinback/mapper/DiscountStrategyMapper.java
  14. 80 0
      src/main/java/com/example/xiaoshiweixinback/service/ActivityService.java
  15. 33 0
      src/main/java/com/example/xiaoshiweixinback/service/AssoActivityVoucherService.java
  16. 4 3
      src/main/java/com/example/xiaoshiweixinback/service/AssoPersonVoucherService.java
  17. 0 20
      src/main/java/com/example/xiaoshiweixinback/service/DiscountStrategyService.java
  18. 3 0
      src/main/java/com/example/xiaoshiweixinback/service/InviteMessageService.java
  19. 18 0
      src/main/resources/mapper/ActivityMapper.xml
  20. 17 0
      src/main/resources/mapper/AssoVipFunctionMapper.xml

+ 1 - 1
src/main/java/com/example/xiaoshiweixinback/business/exception/BusinessException.java

@@ -17,7 +17,7 @@ public class BusinessException extends RuntimeException {
 
 	public BusinessException(ExceptionEnum e, String errorMessage) {
 		super(errorMessage);
-		this.errorCode = errorCode;
+		this.errorCode = e.getCode();
 		this.errorMessage = errorMessage;
 	}
 

+ 2 - 2
src/main/java/com/example/xiaoshiweixinback/business/exception/ExceptionEnum.java

@@ -14,8 +14,8 @@ public enum ExceptionEnum {
     PERMISSION_NO_VIP("606","未开会员"),
     PERMISSION_BEYOND_USETIME("607","超过使用次数"),
 
-    BUSINESS_ERROR("608","业务错误"),
-    BUSINESS_CHECK("609","参数校验错误"),
+    BUSINESS_ERROR("708","业务错误"),
+    BUSINESS_CHECK("709","参数校验错误"),
     /*APP端 100000-300000*/
     SUCCESS("000000", "调用成功"),
     PARAMETER_VERIFICATION_ERROR("000001", "数据参数校验异常"),

+ 1 - 0
src/main/java/com/example/xiaoshiweixinback/controller/VoucherManageController.java

@@ -73,6 +73,7 @@ public class VoucherManageController {
     @PostMapping("/sendVoucherToPerson")
     public Response sendVoucherToPerson (@RequestBody SendVoucherToPersonVO sendVoucherToPersonVO) {
         try {
+            sendVoucherToPersonVO.setGetWay(0);
             assoPersonVoucherService.sendVoucherToPerson(sendVoucherToPersonVO);
         }
         catch (Exception e)

+ 6 - 6
src/main/java/com/example/xiaoshiweixinback/domain/DiscountStrategy.java

@@ -8,16 +8,15 @@ import java.io.Serializable;
 import java.util.Date;
 
 import com.example.xiaoshiweixinback.domain.BaseEntity;
-import com.example.xiaoshiweixinback.domain.Monitor;
 import lombok.Data;
 
 /**
  * 折扣策略
- * @TableName discount_strategy
+ * @TableName activity
  */
-@TableName(value ="discount_strategy")
+@TableName(value ="activity")
 @Data
-public class DiscountStrategy extends BaseEntity<DiscountStrategy> {
+public class Activity extends BaseEntity<Activity> {
     /**
      * ID
      */
@@ -63,12 +62,13 @@ public class DiscountStrategy extends BaseEntity<DiscountStrategy> {
     private Double threshold;
 
     /**
-     *
+     * 
      */
     private String createId;
 
     /**
-     *
+     * 
      */
     private Date createTime;
+
 }

+ 41 - 0
src/main/java/com/example/xiaoshiweixinback/domain/AssoActivityVoucher.java

@@ -0,0 +1,41 @@
+package com.example.xiaoshiweixinback.domain;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import java.io.Serializable;
+
+import com.example.xiaoshiweixinback.domain.Activity;
+import com.example.xiaoshiweixinback.domain.BaseEntity;
+import lombok.Data;
+
+/**
+ * 活动和优惠券关联表
+ * @TableName asso_activity_voucher
+ */
+@TableName(value ="asso_activity_voucher")
+@Data
+public class AssoActivityVoucher extends BaseEntity<AssoActivityVoucher> {
+    /**
+     * ID
+     */
+    @TableId(type = IdType.AUTO)
+    private Integer id;
+
+    /**
+     * 活动id
+     */
+    private Integer activityId;
+
+    /**
+     * 优惠券id
+     */
+    private Integer voucherId;
+
+    /**
+     * 优惠券数量
+     */
+    private Integer voucherNum;
+
+}

+ 1 - 0
src/main/java/com/example/xiaoshiweixinback/domain/AssoPersonVoucher.java

@@ -70,5 +70,6 @@ public class AssoPersonVoucher   extends BaseEntity<AssoPersonVoucher>{
      *
      */
     private Date createTime;
+    private Integer getWay;
 
 }

+ 1 - 1
src/main/java/com/example/xiaoshiweixinback/domain/Voucher.java

@@ -8,7 +8,7 @@ import java.io.Serializable;
 import java.util.Date;
 
 import com.example.xiaoshiweixinback.domain.BaseEntity;
-import com.example.xiaoshiweixinback.domain.DiscountStrategy;
+
 import lombok.Data;
 
 /**

+ 1 - 1
src/main/java/com/example/xiaoshiweixinback/entity/assoPersonVoucher/SendVoucherToPersonVO.java

@@ -9,7 +9,7 @@ import java.util.List;
 public class SendVoucherToPersonVO {
     private List<String> personUuids;
     private List<InAddVoucherVO> inAddVoucherVOS;
-
+    private Integer getWay;
     @Data
     public static class InAddVoucherVO {
         private Integer voucherId;

+ 5 - 0
src/main/java/com/example/xiaoshiweixinback/factorys/goodFactory/GoodVipService.java

@@ -6,6 +6,7 @@ import com.example.xiaoshiweixinback.business.exception.ExceptionEnum;
 import com.example.xiaoshiweixinback.business.utils.FormatUtil;
 import com.example.xiaoshiweixinback.domain.*;
 import com.example.xiaoshiweixinback.entity.weixinPay.GoodVO;
+import com.example.xiaoshiweixinback.service.ActivityService;
 import com.example.xiaoshiweixinback.service.VipService;
 import lombok.RequiredArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -19,10 +20,14 @@ import java.util.stream.Collectors;
 @RequiredArgsConstructor
 public class GoodVipService implements GoodImp {
     private final VipService vipService;
+    private final ActivityService activityService;
+    private static Integer ACTIVITY_SCOPE=-1;
 @Override
 public void activeGood(Order order, List<AssoPayOrderGood> assoPayOrderGoods){
 AssoPayOrderGood assoPayOrderGood =assoPayOrderGoods.get(0);
 vipService.activateVIP(order,assoPayOrderGood.getGoodUuid());
+String personUuid =order.getPersonUuid();
+ activityService.doingActivity(personUuid,ACTIVITY_SCOPE);
 }
 
     @Override

+ 1 - 0
src/main/java/com/example/xiaoshiweixinback/factorys/goodFactory/GoodVoucherService.java

@@ -42,6 +42,7 @@ public class GoodVoucherService implements GoodImp {
             inAddVoucherVOS.add(voucherVO);
         });
         sendVoucherToPersonVO.setInAddVoucherVOS(inAddVoucherVOS);
+        sendVoucherToPersonVO.setGetWay(1);
         assoPersonVoucherService.sendVoucherToPerson(sendVoucherToPersonVO);
     }
 

+ 20 - 0
src/main/java/com/example/xiaoshiweixinback/mapper/ActivityMapper.java

@@ -0,0 +1,20 @@
+package com.example.xiaoshiweixinback.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.example.xiaoshiweixinback.domain.Activity;
+
+import java.util.List;
+
+/**
+* @author admin
+* @description 针对表【activity(折扣策略)】的数据库操作Mapper
+* @createDate 2024-07-03 16:06:58
+* @Entity com/example/xiaoshiweixinback.domain.Activity
+*/
+public interface ActivityMapper extends BaseMapper<Activity> {
+  public List<Activity> queryScopeActivity(Integer scope);
+}
+
+
+
+

+ 18 - 0
src/main/java/com/example/xiaoshiweixinback/mapper/AssoActivityVoucherMapper.java

@@ -0,0 +1,18 @@
+package com.example.xiaoshiweixinback.mapper;
+
+import com.example.xiaoshiweixinback.domain.AssoActivityVoucher;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+* @author admin
+* @description 针对表【asso_activity_voucher(活动和优惠券关联表)】的数据库操作Mapper
+* @createDate 2024-07-03 16:21:37
+* @Entity com/example/xiaoshiweixinback.domain.AssoActivityVoucher
+*/
+public interface AssoActivityVoucherMapper extends BaseMapper<AssoActivityVoucher> {
+
+}
+
+
+
+

+ 0 - 18
src/main/java/com/example/xiaoshiweixinback/mapper/DiscountStrategyMapper.java

@@ -1,18 +0,0 @@
-package com.example.xiaoshiweixinback.mapper;
-
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.example.xiaoshiweixinback.domain.DiscountStrategy;
-
-/**
-* @author admin
-* @description 针对表【discount_strategy(折扣策略)】的数据库操作Mapper
-* @createDate 2024-06-18 23:11:39
-* @Entity com/example/xiaoshiweixinback.domain.DiscountStrategy
-*/
-public interface DiscountStrategyMapper extends BaseMapper<DiscountStrategy> {
-
-}
-
-
-
-

+ 80 - 0
src/main/java/com/example/xiaoshiweixinback/service/ActivityService.java

@@ -0,0 +1,80 @@
+package com.example.xiaoshiweixinback.service;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.example.xiaoshiweixinback.domain.Activity;
+import com.example.xiaoshiweixinback.domain.AssoActivityVoucher;
+import com.example.xiaoshiweixinback.domain.AssoPersonVoucher;
+import com.example.xiaoshiweixinback.domain.AssoVipVoucher;
+import com.example.xiaoshiweixinback.entity.assoPersonVoucher.SendVoucherToPersonVO;
+import com.example.xiaoshiweixinback.mapper.ActivityMapper;
+import lombok.RequiredArgsConstructor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author admin
+ * @description 针对表【activity(折扣策略)】的数据库操作Service实现
+ * @createDate 2024-07-03 16:06:58
+ */
+@Service
+@RequiredArgsConstructor
+public class ActivityService extends ServiceImpl<ActivityMapper, Activity> {
+    @Autowired
+    private AssoActivityVoucherService assoActivityVoucherService;
+    @Autowired
+    private AssoPersonVoucherService assoPersonVoucherService;
+    //根据使用场景id查询活动
+    public List<Activity> getActivities(Integer useScope) {
+        List<Activity> activities = this.getBaseMapper().queryScopeActivity(useScope);
+        if(activities.size()==0){
+            return null;
+        }
+        Activity activity =activities.get(0);
+        return activities;
+    }
+
+
+    public void sendVoucherToPerson(String personUuid, Integer activityId) {
+   List<AssoActivityVoucher> assoActivityVouchers =  assoActivityVoucherService.getAssoActivityVoucher(activityId);
+ if(assoActivityVouchers.size()==0){
+     return;
+ }
+SendVoucherToPersonVO sendVoucherToPersonVO =this.loadSendVoucherToPersonVO(assoActivityVouchers,personUuid);
+
+        assoPersonVoucherService.sendVoucherToPerson(sendVoucherToPersonVO);
+    }
+
+    private SendVoucherToPersonVO loadSendVoucherToPersonVO(List<AssoActivityVoucher> assoActivityVoucher, String personUuid ) {
+        SendVoucherToPersonVO sendVoucherToPersonVO =new SendVoucherToPersonVO();
+        sendVoucherToPersonVO.setGetWay(0);
+        List<String> personIds =new ArrayList<>();
+        personIds.add(personUuid);
+        sendVoucherToPersonVO.setPersonUuids(personIds);
+        List<SendVoucherToPersonVO.InAddVoucherVO> inAddVoucherVOS =new ArrayList<>();
+        assoActivityVoucher.forEach(item->{
+            SendVoucherToPersonVO.InAddVoucherVO inAddVoucherVO =new SendVoucherToPersonVO.InAddVoucherVO();
+            inAddVoucherVO.setVoucherId(item.getVoucherId());
+            inAddVoucherVO.setNumber(item.getVoucherNum());
+            inAddVoucherVOS.add(inAddVoucherVO);
+        });
+        sendVoucherToPersonVO.setInAddVoucherVOS(inAddVoucherVOS);
+        return sendVoucherToPersonVO;
+    }
+
+    public void doingActivity(String personUuid,Integer useScope){
+    List<Activity> activities =    this.getActivities(useScope);
+        if(activities==null||activities.size()==0){
+            return;
+        }
+        Activity activity =activities.get(0);
+        Integer activityId =activity.getId();
+        this.sendVoucherToPerson(personUuid,activityId);
+    }
+}
+
+
+
+

+ 33 - 0
src/main/java/com/example/xiaoshiweixinback/service/AssoActivityVoucherService.java

@@ -0,0 +1,33 @@
+package com.example.xiaoshiweixinback.service;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+
+import com.example.xiaoshiweixinback.domain.AssoActivityVoucher;
+import com.example.xiaoshiweixinback.mapper.AssoActivityVoucherMapper;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author admin
+ * @description 针对表【asso_activity_voucher(活动和优惠券关联表)】的数据库操作Service实现
+ * @createDate 2024-07-03 16:21:37
+ */
+@Service
+public class AssoActivityVoucherService extends ServiceImpl<AssoActivityVoucherMapper, AssoActivityVoucher> {
+
+    public List<AssoActivityVoucher> getAssoActivityVoucher(Integer activityId) {
+        List<AssoActivityVoucher> assoActivityVouchers = new ArrayList<>();
+        LambdaQueryWrapper<AssoActivityVoucher> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(AssoActivityVoucher::getActivityId, activityId);
+        assoActivityVouchers = this.list(queryWrapper);
+        return assoActivityVouchers;
+
+    }
+}
+
+
+
+

+ 4 - 3
src/main/java/com/example/xiaoshiweixinback/service/AssoPersonVoucherService.java

@@ -45,7 +45,7 @@ public class AssoPersonVoucherService extends ServiceImpl<AssoPersonVoucherMappe
     public void sendVoucherToPerson(SendVoucherToPersonVO sendVoucherToPersonVO) {
         List<String> personUuids = sendVoucherToPersonVO.getPersonUuids();
         List<SendVoucherToPersonVO.InAddVoucherVO> inAddVoucherVOS = sendVoucherToPersonVO.getInAddVoucherVOS();
-
+        Integer getWay =sendVoucherToPersonVO.getGetWay();
         //校验
         if (sendVoucherToPersonVO == null || personUuids == null || personUuids.size() == 0 || sendVoucherToPersonVO.getInAddVoucherVOS() == null) {
             throw new BusinessException(ExceptionEnum.BUSINESS_ERROR, "请校验参数");
@@ -64,7 +64,7 @@ public class AssoPersonVoucherService extends ServiceImpl<AssoPersonVoucherMappe
             }
             for (int t = 0; t < num; t++) {
                 for (String personUuid : personUuids) {
-                    AssoPersonVoucher assoPersonVoucher = this.loadAssoPersonVoucher(voucher, personUuid);
+                    AssoPersonVoucher assoPersonVoucher = this.loadAssoPersonVoucher(voucher, personUuid,getWay);
                     assoPersonVouchers.add(assoPersonVoucher);
                 }
             }
@@ -73,7 +73,7 @@ public class AssoPersonVoucherService extends ServiceImpl<AssoPersonVoucherMappe
         this.getBaseMapper().insertBatchSomeColumn(assoPersonVouchers);
     }
 
-    private AssoPersonVoucher loadAssoPersonVoucher(Voucher voucher, String personUuid) {
+    private AssoPersonVoucher loadAssoPersonVoucher(Voucher voucher, String personUuid,Integer getWay) {
         Date date = new Date();
         AssoPersonVoucher assoPersonVoucher = new AssoPersonVoucher();
         assoPersonVoucher.setPersonUuid(personUuid);
@@ -85,6 +85,7 @@ public class AssoPersonVoucherService extends ServiceImpl<AssoPersonVoucherMappe
         assoPersonVoucher.setExpirationTime(voucher.getExpirationTime());
         assoPersonVoucher.setUseScope(voucher.getUseScope());
         assoPersonVoucher.setUseState(0);
+        assoPersonVoucher.setGetWay(getWay);
         assoPersonVoucher.setCreateTime(date);
         return assoPersonVoucher;
 

+ 0 - 20
src/main/java/com/example/xiaoshiweixinback/service/DiscountStrategyService.java

@@ -1,20 +0,0 @@
-package com.example.xiaoshiweixinback.service;
-
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.example.xiaoshiweixinback.domain.DiscountStrategy;
-import com.example.xiaoshiweixinback.mapper.DiscountStrategyMapper;
-import org.springframework.stereotype.Service;
-
-/**
-* @author admin
-* @description 针对表【discount_strategy(折扣策略)】的数据库操作Service实现
-* @createDate 2024-06-18 23:11:39
-*/
-@Service
-public class DiscountStrategyService extends ServiceImpl<DiscountStrategyMapper, DiscountStrategy> {
-
-}
-
-
-
-

+ 3 - 0
src/main/java/com/example/xiaoshiweixinback/service/InviteMessageService.java

@@ -31,6 +31,8 @@ public class InviteMessageService extends ServiceImpl<InviteMessageMapper, Invit
     private final PersonService personService;
     public  final CacheUtil cacheUtil;
     private final  AssoPersonVipService assoPersonVipService;
+    private final ActivityService activityService;
+    private final Integer ACTIVITY_SCOPE=-2;
     public void checkInvite(String inviteNode) {
         if(inviteNode==null){
             return;
@@ -76,6 +78,7 @@ public class InviteMessageService extends ServiceImpl<InviteMessageMapper, Invit
                 return 0;
             } else {
                 //TODO 给邀请人赠送优惠券
+                activityService.doingActivity(inviteMessage.getInvitedPersonUuid(),ACTIVITY_SCOPE);
                 inviteMessage.setIfBuyVip(true);
                 inviteMessage.updateById();
                 return 3;

+ 18 - 0
src/main/resources/mapper/ActivityMapper.xml

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.example.xiaoshiweixinback.mapper.ActivityMapper">
+    <select id="queryScopeActivity" resultType="com.example.xiaoshiweixinback.domain.Activity">
+    select
+    * from activity
+    <where>
+         (expiration_time &gt; now() or expiration_time is null)
+        <if test="useScope!=null">
+            and
+                find_in_set(#{useScope},use_scope)
+        </if>
+    </where>
+
+    </select>
+</mapper>

+ 17 - 0
src/main/resources/mapper/AssoVipFunctionMapper.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.example.xiaoshiweixinback.mapper.AssoVipFunctionMapper">
+
+    <select id="getAll" resultType="com.example.xiaoshiweixinback.entity.weixinPay.VipRightsVO">
+        select avf.function_uuid      as functionUuid,
+               v.vip_name                 as name,
+               avf.function_parameter as functionParameter,
+               v.vip_uuid        as vipUuid,
+               v.vip_type        as vipType
+        from asso_vip_function as avf
+                 left join vip as v on avf.vip_uuid = v.vip_uuid
+
+    </select>
+
+
+</mapper>