Unverified Commit a2f77152 authored by Tyson's avatar Tyson Committed by GitHub
Browse files

修复订单取消/退款之后优惠券没有返还问题 (#397)

parent acb459a7
......@@ -10,11 +10,9 @@ import org.linlinjava.litemall.core.notify.NotifyService;
import org.linlinjava.litemall.core.notify.NotifyType;
import org.linlinjava.litemall.core.util.JacksonUtil;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.domain.LitemallComment;
import org.linlinjava.litemall.db.domain.LitemallOrder;
import org.linlinjava.litemall.db.domain.LitemallOrderGoods;
import org.linlinjava.litemall.db.domain.UserVo;
import org.linlinjava.litemall.db.domain.*;
import org.linlinjava.litemall.db.service.*;
import org.linlinjava.litemall.db.util.CouponUserConstant;
import org.linlinjava.litemall.db.util.OrderUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -50,6 +48,8 @@ public class AdminOrderService {
private NotifyService notifyService;
@Autowired
private LogHelper logHelper;
@Autowired
private LitemallCouponUserService couponUserService;
public Object list(Integer userId, String orderSn, LocalDateTime start, LocalDateTime end, List<Short> orderStatusArray,
Integer page, Integer limit, String sort, String order) {
......@@ -159,6 +159,15 @@ public class AdminOrderService {
}
}
// 返还优惠券
List<LitemallCouponUser> couponUsers = couponUserService.findByOid(orderId);
for (LitemallCouponUser couponUser: couponUsers) {
// 优惠券状态设置为可使用
couponUser.setStatus(CouponUserConstant.STATUS_USABLE);
couponUser.setUpdateTime(LocalDateTime.now());
couponUserService.update(couponUser);
}
//TODO 发送邮件和短信通知,这里采用异步发送
// 退款成功通知用户, 例如“您申请的订单退款 [ 单号:{1} ] 已成功,请耐心等待到账。”
// 注意订单号只发后6位
......
......@@ -91,4 +91,10 @@ public class LitemallCouponUserService {
example.or().andStatusEqualTo(CouponUserConstant.STATUS_USABLE).andEndTimeLessThan(LocalDateTime.now()).andDeletedEqualTo(false);
return couponUserMapper.selectByExample(example);
}
public List<LitemallCouponUser> findByOid(Integer orderId) {
LitemallCouponUserExample example = new LitemallCouponUserExample();
example.or().andOrderIdEqualTo(orderId).andDeletedEqualTo(false);
return couponUserMapper.selectByExample(example);
}
}
......@@ -534,6 +534,9 @@ public class WxOrderService {
}
}
// 返还优惠券
releaseCoupon(orderId);
return ResponseUtil.ok();
}
......@@ -1013,4 +1016,21 @@ public class WxOrderService {
return ResponseUtil.ok();
}
/**
* 取消订单/退款返还优惠券
* <br/>
* @param orderId
* @return void
* @author Tyson
* @date 2020/6/8/0008 1:41
*/
public void releaseCoupon(Integer orderId) {
List<LitemallCouponUser> couponUsers = couponUserService.findByOid(orderId);
for (LitemallCouponUser couponUser: couponUsers) {
// 优惠券状态设置为可使用
couponUser.setStatus(CouponUserConstant.STATUS_USABLE);
couponUser.setUpdateTime(LocalDateTime.now());
couponUserService.update(couponUser);
}
}
}
\ No newline at end of file
......@@ -11,6 +11,7 @@ import org.linlinjava.litemall.db.service.LitemallGoodsProductService;
import org.linlinjava.litemall.db.service.LitemallOrderGoodsService;
import org.linlinjava.litemall.db.service.LitemallOrderService;
import org.linlinjava.litemall.db.util.OrderUtil;
import org.linlinjava.litemall.wx.service.WxOrderService;
import java.time.LocalDateTime;
import java.util.List;
......@@ -36,6 +37,7 @@ public class OrderUnpaidTask extends Task {
LitemallOrderService orderService = BeanUtil.getBean(LitemallOrderService.class);
LitemallOrderGoodsService orderGoodsService = BeanUtil.getBean(LitemallOrderGoodsService.class);
LitemallGoodsProductService productService = BeanUtil.getBean(LitemallGoodsProductService.class);
WxOrderService wxOrderService = BeanUtil.getBean(WxOrderService.class);
LitemallOrder order = orderService.findById(this.orderId);
if(order == null){
......@@ -62,6 +64,10 @@ public class OrderUnpaidTask extends Task {
throw new RuntimeException("商品货品库存增加失败");
}
}
//返还优惠券
wxOrderService.releaseCoupon(orderId);
logger.info("系统结束处理延时任务---订单超时未付款---" + this.orderId);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment