使用优惠券处理
This commit is contained in:
@@ -12,6 +12,7 @@ import com.peanut.common.utils.OrderUtils;
|
||||
import com.peanut.modules.common.dao.*;
|
||||
import com.peanut.modules.book.service.*;
|
||||
import com.peanut.modules.common.entity.*;
|
||||
import com.peanut.modules.common.service.CouponHistoryService;
|
||||
import com.peanut.modules.common.service.CouponService;
|
||||
import com.peanut.modules.master.service.UserCourseBuyService;
|
||||
import com.peanut.modules.pay.alipay.config.AliPayConfig;
|
||||
@@ -75,6 +76,8 @@ public class AliPayServiceImpl implements AliPayService {
|
||||
private UserVipDao userVipDao;
|
||||
@Autowired
|
||||
private CouponService couponService;
|
||||
@Autowired
|
||||
private CouponHistoryService couponHistoryService;
|
||||
|
||||
@Override
|
||||
public String pay(AlipayDTO payDto) {
|
||||
@@ -158,25 +161,31 @@ public class AliPayServiceImpl implements AliPayService {
|
||||
String body = oldPayZfbOrderEntity.getBody();
|
||||
String customerid = oldPayZfbOrderEntity.getCustomerid();
|
||||
|
||||
BuyOrder order = buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrder>()
|
||||
.eq("order_sn", oldPayZfbOrderEntity.getRelevanceoid()));
|
||||
//使用优惠券
|
||||
if (order.getCouponId()!=null&&order.getCouponId()!=0){
|
||||
CouponHistory couponHistory = couponHistoryService.getById(order.getCouponId());
|
||||
couponHistory.setOrderId(order.getOrderId());
|
||||
couponService.useCouponAmount(couponHistory);
|
||||
}
|
||||
|
||||
if("relearn".equals(subject)){
|
||||
BuyOrder orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrder>()
|
||||
.eq("order_sn", oldPayZfbOrderEntity.getRelevanceoid()));
|
||||
//更新 订单 记录
|
||||
buyOrderService.updateOrderStatus(Integer.valueOf(customerid),oldPayZfbOrderEntity.getRelevanceoid(),"2");
|
||||
//插入复读记录
|
||||
userCourseBuyService.addUserCourseBuyRelearn(orderEntity,"支付宝购买:"+orderEntity.getOrderSn());
|
||||
userCourseBuyService.addUserCourseBuyRelearn(order,"支付宝购买:"+order.getOrderSn());
|
||||
}
|
||||
|
||||
if ("vip".equals(subject)) {
|
||||
BuyOrder orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrder>().eq("order_sn", oldPayZfbOrderEntity.getRelevanceoid()));
|
||||
//更新 订单 记录
|
||||
buyOrderService.updateOrderStatus(Integer.valueOf(customerid),oldPayZfbOrderEntity.getRelevanceoid(),"2");
|
||||
//处理抵扣积分
|
||||
if(orderEntity.getJfDeduction().compareTo(BigDecimal.ZERO)>0){
|
||||
userCoinJf(orderEntity);
|
||||
if(order.getJfDeduction().compareTo(BigDecimal.ZERO)>0){
|
||||
userCoinJf(order);
|
||||
}
|
||||
//开通vip
|
||||
openVipForUser(orderEntity);
|
||||
openVipForUser(order);
|
||||
//获取会员开通 日期
|
||||
// BookBuyConfigEntity bookBuyConfigEntity = bookBuyConfigService.getById(Integer.valueOf(body));
|
||||
// String month = bookBuyConfigEntity.getMonth();
|
||||
@@ -219,42 +228,36 @@ public class AliPayServiceImpl implements AliPayService {
|
||||
buyOrderService.updateOrderStatus(Integer.valueOf(customerid),oldPayZfbOrderEntity.getRelevanceoid(),"2");
|
||||
}
|
||||
if ("order".equals(subject)) {
|
||||
|
||||
BuyOrder orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrder>().eq("order_sn", oldPayZfbOrderEntity.getRelevanceoid()));
|
||||
//更新 订单 记录
|
||||
String ActString = buyOrderService.checkWlOrder(orderEntity.getOrderSn())?"0":"2";
|
||||
String ActString = buyOrderService.checkWlOrder(order.getOrderSn())?"0":"2";
|
||||
buyOrderService.updateOrderStatus(Integer.valueOf(customerid),oldPayZfbOrderEntity.getRelevanceoid(),ActString);
|
||||
|
||||
//处理抵扣积分
|
||||
if(orderEntity.getJfDeduction().compareTo(BigDecimal.ZERO)>0){
|
||||
userCoinJf(orderEntity);
|
||||
if(order.getJfDeduction().compareTo(BigDecimal.ZERO)>0){
|
||||
userCoinJf(order);
|
||||
}
|
||||
|
||||
/* 记录用户购买的书籍 */
|
||||
// 查询订单的所有 book_id
|
||||
List<Integer> orderBookIdList = shopProductBookDao.getOrderBookId(orderEntity.getOrderSn());
|
||||
List<Integer> orderBookIdList = shopProductBookDao.getOrderBookId(order.getOrderSn());
|
||||
// 去重
|
||||
Set<Integer> set = new HashSet<>(orderBookIdList);
|
||||
orderBookIdList.clear();
|
||||
orderBookIdList.addAll(set);
|
||||
// 查询用户的所有 book_id
|
||||
List<Integer> userBookIdList = userEbookBuyDao.getUserBookId(orderEntity.getUserId());
|
||||
List<Integer> userBookIdList = userEbookBuyDao.getUserBookId(order.getUserId());
|
||||
// 取差集
|
||||
orderBookIdList.removeAll(userBookIdList);
|
||||
// 为用户添加书籍
|
||||
for (Integer bookId : orderBookIdList) {
|
||||
UserEbookBuyEntity entity = new UserEbookBuyEntity();
|
||||
entity.setUserId(orderEntity.getUserId());
|
||||
entity.setUserId(order.getUserId());
|
||||
entity.setBookId(bookId);
|
||||
userEbookBuyDao.insert(entity);
|
||||
}
|
||||
|
||||
|
||||
//开通course,start
|
||||
List<ShopProductCourseEntity> orderCourse = buyOrderService.getOrderCourse(orderEntity.getOrderSn());
|
||||
List<ShopProductCourseEntity> orderCourse = buyOrderService.getOrderCourse(order.getOrderSn());
|
||||
for ( ShopProductCourseEntity s : orderCourse){
|
||||
LambdaQueryWrapper<UserCourseBuyEntity> wrapper2 = new LambdaQueryWrapper<>();
|
||||
wrapper2.eq(UserCourseBuyEntity::getUserId,orderEntity.getUserId());
|
||||
wrapper2.eq(UserCourseBuyEntity::getUserId,order.getUserId());
|
||||
wrapper2.eq(UserCourseBuyEntity::getCatalogueId,s.getCatalogueId());
|
||||
wrapper2.and(r->r.isNull(UserCourseBuyEntity::getEndTime).or().gt(UserCourseBuyEntity::getEndTime,new Date()));
|
||||
List<UserCourseBuyEntity> userCourseBuyEntities = userCourseBuyDao.selectList(wrapper2);
|
||||
@@ -267,11 +270,11 @@ public class AliPayServiceImpl implements AliPayService {
|
||||
calendar.add(Calendar.DAY_OF_MONTH,s.getDays());
|
||||
userCourseBuyEntity.setEndTime(calendar.getTime());
|
||||
}
|
||||
userCourseBuyEntity.setCome(userCourseBuyEntity.getCome()+";延期(支付宝购买:"+orderEntity.getOrderSn()+")");
|
||||
userCourseBuyEntity.setCome(userCourseBuyEntity.getCome()+";延期(支付宝购买:"+order.getOrderSn()+")");
|
||||
userCourseBuyDao.updateById(userCourseBuyEntity);
|
||||
}else{
|
||||
UserCourseBuyEntity userCourseBuyEntity = new UserCourseBuyEntity();
|
||||
userCourseBuyEntity.setUserId(orderEntity.getUserId());
|
||||
userCourseBuyEntity.setUserId(order.getUserId());
|
||||
userCourseBuyEntity.setCourseId(s.getCourseId());
|
||||
userCourseBuyEntity.setCatalogueId(s.getCatalogueId());
|
||||
userCourseBuyEntity.setDays(s.getDays());
|
||||
@@ -281,34 +284,34 @@ public class AliPayServiceImpl implements AliPayService {
|
||||
// cal.setTime(new Date());
|
||||
// cal.add(Calendar.DAY_OF_MONTH,s.getDays());
|
||||
// userCourseBuyEntity.setEndTime(cal.getTime());
|
||||
userCourseBuyEntity.setCome("支付宝购买:"+orderEntity.getOrderSn());
|
||||
userCourseBuyEntity.setCome("支付宝购买:"+order.getOrderSn());
|
||||
userCourseBuyDao.insert(userCourseBuyEntity);
|
||||
}
|
||||
}
|
||||
//开通course,end
|
||||
|
||||
List<Integer> collect = buyOrderProductDao.selectList(new LambdaQueryWrapper<BuyOrderProduct>().eq(BuyOrderProduct::getOrderId, orderEntity.getOrderId())).stream().map(BuyOrderProduct::getProductId).collect(Collectors.toList());
|
||||
List<Integer> collect = buyOrderProductDao.selectList(new LambdaQueryWrapper<BuyOrderProduct>().eq(BuyOrderProduct::getOrderId, order.getOrderId())).stream().map(BuyOrderProduct::getProductId).collect(Collectors.toList());
|
||||
//发放优惠卷
|
||||
couponService.insertCouponHistoryByProductId(collect);
|
||||
//手摸脚模购买后会开启用户的脉穴的功能
|
||||
if(collect.contains(128)||collect.contains(129)||collect.contains(130)||collect.contains(131)||collect.contains(136)||collect.contains(137)){
|
||||
MyUserEntity userInfo = userService.getById(orderEntity.getUserId());
|
||||
MyUserEntity userInfo = userService.getById(order.getUserId());
|
||||
userInfo.setPointPower(1);
|
||||
userService.updateById(userInfo);
|
||||
}
|
||||
if(collect.contains(133)||collect.contains(134)||collect.contains(135)){
|
||||
MyUserEntity userInfo = userService.getById(orderEntity.getUserId());
|
||||
MyUserEntity userInfo = userService.getById(order.getUserId());
|
||||
userInfo.setTgdzPower(1);
|
||||
userService.updateById(userInfo);
|
||||
}
|
||||
if(collect.contains(39)||collect.contains(62)||collect.contains(123)||collect.contains(127)){
|
||||
MyUserEntity userInfo = userService.getById(orderEntity.getUserId());
|
||||
MyUserEntity userInfo = userService.getById(order.getUserId());
|
||||
userInfo.setWylqPower(1);
|
||||
userService.updateById(userInfo);
|
||||
}
|
||||
|
||||
if(collect.contains(43)||collect.contains(62)||collect.contains(124)){
|
||||
MyUserEntity userInfo = userService.getById(orderEntity.getUserId());
|
||||
MyUserEntity userInfo = userService.getById(order.getUserId());
|
||||
userInfo.setPrescriptBPower(1);
|
||||
userService.updateById(userInfo);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.peanut.modules.common.dao.*;
|
||||
import com.peanut.modules.book.service.*;
|
||||
import com.peanut.modules.common.entity.*;
|
||||
import com.peanut.modules.common.service.CouponHistoryService;
|
||||
import com.peanut.modules.common.service.CouponService;
|
||||
import com.peanut.modules.master.service.UserCourseBuyService;
|
||||
import com.peanut.modules.pay.refund.entity.PayRefundOrder;
|
||||
@@ -83,6 +84,8 @@ public class WxpayServiceImpl extends ServiceImpl<PayWechatOrderDao, PayWechatOr
|
||||
private UserVipDao userVipDao;
|
||||
@Autowired
|
||||
private CouponService couponService;
|
||||
@Autowired
|
||||
private CouponHistoryService couponHistoryService;
|
||||
|
||||
@Override
|
||||
public void prepay(WechatPaymentInfo paymentInfo){
|
||||
@@ -144,35 +147,34 @@ public class WxpayServiceImpl extends ServiceImpl<PayWechatOrderDao, PayWechatOr
|
||||
payWechatOrderService.updateById(payWechatOrderEntity);
|
||||
// 根据订单号,做幂等处理,并且在对业务数据进行状态检查和处理之前,要采用数据锁进行并发控制,以避免函数重入造成的数据混乱
|
||||
BuyOrder order = this.buyOrderService.getOne(new QueryWrapper<BuyOrder>().eq("order_sn", orderNo));
|
||||
|
||||
//使用优惠券
|
||||
if (order.getCouponId()!=null&&order.getCouponId()!=0){
|
||||
CouponHistory couponHistory = couponHistoryService.getById(order.getCouponId());
|
||||
couponHistory.setOrderId(order.getOrderId());
|
||||
couponService.useCouponAmount(couponHistory);
|
||||
}
|
||||
if("relearn".equals(order.getOrderType())){
|
||||
BuyOrder orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrder>()
|
||||
.eq("order_sn", orderNo));
|
||||
//更新 订单 记录
|
||||
buyOrderService.updateOrderStatus(orderEntity.getUserId(),orderNo,"2");
|
||||
buyOrderService.updateOrderStatus(order.getUserId(),orderNo,"2");
|
||||
//插入复读记录
|
||||
userCourseBuyService.addUserCourseBuyRelearn(orderEntity,"微信购买:"+orderEntity.getOrderSn());
|
||||
userCourseBuyService.addUserCourseBuyRelearn(order,"微信购买:"+order.getOrderSn());
|
||||
}
|
||||
|
||||
if("vip".equals(order.getOrderType())){
|
||||
BuyOrder orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrder>().eq("order_sn", orderNo));
|
||||
//更新 订单 记录
|
||||
buyOrderService.updateOrderStatus(orderEntity.getUserId(),orderNo,"2");
|
||||
buyOrderService.updateOrderStatus(order.getUserId(),orderNo,"2");
|
||||
//处理抵扣积分
|
||||
if(orderEntity.getJfDeduction().compareTo(BigDecimal.ZERO)>0){
|
||||
userCoinJf(orderEntity);
|
||||
if(order.getJfDeduction().compareTo(BigDecimal.ZERO)>0){
|
||||
userCoinJf(order);
|
||||
}
|
||||
//开通vip
|
||||
openVipForUser(orderEntity);
|
||||
openVipForUser(order);
|
||||
}
|
||||
|
||||
// 1.根据订单id获取订单信息
|
||||
if ("order".equals(order.getOrderType())) {
|
||||
BuyOrder orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrder>().eq("order_sn", orderNo));
|
||||
BigDecimal realMoney = orderEntity.getRealMoney();
|
||||
|
||||
if(orderEntity.getJfDeduction().compareTo(BigDecimal.ZERO)>0){
|
||||
userCoinJf(orderEntity);
|
||||
if(order.getJfDeduction().compareTo(BigDecimal.ZERO)>0){
|
||||
userCoinJf(order);
|
||||
}
|
||||
|
||||
//开通book,start
|
||||
|
||||
Reference in New Issue
Block a user