退单
This commit is contained in:
@@ -661,6 +661,12 @@ public class BuyOrderController {
|
||||
|| Constants.ORDER_STATUS_OUT_OF_TIME.equals(buyOrder.getOrderStatus())) {
|
||||
return R.error("当前订单状态不支持退单");
|
||||
}
|
||||
// QueryWrapper<BuyOrderRefund> refundQueryWrapper = new QueryWrapper<>();
|
||||
// refundQueryWrapper.eq("order_id",buyOrder.getOrderId());
|
||||
// long refundOrderNums = buyOrderRefundService.count(refundQueryWrapper);
|
||||
if(buyOrder.getOrderStatus().equals(Constants.ORDER_STATUS_REFUND)){
|
||||
return R.error("请勿重复申请退款");
|
||||
}
|
||||
buyOrder.setOrderStatus(Constants.ORDER_STATUS_REFUND);
|
||||
buyOrderService.updateById(buyOrder);
|
||||
|
||||
@@ -672,7 +678,23 @@ public class BuyOrderController {
|
||||
refundFee = refundFee.compareTo(BigDecimal.ZERO)>0?refundFee:BigDecimal.ZERO;
|
||||
}
|
||||
String remark = params.containsKey("remark") && params.get("remark").toString()!=null?params.get("remark").toString():"";
|
||||
int refundId = buyOrderRefundService.insertBuyOrderRefund(buyOrder,refundFee,deductShipping,remark);
|
||||
|
||||
String refundNo = buyOrderRefundService.genRefundNo();
|
||||
BuyOrderRefund buyOrderRefund = new BuyOrderRefund();
|
||||
buyOrderRefund.setRefundNo(refundNo);
|
||||
buyOrderRefund.setOrderId(buyOrder.getOrderId());
|
||||
buyOrderRefund.setOrderSn(buyOrder.getOrderSn());
|
||||
buyOrderRefund.setUserId(buyOrder.getUserId());
|
||||
buyOrderRefund.setType("线上"); //id
|
||||
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);
|
||||
buyOrderRefundService.save(buyOrderRefund);
|
||||
|
||||
int refundId = buyOrderRefund.getId();
|
||||
|
||||
if (Constants.PAYMENT_METHOD_VIRTUAL.equals(buyOrder.getPaymentMethod())) {
|
||||
//BigDecimal refundPeanutCoin = buyOrder.getRealMoney() == null?BigDecimal.ZERO : buyOrder.getRealMoney();
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.peanut.modules.book.service.CountyService;
|
||||
import com.peanut.modules.book.service.ExpressOrderService;
|
||||
import com.peanut.modules.book.service.MyUserService;
|
||||
import com.peanut.modules.book.service.ProvinceService;
|
||||
import com.peanut.modules.book.vo.UserVipYearVo;
|
||||
import com.peanut.modules.common.dao.*;
|
||||
import com.peanut.modules.book.service.*;
|
||||
import com.peanut.modules.book.to.UserOrderDto;
|
||||
@@ -28,7 +29,9 @@ import com.peanut.modules.common.entity.*;
|
||||
import com.peanut.modules.common.service.*;
|
||||
import com.peanut.modules.common.vo.CourseCatalogueVo;
|
||||
import com.peanut.modules.oss.service.OssService;
|
||||
import com.qiniu.util.Json;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.time.DateUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -110,6 +113,12 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
|
||||
private BuyOrderRefundLogService buyOrderRefundLogService;
|
||||
@Autowired
|
||||
private BuyOrderRefundService buyOrderRefundService;
|
||||
@Autowired
|
||||
private UserVipLogService userVipLogService;
|
||||
@Autowired
|
||||
private UserVipLogDao userVipLogDao;
|
||||
@Autowired
|
||||
private UserVipDao userVipDao;
|
||||
|
||||
// TODO 新版本上线后删除
|
||||
@Override
|
||||
@@ -726,17 +735,12 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
|
||||
return shopProductCourseEntities;
|
||||
}
|
||||
public void removeCourseToUser(BuyOrder orderEntity){
|
||||
List<ShopProductCourseEntity> orderCourse = getOrderCourse(orderEntity.getOrderSn());
|
||||
for (int i=0;i<orderCourse.size();i++){
|
||||
ShopProductCourseEntity s = orderCourse.get(i);
|
||||
LambdaQueryWrapper<UserCourseBuyLog> wrapper2 = new LambdaQueryWrapper<>();
|
||||
wrapper2.eq(UserCourseBuyLog::getOrderSn,orderEntity.getOrderSn());
|
||||
List<UserCourseBuyLog> buyCourseLogList = userCourseBuyLogDao.selectList(wrapper2);
|
||||
for (UserCourseBuyLog courseLog : buyCourseLogList){
|
||||
userCourseBuyDao.deleteById(courseLog.getUserCourseBuyId());
|
||||
userCourseBuyLogDao.deleteById(courseLog.getId());
|
||||
}
|
||||
|
||||
QueryWrapper<UserCourseBuyLog> buyLogQueryWrapper = new QueryWrapper<>();
|
||||
buyLogQueryWrapper.eq("order_sn",orderEntity.getOrderSn());
|
||||
List<UserCourseBuyLog> userCourseBuyLogList = userCourseBuyLogDao.selectList(buyLogQueryWrapper);
|
||||
for (UserCourseBuyLog userCourseBuyLog:userCourseBuyLogList){
|
||||
userCourseBuyDao.deleteById(userCourseBuyLog.getUserCourseBuyId());
|
||||
userCourseBuyLogDao.deleteById(userCourseBuyLog.getId());
|
||||
}
|
||||
}
|
||||
@Override
|
||||
@@ -1074,15 +1078,21 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
|
||||
myUserService.updateById(user);
|
||||
buyOrderRefundLogService.insertRefundLog(refundId,2,1);
|
||||
}
|
||||
//撤回本订单购买赠送的优惠券
|
||||
couponService.refundZSCouponHistoryByOrder(buyOrder);
|
||||
// 恢复用户权益(点穴/时辰取穴/五运六气/肿瘤古方)
|
||||
// myUserService.rollbackUserPowers(buyOrder, orderProducts);
|
||||
//撤回电子书权限
|
||||
userEbookBuyService.rollbackUserEbooks(buyOrder, orderProducts);
|
||||
//撤回课程权限
|
||||
removeCourseToUser(buyOrder);
|
||||
//回滚库存
|
||||
shopProductService.rollbackStock(buyOrder);
|
||||
if(buyOrder.getOrderType().equals("vip")){
|
||||
userVipService.refundVip(buyOrder);
|
||||
}else{
|
||||
//撤回本订单购买赠送的优惠券
|
||||
couponService.refundZSCouponHistoryByOrder(buyOrder);
|
||||
/*//恢复用户权益(点穴/时辰取穴/五运六气/肿瘤古方)
|
||||
myUserService.rollbackUserPowers(buyOrder, orderProducts);*/
|
||||
//撤回电子书权限
|
||||
userEbookBuyService.rollbackUserEbooks(buyOrder, orderProducts);
|
||||
//撤回课程权限
|
||||
removeCourseToUser(buyOrder);
|
||||
//回滚库存
|
||||
shopProductService.rollbackStock(buyOrder);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
46
src/main/java/com/peanut/modules/book/vo/UserVipYearVo.java
Normal file
46
src/main/java/com/peanut/modules/book/vo/UserVipYearVo.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package com.peanut.modules.book.vo;
|
||||
|
||||
import com.spire.ms.System.DateTime;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
public class UserVipYearVo implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Integer id;
|
||||
private Integer year;
|
||||
private Date endTime;
|
||||
private Date startTime;
|
||||
|
||||
public Integer getYear() {
|
||||
return year;
|
||||
}
|
||||
|
||||
public void setYear(Integer year) {
|
||||
this.year = year;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Date getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public void setEndTime(Date endTime) {
|
||||
this.endTime = endTime;
|
||||
}
|
||||
|
||||
public Date getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public void setStartTime(Date startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.peanut.modules.common.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.peanut.modules.common.entity.UserVipLog;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
@@ -9,7 +10,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
public interface UserVipLogDao extends BaseMapper<UserVipLog> {
|
||||
public interface UserVipLogDao extends MPJBaseMapper<UserVipLog> {
|
||||
|
||||
List<Map<String,Object>> getUserVipLogInfo(@Param("date") String date);
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ public class BuyOrderRefund implements Serializable {
|
||||
|
||||
@TableId
|
||||
private Integer id;
|
||||
private String refundNo;
|
||||
private Integer userId;
|
||||
//订单类型 线上 线下
|
||||
private String type;
|
||||
|
||||
@@ -8,4 +8,5 @@ import java.math.BigDecimal;
|
||||
|
||||
public interface BuyOrderRefundService extends IService<BuyOrderRefund> {
|
||||
int insertBuyOrderRefund(BuyOrder buyOrder, BigDecimal refundFee, int deductShipping,String remark);
|
||||
String genRefundNo();
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ public interface CouponService extends IService<CouponEntity> {
|
||||
|
||||
R insertCouponHistory(int couponId, int userId,int getType,int status,String remark);
|
||||
|
||||
R insertCouponHistory(BuyOrder buyOrder, int couponId, int userId, int getType, int status, String remark);
|
||||
|
||||
List<CouponHistory> getCouponListPayment(Map<String,Object> params);
|
||||
|
||||
//使用优惠卷
|
||||
|
||||
@@ -29,4 +29,5 @@ public interface UserVipService extends IService<UserVip> {
|
||||
|
||||
void openVipForUser(BuyOrder buyOrder);
|
||||
|
||||
void refundVip(BuyOrder buyOrder);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Random;
|
||||
|
||||
@Slf4j
|
||||
@Service("commonBuyOrderRefundService")
|
||||
@@ -30,4 +31,10 @@ public class BuyOrderRefundServiceImpl extends ServiceImpl<BuyOrderRefundDao, Bu
|
||||
this.save(buyOrderRefund);
|
||||
return buyOrderRefund.getId();
|
||||
}
|
||||
@Override
|
||||
public String genRefundNo() {
|
||||
long time = System.currentTimeMillis();
|
||||
int random = new Random().nextInt(900) + 100; // 100~999
|
||||
return "RF" + time + random;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +123,50 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
|
||||
return R.error("优惠券暂未开始发放");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public R insertCouponHistory(BuyOrder buyOrder, int couponId, int userId, int getType, int status, String remark) {
|
||||
CouponEntity couponEntity = couponDao.selectById(couponId);
|
||||
if (couponEntity.getCurrentState()==0){
|
||||
int historyCount = couponHistoryDao.selectCount(new LambdaQueryWrapper<CouponHistory>()
|
||||
.eq(CouponHistory::getCouponId,couponId)).intValue();
|
||||
//是否超出总发行量
|
||||
if (historyCount<couponEntity.getTotalCirculation()){
|
||||
List<CouponHistory> historyList = couponHistoryDao.selectList(new LambdaQueryWrapper<CouponHistory>()
|
||||
.eq(CouponHistory::getUserId,userId)
|
||||
.eq(CouponHistory::getCouponId,couponId));
|
||||
//是否超出可持有张数
|
||||
if (historyList.size()<couponEntity.getLimitedCollar()){
|
||||
CouponHistory couponHistory = new CouponHistory();
|
||||
couponHistory.setCouponId(couponId);
|
||||
couponHistory.setUserId(userId);
|
||||
couponHistory.setGetType(getType);
|
||||
couponHistory.setStatus(status);
|
||||
couponHistory.setRemark(remark);
|
||||
couponHistory.setEffectType(couponEntity.getEffectType());
|
||||
Date date = new Date();
|
||||
if (couponEntity.getEffectType()==1){
|
||||
couponHistory.setStartTime(date);
|
||||
couponHistory.setEndTime(DateUtils.addDateDays(date,couponEntity.getValidity()));
|
||||
}else if (couponEntity.getEffectType()==2){
|
||||
couponHistory.setStartTime(couponEntity.getEffectTime());
|
||||
couponHistory.setEndTime(couponEntity.getExpireTime());
|
||||
}
|
||||
if (couponHistory.getStatus()==1){
|
||||
couponHistory.setUseTime(date);
|
||||
}
|
||||
couponHistory.setOrderId(buyOrder.getOrderId());
|
||||
couponHistoryDao.insert(couponHistory);
|
||||
return R.ok();
|
||||
}else {
|
||||
return R.error("每人限领"+couponEntity.getLimitedCollar()+"张");
|
||||
}
|
||||
}else {
|
||||
return R.error("优惠券已放完");
|
||||
}
|
||||
}else {
|
||||
return R.error("优惠券暂未开始发放");
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public List<CouponHistory> getCouponListPayment(Map<String, Object> params) {
|
||||
List<CouponHistory> res = new ArrayList<>();
|
||||
@@ -280,17 +323,25 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
|
||||
if (userVipList.size() > 0) {
|
||||
isVip = true;
|
||||
}
|
||||
System.out.println("isVip:"+isVip);
|
||||
BigDecimal refundAllJF = BigDecimal.ZERO;
|
||||
Boolean isRefundCoupon = false;
|
||||
for (Map<String,Object> map : buyOrderProducts) {
|
||||
ShopProduct shopProduct = shopProductDao.selectById(map.get("product_id").toString());
|
||||
System.out.println("goodsType:"+shopProduct.getGoodsType());
|
||||
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));
|
||||
BigDecimal sumRefundJF = couponEntity.getCouponAmount().multiply(quantity);
|
||||
refundAllJF = refundAllJF.add(sumRefundJF);
|
||||
|
||||
QueryWrapper<CouponHistory> couponHistoryRemoveWrapper = new QueryWrapper<>();
|
||||
couponHistoryRemoveWrapper.eq("order_id",order.getOrderId());
|
||||
couponHistoryRemoveWrapper.eq("status",1);
|
||||
couponHistoryService.remove(couponHistoryRemoveWrapper);
|
||||
}else{
|
||||
isRefundCoupon = true;
|
||||
}
|
||||
@@ -338,7 +389,7 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
|
||||
if (couponEntity.getCouponType()==0){
|
||||
BigDecimal jf = BigDecimal.ZERO;
|
||||
for (int i=0;i<Integer.parseInt(map.get("quantity").toString());i++){
|
||||
R res = insertCouponHistory(couponId,order.getUserId(), 1,1,
|
||||
R res = insertCouponHistory(order,couponId,order.getUserId(), 1,1,
|
||||
"购买商品"+shopProduct.getProductName()+"赠送;vip用户购买预售书优惠券换积分。");
|
||||
if (Integer.parseInt(res.get("code").toString())==0&&couponEntity.getCouponAmount() != null && couponEntity.getCouponAmount().compareTo(BigDecimal.ZERO)>0) {
|
||||
jf = jf.add(couponEntity.getCouponAmount());
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
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.ShiroUtils;
|
||||
import com.peanut.modules.book.vo.UserVipYearVo;
|
||||
import com.peanut.modules.common.dao.*;
|
||||
import com.peanut.modules.common.entity.*;
|
||||
import com.peanut.modules.common.service.UserVipLogService;
|
||||
@@ -12,7 +15,6 @@ import org.apache.commons.lang.time.DateUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
|
||||
@Slf4j
|
||||
@@ -33,6 +35,8 @@ public class UserVipServiceImpl extends ServiceImpl<UserVipDao, UserVip> impleme
|
||||
private VipBuyConfigDao vipBuyConfigDao;
|
||||
@Autowired
|
||||
private UserVipLogService userVipLogService;
|
||||
@Autowired
|
||||
private UserVipLogDao userVipLogDao;
|
||||
|
||||
@Override
|
||||
public boolean isVip() {
|
||||
@@ -401,5 +405,26 @@ public class UserVipServiceImpl extends ServiceImpl<UserVipDao, UserVip> impleme
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refundVip(BuyOrder buyOrder){
|
||||
MPJLambdaWrapper<UserVipLog> UserVipLogMPJLambdaWrapper = new MPJLambdaWrapper<>();
|
||||
UserVipLogMPJLambdaWrapper.leftJoin(UserVip.class,UserVip::getId,UserVipLog::getUserVipId);
|
||||
UserVipLogMPJLambdaWrapper.leftJoin(BuyOrder.class,BuyOrder::getOrderSn,UserVipLog::getOrderSn);
|
||||
UserVipLogMPJLambdaWrapper.leftJoin(VipBuyConfigEntity.class,VipBuyConfigEntity::getId,BuyOrder::getVipBuyConfigId);
|
||||
UserVipLogMPJLambdaWrapper.selectAll(UserVip.class);
|
||||
UserVipLogMPJLambdaWrapper.select(VipBuyConfigEntity::getYear);
|
||||
UserVipLogMPJLambdaWrapper.eq(UserVipLog::getOrderSn,buyOrder.getOrderSn()).eq(UserVip::getState,0);
|
||||
List<UserVipYearVo> userVipYearList = userVipLogDao.selectJoinList(UserVipYearVo.class, UserVipLogMPJLambdaWrapper);
|
||||
for (UserVipYearVo userVipYearVo:userVipYearList){
|
||||
UserVip userVip = userVipDao.selectById(userVipYearVo.getId());
|
||||
userVip.setEndTime(DateUtils.addYears(userVip.getEndTime(),-userVipYearVo.getYear()));
|
||||
if(userVip.getStartTime().compareTo(userVip.getEndTime())==0){
|
||||
this.removeById(userVip);
|
||||
}else{
|
||||
this.updateById(userVip);
|
||||
}
|
||||
}
|
||||
userVipLogService.remove(new QueryWrapper<UserVipLog>().eq("order_sn",buyOrder.getOrderSn()).eq("user_id",buyOrder.getUserId()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user