This commit is contained in:
PQZ 2024-09-23 20:27:46 +08:00
parent 8af9224cbb
commit 32f4b4fa64
16 changed files with 234 additions and 77 deletions

View File

@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.custom.service.CustomerActiveService;
import cn.iocoder.yudao.module.custom.vo.CustomerActivePageReqVO;
import cn.iocoder.yudao.module.custom.vo.CustomerActiveRespVO;
import cn.iocoder.yudao.module.custom.vo.CustomerActiveSaveReqVO;
import cn.iocoder.yudao.module.member.vo.ActiveMainPageReqVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -18,6 +19,8 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - 用户参与活动记录")
@ -72,4 +75,19 @@ public class CustomerActiveController {
}
/**
*
* @author PQZ
* @date 16:12 2024/9/23
* @param pageReqVO ActiveMainPageReqVO实体
* @return cn.iocoder.yudao.framework.common.pojo.CommonResult<com.baomidou.mybatisplus.core.metadata.IPage<?>>
**/
@GetMapping("/list")
@Operation(summary = "可参与营销活动")
@PreAuthorize("@ss.hasPermission('member:active-main:query')")
public CommonResult<List<?>> getActiveMainPage(ActiveMainPageReqVO pageReqVO) {
return success(customerActiveService.isJoinActive(pageReqVO));
}
}

View File

