优惠卷

复读
This commit is contained in:
wuchunlei
2024-10-25 10:43:11 +08:00
parent 54901e7133
commit cce2106e04
17 changed files with 602 additions and 100 deletions

View File

@@ -4,18 +4,18 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.peanut.common.utils.R;
import com.peanut.modules.book.service.BuyOrderProductService;
import com.peanut.modules.book.service.ShopProductService;
import com.peanut.modules.common.entity.*;
import com.peanut.modules.common.service.BuyOrderService;
import com.peanut.modules.common.service.CouponHistoryService;
import com.peanut.modules.common.service.CouponService;
import com.peanut.modules.common.service.CouponToProductService;
import com.peanut.modules.master.service.CourseService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -29,6 +29,12 @@ public class CouponController {
private CouponService couponService;
@Autowired
private CouponHistoryService couponHistoryService;
@Autowired
private CourseService courseService;
@Autowired
private CouponToProductService couponToProductService;
@Autowired
private ShopProductService shopProductService;
//优惠卷列表
@RequestMapping("/getCouponList")
@@ -104,17 +110,26 @@ public class CouponController {
return R.ok().put("couponEntity",couponEntity);
}
//修改优惠劵状态
@RequestMapping("/updateCouponState")
public R updateCouponState(@RequestBody Map<String,Object> params){
CouponEntity coupon = couponService.getById(params.get("id").toString());
coupon.setCurrentState((int)params.get("currentState"));
couponService.updateById(coupon);
return R.ok();
}
//修改优惠劵
@RequestMapping("/updateCoupon")
public R updateCoupon(@RequestBody CouponEntity couponEntity){
int count = couponHistoryService.count(new LambdaQueryWrapper<CouponHistory>()
.eq(CouponHistory::getCouponId,couponEntity.getId()));
if (count>0){
return R.error("已有用户拥有优惠");
return R.error("已有用户拥有优惠");
}
CouponEntity c = couponService.getById(couponEntity.getId());
if (c.getCurrentState()==0){
return R.error("优惠发放中,请先结束再修改");
return R.error("优惠发放中,请先结束再修改");
}
couponService.updateById(couponEntity);
return R.ok();
@@ -127,11 +142,11 @@ public class CouponController {
int count = couponHistoryService.count(new LambdaQueryWrapper<CouponHistory>()
.eq(CouponHistory::getCouponId,couponId));
if (count>0){
return R.error("已有用户拥有优惠");
return R.error("已有用户拥有优惠");
}
CouponEntity c = couponService.getById(couponId);
if (c.getCurrentState()==0){
return R.error("优惠发放中,请先结束再删除");
return R.error("优惠发放中,请先结束再删除");
}
couponService.removeById(couponId);
return R.ok();
@@ -161,11 +176,17 @@ public class CouponController {
return R.ok();
}
//当前优惠卷可用商品
@RequestMapping("/getShopProductByCoupon")
public R getShopProductByCoupon(@RequestBody Map<String,Object> params){
Set<Integer> l = couponService.getShopProductByCoupon(Integer.parseInt(params.get("couponId").toString()));
return R.ok().put("productIds",l);
//优惠卷可绑定课程
@RequestMapping("/getCourseList")
public R getCourseList(@RequestBody Map<String,Object> params){
Integer limit = Integer.valueOf(params.get("limit").toString());
Integer page = Integer.valueOf(params.get("page").toString());
LambdaQueryWrapper<CourseEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.select(CourseEntity::getId,CourseEntity::getTitle);
wrapper.like(CourseEntity::getTitle,params.get("title"));
wrapper.orderByDesc(CourseEntity::getId);
Page<CourseEntity> courses = courseService.page(new Page<>(page, limit), wrapper);
return R.ok().put("courses",courses);
}
//付款时优惠卷列表
@@ -175,4 +196,42 @@ public class CouponController {
return R.ok().put("couponHistoryList",couponHistoryList);
}
//购买商品绑定优惠卷列表
@RequestMapping("/couponToProductList")
public R couponToShopproductList(@RequestBody Map<String,Object> params){
Integer limit = Integer.valueOf(params.get("limit").toString());
Integer page = Integer.valueOf(params.get("page").toString());
LambdaQueryWrapper<CouponToProduct> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(CouponToProduct::getProductId,params.get("productId"));
wrapper.orderByDesc(CouponToProduct::getId);
Page<CouponToProduct> couponToShopproductPage = couponToProductService.page(new Page<>(page, limit), wrapper);
for (CouponToProduct couponToProduct : couponToShopproductPage.getRecords()) {
couponToProduct.setCouponEntity(couponService.getById(couponToProduct.getCouponId()));
couponToProduct.setShopProduct(shopProductService.getById(couponToProduct.getShopProduct()));
}
return R.ok().put("couponToShopproductPage",couponToShopproductPage);
}
//商品绑定优惠卷
@RequestMapping("/setCouponToProduct")
public R setCouponToProduct(@RequestBody CouponToProduct couponToProduct){
CouponToProduct c = couponToProductService.getOne(new LambdaQueryWrapper<CouponToProduct>()
.eq(CouponToProduct::getCouponId, couponToProduct.getCouponId())
.eq(CouponToProduct::getProductId, couponToProduct.getProductId()));
if (c == null){
couponToProductService.save(couponToProduct);
return R.ok();
}else {
return R.error("已存在");
}
}
//解绑商品优惠卷
@RequestMapping("/unbindCouponToProduct")
public R unbindCouponToProduct(@RequestBody Map<String,Object> params){
couponToProductService.removeById(params.get("id").toString());
return R.ok();
}
}

View File

@@ -0,0 +1,222 @@
package com.peanut.modules.common.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.peanut.common.utils.R;
import com.peanut.common.utils.ShiroUtils;
import com.peanut.config.Constants;
import com.peanut.config.DelayQueueConfig;
import com.peanut.modules.book.service.TransactionDetailsService;
import com.peanut.modules.common.entity.*;
import com.peanut.modules.common.service.BuyOrderService;
import com.peanut.modules.common.service.MyUserService;
import com.peanut.modules.master.service.ShopProductService;
import com.peanut.modules.master.service.UserCourseBuyService;
import com.peanut.modules.pay.weChatPay.dto.WechatPaymentInfo;
import com.peanut.modules.pay.weChatPay.service.WxpayService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Slf4j
@RestController("commonCourseRelearn")
@RequestMapping("common/courseRelearn")
public class CourseRelearnController {
@Autowired
private UserCourseBuyService userCourseBuyService;
@Autowired
private ShopProductService shopProductService;
@Autowired
private BuyOrderService buyOrderService;
@Autowired
private MyUserService userService;
@Autowired
private WxpayService wxpayService;
@Autowired
private TransactionDetailsService transactionDetailsService;
@Autowired
private RabbitTemplate rabbitTemplate;
//复读订单列表
@RequestMapping("/orderListRelearn")
public R orderListRelearn(@RequestBody Map<String,Object> params) {
MPJLambdaWrapper<BuyOrder> wrapper = new MPJLambdaWrapper<>();
wrapper.selectAll(BuyOrder.class);
wrapper.leftJoin(MyUserEntity.class, MyUserEntity::getId,BuyOrder::getUserId);
wrapper.eq(BuyOrder::getOrderType,"relearn");
if (StringUtils.isNotEmpty(params.get("orderSn").toString())) {
wrapper.eq(BuyOrder::getOrderSn,params.get("orderSn"));
}
if (StringUtils.isNotEmpty(params.get("userInfo").toString())) {
wrapper.and(t->t.like(MyUserEntity::getName,params.get("userInfo")).or().like(MyUserEntity::getNickname,params.get("userInfo"))
.or().like(MyUserEntity::getTel,params.get("userInfo")).or().like(MyUserEntity::getEmail,params.get("userInfo")));
}
wrapper.orderByDesc(BuyOrder::getOrderId);
Page<BuyOrder> buyOrderPage = buyOrderService.page(new Page<BuyOrder>(
Long.parseLong(params.get("page").toString()), Long.parseLong(params.get("limit").toString())), wrapper);
for (BuyOrder buyOrder : buyOrderPage.getRecords()){
buyOrder.setUser(userService.getById(buyOrder.getUserId()));
}
return R.ok().put("buyOrderPage",buyOrderPage);
}
//课程目录是否可复读(已购买并过期)
@RequestMapping("/courseCatalogueCanRelearn")
public R courseCatalogueCanRelearn(@RequestBody Map<String,Object> params){
boolean flag = false;
List<UserCourseBuyEntity> list = userCourseBuyService.list(new MPJLambdaWrapper<UserCourseBuyEntity>()
.disableLogicDel()//查询出已删除数据
.eq(UserCourseBuyEntity::getUserId, ShiroUtils.getUId())
.eq(UserCourseBuyEntity::getCatalogueId,params.get("courseCatalogueId")));
if (list.size() > 0) {
flag = true;
for (UserCourseBuyEntity userCourseBuyEntity : list) {
if (userCourseBuyEntity.getDelFlag()==0) {
flag = false;
}
}
}
return R.ok().put("canRelearn",flag);
}
//课程目录复读列表
@RequestMapping("/relearnShopProductList")
public R relearnShopProductList(@RequestBody Map<String,Object> params) {
MPJLambdaWrapper<ShopProduct> wrapper = new MPJLambdaWrapper<>();
wrapper.leftJoin(ShopProductCourseEntity.class,ShopProductCourseEntity::getProductId,ShopProduct::getProductId);
wrapper.selectAll(ShopProduct.class);
wrapper.eq(ShopProductCourseEntity::getCatalogueId,params.get("catalogueId"));
wrapper.eq(ShopProductCourseEntity::getDays,365);
ShopProduct shopProduct = shopProductService.getOne(wrapper);
if (shopProduct == null) {
return R.error("未找到一年期商品");
}else {
ShopProduct sp1 = new ShopProduct();
sp1.setProductId(shopProduct.getProductId());
sp1.setProductName(shopProduct.getProductName().replace("一年","一月"));
sp1.setProductImages(shopProduct.getProductImages());
BigDecimal sp1Price = shopProduct.getPrice().divide(new BigDecimal(12),0, RoundingMode.DOWN);
sp1.setPrice(sp1Price);
ShopProduct sp2 = new ShopProduct();
sp2.setProductId(shopProduct.getProductId());
sp2.setProductName(shopProduct.getProductName().replace("一年","三月"));
sp2.setProductImages(shopProduct.getProductImages());
BigDecimal sp2Price = shopProduct.getPrice().divide(new BigDecimal(4),0, RoundingMode.DOWN);
sp2Price = sp2Price.multiply(new BigDecimal(0.6));
sp2Price = sp2Price.setScale(0, RoundingMode.DOWN);
sp2.setPrice(sp2Price);
List<ShopProduct> res = new ArrayList<>();
res.add(sp1);
res.add(sp2);
return R.ok().put("productList",res);
}
}
@RequestMapping("/relearnSave")
@Transactional
public R relearnSave(@RequestBody BuyOrder buyOrder){
int uid = ShiroUtils.getUId();
buyOrder.setOrderStatus("0");
buyOrder.setOrderType("relearn");
String timeId = IdWorker.getTimeId().substring(0, 32);
buyOrder.setOrderSn(timeId);
buyOrder.setUserId(uid);
buyOrderService.save(buyOrder);
BigDecimal totalPrice = buyOrder.getRealMoney();
//虚拟币支付
if (Constants.PAYMENT_METHOD_VIRTUAL.equals(buyOrder.getPaymentMethod())) {
buyOrder.setOrderStatus(Constants.ORDER_STATUS_TO_BE_SHIPPED);
MyUserEntity user = userService.getById(buyOrder.getUserId());
if (usePeanutCoin(user, totalPrice)) {
buyOrder.setSuccessTime(new Date());
// 更新订单状态
buyOrderService.updateOrderStatus(user.getId(), buyOrder.getOrderSn(), "2");
//记录用户虚拟币消费
if(totalPrice.compareTo(BigDecimal.ZERO)>0){
recordTransaction(buyOrder, user, totalPrice);
}
//插入复读记录
userCourseBuyService.addUserCourseBuyRelearn(buyOrder,"虚拟币购买:"+buyOrder.getOrderSn());
} else {
return R.error(500, "余额不足!");
}
}
//微信支付预付款订单
if(Constants.PAYMENT_METHOD_WECHAT_PAY.equals(buyOrder.getPaymentMethod())){
BuyOrder buyOrderEntity = buyOrderService.getBaseMapper().selectOne(new LambdaQueryWrapper<BuyOrder>()
.eq(BuyOrder::getOrderSn, timeId));
WechatPaymentInfo paymentInfo = new WechatPaymentInfo();
paymentInfo.setOrderSn(buyOrderEntity.getOrderSn());
paymentInfo.setBuyOrderId(buyOrder.getOrderId());
paymentInfo.setTotalAmount(buyOrderEntity.getRealMoney());
if (buyOrder.getCome()==2){
paymentInfo.setAppName("wumen");
} else if (buyOrder.getCome()==1) {
paymentInfo.setAppName("zmzm");
}else {
paymentInfo.setAppName(buyOrder.getAppName());
}
wxpayService.prepay(paymentInfo);
}
rabbitTemplate.convertAndSend(
DelayQueueConfig.ORDER_TO_BE_PAY_EXCHANGE,
DelayQueueConfig.ORDER_TO_BE_PAY_ROUTING_KEY,
buyOrder.getOrderId(),
messagePostProcessor()
);
return R.ok().put("orderSn", timeId).put("money", totalPrice);
}
private boolean usePeanutCoin(MyUserEntity user, BigDecimal totalPrice) {
if (user.getPeanutCoin().compareTo(totalPrice) >= 0) {
if(totalPrice.compareTo(BigDecimal.ZERO)==0){//纯积分支付,虚拟币不用支付
return true;
}
user.setPeanutCoin(user.getPeanutCoin().subtract(totalPrice));
userService.updateById(user);
return true;
}
return false;
}
private void recordTransaction(BuyOrder buyOrder, MyUserEntity user, BigDecimal totalPrice) {
TransactionDetailsEntity transactionDetailsEntity = new TransactionDetailsEntity();
transactionDetailsEntity.setRemark("订单编号为 - " + buyOrder.getOrderSn());
transactionDetailsEntity.setUserId(user.getId());
transactionDetailsEntity.setUserName(user.getNickname());
transactionDetailsEntity.setChangeAmount(totalPrice.negate());
transactionDetailsEntity.setUserBalance(user.getPeanutCoin());
transactionDetailsEntity.setTel(user.getTel());
transactionDetailsEntity.setOrderType("购买商品");
transactionDetailsService.save(transactionDetailsEntity);
}
private MessagePostProcessor messagePostProcessor() {
return message -> {
//设置有效期30分钟
message.getMessageProperties().setExpiration(String.valueOf(30 * 60 * 1000));
return message;
};
}
}

View File

@@ -0,0 +1,9 @@
package com.peanut.modules.common.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.peanut.modules.common.entity.CouponToProduct;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface CouponToProductDao extends BaseMapper<CouponToProduct> {
}

View File

@@ -49,6 +49,10 @@ public class CouponHistory {
@TableLogic
private Integer delFlag;
@TableField(exist = false)
private int canUse;
@TableField(exist = false)
private String canUseReason;
@TableField(exist = false)
private CouponEntity couponEntity;
@TableField(exist = false)

View File

@@ -0,0 +1,29 @@
package com.peanut.modules.common.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@Data
@TableName("coupon_to_product")
public class CouponToProduct {
@TableId
private Integer id;
private Integer couponId;
private Integer productId;
@TableLogic
private Integer delFlag;
@TableField(exist = false)
private CouponEntity couponEntity;
@TableField(exist = false)
private ShopProduct shopProduct;
}

View File

@@ -4,12 +4,13 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.common.utils.R;
import com.peanut.modules.common.entity.CouponEntity;
import com.peanut.modules.common.entity.CouponHistory;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Set;
public interface CouponService extends IService<CouponEntity> {
CouponEntity getByIdSetRange(int id);
@@ -20,6 +21,13 @@ public interface CouponService extends IService<CouponEntity> {
List<CouponHistory> getCouponListPayment(Map<String,Object> params);
Set<Integer> getShopProductByCoupon(int couponId);
//使用优惠卷
void useCouponAmount(CouponHistory couponHistory);
//回滚优惠卷
void rollbackCoupon(int couponHistoryId);
//通过商品发放优惠卷
void insertCouponHistoryByProductId(List<Integer> productIds);
}

View File

@@ -0,0 +1,7 @@
package com.peanut.modules.common.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.modules.common.entity.CouponToProduct;
public interface CouponToProductService extends IService<CouponToProduct> {
}

View File

@@ -3,7 +3,6 @@ package com.peanut.modules.common.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.peanut.common.utils.DateUtil;
import com.peanut.common.utils.DateUtils;
import com.peanut.common.utils.R;
import com.peanut.common.utils.ShiroUtils;
@@ -11,14 +10,13 @@ import com.peanut.config.DelayQueueConfig;
import com.peanut.modules.common.dao.*;
import com.peanut.modules.common.entity.*;
import com.peanut.modules.common.service.CouponService;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.*;
@Slf4j
@@ -36,9 +34,11 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
@Autowired
private RabbitTemplate rabbitTemplate;
@Autowired
private ShopProductDao shopProductDao;
@Autowired
private ShopProductCourseDao shopProductCourseDao;
@Autowired
private CouponToProductDao couponToProductDao;
@Autowired
private ShopProductDao shopProductDao;
@Override
public CouponEntity getByIdSetRange(int id) {
@@ -95,19 +95,21 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
couponHistory.setEndTime(couponEntity.getExpireTime());
}
couponHistoryDao.insert(couponHistory);
//发放完优惠卷设置过期
rabbitTemplate.convertAndSend(
DelayQueueConfig.COMMON_EXCHANGE,
DelayQueueConfig.COMMON_ROUTING_KEY,
"couponExpire"+","+couponHistory.getId(),
messagePostProcessor(couponHistory.getEndTime().getTime()-new Date().getTime())
);
if (couponEntity.getEffectType()!=0){
//发放完优惠卷设置过期
rabbitTemplate.convertAndSend(
DelayQueueConfig.COMMON_EXCHANGE,
DelayQueueConfig.COMMON_ROUTING_KEY,
"couponExpire"+","+couponHistory.getId(),
messagePostProcessor(couponHistory.getEndTime().getTime()-new Date().getTime())
);
}
return R.ok();
}else {
return R.error("每人限领"+couponEntity.getLimitedCollar()+"");
}
}else {
return R.error("优惠已放完");
return R.error("优惠已放完");
}
}
private MessagePostProcessor messagePostProcessor(long date) {
@@ -125,16 +127,33 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
.eq(CouponHistory::getStatus,0));
if (couponHistoryList.size() > 0) {
for (CouponHistory couponHistory : couponHistoryList) {
if (couponHistory.getEffectType()==0){
res.add(couponHistory);
}else {
List<ShopProduct> shopProductList = shopProductDao.selectList(new MPJLambdaWrapper<ShopProduct>()
.leftJoin(BuyOrderProduct.class,BuyOrderProduct::getProductId,ShopProduct::getProductId)
.eq(BuyOrderProduct::getOrderId,params.get("orderId").toString()));
for (ShopProduct shopProduct : shopProductList) {
Set<Integer> set = getShopProductByCoupon(couponHistory.getCouponId());
if(!set.add(shopProduct.getProductId())){
res.add(couponHistory);
CouponEntity couponEntity = this.baseMapper.selectById(couponHistory.getCouponId());
if (couponEntity != null) {
//校验优惠卷使用时间
couponHistory.setCanUse(1);
couponHistory.setCanUseReason("");
if (couponHistory.getEffectType()!=0){
if (couponHistory.getStartTime().getTime() < new Date().getTime() &&
couponHistory.getEndTime().getTime() > new Date().getTime()) {
}else {
couponHistory.setCanUse(0);
couponHistory.setCanUseReason("优惠券使用时间未到");
}
}
couponHistory.setCouponEntity(couponEntity);
if (couponEntity.getCouponRange()==0){
//无限制
res.add(couponHistory);
}else {
String shopProductIds = params.get("shopProductIds").toString();
String[] ids = shopProductIds.split(",");
for (String shopProductId : ids) {
//通过优惠卷获取商品
Set<Integer> set = getShopProductByCoupon(couponEntity);
//比对用户优惠卷是否有此商品
if(!set.add(Integer.parseInt(shopProductId))){
res.add(couponHistory);
}
}
}
}
@@ -143,32 +162,30 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
return res;
}
@Override
public Set<Integer> getShopProductByCoupon(int couponId) {
public Set<Integer> getShopProductByCoupon(CouponEntity couponEntity) {
Set<Integer> set = new HashSet<>();
CouponEntity couponEntity = couponDao.selectById(couponId);
if (couponEntity!=null){
String[] strs = couponEntity.getRangeInfo().split(",");
if (couponEntity.getCouponRange()==1) {
for (String courseId : strs) {
List<ShopProductCourseEntity> shopProductCourseList = shopProductCourseDao.selectList(new LambdaQueryWrapper<ShopProductCourseEntity>()
.eq(ShopProductCourseEntity::getCourseId,courseId));
for (ShopProductCourseEntity shopProductCourseEntity : shopProductCourseList) {
set.add(shopProductCourseEntity.getProductId());
}
String[] strs = couponEntity.getRangeInfo().split(",");
if (couponEntity.getCouponRange()==1) {
//1课程卷
for (String courseId : strs) {
List<ShopProductCourseEntity> shopProductCourseList = shopProductCourseDao.selectList(new LambdaQueryWrapper<ShopProductCourseEntity>()
.eq(ShopProductCourseEntity::getCourseId,courseId));
for (ShopProductCourseEntity shopProductCourseEntity : shopProductCourseList) {
set.add(shopProductCourseEntity.getProductId());
}
}else if (couponEntity.getCouponRange()==2) {
for (String courseMedical : strs) {
MPJLambdaWrapper<ShopProductCourseEntity> wrapper = new MPJLambdaWrapper<>();
wrapper.leftJoin(CourseToMedicine.class,CourseToMedicine::getCourseId,ShopProductCourseEntity::getCourseId);
List l = new ArrayList();
getCourseMedicalIds(Integer.parseInt(courseMedical),l);
wrapper.in(CourseToMedicine::getMedicalId,l);
wrapper.selectAll(ShopProductCourseEntity.class);
List<ShopProductCourseEntity> shopProductCourseList = shopProductCourseDao.selectList(wrapper);
for (ShopProductCourseEntity shopProductCourseEntity : shopProductCourseList) {
set.add(shopProductCourseEntity.getProductId());
}
}
}else if (couponEntity.getCouponRange()==2) {
//2课程品类卷
for (String courseMedical : strs) {
MPJLambdaWrapper<ShopProductCourseEntity> wrapper = new MPJLambdaWrapper<>();
wrapper.leftJoin(CourseToMedicine.class,CourseToMedicine::getCourseId,ShopProductCourseEntity::getCourseId);
List l = new ArrayList();
getCourseMedicalIds(Integer.parseInt(courseMedical),l);
wrapper.in(CourseToMedicine::getMedicalId,l);
wrapper.selectAll(ShopProductCourseEntity.class);
List<ShopProductCourseEntity> shopProductCourseList = shopProductCourseDao.selectList(wrapper);
for (ShopProductCourseEntity shopProductCourseEntity : shopProductCourseList) {
set.add(shopProductCourseEntity.getProductId());
}
}
}
@@ -188,5 +205,36 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
}
}
@Override
public void useCouponAmount(CouponHistory couponHistory) {
couponHistory.setStatus(1);//使用状态 0 未使用 1 已使用 2 已过期
couponHistory.setUseTime(new Date());
couponHistoryDao.updateById(couponHistory);
}
@Override
public void rollbackCoupon(int couponHistoryId) {
CouponHistory couponHistory = couponHistoryDao.selectById(couponHistoryId);
if (couponHistory != null) {
couponHistory.setOrderId(0);
couponHistory.setStatus(0);
couponHistory.setUseTime(null);
couponHistoryDao.updateById(couponHistory);
}
}
@Override
public void insertCouponHistoryByProductId(List<Integer> productIds) {
List<CouponToProduct> couponToProductList = couponToProductDao.selectList(new LambdaQueryWrapper<CouponToProduct>()
.in(CouponToProduct::getProductId,productIds));
for (CouponToProduct couponToProduct : couponToProductList) {
ShopProduct shopProduct = shopProductDao.selectById(couponToProduct.getProductId());
insertCouponHistory(couponToProduct.getCouponId(),
ShiroUtils.getUId(), 1,"购买商品"+shopProduct.getProductName()+"赠送");
}
}
}

View File

@@ -0,0 +1,13 @@
package com.peanut.modules.common.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.modules.common.dao.CouponToProductDao;
import com.peanut.modules.common.entity.CouponToProduct;
import com.peanut.modules.common.service.CouponToProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service("commonCouponToProductService")
public class CouponToProductServiceImpl extends ServiceImpl<CouponToProductDao, CouponToProduct> implements CouponToProductService {
}