瀏覽代碼

微信支付退款问题

小么熊🐻 3 年之前
父節點
當前提交
c370913a7d

+ 54 - 0
jsjp-admin/src/main/java/com/miaxis/app/controller/gzpt/GzptDictDataController.java

@@ -0,0 +1,54 @@
+package com.miaxis.app.controller.gzpt;
+
+
+import com.miaxis.common.constant.Constants;
+import com.miaxis.common.core.controller.BaseController;
+import com.miaxis.common.core.domain.Response;
+import com.miaxis.common.core.domain.entity.SysDictData;
+import com.miaxis.common.core.domain.entity.UserInfo;
+import com.miaxis.common.exception.CustomException;
+import com.miaxis.common.utils.SecurityUtils;
+import com.miaxis.newgzpt.domain.GzptUserInfo;
+import com.miaxis.newgzpt.dto.GzptUserInfoDTO;
+import com.miaxis.newgzpt.service.IGzptUserInfoService;
+import com.miaxis.system.service.ISysDictDataService;
+import com.miaxis.system.service.ISysDictTypeService;
+import com.miaxis.user.service.IUserInfoService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+/**
+ * <p>
+ * 学员基本信息表 前端控制器
+ * </p>
+ *
+ * @since 2021-03-09
+ */
+@RestController
+@Api(tags = "【app-字典信息查询】")
+@RequestMapping(Constants.OPEN_PREFIX+"/gzpt/userInfo")
+public class GzptDictDataController extends BaseController {
+
+
+    @Autowired
+    private ISysDictTypeService dictTypeService;
+
+    /**
+     * 根据字典类型查询字典数据信息
+     */
+    @GetMapping(value = "/type/{dictType}")
+    @ApiOperation("根据字典类型查询字典数据信息")
+    public Response<List<SysDictData>> dictType(
+            @ApiParam(name = "dictType", value = "根据字典类型查询字典数据信息", required = true)
+            @PathVariable("dictType") String dictType
+    ){
+        return Response.success(dictTypeService.selectDictDataByType(dictType));
+    }
+
+}
+

+ 132 - 5
jsjp-admin/src/main/java/com/miaxis/app/controller/wx/WxNotifyController.java