@ -29,28 +29,31 @@ public class CustomerCouponController {
@Resource
private CustomerCouponService customerCouponService;
@PostMapping("/create")
@Operation(summary = "创建用户卡券")
/**
* 核销用户卡券
*
* @param saveReqVO CustomerCouponSaveReqVO实体
* @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.lang.Boolean>
* @author PQZ
* @date 15:58 2024/9/23
**/
@PostMapping("/couponVerification")
@Operation(summary = "核销用户卡券")
@PreAuthorize("@ss.hasPermission('base:customer-coupon:create')")
public CommonResult<String> createCustomerCoupon(@Valid @RequestBody CustomerCouponSaveReqVO createReqVO) {
return success(customerCouponService.createCustomerCoupon(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新用户卡券")
@PreAuthorize("@ss.hasPermission('base:customer-coupon:update')")
public CommonResult<Boolean> updateCustomerCoupon(@Valid @RequestBody CustomerCouponSaveReqVO updateReqVO) {
customerCouponService.updateCustomerCoupon(updateReqVO);
public CommonResult<Boolean> createCustomerCoupon(@Valid @RequestBody CustomerCouponSaveReqVO saveReqVO) {
customerCouponService.couponVerification(saveReqVO);
return success(true);
}
/**
* 删除用户卡券
*
* @param id 用户卡券id
* @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.lang.Boolean>
* @author PQZ
* @date 23:01 2024/9/20
* @param id TODO
* @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.lang.Boolean>
**/
**/
@DeleteMapping("/delete")
@Operation(summary = "删除用户卡券")
@Parameter(name = "id", description = "编号", required = true)
@ -62,11 +65,12 @@ public class CustomerCouponController {
/**
* 获取卡券信息及当前消费记录
* @author PQZ
* @date 22:56 2024/9/20
*
* @param id 用户卡券id
* @return cn.iocoder.yudao.framework.common.pojo.CommonResult<cn.iocoder.yudao.module.custom.vo.CustomerCouponRespVO>
**/
* @author PQZ
* @date 22:56 2024/9/20
**/
@GetMapping("/get")
@Operation(summary = "获得用户卡券")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@ -75,13 +79,5 @@ public class CustomerCouponController {
return success(customerCouponService.getCustomerCoupon(id));
}
@GetMapping("/page")
@Operation(summary = "获得用户卡券分页")
@PreAuthorize("@ss.hasPermission('base:customer-coupon:query')")
public CommonResult<PageResult<CustomerCouponRespVO>> getCustomerCouponPage(@Valid CustomerCouponPageReqVO pageReqVO) {
PageResult<CustomerCoupon> pageResult = customerCouponService.getCustomerCouponPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, CustomerCouponRespVO.class));
}
}

View File

@ -4,9 +4,12 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.custom.entity.CustomerActive;
import cn.iocoder.yudao.module.custom.vo.CustomerActivePageReqVO;
import cn.iocoder.yudao.module.custom.vo.CustomerActiveSaveReqVO;
import cn.iocoder.yudao.module.member.vo.ActiveMainPageReqVO;
import cn.iocoder.yudao.module.member.vo.ActiveMainRespVO;
import com.baomidou.mybatisplus.extension.service.IService;
import javax.validation.Valid;
import java.util.List;
/**
* 用户参与活动记录 Service 接口
@ -42,6 +45,8 @@ public interface CustomerActiveService extends IService<CustomerActive> {
*/
CustomerActive getCustomerActive(String id);
/**
* 获得用户参与活动记录分页
*
@ -50,4 +55,14 @@ public interface CustomerActiveService extends IService<CustomerActive> {
*/
PageResult<CustomerActive> getCustomerActivePage(CustomerActivePageReqVO pageReqVO);
/**
* 可参与营销活动
* @author PQZ
* @date 16:18 2024/9/23
* @param pageReqVO ActiveMainPageReqVO 实体
* @return java.util.List<cn.iocoder.yudao.module.member.vo.ActiveMainRespVO>
**/
List<ActiveMainRespVO> isJoinActive(ActiveMainPageReqVO pageReqVO);
}

View File

@ -17,20 +17,15 @@ import java.util.List;
*/
public interface CustomerCouponService extends IService<CustomerCoupon> {
/**
* 创建用户卡券
*
* @param createReqVO 创建信息
* @return 编号
*/
String createCustomerCoupon(@Valid CustomerCouponSaveReqVO createReqVO);
/**
* 更新用户卡券
*
* @param updateReqVO 更新信息
*/
void updateCustomerCoupon(@Valid CustomerCouponSaveReqVO updateReqVO);
* 卡券核销
* @author PQZ
* @date 15:37 2024/9/23
* @param saveReqVO CustomerCouponSaveReqVO实体
**/
void couponVerification(CustomerCouponSaveReqVO saveReqVO);
/**
* 删除用户卡券
@ -49,13 +44,7 @@ public interface CustomerCouponService extends IService<CustomerCoupon> {
CustomerCouponRespVO getCustomerCoupon(String id);
/**
* 获得用户卡券分页
*
* @param pageReqVO 分页查询
* @return 用户卡券分页
*/
PageResult<CustomerCoupon> getCustomerCouponPage(CustomerCouponPageReqVO pageReqVO);
/**
* 根据用户id获取卡券信息

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.custom.service.impl;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.module.custom.entity.*;
import cn.iocoder.yudao.module.custom.mapper.CustomerActiveMapper;
import cn.iocoder.yudao.module.custom.service.*;
@ -13,7 +14,9 @@ import cn.iocoder.yudao.module.member.entity.ActiveRule;
import cn.iocoder.yudao.module.member.entity.MemberCoupon;
import cn.iocoder.yudao.module.member.service.ActiveMainService;
import cn.iocoder.yudao.module.member.service.MemberCouponService;
import cn.iocoder.yudao.module.member.vo.ActiveMainPageReqVO;
import cn.iocoder.yudao.module.member.vo.ActiveMainRespVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mzt.logapi.service.IFunctionService;
import org.springframework.stereotype.Service;
@ -57,7 +60,6 @@ public class CustomerActiveServiceImpl extends ServiceImpl<CustomerActiveMapper,
private CustomerBalanceService balanceService;
/**
* 参与活动
*
@ -117,7 +119,7 @@ public class CustomerActiveServiceImpl extends ServiceImpl<CustomerActiveMapper,
}
List<ActiveRule> ruleList = active.getRuleList();
//转换余额信息
balance = transBalance(customer,saveReqVO.getTopUpAmount(),ruleList);
balance = transBalance(customer, saveReqVO.getTopUpAmount(), ruleList);
//记录日志
CustomerBalanceChange change = changeService.initChange(customer.getId(),
customer.getUserId(), null, BALANCE_CHANGE_TYPE_CZ, BALANCE_CHANGE_MAIN_YE,
@ -207,17 +209,20 @@ public class CustomerActiveServiceImpl extends ServiceImpl<CustomerActiveMapper,
result.setCusId(customer.getId());
result.setUserId(customer.getUserId());
List<ActiveRule> sortList = ruleList.stream().sorted(Comparator.comparing(ActiveRule::getRechAmount).reversed()).collect(Collectors.toList());
BigDecimal nowChange = amount;
for (ActiveRule item : sortList) {
//如果规则匹配
if (amount.compareTo(item.getRechAmount()) >= 0) {
BigDecimal nowChange = amount.add(item.getGiveAmount());
//余额
result.setBalance(customer.getBalance().add(nowChange));
//累计充值金额
result.setAllBalance(customer.getBalance().add(nowChange));
result.setNowChange(nowChange);
nowChange = amount.add(item.getGiveAmount());
break;
}
}
//余额
result.setBalance(customer.getBalance().add(nowChange));
//累计充值金额
result.setAllBalance(customer.getBalance().add(nowChange));
//本次变动金额
result.setNowChange(nowChange);
return result;
}
@ -239,4 +244,29 @@ public class CustomerActiveServiceImpl extends ServiceImpl<CustomerActiveMapper,
return null;
}
/**
* 可参与营销活动
*
* @param pageReqVO ActiveMainPageReqVO 实体
* @return java.util.List<cn.iocoder.yudao.module.member.vo.ActiveMainRespVO>
* @author PQZ
* @date 16:18 2024/9/23
**/
@Override
public List<ActiveMainRespVO> isJoinActive(ActiveMainPageReqVO pageReqVO) {
LambdaQueryWrapper<CustomerActive> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(BaseDO::getDeleted, 0).eq(CustomerActive::getCusId, pageReqVO.getCusId());
List<CustomerActive> myList = list(lambdaQueryWrapper);
//活动id集合
List<String> activeIds = myList.stream().map(CustomerActive::getActiveId).distinct().collect(Collectors.toList());
List<ActiveMainRespVO> list = activeMainService.listActive(pageReqVO);
//排除已参与的
list.forEach(item -> {
if (activeIds.contains(item.getId())) {
item.setIsJoin(GENERAL_YES);
}
});
return list;
}
}

View File

@ -12,11 +12,15 @@ import cn.iocoder.yudao.module.custom.vo.CustomerCouponRespVO;
import cn.iocoder.yudao.module.custom.vo.CustomerCouponSaveReqVO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import static cn.iocoder.yudao.common.BaseConstants.*;
/**
* 用户卡券 Service 实现类
*
@ -31,20 +35,37 @@ public class CustomerCouponServiceImpl extends ServiceImpl<CustomerCouponMapper,
@Resource
private CustomerBalanceChangeService changeService;
@Override
public String createCustomerCoupon(CustomerCouponSaveReqVO createReqVO) {
// 插入
CustomerCoupon customerCoupon = BeanUtils.toBean(createReqVO, CustomerCoupon.class);
customerCouponMapper.insert(customerCoupon);
// 返回
return customerCoupon.getId();
}
/**
* 卡券核销
*
* @param saveReqVO CustomerCouponSaveReqVO实体
* @author PQZ
* @date 15:37 2024/9/23
**/
@Override
public void updateCustomerCoupon(CustomerCouponSaveReqVO updateReqVO) {
// 更新
CustomerCoupon updateObj = BeanUtils.toBean(updateReqVO, CustomerCoupon.class);
customerCouponMapper.updateById(updateObj);
@Transactional(rollbackFor = Exception.class)
public void couponVerification(CustomerCouponSaveReqVO saveReqVO) {
CustomerCoupon customerCoupon = getById(saveReqVO.getId());
//核销后剩余
BigDecimal newBalance = customerCoupon.getBalance().subtract(saveReqVO.getChangeBalance());
customerCoupon.setBalance(newBalance);
if (newBalance.compareTo(BigDecimal.ZERO) == 0) {
customerCoupon.setIsValid(GENERAL_NO);
}
//保存核销后的卡券
saveOrUpdate(customerCoupon);
//保存核销记录
changeService.saveChange(saveReqVO.getCusId(),
saveReqVO.getUserId(),
saveReqVO.getCouponId(),
BALANCE_CHANGE_TYPE_KQHX,
BALANCE_CHANGE_MAIN_KQ,
saveReqVO.getOutRule(),
saveReqVO.getChangeBalance(),
newBalance,
"核销" + saveReqVO.getCouponName() + saveReqVO.getChangeBalance() + "次/元,核销后剩余" + newBalance + "次/元"
);
}
@Override
@ -56,25 +77,21 @@ public class CustomerCouponServiceImpl extends ServiceImpl<CustomerCouponMapper,
/**
* 获取用户卡券信息及卡券变动信息
* @author PQZ
* @date 22:51 2024/9/20
*
* @param id 用户卡券id
* @return cn.iocoder.yudao.module.custom.vo.CustomerCouponRespVO
* @author PQZ
* @date 22:51 2024/9/20
**/
@Override
public CustomerCouponRespVO getCustomerCoupon(String id) {
CustomerCoupon coupon = getById(id);
CustomerCouponRespVO result = BeanUtils.toBean(coupon,CustomerCouponRespVO.class);
List<CustomerBalanceChange> changeList = changeService.getCouponChange(coupon.getCusId(),coupon.getCouponId());
CustomerCouponRespVO result = BeanUtils.toBean(coupon, CustomerCouponRespVO.class);
List<CustomerBalanceChange> changeList = changeService.getCouponChange(coupon.getCusId(), coupon.getCouponId());
result.setChangeList(changeList);
return result;
}
@Override
public PageResult<CustomerCoupon> getCustomerCouponPage(CustomerCouponPageReqVO pageReqVO) {
return null;
}
/**
* 根据用户id获取卡券信息
*

View File

@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.custom.vo;
import cn.iocoder.yudao.module.custom.entity.CustomerCoupon;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.time.LocalDateTime;
import java.util.*;
import javax.validation.constraints.*;
import java.math.BigDecimal;
@ -10,6 +12,35 @@ import java.math.BigDecimal;
@Schema(description = "管理后台 - 用户卡券新增/修改 Request VO")
@Data
public class CustomerCouponSaveReqVO extends CustomerCoupon {
/**本次核销次数*/
private BigDecimal changeBalance;
/**
* 卡券名称
*/
private String couponName;
/**
* 卡券类型保养卡服务券礼包券
*/
private String couponType;
/**
* 适用车型数据字典
*/
private String carModel;
/**
* 开始有效期
*/
private LocalDateTime beginTime;
/**
* 结束有效期
*/
private LocalDateTime endTime;
/**
* 效果图片
*/
private String image;
/**
* 来源活动名称
*/
private String activeName;
}

View File

@ -19,6 +19,8 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - 营销活动")
@ -114,5 +116,4 @@ public class ActiveMainController {
return success(activeMainService.queryListPage(pageReqVO, page));
}
}

View File

@ -11,6 +11,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 营销活动 Mapper
*
@ -29,4 +31,14 @@ public interface ActiveMainMapper extends BaseMapper<ActiveMain> {
* @date 14:10 2024/9/19
**/
IPage<ActiveMainRespVO> selectListPage(@Param("entity") ActiveMainPageReqVO entity, Page<ActiveMainRespVO> page);
/**
* 不分页查询可参与的活动规则
*
* @param entity ActiveMainPageReqVO实体
* @return java.util.List<cn.iocoder.yudao.module.member.vo.ActiveMainRespVO>
* @author PQZ
* @date 16:10 2024/9/23
**/
List<ActiveMainRespVO> listActiveMain(@Param("entity") ActiveMainPageReqVO entity);
}

View File

@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import javax.validation.Valid;
import java.util.List;
/**
* 营销活动 Service 接口
@ -55,4 +56,15 @@ public interface ActiveMainService extends IService<ActiveMain> {
**/
IPage<ActiveMainRespVO> queryListPage(ActiveMainPageReqVO pageReqVO, Page<ActiveMainRespVO> page);
/**
* 不分页查询可参与的活动规则
*
* @param pageReqVO ActiveMainPageReqVO实体
* @return java.util.List<cn.iocoder.yudao.module.member.vo.ActiveMainRespVO>
* @author PQZ
* @date 16:11 2024/9/23
**/
List<ActiveMainRespVO> listActive(ActiveMainPageReqVO pageReqVO);
}

