This commit is contained in:
zhaohengkun 2024-10-10 19:50:09 +08:00
commit 6b40385e39
8 changed files with 368 additions and 0 deletions

View File

@ -34,5 +34,7 @@ public interface ActiveRecommendRecordsService extends IService<ActiveRecommendR
* @return
*/
boolean add(ActiveRecommendRecordsDTO activeRecommendRecordsDTO) throws Exception;
void recommendMembersRechargePolite(Integer storeId,Integer inviteeUserId, String payType);
}

View File

@ -1,11 +1,18 @@
package com.fuint.business.marketingActivity.activeRecommend.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fuint.business.integral.entity.IntegralDetail;
import com.fuint.business.integral.mapper.IntegralDetailMapper;
import com.fuint.business.marketingActivity.activeApplet.entity.ActiveApplet;
import com.fuint.business.marketingActivity.activeApplet.mapper.ActiveAppletMapper;
import com.fuint.business.marketingActivity.activeConsumption.entity.ActiveConsumption;
import com.fuint.business.marketingActivity.activeRecommend.dto.ActiveRecommendRecordsDTO;
import com.fuint.business.marketingActivity.activeRecommend.entity.ActiveRecommend;
@ -16,11 +23,23 @@ import com.fuint.business.marketingActivity.activeRecommend.service.ActiveRecomm
import com.fuint.business.marketingActivity.activeRecommend.service.ActiveRecommendService;
import com.fuint.business.marketingActivity.activeRecommend.vo.ActiveRecommendRecordsVO;
import com.fuint.business.marketingActivity.activeRecommend.vo.ActiveRecommendVO;
import com.fuint.business.marketingActivity.activeUserRecharge.entity.ActiveUserRecharge;
import com.fuint.business.marketingActivity.activeUserRecharge.entity.ActiveUserRechargeChild;
import com.fuint.business.marketingActivity.activeUserRecharge.entity.ActiveUserRechargeRecords;
import com.fuint.business.marketingActivity.activeUserRecharge.mapper.ActiveUserRechargeChildMapper;
import com.fuint.business.marketingActivity.activeUserRecharge.mapper.ActiveUserRechargeMapper;
import com.fuint.business.marketingActivity.activeUserRecharge.mapper.ActiveUserRechargeRecordsMapper;
import com.fuint.business.marketingActivity.cardCoupon.entity.CardCoupon;
import com.fuint.business.marketingActivity.cardCoupon.entity.CardCouponUser;
import com.fuint.business.marketingActivity.cardCoupon.mapper.CardCouponMapper;
import com.fuint.business.marketingActivity.cardCoupon.mapper.CardCouponUserMapper;
import com.fuint.business.marketingActivity.cardExchange.entity.CardExchangeRecord;
import com.fuint.business.marketingActivity.cardExchange.service.CardExchangeRecordService;
import com.fuint.business.marketingActivity.cardFavorable.entity.CardFavorableRecord;
import com.fuint.business.marketingActivity.cardFavorable.service.CardFavorableRecordService;
import com.fuint.business.marketingActivity.cardFavorable.service.CardFavorableService;
import com.fuint.business.order.entity.GrowthValueChange;
import com.fuint.business.order.mapper.GrowthValueChangeMapper;
import com.fuint.business.storeInformation.service.ILJStoreService;
import com.fuint.business.userManager.entity.LJUser;
import com.fuint.business.userManager.entity.UserBalance;
@ -29,13 +48,18 @@ import com.fuint.business.userManager.service.LJUserService;
import com.fuint.business.userManager.service.UserBalanceService;
import com.fuint.common.dto.AccountInfo;
import com.fuint.common.util.TokenUtil;
import com.fuint.repository.mapper.MtUserGradeMapper;
import com.fuint.repository.model.MtUserGrade;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@ -63,6 +87,25 @@ public class ActiveRecommendRecordsServiceImpl extends ServiceImpl<ActiveRecomme
private CardExchangeRecordService cardExchangeRecordService;
@Resource
private ILJStoreService iljStoreService;
@Autowired
private ActiveUserRechargeMapper activeUserRechargeMapper;
@Autowired
private ActiveUserRechargeChildMapper activeUserRechargeChildMapper;
@Autowired
private ActiveUserRechargeRecordsMapper activeUserRechargeRecordsMapper;
@Autowired
private UserBalanceMapper userBalanceMapper;
@Autowired
private CardCouponUserMapper cardCouponUserMapper;
@Autowired
private CardCouponMapper cardCouponMapper;
@Autowired
private GrowthValueChangeMapper growthValueChangeMapper;
@Autowired
private MtUserGradeMapper mtUserGradeMapper;
@Autowired
private IntegralDetailMapper integralDetailMapper;
/**
* 小程序端查询邀请记录
* @param page
@ -251,5 +294,179 @@ public class ActiveRecommendRecordsServiceImpl extends ServiceImpl<ActiveRecomme
return false;
}
@Override
public void recommendMembersRechargePolite(Integer storeId, Integer inviteeUserId, String payType) {
//查询当前用户是否有推荐人
ActiveRecommendRecords activeRecommendRecords = baseMapper.selectOne(new LambdaQueryWrapper<ActiveRecommendRecords>()
.eq(ActiveRecommendRecords::getInviteeUserId, inviteeUserId)
.eq(ActiveRecommendRecords::getStoreId, storeId));
if (ObjectUtil.isNotEmpty(activeRecommendRecords)) {
//查询当前店铺的推荐有礼活动
ActiveUserRecharge activeUserRecharge = activeUserRechargeMapper.selectOne(new LambdaQueryWrapper<ActiveUserRecharge>()
.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<ActiveUserRechargeRecords>()
.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<UserBalance>()
.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<ActiveUserRechargeChild> activeUserRechargeChildren = activeUserRechargeChildMapper.selectList(new LambdaQueryWrapper<ActiveUserRechargeChild>()
.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<MtUserGrade> mtUserGrades = mtUserGradeMapper.selectList(new LambdaQueryWrapper<MtUserGrade>()
.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;
}
}

View File

@ -0,0 +1,20 @@
package com.fuint.business.marketingActivity.activeUserRecharge.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
/**
* <p>
* 推荐会员充值有礼记录表 前端控制器
* </p>
*
* @author dianliang
* @since 2024-10-10
*/
@Controller
@RequestMapping("/active-user-recharge-records")
public class ActiveUserRechargeRecordsController {
}

View File

@ -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;
/**
* <p>
* 推荐会员充值有礼记录表
* </p>
*
* @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;
}

View File

@ -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;
/**
* <p>
* 推荐会员充值有礼记录表 Mapper 接口
* </p>
*
* @author dianliang
* @since 2024-10-10
*/
public interface ActiveUserRechargeRecordsMapper extends BaseMapper<ActiveUserRechargeRecords> {
}

View File

@ -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;
/**
* <p>
* 推荐会员充值有礼记录表 服务类
* </p>
*
* @author dianliang
* @since 2024-10-10
*/
public interface IActiveUserRechargeRecordsService extends IService<ActiveUserRechargeRecords> {
}

View File

@ -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;
/**
* <p>
* 推荐会员充值有礼记录表 服务实现类
* </p>
*
* @author dianliang
* @since 2024-10-10
*/
@Service
public class ActiveUserRechargeRecordsServiceImpl extends ServiceImpl<ActiveUserRechargeRecordsMapper, ActiveUserRechargeRecords> implements IActiveUserRechargeRecordsService {
}

View File

@ -0,0 +1,5 @@
<?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.fuint.business.marketingActivity.activeUserRecharge.mapper.ActiveUserRechargeRecordsMapper">
</mapper>