Merge remote-tracking branch 'origin/zcc'
This commit is contained in:
@@ -20,6 +20,8 @@ import com.peanut.modules.book.vo.response.OrderAddressResponseVo;
|
|||||||
import com.peanut.modules.common.dao.JfTransactionDetailsDao;
|
import com.peanut.modules.common.dao.JfTransactionDetailsDao;
|
||||||
import com.peanut.modules.common.dao.UserCourseBuyDao;
|
import com.peanut.modules.common.dao.UserCourseBuyDao;
|
||||||
import com.peanut.modules.common.entity.*;
|
import com.peanut.modules.common.entity.*;
|
||||||
|
import com.peanut.modules.common.service.CouponHistoryService;
|
||||||
|
import com.peanut.modules.common.service.CouponService;
|
||||||
import com.peanut.modules.pay.weChatPay.dto.WechatPaymentInfo;
|
import com.peanut.modules.pay.weChatPay.dto.WechatPaymentInfo;
|
||||||
import com.peanut.modules.pay.weChatPay.service.WxpayService;
|
import com.peanut.modules.pay.weChatPay.service.WxpayService;
|
||||||
import com.peanut.modules.sys.entity.SysConfigEntity;
|
import com.peanut.modules.sys.entity.SysConfigEntity;
|
||||||
@@ -30,7 +32,6 @@ import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
@@ -89,6 +90,10 @@ public class BuyOrderController {
|
|||||||
private UserCourseBuyDao userCourseBuyDao;
|
private UserCourseBuyDao userCourseBuyDao;
|
||||||
@Autowired
|
@Autowired
|
||||||
private JfTransactionDetailsDao jfTransactionDetailsDao;
|
private JfTransactionDetailsDao jfTransactionDetailsDao;
|
||||||
|
@Autowired
|
||||||
|
private CouponService couponService;
|
||||||
|
@Autowired
|
||||||
|
private CouponHistoryService couponHistoryService;
|
||||||
|
|
||||||
@RequestMapping(value = "/decomposeShipment", method = RequestMethod.POST)
|
@RequestMapping(value = "/decomposeShipment", method = RequestMethod.POST)
|
||||||
public R decomposeShipment(@RequestBody BuyOrderListRequestVo requestVo) {
|
public R decomposeShipment(@RequestBody BuyOrderListRequestVo requestVo) {
|
||||||
@@ -195,7 +200,10 @@ public class BuyOrderController {
|
|||||||
*/
|
*/
|
||||||
@RequestMapping(value = "/placeOrder", method = RequestMethod.POST)
|
@RequestMapping(value = "/placeOrder", method = RequestMethod.POST)
|
||||||
@Transactional
|
@Transactional
|
||||||
public R placeOrder(@RequestBody BuyOrder buyOrder) throws IOException {
|
public R placeOrder(@RequestBody BuyOrder buyOrder) {
|
||||||
|
String orderSn = IdWorker.getTimeId().substring(0, 32);
|
||||||
|
buyOrder.setOrderSn(orderSn);
|
||||||
|
buyOrderService.save(buyOrder);
|
||||||
List<BuyOrderProduct> buyOrderProductList = buyOrder.getProductList();
|
List<BuyOrderProduct> buyOrderProductList = buyOrder.getProductList();
|
||||||
// 订单实收金额
|
// 订单实收金额
|
||||||
BigDecimal totalPrice = new BigDecimal(0);
|
BigDecimal totalPrice = new BigDecimal(0);
|
||||||
@@ -237,7 +245,27 @@ public class BuyOrderController {
|
|||||||
totalPrice = totalPrice.add(price.multiply(BigDecimal.valueOf(quantity)));
|
totalPrice = totalPrice.add(price.multiply(BigDecimal.valueOf(quantity)));
|
||||||
}
|
}
|
||||||
//商品价格减去优惠券的优惠金额
|
//商品价格减去优惠券的优惠金额
|
||||||
// totalPrice = totalPrice.subtract(0);
|
if (buyOrder!=null&&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("优惠券使用时间未到");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CouponEntity coupon = couponService.getById(couponHistory.getCouponId());
|
||||||
|
if (coupon != null){
|
||||||
|
if (new BigDecimal(coupon.getUseLevel()).compareTo(totalPrice)>0){
|
||||||
|
return R.error("未达到优惠券使用门槛");
|
||||||
|
}
|
||||||
|
couponHistory.setOrderId(buyOrder.getOrderId());
|
||||||
|
couponService.useCouponAmount(couponHistory);
|
||||||
|
totalPrice = totalPrice.subtract(coupon.getCouponAmount());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//加上运费金额
|
//加上运费金额
|
||||||
totalPrice = totalPrice.add(getShoppingAmount(buyOrder));
|
totalPrice = totalPrice.add(getShoppingAmount(buyOrder));
|
||||||
@@ -251,8 +279,6 @@ public class BuyOrderController {
|
|||||||
return R.error("系统错误订单金额异常!");
|
return R.error("系统错误订单金额异常!");
|
||||||
}
|
}
|
||||||
|
|
||||||
String orderSn = IdWorker.getTimeId().substring(0, 32);
|
|
||||||
buyOrder.setOrderSn(orderSn);
|
|
||||||
if(buyOrder.getAddressId()!=0){
|
if(buyOrder.getAddressId()!=0){
|
||||||
QueryWrapper<UserAddress> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<UserAddress> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq("id", buyOrder.getAddressId());
|
queryWrapper.eq("id", buyOrder.getAddressId());
|
||||||
@@ -269,7 +295,7 @@ public class BuyOrderController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
buyOrder.setOrderStatus("0");
|
buyOrder.setOrderStatus("0");
|
||||||
buyOrderService.save(buyOrder);
|
buyOrderService.updateById(buyOrder);
|
||||||
|
|
||||||
//解决购物车相关问题
|
//解决购物车相关问题
|
||||||
for (BuyOrderProduct buyOrderProduct : buyOrderProductList) {
|
for (BuyOrderProduct buyOrderProduct : buyOrderProductList) {
|
||||||
@@ -301,6 +327,11 @@ public class BuyOrderController {
|
|||||||
//消费用户积分并记录用户积分消费记录
|
//消费用户积分并记录用户积分消费记录
|
||||||
addEbookToUser(buyOrderProductList, buyOrder, 0);
|
addEbookToUser(buyOrderProductList, buyOrder, 0);
|
||||||
addCourseToUser(buyOrder);
|
addCourseToUser(buyOrder);
|
||||||
|
//发放优惠卷
|
||||||
|
List<Integer> collect = buyOrderProductService.list(new LambdaQueryWrapper<BuyOrderProduct>()
|
||||||
|
.eq(BuyOrderProduct::getOrderId, buyOrder.getOrderId()))
|
||||||
|
.stream().map(BuyOrderProduct::getProductId).collect(Collectors.toList());
|
||||||
|
couponService.insertCouponHistoryByProductId(collect);
|
||||||
} else {
|
} else {
|
||||||
return R.error(500, "天医币余额不足!");
|
return R.error(500, "天医币余额不足!");
|
||||||
}
|
}
|
||||||
@@ -459,10 +490,15 @@ public class BuyOrderController {
|
|||||||
QueryWrapper<BuyOrder> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<BuyOrder> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq("order_sn", orderSn);
|
queryWrapper.eq("order_sn", orderSn);
|
||||||
BuyOrder buyOrder = buyOrderService.getOne(queryWrapper);
|
BuyOrder buyOrder = buyOrderService.getOne(queryWrapper);
|
||||||
|
|
||||||
if (buyOrder == null) {
|
if (buyOrder == null) {
|
||||||
return R.error("订单不存在");
|
return R.error("订单不存在");
|
||||||
}
|
}
|
||||||
|
//回滚优惠卷
|
||||||
|
if (buyOrder.getCouponId()!=null&&buyOrder.getCouponId()!=0){
|
||||||
|
couponService.rollbackCoupon(buyOrder.getCouponId());
|
||||||
|
buyOrder.setCouponId(null);
|
||||||
|
buyOrderService.updateById(buyOrder);
|
||||||
|
}
|
||||||
// 库存回滚
|
// 库存回滚
|
||||||
QueryWrapper<BuyOrderProduct> buyOrderProductQueryWrapper = new QueryWrapper<>();
|
QueryWrapper<BuyOrderProduct> buyOrderProductQueryWrapper = new QueryWrapper<>();
|
||||||
buyOrderProductQueryWrapper.eq("order_id", buyOrder.getOrderId());
|
buyOrderProductQueryWrapper.eq("order_id", buyOrder.getOrderId());
|
||||||
@@ -500,18 +536,22 @@ public class BuyOrderController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* app 端 取消订单
|
* app 端 取消订单
|
||||||
* TODO 新版本上线后此方法删除
|
|
||||||
*/
|
*/
|
||||||
@RequestMapping("/appDelete")
|
@RequestMapping("/appDelete")
|
||||||
@Transactional
|
@Transactional
|
||||||
public R appDelete(@RequestParam("orderId") Integer orderId) {
|
public R appDelete(@RequestParam("orderId") Integer orderId) {
|
||||||
|
|
||||||
//1. 判断订单状态
|
//1. 判断订单状态
|
||||||
BuyOrder byId = buyOrderService.getById(orderId);
|
BuyOrder buyOrder = buyOrderService.getById(orderId);
|
||||||
if (byId != null) {
|
if (buyOrder != null) {
|
||||||
|
//回滚优惠卷
|
||||||
|
if (buyOrder.getCouponId()!=null&&buyOrder.getCouponId()!=0){
|
||||||
|
couponService.rollbackCoupon(buyOrder.getCouponId());
|
||||||
|
buyOrder.setCouponId(null);
|
||||||
|
buyOrderService.updateById(buyOrder);
|
||||||
|
}
|
||||||
// 库存回滚
|
// 库存回滚
|
||||||
List<BuyOrderDetail> buyOrderDetailEntities = buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetail>()
|
List<BuyOrderDetail> buyOrderDetailEntities = buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetail>()
|
||||||
.eq("order_id", byId.getOrderId()));
|
.eq("order_id", buyOrder.getOrderId()));
|
||||||
for (BuyOrderDetail buyOrderDetailEntity : buyOrderDetailEntities) {
|
for (BuyOrderDetail buyOrderDetailEntity : buyOrderDetailEntities) {
|
||||||
Integer productId = buyOrderDetailEntity.getProductId();
|
Integer productId = buyOrderDetailEntity.getProductId();
|
||||||
ShopProduct product = shopProductService.getById(productId);
|
ShopProduct product = shopProductService.getById(productId);
|
||||||
|
|||||||
@@ -195,6 +195,7 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
|
|||||||
} else if (type.equals("1")) {
|
} else if (type.equals("1")) {
|
||||||
orderEntity.setOrderStatus("2");
|
orderEntity.setOrderStatus("2");
|
||||||
} else if (type.equals("2")) {
|
} else if (type.equals("2")) {
|
||||||
|
orderEntity.setPaymentDate(new Date());
|
||||||
orderEntity.setOrderStatus("3");
|
orderEntity.setOrderStatus("3");
|
||||||
}
|
}
|
||||||
updateById(orderEntity);
|
updateById(orderEntity);
|
||||||
|
|||||||
@@ -4,18 +4,18 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||||
import com.peanut.common.utils.R;
|
import com.peanut.common.utils.R;
|
||||||
import com.peanut.modules.book.service.BuyOrderProductService;
|
import com.peanut.modules.book.service.ShopProductService;
|
||||||
import com.peanut.modules.common.entity.*;
|
import com.peanut.modules.common.entity.*;
|
||||||
import com.peanut.modules.common.service.BuyOrderService;
|
|
||||||
import com.peanut.modules.common.service.CouponHistoryService;
|
import com.peanut.modules.common.service.CouponHistoryService;
|
||||||
import com.peanut.modules.common.service.CouponService;
|
import com.peanut.modules.common.service.CouponService;
|
||||||
|
import com.peanut.modules.common.service.CouponToProductService;
|
||||||
|
import com.peanut.modules.master.service.CourseService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -29,6 +29,12 @@ public class CouponController {
|
|||||||
private CouponService couponService;
|
private CouponService couponService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private CouponHistoryService couponHistoryService;
|
private CouponHistoryService couponHistoryService;
|
||||||
|
@Autowired
|
||||||
|
private CourseService courseService;
|
||||||
|
@Autowired
|
||||||
|
private CouponToProductService couponToProductService;
|
||||||
|
@Autowired
|
||||||
|
private ShopProductService shopProductService;
|
||||||
|
|
||||||
//优惠卷列表
|
//优惠卷列表
|
||||||
@RequestMapping("/getCouponList")
|
@RequestMapping("/getCouponList")
|
||||||
@@ -104,17 +110,26 @@ public class CouponController {
|
|||||||
return R.ok().put("couponEntity",couponEntity);
|
return R.ok().put("couponEntity",couponEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//修改优惠劵状态
|
||||||
|
@RequestMapping("/updateCouponState")
|
||||||
|
public R updateCouponState(@RequestBody Map<String,Object> params){
|
||||||
|
CouponEntity coupon = couponService.getById(params.get("id").toString());
|
||||||
|
coupon.setCurrentState((int)params.get("currentState"));
|
||||||
|
couponService.updateById(coupon);
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
//修改优惠劵
|
//修改优惠劵
|
||||||
@RequestMapping("/updateCoupon")
|
@RequestMapping("/updateCoupon")
|
||||||
public R updateCoupon(@RequestBody CouponEntity couponEntity){
|
public R updateCoupon(@RequestBody CouponEntity couponEntity){
|
||||||
int count = couponHistoryService.count(new LambdaQueryWrapper<CouponHistory>()
|
int count = couponHistoryService.count(new LambdaQueryWrapper<CouponHistory>()
|
||||||
.eq(CouponHistory::getCouponId,couponEntity.getId()));
|
.eq(CouponHistory::getCouponId,couponEntity.getId()));
|
||||||
if (count>0){
|
if (count>0){
|
||||||
return R.error("已有用户拥有优惠卷");
|
return R.error("已有用户拥有优惠券");
|
||||||
}
|
}
|
||||||
CouponEntity c = couponService.getById(couponEntity.getId());
|
CouponEntity c = couponService.getById(couponEntity.getId());
|
||||||
if (c.getCurrentState()==0){
|
if (c.getCurrentState()==0){
|
||||||
return R.error("优惠卷发放中,请先结束再修改");
|
return R.error("优惠券发放中,请先结束再修改");
|
||||||
}
|
}
|
||||||
couponService.updateById(couponEntity);
|
couponService.updateById(couponEntity);
|
||||||
return R.ok();
|
return R.ok();
|
||||||
@@ -127,11 +142,11 @@ public class CouponController {
|
|||||||
int count = couponHistoryService.count(new LambdaQueryWrapper<CouponHistory>()
|
int count = couponHistoryService.count(new LambdaQueryWrapper<CouponHistory>()
|
||||||
.eq(CouponHistory::getCouponId,couponId));
|
.eq(CouponHistory::getCouponId,couponId));
|
||||||
if (count>0){
|
if (count>0){
|
||||||
return R.error("已有用户拥有优惠卷");
|
return R.error("已有用户拥有优惠券");
|
||||||
}
|
}
|
||||||
CouponEntity c = couponService.getById(couponId);
|
CouponEntity c = couponService.getById(couponId);
|
||||||
if (c.getCurrentState()==0){
|
if (c.getCurrentState()==0){
|
||||||
return R.error("优惠卷发放中,请先结束再删除");
|
return R.error("优惠券发放中,请先结束再删除");
|
||||||
}
|
}
|
||||||
couponService.removeById(couponId);
|
couponService.removeById(couponId);
|
||||||
return R.ok();
|
return R.ok();
|
||||||
@@ -161,11 +176,17 @@ public class CouponController {
|
|||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
//当前优惠卷可用商品
|
//优惠卷可绑定课程
|
||||||
@RequestMapping("/getShopProductByCoupon")
|
@RequestMapping("/getCourseList")
|
||||||
public R getShopProductByCoupon(@RequestBody Map<String,Object> params){
|
public R getCourseList(@RequestBody Map<String,Object> params){
|
||||||
Set<Integer> l = couponService.getShopProductByCoupon(Integer.parseInt(params.get("couponId").toString()));
|
Integer limit = Integer.valueOf(params.get("limit").toString());
|
||||||
return R.ok().put("productIds",l);
|
Integer page = Integer.valueOf(params.get("page").toString());
|
||||||
|
LambdaQueryWrapper<CourseEntity> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.select(CourseEntity::getId,CourseEntity::getTitle);
|
||||||
|
wrapper.like(CourseEntity::getTitle,params.get("title"));
|
||||||
|
wrapper.orderByDesc(CourseEntity::getId);
|
||||||
|
Page<CourseEntity> courses = courseService.page(new Page<>(page, limit), wrapper);
|
||||||
|
return R.ok().put("courses",courses);
|
||||||
}
|
}
|
||||||
|
|
||||||
//付款时优惠卷列表
|
//付款时优惠卷列表
|
||||||
@@ -175,4 +196,42 @@ public class CouponController {
|
|||||||
return R.ok().put("couponHistoryList",couponHistoryList);
|
return R.ok().put("couponHistoryList",couponHistoryList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//购买商品绑定优惠卷列表
|
||||||
|
@RequestMapping("/couponToProductList")
|
||||||
|
public R couponToShopproductList(@RequestBody Map<String,Object> params){
|
||||||
|
Integer limit = Integer.valueOf(params.get("limit").toString());
|
||||||
|
Integer page = Integer.valueOf(params.get("page").toString());
|
||||||
|
LambdaQueryWrapper<CouponToProduct> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(CouponToProduct::getProductId,params.get("productId"));
|
||||||
|
wrapper.orderByDesc(CouponToProduct::getId);
|
||||||
|
Page<CouponToProduct> couponToShopproductPage = couponToProductService.page(new Page<>(page, limit), wrapper);
|
||||||
|
for (CouponToProduct couponToProduct : couponToShopproductPage.getRecords()) {
|
||||||
|
couponToProduct.setCouponEntity(couponService.getById(couponToProduct.getCouponId()));
|
||||||
|
couponToProduct.setShopProduct(shopProductService.getById(couponToProduct.getShopProduct()));
|
||||||
|
}
|
||||||
|
return R.ok().put("couponToShopproductPage",couponToShopproductPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
//商品绑定优惠卷
|
||||||
|
@RequestMapping("/setCouponToProduct")
|
||||||
|
public R setCouponToProduct(@RequestBody CouponToProduct couponToProduct){
|
||||||
|
CouponToProduct c = couponToProductService.getOne(new LambdaQueryWrapper<CouponToProduct>()
|
||||||
|
.eq(CouponToProduct::getCouponId, couponToProduct.getCouponId())
|
||||||
|
.eq(CouponToProduct::getProductId, couponToProduct.getProductId()));
|
||||||
|
if (c == null){
|
||||||
|
couponToProductService.save(couponToProduct);
|
||||||
|
return R.ok();
|
||||||
|
}else {
|
||||||
|
return R.error("已存在");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//解绑商品优惠卷
|
||||||
|
@RequestMapping("/unbindCouponToProduct")
|
||||||
|
public R unbindCouponToProduct(@RequestBody Map<String,Object> params){
|
||||||
|
couponToProductService.removeById(params.get("id").toString());
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,222 @@
|
|||||||
|
package com.peanut.modules.common.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||||
|
import com.peanut.common.utils.R;
|
||||||
|
import com.peanut.common.utils.ShiroUtils;
|
||||||
|
import com.peanut.config.Constants;
|
||||||
|
import com.peanut.config.DelayQueueConfig;
|
||||||
|
import com.peanut.modules.book.service.TransactionDetailsService;
|
||||||
|
import com.peanut.modules.common.entity.*;
|
||||||
|
import com.peanut.modules.common.service.BuyOrderService;
|
||||||
|
import com.peanut.modules.common.service.MyUserService;
|
||||||
|
import com.peanut.modules.master.service.ShopProductService;
|
||||||
|
import com.peanut.modules.master.service.UserCourseBuyService;
|
||||||
|
import com.peanut.modules.pay.weChatPay.dto.WechatPaymentInfo;
|
||||||
|
import com.peanut.modules.pay.weChatPay.service.WxpayService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.springframework.amqp.core.MessagePostProcessor;
|
||||||
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController("commonCourseRelearn")
|
||||||
|
@RequestMapping("common/courseRelearn")
|
||||||
|
public class CourseRelearnController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserCourseBuyService userCourseBuyService;
|
||||||
|
@Autowired
|
||||||
|
private ShopProductService shopProductService;
|
||||||
|
@Autowired
|
||||||
|
private BuyOrderService buyOrderService;
|
||||||
|
@Autowired
|
||||||
|
private MyUserService userService;
|
||||||
|
@Autowired
|
||||||
|
private WxpayService wxpayService;
|
||||||
|
@Autowired
|
||||||
|
private TransactionDetailsService transactionDetailsService;
|
||||||
|
@Autowired
|
||||||
|
private RabbitTemplate rabbitTemplate;
|
||||||
|
|
||||||
|
//复读订单列表
|
||||||
|
@RequestMapping("/orderListRelearn")
|
||||||
|
public R orderListRelearn(@RequestBody Map<String,Object> params) {
|
||||||
|
MPJLambdaWrapper<BuyOrder> wrapper = new MPJLambdaWrapper<>();
|
||||||
|
wrapper.selectAll(BuyOrder.class);
|
||||||
|
wrapper.leftJoin(MyUserEntity.class, MyUserEntity::getId,BuyOrder::getUserId);
|
||||||
|
wrapper.eq(BuyOrder::getOrderType,"relearn");
|
||||||
|
if (StringUtils.isNotEmpty(params.get("orderSn").toString())) {
|
||||||
|
wrapper.eq(BuyOrder::getOrderSn,params.get("orderSn"));
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotEmpty(params.get("userInfo").toString())) {
|
||||||
|
wrapper.and(t->t.like(MyUserEntity::getName,params.get("userInfo")).or().like(MyUserEntity::getNickname,params.get("userInfo"))
|
||||||
|
.or().like(MyUserEntity::getTel,params.get("userInfo")).or().like(MyUserEntity::getEmail,params.get("userInfo")));
|
||||||
|
}
|
||||||
|
wrapper.orderByDesc(BuyOrder::getOrderId);
|
||||||
|
Page<BuyOrder> buyOrderPage = buyOrderService.page(new Page<BuyOrder>(
|
||||||
|
Long.parseLong(params.get("page").toString()), Long.parseLong(params.get("limit").toString())), wrapper);
|
||||||
|
for (BuyOrder buyOrder : buyOrderPage.getRecords()){
|
||||||
|
buyOrder.setUser(userService.getById(buyOrder.getUserId()));
|
||||||
|
}
|
||||||
|
return R.ok().put("buyOrderPage",buyOrderPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
//课程目录是否可复读(已购买并过期)
|
||||||
|
@RequestMapping("/courseCatalogueCanRelearn")
|
||||||
|
public R courseCatalogueCanRelearn(@RequestBody Map<String,Object> params){
|
||||||
|
boolean flag = false;
|
||||||
|
List<UserCourseBuyEntity> list = userCourseBuyService.list(new MPJLambdaWrapper<UserCourseBuyEntity>()
|
||||||
|
.disableLogicDel()//查询出已删除数据
|
||||||
|
.eq(UserCourseBuyEntity::getUserId, ShiroUtils.getUId())
|
||||||
|
.eq(UserCourseBuyEntity::getCatalogueId,params.get("courseCatalogueId")));
|
||||||
|
if (list.size() > 0) {
|
||||||
|
flag = true;
|
||||||
|
for (UserCourseBuyEntity userCourseBuyEntity : list) {
|
||||||
|
if (userCourseBuyEntity.getDelFlag()==0) {
|
||||||
|
flag = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return R.ok().put("canRelearn",flag);
|
||||||
|
}
|
||||||
|
|
||||||
|
//课程目录复读列表
|
||||||
|
@RequestMapping("/relearnShopProductList")
|
||||||
|
public R relearnShopProductList(@RequestBody Map<String,Object> params) {
|
||||||
|
MPJLambdaWrapper<ShopProduct> wrapper = new MPJLambdaWrapper<>();
|
||||||
|
wrapper.leftJoin(ShopProductCourseEntity.class,ShopProductCourseEntity::getProductId,ShopProduct::getProductId);
|
||||||
|
wrapper.selectAll(ShopProduct.class);
|
||||||
|
wrapper.eq(ShopProductCourseEntity::getCatalogueId,params.get("catalogueId"));
|
||||||
|
wrapper.eq(ShopProductCourseEntity::getDays,365);
|
||||||
|
ShopProduct shopProduct = shopProductService.getOne(wrapper);
|
||||||
|
if (shopProduct == null) {
|
||||||
|
return R.error("未找到一年期商品");
|
||||||
|
}else {
|
||||||
|
ShopProduct sp1 = new ShopProduct();
|
||||||
|
sp1.setProductId(shopProduct.getProductId());
|
||||||
|
sp1.setProductName(shopProduct.getProductName().replace("一年","一月"));
|
||||||
|
sp1.setProductImages(shopProduct.getProductImages());
|
||||||
|
BigDecimal sp1Price = shopProduct.getPrice().divide(new BigDecimal(12),0, RoundingMode.DOWN);
|
||||||
|
sp1.setPrice(sp1Price);
|
||||||
|
|
||||||
|
ShopProduct sp2 = new ShopProduct();
|
||||||
|
sp2.setProductId(shopProduct.getProductId());
|
||||||
|
sp2.setProductName(shopProduct.getProductName().replace("一年","三月"));
|
||||||
|
sp2.setProductImages(shopProduct.getProductImages());
|
||||||
|
BigDecimal sp2Price = shopProduct.getPrice().divide(new BigDecimal(4),0, RoundingMode.DOWN);
|
||||||
|
sp2Price = sp2Price.multiply(new BigDecimal(0.6));
|
||||||
|
sp2Price = sp2Price.setScale(0, RoundingMode.DOWN);
|
||||||
|
sp2.setPrice(sp2Price);
|
||||||
|
|
||||||
|
List<ShopProduct> res = new ArrayList<>();
|
||||||
|
res.add(sp1);
|
||||||
|
res.add(sp2);
|
||||||
|
return R.ok().put("productList",res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/relearnSave")
|
||||||
|
@Transactional
|
||||||
|
public R relearnSave(@RequestBody BuyOrder buyOrder){
|
||||||
|
int uid = ShiroUtils.getUId();
|
||||||
|
buyOrder.setOrderStatus("0");
|
||||||
|
buyOrder.setOrderType("relearn");
|
||||||
|
String timeId = IdWorker.getTimeId().substring(0, 32);
|
||||||
|
buyOrder.setOrderSn(timeId);
|
||||||
|
buyOrder.setUserId(uid);
|
||||||
|
buyOrderService.save(buyOrder);
|
||||||
|
BigDecimal totalPrice = buyOrder.getRealMoney();
|
||||||
|
//虚拟币支付
|
||||||
|
if (Constants.PAYMENT_METHOD_VIRTUAL.equals(buyOrder.getPaymentMethod())) {
|
||||||
|
buyOrder.setOrderStatus(Constants.ORDER_STATUS_TO_BE_SHIPPED);
|
||||||
|
MyUserEntity user = userService.getById(buyOrder.getUserId());
|
||||||
|
if (usePeanutCoin(user, totalPrice)) {
|
||||||
|
buyOrder.setSuccessTime(new Date());
|
||||||
|
// 更新订单状态
|
||||||
|
buyOrderService.updateOrderStatus(user.getId(), buyOrder.getOrderSn(), "2");
|
||||||
|
//记录用户虚拟币消费
|
||||||
|
if(totalPrice.compareTo(BigDecimal.ZERO)>0){
|
||||||
|
recordTransaction(buyOrder, user, totalPrice);
|
||||||
|
}
|
||||||
|
//插入复读记录
|
||||||
|
userCourseBuyService.addUserCourseBuyRelearn(buyOrder,"虚拟币购买:"+buyOrder.getOrderSn());
|
||||||
|
} else {
|
||||||
|
return R.error(500, "余额不足!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//微信支付预付款订单
|
||||||
|
if(Constants.PAYMENT_METHOD_WECHAT_PAY.equals(buyOrder.getPaymentMethod())){
|
||||||
|
BuyOrder buyOrderEntity = buyOrderService.getBaseMapper().selectOne(new LambdaQueryWrapper<BuyOrder>()
|
||||||
|
.eq(BuyOrder::getOrderSn, timeId));
|
||||||
|
WechatPaymentInfo paymentInfo = new WechatPaymentInfo();
|
||||||
|
paymentInfo.setOrderSn(buyOrderEntity.getOrderSn());
|
||||||
|
paymentInfo.setBuyOrderId(buyOrder.getOrderId());
|
||||||
|
paymentInfo.setTotalAmount(buyOrderEntity.getRealMoney());
|
||||||
|
if (buyOrder.getCome()==2){
|
||||||
|
paymentInfo.setAppName("wumen");
|
||||||
|
} else if (buyOrder.getCome()==1) {
|
||||||
|
paymentInfo.setAppName("zmzm");
|
||||||
|
}else {
|
||||||
|
paymentInfo.setAppName(buyOrder.getAppName());
|
||||||
|
}
|
||||||
|
wxpayService.prepay(paymentInfo);
|
||||||
|
}
|
||||||
|
rabbitTemplate.convertAndSend(
|
||||||
|
DelayQueueConfig.ORDER_TO_BE_PAY_EXCHANGE,
|
||||||
|
DelayQueueConfig.ORDER_TO_BE_PAY_ROUTING_KEY,
|
||||||
|
buyOrder.getOrderId(),
|
||||||
|
messagePostProcessor()
|
||||||
|
);
|
||||||
|
return R.ok().put("orderSn", timeId).put("money", totalPrice);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean usePeanutCoin(MyUserEntity user, BigDecimal totalPrice) {
|
||||||
|
if (user.getPeanutCoin().compareTo(totalPrice) >= 0) {
|
||||||
|
if(totalPrice.compareTo(BigDecimal.ZERO)==0){//纯积分支付,虚拟币不用支付
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
user.setPeanutCoin(user.getPeanutCoin().subtract(totalPrice));
|
||||||
|
userService.updateById(user);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void recordTransaction(BuyOrder buyOrder, MyUserEntity user, BigDecimal totalPrice) {
|
||||||
|
TransactionDetailsEntity transactionDetailsEntity = new TransactionDetailsEntity();
|
||||||
|
transactionDetailsEntity.setRemark("订单编号为 - " + buyOrder.getOrderSn());
|
||||||
|
transactionDetailsEntity.setUserId(user.getId());
|
||||||
|
transactionDetailsEntity.setUserName(user.getNickname());
|
||||||
|
transactionDetailsEntity.setChangeAmount(totalPrice.negate());
|
||||||
|
transactionDetailsEntity.setUserBalance(user.getPeanutCoin());
|
||||||
|
transactionDetailsEntity.setTel(user.getTel());
|
||||||
|
transactionDetailsEntity.setOrderType("购买商品");
|
||||||
|
transactionDetailsService.save(transactionDetailsEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
private MessagePostProcessor messagePostProcessor() {
|
||||||
|
return message -> {
|
||||||
|
//设置有效期30分钟
|
||||||
|
message.getMessageProperties().setExpiration(String.valueOf(30 * 60 * 1000));
|
||||||
|
return message;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
package com.peanut.modules.common.controller;
|
||||||
|
|
||||||
|
import com.peanut.common.utils.R;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 心身医学自评表
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestController("commonSelfEvaluationForm")
|
||||||
|
@RequestMapping("common/selfEvaluationForm")
|
||||||
|
public class SelfEvaluationFormController {
|
||||||
|
|
||||||
|
/*
|
||||||
|
中国大陆用户
|
||||||
|
SDS的评定结果以标准分来定:
|
||||||
|
标准分小于52分为无抑郁;标准分大于等于52分且小于62分为轻微至轻度抑郁;标准分大于等于62分且小于72分为中至重度抑郁;标准分大于等于72分为重度抑郁。
|
||||||
|
|
||||||
|
其它国家和地区
|
||||||
|
标准分小于50分为无抑郁;标准分大于等于50分且小于60分为轻微至轻度抑郁;标准分大于等于60分且小于70分为中至重度抑郁;标准分大于等于70分为重度抑郁。
|
||||||
|
|
||||||
|
计分规则:
|
||||||
|
SDS评定采用1—4制记分,评分时间为过去一周内。
|
||||||
|
正向题,依次评为粗分1、2、3、4分 (1 3 4 7 8 9 10 13 15 19)
|
||||||
|
反向题,依次评为粗分4、3、2、1分 (2 5 6 11 12 14 16 17 18 20)
|
||||||
|
20项相加得到原始分,原始分分乘以1.25以后取整,得到标准分。
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
//打分
|
||||||
|
@RequestMapping("/calculationForm")
|
||||||
|
public R calculationForm(@RequestBody Map<String,Object> params) {
|
||||||
|
List<Integer> list = (List) params.get("resList");
|
||||||
|
int total = 0;
|
||||||
|
for (int i=0;i < list.size(); i++) {
|
||||||
|
//反向题
|
||||||
|
if (i==1||i==4||i==5||i==10||i==11||i==13||i==15||i==16||i==17||i==19){
|
||||||
|
if (list.get(i)==1){
|
||||||
|
total += 4;
|
||||||
|
}else if(list.get(i)==2){
|
||||||
|
total += 3;
|
||||||
|
}else if (list.get(i) == 3) {
|
||||||
|
total += 2;
|
||||||
|
}else {
|
||||||
|
total += 1;
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
total += list.get(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
total = (int)(total*1.25);
|
||||||
|
String country = params.get("country").toString();
|
||||||
|
if ("CN".equals(country)){
|
||||||
|
total = total - 2;
|
||||||
|
}
|
||||||
|
String res ="无抑郁";
|
||||||
|
if (total>=70){
|
||||||
|
res ="重度抑郁";
|
||||||
|
}else if (total >= 60) {
|
||||||
|
res ="中至重度抑郁";
|
||||||
|
}else if (total >= 50) {
|
||||||
|
res ="轻微至轻度抑郁";
|
||||||
|
}
|
||||||
|
return R.ok().put("res",res);
|
||||||
|
}
|
||||||
|
|
||||||
|
//自评表题目列表
|
||||||
|
@RequestMapping("/getSelfEvaluationFormList")
|
||||||
|
public R getSelfEvaluationFormList() {
|
||||||
|
List list = new ArrayList();
|
||||||
|
list.add("我觉得闷闷不乐,情绪低沉");
|
||||||
|
list.add("我觉得一天之中早晨最好");
|
||||||
|
list.add("我一阵阵哭出来或觉得想哭");
|
||||||
|
list.add("我晚上睡眠不好");
|
||||||
|
list.add("我吃得跟平常一样多");
|
||||||
|
list.add("我与异性密切接触时和以往一样感到愉快");
|
||||||
|
list.add("我发觉我的体重下降");
|
||||||
|
list.add("我有便秘的苦恼");
|
||||||
|
list.add("我心跳比平时快");
|
||||||
|
list.add("我无缘无故地感到疲乏");
|
||||||
|
list.add("我的头脑跟平常一样清楚");
|
||||||
|
list.add("觉得经常做的事情并没有困难");
|
||||||
|
list.add("我觉得不安而平静不下来");
|
||||||
|
list.add("我对将来抱有希望");
|
||||||
|
list.add("我比平常容易生气激动");
|
||||||
|
list.add("我觉得作出决定是容易的");
|
||||||
|
list.add("我觉得自己是个有用的人,有人需要我");
|
||||||
|
list.add("我的生活过得很有意思");
|
||||||
|
list.add("我认为如果我死了别人会生活得好些");
|
||||||
|
list.add("我平常感兴趣的事我仍然照样感兴趣");
|
||||||
|
return R.ok().put("list",list);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.peanut.modules.common.dao;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.peanut.modules.common.entity.CouponToProduct;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface CouponToProductDao extends BaseMapper<CouponToProduct> {
|
||||||
|
}
|
||||||
@@ -49,6 +49,10 @@ public class CouponHistory {
|
|||||||
@TableLogic
|
@TableLogic
|
||||||
private Integer delFlag;
|
private Integer delFlag;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private int canUse;
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String canUseReason;
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private CouponEntity couponEntity;
|
private CouponEntity couponEntity;
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.peanut.modules.common.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@TableName("coupon_to_product")
|
||||||
|
public class CouponToProduct {
|
||||||
|
|
||||||
|
@TableId
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
private Integer couponId;
|
||||||
|
|
||||||
|
private Integer productId;
|
||||||
|
|
||||||
|
@TableLogic
|
||||||
|
private Integer delFlag;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private CouponEntity couponEntity;
|
||||||
|
@TableField(exist = false)
|
||||||
|
private ShopProduct shopProduct;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,12 +4,13 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
|||||||
import com.peanut.common.utils.R;
|
import com.peanut.common.utils.R;
|
||||||
import com.peanut.modules.common.entity.CouponEntity;
|
import com.peanut.modules.common.entity.CouponEntity;
|
||||||
import com.peanut.modules.common.entity.CouponHistory;
|
import com.peanut.modules.common.entity.CouponHistory;
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public interface CouponService extends IService<CouponEntity> {
|
public interface CouponService extends IService<CouponEntity> {
|
||||||
|
|
||||||
CouponEntity getByIdSetRange(int id);
|
CouponEntity getByIdSetRange(int id);
|
||||||
@@ -20,6 +21,13 @@ public interface CouponService extends IService<CouponEntity> {
|
|||||||
|
|
||||||
List<CouponHistory> getCouponListPayment(Map<String,Object> params);
|
List<CouponHistory> getCouponListPayment(Map<String,Object> params);
|
||||||
|
|
||||||
Set<Integer> getShopProductByCoupon(int couponId);
|
//使用优惠卷
|
||||||
|
void useCouponAmount(CouponHistory couponHistory);
|
||||||
|
|
||||||
|
//回滚优惠卷
|
||||||
|
void rollbackCoupon(int couponHistoryId);
|
||||||
|
|
||||||
|
//通过商品发放优惠卷
|
||||||
|
void insertCouponHistoryByProductId(List<Integer> productIds);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.peanut.modules.common.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.peanut.modules.common.entity.CouponToProduct;
|
||||||
|
|
||||||
|
public interface CouponToProductService extends IService<CouponToProduct> {
|
||||||
|
}
|
||||||
@@ -3,7 +3,6 @@ package com.peanut.modules.common.service.impl;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||||
import com.peanut.common.utils.DateUtil;
|
|
||||||
import com.peanut.common.utils.DateUtils;
|
import com.peanut.common.utils.DateUtils;
|
||||||
import com.peanut.common.utils.R;
|
import com.peanut.common.utils.R;
|
||||||
import com.peanut.common.utils.ShiroUtils;
|
import com.peanut.common.utils.ShiroUtils;
|
||||||
@@ -11,14 +10,13 @@ import com.peanut.config.DelayQueueConfig;
|
|||||||
import com.peanut.modules.common.dao.*;
|
import com.peanut.modules.common.dao.*;
|
||||||
import com.peanut.modules.common.entity.*;
|
import com.peanut.modules.common.entity.*;
|
||||||
import com.peanut.modules.common.service.CouponService;
|
import com.peanut.modules.common.service.CouponService;
|
||||||
import io.swagger.models.auth.In;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.springframework.amqp.core.MessagePostProcessor;
|
import org.springframework.amqp.core.MessagePostProcessor;
|
||||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -36,9 +34,11 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
|
|||||||
@Autowired
|
@Autowired
|
||||||
private RabbitTemplate rabbitTemplate;
|
private RabbitTemplate rabbitTemplate;
|
||||||
@Autowired
|
@Autowired
|
||||||
private ShopProductDao shopProductDao;
|
|
||||||
@Autowired
|
|
||||||
private ShopProductCourseDao shopProductCourseDao;
|
private ShopProductCourseDao shopProductCourseDao;
|
||||||
|
@Autowired
|
||||||
|
private CouponToProductDao couponToProductDao;
|
||||||
|
@Autowired
|
||||||
|
private ShopProductDao shopProductDao;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CouponEntity getByIdSetRange(int id) {
|
public CouponEntity getByIdSetRange(int id) {
|
||||||
@@ -95,19 +95,21 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
|
|||||||
couponHistory.setEndTime(couponEntity.getExpireTime());
|
couponHistory.setEndTime(couponEntity.getExpireTime());
|
||||||
}
|
}
|
||||||
couponHistoryDao.insert(couponHistory);
|
couponHistoryDao.insert(couponHistory);
|
||||||
//发放完优惠卷设置过期
|
if (couponEntity.getEffectType()!=0){
|
||||||
rabbitTemplate.convertAndSend(
|
//发放完优惠卷设置过期
|
||||||
DelayQueueConfig.COMMON_EXCHANGE,
|
rabbitTemplate.convertAndSend(
|
||||||
DelayQueueConfig.COMMON_ROUTING_KEY,
|
DelayQueueConfig.COMMON_EXCHANGE,
|
||||||
"couponExpire"+","+couponHistory.getId(),
|
DelayQueueConfig.COMMON_ROUTING_KEY,
|
||||||
messagePostProcessor(couponHistory.getEndTime().getTime()-new Date().getTime())
|
"couponExpire"+","+couponHistory.getId(),
|
||||||
);
|
messagePostProcessor(couponHistory.getEndTime().getTime()-new Date().getTime())
|
||||||
|
);
|
||||||
|
}
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}else {
|
}else {
|
||||||
return R.error("每人限领"+couponEntity.getLimitedCollar()+"张");
|
return R.error("每人限领"+couponEntity.getLimitedCollar()+"张");
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
return R.error("优惠卷已放完");
|
return R.error("优惠券已放完");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private MessagePostProcessor messagePostProcessor(long date) {
|
private MessagePostProcessor messagePostProcessor(long date) {
|
||||||
@@ -125,16 +127,33 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
|
|||||||
.eq(CouponHistory::getStatus,0));
|
.eq(CouponHistory::getStatus,0));
|
||||||
if (couponHistoryList.size() > 0) {
|
if (couponHistoryList.size() > 0) {
|
||||||
for (CouponHistory couponHistory : couponHistoryList) {
|
for (CouponHistory couponHistory : couponHistoryList) {
|
||||||
if (couponHistory.getEffectType()==0){
|
CouponEntity couponEntity = this.baseMapper.selectById(couponHistory.getCouponId());
|
||||||
res.add(couponHistory);
|
if (couponEntity != null) {
|
||||||
}else {
|
//校验优惠卷使用时间
|
||||||
List<ShopProduct> shopProductList = shopProductDao.selectList(new MPJLambdaWrapper<ShopProduct>()
|
couponHistory.setCanUse(1);
|
||||||
.leftJoin(BuyOrderProduct.class,BuyOrderProduct::getProductId,ShopProduct::getProductId)
|
couponHistory.setCanUseReason("");
|
||||||
.eq(BuyOrderProduct::getOrderId,params.get("orderId").toString()));
|
if (couponHistory.getEffectType()!=0){
|
||||||
for (ShopProduct shopProduct : shopProductList) {
|
if (couponHistory.getStartTime().getTime() < new Date().getTime() &&
|
||||||
Set<Integer> set = getShopProductByCoupon(couponHistory.getCouponId());
|
couponHistory.getEndTime().getTime() > new Date().getTime()) {
|
||||||
if(!set.add(shopProduct.getProductId())){
|
}else {
|
||||||
res.add(couponHistory);
|
couponHistory.setCanUse(0);
|
||||||
|
couponHistory.setCanUseReason("优惠券使用时间未到");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
couponHistory.setCouponEntity(couponEntity);
|
||||||
|
if (couponEntity.getCouponRange()==0){
|
||||||
|
//无限制
|
||||||
|
res.add(couponHistory);
|
||||||
|
}else {
|
||||||
|
String shopProductIds = params.get("shopProductIds").toString();
|
||||||
|
String[] ids = shopProductIds.split(",");
|
||||||
|
for (String shopProductId : ids) {
|
||||||
|
//通过优惠卷获取商品
|
||||||
|
Set<Integer> set = getShopProductByCoupon(couponEntity);
|
||||||
|
//比对用户优惠卷是否有此商品
|
||||||
|
if(!set.add(Integer.parseInt(shopProductId))){
|
||||||
|
res.add(couponHistory);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -143,32 +162,30 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public Set<Integer> getShopProductByCoupon(CouponEntity couponEntity) {
|
||||||
public Set<Integer> getShopProductByCoupon(int couponId) {
|
|
||||||
Set<Integer> set = new HashSet<>();
|
Set<Integer> set = new HashSet<>();
|
||||||
CouponEntity couponEntity = couponDao.selectById(couponId);
|
String[] strs = couponEntity.getRangeInfo().split(",");
|
||||||
if (couponEntity!=null){
|
if (couponEntity.getCouponRange()==1) {
|
||||||
String[] strs = couponEntity.getRangeInfo().split(",");
|
//1课程卷
|
||||||
if (couponEntity.getCouponRange()==1) {
|
for (String courseId : strs) {
|
||||||
for (String courseId : strs) {
|
List<ShopProductCourseEntity> shopProductCourseList = shopProductCourseDao.selectList(new LambdaQueryWrapper<ShopProductCourseEntity>()
|
||||||
List<ShopProductCourseEntity> shopProductCourseList = shopProductCourseDao.selectList(new LambdaQueryWrapper<ShopProductCourseEntity>()
|
.eq(ShopProductCourseEntity::getCourseId,courseId));
|
||||||
.eq(ShopProductCourseEntity::getCourseId,courseId));
|
for (ShopProductCourseEntity shopProductCourseEntity : shopProductCourseList) {
|
||||||
for (ShopProductCourseEntity shopProductCourseEntity : shopProductCourseList) {
|
set.add(shopProductCourseEntity.getProductId());
|
||||||
set.add(shopProductCourseEntity.getProductId());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}else if (couponEntity.getCouponRange()==2) {
|
}
|
||||||
for (String courseMedical : strs) {
|
}else if (couponEntity.getCouponRange()==2) {
|
||||||
MPJLambdaWrapper<ShopProductCourseEntity> wrapper = new MPJLambdaWrapper<>();
|
//2课程品类卷
|
||||||
wrapper.leftJoin(CourseToMedicine.class,CourseToMedicine::getCourseId,ShopProductCourseEntity::getCourseId);
|
for (String courseMedical : strs) {
|
||||||
List l = new ArrayList();
|
MPJLambdaWrapper<ShopProductCourseEntity> wrapper = new MPJLambdaWrapper<>();
|
||||||
getCourseMedicalIds(Integer.parseInt(courseMedical),l);
|
wrapper.leftJoin(CourseToMedicine.class,CourseToMedicine::getCourseId,ShopProductCourseEntity::getCourseId);
|
||||||
wrapper.in(CourseToMedicine::getMedicalId,l);
|
List l = new ArrayList();
|
||||||
wrapper.selectAll(ShopProductCourseEntity.class);
|
getCourseMedicalIds(Integer.parseInt(courseMedical),l);
|
||||||
List<ShopProductCourseEntity> shopProductCourseList = shopProductCourseDao.selectList(wrapper);
|
wrapper.in(CourseToMedicine::getMedicalId,l);
|
||||||
for (ShopProductCourseEntity shopProductCourseEntity : shopProductCourseList) {
|
wrapper.selectAll(ShopProductCourseEntity.class);
|
||||||
set.add(shopProductCourseEntity.getProductId());
|
List<ShopProductCourseEntity> shopProductCourseList = shopProductCourseDao.selectList(wrapper);
|
||||||
}
|
for (ShopProductCourseEntity shopProductCourseEntity : shopProductCourseList) {
|
||||||
|
set.add(shopProductCourseEntity.getProductId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -188,5 +205,36 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void useCouponAmount(CouponHistory couponHistory) {
|
||||||
|
couponHistory.setStatus(1);//使用状态 0 未使用 1 已使用 2 已过期
|
||||||
|
couponHistory.setUseTime(new Date());
|
||||||
|
couponHistoryDao.updateById(couponHistory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void rollbackCoupon(int couponHistoryId) {
|
||||||
|
CouponHistory couponHistory = couponHistoryDao.selectById(couponHistoryId);
|
||||||
|
if (couponHistory != null) {
|
||||||
|
couponHistory.setOrderId(0);
|
||||||
|
couponHistory.setStatus(0);
|
||||||
|
couponHistory.setUseTime(null);
|
||||||
|
couponHistoryDao.updateById(couponHistory);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void insertCouponHistoryByProductId(List<Integer> productIds) {
|
||||||
|
List<CouponToProduct> couponToProductList = couponToProductDao.selectList(new LambdaQueryWrapper<CouponToProduct>()
|
||||||
|
.in(CouponToProduct::getProductId,productIds));
|
||||||
|
for (CouponToProduct couponToProduct : couponToProductList) {
|
||||||
|
ShopProduct shopProduct = shopProductDao.selectById(couponToProduct.getProductId());
|
||||||
|
insertCouponHistory(couponToProduct.getCouponId(),
|
||||||
|
ShiroUtils.getUId(), 1,"购买商品"+shopProduct.getProductName()+"赠送");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.peanut.modules.common.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.peanut.modules.common.dao.CouponToProductDao;
|
||||||
|
import com.peanut.modules.common.entity.CouponToProduct;
|
||||||
|
import com.peanut.modules.common.service.CouponToProductService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service("commonCouponToProductService")
|
||||||
|
public class CouponToProductServiceImpl extends ServiceImpl<CouponToProductDao, CouponToProduct> implements CouponToProductService {
|
||||||
|
}
|
||||||
@@ -1,7 +1,11 @@
|
|||||||
package com.peanut.modules.master.service;
|
package com.peanut.modules.master.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.peanut.modules.common.entity.BuyOrder;
|
||||||
import com.peanut.modules.common.entity.UserCourseBuyEntity;
|
import com.peanut.modules.common.entity.UserCourseBuyEntity;
|
||||||
|
|
||||||
public interface UserCourseBuyService extends IService<UserCourseBuyEntity> {
|
public interface UserCourseBuyService extends IService<UserCourseBuyEntity> {
|
||||||
|
|
||||||
|
void addUserCourseBuyRelearn(BuyOrder buyOrder,String come);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,39 @@
|
|||||||
package com.peanut.modules.master.service.impl;
|
package com.peanut.modules.master.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.peanut.modules.common.dao.ShopProductCourseDao;
|
||||||
import com.peanut.modules.common.dao.UserCourseBuyDao;
|
import com.peanut.modules.common.dao.UserCourseBuyDao;
|
||||||
|
import com.peanut.modules.common.entity.BuyOrder;
|
||||||
|
import com.peanut.modules.common.entity.ShopProductCourseEntity;
|
||||||
import com.peanut.modules.common.entity.UserCourseBuyEntity;
|
import com.peanut.modules.common.entity.UserCourseBuyEntity;
|
||||||
import com.peanut.modules.master.service.UserCourseBuyService;
|
import com.peanut.modules.master.service.UserCourseBuyService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service("masterUserCourseBuyService")
|
@Service("masterUserCourseBuyService")
|
||||||
public class UserCourseBuyServiceImpl extends ServiceImpl<UserCourseBuyDao, UserCourseBuyEntity> implements UserCourseBuyService {
|
public class UserCourseBuyServiceImpl extends ServiceImpl<UserCourseBuyDao, UserCourseBuyEntity> implements UserCourseBuyService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public ShopProductCourseDao shopProductCourseDao;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addUserCourseBuyRelearn(BuyOrder buyOrder,String come) {
|
||||||
|
String[] info = buyOrder.getRemark().split(",");
|
||||||
|
ShopProductCourseEntity spc = shopProductCourseDao.selectOne(new LambdaQueryWrapper<ShopProductCourseEntity>()
|
||||||
|
.eq(ShopProductCourseEntity::getProductId,info[0]));
|
||||||
|
UserCourseBuyEntity userCourseBuyEntity = new UserCourseBuyEntity();
|
||||||
|
userCourseBuyEntity.setUserId(buyOrder.getUserId());
|
||||||
|
userCourseBuyEntity.setCourseId(spc.getCourseId());
|
||||||
|
userCourseBuyEntity.setCatalogueId(spc.getCatalogueId());
|
||||||
|
if (info[1].contains("一月")){
|
||||||
|
userCourseBuyEntity.setDays(30);
|
||||||
|
}else if (info[1].contains("三月")){
|
||||||
|
userCourseBuyEntity.setDays(90);
|
||||||
|
}
|
||||||
|
userCourseBuyEntity.setCome("复读-"+come);
|
||||||
|
this.baseMapper.insert(userCourseBuyEntity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -273,9 +273,10 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, CourseEntity> impl
|
|||||||
MPJLambdaWrapper<CourseEntity> wrapper = new MPJLambdaWrapper<>();
|
MPJLambdaWrapper<CourseEntity> wrapper = new MPJLambdaWrapper<>();
|
||||||
wrapper.distinct();
|
wrapper.distinct();
|
||||||
wrapper.leftJoin(CourseCatalogueEntity.class,CourseCatalogueEntity::getCourseId,CourseEntity::getId);
|
wrapper.leftJoin(CourseCatalogueEntity.class,CourseCatalogueEntity::getCourseId,CourseEntity::getId);
|
||||||
//关掉本次查询del_flg = 0的条件,查询过期课程
|
wrapper.rightJoin(UserCourseBuyEntity.class,UserCourseBuyEntity::getCatalogueId,CourseCatalogueEntity::getId);
|
||||||
wrapper.disableSubLogicDel().rightJoin(UserCourseBuyEntity.class,UserCourseBuyEntity::getCatalogueId,CourseCatalogueEntity::getId);
|
|
||||||
wrapper.rightJoin(CourseToMedicine.class,CourseToMedicine::getCourseId,CourseEntity::getId);
|
wrapper.rightJoin(CourseToMedicine.class,CourseToMedicine::getCourseId,CourseEntity::getId);
|
||||||
|
//关掉本次查询del_flg = 0的条件,查询过期课程
|
||||||
|
wrapper.disableSubLogicDel();
|
||||||
wrapper.eq(UserCourseBuyEntity::getUserId,param.get("userId"));
|
wrapper.eq(UserCourseBuyEntity::getUserId,param.get("userId"));
|
||||||
wrapper.eq(UserCourseBuyEntity::getDelFlag,-1);
|
wrapper.eq(UserCourseBuyEntity::getDelFlag,-1);
|
||||||
wrapper.selectAll(CourseEntity.class);
|
wrapper.selectAll(CourseEntity.class);
|
||||||
@@ -283,8 +284,18 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, CourseEntity> impl
|
|||||||
wrapper.selectAs(CourseCatalogueEntity::getTitle,"catalogueTitle");
|
wrapper.selectAs(CourseCatalogueEntity::getTitle,"catalogueTitle");
|
||||||
wrapper.orderByAsc(CourseEntity::getSort);
|
wrapper.orderByAsc(CourseEntity::getSort);
|
||||||
wrapper.orderByAsc(CourseCatalogueEntity::getSort);
|
wrapper.orderByAsc(CourseCatalogueEntity::getSort);
|
||||||
List courseEntities = this.getBaseMapper().selectMaps(wrapper);
|
List<Map<String,Object>> courseEntities = this.getBaseMapper().selectMaps(wrapper);
|
||||||
return courseEntities;
|
List<Map<String,Object>> res = new ArrayList<>();
|
||||||
|
//如果过期又开通,去除
|
||||||
|
for (Map<String,Object> c : courseEntities) {
|
||||||
|
UserCourseBuyEntity ucb = userCourseBuyDao.selectOne(new LambdaQueryWrapper<UserCourseBuyEntity>()
|
||||||
|
.eq(UserCourseBuyEntity::getUserId,param.get("userId"))
|
||||||
|
.eq(UserCourseBuyEntity::getCatalogueId,c.get("catalogueId")));
|
||||||
|
if (ucb == null) {
|
||||||
|
res.add(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
}else {
|
}else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ import com.peanut.modules.common.entity.BuyOrder;
|
|||||||
import com.peanut.modules.common.entity.BuyOrderProduct;
|
import com.peanut.modules.common.entity.BuyOrderProduct;
|
||||||
import com.peanut.modules.common.entity.ShopProduct;
|
import com.peanut.modules.common.entity.ShopProduct;
|
||||||
import com.peanut.modules.book.service.BuyOrderService;
|
import com.peanut.modules.book.service.BuyOrderService;
|
||||||
|
import com.peanut.modules.common.service.CouponService;
|
||||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,16 +29,22 @@ public class OrderCancelConsumer {
|
|||||||
BuyOrderProductDao buyOrderProductDao;
|
BuyOrderProductDao buyOrderProductDao;
|
||||||
@Autowired
|
@Autowired
|
||||||
ShopProductDao shopProductDao;
|
ShopProductDao shopProductDao;
|
||||||
|
@Autowired
|
||||||
|
CouponService couponService;
|
||||||
|
|
||||||
@RabbitListener(queues = DelayQueueConfig.ORDER_CANCEL_DEAD_LETTER_QUEUE)
|
@RabbitListener(queues = DelayQueueConfig.ORDER_CANCEL_DEAD_LETTER_QUEUE)
|
||||||
public void orderConsumer(String orderId) {
|
public void orderConsumer(String orderId) {
|
||||||
BuyOrder buyOrder = buyOrderService.getById(orderId);
|
BuyOrder buyOrder = buyOrderService.getById(orderId);
|
||||||
if(buyOrder == null){
|
if(buyOrder == null){
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(Constants.ORDER_STATUS_TO_BE_PAID.equals(buyOrder.getOrderStatus())){
|
if(Constants.ORDER_STATUS_TO_BE_PAID.equals(buyOrder.getOrderStatus())){
|
||||||
buyOrder.setOrderStatus(Constants.ORDER_STATUS_OUT_OF_TIME);
|
buyOrder.setOrderStatus(Constants.ORDER_STATUS_OUT_OF_TIME);
|
||||||
|
//回滚优惠卷
|
||||||
|
if (buyOrder.getCouponId()!=null&&buyOrder.getCouponId()!=0){
|
||||||
|
couponService.rollbackCoupon(buyOrder.getCouponId());
|
||||||
|
buyOrder.setCouponId(null);
|
||||||
|
}
|
||||||
//回滚库存
|
//回滚库存
|
||||||
LambdaQueryWrapper<BuyOrderProduct> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<BuyOrderProduct> wrapper = new LambdaQueryWrapper<>();
|
||||||
wrapper.eq(BuyOrderProduct::getOrderId,buyOrder.getOrderId());
|
wrapper.eq(BuyOrderProduct::getOrderId,buyOrder.getOrderId());
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ public class AppController {
|
|||||||
transactionDetailsEntity.setChangeAmount(new BigDecimal(money));
|
transactionDetailsEntity.setChangeAmount(new BigDecimal(money));
|
||||||
transactionDetailsEntity.setOrderType("充值");
|
transactionDetailsEntity.setOrderType("充值");
|
||||||
transactionDetailsEntity.setRelationId(order.getId());
|
transactionDetailsEntity.setRelationId(order.getId());
|
||||||
transactionDetailsEntity.setRemark("苹果充值:"+order.getTransactionId());
|
transactionDetailsEntity.setRemark("苹果充值:"+order.getOrderid());
|
||||||
MyUserEntity user = userService.getById(Integer.valueOf(customerid));
|
MyUserEntity user = userService.getById(Integer.valueOf(customerid));
|
||||||
BigDecimal peanutCoin = user.getPeanutCoin();
|
BigDecimal peanutCoin = user.getPeanutCoin();
|
||||||
transactionDetailsEntity.setUserBalance(peanutCoin);
|
transactionDetailsEntity.setUserBalance(peanutCoin);
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import com.peanut.common.utils.OrderUtils;
|
|||||||
import com.peanut.modules.common.dao.*;
|
import com.peanut.modules.common.dao.*;
|
||||||
import com.peanut.modules.book.service.*;
|
import com.peanut.modules.book.service.*;
|
||||||
import com.peanut.modules.common.entity.*;
|
import com.peanut.modules.common.entity.*;
|
||||||
|
import com.peanut.modules.common.service.CouponService;
|
||||||
|
import com.peanut.modules.master.service.UserCourseBuyService;
|
||||||
import com.peanut.modules.pay.alipay.config.AliPayConfig;
|
import com.peanut.modules.pay.alipay.config.AliPayConfig;
|
||||||
import com.peanut.modules.pay.alipay.config.AliPayUtil;
|
import com.peanut.modules.pay.alipay.config.AliPayUtil;
|
||||||
import com.peanut.modules.pay.alipay.dto.AlipayDTO;
|
import com.peanut.modules.pay.alipay.dto.AlipayDTO;
|
||||||
@@ -62,6 +64,8 @@ public class AliPayServiceImpl implements AliPayService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private UserCourseBuyDao userCourseBuyDao;
|
private UserCourseBuyDao userCourseBuyDao;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
private UserCourseBuyService userCourseBuyService;
|
||||||
|
@Autowired
|
||||||
private JfTransactionDetailsDao jfTransactionDetailsDao;
|
private JfTransactionDetailsDao jfTransactionDetailsDao;
|
||||||
@Autowired
|
@Autowired
|
||||||
private MyUserDao myUserDao;
|
private MyUserDao myUserDao;
|
||||||
@@ -69,6 +73,8 @@ public class AliPayServiceImpl implements AliPayService {
|
|||||||
private VipBuyConfigDao vipBuyConfigDao;
|
private VipBuyConfigDao vipBuyConfigDao;
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserVipDao userVipDao;
|
private UserVipDao userVipDao;
|
||||||
|
@Autowired
|
||||||
|
private CouponService couponService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String pay(AlipayDTO payDto) {
|
public String pay(AlipayDTO payDto) {
|
||||||
@@ -95,9 +101,6 @@ public class AliPayServiceImpl implements AliPayService {
|
|||||||
aliNotifyDto.setCustomerid(payDto.getCustomerId());
|
aliNotifyDto.setCustomerid(payDto.getCustomerId());
|
||||||
aliNotifyDto.setRelevanceoid(payDto.getRelevanceoid());
|
aliNotifyDto.setRelevanceoid(payDto.getRelevanceoid());
|
||||||
payZfbOrderService.save(aliNotifyDto);
|
payZfbOrderService.save(aliNotifyDto);
|
||||||
BuyOrder order = this.buyOrderService.getOne(new QueryWrapper<BuyOrder>().eq("order_sn",payDto.getRelevanceoid()).eq("del_flag","0"));
|
|
||||||
order.setPaymentDate(new Date());
|
|
||||||
this.buyOrderService.updateById(order);
|
|
||||||
|
|
||||||
orderInfo = resJson;
|
orderInfo = resJson;
|
||||||
}
|
}
|
||||||
@@ -155,33 +158,33 @@ public class AliPayServiceImpl implements AliPayService {
|
|||||||
String body = oldPayZfbOrderEntity.getBody();
|
String body = oldPayZfbOrderEntity.getBody();
|
||||||
String customerid = oldPayZfbOrderEntity.getCustomerid();
|
String customerid = oldPayZfbOrderEntity.getCustomerid();
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
if ("vip".equals(subject)) {
|
if ("vip".equals(subject)) {
|
||||||
BuyOrder orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrder>().eq("order_sn", oldPayZfbOrderEntity.getRelevanceoid()));
|
BuyOrder orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrder>().eq("order_sn", oldPayZfbOrderEntity.getRelevanceoid()));
|
||||||
//更新 订单 记录
|
//更新 订单 记录
|
||||||
|
|
||||||
buyOrderService.updateOrderStatus(Integer.valueOf(customerid),oldPayZfbOrderEntity.getRelevanceoid(),"2");
|
buyOrderService.updateOrderStatus(Integer.valueOf(customerid),oldPayZfbOrderEntity.getRelevanceoid(),"2");
|
||||||
|
|
||||||
//处理抵扣积分
|
//处理抵扣积分
|
||||||
if(orderEntity.getJfDeduction().compareTo(BigDecimal.ZERO)>0){
|
if(orderEntity.getJfDeduction().compareTo(BigDecimal.ZERO)>0){
|
||||||
userCoinJf(orderEntity);
|
userCoinJf(orderEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
//开通vip
|
//开通vip
|
||||||
openVipForUser(orderEntity);
|
openVipForUser(orderEntity);
|
||||||
|
|
||||||
//获取会员开通 日期
|
//获取会员开通 日期
|
||||||
|
|
||||||
// BookBuyConfigEntity bookBuyConfigEntity = bookBuyConfigService.getById(Integer.valueOf(body));
|
// BookBuyConfigEntity bookBuyConfigEntity = bookBuyConfigService.getById(Integer.valueOf(body));
|
||||||
// String month = bookBuyConfigEntity.getMonth();
|
// String month = bookBuyConfigEntity.getMonth();
|
||||||
// userService.openMember(Integer.valueOf(customerid),Integer.valueOf(month));
|
// userService.openMember(Integer.valueOf(customerid),Integer.valueOf(month));
|
||||||
//
|
|
||||||
// // 插入 开通记录
|
// // 插入 开通记录
|
||||||
//
|
|
||||||
// buyOrderService.updateOrderStatus(Integer.valueOf(customerid),oldPayZfbOrderEntity.getRelevanceoid(),"2");
|
// buyOrderService.updateOrderStatus(Integer.valueOf(customerid),oldPayZfbOrderEntity.getRelevanceoid(),"2");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if("point".equals(subject)){
|
if("point".equals(subject)){
|
||||||
// 插入花生币 变动记录
|
// 插入花生币 变动记录
|
||||||
BookBuyConfigEntity bookBuyConfigEntity = bookBuyConfigService.getById(Integer.valueOf(body));
|
BookBuyConfigEntity bookBuyConfigEntity = bookBuyConfigService.getById(Integer.valueOf(body));
|
||||||
@@ -284,8 +287,10 @@ public class AliPayServiceImpl implements AliPayService {
|
|||||||
}
|
}
|
||||||
//开通course,end
|
//开通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, orderEntity.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)){
|
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(orderEntity.getUserId());
|
||||||
userInfo.setPointPower(1);
|
userInfo.setPointPower(1);
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|||||||
import com.peanut.modules.common.dao.*;
|
import com.peanut.modules.common.dao.*;
|
||||||
import com.peanut.modules.book.service.*;
|
import com.peanut.modules.book.service.*;
|
||||||
import com.peanut.modules.common.entity.*;
|
import com.peanut.modules.common.entity.*;
|
||||||
|
import com.peanut.modules.common.service.CouponService;
|
||||||
|
import com.peanut.modules.master.service.UserCourseBuyService;
|
||||||
import com.peanut.modules.pay.refund.entity.PayRefundOrder;
|
import com.peanut.modules.pay.refund.entity.PayRefundOrder;
|
||||||
import com.peanut.modules.pay.refund.service.PayRefundOrderService;
|
import com.peanut.modules.pay.refund.service.PayRefundOrderService;
|
||||||
import com.peanut.modules.pay.weChatPay.config.WechatPayConfig;
|
import com.peanut.modules.pay.weChatPay.config.WechatPayConfig;
|
||||||
@@ -70,6 +72,8 @@ public class WxpayServiceImpl extends ServiceImpl<PayWechatOrderDao, PayWechatOr
|
|||||||
@Autowired
|
@Autowired
|
||||||
private UserCourseBuyDao userCourseBuyDao;
|
private UserCourseBuyDao userCourseBuyDao;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
private UserCourseBuyService userCourseBuyService;
|
||||||
|
@Autowired
|
||||||
private JfTransactionDetailsDao jfTransactionDetailsDao;
|
private JfTransactionDetailsDao jfTransactionDetailsDao;
|
||||||
@Autowired
|
@Autowired
|
||||||
private MyUserDao myUserDao;
|
private MyUserDao myUserDao;
|
||||||
@@ -77,6 +81,8 @@ public class WxpayServiceImpl extends ServiceImpl<PayWechatOrderDao, PayWechatOr
|
|||||||
private VipBuyConfigDao vipBuyConfigDao;
|
private VipBuyConfigDao vipBuyConfigDao;
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserVipDao userVipDao;
|
private UserVipDao userVipDao;
|
||||||
|
@Autowired
|
||||||
|
private CouponService couponService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void prepay(WechatPaymentInfo paymentInfo){
|
public void prepay(WechatPaymentInfo paymentInfo){
|
||||||
@@ -139,18 +145,23 @@ public class WxpayServiceImpl extends ServiceImpl<PayWechatOrderDao, PayWechatOr
|
|||||||
// 根据订单号,做幂等处理,并且在对业务数据进行状态检查和处理之前,要采用数据锁进行并发控制,以避免函数重入造成的数据混乱
|
// 根据订单号,做幂等处理,并且在对业务数据进行状态检查和处理之前,要采用数据锁进行并发控制,以避免函数重入造成的数据混乱
|
||||||
BuyOrder order = this.buyOrderService.getOne(new QueryWrapper<BuyOrder>().eq("order_sn", orderNo));
|
BuyOrder order = this.buyOrderService.getOne(new QueryWrapper<BuyOrder>().eq("order_sn", orderNo));
|
||||||
|
|
||||||
if("vip".equals(order.getOrderType())){
|
if("relearn".equals(order.getOrderType())){
|
||||||
|
BuyOrder orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrder>()
|
||||||
|
.eq("order_sn", orderNo));
|
||||||
|
//更新 订单 记录
|
||||||
|
buyOrderService.updateOrderStatus(orderEntity.getUserId(),orderNo,"2");
|
||||||
|
//插入复读记录
|
||||||
|
userCourseBuyService.addUserCourseBuyRelearn(orderEntity,"微信购买:"+orderEntity.getOrderSn());
|
||||||
|
}
|
||||||
|
|
||||||
|
if("vip".equals(order.getOrderType())){
|
||||||
BuyOrder orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrder>().eq("order_sn", orderNo));
|
BuyOrder orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrder>().eq("order_sn", orderNo));
|
||||||
//更新 订单 记录
|
//更新 订单 记录
|
||||||
|
|
||||||
buyOrderService.updateOrderStatus(orderEntity.getUserId(),orderNo,"2");
|
buyOrderService.updateOrderStatus(orderEntity.getUserId(),orderNo,"2");
|
||||||
|
|
||||||
//处理抵扣积分
|
//处理抵扣积分
|
||||||
if(orderEntity.getJfDeduction().compareTo(BigDecimal.ZERO)>0){
|
if(orderEntity.getJfDeduction().compareTo(BigDecimal.ZERO)>0){
|
||||||
userCoinJf(orderEntity);
|
userCoinJf(orderEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
//开通vip
|
//开通vip
|
||||||
openVipForUser(orderEntity);
|
openVipForUser(orderEntity);
|
||||||
}
|
}
|
||||||
@@ -160,13 +171,10 @@ public class WxpayServiceImpl extends ServiceImpl<PayWechatOrderDao, PayWechatOr
|
|||||||
BuyOrder orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrder>().eq("order_sn", orderNo));
|
BuyOrder orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrder>().eq("order_sn", orderNo));
|
||||||
BigDecimal realMoney = orderEntity.getRealMoney();
|
BigDecimal realMoney = orderEntity.getRealMoney();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(orderEntity.getJfDeduction().compareTo(BigDecimal.ZERO)>0){
|
if(orderEntity.getJfDeduction().compareTo(BigDecimal.ZERO)>0){
|
||||||
userCoinJf(orderEntity);
|
userCoinJf(orderEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//开通book,start
|
//开通book,start
|
||||||
// 查询订单的所有 book_id
|
// 查询订单的所有 book_id
|
||||||
List<Integer> orderBookIdList = shopProductBookService.getOrderBookId(order.getOrderSn());
|
List<Integer> orderBookIdList = shopProductBookService.getOrderBookId(order.getOrderSn());
|
||||||
@@ -226,8 +234,10 @@ public class WxpayServiceImpl extends ServiceImpl<PayWechatOrderDao, PayWechatOr
|
|||||||
}
|
}
|
||||||
//开通course,end
|
//开通course,end
|
||||||
|
|
||||||
//手摸脚模购买后会开启用户的脉穴的功能
|
|
||||||
List<Integer> collect = buyOrderProductDao.selectList(new LambdaQueryWrapper<BuyOrderProduct>().eq(BuyOrderProduct::getOrderId, order.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)){
|
if(collect.contains(128)||collect.contains(129)||collect.contains(130)||collect.contains(131)||collect.contains(136)||collect.contains(137)){
|
||||||
MyUserEntity userInfo = userService.getById(order.getUserId());
|
MyUserEntity userInfo = userService.getById(order.getUserId());
|
||||||
userInfo.setPointPower(1);
|
userInfo.setPointPower(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user