Browse Source

支付与退款操作

小么熊🐻 2 years ago
parent
commit
8a3bbe9419
22 changed files with 244 additions and 420 deletions
  1. 11 15
      nbjk-admin/src/main/java/com/miaxis/app/controller/wx/WxController.java
  2. 4 0
      nbjk-admin/src/main/java/com/miaxis/app/controller/wx/WxNotifyController.java
  3. 86 0
      nbjk-admin/src/main/java/com/miaxis/pc/controller/PcOrderInfoController.java
  4. 2 2
      nbjk-admin/src/main/resources/application-dev.yml
  5. 2 2
      nbjk-admin/src/main/resources/application-prod.yml
  6. 0 120
      nbjk-admin/src/main/resources/application-prodtest.yml
  7. 5 2
      nbjk-admin/src/test/java/com/miaxis/test/NormalTest.java
  8. 5 59
      nbjk-service/src/main/java/com/miaxis/exam/domain/ExamInfo.java
  9. 7 0
      nbjk-service/src/main/java/com/miaxis/order/domain/OrderInfo.java
  10. 1 31
      nbjk-service/src/main/java/com/miaxis/order/mapper/OrderInfoMapper.java
  11. 2 8
      nbjk-service/src/main/java/com/miaxis/order/service/IOrderInfoService.java
  12. 25 19
      nbjk-service/src/main/java/com/miaxis/order/service/impl/OrderInfoServiceImpl.java
  13. 1 69
      nbjk-service/src/main/java/com/miaxis/vip/domain/VipUserExam.java
  14. 2 0
      nbjk-service/src/main/java/com/miaxis/vip/mapper/VipUserExamMapper.java
  15. 2 0
      nbjk-service/src/main/java/com/miaxis/vip/service/IVipUserExamService.java
  16. 5 0
      nbjk-service/src/main/java/com/miaxis/vip/service/impl/VipUserExamServiceImpl.java
  17. 7 0
      nbjk-service/src/main/java/com/miaxis/wx/domain/WxOrder.java
  18. 5 4
      nbjk-service/src/main/java/com/miaxis/wx/dto/WxOrderDTO.java
  19. 32 11
      nbjk-service/src/main/java/com/miaxis/wx/service/impl/RefundRecordServiceImpl.java
  20. 12 47
      nbjk-service/src/main/resources/mapper/order/OrderInfoMapper.xml
  21. 6 2
      nbjk-service/src/main/resources/mapper/vip/VipUserExamMapper.xml
  22. 22 29
      nbjk-service/src/main/resources/mapper/wx/WxOrderMapper.xml

+ 11 - 15
nbjk-admin/src/main/java/com/miaxis/app/controller/wx/WxController.java

@@ -13,11 +13,9 @@ import com.miaxis.common.enums.OrderStatusEnum;
 import com.miaxis.common.exception.CustomException;
 import com.miaxis.common.utils.SecurityUtils;
 import com.miaxis.common.utils.uuid.CommonUtils;
-import com.miaxis.system.domain.SysConfig;
-import com.miaxis.system.service.ISysConfigService;
+import com.miaxis.exam.domain.ExamInfo;
+import com.miaxis.exam.service.IExamInfoService;
 import com.miaxis.system.service.ISysDictDataService;
-import com.miaxis.system.service.ISysDictTypeService;
-import com.miaxis.system.service.ISysUserService;
 import com.miaxis.wx.domain.WxOrder;
 import com.miaxis.wx.dto.WxOrderDTO;
 import com.miaxis.wx.service.IWxOrderService;
@@ -43,7 +41,6 @@ import java.io.File;
 import java.security.PrivateKey;
 import java.security.Signature;
 import java.util.Base64;
-import java.util.List;
 
 import static com.miaxis.common.utils.OrderCodeFactory.getOrderCode;
 
