Merge remote-tracking branch 'origin/zcc'

This commit is contained in:
wangjinlei
2024-11-01 16:55:15 +08:00
5 changed files with 101 additions and 79 deletions

View File

@@ -201,9 +201,6 @@ public class BuyOrderController {
@RequestMapping(value = "/placeOrder", method = RequestMethod.POST)
@Transactional
public R placeOrder(@RequestBody BuyOrder buyOrder) {
String orderSn = IdWorker.getTimeId().substring(0, 32);
buyOrder.setOrderSn(orderSn);
buyOrderService.save(buyOrder);
List<BuyOrderProduct> buyOrderProductList = buyOrder.getProductList();
// 订单实收金额
BigDecimal totalPrice = new BigDecimal(0);
@@ -245,24 +242,27 @@ public class BuyOrderController {
totalPrice = totalPrice.add(price.multiply(BigDecimal.valueOf(quantity)));
}
//商品价格减去优惠券的优惠金额
if (buyOrder!=null&&buyOrder.getCouponId()!=null&&buyOrder.getCouponId()!=0){
if (buyOrder.getCouponId()!=null&&buyOrder.getCouponId()!=0){
CouponHistory couponHistory = couponHistoryService.getById(buyOrder.getCouponId());
if (couponHistory!=null){
if (couponHistory.getEffectType()!=0){
if (couponHistory.getStartTime().getTime()<new Date().getTime()&&
couponHistory.getEndTime().getTime()>new Date().getTime()){
}else {
return R.error("优惠券使用时间未到");
if (couponHistory.getStatus()==0){
if (couponHistory.getEffectType()!=0){
if (couponHistory.getStartTime().getTime()<new Date().getTime()&&
couponHistory.getEndTime().getTime()>new Date().getTime()){
}else {
return R.error("优惠券使用时间未到");
}
}
}
CouponEntity coupon = couponService.getById(couponHistory.getCouponId());
if (coupon != null){
if (new BigDecimal(coupon.getUseLevel()).compareTo(totalPrice)>0){
return R.error("未达到优惠券使用门槛");
CouponEntity coupon = couponService.getById(couponHistory.getCouponId());
if (coupon != null){
totalPrice = totalPrice.subtract(coupon.getCouponAmount());
}
}else {
if (couponHistory.getStatus()==1){
return R.error("优惠券已被使用");
}else if (couponHistory.getStatus() == 2){
return R.error("优惠券已过期");
}
couponHistory.setOrderId(buyOrder.getOrderId());
couponService.useCouponAmount(couponHistory);
totalPrice = totalPrice.subtract(coupon.getCouponAmount());
}
}
}
@@ -279,6 +279,8 @@ public class BuyOrderController {
return R.error("系统错误订单金额异常!");
}
String orderSn = IdWorker.getTimeId().substring(0, 32);
buyOrder.setOrderSn(orderSn);
if(buyOrder.getAddressId()!=0){
QueryWrapper<UserAddress> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("id", buyOrder.getAddressId());
@@ -295,7 +297,7 @@ public class BuyOrderController {
}
}
buyOrder.setOrderStatus("0");
buyOrderService.updateById(buyOrder);
buyOrderService.save(buyOrder);
//解决购物车相关问题
for (BuyOrderProduct buyOrderProduct : buyOrderProductList) {
@@ -495,7 +497,6 @@ public class BuyOrderController {
}
//回滚优惠卷
if (buyOrder.getCouponId()!=null&&buyOrder.getCouponId()!=0){
couponService.rollbackCoupon(buyOrder.getCouponId());
buyOrder.setCouponId(null);
buyOrderService.updateById(buyOrder);
}
@@ -545,7 +546,6 @@ public class BuyOrderController {
if (buyOrder != null) {
//回滚优惠卷
if (buyOrder.getCouponId()!=null&&buyOrder.getCouponId()!=0){
couponService.rollbackCoupon(buyOrder.getCouponId());
buyOrder.setCouponId(null);
buyOrderService.updateById(buyOrder);
}

View File

@@ -32,7 +32,7 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
@Autowired
private CourseMedicineDao courseMedicineDao;
@Autowired
private RabbitTemplate rabbitTemplate;
private CourseToMedicineDao courseToMedicineDao;
@Autowired
private ShopProductCourseDao shopProductCourseDao;
@Autowired
@@ -56,11 +56,17 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
if (couponEntity.getCouponRange()==1){
list.add(courseDao.selectOne(new LambdaQueryWrapper<CourseEntity>()
.eq(CourseEntity::getId,Integer.parseInt(str))
.select(CourseEntity::getId,CourseEntity::getTitle)));
.select(CourseEntity::getId,CourseEntity::getTitle,CourseEntity::getImage)));
}else if(couponEntity.getCouponRange()==2){
list.add(courseMedicineDao.selectOne(new LambdaQueryWrapper<CourseMedicine>()
.eq(CourseMedicine::getId,Integer.parseInt(str))
.select(CourseMedicine::getId,CourseMedicine::getTitle)));
}else if(couponEntity.getCouponRange()==3){
MPJLambdaWrapper<CourseToMedicine> wrapper = new MPJLambdaWrapper();
wrapper.leftJoin(CourseEntity.class,CourseEntity::getId,CourseToMedicine::getCourseId);
wrapper.selectAll(CourseEntity.class);
wrapper.select(CourseEntity::getId,CourseEntity::getTitle,CourseEntity::getImage);
list.addAll(courseToMedicineDao.selectJoinList(CourseEntity.class,wrapper));
}
}
}
@@ -107,12 +113,6 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
return R.error("优惠券暂未开始发放");
}
}
private MessagePostProcessor messagePostProcessor(long date) {
return message -> {
message.getMessageProperties().setDelay((int)date);
return message;
};
}
@Override
public List<CouponHistory> getCouponListPayment(Map<String, Object> params) {
@@ -128,8 +128,8 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
couponHistory.setCanUse(1);
couponHistory.setCanUseReason("");
if (couponHistory.getEffectType()!=0){
if (couponHistory.getStartTime().getTime() < new Date().getTime() &&
couponHistory.getEndTime().getTime() > new Date().getTime()) {
if (couponHistory.getStartTime().getTime() <= new Date().getTime() &&
couponHistory.getEndTime().getTime() >= new Date().getTime()) {
}else {
couponHistory.setCanUse(0);
couponHistory.setCanUseReason("优惠券使用时间未到");
@@ -140,13 +140,25 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
//无限制
res.add(couponHistory);
}else {
String shopProductIds = params.get("shopProductIds").toString();
String[] ids = shopProductIds.split(",");
for (String shopProductId : ids) {
//课程券和课程分类券
//"shopProductInfos":"1:69:1,2:79:1"//商品id价格数量
String shopProductInfos = params.get("shopProductInfos").toString();
String[] infos = shopProductInfos.split(",");
for (String shopProductInfo : infos) {
String[] info = shopProductInfo.split(":");
//通过优惠卷获取商品
Set<Integer> set = getShopProductByCoupon(couponEntity);
//比对用户优惠卷是否有此商品
if(!set.add(Integer.parseInt(shopProductId))){
if(!set.add(Integer.parseInt(info[0]))){
BigDecimal totalAmount = new BigDecimal(info[1]).multiply(new BigDecimal(info[2]));
if (new BigDecimal(couponEntity.getUseLevel()).compareTo(totalAmount)>0){
couponHistory.setCanUse(0);
couponHistory.setCanUseReason("优惠券未到使用门槛");
}
if (couponEntity.getCouponAmount().compareTo(totalAmount)>0){
couponHistory.setCanUse(0);
couponHistory.setCanUseReason("优惠券面额大于商品价值");
}
res.add(couponHistory);
}
}
@@ -183,6 +195,12 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
set.add(shopProductCourseEntity.getProductId());
}
}
}else if (couponEntity.getCouponRange()==3) {
//3全部课程商品
List<ShopProductCourseEntity> shopProductCourseList = shopProductCourseDao.selectList(new LambdaQueryWrapper<>());
for (ShopProductCourseEntity shopProductCourseEntity : shopProductCourseList) {
set.add(shopProductCourseEntity.getProductId());
}
}
return set;
}

View File

@@ -42,7 +42,6 @@ public class OrderCancelConsumer {
buyOrder.setOrderStatus(Constants.ORDER_STATUS_OUT_OF_TIME);
//回滚优惠卷
if (buyOrder.getCouponId()!=null&&buyOrder.getCouponId()!=0){
couponService.rollbackCoupon(buyOrder.getCouponId());
buyOrder.setCouponId(null);
}
//回滚库存

View File

@@ -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);
}
//开通coursestart
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);
}
}
//开通courseend
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);
}

View File

@@ -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);
}
//开通bookstart