VIP改版
This commit is contained in:
@@ -2,9 +2,7 @@ package com.peanut.modules.pay.IOSPay.model.dto;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.models.auth.In;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import java.io.Serializable;
|
||||
|
||||
@@ -29,6 +27,7 @@ public class IapRequestDTO implements Serializable {
|
||||
@Column(name = "receiptData")
|
||||
String receiptData;
|
||||
|
||||
@JsonProperty("isSandBox")
|
||||
boolean isSandBox;
|
||||
|
||||
String relevanceoid;
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.peanut.modules.common.entity.*;
|
||||
import com.peanut.modules.common.service.CouponHistoryService;
|
||||
import com.peanut.modules.common.service.CouponService;
|
||||
import com.peanut.modules.common.service.OfflineActivityToUserService;
|
||||
import com.peanut.modules.common.service.UserVipService;
|
||||
import com.peanut.modules.master.service.UserCourseBuyService;
|
||||
import com.peanut.modules.pay.alipay.config.AliPayConfig;
|
||||
import com.peanut.modules.pay.alipay.config.AliPayUtil;
|
||||
@@ -30,8 +31,6 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.Period;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -71,11 +70,7 @@ public class AliPayServiceImpl implements AliPayService {
|
||||
@Autowired
|
||||
private JfTransactionDetailsDao jfTransactionDetailsDao;
|
||||
@Autowired
|
||||
private MyUserDao myUserDao;
|
||||
@Autowired
|
||||
private VipBuyConfigDao vipBuyConfigDao;
|
||||
@Autowired
|
||||
private UserVipDao userVipDao;
|
||||
private UserVipService userVipService;
|
||||
@Autowired
|
||||
private CouponService couponService;
|
||||
@Autowired
|
||||
@@ -200,13 +195,7 @@ public class AliPayServiceImpl implements AliPayService {
|
||||
userCoinJf(order);
|
||||
}
|
||||
//开通vip
|
||||
openVipForUser(order);
|
||||
//获取会员开通 日期
|
||||
// BookBuyConfigEntity bookBuyConfigEntity = bookBuyConfigService.getById(Integer.valueOf(body));
|
||||
// String month = bookBuyConfigEntity.getMonth();
|
||||
// userService.openMember(Integer.valueOf(customerid),Integer.valueOf(month));
|
||||
// // 插入 开通记录
|
||||
// buyOrderService.updateOrderStatus(Integer.valueOf(customerid),oldPayZfbOrderEntity.getRelevanceoid(),"2");
|
||||
userVipService.openVipForUser(order);
|
||||
}
|
||||
|
||||
if("point".equals(subject)){
|
||||
@@ -342,91 +331,6 @@ public class AliPayServiceImpl implements AliPayService {
|
||||
}
|
||||
}
|
||||
|
||||
private void openVipForUser(BuyOrder buyOrder) throws Exception {
|
||||
VipBuyConfigEntity vipBuyConfigEntity = vipBuyConfigDao.selectById(buyOrder.getVipBuyConfigId());
|
||||
MyUserEntity userEntity = myUserDao.selectById(buyOrder.getUserId());
|
||||
String u_v_type = userEntity.getVip();
|
||||
if(vipBuyConfigEntity.getType()==1){//超v
|
||||
if(u_v_type.equals("0")){//初次办理
|
||||
UserVip userVip = new UserVip();
|
||||
userVip.setUserId(userEntity.getId());
|
||||
userVip.setType(1);
|
||||
userVip.setStartTime(new Date());
|
||||
LocalDate today = LocalDate.now();
|
||||
LocalDate threeYearsLater = today.plus(Period.ofYears(vipBuyConfigEntity.getYear()));
|
||||
Date threeYearsDate = Date.from(threeYearsLater.atStartOfDay(java.time.ZoneId.systemDefault()).toInstant());
|
||||
userVip.setEndTime(threeYearsDate);
|
||||
userVipDao.insert(userVip);
|
||||
userEntity.setVip("1");
|
||||
myUserDao.updateById(userEntity);
|
||||
} else if(u_v_type.equals("1")){//vip延期
|
||||
List<UserVip> userVips = userVipDao.selectList(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId, userEntity.getId()).gt(UserVip::getEndTime, new Date()).eq(UserVip::getState, 0));
|
||||
if(userVips.size()!=1){
|
||||
throwExceptionMethod();
|
||||
}
|
||||
UserVip userVip = userVips.get(0);
|
||||
Date endTime = userVip.getEndTime();
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(endTime);
|
||||
calendar.add(Calendar.YEAR,vipBuyConfigEntity.getYear());
|
||||
userVip.setEndTime(calendar.getTime());
|
||||
userVipDao.updateById(userVip);
|
||||
}else if (u_v_type.equals("2")||u_v_type.equals("3")){//医学vip或国学vip升级
|
||||
List<UserVip> userVips = userVipDao.selectList(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId, userEntity.getId()).gt(UserVip::getEndTime, new Date()).eq(UserVip::getState, 0));
|
||||
if(userVips.size()!=1){
|
||||
throwExceptionMethod();
|
||||
}
|
||||
UserVip userVip1 = userVips.get(0);
|
||||
userVip1.setEndTime(new Date());
|
||||
userVip1.setState(1);
|
||||
userVipDao.updateById(userVip1);
|
||||
UserVip userVip = new UserVip();
|
||||
userVip.setUserId(userEntity.getId());
|
||||
userVip.setType(1);
|
||||
userVip.setStartTime(new Date());
|
||||
LocalDate today = LocalDate.now();
|
||||
LocalDate threeYearsLater = today.plus(Period.ofYears(vipBuyConfigEntity.getYear()));
|
||||
Date threeYearsDate = Date.from(threeYearsLater.atStartOfDay(java.time.ZoneId.systemDefault()).toInstant());
|
||||
userVip.setEndTime(threeYearsDate);
|
||||
userVipDao.insert(userVip);
|
||||
userEntity.setVip("1");
|
||||
myUserDao.updateById(userEntity);
|
||||
}
|
||||
}
|
||||
if(vipBuyConfigEntity.getType()==2||vipBuyConfigEntity.getType()==3){//医学vip或国学vip
|
||||
if(userEntity.getVip().equals("2")||userEntity.getVip().equals("3")){//续费
|
||||
List<UserVip> userVips = userVipDao.selectList(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId, userEntity.getId()).gt(UserVip::getEndTime, new Date()).eq(UserVip::getState, 0));
|
||||
if(userVips.size()!=1){
|
||||
throwExceptionMethod();
|
||||
}
|
||||
UserVip userVip = userVips.get(0);
|
||||
Date endTime = userVip.getEndTime();
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(endTime);
|
||||
calendar.add(Calendar.YEAR,vipBuyConfigEntity.getYear());
|
||||
userVip.setEndTime(calendar.getTime());
|
||||
userVipDao.updateById(userVip);
|
||||
}else{//新办理
|
||||
UserVip userVip = new UserVip();
|
||||
userVip.setUserId(userEntity.getId());
|
||||
userVip.setType(vipBuyConfigEntity.getType());
|
||||
userVip.setStartTime(new Date());
|
||||
LocalDate today = LocalDate.now();
|
||||
LocalDate threeYearsLater = today.plus(Period.ofYears(vipBuyConfigEntity.getYear()));
|
||||
Date threeYearsDate = Date.from(threeYearsLater.atStartOfDay(java.time.ZoneId.systemDefault()).toInstant());
|
||||
userVip.setEndTime(threeYearsDate);
|
||||
userVipDao.insert(userVip);
|
||||
userEntity.setVip(vipBuyConfigEntity.getType().toString());
|
||||
myUserDao.updateById(userEntity);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void throwExceptionMethod() throws Exception {
|
||||
throw new Exception("开通vip异常");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public String refund(Map<String,Object> params) {
|
||||
|
||||
@@ -42,8 +42,8 @@ public class ApplePayController {
|
||||
// return Result.failed(ResultCode.APPLE_NULL);
|
||||
} else {
|
||||
//
|
||||
return applePayService.getAppPay(verifyResult, TransactionID);
|
||||
|
||||
// return applePayService.getAppPay(verifyResult, TransactionID);
|
||||
return R.ok();
|
||||
// return applePayService.doIosRequest(TransactionID,receipt,userId);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.peanut.modules.pay.applePay.service;
|
||||
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.pay.IOSPay.Result;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -30,7 +29,7 @@ public interface ApplePayService {
|
||||
|
||||
|
||||
|
||||
R getAppPay(String verifyResult, String transactionID);
|
||||
// R getAppPay(String verifyResult, String transactionID);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package com.peanut.modules.pay.applePay.service.impl;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
|
||||
import com.peanut.common.utils.DateUtils;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.book.service.*;
|
||||
import com.peanut.modules.common.entity.*;
|
||||
import com.peanut.modules.pay.IOSPay.Result;
|
||||
import com.peanut.modules.pay.applePay.service.ApplePayService;
|
||||
import com.peanut.modules.pay.applePay.utils.*;
|
||||
@@ -15,8 +12,6 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
@@ -122,63 +117,38 @@ public class ApplePayServiceImpl implements ApplePayService {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public R getAppPay(String verifyResult, String transactionID) {
|
||||
log.info("##########################苹果支付验证!########################");
|
||||
JSONObject jsonObject = JSONObject.parseObject(verifyResult);
|
||||
String status = jsonObject.getString("status");
|
||||
//判断是否验证成功
|
||||
if ("0".equals(status)) {
|
||||
//app端所提供的收据是有效的,验证成功
|
||||
String receipt = jsonObject.getString("receipt");
|
||||
JSONObject returnJson = JSONObject.parseObject(receipt);
|
||||
String in_app = returnJson.getString("in_app");
|
||||
JSONObject in_appJson = JSONObject.parseObject(in_app.substring(1, in_app.length() - 1));
|
||||
String transactionId = in_appJson.getString("transaction_id");
|
||||
String in_app_ownership_type = in_appJson.getString("in_app_ownership_type");
|
||||
//如果验证后的订单号与app端传来的订单号一致并且状态为已支付状态则处理自己的业务
|
||||
if (transactionID.equals(transactionId) && "PURCHASED".equals(in_app_ownership_type)) {
|
||||
//===================处理自己的业务 ============================
|
||||
BuyOrder order = this.buyOrderService.getOne(new QueryWrapper<BuyOrder>().eq("order_sn", transactionId ));
|
||||
PayWechatOrderEntity wechat = new PayWechatOrderEntity();
|
||||
// @Override
|
||||
// @Transactional
|
||||
// public R getAppPay(String verifyResult, String transactionID) {
|
||||
// log.info("##########################苹果支付验证!########################");
|
||||
// JSONObject jsonObject = JSONObject.parseObject(verifyResult);
|
||||
// String status = jsonObject.getString("status");
|
||||
// //判断是否验证成功
|
||||
// if ("0".equals(status)) {
|
||||
// //app端所提供的收据是有效的,验证成功
|
||||
// String receipt = jsonObject.getString("receipt");
|
||||
// JSONObject returnJson = JSONObject.parseObject(receipt);
|
||||
// String in_app = returnJson.getString("in_app");
|
||||
// JSONObject in_appJson = JSONObject.parseObject(in_app.substring(1, in_app.length() - 1));
|
||||
// String transactionId = in_appJson.getString("transaction_id");
|
||||
// String in_app_ownership_type = in_appJson.getString("in_app_ownership_type");
|
||||
// //如果验证后的订单号与app端传来的订单号一致并且状态为已支付状态则处理自己的业务
|
||||
// if (transactionID.equals(transactionId) && "PURCHASED".equals(in_app_ownership_type)) {
|
||||
// //===================处理自己的业务 ============================
|
||||
// BuyOrder order = this.buyOrderService.getOne(new QueryWrapper<BuyOrder>().eq("order_sn", transactionId ));
|
||||
// PayWechatOrderEntity wechat = new PayWechatOrderEntity();
|
||||
//
|
||||
//
|
||||
// }
|
||||
// return R.ok();
|
||||
// }
|
||||
// return R.error("苹果内购验证失败");
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
if ("vip".equals(order.getOrderType())) {
|
||||
//会员记录
|
||||
BookBuyConfigEntity bookBuyConfigEntity = bookBuyConfigService.getById(wechat.getBuyOrderId());
|
||||
String month = bookBuyConfigEntity.getMonth();
|
||||
userService.openMember(Integer.valueOf(transactionId),Integer.valueOf(month));
|
||||
buyOrderService.updateOrderStatus(Integer.valueOf(transactionId),order.getOrderSn(),"2");
|
||||
|
||||
|
||||
|
||||
}
|
||||
if ("order".equals(order.getOrderType())) {
|
||||
|
||||
BuyOrder orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrder>().eq("order_sn", wechat.getOrderId()));
|
||||
BigDecimal realMoney = orderEntity.getRealMoney();
|
||||
//更新 订单 记录
|
||||
|
||||
}
|
||||
if ("point".equals(order.getOrderType())) {
|
||||
BookBuyConfigEntity bookBuyConfigEntity = bookBuyConfigService.getById(wechat.getBuyOrderId());
|
||||
MyUserEntity userEntity = userService.getById(Integer.valueOf(order.getUserId()));
|
||||
String realMoney = bookBuyConfigEntity.getRealMoney();
|
||||
userService.rechargeHSPoint(userEntity,Integer.valueOf(realMoney));
|
||||
//插入虚拟币消费记录
|
||||
transactionDetailsService.rechargeRecord(userEntity,realMoney,wechat.getId().intValue(),"苹果支付",order.getOrderSn());
|
||||
//插入花生币充值记录
|
||||
payPaymentOrderService.insertDetail(userEntity,bookBuyConfigEntity,wechat.getId().toString());
|
||||
buyOrderService.updateOrderStatus(Integer.valueOf(order.getUserId()),order.getOrderSn(),"2");
|
||||
}
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
return R.error("苹果内购验证失败");
|
||||
}}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.peanut.modules.common.entity.*;
|
||||
import com.peanut.modules.common.service.CouponHistoryService;
|
||||
import com.peanut.modules.common.service.CouponService;
|
||||
import com.peanut.modules.common.service.OfflineActivityToUserService;
|
||||
import com.peanut.modules.common.service.UserVipService;
|
||||
import com.peanut.modules.master.service.UserCourseBuyService;
|
||||
import com.peanut.modules.pay.refund.entity.PayRefundOrder;
|
||||
import com.peanut.modules.pay.refund.service.PayRefundOrderService;
|
||||
@@ -27,11 +28,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.Period;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -79,11 +77,7 @@ public class WxpayServiceImpl extends ServiceImpl<PayWechatOrderDao, PayWechatOr
|
||||
@Autowired
|
||||
private JfTransactionDetailsDao jfTransactionDetailsDao;
|
||||
@Autowired
|
||||
private MyUserDao myUserDao;
|
||||
@Autowired
|
||||
private VipBuyConfigDao vipBuyConfigDao;
|
||||
@Autowired
|
||||
private UserVipDao userVipDao;
|
||||
private UserVipService userVipService;
|
||||
@Autowired
|
||||
private CouponService couponService;
|
||||
@Autowired
|
||||
@@ -183,7 +177,7 @@ public class WxpayServiceImpl extends ServiceImpl<PayWechatOrderDao, PayWechatOr
|
||||
userCoinJf(order);
|
||||
}
|
||||
//开通vip
|
||||
openVipForUser(order);
|
||||
userVipService.openVipForUser(order);
|
||||
}
|
||||
|
||||
// 1.根据订单id获取订单信息
|
||||
@@ -307,92 +301,6 @@ public class WxpayServiceImpl extends ServiceImpl<PayWechatOrderDao, PayWechatOr
|
||||
}
|
||||
}
|
||||
|
||||
private void openVipForUser(BuyOrder buyOrder) throws Exception {
|
||||
VipBuyConfigEntity vipBuyConfigEntity = vipBuyConfigDao.selectById(buyOrder.getVipBuyConfigId());
|
||||
MyUserEntity userEntity = myUserDao.selectById(buyOrder.getUserId());
|
||||
String u_v_type = userEntity.getVip();
|
||||
if(vipBuyConfigEntity.getType()==1){//超v
|
||||
if(u_v_type.equals("0")){//初次办理
|
||||
UserVip userVip = new UserVip();
|
||||
userVip.setUserId(userEntity.getId());
|
||||
userVip.setType(1);
|
||||
userVip.setStartTime(new Date());
|
||||
LocalDate today = LocalDate.now();
|
||||
LocalDate threeYearsLater = today.plus(Period.ofYears(vipBuyConfigEntity.getYear()));
|
||||
Date threeYearsDate = Date.from(threeYearsLater.atStartOfDay(java.time.ZoneId.systemDefault()).toInstant());
|
||||
userVip.setEndTime(threeYearsDate);
|
||||
userVipDao.insert(userVip);
|
||||
userEntity.setVip("1");
|
||||
myUserDao.updateById(userEntity);
|
||||
}else if(u_v_type.equals("1")){//vip延期
|
||||
List<UserVip> userVips = userVipDao.selectList(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId, userEntity.getId()).gt(UserVip::getEndTime, new Date()).eq(UserVip::getState, 0));
|
||||
if(userVips.size()!=1){
|
||||
throwExceptionMethod();
|
||||
}
|
||||
UserVip userVip = userVips.get(0);
|
||||
Date endTime = userVip.getEndTime();
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(endTime);
|
||||
calendar.add(Calendar.YEAR,vipBuyConfigEntity.getYear());
|
||||
userVip.setEndTime(calendar.getTime());
|
||||
userVipDao.updateById(userVip);
|
||||
}else if (u_v_type.equals("2")||u_v_type.equals("3")){//医学vip或国学vip升级
|
||||
List<UserVip> userVips = userVipDao.selectList(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId, userEntity.getId()).gt(UserVip::getEndTime, new Date()).eq(UserVip::getState, 0));
|
||||
if(userVips.size()!=1){
|
||||
throwExceptionMethod();
|
||||
}
|
||||
UserVip userVip1 = userVips.get(0);
|
||||
userVip1.setEndTime(new Date());
|
||||
userVip1.setState(1);
|
||||
userVipDao.updateById(userVip1);
|
||||
UserVip userVip = new UserVip();
|
||||
userVip.setUserId(userEntity.getId());
|
||||
userVip.setType(1);
|
||||
userVip.setStartTime(new Date());
|
||||
LocalDate today = LocalDate.now();
|
||||
LocalDate threeYearsLater = today.plus(Period.ofYears(vipBuyConfigEntity.getYear()));
|
||||
Date threeYearsDate = Date.from(threeYearsLater.atStartOfDay(java.time.ZoneId.systemDefault()).toInstant());
|
||||
userVip.setEndTime(threeYearsDate);
|
||||
userVipDao.insert(userVip);
|
||||
userEntity.setVip("1");
|
||||
myUserDao.updateById(userEntity);
|
||||
|
||||
}
|
||||
}
|
||||
if(vipBuyConfigEntity.getType()==2||vipBuyConfigEntity.getType()==3){//医学vip或国学vip
|
||||
if(userEntity.getVip().equals("2")||userEntity.getVip().equals("3")){//续费
|
||||
List<UserVip> userVips = userVipDao.selectList(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId, userEntity.getId()).gt(UserVip::getEndTime, new Date()).eq(UserVip::getState, 0));
|
||||
if(userVips.size()!=1){
|
||||
throwExceptionMethod();
|
||||
}
|
||||
UserVip userVip = userVips.get(0);
|
||||
Date endTime = userVip.getEndTime();
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(endTime);
|
||||
calendar.add(Calendar.YEAR,vipBuyConfigEntity.getYear());
|
||||
userVip.setEndTime(calendar.getTime());
|
||||
userVipDao.updateById(userVip);
|
||||
}else{//新办理
|
||||
UserVip userVip = new UserVip();
|
||||
userVip.setUserId(userEntity.getId());
|
||||
userVip.setType(vipBuyConfigEntity.getType());
|
||||
userVip.setStartTime(new Date());
|
||||
LocalDate today = LocalDate.now();
|
||||
LocalDate threeYearsLater = today.plus(Period.ofYears(vipBuyConfigEntity.getYear()));
|
||||
Date threeYearsDate = Date.from(threeYearsLater.atStartOfDay(java.time.ZoneId.systemDefault()).toInstant());
|
||||
userVip.setEndTime(threeYearsDate);
|
||||
userVipDao.insert(userVip);
|
||||
userEntity.setVip(vipBuyConfigEntity.getType().toString());
|
||||
myUserDao.updateById(userEntity);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void throwExceptionMethod() throws Exception {
|
||||
throw new Exception("开通vip异常");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String refund(Map<String,Object> map){
|
||||
LambdaQueryWrapper<PayWechatOrderEntity> wrapper = new LambdaQueryWrapper();
|
||||
|
||||
Reference in New Issue
Block a user