@@ -69,19 +66,19 @@ public class WxController extends BaseController {
     @Autowired
     private IWxOrderService wxOrderService;
 
-
     @Autowired
     private ISysDictDataService dictDataService;
 
+    @Autowired
+    private IExamInfoService examInfoService;
+
 
     @Value("${xcx.appid}")
     private String xcxAppid;
 
-
     @Value("${app.appid}")
     private String appid;
 
-
     @Value("${wxpay.notifyUrl}")
     private  String notifyUrl ;
 
@@ -195,7 +192,6 @@ public class WxController extends BaseController {
         String nonceStr;
         String timeStamp;
         String sign;
-
     }
 
 
@@ -207,12 +203,14 @@ public class WxController extends BaseController {
     @ApiOperation("微信小程序支付下单")
     public Response<JSONObject> xcxPrepareOrder(@RequestBody WxOrderDTO wxOrderDTO) throws Exception{
 
-        SysDictData sysDictData = dictDataService.selectDictDataById(wxOrderDTO.getDictCode());
-        String[] values = sysDictData.getDictValue().split(",");
+        ExamInfo examInfo = examInfoService.getById(wxOrderDTO.getExamId());
+
         //创建本地微信订单
         WxOrder order = new WxOrder();
         UserInfo userInfo = SecurityUtils.getLoginUser().getStudent();
         String orderCode = getOrderCode(userInfo.getId());
+        order.setGoodsId(wxOrderDTO.getExamId());
+        order.setGoodsName(examInfo.getName());
         order.setOutTradeNo(orderCode);
         order.setXcxOpenid(userInfo.getXcxOpenid());
         order.setAppOpenid(userInfo.getAppOpenid());
@@ -220,13 +218,11 @@ public class WxController extends BaseController {
         order.setUnionId(userInfo.getUnionId());
         order.setPhoneType(wxOrderDTO.getPhoneType()); //手机类型 1:苹果 2:安卓
         order.setForeType(wxOrderDTO.getForeType()); //前端类型 1:app 2:小程序 3:公众号
+        order.setTotal(examInfo.getPrice());
 
-        Double price = Double.parseDouble(values[0])*100;   //订单总额
-        int b =  new Double(price).intValue();
-        order.setTotal(b);
         order.setOrderStatus(OrderStatusEnum.PROCESSING.getCode());
         wxOrderService.save(order);
-        return Response.success(placeXcxWxOrder(order, sysDictData.getDictLabel()));
+        return Response.success(placeXcxWxOrder(order, examInfo.getName()));
 
 
     }

+ 4 - 0
nbjk-admin/src/main/java/com/miaxis/app/controller/wx/WxNotifyController.java

@@ -183,6 +183,10 @@ public class WxNotifyController {
         refundRecord.setUserReceivedAccount(jsonObject.getString("user_received_account"));
         refundRecord.setStatus(jsonObject.getString("refund_status"));
         refundRecordService.updateById(refundRecord);
+        if ("SUCCESS".equals(refundRecord.getStatus())) {
+            //退款成功
+
+        }
     }
 
 

+ 86 - 0
nbjk-admin/src/main/java/com/miaxis/pc/controller/PcOrderInfoController.java

@@ -0,0 +1,86 @@
+package com.miaxis.pc.controller;
+
+import com.miaxis.common.core.controller.BaseController;
+import com.miaxis.common.core.domain.Response;
+import com.miaxis.common.core.page.ResponsePageInfo;
+import com.miaxis.order.domain.OrderInfo;
+import com.miaxis.order.dto.OrderInfoDto;
+import com.miaxis.order.service.IOrderInfoService;
+import com.miaxis.wx.domain.WxOrder;
+import com.miaxis.wx.service.IRefundRecordService;
+import com.miaxis.wx.service.IWxOrderService;
+import io.swagger.annotations.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+import static com.miaxis.common.utils.OrderCodeFactory.getOrderCode;
+
+/**
+ * 【订单信息】Controller
+ *
+ * @author miaxis
+ * @date 2022-06-07
+ */
+@RestController
+@RequestMapping("/order/info")
+@Api(tags={"【PC-订单信息】"})
+public class PcOrderInfoController extends BaseController {
+    @Autowired
+    private IOrderInfoService orderInfoService;
+    @Autowired
+    private IWxOrderService wxOrderService;
+
+    @Autowired
+    private IRefundRecordService refundRecordService;
+
+    /**
+     * 查询订单信息列表
+     */
+    @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<OrderInfo> list(@ModelAttribute OrderInfoDto orderInfoDto){
+        startPage();
+        List<OrderInfo> list = orderInfoService.selectOrderInfoList(orderInfoDto);
+        return toResponsePageInfo(list);
+    }
+
+    /**
+     * 获取订单信息详细信息
+     */
+    @GetMapping(value = "/{id}")
+    @ApiOperation("获取订单信息详细信息")
+    public Response<OrderInfo> getInfo(
+            @ApiParam(name = "id", value = "订单信息参数", required = true)
+            @PathVariable("id") Long id
+    ){
+        return Response.success(orderInfoService.getById(id));
+    }
+
+
+    /**
+     * 发起退款
+     */
+    @PutMapping(value = "/refund/{outTradeNo}")
+    @ApiOperation("发起退款")
+    public Response<OrderInfo> refund(
+            @ApiParam(name = "outTradeNo", value = "订单信息参数", required = true)
+            @PathVariable("outTradeNo") String outTradeNo,
+            String reason
+    ) throws Exception {
+        String refundCode = getOrderCode(null);
+        WxOrder order = wxOrderService.getByOutTradeNo(outTradeNo);
+        refundRecordService.refund(order,refundCode,reason);
+        return Response.success();
+    }
+
+
+
+
+
+}

+ 2 - 2
nbjk-admin/src/main/resources/application-dev.yml

@@ -116,8 +116,8 @@ wxpay:
     merchantId: 1639487489
     serialNumber: 1304D67DC59D94217412C49E20D5B0E00A5A122D
     v3key: PIQKEpG1FEoBEELgv0GUxkUJKTkc0jGB
-    notifyUrl: http://nbjk-admin.zzxcx.net/prod-api/open-api/wx/notify/wxpay
-    notifyUrlRefund: http://nbjk-admin.zzxcx.net/prod-api/open-api/wx/notify/refund
+    notifyUrl: https://1a0j71808.imdo.co/open-api/wx/notify/wxpay
+    notifyUrlRefund: https://1a0j71808.imdo.co/open-api/wx/notify/refund
 
 
 

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

@@ -118,5 +118,5 @@ wxpay:
     merchantId: 1639487489
     serialNumber: 1304D67DC59D94217412C49E20D5B0E00A5A122D
     v3key: PIQKEpG1FEoBEELgv0GUxkUJKTkc0jGB
-    notifyUrl: http://nbjk-admin.zzxcx.net/prod-api/open-api/wx/notify/wxpay
-    notifyUrlRefund: http://nbjk-admin.zzxcx.net/prod-api/open-api/wx/notify/refund
+    notifyUrl: http://nbjk.zzxcx.net/prod-api/open-api/wx/notify/wxpay
+    notifyUrlRefund: http://nbjk.zzxcx.net/prod-api/open-api/wx/notify/refund

+ 0 - 120
nbjk-admin/src/main/resources/application-prodtest.yml

@@ -1,120 +0,0 @@
-# 数据源配置
-spring:
-    datasource:
-        type: com.alibaba.druid.pool.DruidDataSource
-#        driverClassName: com.mysql.cj.jdbc.Driver
-        druid:
-            # 主库数据源
-            master:
-                # url: jdbc:mysql://172.17.0.6:3306/nbjk?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true
-                url: jdbc:mysql://sh-cdb-2y9n2832.sql.tencentcdb.com:60123/nbjk?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true
-                username: root
-                password: Miaxis@2020
-            # 初始连接数
-            initialSize: 5
-            # 最小连接池数量
-            minIdle: 10
-            # 最大连接池数量
-            maxActive: 20
-            # 配置获取连接等待超时的时间
-            maxWait: 60000
-            # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
-            timeBetweenEvictionRunsMillis: 60000
-            # 配置一个连接在池中最小生存的时间,单位是毫秒
-            minEvictableIdleTimeMillis: 300000
-            # 配置一个连接在池中最大生存的时间,单位是毫秒
-            maxEvictableIdleTimeMillis: 900000
-            # 配置检测连接是否有效
-            validationQuery: SELECT 1 FROM DUAL
-            testWhileIdle: true
-            testOnBorrow: false
-            testOnReturn: false
-            webStatFilter:
-                enabled: true
-            statViewServlet:
-                enabled: true
-                # 设置白名单,不填则允许所有访问
-                allow:
-                url-pattern: /druid/*
-                # 控制台管理用户名和密码
-                login-username:
-                login-password:
-            filter:
-                stat:
-                    enabled: true
-                    # 慢SQL记录
-                    log-slow-sql: true
-                    slow-sql-millis: 1000
-                    merge-sql: true
-                wall:
-                    config:
-                        multi-statement-allow: true
-    cache:
-        type: redis
-    # redis 配置
-    redis:
-        database: 1
-        # 地址
-        host: sh-crs-lfzs3n8w.sql.tencentcdb.com
-        # 端口,默认为6379
-        port: 29466
-        # 密码
-        password: miaxis110
-        # 连接超时时间
-        timeout: 10s
-        lettuce:
-            pool:
-                # 连接池中的最小空闲连接
-                min-idle: 0
-                # 连接池中的最大空闲连接
-                max-idle: 8
-                # 连接池的最大数据库连接数
-                max-active: 8
-                # #连接池最大阻塞等待时间(使用负值表示没有限制)
-                max-wait: -1ms
-    mail:
-        # 配置 SMTP 服务器地址
-        host: smtp.163.com
-        # 发送者邮箱
-        username: xmze2023@163.com
-        # 配置密码,注意不是真正的密码,而是刚刚申请到的授权码
-        password: JOAHFDRHRSIQNVEL
-        # 端口号465或587
-        port: 25
-        # 默认的邮件编码为UTF-8
-        default-encoding: UTF-8
-        # 配置SSL 加密工厂
-        properties:
-            mail:
-                smtp:
-                    socketFactoryClass: javax.net.ssl.SSLSocketFactory
-                #表示开启 DEBUG 模式,这样,邮件发送过程的日志会在控制台打印出来,方便排查错误
-                debug: true
-
-# 微信app端
-app:
-    appId: wxfb80ed2dac7a6bb9
-    appSecret: ac7eb47efc59f3cdbec46d3bf3a68627
-
-# 微信公众号
-gzh:
-    appId: wx457ba48e0801c0b6
-    appSecret: 0212a4fc020cdc0c968eb17126d5fee1
-
-# 小程序
-xcx:
-    appId: wx97bbc22daac9362a
-    appSecret: e67435002c220ef2f69a1b43508c61ec
-
-
-
-# 微信支付
-wxpay:
-    v3url: https://api.mch.weixin.qq.com/v3/pay/transactions/app
-    v3JsUrl: https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi
-    v3urlRefund: https://api.mch.weixin.qq.com/v3/refund/domestic/refunds
-    merchantId: 1639487489
-    serialNumber: 1304D67DC59D94217412C49E20D5B0E00A5A122D
-    v3key: PIQKEpG1FEoBEELgv0GUxkUJKTkc0jGB
-    notifyUrl: http://nbjk-admin.zzxcx.net/prod-api/open-api/wx/notify/wxpay
-    notifyUrlRefund: http://nbjk-admin.zzxcx.net/prod-api/open-api/wx/notify/refund

+ 5 - 2
nbjk-admin/src/test/java/com/miaxis/test/NormalTest.java

@@ -2,6 +2,7 @@ package com.miaxis.test;
 
 import com.miaxis.NbjkApplication;
 import com.miaxis.score.service.IScoreInfoService;
+import com.miaxis.vip.service.IVipUserExamService;
 import com.miaxis.wx.service.IWxGzhService;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -23,10 +24,12 @@ public class NormalTest {
     private IWxGzhService wxGzhService;
 
 
+    @Autowired
+    private IVipUserExamService vipUserExamService;
+
     @Test
     public void test1() throws Exception {
-        wxGzhService.handlePublicMsg(null);
-
+        vipUserExamService.deleteVipUserExamByUnionIdAndGoodsId("o_cXm6Boi-diVB7oc5pgajA5Y-U0",1l);
 
     }
 

+ 5 - 59
nbjk-service/src/main/java/com/miaxis/exam/domain/ExamInfo.java

@@ -65,68 +65,14 @@ public class ExamInfo extends BaseBusinessEntity{
     @ApiModelProperty(value = "城市名称")
     private String city;
 
-    public void setId(Long id){
-        this.id = id;
-    }
 
-    public Long getId(){
-        return id;
-    }
-    public void setName(String name){
-        this.name = name;
-    }
-
-    public String getName(){
-        return name;
-    }
-    public void setImage(String image){
-        this.image = image;
-    }
-
-    public String getImage(){
-        return image;
-    }
-    public void setProvinceId(String provinceId){
-        this.provinceId = provinceId;
-    }
-
-    public String getProvinceId(){
-        return provinceId;
-    }
-    public void setProvince(String province){
-        this.province = province;
-    }
+    /** 城市名称 */
+    @Excel(name = "价格")
+    @TableField("price")
+    @ApiModelProperty(value = "价格")
+    private Integer price;
 
-    public String getProvince(){
-        return province;
-    }
-    public void setCityId(String cityId){
-        this.cityId = cityId;
-    }
 
-    public String getCityId(){
-        return cityId;
-    }
-    public void setCity(String city){
-        this.city = city;
-    }
 
-    public String getCity(){
-        return city;
-    }
 
-    @Override
-    public String toString() {
-        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
-            .append("id", getId())
-            .append("name", getName())
-            .append("image", getImage())
-            .append("provinceId", getProvinceId())
-            .append("province", getProvince())
-            .append("cityId", getCityId())
-            .append("city", getCity())
-            .append("createTime", getCreateTime())
-            .append("updateTime", getUpdateTime())
-            .toString();
-    }
 }

+ 7 - 0
nbjk-service/src/main/java/com/miaxis/order/domain/OrderInfo.java

@@ -29,6 +29,13 @@ public class OrderInfo extends BaseBusinessEntity{
     @ApiModelProperty(value = "主键")
     private Long id;
 
+
+    /** 商品ID */
+    @Excel(name = "商品ID")
+    @TableField("goods_id")
+    @ApiModelProperty(value = "商品ID")
+    private Long goodsId;
+
     /** 商品 */
     @Excel(name = "商品")
     @TableField("goods_name")

+ 1 - 31
nbjk-service/src/main/java/com/miaxis/order/mapper/OrderInfoMapper.java

@@ -23,36 +23,6 @@ public interface OrderInfoMapper extends BaseMapper<OrderInfo> {
      */
     public List<OrderInfo> selectOrderInfoList(OrderInfoDto orderInfo);
 
-    /**
-     * 查询今日收益
-     *
-     * @param orderInfo orderInfo
-     * @return orderInfo集合
-     */
-    public Integer selectTodayTotal(OrderInfoDto orderInfo);
 
-
-    /**
-     * 查询昨日收益
-     *
-     * @param orderInfo orderInfo
-     * @return orderInfo 集合
-     */
-    public Integer selectYesterdayTotal(OrderInfoDto orderInfo);
-
-    /**
-     * 总收益
-     *
-     * @param orderInfo orderInfo
-     * @return orderInfo 集合
-     */
-    public Integer selectTotal(OrderInfoDto orderInfo);
-
-
-    /**
-     * 按年查询每月收益
-     * @param orderInfoMonthDto
-     * @return
-     */
-    List<OrderInfoMonthVo> selectMonthIncome(OrderInfoMonthDto orderInfoMonthDto);
+    OrderInfo getByOutTradeNo(String outTradeNo);
 }

+ 2 - 8
nbjk-service/src/main/java/com/miaxis/order/service/IOrderInfoService.java

@@ -24,15 +24,9 @@ public interface IOrderInfoService extends IService<OrderInfo> {
      */
     List<OrderInfo> selectOrderInfoList(OrderInfoDto orderInfoDto);
 
-    Integer selectTotal(OrderInfoDto orderInfoDto);
-
-
-    Integer selectYesterdayTotal(OrderInfoDto orderInfoDto);
-
-    Integer selectTodayTotal(OrderInfoDto orderInfoDto);
 
+    void writeVipDataToDb(WxOrder wxOrder, int payType);
 
-    List<OrderInfoMonthVo> selectMonthIncome(OrderInfoMonthDto orderInfoMonthDto);
 
-    void writeVipDataToDb(WxOrder wxOrder, int payType);
+    OrderInfo getByOutTradeNo(String outTradeNo);
 }

+ 25 - 19
nbjk-service/src/main/java/com/miaxis/order/service/impl/OrderInfoServiceImpl.java

@@ -2,12 +2,17 @@ package com.miaxis.order.service.impl;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 
+import com.miaxis.exam.domain.ExamInfo;
+import com.miaxis.exam.service.IExamInfoService;
 import com.miaxis.order.domain.OrderInfo;
 import com.miaxis.order.dto.OrderInfoDto;
 import com.miaxis.order.dto.OrderInfoMonthDto;
 import com.miaxis.order.mapper.OrderInfoMapper;
 import com.miaxis.order.service.IOrderInfoService;
 import com.miaxis.order.vo.OrderInfoMonthVo;
+import com.miaxis.vip.domain.VipUserExam;
+import com.miaxis.vip.service.IVipExamVideoService;
+import com.miaxis.vip.service.IVipUserExamService;
 import com.miaxis.wx.domain.WxOrder;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.cache.annotation.CacheConfig;
@@ -27,11 +32,17 @@ import java.util.List;
 public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo> implements IOrderInfoService {
 
 
+    @Autowired
+    private OrderInfoMapper orderInfoMapper;
 
+    @Autowired
+    private IExamInfoService examInfoService;
 
     @Autowired
-    private OrderInfoMapper orderInfoMapper;
+    private IVipUserExamService vipUserExamService;
 
+    @Autowired
+    private IVipExamVideoService vipExamVideoService;
     /**
      * 查询ad列表
      *
@@ -44,29 +55,15 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
     }
 
     @Override
-    public Integer selectTotal(OrderInfoDto orderInfoDto) {
-        return orderInfoMapper.selectTotal(orderInfoDto);
-    }
-
-    @Override
-    public Integer selectYesterdayTotal(OrderInfoDto orderInfoDto) {
-        return orderInfoMapper.selectYesterdayTotal(orderInfoDto);
-    }
-
-    @Override
-    public Integer selectTodayTotal(OrderInfoDto orderInfoDto) {
-        return orderInfoMapper.selectTodayTotal(orderInfoDto);
-    }
-
-    @Override
-    public List<OrderInfoMonthVo> selectMonthIncome(OrderInfoMonthDto orderInfoMonthDto) {
-        return orderInfoMapper.selectMonthIncome(orderInfoMonthDto);
+    public OrderInfo getByOutTradeNo(String outTradeNo) {
+        return orderInfoMapper.getByOutTradeNo(outTradeNo);
     }
 
     @Override
     public void writeVipDataToDb(WxOrder order, int payType) {
         Date now = new Date();
         OrderInfo orderInfo = new OrderInfo();
+        orderInfo.setGoodsId(order.getGoodsId());
         orderInfo.setGoodsName(order.getGoodsName());
         orderInfo.setUserId(order.getUserId());
         orderInfo.setUnionId(order.getUnionId());
@@ -76,14 +73,23 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
         orderInfo.setOutTradeNo(order.getOutTradeNo());
         orderInfo.setTotal(order.getTotal());
         orderInfo.setTradeType(1);
-        orderInfo.setSuccessTime(now);
+        orderInfo.setSuccessTime(order.getSuccessTime());
         orderInfo.setPayType(payType);
         orderInfo.setForeType(order.getForeType());
 
+        //添加会员信息
+        ExamInfo examInfo = examInfoService.getById(order.getGoodsId());
+        VipUserExam vipUserExam = new VipUserExam();
+        vipUserExam.setUserId(order.getUserId());
+        vipUserExam.setUnionId(order.getUnionId());
+        vipUserExam.setExamId(examInfo.getId());
+        vipUserExam.setExamName(examInfo.getName());
+        vipUserExamService.save(vipUserExam);
         this.save(orderInfo);
     }
 
 
+
 }
 
 

+ 1 - 69
nbjk-service/src/main/java/com/miaxis/vip/domain/VipUserExam.java

@@ -42,17 +42,12 @@ public class VipUserExam extends BaseBusinessEntity{
     @ApiModelProperty(value = "联合ID")
     private String unionId;
 
-    /** 昵称 */
-    @Excel(name = "昵称")
-    @TableField("nick_name")
-    @ApiModelProperty(value = "昵称")
-    private String nickName;
 
     /** 考场ID */
     @Excel(name = "考场ID")
     @TableField("exam_id")
     @ApiModelProperty(value = "考场ID")
-    private String examId;
+    private Long examId;
 
     /** 考场名称 */
     @Excel(name = "考场名称")
@@ -67,68 +62,5 @@ public class VipUserExam extends BaseBusinessEntity{
     @ApiModelProperty(value = "到期时间")
     private Date expirationTime;
 
-    public void setId(Long id){
-        this.id = id;
-    }
 
-    public Long getId(){
-        return id;
-    }
-    public void setUserId(Long userId){
-        this.userId = userId;
-    }
-
-    public Long getUserId(){
-        return userId;
-    }
-    public void setUnionId(String unionId){
-        this.unionId = unionId;
-    }
-
-    public String getUnionId(){
-        return unionId;
-    }
-    public void setNickName(String nickName){
-        this.nickName = nickName;
-    }
-
-    public String getNickName(){
-        return nickName;
-    }
-    public void setExamId(String examId){
-        this.examId = examId;
-    }
-
-    public String getExamId(){
-        return examId;
-    }
-    public void setExamName(String examName){
-        this.examName = examName;
-    }
-
-    public String getExamName(){
-        return examName;
-    }
-    public void setExpirationTime(Date expirationTime){
-        this.expirationTime = expirationTime;
-    }
-
-    public Date getExpirationTime(){
-        return expirationTime;
-    }
-
-    @Override
-    public String toString() {
-        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
-            .append("id", getId())
-            .append("userId", getUserId())
-            .append("unionId", getUnionId())
-            .append("nickName", getNickName())
-            .append("examId", getExamId())
-            .append("examName", getExamName())
-            .append("expirationTime", getExpirationTime())
-            .append("createTime", getCreateTime())
-            .append("updateTime", getUpdateTime())
-            .toString();
-    }
 }

+ 2 - 0
nbjk-service/src/main/java/com/miaxis/vip/mapper/VipUserExamMapper.java

@@ -3,6 +3,7 @@ package com.miaxis.vip.mapper;
 import java.util.List;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.miaxis.vip.domain.VipUserExam;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * 考场会员Mapper接口
@@ -19,4 +20,5 @@ public interface VipUserExamMapper extends BaseMapper<VipUserExam> {
      */
     public List<VipUserExam> selectVipUserExamList(VipUserExam vipUserExam);
 
+    void deleteVipUserExamByUnionIdAndGoodsId(@Param("unionId")String unionId,@Param("goodsId") Long goodsId);
 }

+ 2 - 0
nbjk-service/src/main/java/com/miaxis/vip/service/IVipUserExamService.java

@@ -18,4 +18,6 @@ public interface IVipUserExamService extends IService<VipUserExam>{
      * @return 考场会员集合
      */
     public List<VipUserExam> selectVipUserExamList(VipUserExam vipUserExam);
+
+    void deleteVipUserExamByUnionIdAndGoodsId(String unionId, Long goodsId);
 }

+ 5 - 0
nbjk-service/src/main/java/com/miaxis/vip/service/impl/VipUserExamServiceImpl.java

@@ -30,4 +30,9 @@ public class VipUserExamServiceImpl extends ServiceImpl<VipUserExamMapper, VipUs
     public List<VipUserExam> selectVipUserExamList(VipUserExam vipUserExam){
         return vipUserExamMapper.selectVipUserExamList(vipUserExam);
     }
+
+    @Override
+    public void deleteVipUserExamByUnionIdAndGoodsId(String unionId, Long goodsId) {
+        vipUserExamMapper.deleteVipUserExamByUnionIdAndGoodsId(unionId,goodsId);
+    }
 }

+ 7 - 0
nbjk-service/src/main/java/com/miaxis/wx/domain/WxOrder.java

@@ -28,6 +28,13 @@ public class WxOrder extends BaseBusinessEntity {
     @ApiModelProperty(value = "id")
     private Long id;
 
+
+    /** 商品ID */
+    @Excel(name = "商品ID")
+    @TableField("goods_id")
+    @ApiModelProperty(value = "商品ID(考场ID)")
+    private Long goodsId;
+
     /** 商品名称 */
     @Excel(name = "商品名称")
     @TableField("goods_name")

+ 5 - 4
nbjk-service/src/main/java/com/miaxis/wx/dto/WxOrderDTO.java

@@ -8,12 +8,13 @@ public class WxOrderDTO {
     private static final long serialVersionUID = 1L;
 
 
-    @ApiModelProperty(value = "商品字典编码",required = true)
-    private Long dictCode;
 
-    @ApiModelProperty(value = "手机类型 1苹果 2安卓")
+    @ApiModelProperty(value = "考场ID",required = true)
+    private Long examId;
+
+    @ApiModelProperty(value = "手机类型 1苹果 2安卓",required = true)
     private Integer phoneType;  // 1苹果 2安卓
 
-    @ApiModelProperty(value = "前端类型 1:app 2:小程序 3:公众号")
+    @ApiModelProperty(value = "前端类型 1:app 2:小程序 3:公众号",required = true)
     private Integer foreType;
 }

+ 32 - 11
nbjk-service/src/main/java/com/miaxis/wx/service/impl/RefundRecordServiceImpl.java

@@ -7,14 +7,18 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.miaxis.common.config.WxpayConfig;
 import com.miaxis.common.core.domain.entity.UserInfo;
-import com.miaxis.common.enums.OrderStatusEnum;
 import com.miaxis.common.exception.CustomException;
+import com.miaxis.order.domain.OrderInfo;
+import com.miaxis.order.service.IOrderInfoService;
 import com.miaxis.user.service.IUserInfoService;
+import com.miaxis.vip.service.IVipUserExamService;
 import com.miaxis.wx.domain.RefundRecord;
 import com.miaxis.wx.domain.WxOrder;
 import com.miaxis.wx.dto.WxNotifyReturnDTO;
 import com.miaxis.wx.mapper.RefundRecordMapper;
 import com.miaxis.wx.service.IRefundRecordService;
+import com.miaxis.wx.service.IWxOrderService;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
 import org.apache.http.client.HttpClient;
@@ -35,6 +39,7 @@ import java.util.List;
  * @date 2021-05-18
  */
 @Service
+@Slf4j
 public class RefundRecordServiceImpl extends ServiceImpl<RefundRecordMapper, RefundRecord> implements IRefundRecordService {
     @Resource
     private RefundRecordMapper refundRecordMapper;
@@ -48,6 +53,17 @@ public class RefundRecordServiceImpl extends ServiceImpl<RefundRecordMapper, Ref
 
     @Autowired
     private IUserInfoService userInfoService;
+
+    @Autowired
+    private IOrderInfoService orderInfoService;
+
+    @Autowired
+    private IVipUserExamService vipUserExamService;
+
+    @Autowired
+    private IWxOrderService wxOrderService;
+
+
     /**
      * 查询微信退款记录列表
      *
@@ -85,7 +101,20 @@ public class RefundRecordServiceImpl extends ServiceImpl<RefundRecordMapper, Ref
         // 返回数据:
         String bodyAsString = EntityUtils.toString(response.getEntity());
         if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
+            log.info("退款成功,订单号:"+wxOrder);
             wxOrder.setOutRefundNo(refundCode);
+            //更新这个字段
+            wxOrder.setOutRefundNo(refundCode);
+            wxOrder.setRefundReason(failCause);
+            wxOrder.setTradeType("3");
+            wxOrderService.updateById(wxOrder);
+            OrderInfo orderInfo = orderInfoService.getByOutTradeNo(wxOrder.getOutTradeNo());
+            orderInfo.setOutRefundNo(refundCode);
+            orderInfo.setTradeType(3);
+            orderInfo.setRefundReason(failCause);
+            orderInfoService.updateById(orderInfo);
+
+
             //  保存退款数据到数据库
             RefundRecord refundRecord = new RefundRecord();
             JSONObject jsonObject = JSONObject.parseObject(bodyAsString);
@@ -113,16 +142,8 @@ public class RefundRecordServiceImpl extends ServiceImpl<RefundRecordMapper, Ref
             refundRecord.setCurrency(amount.getString("currency"));
             this.save(refundRecord);
 
-            //退款完成 解除会员vip身份
-            UserInfo userInfo = userInfoService.getOne(new QueryWrapper<UserInfo>().eq("app_openid", wxOrder.getAppOpenid()));
-            userInfo.setIsVip(0);
-            userInfoService.updateById(userInfo);
-
-
-            //改变订单状态
-
-
-
+            //TODO 退款完成 解除会员vip身份也可以在外层做
+            vipUserExamService.deleteVipUserExamByUnionIdAndGoodsId(wxOrder.getUnionId(),wxOrder.getGoodsId());
 
             WxNotifyReturnDTO wxNotifyReturnDTO = new WxNotifyReturnDTO();
             wxNotifyReturnDTO.setCode("SUCCESS");

+ 12 - 47
nbjk-service/src/main/resources/mapper/order/OrderInfoMapper.xml

@@ -6,23 +6,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
     <resultMap type="OrderInfo" id="OrderInfoResult">
         <result property="id"    column="id"    />
+        <result property="goodsId"   column="goods_id"    />
         <result property="goodsName"    column="goods_name"    />
+        <result property="userId"    column="user_id"    />
+        <result property="unionId"    column="union_id"    />
+        <result property="appOpenid"    column="app_openid"    />
+        <result property="xcxOpenid"    column="xcx_openid"    />
+        <result property="gzhOpenid"    column="gzh_openid"    />
         <result property="out_trade_no"    column="outTradeNo"    />
         <result property="outRefundNo"    column="out_refund_no"    />
         <result property="total"    column="total"    />
         <result property="tradeType"    column="trade_type"    />
         <result property="successTime"    column="success_time"    />
+        <result property="payType"    column="pay_type"    />
+        <result property="phoneType"    column="phone_type"    />
         <result property="createTime"    column="create_time"    />
         <result property="updateTime"    column="update_time"    />
     </resultMap>
 
     <sql id="selectOrderInfoVo">
-        select * from v_wx_order
+        select * from order_info
     </sql>
 
     <select id="selectOrderInfoList" parameterType="OrderInfoDto" resultMap="OrderInfoResult">
         <include refid="selectOrderInfoVo"/>
         <where>
+            <if test="goodsId != null "> and goods_id = #{goodsId}</if>
             <if test="goodsName != null  and goodsName != ''"> and goods_name = #{goodsName}</if>
             <if test="outTradeNo != null  and outTradeNo != ''"> and out_trade_no = #{outTradeNo}</if>
             <if test="outRefundNo != null and outRefundNo != '' "> and status = #{status}</if>
@@ -38,54 +47,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </where>
     </select>
 
-
-    <select id="selectMonthIncome" parameterType="com.miaxis.order.dto.OrderInfoMonthDto" resultType="com.miaxis.order.vo.OrderInfoMonthVo">
-        select ifnull(sum(commission_price),0) as income,DATE_FORMAT(success_time,'%Y-%m') as yearMonth from v_wx_order
-        <where>
-            <if test="referralUserId != null and referralUserId != ''  "> and referral_user_id = #{referralUserId}</if>
-            <if test="year != null and year != '' ">
-                and DATE_FORMAT(success_time,'%Y') <![CDATA[ = ]]> #{year}
-            </if>
-            GROUP BY DATE_FORMAT(success_time,'%Y-%m')
-        </where>
-    </select>
-
-
-
-    <select id="selectTodayTotal" parameterType="OrderInfoDto" resultType="Integer">
-        select ifnull(sum(commission_price),0) FROM v_wx_order
-        <where>
-            <if test="goodsName != null  and goodsName != ''"> and goods_name = #{goodsName}</if>
-            <if test="outTradeNo != null  and outTradeNo != ''"> and out_trade_no = #{outTradeNo}</if>
-            <if test="outRefundNo != null and outRefundNo != '' "> and status = #{status}</if>
-            <if test="total != null "> and total = #{total}</if>
-            <if test="tradeType != null and tradeType != ''  "> and trade_type = #{tradeType}</if>
-            <if test="referralUserId != null and referralUserId != ''  "> and referral_user_id = #{referralUserId}</if>
-            and TO_DAYS(success_time) = TO_DAYS(NOW())
-        </where>
-    </select>
-
-
-    <select id="selectYesterdayTotal" parameterType="OrderInfoDto" resultType="Integer">
-        select ifnull(sum(commission_price),0) FROM v_wx_order
-        <where>
-            <if test="goodsName != null  and goodsName != ''"> and goods_name = #{goodsName}</if>
-            <if test="outTradeNo != null  and outTradeNo != ''"> and out_trade_no = #{outTradeNo}</if>
-            <if test="outRefundNo != null and outRefundNo != '' "> and status = #{status}</if>
-            <if test="total != null "> and total = #{total}</if>
-            <if test="tradeType != null and tradeType != ''  "> and trade_type = #{tradeType}</if>
-            <if test="referralUserId != null and referralUserId != ''  "> and referral_user_id = #{referralUserId}</if>
-            and TO_DAYS(NOW()) - TO_DAYS(success_time) = 1
-        </where>
+    <select id="getByOutTradeNo" parameterType="string" resultType="com.miaxis.order.domain.OrderInfo">
+        select * from order_info where out_trade_no =#{outTradeNo}
     </select>
 
-    <select id="selectTotal" parameterType="OrderInfoDto" resultType="Integer">
-        select ifnull(sum(total),0) FROM v_wx_order
-        <where>
-            <if test="referralUserId != null and referralUserId != ''  "> and referral_user_id = #{referralUserId}</if>
-        </where>
-    </select>
-    <select id="selectMonthIncone" resultType="com.miaxis.order.vo.OrderInfoMonthVo"></select>
 
 
 </mapper>

+ 6 - 2
nbjk-service/src/main/resources/mapper/vip/VipUserExamMapper.xml

@@ -8,7 +8,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="id"    column="id"    />
         <result property="userId"    column="user_id"    />
         <result property="unionId"    column="union_id"    />
-        <result property="nickName"    column="nick_name"    />
         <result property="examId"    column="exam_id"    />
         <result property="examName"    column="exam_name"    />
         <result property="expirationTime"    column="expiration_time"    />
@@ -25,11 +24,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <where>
             <if test="userId != null "> and user_id = #{userId}</if>
             <if test="unionId != null  and unionId != ''"> and union_id = #{unionId}</if>
-            <if test="nickName != null  and nickName != ''"> and nick_name like concat('%', #{nickName}, '%')</if>
             <if test="examId != null  and examId != ''"> and exam_id = #{examId}</if>
             <if test="examName != null  and examName != ''"> and exam_name like concat('%', #{examName}, '%')</if>
             <if test="expirationTime != null "> and expiration_time = #{expirationTime}</if>
         </where>
     </select>
 
+
+    <delete id="deleteVipUserExamByUnionIdAndGoodsId">
+        delete from vip_user_exam where exam_id = #{goodsId} and union_id = #{unionId}
+    </delete>
+
+
 </mapper>

+ 22 - 29
nbjk-service/src/main/resources/mapper/wx/WxOrderMapper.xml

@@ -6,7 +6,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
     <resultMap type="WxOrder" id="WxOrderResult">
         <result property="id"    column="id"    />
+        <result property="goodsId"    column="goods_id"    />
+        <result property="goodsName"    column="goods_name"    />
+        <result property="userId"    column="user_id"    />
+        <result property="unionId"    column="union_id"    />
+        <result property="appOpenid"    column="app_openid"    />
+        <result property="xcxOpenid"    column="xcx_openid"    />
+        <result property="gzhOpenid"    column="gzh_openid"    />
         <result property="outTradeNo"    column="out_trade_no"    />
+        <result property="outRefundNo"    column="out_refund_no"    />
+        <result property="refundReason"    column="refund_reason"    />
         <result property="transactionId"    column="transaction_id"    />
         <result property="tradeType"    column="trade_type"    />
         <result property="tradeState"    column="trade_state"    />
@@ -14,24 +23,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="bankType"    column="bank_type"    />
         <result property="attach"    column="attach"    />
         <result property="successTime"    column="success_time"    />
-        <result property="openid"    column="openid"    />
-        <result property="goodsName"    column="goods_name"    />
         <result property="total"    column="total"    />
         <result property="payerTotal"    column="payer_total"    />
         <result property="currency"    column="currency"    />
         <result property="payerCurrency"    column="payer_currency"    />
-        <result property="deviceId"    column="device_id"    />
-        <result property="seat"    column="seat"    />
-        <result property="reservedPhone"    column="reserved_phone"    />
-        <result property="acceptChangeSeat"    column="accept_change_seat"    />
-        <result property="seatId"    column="seat_id"    />
-        <result property="seatNo"    column="seat_no"    />
-        <result property="orderState"    column="order_state"    />
-        <result property="orderPrice"    column="order_price"    />
-        <result property="closeCause"    column="close_cause"    />
-        <result property="realSeat"    column="real_seat"    />
-        <result property="ticketCode"    column="ticket_code"    />
-        <result property="ticketImage"    column="ticket_image"    />
+        <result property="orderStatus"    column="order_status"    />
+        <result property="phoneType"    column="phone_type"    />
+        <result property="foreType"    column="fore_type"    />
         <result property="createTime"    column="create_time"    />
         <result property="updateTime"    column="update_time"    />
     </resultMap>
@@ -48,7 +46,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <select id="selectWxOrderList" parameterType="WxOrder" resultMap="WxOrderResult">
         <include refid="selectWxOrderVo"/>
         <where>
-            <if test="outTradeNo != null "> and out_trade_no = #{outTradeNo}</if>
+            <if test="goodsId != null"> and goods_id = #{goodsId}</if>
+            <if test="goodsName != null  and goodsName != ''"> and goods_name like concat('%', #{goodsName}, '%')</if>
+            <if test="userId != null"> and user_id = #{userId}</if>
+            <if test="unionId != null  and unionId != ''"> and union_id = #{unionId}</if>
+            <if test="outTradeNo != null and outTradeNo != ''"> and out_trade_no = #{outTradeNo}</if>
+            <if test="outRefundNo != null and outRefundNo != ''"> and out_refund_no = #{outRefundNo}</if>
+            <if test="refundReason != null and refundReason != ''"> and refund_reason = #{refundReason}</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>
@@ -56,24 +60,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <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="deviceId != null  and deviceId != ''"> and device_id = #{deviceId}</if>
-            <if test="seat != null  and seat != ''"> and seat = #{seat}</if>
-            <if test="reservedPhone != null  and reservedPhone != ''"> and reserved_phone = #{reservedPhone}</if>
-            <if test="acceptChangeSeat != null "> and accept_change_seat = #{acceptChangeSeat}</if>
-            <if test="seatId != null  and seatId != ''"> and seat_id = #{seatId}</if>
-            <if test="seatno != null  and seatno != ''"> and seat_no = #{seatNo}</if>
-            <if test="orderState != null  and orderState != ''"> and order_state = #{orderState}</if>
-            <if test="orderPrice != null "> and order_price = #{orderPrice}</if>
-            <if test="closeCause != null  and closeCause != ''"> and close_cause = #{closeCause}</if>
-            <if test="realSeat != null  and realSeat != ''"> and real_seat = #{realSeat}</if>
-            <if test="ticketCode != null  and ticketCode != ''"> and ticket_code = #{ticketCode}</if>
-            <if test="ticketImage != null  and ticketImage != ''"> and ticket_image = #{ticketImage}</if>
+            <if test="orderStatus != null  and orderStatus != ''"> and order_status = #{orderStatus}</if>
+            <if test="phoneType != null"> and phone_type = #{phoneType}</if>
+            <if test="foreType != null"> and fore_type = #{foreType}</if>
         </where>
     </select>