View File

@ -21,7 +21,7 @@ public interface MemberCouponService extends IService<MemberCoupon> {
/**
* 保存基础卡券信息
*
* @param saveReqVO TODO
* @param saveReqVO MemberCouponSaveReqVO实体
* @return void
* @author PQZ
* @date 14:22 2024/9/19

View File

@ -39,6 +39,7 @@ public class ActiveMainServiceImpl extends ServiceImpl<ActiveMainMapper, ActiveM
private ActiveRuleCouponService activeRuleCouponService;
/**
* 保存营销活动
*
@ -108,5 +109,18 @@ public class ActiveMainServiceImpl extends ServiceImpl<ActiveMainMapper, ActiveM
return activeMainMapper.selectListPage(pageReqVO, page);
}
/**
* 不分页查询可参与的活动规则
*
* @param pageReqVO ActiveMainPageReqVO实体
* @return java.util.List<cn.iocoder.yudao.module.member.vo.ActiveMainRespVO>
* @author PQZ
* @date 16:11 2024/9/23
**/
@Override
public List<ActiveMainRespVO> listActive(ActiveMainPageReqVO pageReqVO) {
return activeMainMapper.listActiveMain(pageReqVO);
}
}

View File

@ -17,4 +17,6 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
public class ActiveMainPageReqVO extends ActiveMain {
/**用于判断是否查询当前时间段可参与的活动*/
private String isNow;
/**当前客户id*/
private String cusId;
}

