Browse Source

Merge remote-tracking branch 'upsteam/master'

dq 6 years ago
parent
commit
3b0ea396be

+ 34 - 43
kmall-admin/src/main/java/com/kmall/admin/controller/OrderController.java

@@ -354,49 +354,42 @@ public class OrderController {
         }
 
         if (orderInfo.getOrderStatus() != 0) {
-
-            List<OrderWXPayRecordEntity> orderWXPayRecords =
-                    orderWXPayRecordService.getRecordsByOutTradeNo(orderInfo.getOrderSn());
-            //支付成功的发送到微信的订单编号
-            String paySuccessOutTradeNoWX = null;
-            if (orderWXPayRecords != null) {
-                for (OrderWXPayRecordEntity orderWXPayRecord : orderWXPayRecords) {
-                    if ("SUCCESS".equals(orderWXPayRecord.getTradeState())) {
-                        paySuccessOutTradeNoWX = orderWXPayRecord.getOutTradeNoWX();
-                        break;
+            //现金支付
+            if (Dict.payFlag.item_cash.getItem().equals(orderInfo.getPayFlag())) {
+                orderService.refund(orderInfo, null);
+                //微信支付
+            } else if (Dict.payFlag.item_weixin.getItem().equals(orderInfo.getPayFlag())) {
+                // todo 退款
+                WechatRefundApiResult result = WechatUtil
+                        .wxRefund(orderInfo.getOrderSnWx(), orderInfo.getActualPrice().doubleValue(),
+                                  orderInfo.getActualPrice().doubleValue());
+                if (result.getResult_code().equals("SUCCESS")) {
+                    orderService.refund(orderInfo, result);
+                } else {
+                    OrderRefundEntity mallOrderRefund = orderRefundService.queryObjectByOrderId(orderInfo.getId());
+                    OrderRefundEntity orderRefund = new OrderRefundEntity();
+                    orderRefund.setRefundType(Integer.parseInt(Dict.RefundType.item_1.getItem()));
+                    orderRefund.setRefundMoney(BigDecimal.valueOf(orderInfo.getActualPrice().doubleValue()));
+                    orderRefund.setRefundStatus(Integer.parseInt(Dict.RefundStatus.item_4.getItem()));
+                    orderRefund.setModTime(new Date());
+                    orderRefund.setOutRefundNo(result.getOut_refund_no());
+                    if (mallOrderRefund != null) {
+                        orderRefund.setId(mallOrderRefund.getId());
+                        orderRefundService.update(orderRefund);//退款记录
                     }
-                }
-            }
 
-            // todo 退款
-            WechatRefundApiResult result = WechatUtil
-                    .wxRefund(paySuccessOutTradeNoWX, orderInfo.getActualPrice().doubleValue(),
-                              orderInfo.getActualPrice().doubleValue());
-            if (result.getResult_code().equals("SUCCESS")) {
-                orderService.refund(orderInfo, result);
-            } else {
-                OrderRefundEntity mallOrderRefund = orderRefundService.queryObjectByOrderId(orderInfo.getId());
-                OrderRefundEntity orderRefund = new OrderRefundEntity();
-                orderRefund.setRefundType(Integer.parseInt(Dict.RefundType.item_1.getItem()));
-                orderRefund.setRefundMoney(BigDecimal.valueOf(orderInfo.getActualPrice().doubleValue()));
-                orderRefund.setRefundStatus(Integer.parseInt(Dict.RefundStatus.item_4.getItem()));
-                orderRefund.setModTime(new Date());
-                orderRefund.setOutRefundNo(result.getOut_refund_no());
-                if (mallOrderRefund != null) {
-                    orderRefund.setId(mallOrderRefund.getId());
-                    orderRefundService.update(orderRefund);//退款记录
-                }
-
-                OrderExceptionRecordEntity mallOrderExceptionRecord = new OrderExceptionRecordEntity();
-                mallOrderExceptionRecord.setUserId(Integer.parseInt(orderInfo.getUserId() + ""));
-                mallOrderExceptionRecord.setOrderSn(orderInfo.getOrderSn());
-                mallOrderExceptionRecord.setExceptionStatus(Dict.exceptionStatus.item_03.getItem());
-                mallOrderExceptionRecord.setExceptionContent("退款失败" + result.getErr_code_des());
-                mallOrderExceptionRecord.setCreateTime(new Date());
-                orderExceptionRecordService.save(mallOrderExceptionRecord);
+                    OrderExceptionRecordEntity mallOrderExceptionRecord = new OrderExceptionRecordEntity();
+                    mallOrderExceptionRecord.setUserId(Integer.parseInt(orderInfo.getUserId() + ""));
+                    mallOrderExceptionRecord.setOrderSn(orderInfo.getOrderSn());
+                    mallOrderExceptionRecord.setExceptionStatus(Dict.exceptionStatus.item_03.getItem());
+                    mallOrderExceptionRecord.setExceptionContent("退款失败" + result.getErr_code_des());
+                    mallOrderExceptionRecord.setCreateTime(new Date());
+                    orderExceptionRecordService.save(mallOrderExceptionRecord);
 
-                return R.error(result.getErr_code_des());
+                    return R.error(result.getErr_code_des());
+                }
             }
+
         }
 
         return R.ok("退款成功");
@@ -441,7 +434,7 @@ public class OrderController {
     @RequestMapping("/confirmPay")
     @RequiresPermissions("order:confirmPay")
     public R confirmPay(@RequestBody Long id) {
-        orderService.confirmPay(id);
+        orderService.confirmPay(id, Dict.payFlag.item_cash, null);
 
         return R.ok();
     }
@@ -504,9 +497,7 @@ public class OrderController {
                 .wxMicropay(store.getMerchName() + "-" + store.getStoreName(), orderEntity.getOrderBizType(), null,
                             orderWXPayRecordCurrent.getOutTradeNoWX(), orderEntity.getActualPrice().doubleValue(),
                             "127.0.0.1", auth_code);
-        System.out.println("orderWXPayRecordEntity.id=" + orderWXPayRecordCurrent.getId());
         orderWXPayRecordService.updateRecord(orderWXPayRecordCurrent.getId(), wechatMicropayApiResult);
-        System.out.println(wechatMicropayApiResult);
 
         //当支付成功时,修改订单,并把其他支付记录撤销
         if (WechatUtil.WXTradeState.SUCCESS.getCode().equals(wechatMicropayApiResult.getTrade_state())) {
@@ -535,7 +526,7 @@ public class OrderController {
                     }
                 }
             }
-            orderService.confirmPay(id);
+            orderService.confirmPay(id, Dict.payFlag.item_weixin, orderWXPayRecordCurrent.getOutTradeNoWX());
             r = R.ok();
             //用户支付中
         } else if (WechatUtil.WXTradeState.USERPAYING.getCode().equals(wechatMicropayApiResult.getTrade_state())) {

+ 21 - 0
kmall-admin/src/main/java/com/kmall/admin/entity/OrderEntity.java

@@ -130,6 +130,27 @@ public class OrderEntity
 
     private String isOnfflineOrder;
 
+    private String payFlag;
+
+    private String orderSnWx;
+
+    public String getOrderSnWx() {
+        return orderSnWx;
+    }
+
+    public void setOrderSnWx(String orderSnWx) {
+        this.orderSnWx = orderSnWx;
+    }
+
+    public String getPayFlag() {
+        return payFlag;
+    }
+
+    public void setPayFlag(String payFlag) {
+        this.payFlag = payFlag;
+    }
+
+
     public String getIsOnfflineOrder() {
         return isOnfflineOrder;
     }

+ 2 - 1
kmall-admin/src/main/java/com/kmall/admin/service/OrderService.java

@@ -3,6 +3,7 @@ package com.kmall.admin.service;
 import com.kmall.admin.entity.OfflineCartEntity;
 import com.kmall.admin.entity.OrderEntity;
 import com.kmall.admin.entity.OrderRefundEntity;
+import com.kmall.api.contants.Dict;
 import com.kmall.common.entity.SysUserEntity;
 import com.kmall.common.utils.R;
 import com.kmall.common.utils.print.ticket.item.Ticket;
@@ -86,5 +87,5 @@ public interface OrderService {
 
     Map orderSubmit(List<OfflineCartEntity> offlineCartEntityList,SysUserEntity user);
 
-    int confirmPay(Long id);
+    int confirmPay(Long id, Dict.payFlag payFlag,String orderSnWx);
 }

+ 128 - 88
kmall-admin/src/main/java/com/kmall/admin/service/impl/OrderServiceImpl.java

@@ -32,7 +32,8 @@ import java.util.*;
 
 
 @Service("orderService")
-public class OrderServiceImpl implements OrderService {
+public class OrderServiceImpl
+        implements OrderService {
     @Autowired
     private OrderDao orderDao;
     @Autowired
@@ -92,6 +93,7 @@ public class OrderServiceImpl implements OrderService {
 
     /**
      * 取消订单
+     *
      * @param order
      */
     @Override
@@ -116,11 +118,13 @@ public class OrderServiceImpl implements OrderService {
         map.put("orderId", order.getId());
         List<OrderGoodsEntity> orderGoodsVoList = orderGoodsDao.queryList(map);
         for (OrderGoodsEntity orderGoodsEntity : orderGoodsVoList) {
-            ProductStoreRelaEntity storeRelaEntity = productStoreRelaDao.queryByStoreIdProductId(Long.valueOf(order.getStoreId()), Long.valueOf(orderGoodsEntity.getProductId()));
+            ProductStoreRelaEntity storeRelaEntity = productStoreRelaDao
+                    .queryByStoreIdProductId(Long.valueOf(order.getStoreId()),
+                                             Long.valueOf(orderGoodsEntity.getProductId()));
             if (null == storeRelaEntity || null == storeRelaEntity.getSellVolume()) {
                 storeRelaEntity.setSellVolume(0);
             }
-            BigDecimal sellVolume = new BigDecimal(storeRelaEntity.getSellVolume()-orderGoodsEntity.getNumber());//销售量
+            BigDecimal sellVolume = new BigDecimal(storeRelaEntity.getSellVolume() - orderGoodsEntity.getNumber());//销售量
             if (sellVolume.compareTo(Constant.ZERO) < 0) {
                 sellVolume = Constant.ZERO;
             }
@@ -211,12 +215,13 @@ public class OrderServiceImpl implements OrderService {
         // 获取门店
         StoreEntity storeEntity = storeDao.queryObject(orderEntity.getStoreId());
         // 获取清关信息
-        OrderProcessRecordEntity orderProcessRecordEntity = orderProcessRecordDao.queryObjectByOrderSn(orderEntity.getOrderSn());
+        OrderProcessRecordEntity orderProcessRecordEntity =
+                orderProcessRecordDao.queryObjectByOrderSn(orderEntity.getOrderSn());
 
         // 小票头
         TicketHead head = new TicketHead();
         head.setTitle(OmsMerchPropertiesBuilder.instance().getMerchName() + storeEntity.getStoreName());
-//        head.setMemberId(orderEntity.getUserName().toString());
+        //        head.setMemberId(orderEntity.getUserName().toString());
         head.setOrderId(orderEntity.getOrderSn());
         head.setTradeTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss EEE").format(new Date()));
 
@@ -226,8 +231,12 @@ public class OrderServiceImpl implements OrderService {
         List<Goods> goodsList = new ArrayList<>();
         for (OrderGoodsEntity orderGoods : orderGoodsEntityList) {
             goodsTotal += orderGoods.getNumber();
-            total = total.add(orderGoods.getRetailPrice().multiply(new BigDecimal(orderGoods.getNumber()))).setScale(2, BigDecimal.ROUND_HALF_UP);
-            Goods goods = new Goods(orderGoods.getGoodsName(), orderGoods.getRetailPrice().toString(), orderGoods.getNumber().toString(), orderGoods.getRetailPrice().multiply(new BigDecimal(orderGoods.getNumber())).setScale(2,BigDecimal.ROUND_HALF_UP).toString());
+            total = total.add(orderGoods.getRetailPrice().multiply(new BigDecimal(orderGoods.getNumber())))
+                         .setScale(2, BigDecimal.ROUND_HALF_UP);
+            Goods goods = new Goods(orderGoods.getGoodsName(), orderGoods.getRetailPrice().toString(),
+                                    orderGoods.getNumber().toString(),
+                                    orderGoods.getRetailPrice().multiply(new BigDecimal(orderGoods.getNumber()))
+                                              .setScale(2, BigDecimal.ROUND_HALF_UP).toString());
             goodsList.add(goods);
         }
 
@@ -238,13 +247,14 @@ public class OrderServiceImpl implements OrderService {
         cashInfo.setReceipts(orderEntity.getActualPrice().setScale(2, BigDecimal.ROUND_HALF_UP).toString());
         cashInfo.setOddChange("0.00");
         cashInfo.setCoupon(orderEntity.getCouponPrice().setScale(2, BigDecimal.ROUND_HALF_UP).toString());
-        cashInfo.setFreight(new BigDecimal(orderEntity.getFreightPrice()).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
+        cashInfo.setFreight(
+                new BigDecimal(orderEntity.getFreightPrice()).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
         cashInfo.setPaymentMode("微信支付");
 
         // 海关清单
         CusListing cusListing = new CusListing();
         cusListing.setOrderId(orderEntity.getOrderSn());
-        if(!orderEntity.getOrderBizType().equalsIgnoreCase(Dict.orderBizType.item_11.getItem())){
+        if (!orderEntity.getOrderBizType().equalsIgnoreCase(Dict.orderBizType.item_11.getItem())) {
             cusListing.setWaybillId(orderProcessRecordEntity.getLogisticsNo());
             cusListing.setInvtNo(orderProcessRecordEntity.getInvtNo());
             cusListing.setConsignee(orderEntity.getConsignee());
@@ -265,34 +275,41 @@ public class OrderServiceImpl implements OrderService {
         if (order.getOrderStatus() == Integer.parseInt(Dict.orderStatus.item_201.getItem())) {
             order.setOrderStatus(Integer.parseInt(Dict.orderStatus.item_401.getItem()));
         }
-        order.setPayStatus(Integer.parseInt(Dict.payStatus.item_3.getItem()));
+
+        if (Dict.payFlag.item_cash.getItem().equals(order.getPayFlag())) {
+            order.setPayStatus(Integer.parseInt(Dict.payStatus.item_4.getItem()));
+        }else{
+            order.setPayStatus(Integer.parseInt(Dict.payStatus.item_3.getItem()));
+
+            OrderRefundEntity mallOrderRefund = orderRefundDao.queryObjectByOrderId(order.getId());
+
+            OrderRefundEntity orderRefund = new OrderRefundEntity();
+            orderRefund.setRefundId(result.getRefund_id());
+            orderRefund.setOutRefundNo(result.getOut_refund_no());
+            orderRefund
+                    .setRefundMoney(BigDecimal.valueOf(Long.valueOf(result.getRefund_fee())).divide(Constant.ONE_HUNDRED));
+            orderRefund.setRefundStatus(Integer.parseInt(Dict.RefundStatus.item_5.getItem()));//退款处理中
+            orderRefund.setModTime(new Date());
+
+            if (mallOrderRefund != null) {
+                orderRefund.setId(mallOrderRefund.getId());
+                orderRefund.setRefundType(mallOrderRefund.getRefundType());
+                orderRefundDao.update(orderRefund);
+            } else {
+                orderRefund.setOrderId(Integer.parseInt(order.getId() + ""));
+                orderRefund.setUserId(Integer.parseInt(order.getUserId() + ""));
+                orderRefund.setCreateTime(new Date());
+                orderRefundDao.save(orderRefund);//退款记录
+            }
+        }
+
+        orderDao.update(order);//修改为退款中
 
         // 判断是否有优惠券
         UserCouponEntity couponVo = userCouponDao.queryByOrderId(order.getId());
         if (null != couponVo) {
             userCouponDao.cancelOrder(couponVo);
         }
-        orderDao.update(order);//修改为退款中
-
-        OrderRefundEntity mallOrderRefund = orderRefundDao.queryObjectByOrderId(order.getId());
-
-        OrderRefundEntity orderRefund = new OrderRefundEntity();
-        orderRefund.setRefundId(result.getRefund_id());
-        orderRefund.setOutRefundNo(result.getOut_refund_no());
-        orderRefund.setRefundMoney(BigDecimal.valueOf(Long.valueOf(result.getRefund_fee())).divide(Constant.ONE_HUNDRED));
-        orderRefund.setRefundStatus(Integer.parseInt(Dict.RefundStatus.item_5.getItem()));//退款处理中
-        orderRefund.setModTime(new Date());
-
-        if(mallOrderRefund !=null){
-            orderRefund.setId(mallOrderRefund.getId());
-            orderRefund.setRefundType(mallOrderRefund.getRefundType());
-            orderRefundDao.update(orderRefund);
-        }else{
-            orderRefund.setOrderId(Integer.parseInt(order.getId()+""));
-            orderRefund.setUserId(Integer.parseInt(order.getUserId()+""));
-            orderRefund.setCreateTime(new Date());
-            orderRefundDao.save(orderRefund);//退款记录
-        }
 
         if (!needUpdateStock) {
             return;
@@ -302,11 +319,13 @@ public class OrderServiceImpl implements OrderService {
         map.put("orderId", order.getId());
         List<OrderGoodsEntity> orderGoodsVoList = orderGoodsDao.queryList(map);
         for (OrderGoodsEntity orderGoodsEntity : orderGoodsVoList) {
-            ProductStoreRelaEntity storeRelaEntity = productStoreRelaDao.queryByStoreIdProductId(Long.valueOf(order.getStoreId()), Long.valueOf(orderGoodsEntity.getProductId()));
+            ProductStoreRelaEntity storeRelaEntity = productStoreRelaDao
+                    .queryByStoreIdProductId(Long.valueOf(order.getStoreId()),
+                                             Long.valueOf(orderGoodsEntity.getProductId()));
             if (null == storeRelaEntity || null == storeRelaEntity.getSellVolume()) {
                 storeRelaEntity.setSellVolume(0);
             }
-            BigDecimal sellVolume = new BigDecimal(storeRelaEntity.getSellVolume()-orderGoodsEntity.getNumber());//销售量
+            BigDecimal sellVolume = new BigDecimal(storeRelaEntity.getSellVolume() - orderGoodsEntity.getNumber());//销售量
             if (sellVolume.compareTo(Constant.ZERO) < 0) {
                 sellVolume = Constant.ZERO;
             }
@@ -327,7 +346,7 @@ public class OrderServiceImpl implements OrderService {
     @Transactional
     public void applyRefundDeal(OrderEntity orderInfo, OrderRefundEntity refundEntity) {
         refundEntity.setApprovalTime(new Date());
-//        refundEntity.setApprover(ShiroUtils.getUserId());
+        //        refundEntity.setApprover(ShiroUtils.getUserId());
         //  退积分
         try {
             Integer integral = 1;
@@ -374,9 +393,9 @@ public class OrderServiceImpl implements OrderService {
             result = orderDao.getTodayUserOrder();
         } else if ("todayUserSales".equals(type)) {
             result = orderDao.getTodayUserSales();
-        } else if("incomeSum".equals(type)){
+        } else if ("incomeSum".equals(type)) {
             result = orderDao.getIncomeSum();
-        } else if("payedOrderCount".equals(type)){
+        } else if ("payedOrderCount".equals(type)) {
             result = orderDao.getPayedOrderCount();
         }
         return result;
@@ -388,11 +407,11 @@ public class OrderServiceImpl implements OrderService {
         if (orderEntity == null) {
             throw new RRException("此订单不存在!");
         }
-        if(orderEntity.getShippingStatus() == 0){
-            if(orderEntity.getOrderBizType().equalsIgnoreCase(Dict.orderBizType.item_00.getItem())
-                    || orderEntity.getOrderBizType().equalsIgnoreCase(Dict.orderBizType.item_02.getItem())){
+        if (orderEntity.getShippingStatus() == 0) {
+            if (orderEntity.getOrderBizType().equalsIgnoreCase(Dict.orderBizType.item_00.getItem()) ||
+                orderEntity.getOrderBizType().equalsIgnoreCase(Dict.orderBizType.item_02.getItem())) {
                 throw new RRException("此订单还未发货!");
-            }else{
+            } else {
                 if (StringUtils.isNullOrEmpty(orderEntity.getShippingNo())) {
                     throw new RRException("此订单还未发货!");
                 }
@@ -401,22 +420,26 @@ public class OrderServiceImpl implements OrderService {
 
         Map logisticsInfo = new HashMap();
         List<WuliuEntity> wuliuEntityList = new ArrayList<>();
-        OrderProcessRecordEntity orderProcessRecordEntity = orderProcessRecordDao.queryObjectByOrderSn(orderEntity.getOrderSn());
+        OrderProcessRecordEntity orderProcessRecordEntity =
+                orderProcessRecordDao.queryObjectByOrderSn(orderEntity.getOrderSn());
         if (orderProcessRecordEntity != null) {
-            if(orderEntity.getOrderBizType().equals(Dict.orderBizType.item_10.getItem())
-                    || orderEntity.getOrderBizType().equals(Dict.orderBizType.item_02.getItem())) {
+            if (orderEntity.getOrderBizType().equals(Dict.orderBizType.item_10.getItem()) ||
+                orderEntity.getOrderBizType().equals(Dict.orderBizType.item_02.getItem())) {
                 WuliuEntity wuliuEntity = new WuliuEntity();
-                wuliuEntity.setAcceptTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(orderProcessRecordEntity.getCustomsSuccTime()));
-                wuliuEntity.setAcceptStation(PrintTicketPropertiesBuilder.instance().getAddress()
-                        + "送达" + storeDao.queryObject(orderEntity.getStoreId()).getStoreAddress()
-                        + ";交易完成,用户已提走");
+                wuliuEntity.setAcceptTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
+                                                  .format(orderProcessRecordEntity.getCustomsSuccTime()));
+                wuliuEntity.setAcceptStation(PrintTicketPropertiesBuilder.instance().getAddress() + "送达" +
+                                             storeDao.queryObject(orderEntity.getStoreId()).getStoreAddress() +
+                                             ";交易完成,用户已提走");
                 wuliuEntityList.add(wuliuEntity);
             }
-            if (StringUtils.isNotEmpty(orderEntity.getShippingCode())
-                    && StringUtils.isNotEmpty(orderEntity.getShippingNo()) &&orderProcessRecordEntity.getShipmentStartTime()!=null) {
-                JSONObject traces = KdniaoUtil.getOrderTracesByJson(orderEntity.getShippingCode(), orderEntity.getShippingNo());
+            if (StringUtils.isNotEmpty(orderEntity.getShippingCode()) &&
+                StringUtils.isNotEmpty(orderEntity.getShippingNo()) &&
+                orderProcessRecordEntity.getShipmentStartTime() != null) {
+                JSONObject traces =
+                        KdniaoUtil.getOrderTracesByJson(orderEntity.getShippingCode(), orderEntity.getShippingNo());
                 List<Map> mapList = (List<Map>) traces.get("Traces");
-                if(mapList!=null&&mapList.size()>0) {
+                if (mapList != null && mapList.size() > 0) {
                     for (Map map : mapList) {
                         WuliuEntity wuliuEntity = new WuliuEntity();
                         wuliuEntity.setAcceptTime(map.get("AcceptTime").toString());
@@ -424,24 +447,27 @@ public class OrderServiceImpl implements OrderService {
                         wuliuEntityList.add(wuliuEntity);
                     }
                 }
-                String state = traces.get("State")+"";
+                String state = traces.get("State") + "";
                 if (Dict.logisticsStatus.item_0.getItem().equals(state) && traces.getBoolean("Success")) {
-                    String reason = traces.get("Reason")+"";
+                    String reason = traces.get("Reason") + "";
                     WuliuEntity wuliuEntity = new WuliuEntity();
                     wuliuEntity.setAcceptStation(reason);
                     wuliuEntityList.add(wuliuEntity);
                 }
             }
-            if (Dict.isSend.item_1.getItem().equalsIgnoreCase(orderProcessRecordEntity.getIsCustomsSend()) && orderProcessRecordEntity.getShipmentStartTime() != null) {
+            if (Dict.isSend.item_1.getItem().equalsIgnoreCase(orderProcessRecordEntity.getIsCustomsSend()) &&
+                orderProcessRecordEntity.getShipmentStartTime() != null) {
                 WuliuEntity wuliuEntity = new WuliuEntity();
-                wuliuEntity.setAcceptStation( "订单已出库");
-                wuliuEntity.setAcceptTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(orderProcessRecordEntity.getShipmentStartTime()));
+                wuliuEntity.setAcceptStation("订单已出库");
+                wuliuEntity.setAcceptTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
+                                                  .format(orderProcessRecordEntity.getShipmentStartTime()));
                 wuliuEntityList.add(wuliuEntity);
             }
             if (Dict.isSend.item_1.getItem().equals(orderProcessRecordEntity.getIsCustomsSend())) {
                 WuliuEntity wuliuEntity = new WuliuEntity();
                 wuliuEntity.setAcceptStation("订单清关完成,等待仓库发货");
-                wuliuEntity.setAcceptTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(orderProcessRecordEntity.getCustomsSuccTime()));
+                wuliuEntity.setAcceptTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
+                                                  .format(orderProcessRecordEntity.getCustomsSuccTime()));
                 wuliuEntityList.add(wuliuEntity);
             }
 
@@ -450,22 +476,26 @@ public class OrderServiceImpl implements OrderService {
                 wuliuEntity.setAcceptStation("订单清关失败");
                 wuliuEntityList.add(wuliuEntity);
             }
-            if (Dict.isSend.item_1.getItem().equalsIgnoreCase(orderProcessRecordEntity.getIsEleOrderSend()) && orderProcessRecordEntity.getWaybillSuccTime()!=null) {
+            if (Dict.isSend.item_1.getItem().equalsIgnoreCase(orderProcessRecordEntity.getIsEleOrderSend()) &&
+                orderProcessRecordEntity.getWaybillSuccTime() != null) {
                 WuliuEntity wuliuEntity = new WuliuEntity();
                 wuliuEntity.setAcceptStation("海关三单发送成功");
-                wuliuEntity.setAcceptTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(orderProcessRecordEntity.getWaybillSuccTime()));
+                wuliuEntity.setAcceptTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
+                                                  .format(orderProcessRecordEntity.getWaybillSuccTime()));
                 wuliuEntityList.add(wuliuEntity);
             }
-            if(Dict.isSend.item_1.getItem().equals(orderProcessRecordEntity.getIsPaymentSend())){
+            if (Dict.isSend.item_1.getItem().equals(orderProcessRecordEntity.getIsPaymentSend())) {
                 WuliuEntity wuliuEntity = new WuliuEntity();
                 wuliuEntity.setAcceptStation("订单支付成功");
-                wuliuEntity.setAcceptTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(orderProcessRecordEntity.getPaySuccTime()));
+                wuliuEntity.setAcceptTime(
+                        new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(orderProcessRecordEntity.getPaySuccTime()));
                 wuliuEntityList.add(wuliuEntity);
             }
-            if(Dict.isSend.item_1.getItem().equalsIgnoreCase(orderProcessRecordEntity.getIsAddOrderSend())){
+            if (Dict.isSend.item_1.getItem().equalsIgnoreCase(orderProcessRecordEntity.getIsAddOrderSend())) {
                 WuliuEntity wuliuEntity = new WuliuEntity();
                 wuliuEntity.setAcceptStation("订单下单成功");
-                wuliuEntity.setAcceptTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(orderProcessRecordEntity.getAddOrderSuccTime()));
+                wuliuEntity.setAcceptTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
+                                                  .format(orderProcessRecordEntity.getAddOrderSuccTime()));
                 wuliuEntityList.add(wuliuEntity);
             }
         }
@@ -487,10 +517,10 @@ public class OrderServiceImpl implements OrderService {
 
     @Transactional
     @Override
-    public Map orderSubmit(List<OfflineCartEntity> offlineCartList,SysUserEntity user){
+    public Map orderSubmit(List<OfflineCartEntity> offlineCartList, SysUserEntity user) {
         Map resultObj = new HashMap();
-        try{
-            if(user == null) {
+        try {
+            if (user == null) {
                 resultObj.put("errno", 400);
                 resultObj.put("errmsg", "用户登录超时,请重新登录");
                 return resultObj;
@@ -500,7 +530,7 @@ public class OrderServiceImpl implements OrderService {
                 resultObj.put("errmsg", "该操作只允许店员账户操作");
                 return resultObj;
             }
-            if(org.apache.commons.lang3.StringUtils.isEmpty(user.getMerchSn())){
+            if (org.apache.commons.lang3.StringUtils.isEmpty(user.getMerchSn())) {
                 resultObj.put("errno", 400);
                 resultObj.put("errmsg", "操作用户的商户编号为空,请先维护用户商户编号信息再来操作");
                 return resultObj;
@@ -524,19 +554,21 @@ public class OrderServiceImpl implements OrderService {
             }
             // 检查库存和更新库存
             for (OfflineCartEntity cartEntity : offlineCartEntityList) {
-                if(goodsDao.queryObject(cartEntity.getGoodsId()) == null){
+                if (goodsDao.queryObject(cartEntity.getGoodsId()) == null) {
                     resultObj.put("errno", 400);
                     resultObj.put("errmsg", "订单提交失败:商品不存在");
                     return resultObj;
                 }
                 //取得规格的信息,判断规格库存
-                ProductStoreRelaEntity productInfo = productStoreRelaDao.queryByGoodsIdAndStoreId(Long.valueOf(storeId),Long.valueOf(cartEntity.getGoodsId()));
-                synchronized (productInfo){
-                    if (null == productInfo || null == productInfo.getStockNum() || productInfo.getStockNum() < cartEntity.getNumber()) {
+                ProductStoreRelaEntity productInfo = productStoreRelaDao
+                        .queryByGoodsIdAndStoreId(Long.valueOf(storeId), Long.valueOf(cartEntity.getGoodsId()));
+                synchronized (productInfo) {
+                    if (null == productInfo || null == productInfo.getStockNum() ||
+                        productInfo.getStockNum() < cartEntity.getNumber()) {
                         resultObj.put("errno", 400);
                         resultObj.put("errmsg", "库存不足,仅剩余" + productInfo.getStockNum());
                         return resultObj;
-                    }else{
+                    } else {
                         productInfo.setStockNum(productInfo.getStockNum() - cartEntity.getNumber());
                         productInfo.setStoreId(Long.valueOf(storeId));
                         productInfo.addSellVolume();
@@ -544,13 +576,13 @@ public class OrderServiceImpl implements OrderService {
                     }
                 }
             }
-            String merchOrderSn = "EMATO"+CommonUtil.generateOrderNumber();
-            OrderEntity order = setOrderVo(user,offlineCartEntityList,user.getMerchSn());
+            String merchOrderSn = "EMATO" + CommonUtil.generateOrderNumber();
+            OrderEntity order = setOrderVo(user, offlineCartEntityList, user.getMerchSn());
             order.setStoreId(storeId);
             order.setMerchOrderSn(merchOrderSn);
 
             //开启事务,插入订单信息和订单商品
-            if(order != null) {
+            if (order != null) {
                 orderDao.save(order);
                 if (null == order.getId()) {
                     resultObj.put("errno", 400);
@@ -570,7 +602,7 @@ public class OrderServiceImpl implements OrderService {
                 resultObj.put("errmsg", "订单提交成功");
                 resultObj.put("data", orderInfoMap);
             }
-        }catch (Exception e){
+        } catch (Exception e) {
             e.printStackTrace();
             resultObj.put("errno", 400);
             resultObj.put("errmsg", "订单异常");
@@ -581,15 +613,18 @@ public class OrderServiceImpl implements OrderService {
 
     /**
      * 设置订单数据
+     *
      * @param loginUser
      * @return
      */
-    public OrderEntity setOrderVo(SysUserEntity loginUser,List<OfflineCartEntity> offlineCartEntityList,String merchSn){
+    public OrderEntity setOrderVo(SysUserEntity loginUser, List<OfflineCartEntity> offlineCartEntityList,
+                                  String merchSn) {
         OrderEntity orderInfo = new OrderEntity();
         BigDecimal freightPrice = new BigDecimal(0.00);
         BigDecimal goodsTotalPrice = new BigDecimal(0.00);
         for (OfflineCartEntity offlineCartEntity : offlineCartEntityList) {
-            goodsTotalPrice = goodsTotalPrice.add(offlineCartEntity.getRetailPrice().multiply(new BigDecimal(offlineCartEntity.getNumber())));
+            goodsTotalPrice = goodsTotalPrice
+                    .add(offlineCartEntity.getRetailPrice().multiply(new BigDecimal(offlineCartEntity.getNumber())));
         }
         //订单价格计算:订单的总价+运费
         BigDecimal orderTotalPrice = goodsTotalPrice.add(freightPrice);
@@ -602,23 +637,23 @@ public class OrderServiceImpl implements OrderService {
         BigDecimal actualPrice = orderTotalPrice.subtract(couponPrice);
 
         //商户(拼音首字母)+业务类型+编号
-//        String merchSn = OmsMerchPropertiesBuilder.instance().getMerchSn();
-//        String merchShortName = OmsMerchPropertiesBuilder.instance().getMerchShortName();
+        //        String merchSn = OmsMerchPropertiesBuilder.instance().getMerchSn();
+        //        String merchShortName = OmsMerchPropertiesBuilder.instance().getMerchShortName();
         MerchEntity merchEntity = merchDao.findByMerchSn(merchSn);
         String merchShortName = "";
-        if(merchEntity != null){
+        if (merchEntity != null) {
             merchShortName = merchEntity.getMerchShortName();
         }
         String orderSn = merchShortName + Dict.orderBizType.item_11.getItem() + CommonUtil.generateOrderNumber();
         orderInfo.setOrderSn(orderSn);
         orderInfo.setMerchSn(merchSn);
-        orderInfo.setUserId(Integer.parseInt(loginUser.getUserId()+""));
+        orderInfo.setUserId(Integer.parseInt(loginUser.getUserId() + ""));
         orderInfo.setFreightPrice(freightPrice.intValue());
         orderInfo.setOrderBizType(Dict.orderBizType.item_11.getItem());
 
         /*orderInfo.setCoupon_id(userCouponId);
         orderInfo.setCoupon_name(couponName);*/
-//        orderInfo.setFullCutPrice(fullCutCouponDec);//使用的优惠券
+        //        orderInfo.setFullCutPrice(fullCutCouponDec);//使用的优惠券
         orderInfo.setCouponPrice(couponPrice);
         orderInfo.setPostscript("");//留言
         orderInfo.setAddTime(new Date());
@@ -646,10 +681,10 @@ public class OrderServiceImpl implements OrderService {
     }
 
 
-    public OrderGoodsEntity setOrderGoodsVo(OrderEntity orderInfo,OfflineCartEntity goodsItem){
+    public OrderGoodsEntity setOrderGoodsVo(OrderEntity orderInfo, OfflineCartEntity goodsItem) {
         GoodsEntity goodsVo = goodsDao.queryObject(goodsItem.getGoodsId());
         OrderGoodsEntity orderGoodsVo = new OrderGoodsEntity();
-        orderGoodsVo.setOrderId(Integer.parseInt(orderInfo.getId()+""));
+        orderGoodsVo.setOrderId(Integer.parseInt(orderInfo.getId() + ""));
         orderGoodsVo.setGoodsId(goodsItem.getGoodsId());
         orderGoodsVo.setGoodsSn(goodsItem.getGoodsSn());
         orderGoodsVo.setProductId(goodsItem.getProductId());
@@ -667,7 +702,7 @@ public class OrderServiceImpl implements OrderService {
     }
 
     @Override
-    public OrderEntity queryObjectBySysUser(Long id){
+    public OrderEntity queryObjectBySysUser(Long id) {
         OrderEntity orderEntity = orderDao.queryObjectBySysUser(id);
 
         Map<String, Object> map = new HashMap<String, Object>();
@@ -676,10 +711,11 @@ public class OrderServiceImpl implements OrderService {
         orderEntity.setOrderGoodsEntityList(orderGoodsEntityList);
         return orderEntity;
     }
+
     @Override
-    public int confirmPay(Long id) {
+    public int confirmPay(Long id, Dict.payFlag payFlag,String orderSnWx) {
         SysUserEntity user = ShiroUtils.getUserEntity();
-        if(user == null) {
+        if (user == null) {
             throw new RRException("用户登录超时,请重新登录");
         }
         if (!user.getRoleType().equalsIgnoreCase("2")) {
@@ -700,7 +736,11 @@ public class OrderServiceImpl implements OrderService {
         }
         orderEntity.setOrderStatus(Integer.parseInt(Dict.orderStatus.item_201.getItem()));
         orderEntity.setPayStatus(Integer.parseInt(Dict.payStatus.item_2.getItem()));
+        orderEntity.setPayFlag(payFlag.getItem());
         orderEntity.setPayTime(new Date());
+        if(orderSnWx != null){
+            orderEntity.setOrderSnWx(orderSnWx);
+        }
         orderDao.update(orderEntity);
         return 0;
     }

+ 8 - 0
kmall-admin/src/main/resources/mybatis/mapper/OrderDao.xml

@@ -50,12 +50,14 @@
         <result property="isPaymentSend" column="is_payment_send"/>
         <result property="isEleOrderSend" column="is_ele_order_send"/>
         <result property="isCustomsSend" column="is_customs_send"/>
+        <result property="payFlag" column="pay_flag"/>
         <result column="buyer_pay_check" property="buyerPayCheck"/>
         <result property="merchSn" column="merch_sn"/>
         <result property="sku" column="sku"/>
         <result property="createTime" column="create_time"/>
         <result property="modTime" column="mod_time"/>
         <result property="isOnfflineOrder" column="is_onffline_order"/>
+        <result property="orderSnWx" column="order_sn_wx"/>
     </resultMap>
 
     <select id="queryObject" resultType="com.kmall.admin.entity.OrderEntity">
@@ -265,6 +267,8 @@
 			`store_id`,
 			`order_biz_type`,
 			`is_onffline_order`,
+			`order_sn_wx`,
+			`pay_flag`,
             `merch_sn`,
             `create_time`,
             `mod_time`
@@ -307,6 +311,8 @@
 			#{storeId},
 			#{orderBizType},
 			#{isOnfflineOrder},
+			#{orderSnWx},
+			#{payFlag},
             #{merchSn},
             #{createTime},
             #{modTime}
@@ -350,6 +356,8 @@
             <if test="callbackStatus != null">`callback_status` = #{callbackStatus},</if>
             <if test="orderType != null">`order_type` = #{orderType},</if>
             <if test="storeId != null">`store_id` = #{storeId},</if>
+            <if test="payFlag != null">`pay_flag` = #{payFlag},</if>
+            <if test="orderSnWx != null">`order_sn_wx` = #{orderSnWx},</if>
             <if test="orderBizType != null">`order_biz_type` = #{orderBizType},</if>
             <if test="merchSn != null">`merch_sn` = #{merchSn},</if>
             <if test="createTime != null">`create_time` = #{createTime},</if>

+ 1 - 1
kmall-admin/src/main/resources/mybatis/mapper/UserDao.xml

@@ -61,7 +61,7 @@
     </select>
 
     <select id="queryTotal" resultType="int">
-        select count(*) from mall_user
+        select count(distinct mall_user.id) from mall_user
         LEFT JOIN mall_merch_user ON mall_user.id=mall_merch_user.user_id
         LEFT JOIN mall_user_level ON mall_user.user_level_id=mall_user_level.id
         WHERE 1=1

+ 6 - 6
kmall-admin/src/main/webapp/WEB-INF/page/sys/main.html

@@ -259,10 +259,10 @@
         },
         created: function () {
             let vue = this;
-            $.getJSON("../order/queryTotal", function (r) {
+            $.getJSON("../order/queryTotal?isOnfiilineOrder=0", function (r) {
                 vue.orderSum = r.sum;
             });
-            $.getJSON("../order/queryTotal?orderStatus=201&payStatus=2", function (r) {
+            $.getJSON("../order/queryTotal?orderStatus=201&payStatus=2&isOnfiilineOrder=0", function (r) {
                 vue.dfOrderSum = r.sum;
                 if (r.sum > 0) {
                     iview.Notice.info({
@@ -285,16 +285,16 @@
                     iN.setTitle(true).player();
                 }
             });
-            $.getJSON("../order/queryTotal?shippingStatus=1", function (r) {
+            $.getJSON("../order/queryTotal?isOnfiilineOrder=0&shippingStatus=1", function (r) {
                 vue.yfOrderSum = r.sum;
             });
-            $.getJSON("../order/queryTotal?orderStatus=0", function (r) {
+            $.getJSON("../order/queryTotal?isOnfiilineOrder=0&orderStatus=0", function (r) {
                 vue.yfkOrderSum = r.sum;
             });
-            $.getJSON("../order/queryTotal?orderStatus=402", function (r) {
+            $.getJSON("../order/queryTotal?isOnfiilineOrder=0&orderStatus=402", function (r) {
                 vue.ywcOrderSum = r.sum;
             });
-            $.getJSON("../order/queryTotal?shippingStatus=4", function (r) {
+            $.getJSON("../order/queryTotal?isOnfiilineOrder=0&shippingStatus=4", function (r) {
                 vue.thcOrderSum = r.sum;
             });
             $.getJSON("../order/getUserOrderInfo?type=yfkOrderUserSum", function (r) {

+ 3 - 3
kmall-api/src/main/java/com/kmall/api/api/ApiPayController.java

@@ -15,7 +15,7 @@ import com.kmall.common.utils.MapUtils;
 import com.kmall.common.utils.XmlUtil;
 import com.kmall.common.utils.wechat.AESUtil;
 import com.kmall.common.utils.wechat.WechatRefundApiResult;
-import com.kmall.common.utils.wechat.WechatRefundResult;
+import com.kmall.common.utils.wechat.WechatRefundNotifyResult;
 import com.kmall.common.utils.wechat.WechatUtil;
 import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
@@ -225,7 +225,7 @@ public class ApiPayController extends ApiBaseAction {
     @RequestMapping(value = "/notify", produces = "text/html;charset=UTF-8")
     @ResponseBody
     public void notify(HttpServletRequest request, HttpServletResponse response) {
-        logger.error("notify start");
+        logger.info("微信订单回调接口>>>>>>notify start");
         try {
             request.setCharacterEncoding("UTF-8");
             response.setCharacterEncoding("UTF-8");
@@ -345,7 +345,7 @@ public class ApiPayController extends ApiBaseAction {
             in.close();
             String reponseXml = new String(out.toByteArray(), "utf-8");//xml数据
             logger.error("reponseXml:" + reponseXml);
-            WechatRefundResult result = (WechatRefundResult) XmlUtil.xmlStrToBean(reponseXml, WechatRefundResult.class);
+            WechatRefundNotifyResult result = (WechatRefundNotifyResult) XmlUtil.xmlStrToBean(reponseXml, WechatRefundNotifyResult.class);
 
             if (result.getReturn_code().equalsIgnoreCase("FAIL")) {
                 logger.info("微信查询接口调用失败: "+result.getReturn_msg());

+ 4 - 1
kmall-api/src/main/java/com/kmall/api/contants/Dict.java

@@ -13,7 +13,10 @@ public class Dict {
     public enum payFlag {
         item_weixin("weixin", "微信"),
         item_tenpay("tenpay", "财付通"),
-        item_alipay("alipay", "支付宝");
+        item_alipay("alipay", "支付宝"),
+        item_pingan("pingan", "平安支付"),
+        item_wxglobalpay("wxglobalpay", "微信国际支付"),
+        item_cash("cash", "现金");
 
         private String item;
         private String itemName;

+ 1 - 0
kmall-common/src/main/java/com/kmall/common/utils/DateUtils.java

@@ -23,6 +23,7 @@ public class DateUtils {
      * 时间格式(yyyy-MM-dd)
      */
     public final static String DATE_PATTERN = "yyyy-MM-dd";
+    public static String DATE_TIME_PATTERN_YYYY_MM_DD = "yyyyMMdd";
     /**
      * 无分隔符日期格式 "yyyyMMddHHmmss"
      */

+ 4 - 10
kmall-common/src/main/java/com/kmall/common/utils/wechat/WechatUtil.java

@@ -175,7 +175,6 @@ public class WechatUtil {
      * 请求微信https
      **/
     private static String sendSSLPostToWx(String mapToXml, SSLConnectionSocketFactory sslcsf, String requestUrl) {
-
         HttpPost httPost = new HttpPost(requestUrl);
         httPost.addHeader("Connection", "keep-alive");
         httPost.addHeader("Accept", "*/*");
@@ -280,7 +279,6 @@ public class WechatUtil {
      * 方法描述:根据签名加密请求参数
      * 创建时间:2017年6月8日  上午11:28:52
      * 作者: xubo
-     *
      * @param
      * @return
      */
@@ -571,20 +569,18 @@ public class WechatUtil {
         params.put("sign", arraySign(params, CommonWxPayPropertiesBuilder.instance().getPaySignKey()));//签名
         return params;
     }
-
-
     /**
-     * 绑定撤销订单输入参数
+     * 撤销订单输入参数
      *
      * @param out_trade_no 订单编号(发送到微信的编号)
-     * @return 撤销订单输入参数
+     * @return 撤销订单输入参数
      */
     private static Map<Object, Object> buildReverseRequsetMapParam(String out_trade_no) {
         Map<Object, Object> params = new HashMap<Object, Object>();
         params.put("appid", CommonWxPayPropertiesBuilder.instance().getAppId());//微信分配的公众账号ID(企业号corpid即为此appId)
         params.put("mch_id", CommonWxPayPropertiesBuilder.instance().getMchId());//微信支付分配的商户号
-        params.put("out_trade_no", out_trade_no);//商户传给微信的订单号
         params.put("nonce_str", CharUtil.getRandomString(16));//随机字符串,不长于32位。推荐随机数生成算法
+        params.put("out_trade_no", out_trade_no);//商户传给微信的订单号
         //签名前必须要参数全部写在前面
         params.put("sign", arraySign(params, CommonWxPayPropertiesBuilder.instance().getPaySignKey()));//签名
         return params;
@@ -609,7 +605,7 @@ public class WechatUtil {
     }
 
     /**
-     * 请求退款微信
+     * 线下扫码支付请求微信退款
      **/
     private static String sendMicropaySSLPostToWx(String mapToXml) {
         logger.info("*******付款码支付(WX Request:" + mapToXml);
@@ -628,7 +624,6 @@ public class WechatUtil {
         return xmlStr;
     }
 
-
     /**
      * 请求查询订单微信
      **/
@@ -639,7 +634,6 @@ public class WechatUtil {
         return xmlStr;
     }
 
-
     public static void main(String[] args) throws Exception {
         Map<Object, Object> parame = new TreeMap<Object, Object>();
         parame.put("mch_id", ResourceUtil.getConfigByName("\\conf\\wx-mp", "wx.mchId"));//

+ 292 - 0
kmall-common/src/main/java/com/kmall/common/utils/wechat/wxglobal/WechatGlobalUtil.java

@@ -0,0 +1,292 @@
+package com.kmall.common.utils.wechat.wxglobal;
+
+import com.alibaba.druid.support.logging.Log;
+import com.alibaba.druid.support.logging.LogFactory;
+import com.kmall.common.service.pay.wxpay.CommonWxPayPropertiesBuilder;
+import com.kmall.common.utils.*;
+import com.kmall.common.utils.wechat.*;
+import com.kmall.common.utils.wechat.wxglobal.dto.WechatGlobalQueryApiResult;
+import com.kmall.common.utils.wechat.wxglobal.dto.WechatGlobalQueryRateResult;
+import com.kmall.common.utils.wechat.wxglobal.dto.WechatGlobalRefundApiResult;
+import com.kmall.common.utils.wechat.wxglobal.dto.WechatGlobalRefundQueryResult;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.config.RegistryBuilder;
+import org.apache.http.conn.socket.ConnectionSocketFactory;
+import org.apache.http.conn.socket.PlainConnectionSocketFactory;
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
+import org.apache.http.util.EntityUtils;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.math.BigDecimal;
+import java.math.MathContext;
+import java.net.URLEncoder;
+import java.util.*;
+
+/**
+ * <p>Title: 微信退款工具类</p>
+ * <p>Description: 微信退款工具类,通过充值客户端的不同初始化不同的工具类,得到相应微信退款相关的appid和muchid</p>
+ *
+ * @author xubo
+ * @date 2017年6月6日  下午5:05:03
+ */
+public class WechatGlobalUtil {
+    private static Log logger = LogFactory.getLog(WechatGlobalUtil.class);
+    private static final String EMPTY = "";
+    private static final String URL_PARAM_CONNECT_FLAG = "&";
+
+    /**
+     * 菜单类型
+     *
+     * @author Scott
+     * @email
+     * @date 2016年11月15日 下午1:24:29
+     */
+    public enum WXTradeState {
+        /**
+         * 支付成功
+         */
+        SUCCESS("SUCCESS", "支付成功"),
+        /**
+         * 转入退款
+         */
+        REFUND("REFUND", "转入退款"),
+
+        /**
+         * 未支付
+         */
+        NOTPAY("NOTPAY", "未支付"),
+
+        /**
+         * 已关闭
+         */
+        CLOSED("CLOSED", "已关闭"),
+
+        /**
+         * 已撤销(付款码支付)
+         */
+        REVOKED("REVOKED", "已撤销"),
+
+        /**
+         * 用户支付中(付款码支付)
+         */
+        USERPAYING("USERPAYING", "用户支付中"),
+
+        /**
+         * 支付失败(付款码支付)
+         */
+        PAYERROR("PAYERROR", "支付失败");
+
+        private String code;
+        private String codeZn;
+
+        private WXTradeState(String code, String codeZn) {
+            this.code = code;
+            this.codeZn = codeZn;
+        }
+
+        public String getCode() {
+            return code;
+        }
+
+        public String getCodeZn() {
+            return codeZn;
+        }
+    }
+
+
+    /**
+     * 微信境外查询订单
+     * @param
+     * @return
+     */
+    public static WechatGlobalQueryApiResult wxOrderQuery(String out_trade_no) {
+        //初始化请求微信服务器的配置信息包括appid密钥等
+        //构建请求参数
+        Map<Object, Object> params = new HashMap<Object, Object>();
+        params.put("appid", CommonWxPayPropertiesBuilder.instance().getAppId());//微信分配的公众账号ID(企业号corpid即为此appId)
+        params.put("mch_id", CommonWxPayPropertiesBuilder.instance().getMchId());//微信支付分配的商户号
+        params.put("out_trade_no", out_trade_no);//商户传给微信的订单号
+        params.put("nonce_str", CharUtil.getRandomString(16));//随机字符串,不长于32位。推荐随机数生成算法
+        //签名前必须要参数全部写在前面
+        params.put("sign", WechatUtil.arraySign(params, CommonWxPayPropertiesBuilder.instance().getPaySignKey()));//签名
+        String mapToXml = MapUtils.convertMap2Xml(params);
+        //请求微信
+        String reponseXml = sendQuerySSLPostToWx(mapToXml, WechatConfig.getSslcsf());
+        WechatGlobalQueryApiResult result =
+                (WechatGlobalQueryApiResult) XmlUtil.xmlStrToBean(reponseXml, WechatGlobalQueryApiResult.class);
+        return result;
+    }
+    /**
+     * 请求查询订单微信
+     **/
+    private static String sendQuerySSLPostToWx(String mapToXml, SSLConnectionSocketFactory sslcsf) {
+        logger.info("*******查询订单(WX Request:" + mapToXml);
+        String xmlStr = sendSSLPostToWx(mapToXml, sslcsf, CommonWxPayPropertiesBuilder.instance().getOrderquery());
+        logger.info("*******查询订单(WX Response:" + xmlStr);
+        return xmlStr;
+    }
+
+    /**
+     * 微信查询汇率
+     * @param out_trade_no
+     * @return
+     */
+    public static WechatGlobalQueryRateResult wxQueryexchagerate(String out_trade_no) {
+        //初始化请求微信服务器的配置信息包括appid密钥等
+        //构建请求参数
+        Map<Object, Object> params = new HashMap<Object, Object>();
+        params.put("appid", CommonWxPayPropertiesBuilder.instance().getAppId());//微信分配的公众账号ID(企业号corpid即为此appId)
+        params.put("mch_id", CommonWxPayPropertiesBuilder.instance().getMchId());//微信支付分配的商户号
+        params.put("fee_type", "HKD");//外币币种
+        params.put("date", DateUtils.format(new Date(),DateUtils.DATE_TIME_PATTERN_YYYY_MM_DD));//格式为yyyyMMdd
+        //签名前必须要参数全部写在前面
+        params.put("sign", WechatUtil.arraySign(params, CommonWxPayPropertiesBuilder.instance().getPaySignKey()));//签名
+        String mapToXml = MapUtils.convertMap2Xml(params);
+        //请求微信
+        String reponseXml = sendSSLPostToWx(mapToXml, WechatConfig.getSslcsf(), "https://api.mch.weixin.qq.com/pay/queryexchagerate");
+
+        WechatGlobalQueryRateResult result =
+                (WechatGlobalQueryRateResult) XmlUtil.xmlStrToBean(reponseXml, WechatGlobalQueryRateResult.class);
+        return result;
+    }
+
+    /**
+     * 微信境外申请退款
+     * @param
+     * @return
+     */
+    public static WechatGlobalRefundApiResult wxRefund(String out_trade_no, Double orderMoney, Double refundMoney) {
+        //初始化请求微信服务器的配置信息包括appid密钥等
+        //转换金钱格式
+        BigDecimal bdOrderMoney = new BigDecimal(orderMoney, MathContext.DECIMAL32);
+        BigDecimal bdRefundMoney = new BigDecimal(refundMoney, MathContext.DECIMAL32);
+        //构建请求参数
+        Map<Object, Object> params = new HashMap<Object, Object>();
+        params.put("appid", CommonWxPayPropertiesBuilder.instance().getAppId());//微信分配的公众账号ID(企业号corpid即为此appId)
+        params.put("mch_id", CommonWxPayPropertiesBuilder.instance().getMchId());//微信支付分配的商户号
+        params.put("nonce_str", CharUtil.getRandomString(16));//随机字符串,不长于32位。推荐随机数生成算法
+        params.put("out_trade_no", out_trade_no);//商户传给微信的订单号
+        params.put("out_refund_no", System.currentTimeMillis() + "");//商户系统内部的退款单号,商户系统内部唯一,同一退款单号多次请求只退一笔
+        params.put("total_fee", bdOrderMoney.multiply(Constant.ONE_HUNDRED).intValue());//订单总金额,单位为分,只能为整数
+        params.put("refund_fee", bdRefundMoney.multiply(Constant.ONE_HUNDRED).intValue());//退款总金额,订单总金额,单位为分,只能为整数
+        params.put("op_user_id", CommonWxPayPropertiesBuilder.instance().getMchId());//操作员帐号, 默认为商户号
+        params.put("notify_url", CommonWxPayPropertiesBuilder.instance().getRefundNotifyUrl());
+        //签名前必须要参数全部写在前面
+        params.put("sign", WechatUtil.arraySign(params, CommonWxPayPropertiesBuilder.instance().getPaySignKey()));//签名
+        String mapToXml = MapUtils.convertMap2Xml(params);
+
+        //请求微信
+        String reponseXml = sendRefundSSLPostToWx(mapToXml, WechatConfig.getSslcsf());
+        WechatGlobalRefundApiResult result =
+                (WechatGlobalRefundApiResult) XmlUtil.xmlStrToBean(reponseXml, WechatGlobalRefundApiResult.class);
+        result.setOut_refund_no((String) params.get("out_refund_no"));
+        return result;
+    }
+
+    /**
+     * 请求退款微信
+     **/
+    public static String sendRefundSSLPostToWx(String mapToXml, SSLConnectionSocketFactory sslcsf) {
+        logger.info("*******退款(WX Request:" + mapToXml);
+        String xmlStr = sendSSLPostToWx(mapToXml, sslcsf, CommonWxPayPropertiesBuilder.instance().getRefundUrl());
+        logger.info("*******退款(WX Response:" + xmlStr);
+        return xmlStr;
+    }
+
+
+    /**
+     * 微信境外查询退款
+     * @param
+     * @return
+     */
+    public static WechatGlobalRefundQueryResult wxRefundquery(String out_trade_no) {
+        Map<Object, Object> params = new HashMap<Object, Object>();
+        params.put("appid", CommonWxPayPropertiesBuilder.instance().getAppId());//微信分配的公众账号ID(企业号corpid即为此appId)
+        params.put("mch_id", CommonWxPayPropertiesBuilder.instance().getMchId());//微信支付分配的商户号
+        params.put("nonce_str", CharUtil.getRandomString(16));//随机字符串,不长于32位。推荐随机数生成算法
+        params.put("out_trade_no", out_trade_no);//商户侧传给微信的订单号
+        //签名前必须要参数全部写在前面
+        params.put("sign", WechatUtil.arraySign(params, CommonWxPayPropertiesBuilder.instance().getPaySignKey()));//签名
+        String mapToXml = MapUtils.convertMap2Xml(params);
+        String reponseXml = sendRefundQerutySSLPostToWx(mapToXml, WechatConfig.getSslcsf());
+        System.out.println(reponseXml);
+        WechatGlobalRefundQueryResult result =
+                (WechatGlobalRefundQueryResult) XmlUtil.xmlStrToBean(reponseXml, WechatGlobalRefundQueryResult.class);
+        result.setXmlStr(reponseXml);
+        return result;
+    }
+    public static String sendRefundQerutySSLPostToWx(String mapToXml, SSLConnectionSocketFactory sslcsf) {
+        logger.info("*******退款查询(WX Request:" + mapToXml);
+        String xmlStr = sendSSLPostToWx(mapToXml, sslcsf, CommonWxPayPropertiesBuilder.instance().getRefundqueryUrl());
+        logger.info("*******退款查询(WX Response:" + xmlStr);
+        return xmlStr;
+    }
+
+    /**
+     * 请求微信https
+     **/
+    private static String sendSSLPostToWx(String mapToXml, SSLConnectionSocketFactory sslcsf, String requestUrl) {
+
+        HttpPost httPost = new HttpPost(requestUrl);
+        httPost.addHeader("Connection", "keep-alive");
+        httPost.addHeader("Accept", "*/*");
+        httPost.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
+        httPost.addHeader("Host", "api.mch.weixin.qq.com");
+        httPost.addHeader("X-Requested-With", "XMLHttpRequest");
+        httPost.addHeader("Cache-Control", "max-age=0");
+        httPost.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) ");
+        httPost.setEntity(new StringEntity(mapToXml, "UTF-8"));
+        CloseableHttpClient httpClient = null;
+        if (sslcsf != null) {
+            httpClient = HttpClients.custom().setSSLSocketFactory(sslcsf).build();
+        } else {
+            httpClient = HttpClients.createDefault();
+        }
+
+        CloseableHttpResponse response = null;
+        try {
+            response = httpClient.execute(httPost);
+            HttpEntity entity = response.getEntity();
+            String xmlStr = EntityUtils.toString(entity, "UTF-8");
+            return xmlStr;
+        } catch (Exception e) {
+            logger.error(e.getMessage(), e);
+            return null;
+        } finally {
+            try {
+                if (response != null) {
+                    response.close();
+                }
+            } catch (IOException e) {
+                logger.error(e.getMessage(), e);
+            }
+        }
+    }
+
+    public static void main(String[] args) throws Exception {
+        Map<Object, Object> parame = new TreeMap<Object, Object>();
+        parame.put("mch_id", "");//
+        String randomStr = CharUtil.getRandomNum(18).toUpperCase();
+        parame.put("nonce_str", randomStr);//
+        String sign = WechatUtil.arraySign(parame, "");
+        parame.put("sign", sign);// 数字签证
+
+        String xml = MapUtils.convertMap2Xml(parame);
+        logger.info("xml:" + xml);
+        Map<String, Object> resultUn = XmlUtil.xmlStrToMap(
+                WechatUtil.requestOnce("https://apitest.mch.weixin.qq.com/sandboxnew/pay/getsignkey", xml));
+        System.out.print(resultUn);
+    }
+}

+ 240 - 0
kmall-common/src/main/java/com/kmall/common/utils/wechat/wxglobal/dto/WechatGlobalQueryApiResult.java

@@ -0,0 +1,240 @@
+package com.kmall.common.utils.wechat.wxglobal.dto;
+
+/**
+ * 微信境外支付查询返回的字段
+ * @author huangyaqin
+ * @version 1.0
+ * 2018-12-11 10:22
+ */
+public class WechatGlobalQueryApiResult {
+	private String return_code;
+	private String return_msg;
+
+	private String appid;
+	private String mch_id;
+	private String nonce_str;
+	private String sign;
+	private String result_code;
+	private String err_code;
+	private String err_code_des;
+
+	private String device_info;
+	private String openId;//用户标识
+	private String is_subscribe;//是否关注公众账号
+	private String trade_type;//调用接口提交的交易类型,取值如下:JSAPI,NATIVE,APP,MICROPAY
+	/**
+	 * SUCCESS—支付成功
+	 REFUND—转入退款
+	 NOTPAY—未支付
+	 CLOSED—已关闭
+	 REVOKED—已撤销(刷卡支付)
+	 USERPAYING--用户支付中
+	 PAYERROR--支付失败(其他原因,如银行返回失败)
+	 */
+	private String trade_state;
+	private String bank_type;//付款银行
+	private String total_fee;//订单金额
+	private String fee_type;
+	private String cash_fee;//用户支付金额
+	private String cash_fee_type;//用户支付金额币种
+	private String transaction_id;
+	private String out_trade_no;
+	private String attach;//附加数据
+	private String time_end;//支付完成时间 yyyyMMddHHmmss
+	/**
+	 * 标价币种与支付币种的兑换比例乘以10的8次方即为此值,例如美元兑换人民币的比例为6.5,则rate=650000000
+	 */
+	private String rate;//汇率
+
+	public String getReturn_code() {
+		return return_code;
+	}
+
+	public void setReturn_code(String return_code) {
+		this.return_code = return_code;
+	}
+
+	public String getReturn_msg() {
+		return return_msg;
+	}
+
+	public void setReturn_msg(String return_msg) {
+		this.return_msg = return_msg;
+	}
+
+	public String getAppid() {
+		return appid;
+	}
+
+	public void setAppid(String appid) {
+		this.appid = appid;
+	}
+
+	public String getMch_id() {
+		return mch_id;
+	}
+
+	public void setMch_id(String mch_id) {
+		this.mch_id = mch_id;
+	}
+
+	public String getNonce_str() {
+		return nonce_str;
+	}
+
+	public void setNonce_str(String nonce_str) {
+		this.nonce_str = nonce_str;
+	}
+
+	public String getSign() {
+		return sign;
+	}
+
+	public void setSign(String sign) {
+		this.sign = sign;
+	}
+
+	public String getResult_code() {
+		return result_code;
+	}
+
+	public void setResult_code(String result_code) {
+		this.result_code = result_code;
+	}
+
+	public String getErr_code() {
+		return err_code;
+	}
+
+	public void setErr_code(String err_code) {
+		this.err_code = err_code;
+	}
+
+	public String getErr_code_des() {
+		return err_code_des;
+	}
+
+	public void setErr_code_des(String err_code_des) {
+		this.err_code_des = err_code_des;
+	}
+
+	public String getDevice_info() {
+		return device_info;
+	}
+
+	public void setDevice_info(String device_info) {
+		this.device_info = device_info;
+	}
+
+	public String getOpenId() {
+		return openId;
+	}
+
+	public void setOpenId(String openId) {
+		this.openId = openId;
+	}
+
+	public String getIs_subscribe() {
+		return is_subscribe;
+	}
+
+	public void setIs_subscribe(String is_subscribe) {
+		this.is_subscribe = is_subscribe;
+	}
+
+	public String getTrade_type() {
+		return trade_type;
+	}
+
+	public void setTrade_type(String trade_type) {
+		this.trade_type = trade_type;
+	}
+
+	public String getTrade_state() {
+		return trade_state;
+	}
+
+	public void setTrade_state(String trade_state) {
+		this.trade_state = trade_state;
+	}
+
+	public String getBank_type() {
+		return bank_type;
+	}
+
+	public void setBank_type(String bank_type) {
+		this.bank_type = bank_type;
+	}
+
+	public String getTotal_fee() {
+		return total_fee;
+	}
+
+	public void setTotal_fee(String total_fee) {
+		this.total_fee = total_fee;
+	}
+
+	public String getFee_type() {
+		return fee_type;
+	}
+
+	public void setFee_type(String fee_type) {
+		this.fee_type = fee_type;
+	}
+
+	public String getCash_fee() {
+		return cash_fee;
+	}
+
+	public void setCash_fee(String cash_fee) {
+		this.cash_fee = cash_fee;
+	}
+
+	public String getCash_fee_type() {
+		return cash_fee_type;
+	}
+
+	public void setCash_fee_type(String cash_fee_type) {
+		this.cash_fee_type = cash_fee_type;
+	}
+
+	public String getTransaction_id() {
+		return transaction_id;
+	}
+
+	public void setTransaction_id(String transaction_id) {
+		this.transaction_id = transaction_id;
+	}
+
+	public String getOut_trade_no() {
+		return out_trade_no;
+	}
+
+	public void setOut_trade_no(String out_trade_no) {
+		this.out_trade_no = out_trade_no;
+	}
+
+	public String getAttach() {
+		return attach;
+	}
+
+	public void setAttach(String attach) {
+		this.attach = attach;
+	}
+
+	public String getTime_end() {
+		return time_end;
+	}
+
+	public void setTime_end(String time_end) {
+		this.time_end = time_end;
+	}
+
+	public String getRate() {
+		return rate;
+	}
+
+	public void setRate(String rate) {
+		this.rate = rate;
+	}
+}

+ 199 - 0
kmall-common/src/main/java/com/kmall/common/utils/wechat/wxglobal/dto/WechatGlobalRefundApiResult.java

@@ -0,0 +1,199 @@
+package com.kmall.common.utils.wechat.wxglobal.dto;
+/**
+ * 微信境外申请退款返回的字段
+ * @author huangyaqin
+ * @version 1.0
+ * 2018-12-11 10:22
+ */
+public class WechatGlobalRefundApiResult {
+	private String return_code;
+	private String return_msg;
+	
+	private String result_code;
+	private String err_code;
+	private String err_code_des;
+	private String appid;
+	private String mch_id;
+	private String nonce_str;
+	private String sign;
+	private String transaction_id;
+	private String out_trade_no;
+	private String out_refund_no;
+	private String refund_id;
+	private String refund_fee;//申请退款金额
+	private String refund_fee_type;//退款币种
+	private String total_fee;//订单金额
+	private String fee_type;
+	private String cash_fee;//用户支付金额
+	private String cash_fee_type;//用户支付金额币种
+	private String cash_refund_fee;//用户退款金额
+	private String cash_refund_fee_type;//用户退款金额币种
+
+	public String getReturn_code() {
+		return return_code;
+	}
+
+	public void setReturn_code(String return_code) {
+		this.return_code = return_code;
+	}
+
+	public String getReturn_msg() {
+		return return_msg;
+	}
+
+	public void setReturn_msg(String return_msg) {
+		this.return_msg = return_msg;
+	}
+
+	public String getResult_code() {
+		return result_code;
+	}
+
+	public void setResult_code(String result_code) {
+		this.result_code = result_code;
+	}
+
+	public String getErr_code() {
+		return err_code;
+	}
+
+	public void setErr_code(String err_code) {
+		this.err_code = err_code;
+	}
+
+	public String getErr_code_des() {
+		return err_code_des;
+	}
+
+	public void setErr_code_des(String err_code_des) {
+		this.err_code_des = err_code_des;
+	}
+
+	public String getAppid() {
+		return appid;
+	}
+
+	public void setAppid(String appid) {
+		this.appid = appid;
+	}
+
+	public String getMch_id() {
+		return mch_id;
+	}
+
+	public void setMch_id(String mch_id) {
+		this.mch_id = mch_id;
+	}
+
+	public String getNonce_str() {
+		return nonce_str;
+	}
+
+	public void setNonce_str(String nonce_str) {
+		this.nonce_str = nonce_str;
+	}
+
+	public String getSign() {
+		return sign;
+	}
+
+	public void setSign(String sign) {
+		this.sign = sign;
+	}
+
+	public String getTransaction_id() {
+		return transaction_id;
+	}
+
+	public void setTransaction_id(String transaction_id) {
+		this.transaction_id = transaction_id;
+	}
+
+	public String getOut_trade_no() {
+		return out_trade_no;
+	}
+
+	public void setOut_trade_no(String out_trade_no) {
+		this.out_trade_no = out_trade_no;
+	}
+
+	public String getOut_refund_no() {
+		return out_refund_no;
+	}
+
+	public void setOut_refund_no(String out_refund_no) {
+		this.out_refund_no = out_refund_no;
+	}
+
+	public String getRefund_id() {
+		return refund_id;
+	}
+
+	public void setRefund_id(String refund_id) {
+		this.refund_id = refund_id;
+	}
+
+	public String getRefund_fee() {
+		return refund_fee;
+	}
+
+	public void setRefund_fee(String refund_fee) {
+		this.refund_fee = refund_fee;
+	}
+
+	public String getRefund_fee_type() {
+		return refund_fee_type;
+	}
+
+	public void setRefund_fee_type(String refund_fee_type) {
+		this.refund_fee_type = refund_fee_type;
+	}
+
+	public String getTotal_fee() {
+		return total_fee;
+	}
+
+	public void setTotal_fee(String total_fee) {
+		this.total_fee = total_fee;
+	}
+
+	public String getFee_type() {
+		return fee_type;
+	}
+
+	public void setFee_type(String fee_type) {
+		this.fee_type = fee_type;
+	}
+
+	public String getCash_fee() {
+		return cash_fee;
+	}
+
+	public void setCash_fee(String cash_fee) {
+		this.cash_fee = cash_fee;
+	}
+
+	public String getCash_fee_type() {
+		return cash_fee_type;
+	}
+
+	public void setCash_fee_type(String cash_fee_type) {
+		this.cash_fee_type = cash_fee_type;
+	}
+
+	public String getCash_refund_fee() {
+		return cash_refund_fee;
+	}
+
+	public void setCash_refund_fee(String cash_refund_fee) {
+		this.cash_refund_fee = cash_refund_fee;
+	}
+
+	public String getCash_refund_fee_type() {
+		return cash_refund_fee_type;
+	}
+
+	public void setCash_refund_fee_type(String cash_refund_fee_type) {
+		this.cash_refund_fee_type = cash_refund_fee_type;
+	}
+}

+ 281 - 0
kmall-common/src/main/java/com/kmall/common/utils/wechat/wxglobal/dto/WechatGlobalRefundQueryResult.java

@@ -0,0 +1,281 @@
+package com.kmall.common.utils.wechat.wxglobal.dto;
+
+/**
+ * 微信境外退款查询返回的字段
+ * @author huangyaqin
+ * @version 1.0
+ * 2018-12-11 10:22
+ */
+public class WechatGlobalRefundQueryResult {
+    private String xmlStr;
+    private String return_code;
+    private String return_msg;
+
+    private String result_code;
+    private String err_code;
+    private String err_code_des;
+    private String appid;
+    private String mch_id;
+    private String nonce_str;
+    private String sign;
+    private String transaction_id;//微信订单号
+    private String out_trade_no;//商户订单号
+    private String total_fee;//订单金额 订单总金额,单位为分,只能为整数
+//    private String settlement_total_fee;//应结订单金额 =订单金额-免充值优惠券金额
+    private String fee_type;//货币种类
+    private String cash_fee;//现金支付金额	现金支付金额,单位为分,只能为整数
+    private String cash_fee_type;//用户支付金额币种
+    private String rate;//汇率
+    private String total_refund_count;//订单总退款次数
+    private String refund_count;//退款笔数
+
+    /**
+     * 以下数据会有多条
+     */
+    private String refund_fee;//申请退款金额	 退款总金额,单位为分,可以做部分退款
+    private String out_refund_no;//商户退款单号
+    private String refund_id;//微信退款单号
+    private String refund_channel;//退款渠道 ORIGINAL—原路退款 BALANCE—退回到余额 OTHER_BALANCE—原账户异常退到其他余额账户 OTHER_BANKCARD—原银行卡异常退到其他银行卡
+    /**
+     * SUCCESS—退款成功
+     REFUNDCLOSE—退款关闭。
+     PROCESSING—退款处理中
+     CHANGE—退款异常,退款到银行发现用户的卡作废或者冻结了,导致原路退款银行卡失败
+     */
+    private String refund_status;//退款状态
+    /**
+     * REFUND_SOURCE_RECHARGE_FUNDS---可用余额退款/基本账户
+     REFUND_SOURCE_UNSETTLED_FUNDS---未结算资金退款
+     */
+    private String refund_account;//退款资金来源
+    /**
+     * 取当前退款单的退款入账方
+     1)退回银行卡:
+     {银行名称}{卡类型}{卡尾号}
+     2)退回支付用户零钱:
+     支付用户零钱
+     3)退还商户:
+     商户基本账户
+     商户结算银行账户
+     4)退回支付用户零钱通:
+     支付用户零钱通
+     */
+    private String refund_recv_accout;
+    private String refund_success_time;//退款成功时间
+
+    public String getXmlStr() {
+        return xmlStr;
+    }
+
+    public void setXmlStr(String xmlStr) {
+        this.xmlStr = xmlStr;
+    }
+
+    public String getReturn_code() {
+        return return_code;
+    }
+
+    public void setReturn_code(String return_code) {
+        this.return_code = return_code;
+    }
+
+    public String getReturn_msg() {
+        return return_msg;
+    }
+
+    public void setReturn_msg(String return_msg) {
+        this.return_msg = return_msg;
+    }
+
+    public String getResult_code() {
+        return result_code;
+    }
+
+    public void setResult_code(String result_code) {
+        this.result_code = result_code;
+    }
+
+    public String getErr_code() {
+        return err_code;
+    }
+
+    public void setErr_code(String err_code) {
+        this.err_code = err_code;
+    }
+
+    public String getErr_code_des() {
+        return err_code_des;
+    }
+
+    public void setErr_code_des(String err_code_des) {
+        this.err_code_des = err_code_des;
+    }
+
+    public String getAppid() {
+        return appid;
+    }
+
+    public void setAppid(String appid) {
+        this.appid = appid;
+    }
+
+    public String getMch_id() {
+        return mch_id;
+    }
+
+    public void setMch_id(String mch_id) {
+        this.mch_id = mch_id;
+    }
+
+    public String getNonce_str() {
+        return nonce_str;
+    }
+
+    public void setNonce_str(String nonce_str) {
+        this.nonce_str = nonce_str;
+    }
+
+    public String getSign() {
+        return sign;
+    }
+
+    public void setSign(String sign) {
+        this.sign = sign;
+    }
+
+    public String getTransaction_id() {
+        return transaction_id;
+    }
+
+    public void setTransaction_id(String transaction_id) {
+        this.transaction_id = transaction_id;
+    }
+
+    public String getOut_trade_no() {
+        return out_trade_no;
+    }
+
+    public void setOut_trade_no(String out_trade_no) {
+        this.out_trade_no = out_trade_no;
+    }
+
+    public String getTotal_fee() {
+        return total_fee;
+    }
+
+    public void setTotal_fee(String total_fee) {
+        this.total_fee = total_fee;
+    }
+
+    public String getFee_type() {
+        return fee_type;
+    }
+
+    public void setFee_type(String fee_type) {
+        this.fee_type = fee_type;
+    }
+
+    public String getCash_fee() {
+        return cash_fee;
+    }
+
+    public void setCash_fee(String cash_fee) {
+        this.cash_fee = cash_fee;
+    }
+
+    public String getCash_fee_type() {
+        return cash_fee_type;
+    }
+
+    public void setCash_fee_type(String cash_fee_type) {
+        this.cash_fee_type = cash_fee_type;
+    }
+
+    public String getRate() {
+        return rate;
+    }
+
+    public void setRate(String rate) {
+        this.rate = rate;
+    }
+
+    public String getTotal_refund_count() {
+        return total_refund_count;
+    }
+
+    public void setTotal_refund_count(String total_refund_count) {
+        this.total_refund_count = total_refund_count;
+    }
+
+    public String getRefund_count() {
+        return refund_count;
+    }
+
+    public void setRefund_count(String refund_count) {
+        this.refund_count = refund_count;
+    }
+
+    public String getRefund_fee() {
+        return refund_fee;
+    }
+
+    public void setRefund_fee(String refund_fee) {
+        this.refund_fee = refund_fee;
+    }
+
+    public String getOut_refund_no() {
+        return out_refund_no;
+    }
+
+    public void setOut_refund_no(String out_refund_no) {
+        this.out_refund_no = out_refund_no;
+    }
+
+    public String getRefund_id() {
+        return refund_id;
+    }
+
+    public void setRefund_id(String refund_id) {
+        this.refund_id = refund_id;
+    }
+
+    public String getRefund_channel() {
+        return refund_channel;
+    }
+
+    public void setRefund_channel(String refund_channel) {
+        this.refund_channel = refund_channel;
+    }
+
+    public String getRefund_status() {
+        return refund_status;
+    }
+
+    public void setRefund_status(String refund_status) {
+        this.refund_status = refund_status;
+    }
+
+    public String getRefund_account() {
+        return refund_account;
+    }
+
+    public void setRefund_account(String refund_account) {
+        this.refund_account = refund_account;
+    }
+
+    public String getRefund_recv_accout() {
+        return refund_recv_accout;
+    }
+
+    public void setRefund_recv_accout(String refund_recv_accout) {
+        this.refund_recv_accout = refund_recv_accout;
+    }
+
+    public String getRefund_success_time() {
+        return refund_success_time;
+    }
+
+    public void setRefund_success_time(String refund_success_time) {
+        this.refund_success_time = refund_success_time;
+    }
+}

+ 5 - 7
kmall-schedule/src/main/java/com/kmall/schedule/service/QzOrderService.java

@@ -226,13 +226,10 @@ public class QzOrderService {
                 String out_trade_no = MapUtils.getString("merch_order_sn", map);
                 String order_id = MapUtils.getString("order_id", map);
                 Integer is_onffline_order = MapUtils.getInteger("is_onffline_order", map);
-                String order_sn = MapUtils.getString("order_sn", map);
+                String order_sn_wx = MapUtils.getString("order_sn_wx", map);
 
-                if(is_onffline_order == 1){
-                    List<Map> paySuccessRecords = qzOrderMapper.queryWXPaySuccessRecords(order_sn);
-                    if(paySuccessRecords != null && paySuccessRecords.size() > 0){
-                        out_trade_no = MapUtils.getString("out_trade_no_wx", paySuccessRecords.get(0));
-                    }
+                if (is_onffline_order == 1) {
+                    out_trade_no = order_sn_wx;
                 }
 
                 WechatRefundQueryResult result = WechatUtil.wxRefundquery(out_trade_no);
@@ -328,7 +325,6 @@ public class QzOrderService {
                         result.getTrade_state().equalsIgnoreCase("SUCCESS")) {
                         Date successTime = DateUtils.convertStringToDate(result.getTime_end(),
                                                                          DateUtils.DATE_TIME_PATTERN_YYYY_MM_DD_HH_MM_SS);
-
                         Map orderRaram = new HashMap();
                         orderRaram.put("payStatus", 2);//已支付
                         orderRaram.put("orderStatus", 201);//已支付
@@ -418,6 +414,8 @@ public class QzOrderService {
                             Map orderRaram = new HashMap();
                             orderRaram.put("payStatus", 2);//已支付
                             orderRaram.put("orderStatus", 201);//已支付
+                            orderRaram.put("payFlag", "weixin");
+                            orderRaram.put("orderSnWx",out_trade_no_wx);
                             orderRaram.put("payTime", new Date());
                             orderRaram.put("orderId", MapUtils.getInteger("id", order));
                             qzOrderMapper.updateOrderInfo(orderRaram);

+ 3 - 2
kmall-schedule/src/main/resources/mybatis/mapper/QzOrderMapper.xml

@@ -48,7 +48,7 @@
 
 
     <select id="queryRefundOrderList" resultType="map">
-        select a.pay_transaction_id,a.merch_order_sn,a.order_sn,a.order_status,a.pay_status,f.out_refund_no,f.refund_id,f.order_id,f.id 'orderRefundId',a.is_onffline_order
+        select a.pay_transaction_id,a.merch_order_sn,a.order_sn,a.order_status,a.pay_status,f.out_refund_no,f.refund_id,f.order_id,f.id 'orderRefundId',a.is_onffline_order,a.order_sn_wx
         from mall_order a
         inner join mall_order_refund f on a.id = f.order_id	where (f.out_refund_no is null or f.refund_id is null
         or f.refund_time is null or f.wechat_refund_status_des is null) and a.order_status = '401' and f.refund_status
@@ -66,12 +66,13 @@
         AND a.is_onffline_order = 0
     </select>
 
-
     <update id="updateOrderInfo" parameterType="map">
         UPDATE mall_order a
         <set>
             <if test="orderStatus != null">a.order_status = #{orderStatus},</if>
             <if test="payStatus != null">a.pay_status = #{payStatus},</if>
+            <if test="payFlag != null">a.pay_flag = #{payFlag},</if>
+            <if test="orderSnWx != null">a.order_sn_wx = #{orderSnWx},</if>
             <if test="payTransactionId != null">a.pay_transaction_id = #{payTransactionId},</if>
             <if test="payTime != null">a.pay_time = #{payTime},</if>
         </set>