diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activeRecommend/service/ActiveRecommendRecordsService.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activeRecommend/service/ActiveRecommendRecordsService.java index c4963d539..86e6b1c91 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activeRecommend/service/ActiveRecommendRecordsService.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activeRecommend/service/ActiveRecommendRecordsService.java @@ -34,5 +34,7 @@ public interface ActiveRecommendRecordsService extends IService() + .eq(ActiveRecommendRecords::getInviteeUserId, inviteeUserId) + .eq(ActiveRecommendRecords::getStoreId, storeId)); + if (ObjectUtil.isNotEmpty(activeRecommendRecords)) { + //查询当前店铺的推荐有礼活动 + ActiveUserRecharge activeUserRecharge = activeUserRechargeMapper.selectOne(new LambdaQueryWrapper() + .eq(ActiveUserRecharge::getStoreId, storeId)); + if (ObjectUtil.isNotEmpty(activeUserRecharge)) { + //判断是否在线 + if (!"0".equals(activeUserRecharge.getIsonline())) { + return; + } + //判断当前优惠是否可以使用 + if (!"0".equals(activeUserRecharge.getActiveTimeType())) { + DateTime now = DateUtil.date(); + Date activeStartTime = activeUserRecharge.getActiveStartTime(); + Date activeEndTime = activeUserRecharge.getActiveEndTime(); + //判断当前时间是否在活动的时间之内 + boolean timeBetween = isTimeBetween(activeStartTime, activeEndTime, now); + if (!timeBetween) { + return; + } + } + //判断获取次数是否超过限制 + if (!"0".equals(activeUserRecharge.getFrequencyLimit())) { + //查询推荐人的领取次数 + Integer count = activeUserRechargeRecordsMapper.selectCount(new LambdaQueryWrapper() + .eq(ActiveUserRechargeRecords::getUserId, activeRecommendRecords.getUserId())); + if (count >= activeUserRecharge.getFrequencyLimit()) { + return; + } + } + //判断支付方式是否一致 + String[] split = activeUserRecharge.getPaymentType().split(","); + if (!Arrays.asList(split).contains(payType)) { + return; + } + //判断被邀请人会员等级是否符合要求 + UserBalance userBalance = userBalanceMapper.selectOne(new LambdaQueryWrapper() + .eq(UserBalance::getMtUserId, activeRecommendRecords.getInviteeUserId())); + String[] gradeIds = activeUserRecharge.getUserGradeIds().split(","); + if (!Arrays.asList(gradeIds).contains(userBalance.getGradeId().toString())) { + return; + } + + //获取可以领取的奖励 + String courtesyReward = activeUserRecharge.getCourtesyReward(); + String[] courtesyRewards = courtesyReward.split(","); + for (String reward : courtesyRewards) { + if ("0".equals(reward)) { + //优惠券 + List activeUserRechargeChildren = activeUserRechargeChildMapper.selectList(new LambdaQueryWrapper() + .eq(ActiveUserRechargeChild::getActiveUserRechargeId, activeUserRecharge.getId())); + for (ActiveUserRechargeChild activeUserRechargeChild : activeUserRechargeChildren) { + //优惠券数量 + Integer giftCardTotal = activeUserRechargeChild.getGiftCardTotal(); + //优惠券id + Integer vouchersId = activeUserRechargeChild.getVouchersId(); + //查询优惠券详细信息 + CardCoupon cardCoupon = cardCouponMapper.selectById(vouchersId); + Integer validityDay = 0; + Date effectiveDateStart = new Date(); + Date effectiveDateEnd = new Date(); + if (cardCoupon.getTimeType().equals("1")) { + validityDay = cardCoupon.getValidityDay(); + DateTime now = DateUtil.date(); + effectiveDateStart = now; + effectiveDateEnd = DateUtil.offsetDay(now, validityDay); + }else { + effectiveDateStart = cardCoupon.getEffectiveDateStart(); + effectiveDateEnd = cardCoupon.getEffectiveDateEnd(); + } + + //判断优惠券剩余数量是否足够 如果不够剩多少领多少 + if ((cardCoupon.getTfTotal() - cardCoupon.getGiftCardTotal()) < giftCardTotal) { + giftCardTotal = cardCoupon.getTfTotal() - cardCoupon.getGiftCardTotal(); + } + + //将优惠券添加到用户优惠券表 + for (Integer i = 0; i < giftCardTotal; i++) { + CardCouponUser cardCouponUser = new CardCouponUser(); + cardCouponUser.setChainStoreId(activeUserRecharge.getChainStoreId()); + cardCouponUser.setStoreId(activeUserRecharge.getStoreId()); + cardCouponUser.setMtUserId(Integer.parseInt(activeRecommendRecords.getUserId())); + cardCouponUser.setFromType("5"); + cardCouponUser.setActiveId(activeUserRecharge.getId()); + cardCouponUser.setCardCouponId(vouchersId); + cardCouponUser.setStartTime(effectiveDateStart); + cardCouponUser.setEndTime(effectiveDateEnd); + cardCouponUser.setStatus("0"); + cardCouponUser.setCreateTime(new Date()); + cardCouponUser.setCreateBy(TokenUtil.getNowAccountInfo().getId().toString()); + cardCouponUserMapper.insert(cardCouponUser); + } + } + }else if ("2".equals(reward)) { + //成长值 + Integer growthValue = activeUserRecharge.getGrowthValue(); + + //将成长值添加到用户余额表 + userBalance.setGrowthValue(userBalance.getGrowthValue() + growthValue); + + //添加到成长值变化表 + GrowthValueChange growthValueChange = new GrowthValueChange(); + growthValueChange.setUserId(Integer.parseInt(activeRecommendRecords.getUserId())); + growthValueChange.setChangeType("1"); + growthValueChange.setFromType("5"); + growthValueChange.setGrowthValue(growthValue); + growthValueChange.setAfterTheChange(userBalance.getGrowthValue()); + growthValueChange.setChainStoreId(activeRecommendRecords.getChainStoreId()); + growthValueChange.setStoreId(activeUserRecharge.getStoreId()); + growthValueChange.setCreateTime(new Date()); + growthValueChange.setCreateBy(TokenUtil.getNowAccountInfo().getId().toString()); + + growthValueChangeMapper.insert(growthValueChange); + + //判断用户等级是否有变化 + List mtUserGrades = mtUserGradeMapper.selectList(new LambdaQueryWrapper() + .eq(MtUserGrade::getStoreId, storeId)); + if (CollUtil.isNotEmpty(mtUserGrades)) { + //判断当前用户等级 + for (int i = 0; i < mtUserGrades.size(); i++) { + if (i < mtUserGrades.size() - 2) { + if (userBalance.getGrowthValue() >= mtUserGrades.get(i).getGrowthValue() && userBalance.getGrowthValue() < mtUserGrades.get(i + 1).getGrowthValue()){ + userBalance.setGradeId(mtUserGrades.get(i).getId()); + break; + } + }else { + userBalance.setGradeId(mtUserGrades.get(mtUserGrades.size() - 1).getId()); + } + } + } + userBalance.setUpdateTime(DateUtil.date()); + userBalance.setUpdateBy(TokenUtil.getNowAccountInfo().getId().toString()); + //更新用户信息 + userBalanceMapper.updateById(userBalance); + }else if ("3".equals(reward)) { + //积分 + Integer points = activeUserRecharge.getPoints(); + + //将积分添加到用户余额表 + userBalance.setPoints(userBalance.getPoints() + points); + userBalanceMapper.updateById(userBalance); + + //新增积分变更记录表 + IntegralDetail integralDetail = new IntegralDetail(); + integralDetail.setUserId(Integer.parseInt(activeRecommendRecords.getUserId())); + integralDetail.setPointsChange(Double.valueOf(activeUserRecharge.getPoints())); + integralDetail.setCurrentPoints(userBalance.getPoints()); + integralDetail.setChangeType("1"); + integralDetail.setChangeReason("推荐会员充值有礼赠送"); + integralDetail.setType("推荐会员充值有礼赠送"); + integralDetail.setCreateTime(new Date()); + integralDetail.setCreateBy(TokenUtil.getNowAccountInfo().getId().toString()); + integralDetail.setStoreId(activeUserRecharge.getStoreId()); + integralDetail.setChainStoreId(activeUserRecharge.getChainStoreId()); + integralDetailMapper.insert(integralDetail); + } + } + + } + } + } + + private boolean isTimeBetween(Date activeStartTime, Date activeEndTime, DateTime now) { + if (now.isAfterOrEquals(activeStartTime) && now.isBeforeOrEquals(activeEndTime)) { + return true; + } + return false; + } } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activeUserRecharge/controller/ActiveUserRechargeRecordsController.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activeUserRecharge/controller/ActiveUserRechargeRecordsController.java new file mode 100644 index 000000000..974b58763 --- /dev/null +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activeUserRecharge/controller/ActiveUserRechargeRecordsController.java @@ -0,0 +1,20 @@ +package com.fuint.business.marketingActivity.activeUserRecharge.controller; + + +import org.springframework.web.bind.annotation.RequestMapping; + +import org.springframework.stereotype.Controller; + +/** + *

+ * 推荐会员充值有礼记录表 前端控制器 + *

+ * + * @author dianliang + * @since 2024-10-10 + */ +@Controller +@RequestMapping("/active-user-recharge-records") +public class ActiveUserRechargeRecordsController { + +} diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activeUserRecharge/entity/ActiveUserRechargeRecords.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activeUserRecharge/entity/ActiveUserRechargeRecords.java new file mode 100644 index 000000000..6c604c0f1 --- /dev/null +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activeUserRecharge/entity/ActiveUserRechargeRecords.java @@ -0,0 +1,72 @@ +package com.fuint.business.marketingActivity.activeUserRecharge.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import java.time.LocalDateTime; +import java.io.Serializable; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +/** + *

+ * 推荐会员充值有礼记录表 + *

+ * + * @author dianliang + * @since 2024-10-10 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@TableName("active_user_recharge_records") +@ApiModel(value="ActiveUserRechargeRecords对象", description="推荐会员充值有礼记录表") +public class ActiveUserRechargeRecords implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "id") + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + @ApiModelProperty(value = "活动id") + private Integer activeUserRechargeId; + + @ApiModelProperty(value = "所属连锁店ID") + private Integer chainStoreId; + + @ApiModelProperty(value = "所属店铺ID") + private Integer storeId; + + @ApiModelProperty(value = "邀请人id") + private Integer userId; + + @ApiModelProperty(value = "被邀请人ID") + private Integer inviteeUserId; + + @ApiModelProperty(value = "被邀请人姓名") + private String inviteeUserName; + + @ApiModelProperty(value = "备注") + private String remark; + + @ApiModelProperty(value = "来源") + private String type; + + @ApiModelProperty(value = "创建者") + private String createBy; + + @ApiModelProperty(value = "创建时间") + private LocalDateTime createTime; + + @ApiModelProperty(value = "更新者") + private String updateBy; + + @ApiModelProperty(value = "更新时间") + private LocalDateTime updateTime; + + +} diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activeUserRecharge/mapper/ActiveUserRechargeRecordsMapper.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activeUserRecharge/mapper/ActiveUserRechargeRecordsMapper.java new file mode 100644 index 000000000..823f31913 --- /dev/null +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activeUserRecharge/mapper/ActiveUserRechargeRecordsMapper.java @@ -0,0 +1,16 @@ +package com.fuint.business.marketingActivity.activeUserRecharge.mapper; + +import com.fuint.business.marketingActivity.activeUserRecharge.entity.ActiveUserRechargeRecords; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * 推荐会员充值有礼记录表 Mapper 接口 + *

+ * + * @author dianliang + * @since 2024-10-10 + */ +public interface ActiveUserRechargeRecordsMapper extends BaseMapper { + +} diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activeUserRecharge/service/IActiveUserRechargeRecordsService.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activeUserRecharge/service/IActiveUserRechargeRecordsService.java new file mode 100644 index 000000000..fa314d8d6 --- /dev/null +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activeUserRecharge/service/IActiveUserRechargeRecordsService.java @@ -0,0 +1,16 @@ +package com.fuint.business.marketingActivity.activeUserRecharge.service; + +import com.fuint.business.marketingActivity.activeUserRecharge.entity.ActiveUserRechargeRecords; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 推荐会员充值有礼记录表 服务类 + *

+ * + * @author dianliang + * @since 2024-10-10 + */ +public interface IActiveUserRechargeRecordsService extends IService { + +} diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activeUserRecharge/service/impl/ActiveUserRechargeRecordsServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activeUserRecharge/service/impl/ActiveUserRechargeRecordsServiceImpl.java new file mode 100644 index 000000000..2c82e21dc --- /dev/null +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activeUserRecharge/service/impl/ActiveUserRechargeRecordsServiceImpl.java @@ -0,0 +1,20 @@ +package com.fuint.business.marketingActivity.activeUserRecharge.service.impl; + +import com.fuint.business.marketingActivity.activeUserRecharge.entity.ActiveUserRechargeRecords; +import com.fuint.business.marketingActivity.activeUserRecharge.mapper.ActiveUserRechargeRecordsMapper; +import com.fuint.business.marketingActivity.activeUserRecharge.service.IActiveUserRechargeRecordsService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 推荐会员充值有礼记录表 服务实现类 + *

+ * + * @author dianliang + * @since 2024-10-10 + */ +@Service +public class ActiveUserRechargeRecordsServiceImpl extends ServiceImpl implements IActiveUserRechargeRecordsService { + +} diff --git a/fuintBackend/fuint-application/src/main/resources/mapper/ActiveUserRechargeRecordsMapper.xml b/fuintBackend/fuint-application/src/main/resources/mapper/ActiveUserRechargeRecordsMapper.xml new file mode 100644 index 000000000..246d1cbf3 --- /dev/null +++ b/fuintBackend/fuint-application/src/main/resources/mapper/ActiveUserRechargeRecordsMapper.xml @@ -0,0 +1,5 @@ + + + + +