View File

@ -18,5 +18,7 @@ public class ActiveMainRespVO extends ActiveMain {
private List<MemberCoupon> couponList;
/**活动关联规则*/
private List<ActiveRule> ruleList;
/**当前活动当前用户是否已参与*/
private String isJoin;
}

View File

@ -29,4 +29,23 @@
</where>
ORDER BY dam.create_time DESC
</select>
<select id="listActiveMain" resultType="cn.iocoder.yudao.module.member.vo.ActiveMainRespVO">
SELECT
*
FROM
dl_active_main dam
<where>
dam.deleted = 0
<if test="entity.isNow != null and entity.isNow == 1">
AND begin_time &lt;= NOW()
AND end_time &gt;= NOW()
</if>
<if test="entity.name != null and entity.name != ''">
and dam.name like concat('%', #{entity.name}, '%')
</if>
<if test="entity.type != null and entity.type != ''">
and dam.type like concat('%', #{entity.type}, '%')
</if>
</where>
</select>
</mapper>

View File

@ -40,7 +40,6 @@ public class RepairOrderInfoServiceImpl extends ServiceImpl<RepairOrderInfoMappe
public void saveOrderInfo(RepairOrderInfoSaveReqVO saveReqVO) {
RepairOrderInfo save = BeanUtils.toBean(saveReqVO, RepairOrderInfo.class);
saveOrUpdate(save);
}
@Override