开通aiVip
This commit is contained in:
@@ -22,7 +22,7 @@ public class AiVipLog implements Serializable {
|
||||
private Integer type;
|
||||
|
||||
//可用助手,0全部(预留)
|
||||
private String available_assistant;
|
||||
private String availableAssistant;
|
||||
|
||||
//次数
|
||||
private int count;
|
||||
|
||||
@@ -169,7 +169,7 @@ public class BuyOrder implements Serializable {
|
||||
|
||||
private Integer vipBuyConfigId;
|
||||
|
||||
private Integer abroadBookId;//海外读书购买书籍id
|
||||
private Integer aiBuyConfigId;//ai会员配置表
|
||||
|
||||
private Integer trainingClassId;//培训班id
|
||||
|
||||
|
||||
@@ -4,4 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.modules.common.entity.AiVipLog;
|
||||
|
||||
public interface AiVipLogService extends IService<AiVipLog> {
|
||||
|
||||
void openAiVip(int aiBuyConfigId);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,45 @@
|
||||
package com.peanut.modules.common.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.peanut.common.utils.DateUtils;
|
||||
import com.peanut.common.utils.ShiroUtils;
|
||||
import com.peanut.modules.common.dao.AiBuyConfigDao;
|
||||
import com.peanut.modules.common.dao.AiVipLogDao;
|
||||
import com.peanut.modules.common.entity.AiBuyConfig;
|
||||
import com.peanut.modules.common.entity.AiVipLog;
|
||||
import com.peanut.modules.common.service.AiVipLogService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Slf4j
|
||||
@Service("commonAiVipLogService")
|
||||
public class AiVipLogServiceImpl extends ServiceImpl<AiVipLogDao, AiVipLog> implements AiVipLogService {
|
||||
|
||||
@Autowired
|
||||
private AiBuyConfigDao aiBuyConfigDao;
|
||||
|
||||
@Override
|
||||
public void openAiVip(int aiBuyConfigId) {
|
||||
AiBuyConfig config = aiBuyConfigDao.selectById(aiBuyConfigId);
|
||||
if (config != null) {
|
||||
AiVipLog aiVipLog = new AiVipLog();
|
||||
aiVipLog.setUserId(ShiroUtils.getUId());
|
||||
//1月度2季度
|
||||
aiVipLog.setType(config.getType());
|
||||
aiVipLog.setCount(config.getCount());
|
||||
aiVipLog.setSurplusCount(config.getCount());
|
||||
Date date = new Date();
|
||||
aiVipLog.setStartTime(date);
|
||||
if (config.getType()==1){
|
||||
aiVipLog.setEndTime(DateUtils.addDateMonths(date,1));
|
||||
}else {
|
||||
aiVipLog.setEndTime(DateUtils.addDateMonths(date,3));
|
||||
}
|
||||
this.save(aiVipLog);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +78,8 @@ public class AliPayServiceImpl implements AliPayService {
|
||||
private CouponHistoryService couponHistoryService;
|
||||
@Autowired
|
||||
private TrainingClassService trainingClassService;
|
||||
@Autowired
|
||||
private AiVipLogService aiVipLogService;
|
||||
|
||||
@Override
|
||||
public String pay(AlipayDTO payDto) {
|
||||
@@ -199,6 +201,17 @@ public class AliPayServiceImpl implements AliPayService {
|
||||
userVipService.openVipForUser(order);
|
||||
}
|
||||
|
||||
if ("vip".equals(subject)) {
|
||||
//更新 订单 记录
|
||||
buyOrderService.updateOrderStatus(Integer.valueOf(customerid),oldPayZfbOrderEntity.getRelevanceoid(),"2");
|
||||
//处理抵扣积分
|
||||
if(order.getJfDeduction().compareTo(BigDecimal.ZERO)>0){
|
||||
userCoinJf(order);
|
||||
}
|
||||
//开通aivip
|
||||
aiVipLogService.openAiVip(order.getAiBuyConfigId());
|
||||
}
|
||||
|
||||
if("point".equals(subject)){
|
||||
// 插入花生币 变动记录
|
||||
BookBuyConfigEntity bookBuyConfigEntity = bookBuyConfigService.getById(Integer.valueOf(body));
|
||||
|
||||
@@ -85,6 +85,8 @@ public class WxpayServiceImpl extends ServiceImpl<PayWechatOrderDao, PayWechatOr
|
||||
private CouponHistoryService couponHistoryService;
|
||||
@Autowired
|
||||
private TrainingClassService trainingClassService;
|
||||
@Autowired
|
||||
private AiVipLogService aiVipLogService;
|
||||
|
||||
@Override
|
||||
public void prepay(WechatPaymentInfo paymentInfo){
|
||||
@@ -186,6 +188,17 @@ public class WxpayServiceImpl extends ServiceImpl<PayWechatOrderDao, PayWechatOr
|
||||
userVipService.openVipForUser(order);
|
||||
}
|
||||
|
||||
if("aiVip".equals(order.getOrderType())){
|
||||
//更新 订单 记录
|
||||
buyOrderService.updateOrderStatus(order.getUserId(),orderNo,"2");
|
||||
//处理抵扣积分
|
||||
if(order.getJfDeduction().compareTo(BigDecimal.ZERO)>0){
|
||||
userCoinJf(order);
|
||||
}
|
||||
//开通aivip
|
||||
aiVipLogService.openAiVip(order.getAiBuyConfigId());
|
||||
}
|
||||
|
||||
// 1.根据订单id获取订单信息
|
||||
if ("order".equals(order.getOrderType())) {
|
||||
if(order.getJfDeduction().compareTo(BigDecimal.ZERO)>0){
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
package com.peanut.modules.taihumed.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
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.BuyOrder;
|
||||
import com.peanut.modules.common.entity.MyUserEntity;
|
||||
import com.peanut.modules.common.service.AiVipLogService;
|
||||
import com.peanut.modules.common.service.BuyOrderService;
|
||||
import com.peanut.modules.common.service.JfTransactionDetailsService;
|
||||
import com.peanut.modules.common.service.MyUserService;
|
||||
import com.peanut.modules.pay.weChatPay.dto.WechatPaymentInfo;
|
||||
import com.peanut.modules.pay.weChatPay.service.WxpayService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.core.MessagePostProcessor;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Slf4j
|
||||
@RestController("taihumedAiVip")
|
||||
@RequestMapping("taihumed/aiVip")
|
||||
public class AiVipController {
|
||||
|
||||
@Autowired
|
||||
private BuyOrderService buyOrderService;
|
||||
@Autowired
|
||||
private MyUserService myUserService;
|
||||
@Autowired
|
||||
private TransactionDetailsService transactionDetailsService;
|
||||
@Autowired
|
||||
private JfTransactionDetailsService jfTransactionDetailsService;
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
@Autowired
|
||||
private WxpayService wxpayService;
|
||||
@Autowired
|
||||
private AiVipLogService aiVipLogService;
|
||||
|
||||
//aivip下单
|
||||
@RequestMapping("/placeAiVipOrder")
|
||||
@Transactional
|
||||
public R placeVipOrder(@RequestBody BuyOrder buyOrder){
|
||||
int uid = ShiroUtils.getUId();
|
||||
buyOrder.setOrderStatus("0");
|
||||
buyOrder.setOrderType("aiVip");
|
||||
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 = myUserService.getById(buyOrder.getUserId());
|
||||
if (usePeanutCoin(user, totalPrice)&&useJfCoin(user,buyOrder.getJfDeduction())) {
|
||||
// 更新订单状态
|
||||
buyOrderService.updateOrderStatus(user.getId(), buyOrder.getOrderSn(), "2");
|
||||
//记录用户虚拟币消费
|
||||
if(totalPrice.compareTo(BigDecimal.ZERO)>0){
|
||||
transactionDetailsService.recordTransaction(buyOrder, user, totalPrice);
|
||||
}
|
||||
//记录用户积分消费情况
|
||||
if(buyOrder.getJfDeduction()!=null&&buyOrder.getJfDeduction().compareTo(BigDecimal.ZERO) > 0){
|
||||
jfTransactionDetailsService.recordJfTransaction(buyOrder, user, buyOrder.getJfDeduction());
|
||||
}
|
||||
//开通用户aiVip
|
||||
aiVipLogService.openAiVip(buyOrder.getAiBuyConfigId());
|
||||
} else {
|
||||
rabbitTemplate.convertAndSend(
|
||||
DelayQueueConfig.ORDER_TO_BE_PAY_EXCHANGE,
|
||||
DelayQueueConfig.ORDER_TO_BE_PAY_ROUTING_KEY,
|
||||
buyOrder.getOrderId(),
|
||||
messagePostProcessor()
|
||||
);
|
||||
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(buyOrderEntity.getOrderId());
|
||||
paymentInfo.setTotalAmount(buyOrderEntity.getRealMoney());
|
||||
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",buyOrder.getRealMoney());
|
||||
}
|
||||
|
||||
|
||||
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));
|
||||
myUserService.updateById(user);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean useJfCoin(MyUserEntity user,BigDecimal jf){
|
||||
if(jf==null){
|
||||
return true;
|
||||
}
|
||||
if(user.getJf().compareTo(jf)>=0){
|
||||
user.setJf(user.getJf().subtract(jf));
|
||||
myUserService.updateById(user);
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private MessagePostProcessor messagePostProcessor() {
|
||||
return message -> {
|
||||
//设置有效期30分钟
|
||||
message.getMessageProperties().setExpiration(String.valueOf(30 * 60 * 1000));
|
||||
return message;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user