浏览代码

退款接口增加

小么熊🐻 3 年之前
父节点
当前提交
f91322d167

+ 56 - 12
jsjp-admin/src/main/java/com/miaxis/app/controller/wx/WxNotifyController.java

@@ -172,6 +172,7 @@ public class WxNotifyController {
 
     private void writeRefundNotifyDataToDb(JSONObject jsonObject) {
         String refundId = jsonObject.getString("refund_id");
+        String outTradeNo = jsonObject.getString("out_trade_no");
         RefundRecord refundRecord = refundRecordService.getByRefundId(refundId);
         if (refundRecord == null) {
             log.error("该退款订单不存在");
@@ -181,6 +182,61 @@ public class WxNotifyController {
         refundRecord.setUserReceivedAccount(jsonObject.getString("user_received_account"));
         refundRecord.setStatus(jsonObject.getString("refund_status"));
         refundRecordService.updateById(refundRecord);
+
+        if("SUCCESS".equals(refundRecord.getStatus())){
+            //退款成功
+            long oneYearLong = 1000*60*60*24*365l;
+            WxJsOrder wxJsOrder= wxJsOrderService.getByOutTradeNo(outTradeNo);
+            if ("科目二视频".equals(wxJsOrder.getGoodsName())){
+                GzptVideoVipDTO gzptVideoVipDTO = new GzptVideoVipDTO();
+                gzptVideoVipDTO.setUserId(wxJsOrder.getUserId());
+                GzptVideoVip gv = videoVipService.getGzptVideoVipByUserIdForLocal(gzptVideoVipDTO);
+                if(gv!=null) {
+                    //修改会员信息
+                    Date km2Date = gv.getSubject2();
+                    if(km2Date!=null) {  //扣掉一年时间
+                        long x = km2Date.getTime() - oneYearLong;
+                        Date km2oneYear = new Date(x);
+                        gv.setSubject2(km2oneYear);
+                        videoVipService.updateGzptVideoVipByUserId(gv);
+                    }
+                }
+            } else if ("科目三视频".equals(wxJsOrder.getGoodsName())) {
+                GzptVideoVipDTO gzptVideoVipDTO = new GzptVideoVipDTO();
+                gzptVideoVipDTO.setUserId(wxJsOrder.getUserId());
+                GzptVideoVip gv = videoVipService.getGzptVideoVipByUserIdForLocal(gzptVideoVipDTO);
+                if(gv!=null) {
+                    //修改会员信息
+                    Date km3Date = gv.getSubject3();
+                    if(km3Date!=null) {  //扣掉一年时间
+                        long x = km3Date.getTime() - oneYearLong;
+                        Date km3oneYear = new Date(x);
+                        gv.setSubject3(km3oneYear);
+                        videoVipService.updateGzptVideoVipByUserId(gv);
+                    }
+                }
+            }  else if ("全套实操视频".equals(wxJsOrder.getGoodsName())) {
+                GzptVideoVipDTO gzptVideoVipDTO = new GzptVideoVipDTO();
+                gzptVideoVipDTO.setUserId(wxJsOrder.getUserId());
+                GzptVideoVip gv = videoVipService.getGzptVideoVipByUserIdForLocal(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);
+                    }
+                    if(km3Date!=null) {  //扣掉一年时间
+                        long x = km3Date.getTime() - oneYearLong;
+                        Date km3oneYear = new Date(x);
+                        gv.setSubject3(km3oneYear);
+                    }
+                    videoVipService.updateGzptVideoVipByUserId(gv);
+                }
+            }
+        }
     }
 
 
@@ -221,18 +277,6 @@ public class WxNotifyController {
         wxJsOrderService.updateById(wxJsOrder);
     }
 
-//    public static void main(String[] args) {
-//        Date date = DateUtils.parseDate("2021-03-04");
-//        Date now = new Date();
-//
-//        if(date.compareTo(now)<0){
-//            System.out.println("11111111111");
-//        } else {
-//
-//            System.out.println("33333333333");
-//        }
-//
-//    }
 
 
     @Transactional

+ 123 - 0
jsjp-admin/src/main/java/com/miaxis/pc/controller/order/WxJsOrderController.java

@@ -0,0 +1,123 @@
+package com.miaxis.pc.controller.order;
+
+import com.miaxis.common.annotation.Log;
+import com.miaxis.common.core.controller.BaseController;
+import com.miaxis.common.core.domain.Response;
+import com.miaxis.common.core.page.ResponsePageInfo;
+import com.miaxis.common.enums.BusinessTypeEnum;
+import com.miaxis.common.utils.OrderCodeFactory;
+import com.miaxis.common.utils.poi.ExcelUtil;
+import com.miaxis.wx.domain.WxJsOrder;
+import com.miaxis.wx.dto.WxJsOrderOutTradeNoDTO;
+import com.miaxis.wx.dto.WxNotifyReturnDTO;
+import com.miaxis.wx.service.IRefundRecordService;
+import com.miaxis.wx.service.IWxJsOrderService;
+import io.swagger.annotations.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * 【订单】Controller
+ *
+ * @author miaxis
+ * @date 2022-03-25
+ */
+@RestController
+@RequestMapping("/order/info")
+@Api(tags={"【PC-订单】"})
+public class WxJsOrderController extends BaseController{
+    @Autowired
+    private IWxJsOrderService wxJsOrderService;
+
+    @Autowired
+    private IRefundRecordService refundRecordService;
+
+    /**
+     * 查询订单列表
+     */
+
+    @PreAuthorize("@ss.hasPermi('order:info:query')")
+    @GetMapping("/list")
+    @ApiOperation("查询订单列表")
+        @ApiImplicitParams({
+            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
+            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
+    })
+    public ResponsePageInfo<WxJsOrder> list(@ModelAttribute WxJsOrder wxJsOrder){
+        startPage();
+        List<WxJsOrder> list = wxJsOrderService.selectWxJsOrderList(wxJsOrder);
+        return toResponsePageInfo(list);
+    }
+
+
+
+
+
+    /**
+     * 获取订单详细信息
+     */
+    @PreAuthorize("@ss.hasPermi('order:info:query')")
+    @GetMapping(value = "/{id}")
+    @ApiOperation("获取订单详细信息")
+    public Response<WxJsOrder> getInfo(
+            @ApiParam(name = "id", value = "订单参数", required = true)
+            @PathVariable("id") Long id
+    ){
+        return Response.success(wxJsOrderService.getById(id));
+    }
+
+    /**
+     * 新增订单
+     */
+    @PreAuthorize("@ss.hasPermi('order:info:add')")
+    @Log(title = "订单", businessType = BusinessTypeEnum.INSERT)
+    @PostMapping
+    @ApiOperation("新增订单")
+    public Response<Integer> add(@RequestBody WxJsOrder wxJsOrder){
+        return toResponse(wxJsOrderService.save(wxJsOrder) ? 1 : 0);
+    }
+
+    /**
+     * 修改订单
+     */
+    @PreAuthorize("@ss.hasPermi('order:info:edit')")
+    @Log(title = "订单", businessType = BusinessTypeEnum.UPDATE)
+    @PutMapping
+    @ApiOperation("修改订单")
+    public Response<Integer> edit(@RequestBody WxJsOrder wxJsOrder){
+        return toResponse(wxJsOrderService.updateById(wxJsOrder) ? 1 : 0);
+    }
+
+    /**
+     * 删除订单
+     */
+    @PreAuthorize("@ss.hasPermi('order:info:remove')")
+    @Log(title = "订单", businessType = BusinessTypeEnum.DELETE)
+	@DeleteMapping("/{ids}")
+    @ApiOperation("删除订单")
+    public  Response<Integer> remove(
+            @ApiParam(name = "ids", value = "订单ids参数", required = true)
+            @PathVariable Long[] ids
+    ){
+        return toResponse(wxJsOrderService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
+    }
+
+
+    /**
+     * 订单退款
+     */
+    @PreAuthorize("@ss.hasPermi('order:info:refund')")
+    @Log(title = "订单", businessType = BusinessTypeEnum.UPDATE)
+    @PostMapping("/refund")
+    @ApiOperation("订单退款")
+    public Response<WxNotifyReturnDTO> refund(@RequestBody WxJsOrderOutTradeNoDTO wxJsOrderOutTradeNoDTO) throws Exception {
+        WxJsOrder wxJsOrder = wxJsOrderService.getByOutTradeNo(wxJsOrderOutTradeNoDTO.getOutTradeNo());
+        WxNotifyReturnDTO wxNotifyReturnDTO = refundRecordService.refund(wxJsOrder, OrderCodeFactory.getOrderCode(null), wxJsOrderOutTradeNoDTO.getReason());
+        return Response.success(wxNotifyReturnDTO);
+    }
+
+}

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

@@ -81,8 +81,8 @@ public class NewGzptTest {
 
     @Test
     public void test5() throws Exception {
-        WxJsOrder wxJsOrder = wxJsOrderService.getByOutTradeNo("12022022414151693733762448070264");
-        refundRecordService.refund(wxJsOrder, OrderCodeFactory.getOrderCode(null), "测试退款111");
+        WxJsOrder wxJsOrder = wxJsOrderService.getByOutTradeNo("12022032418011181183838613119074");
+        refundRecordService.refund(wxJsOrder, OrderCodeFactory.getOrderCode(null), "测试退款111BBQ");
     }
 
 

+ 0 - 4
jsjp-service/src/main/java/com/miaxis/wx/domain/WxJsOrder.java

@@ -50,26 +50,22 @@ public class WxJsOrder extends BaseBusinessEntity{
 
 
     /** 商户订单号 */
-    @Excel(name = "商户订单号")
     @TableField("out_trade_no")
     @ApiModelProperty(value = "商户订单号")
     private String outTradeNo;
 
     /** 退款单号 */
-    @Excel(name = "退款单号")
     @TableField("out_refund_no")
     @ApiModelProperty(value = "退款单号")
     private String outRefundNo;
 
     /** 退款原因 */
-    @Excel(name = "退款原因")
     @TableField("refund_reason")
     @ApiModelProperty(value = "退款原因")
     private String refundReason;
 
 
     /** 微信支付系统生成的订单号 */
-    @Excel(name = "微信支付系统生成的订单号")
     @TableField("transaction_id")
     @ApiModelProperty(value = "微信支付系统生成的订单号")
     private String transactionId;

+ 24 - 0
jsjp-service/src/main/java/com/miaxis/wx/dto/WxJsOrderOutTradeNoDTO.java

@@ -0,0 +1,24 @@
+package com.miaxis.wx.dto;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+public class WxJsOrderOutTradeNoDTO {
+    private static final long serialVersionUID = 1L;
+
+
+
+    /** 商户订单号 */
+    @ApiModelProperty(value = "商户订单号",required = true)
+    private String outTradeNo;
+
+    /**
+     * 退款原因
+     */
+    @ApiModelProperty(value = "退款原因",required = true)
+    private String reason;
+
+
+}

+ 1 - 0
jsjp-service/src/main/java/com/miaxis/wx/mapper/WxJsOrderMapper.java

@@ -18,4 +18,5 @@ public interface WxJsOrderMapper extends BaseMapper<WxJsOrder> {
     WxJsOrder getByOutTradeNo(String outTradeNo);
 
     List<WxJsOrder> selectWxJsOrderList(WxJsOrder WxJsOrder);
+
 }

+ 10 - 0
jsjp-service/src/main/java/com/miaxis/wx/service/IWxJsOrderService.java

@@ -3,6 +3,8 @@ package com.miaxis.wx.service;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.miaxis.wx.domain.WxJsOrder;
 
+import java.util.List;
+
 /**
  */
 public interface IWxJsOrderService extends IService<WxJsOrder>{
@@ -12,5 +14,13 @@ public interface IWxJsOrderService extends IService<WxJsOrder>{
 
     public WxJsOrder getByOutTradeNo(String outTradeNo);
 
+    /**
+     * 查询订单列表
+     *
+     * @param wxJsOrder 订单
+     * @return 订单集合
+     */
+    public List<WxJsOrder> selectWxJsOrderList(WxJsOrder wxJsOrder);
+
 
 }

+ 12 - 2
jsjp-service/src/main/java/com/miaxis/wx/service/impl/RefundRecordServiceImpl.java

@@ -6,11 +6,11 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.miaxis.common.config.WxpayConfig;
 import com.miaxis.common.exception.CustomException;
-import com.miaxis.wx.domain.WxJsOrder;
-import com.miaxis.wx.domain.WxOrder;
 import com.miaxis.wx.domain.RefundRecord;
+import com.miaxis.wx.domain.WxJsOrder;
 import com.miaxis.wx.dto.WxNotifyReturnDTO;
 import com.miaxis.wx.mapper.RefundRecordMapper;
+import com.miaxis.wx.mapper.WxJsOrderMapper;
 import com.miaxis.wx.service.IRefundRecordService;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
@@ -36,6 +36,9 @@ public class RefundRecordServiceImpl extends ServiceImpl<RefundRecordMapper, Ref
     @Resource
     private RefundRecordMapper refundRecordMapper;
 
+    @Resource
+    private WxJsOrderMapper wxJsOrderMapper;
+
     @Autowired
     private HttpClient httpClient;
 
@@ -73,9 +76,16 @@ public class RefundRecordServiceImpl extends ServiceImpl<RefundRecordMapper, Ref
 //        objectMapper.writeValue(bos, rootNode);
         httpPost.setEntity(new StringEntity(rootNode.toString(), "utf-8"));
         HttpResponse response = httpClient.execute(httpPost);
+
+
         // 返回数据:
         String bodyAsString = EntityUtils.toString(response.getEntity());
         if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
+            //更新这个字段
+            wxJsOrder.setOutRefundNo(refundCode);
+            wxJsOrder.setRefundReason(failCause);
+            wxJsOrderMapper.updateById(wxJsOrder);
+
             //  保存退款数据到数据库
             RefundRecord refundRecord = new RefundRecord();
             JSONObject jsonObject = JSONObject.parseObject(bodyAsString);

+ 12 - 0
jsjp-service/src/main/java/com/miaxis/wx/service/impl/WxJsOrderServiceImpl.java

@@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.util.List;
 
 /**
  * 电影订单Service业务层处理
@@ -27,4 +28,15 @@ public class WxJsOrderServiceImpl extends ServiceImpl<WxJsOrderMapper, WxJsOrder
     public WxJsOrder getByOutTradeNo(String outTradeNo) {
         return wxJsOrderMapper.getByOutTradeNo(outTradeNo);
     }
+
+    /**
+     * 查询订单列表
+     *
+     * @param wxJsOrder 订单
+     * @return 订单
+     */
+    @Override
+    public List<WxJsOrder> selectWxJsOrderList(WxJsOrder wxJsOrder){
+        return wxJsOrderMapper.selectWxJsOrderList(wxJsOrder);
+    }
 }

+ 16 - 17
jsjp-service/src/main/resources/mapper/wx/WxJsOrderMapper.xml

@@ -38,25 +38,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
 
     <select id="selectWxJsOrderList" parameterType="WxJsOrder" resultMap="WxJsOrderResult">
-        <include refid="selectWxJsOrderVo"/>
+        select w.*,r.refund,r.status from wx_js_order w left join refund_record r ON w.out_refund_no = r.out_refund_no
         <where>
             <if test="userId!=null"> and user_id = #{userId}</if>
-            <if test="userName!=null and userName!=''"> and user_name = #{userName}</if>
-            <if test="outTradeNo != null "> and out_trade_no = #{outTradeNo}</if>
-            <if test="transactionId != null  and transactionId != ''"> and transaction_id = #{transactionId}</if>
-            <if test="tradeType != null  and tradeType != ''"> and trade_type = #{tradeType}</if>
-            <if test="tradeState != null  and tradeState != ''"> and trade_state = #{tradeState}</if>
-            <if test="tradeStateDesc != null  and tradeStateDesc != ''"> and trade_state_desc = #{tradeStateDesc}</if>
-            <if test="bankType != null  and bankType != ''"> and bank_type = #{bankType}</if>
-            <if test="attach != null  and attach != ''"> and attach = #{attach}</if>
-            <if test="successTime != null "> and success_time = #{successTime}</if>
-            <if test="openid != null  and openid != ''"> and openid = #{openid}</if>
-            <if test="goodsName != null  and goodsName != ''"> and goods_name like concat('%', #{goodsName}, '%')</if>
-            <if test="total != null "> and total = #{total}</if>
-            <if test="payerTotal != null "> and payer_total = #{payerTotal}</if>
-            <if test="currency != null  and currency != ''"> and currency = #{currency}</if>
-            <if test="payerCurrency != null  and payerCurrency != ''"> and payer_currency = #{payerCurrency}</if>
-            <if test="orderStatus != null  and orderStatus != ''"> and order_state = #{orderStatus}</if>
+            <if test="userName!=null and userName!=''"> and w.user_name = #{userName}</if>
+            <if test="outTradeNo != null and outTradeNo!=''"> and w.out_trade_no = #{outTradeNo}</if>
+            <if test="transactionId != null  and transactionId != ''"> and w.transaction_id = #{transactionId}</if>
+            <if test="tradeType != null  and tradeType != ''"> and w.trade_type = #{tradeType}</if>
+            <if test="tradeState != null  and tradeState != ''"> and w.trade_state = #{tradeState}</if>
+            <if test="tradeStateDesc != null  and tradeStateDesc != ''"> and w.trade_state_desc = #{tradeStateDesc}</if>
+            <if test="bankType != null  and bankType != ''"> and w.bank_type = #{bankType}</if>
+            <if test="attach != null  and attach != ''"> and w.attach = #{attach}</if>
+            <if test="successTime != null "> and w.success_time = #{successTime}</if>
+            <if test="goodsName != null  and goodsName != ''"> and w.goods_name like concat('%', #{goodsName}, '%')</if>
+            <if test="total != null "> and w.total = #{total}</if>
+            <if test="payerTotal != null "> and w.payer_total = #{payerTotal}</if>
+            <if test="currency != null  and currency != ''"> and w.currency = #{currency}</if>
+            <if test="payerCurrency != null  and payerCurrency != ''"> and w.payer_currency = #{payerCurrency}</if>
+            <if test="orderStatus != null  and orderStatus != ''"> and w.order_state = #{orderStatus}</if>
         </where>
     </select>