@@ -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 {

+ 2 - 2
jsjp-admin/src/main/resources/application-prod.yml

@@ -126,8 +126,8 @@ wxpay:
     merchantId: 1611324484
     serialNumber: 53EBF541F383371B121D7B57B25305FC0BB04F42
     v3key: 7hM14893GvG3JK05575jk1l6P4tF042B
-    notifyUrl: http://admin.zzxcx.net/prod-api/open-api/wx/notify/wxpay
-    notifyUrlRefund: http://admin.zzxcx.net/prod-api/open-api/wx/notify/refund
+    notifyUrl: https://jsjp.zzxcx.net/prod-api/open-api/wx/notify/wxpay
+    notifyUrlRefund: https://jsjp.zzxcx.net/prod-api/open-api/wx/notify/refund
 
 
 # 电影

+ 2 - 2
jsjp-admin/src/main/resources/application-prodtest.yml

@@ -127,8 +127,8 @@ wxpay:
     merchantId: 1611324484
     serialNumber: 53EBF541F383371B121D7B57B25305FC0BB04F42
     v3key: 7hM14893GvG3JK05575jk1l6P4tF042B
-    notifyUrl: http://admin.zzxcx.net/prod-api/open-api/wx/notify/wxpay
-    notifyUrlRefund: http://admin.zzxcx.net/prod-api/open-api/wx/notify/refund
+    notifyUrl: http://218.85.55.253:8888/open-api/wx/notify/wxpay
+    notifyUrlRefund: http://218.85.55.253:8888/open-api/wx/notify/refund
 
 
 # 电影

+ 43 - 12
jsjp-admin/src/test/java/com/miaxis/test/NewGzptTest.java

@@ -3,18 +3,25 @@ package com.miaxis.test;
 
 import com.miaxis.JsjpApplication;
 import com.miaxis.common.utils.DateUtils;
+import com.miaxis.common.utils.OrderCodeFactory;
 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.WxJsOrder;
+import com.miaxis.wx.service.IRefundRecordService;
+import com.miaxis.wx.service.IWxJsOrderService;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ActiveProfiles;
 import org.springframework.test.context.junit4.SpringRunner;
 
 import java.util.Date;
 
+@ActiveProfiles("prodtest")
 @SpringBootTest(classes = JsjpApplication.class)
 @RunWith(SpringRunner.class)
 public class NewGzptTest {
@@ -25,24 +32,29 @@ public class NewGzptTest {
     @Autowired
     private IGzptVideoVipService gzptVideoVipService;
 
+    @Autowired
+    private IWxJsOrderService wxJsOrderService;
+
+    @Autowired
+    private IRefundRecordService refundRecordService;
+
     @Test
     public void test1() throws Exception {
         //      List<GzptUserInfo> list = gzptUserInfoService.getList();
 
-        GzptUserInfo gzptUserInfo = gzptUserInfoService.getInfoById(68l);
+        GzptUserInfo gzptUserInfo = gzptUserInfoService.getInfoById(69l);
         System.out.println(gzptUserInfo);
     }
 
     @Test
     public void test2() throws Exception {
         GzptVideoVip videoVip = new GzptVideoVip();
-        videoVip.setUserId(68l);
+        videoVip.setUserId(70l);
         videoVip.setUserName("测试");
-        videoVip.setLogincode("510106199511184265");
-        videoVip.setSubject1(new Date());
         videoVip.setSubject2(new Date());
-        videoVip.setSubject3(new Date());
-        videoVip.setSubject4(new Date());
+        videoVip.setSubject3(null);
+        System.out.println(videoVip);
+       // videoVip.setSubject3(new Date());
         gzptVideoVipService.saveGzptVideoVip(videoVip);
     }
 
@@ -50,20 +62,39 @@ public class NewGzptTest {
     @Test
     public void test3() throws Exception {
         GzptVideoVip videoVip = new GzptVideoVip();
-        videoVip.setUserId(68l);
+        videoVip.setUserId(69l);
         videoVip.setUserName("测试2");
-        videoVip.setLogincode("510106199511184265");
 
-        Date d1 = DateUtils.parseDate("2021-01-01 12:00:00");
         Date d2 = DateUtils.parseDate("2022-01-01 12:00:00");
         Date d3 = DateUtils.parseDate("2023-01-01 12:00:00");
-        Date d4 = DateUtils.parseDate("2024-01-01 15:00:00");
-        videoVip.setSubject1(d1);
         videoVip.setSubject2(d2);
         videoVip.setSubject3(d3);
-        videoVip.setSubject4(d4);
         gzptVideoVipService.updateGzptVideoVipByUserId(videoVip);
     }
+    @Test
+    public void test4() throws Exception {
+        GzptVideoVipDTO gzptVideoVipDTO = new GzptVideoVipDTO();
+        gzptVideoVipDTO.setUserId(68l);
+        GzptVideoVip gv = gzptVideoVipService.getGzptVideoVipByUserId(gzptVideoVipDTO);
+        System.out.println(gv);
+    }
+
+    @Test
+    public void test5() throws Exception {
+        WxJsOrder wxJsOrder = wxJsOrderService.getByOutTradeNo("12022022414170685733762487935546");
+        refundRecordService.refund(wxJsOrder, OrderCodeFactory.getOrderCode(null), "测试退款");
+    }
+
 
 
+    public static void main(String[] args) {
+        long oneYearLong = 1000*60*60*24*365l;
+        Date now = new Date();
+        long x = now.getTime() + oneYearLong;
+        Date new1 =new Date(x);
+        System.out.println(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",now));
+        System.out.println(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",new1));
+
+
+    }
 }

+ 0 - 13
jsjp-service/src/main/java/com/miaxis/newgzpt/domain/GzptVideoVip.java

@@ -40,14 +40,6 @@ public class GzptVideoVip implements Serializable {
     @TableField("USER_NAME")
     private String userName;
 
-    @ApiModelProperty(value = "登录帐号")
-    @TableField("LOGINCODE")
-    private String logincode;
-
-    @ApiModelProperty(value = "科目1  到期时间")
-    @TableField("SUBJECT1")
-    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
-    private Date subject1;
 
     @ApiModelProperty(value = "科目2  到期时间")
     @TableField("SUBJECT2")
@@ -59,10 +51,5 @@ public class GzptVideoVip implements Serializable {
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private Date subject3;
 
-    @ApiModelProperty(value = "科目4  到期时间")
-    @TableField("SUBJECT4")
-    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
-    private Date subject4;
-
 
 }

+ 0 - 3
jsjp-service/src/main/java/com/miaxis/wx/service/impl/RefundRecordServiceImpl.java

@@ -55,9 +55,6 @@ public class RefundRecordServiceImpl extends ServiceImpl<RefundRecordMapper, Ref
 
     @Override
     public WxNotifyReturnDTO refund(WxJsOrder wxJsOrder, String refundCode, String failCause) throws Exception{
-        if (failCause.length()>80){
-            failCause = "购买失败,详情请在小程序查看";
-        }
         HttpPost httpPost = new HttpPost(wxpayConfig.getV3urlRefund());
         httpPost.addHeader("Accept", "application/json");
         httpPost.addHeader("Content-type","application/json; charset=utf-8");

+ 4 - 7
jsjp-service/src/main/resources/mapper/newgzpt/GzptVideoVipMapper.xml

@@ -6,17 +6,14 @@
     <insert id="saveGzptVideoVip" parameterType="com.miaxis.newgzpt.domain.GzptVideoVip">
         insert into GZPT_VIDEO_VIP VALUES (seq_gzpt_video_vip.nextval,
                                                  #{userId},
-                                                 #{userName},
-                                                 #{logincode},
-                                                 #{subject1},
-                                                 #{subject2},
-                                                 #{subject3},
-                                                 #{subject4})
+                                                 #{userName,jdbcType=VARCHAR},
+                                                 #{subject2,jdbcType=DATE},
+                                                 #{subject3,jdbcType=DATE})
     </insert>
 
     <update id="updateGzptVideoVipByUserId" parameterType="com.miaxis.newgzpt.domain.GzptVideoVip">
         update GZPT_VIDEO_VIP
-        set SUBJECT1 = #{subject1}, SUBJECT2 = #{subject2}, SUBJECT3 = #{subject3}, SUBJECT4 = #{subject4}
+        set SUBJECT2 = #{subject2,jdbcType=DATE}, SUBJECT3 = #{subject3,jdbcType=DATE}
         where user_id = #{userId}
     </update>
 

+ 0 - 5
src/main/resources/mapper/VideoVipMapper.xml

@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.miaxis.gzpt.mapper.VideoVipMapper">
-
-</mapper>