|
@@ -6,6 +6,12 @@ import com.miaxis.common.config.WxpayConfig;
|
|
|
import com.miaxis.common.constant.Constants;
|
|
|
import com.miaxis.common.exception.CustomException;
|
|
|
import com.miaxis.common.utils.AesUtil;
|
|
|
+import com.miaxis.common.utils.DateUtils;
|
|
|
+import com.miaxis.newgzpt.domain.GzptUserInfo;
|
|
|
+import com.miaxis.newgzpt.domain.GzptVideoVip;
|
|
|
+import com.miaxis.newgzpt.dto.GzptVideoVipDTO;
|
|
|
+import com.miaxis.newgzpt.service.IGzptUserInfoService;
|
|
|
+import com.miaxis.newgzpt.service.IGzptVideoVipService;
|
|
|
import com.miaxis.wx.domain.RefundRecord;
|
|
|
import com.miaxis.wx.domain.WxJsOrder;
|
|
|
import com.miaxis.wx.domain.WxOrder;
|
|
@@ -34,6 +40,7 @@ import java.io.IOException;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.security.*;
|
|
|
import java.security.cert.X509Certificate;
|
|
|
+import java.util.Date;
|
|
|
|
|
|
@RestController
|
|
|
@RequiredArgsConstructor
|
|
@@ -54,7 +61,12 @@ public class WxNotifyController {
|
|
|
@Autowired
|
|
|
private AutoUpdateCertificatesVerifier verifier;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IGzptUserInfoService userInfoService;
|
|
|
+
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IGzptVideoVipService videoVipService;
|
|
|
/**
|
|
|
* 微信支付回调接口
|
|
|
*/
|
|
@@ -154,7 +166,6 @@ public class WxNotifyController {
|
|
|
WxNotifyReturnDTO wxNotifyReturnDTO = new WxNotifyReturnDTO();
|
|
|
wxNotifyReturnDTO.setCode("SUCCESS");
|
|
|
wxNotifyReturnDTO.setMessage("成功");
|
|
|
-
|
|
|
return wxNotifyReturnDTO;
|
|
|
}
|
|
|
|
|
@@ -162,14 +173,13 @@ public class WxNotifyController {
|
|
|
String refundId = jsonObject.getString("refund_id");
|
|
|
RefundRecord refundRecord = refundRecordService.getByRefundId(refundId);
|
|
|
if (refundRecord == null) {
|
|
|
- throw new CustomException("该退款订单不存在");
|
|
|
+ log.error("该退款订单不存在");
|
|
|
+ return;
|
|
|
}
|
|
|
refundRecord.setTransactionId(jsonObject.getString("transaction_id"));
|
|
|
refundRecord.setUserReceivedAccount(jsonObject.getString("user_received_account"));
|
|
|
refundRecord.setStatus(jsonObject.getString("refund_status"));
|
|
|
refundRecordService.updateById(refundRecord);
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|
|
@@ -184,7 +194,12 @@ public class WxNotifyController {
|
|
|
String outTradeNo = jsonObject.getString("out_trade_no");
|
|
|
WxJsOrder wxJsOrder = wxJsOrderService.getByOutTradeNo(outTradeNo);
|
|
|
if (wxJsOrder == null) {
|
|
|
- throw new CustomException("该订单不存在");
|
|
|
+ log.error("该订单不存在");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if("SUCCESS".equals(wxJsOrder.getTradeState())){
|
|
|
+ log.info("订单号为"+wxJsOrder.getOutTradeNo()+"的订单已完成操作,无法重复操作!");
|
|
|
+ return;
|
|
|
}
|
|
|
wxJsOrder.setTransactionId(jsonObject.getString("transaction_id"));
|
|
|
JSONObject amount = jsonObject.getJSONObject("amount");
|
|
@@ -199,8 +214,120 @@ public class WxNotifyController {
|
|
|
wxJsOrder.setTradeStateDesc(jsonObject.getString("trade_state_desc"));
|
|
|
wxJsOrder.setTradeType(jsonObject.getString("trade_type"));
|
|
|
wxJsOrder.setAttach(jsonObject.getString("attach"));
|
|
|
+
|
|
|
+ //插入VIP信息
|
|
|
+ writeVipDataToDb(wxJsOrder);
|
|
|
wxJsOrderService.updateById(wxJsOrder);
|
|
|
+ }
|
|
|
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public void writeVipDataToDb(WxJsOrder wxJsOrder) {
|
|
|
+ long oneYearLong = 1000*60*60*24*365l;
|
|
|
+ Date now = new Date();
|
|
|
+
|
|
|
+ if ("科目二视频".equals(wxJsOrder.getGoodsName())){
|
|
|
+ GzptVideoVipDTO gzptVideoVipDTO = new GzptVideoVipDTO();
|
|
|
+ gzptVideoVipDTO.setUserId(wxJsOrder.getUserId());
|
|
|
+ GzptVideoVip gv = videoVipService.getGzptVideoVipByUserId(gzptVideoVipDTO);
|
|
|
+ if(gv!=null) {
|
|
|
+ //修改会员信息
|
|
|
+ Date km2Date = gv.getSubject2();
|
|
|
+ if(km2Date!=null) { //存在会员时间
|
|
|
+ if(km2Date.compareTo(now)<0) { //会员已过期
|
|
|
+ long x = now.getTime() + oneYearLong;
|
|
|
+ Date km2oneYear = new Date(x);
|
|
|
+ gv.setSubject2(km2oneYear);
|
|
|
+ videoVipService.updateGzptVideoVipByUserId(gv);
|
|
|
+ } else { //会员时间延长
|
|
|
+ long x = km2Date.getTime() + oneYearLong;
|
|
|
+ Date km2oneYear = new Date(x);
|
|
|
+ gv.setSubject2(km2oneYear);
|
|
|
+ videoVipService.updateGzptVideoVipByUserId(gv);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //新增会员信息
|
|
|
+ GzptVideoVip videoVip = new GzptVideoVip();
|
|
|
+ videoVip.setUserId(wxJsOrder.getUserId());
|
|
|
+ videoVip.setUserName(wxJsOrder.getUserName());
|
|
|
+ long x = now.getTime() + oneYearLong;
|
|
|
+ Date km2oneYear = new Date(x);
|
|
|
+ videoVip.setSubject2(km2oneYear);
|
|
|
+ System.out.println(videoVip);
|
|
|
+ videoVipService.saveGzptVideoVip(videoVip);
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if ("科目三视频".equals(wxJsOrder.getGoodsName())) {
|
|
|
+ GzptVideoVipDTO gzptVideoVipDTO = new GzptVideoVipDTO();
|
|
|
+ gzptVideoVipDTO.setUserId(wxJsOrder.getUserId());
|
|
|
+ GzptVideoVip gv = videoVipService.getGzptVideoVipByUserId(gzptVideoVipDTO);
|
|
|
+ if(gv!=null) {
|
|
|
+ //修改会员信息
|
|
|
+ Date km3Date = gv.getSubject3();
|
|
|
+ if(km3Date!=null) { //存在会员时间
|
|
|
+ if(km3Date.compareTo(now)<0) { //会员已过期
|
|
|
+ long x = now.getTime() + oneYearLong;
|
|
|
+ Date km3oneYear = new Date(x);
|
|
|
+ gv.setSubject3(km3oneYear);
|
|
|
+ videoVipService.updateGzptVideoVipByUserId(gv);
|
|
|
+ } else { //会员时间延长
|
|
|
+ long x = km3Date.getTime() + oneYearLong;
|
|
|
+ Date km3oneYear = new Date(x);
|
|
|
+ gv.setSubject3(km3oneYear);
|
|
|
+ videoVipService.updateGzptVideoVipByUserId(gv);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //新增会员信息
|
|
|
+ GzptVideoVip videoVip = new GzptVideoVip();
|
|
|
+ videoVip.setUserId(wxJsOrder.getUserId());
|
|
|
+ videoVip.setUserName(wxJsOrder.getUserName());
|
|
|
+ long x = now.getTime() + oneYearLong;
|
|
|
+ Date km3oneYear = new Date(x);
|
|
|
+ videoVip.setSubject3(km3oneYear);
|
|
|
+ videoVipService.saveGzptVideoVip(videoVip);
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if ("全套实操视频".equals(wxJsOrder.getGoodsName())) {
|
|
|
+ GzptVideoVipDTO gzptVideoVipDTO = new GzptVideoVipDTO();
|
|
|
+ gzptVideoVipDTO.setUserId(wxJsOrder.getUserId());
|
|
|
+ GzptVideoVip gv = videoVipService.getGzptVideoVipByUserId(gzptVideoVipDTO);
|
|
|
+ if(gv!=null) {
|
|
|
+ //修改会员信息
|
|
|
+ Date km2Date = gv.getSubject2();
|
|
|
+ Date km3Date = gv.getSubject3();
|
|
|
+ if(km2Date!=null) { //科目二处理
|
|
|
+ long x = km2Date.getTime() + oneYearLong;
|
|
|
+ Date km2oneYear = new Date(x);
|
|
|
+ gv.setSubject2(km2oneYear);
|
|
|
+ } else {
|
|
|
+ long x = now.getTime() + oneYearLong;
|
|
|
+ Date km2oneYear = new Date(x);
|
|
|
+ gv.setSubject2(km2oneYear);
|
|
|
+ }
|
|
|
+ if(km3Date!=null) { //科目三处理
|
|
|
+ long x = km3Date.getTime() + oneYearLong;
|
|
|
+ Date km3oneYear = new Date(x);
|
|
|
+ gv.setSubject3(km3oneYear);
|
|
|
+ } else {
|
|
|
+ long x = now.getTime() + oneYearLong;
|
|
|
+ Date km3oneYear = new Date(x);
|
|
|
+ gv.setSubject3(km3oneYear);
|
|
|
+ }
|
|
|
+ videoVipService.updateGzptVideoVipByUserId(gv);
|
|
|
+ } else {
|
|
|
+ //新增会员信息
|
|
|
+ GzptVideoVip videoVip = new GzptVideoVip();
|
|
|
+ videoVip.setUserId(wxJsOrder.getUserId());
|
|
|
+ videoVip.setUserName(wxJsOrder.getUserName());
|
|
|
+ long x = now.getTime() + oneYearLong;
|
|
|
+ Date oneYear = new Date(x);
|
|
|
+ videoVip.setSubject2(oneYear);
|
|
|
+ videoVip.setSubject3(oneYear);
|
|
|
+ videoVipService.saveGzptVideoVip(videoVip);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private String getSourString(WxpayNotifyDTO wxpayNotifyDTO) throws GeneralSecurityException, IOException {
|