This commit is contained in:
wyn
2026-04-27 17:53:41 +08:00
parent d8fbdcc67a
commit 9b8b818ad1
26 changed files with 600 additions and 32 deletions

View File

@@ -380,6 +380,7 @@ public class UserVipController {
MyUserEntity user = myUserDao.selectById(buyOrder.getUserId());
if (usePeanutCoin(user, totalPrice)&&useJfCoin(user,buyOrder.getJfDeduction())) {
// 更新订单状态
buyOrder.setPaymentDate(new Date());
buyOrderService.updateOrderStatus(user.getId(), buyOrder.getOrderSn(), "2");
//记录用户虚拟币消费
if(totalPrice.compareTo(BigDecimal.ZERO)>0){

View File

@@ -0,0 +1,10 @@
package com.peanut.modules.common.dao;
import com.github.yulichang.base.MPJBaseMapper;
import com.peanut.modules.common.entity.BuyOrderRefund;
import com.peanut.modules.common.entity.BuyOrderRefundLog;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface BuyOrderRefundLogDao extends MPJBaseMapper<BuyOrderRefundLog> {
}

View File

@@ -124,6 +124,7 @@ public class BuyOrder implements Serializable {
* 3已完成
* 4: 交易失败
* 5: 已过期
* 6: 已退款
*/
private String orderStatus;
/**
@@ -223,4 +224,9 @@ public class BuyOrder implements Serializable {
private BookEntity bookEntity;
@TableField(exist = false)
private String trainingClassIdentity;
@TableField(exist = false)
private Boolean refundableStatus;
@TableField(exist = false)
private String refundRemark;
}

View File

@@ -23,6 +23,9 @@ public class BuyOrderRefund implements Serializable {
private String orderSn;
private String payType;
private BigDecimal fee;
private BigDecimal jfDeduction;
private BigDecimal shippingMoney;
private int deductShipping;
//商品名称
private String title;
private String remark;

View File

@@ -0,0 +1,37 @@
package com.peanut.modules.common.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 订单退款进度日志表
*
* @author yl
* @email yl328572838@163.com
* @date 2022-08-29 15:27:44
*/
@Data
@TableName("buy_order_refund_log")
public class BuyOrderRefundLog implements Serializable {
private static final long serialVersionUID = 1L;
@TableId
private Integer id;
private Integer refundId;
private Date createTime;
private int type;
private int status;
@TableField(exist = false)
private String title;
@TableField(exist = false)
private String content;
}

View File

@@ -0,0 +1,9 @@
package com.peanut.modules.common.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.modules.common.entity.BuyOrderRefund;
import com.peanut.modules.common.entity.BuyOrderRefundLog;
public interface BuyOrderRefundLogService extends IService<BuyOrderRefundLog> {
void insertRefundLog(int buyOrderRefundId, int type, int status);
}

View File

@@ -1,7 +1,11 @@
package com.peanut.modules.common.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.modules.common.entity.BuyOrder;
import com.peanut.modules.common.entity.BuyOrderRefund;
import java.math.BigDecimal;
public interface BuyOrderRefundService extends IService<BuyOrderRefund> {
int insertBuyOrderRefund(BuyOrder buyOrder, BigDecimal refundFee, int deductShipping,String remark);
}

View File

@@ -28,6 +28,8 @@ public interface CouponService extends IService<CouponEntity> {
//回滚优惠卷
void rollbackCoupon(int couponHistoryId);
void refundZSCouponHistoryByOrder(BuyOrder order);
//通过商品发放优惠卷
void insertCouponHistoryByProductId(BuyOrder order);

View File

@@ -10,4 +10,7 @@ public interface JfTransactionDetailsService extends IService<JfTransactionDetai
void recordJfTransaction(BuyOrder buyOrder, MyUserEntity user, BigDecimal jf);
void refundJfTransaction(BuyOrder buyOrder, MyUserEntity user);
void recordZsJfTransaction(BuyOrder buyOrder, MyUserEntity user, BigDecimal refundJF);
}

View File

@@ -0,0 +1,22 @@
package com.peanut.modules.common.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.modules.common.dao.BuyOrderRefundLogDao;
import com.peanut.modules.common.entity.BuyOrderRefund;
import com.peanut.modules.common.entity.BuyOrderRefundLog;
import com.peanut.modules.common.service.BuyOrderRefundLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service("commonBuyOrderRefundLogService")
public class BuyOrderRefundLogServiceImpl extends ServiceImpl<BuyOrderRefundLogDao, BuyOrderRefundLog> implements BuyOrderRefundLogService {
@Override
public void insertRefundLog(int refundId, int type, int status){
BuyOrderRefundLog log = new BuyOrderRefundLog();
log.setRefundId(refundId);
log.setType(type);
log.setStatus(status);
this.save(log);
}
}

View File

@@ -2,12 +2,32 @@ package com.peanut.modules.common.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.modules.common.dao.BuyOrderRefundDao;
import com.peanut.modules.common.entity.BuyOrder;
import com.peanut.modules.common.entity.BuyOrderRefund;
import com.peanut.modules.common.service.BuyOrderRefundService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
@Slf4j
@Service("commonBuyOrderRefundService")
public class BuyOrderRefundServiceImpl extends ServiceImpl<BuyOrderRefundDao, BuyOrderRefund> implements BuyOrderRefundService {
@Override
public int insertBuyOrderRefund(BuyOrder buyOrder, BigDecimal refundFee, int deductShipping,String remark){
BuyOrderRefund buyOrderRefund = new BuyOrderRefund();
buyOrderRefund.setOrderId(buyOrder.getOrderId());
buyOrderRefund.setType("线上"); //id
buyOrderRefund.setUserId(buyOrder.getUserId());
buyOrderRefund.setOrderSn(buyOrder.getOrderSn());
buyOrderRefund.setPayType(buyOrder.getPaymentMethod());
buyOrderRefund.setFee(refundFee);
buyOrderRefund.setJfDeduction(buyOrder.getJfDeduction());
buyOrderRefund.setShippingMoney(deductShipping==1?buyOrder.getShippingMoney():BigDecimal.ZERO);
buyOrderRefund.setDeductShipping(deductShipping);
buyOrderRefund.setRemark(remark);
this.save(buyOrderRefund);
return buyOrderRefund.getId();
}
}

View File

@@ -16,6 +16,8 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.Instant;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@@ -73,7 +75,7 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
wrapper.eq(BuyOrder::getUserId,params.get("userId"));
wrapper.eq(BuyOrder::getCome,params.get("come"));
if(StringUtils.isEmpty(params.get("orderStatus").toString())){
Integer[] sts = {0,1,2,3};
Integer[] sts = {0,1,2,3,6};
wrapper.in(BuyOrder::getOrderStatus,sts);
}else{
wrapper.eq(BuyOrder::getOrderStatus,params.get("orderStatus").toString());
@@ -88,6 +90,7 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
}
//组装购买人
b.setUser(userDao.selectById(b.getUserId()));
boolean refundableStatus = false;
//组装充值配置详情
if (b.getProductId()!=null){
BookBuyConfigEntity bookBuyConfigEntity = bookBuyConfigDao.selectById(b.getProductId());
@@ -97,7 +100,12 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
}
b.setBookBuyConfigEntity(bookBuyConfigEntity);
}
long timestamp = Instant.now().toEpochMilli();
long paymentDateTime = b.getPaymentDate()==null?0: b.getPaymentDate().getTime();
if (b.getVipBuyConfigId()!=0){
if(paymentDateTime > timestamp-7*24*60*60*1000){
refundableStatus = true;
}
b.setVipBuyConfigEntity(vipBuyConfigDao.selectById(b.getVipBuyConfigId()));
}
if (b.getAiBuyConfigId()!=0){
@@ -107,10 +115,27 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
List<BuyOrderProduct> buyOrderProducts = buyOrderProductDao.selectList(
new LambdaQueryWrapper<BuyOrderProduct>().eq(BuyOrderProduct::getOrderId, b.getOrderId()));
if (buyOrderProducts.size() > 0) {
for (BuyOrderProduct bb : buyOrderProducts){
boolean[] refundableStatusArr = new boolean[buyOrderProducts.size()];
for (int i=0;i<buyOrderProducts.size();i++){
BuyOrderProduct bb = buyOrderProducts.get(i);
MPJLambdaWrapper<ShopProduct> w = new MPJLambdaWrapper<>();
w.disableLogicDel().eq(ShopProduct::getProductId,bb.getProductId());
bb.setProduct(shopProductDao.selectOne(w));
boolean refundableStatusProduct = false;
if(bb.getProduct().getGoodsType().equals("05") && (paymentDateTime > timestamp-7*24*60*60*1000)){
refundableStatusProduct = true;
}else if(!bb.getProduct().getGoodsType().equals("05") && b.getOrderStatus().equals("1")){
refundableStatusProduct = true;
}
refundableStatusArr[i] = refundableStatusProduct;
}
for (boolean rs : refundableStatusArr){
if(!rs){
refundableStatus = false;
break;
}else{
refundableStatus = true;
}
}
b.setProductList(buyOrderProducts);
b.setTimestamp(b.getCreateTime().getTime()/1000);
@@ -122,6 +147,7 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
b.setExpressList(expressOrders);
}
}
b.setRefundableStatus(b.getOrderStatus().equals("6")?false:refundableStatus);
}
}
return page;

View File

@@ -1,6 +1,7 @@
package com.peanut.modules.common.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.peanut.common.utils.DateUtils;
@@ -8,7 +9,9 @@ import com.peanut.common.utils.R;
import com.peanut.common.utils.ShiroUtils;
import com.peanut.modules.common.dao.*;
import com.peanut.modules.common.entity.*;
import com.peanut.modules.common.service.CouponHistoryService;
import com.peanut.modules.common.service.CouponService;
import com.peanut.modules.common.service.JfTransactionDetailsService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -41,6 +44,10 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
private ShopProductDao shopProductDao;
@Autowired
private JfTransactionDetailsDao jfTransactionDetailsDao;
@Autowired
private JfTransactionDetailsService jfTransactionDetailsService;
@Autowired
private CouponHistoryService couponHistoryService;
@Override
public CouponEntity getByIdSetRange(int id) {
@@ -252,6 +259,59 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
}
}
@Override
public void refundZSCouponHistoryByOrder(BuyOrder order){
MPJLambdaWrapper<CouponToProduct> wrapper = new MPJLambdaWrapper();
wrapper.leftJoin(BuyOrderProduct.class,BuyOrderProduct::getProductId,CouponToProduct::getProductId);
wrapper.leftJoin(CouponEntity.class,CouponEntity::getId,CouponToProduct::getCouponId);
wrapper.eq(CouponEntity::getCurrentState,0);
wrapper.eq(BuyOrderProduct::getOrderId,order.getOrderId());
wrapper.select(CouponToProduct::getCouponId);
wrapper.select(BuyOrderProduct::getProductId);
wrapper.select(BuyOrderProduct::getQuantity);
List<Map<String,Object>> buyOrderProducts = couponToProductDao.selectJoinMaps(wrapper);
MyUserEntity userEntity = userDao.selectById(order.getUserId());
List<UserVip> userVipList = userVipDao.selectList(new LambdaQueryWrapper<UserVip>()
.eq(UserVip::getUserId, userEntity.getId())
.eq(UserVip::getState,0)
.lt(UserVip::getStartTime,order.getPaymentDate()));
boolean isVip = false;
if (userVipList.size() > 0) {
isVip = true;
}
BigDecimal refundAllJF = BigDecimal.ZERO;
Boolean isRefundCoupon = false;
for (Map<String,Object> map : buyOrderProducts) {
ShopProduct shopProduct = shopProductDao.selectById(map.get("product_id").toString());
if ("03".equals(shopProduct.getGoodsType())){
int couponId = Integer.parseInt(map.get("coupon_id").toString());
CouponEntity couponEntity = couponDao.selectById(couponId);
//现金券
if (couponEntity.getCouponType()==0 && isVip){
BigDecimal quantity = new BigDecimal(map.get("quantity").toString());
refundAllJF.add(couponEntity.getCouponAmount().multiply(quantity));
}else{
isRefundCoupon = true;
}
}else{
isRefundCoupon = true;
}
}
if(refundAllJF.compareTo(BigDecimal.ZERO)>0 && userEntity.getJf().compareTo(refundAllJF)>=0){
BigDecimal userJF = userEntity.getJf().subtract(refundAllJF);
userEntity.setJf(userJF.compareTo(BigDecimal.ZERO)>=0?userJF:BigDecimal.ZERO);
userDao.updateById(userEntity);
jfTransactionDetailsService.recordZsJfTransaction(order,userEntity, refundAllJF);
}
if(isRefundCoupon){
QueryWrapper<CouponHistory> couponHistoryRemoveWrapper = new QueryWrapper<>();
couponHistoryRemoveWrapper.eq("order_id",order.getOrderId());
couponHistoryRemoveWrapper.eq("status",0);
couponHistoryService.remove(couponHistoryRemoveWrapper);
}
}
@Override
public void insertCouponHistoryByProductId(BuyOrder order) {
MPJLambdaWrapper<CouponToProduct> wrapper = new MPJLambdaWrapper();

View File

@@ -22,4 +22,26 @@ public class JfTransactionDetailsServiceImpl extends ServiceImpl<JfTransactionDe
jfTransactionDetails.setRemark("消费积分抵扣:"+jf.toString()+",订单号:"+buyOrder.getOrderSn());
getBaseMapper().insert(jfTransactionDetails);
}
@Override
public void refundJfTransaction(BuyOrder buyOrder, MyUserEntity user) {
JfTransactionDetails jfTransactionDetails = new JfTransactionDetails();
jfTransactionDetails.setUserId(user.getId());
jfTransactionDetails.setChangeAmount(buyOrder.getJfDeduction());
jfTransactionDetails.setActType(0);
jfTransactionDetails.setUserBalance(user.getJf().add(buyOrder.getJfDeduction()));
jfTransactionDetails.setRelationId(buyOrder.getOrderId());
jfTransactionDetails.setRemark("订单退款:"+buyOrder.getJfDeduction().toString()+",订单号:"+buyOrder.getOrderSn());
getBaseMapper().insert(jfTransactionDetails);
}
@Override
public void recordZsJfTransaction(BuyOrder buyOrder, MyUserEntity user, BigDecimal refundJF) {
JfTransactionDetails jfTransactionDetails = new JfTransactionDetails();
jfTransactionDetails.setUserId(buyOrder.getUserId());
jfTransactionDetails.setChangeAmount(refundJF);
jfTransactionDetails.setActType(1);
jfTransactionDetails.setUserBalance(user.getJf());
jfTransactionDetails.setRelationId(buyOrder.getOrderId());
jfTransactionDetails.setRemark("订单退款,赠送积分退回:"+refundJF.toString()+",订单号:"+buyOrder.getOrderSn());
getBaseMapper().insert(jfTransactionDetails);
}
}