Browse Source

Merge branch 'master' of hyq/kmall-pt into master

黄亚琴 6 years ago
parent
commit
3394de4ff0

+ 97 - 48
kmall-admin/src/main/java/com/kmall/admin/controller/OrderController.java

@@ -14,6 +14,9 @@ import com.kmall.common.utils.wechat.WechatMicropayApiResult;
 import com.kmall.common.utils.wechat.WechatRefundApiResult;
 import com.kmall.common.utils.wechat.WechatReverseApiResult;
 import com.kmall.common.utils.wechat.WechatUtil;
+import com.kmall.common.utils.wechat.wxglobal.WechatGlobalUtil;
+import com.kmall.common.utils.wechat.wxglobal.dto.WechatGlobalRefundApiResult;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -300,45 +303,92 @@ public class OrderController {
         if (totalActualPrice == null) {
             totalActualPrice = 0d;
         }
-
-        if (orderInfo.getOrderStatus() != 0) {
-            // todo 退款
-            //          WechatRefundApiResult result = WechatUtil.wxRefund(orderInfo.getOrderSn().toString(),
-            //          orderInfo.getActualPrice().doubleValue(), refundMoney.doubleValue());
-            WechatRefundApiResult result = WechatUtil.wxRefund(orderInfo.getMerchOrderSn().toString(), totalActualPrice,
-                                                               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);//退款记录
+        String refundResult = "";
+        if (orderInfo.getOrderStatus() != Integer.parseInt(Dict.orderStatus.item_0.getItem())) {
+            if(orderInfo.getPayFlag().equalsIgnoreCase(Dict.payFlag.item_wxglobalpay.getItem())){
+                refundResult = wxGlobalRefund(orderInfo,totalActualPrice);
+                if(StringUtils.isNotBlank(refundResult)){
+                    return R.error(refundResult);
+                }
+            }else{
+                refundResult = wxRefund(orderInfo,totalActualPrice);
+                if(StringUtils.isNotBlank(refundResult)){
+                    return R.error(refundResult);
                 }
-
-                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.ok("退款成功");
     }
-
+    /**
+     * 微信申请退款
+     * @param orderInfo
+     * @param totalActualPrice
+     * @return
+     */
+    private String wxRefund(OrderEntity orderInfo,Double totalActualPrice){
+        WechatRefundApiResult result = WechatUtil.wxRefund(orderInfo.getMerchOrderSn().toString(), totalActualPrice,
+                orderInfo.getActualPrice().doubleValue());
+        if (result.getResult_code().equals(WechatUtil.WXTradeState.SUCCESS.getCode())) {
+            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);
+            return result.getErr_code_des();
+        }
+        return "";
+    }
 
     /**
+     * 微信国际申请退款
+     * @param orderInfo
+     * @param totalActualPrice
+     * @return
+     */
+    private String wxGlobalRefund(OrderEntity orderInfo,Double totalActualPrice){
+        WechatGlobalRefundApiResult result = WechatGlobalUtil.wxRefund(orderInfo.getMerchOrderSn().toString(), totalActualPrice,
+                orderInfo.getActualPrice().doubleValue());
+        if (result.getResult_code().equals(WechatUtil.WXTradeState.SUCCESS.getCode())) {
+            orderService.globalRefund(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.setOutRefundNo(result.getOut_refund_no());
+            orderRefund.setModTime(new Date());
+            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);
+            return result.getErr_code_des();
+        }
+        return "";
+    }
+    /**
      * 订单退款请求
      */
     @RequiresPermissions(value = {"order:offilineRefund"})
@@ -353,17 +403,16 @@ public class OrderController {
             return R.error("订单已退款");
         }
 
-        if (orderInfo.getOrderStatus() != 0) {
-            //现金支付
+        if (orderInfo.getOrderStatus() != Integer.parseInt(Dict.orderStatus.item_0.getItem())) {
             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")) {
+                if (result.getResult_code().equals(WechatUtil.WXTradeState.SUCCESS.getCode())) {
                     orderService.refund(orderInfo, result);
                 } else {
                     OrderRefundEntity mallOrderRefund = orderRefundService.queryObjectByOrderId(orderInfo.getId());
@@ -371,8 +420,8 @@ public class OrderController {
                     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());
+                    orderRefund.setModTime(new Date());
                     if (mallOrderRefund != null) {
                         orderRefund.setId(mallOrderRefund.getId());
                         orderRefundService.update(orderRefund);//退款记录
@@ -434,7 +483,7 @@ public class OrderController {
     @RequestMapping("/confirmPay")
     @RequiresPermissions("order:confirmPay")
     public R confirmPay(@RequestBody Long id) {
-        orderService.confirmPay(id, Dict.payFlag.item_cash, null);
+        orderService.confirmPay(id, Dict.payFlag.item_cash.getItem(), null);
 
         return R.ok();
     }
@@ -512,13 +561,13 @@ public class OrderController {
                     WechatReverseApiResult wechatReverseApiResult =
                             WechatUtil.wxReverse(orderWXPayRecordTemp.getOutTradeNoWX());
                     //撤销订单成功
-                    if ("SUCCESS".equals(wechatReverseApiResult.getReturn_code()) &&
-                        "SUCCESS".equals(wechatReverseApiResult.getResult_code())) {
+                    if (WechatUtil.WXTradeState.SUCCESS.getCode().equals(wechatReverseApiResult.getReturn_code()) &&
+                            WechatUtil.WXTradeState.SUCCESS.getCode().equals(wechatReverseApiResult.getResult_code())) {
                         //调用订单查询接口
                         WechatRefundApiResult wechatRefundApiResult =
                                 WechatUtil.wxOrderQuery(orderWXPayRecordTemp.getOutTradeNoWX());
-                        if ("SUCCESS".equals(wechatRefundApiResult.getReturn_code()) &&
-                            "SUCCESS".equals(wechatRefundApiResult.getResult_code())) {
+                        if (WechatUtil.WXTradeState.SUCCESS.getCode().equals(wechatRefundApiResult.getReturn_code()) &&
+                                WechatUtil.WXTradeState.SUCCESS.getCode().equals(wechatRefundApiResult.getResult_code())) {
                             // 修改订单支付记录
                             orderWXPayRecordService
                                     .updateWXPayRecordTradeState(orderWXPayRecordTemp.getId(), wechatRefundApiResult);
@@ -526,7 +575,7 @@ public class OrderController {
                     }
                 }
             }
-            orderService.confirmPay(id, Dict.payFlag.item_weixin, orderWXPayRecordCurrent.getOutTradeNoWX());
+            orderService.confirmPay(id, Dict.payFlag.item_weixin.getItem(), orderWXPayRecordCurrent.getOutTradeNoWX());
             r = R.ok();
             //用户支付中
         } else if (WechatUtil.WXTradeState.USERPAYING.getCode().equals(wechatMicropayApiResult.getTrade_state())) {
@@ -536,13 +585,13 @@ public class OrderController {
             WechatReverseApiResult wechatReverseApiResult =
                     WechatUtil.wxReverse(orderWXPayRecordCurrent.getOutTradeNoWX());
             //撤销订单成功
-            if ("SUCCESS".equals(wechatReverseApiResult.getReturn_code()) &&
-                "SUCCESS".equals(wechatReverseApiResult.getResult_code())) {
+            if (WechatUtil.WXTradeState.SUCCESS.getCode().equals(wechatReverseApiResult.getReturn_code()) &&
+                    WechatUtil.WXTradeState.SUCCESS.getCode().equals(wechatReverseApiResult.getResult_code())) {
                 //调用订单查询接口
                 WechatRefundApiResult wechatRefundApiResult =
                         WechatUtil.wxOrderQuery(orderWXPayRecordCurrent.getOutTradeNoWX());
-                if ("SUCCESS".equals(wechatRefundApiResult.getReturn_code()) &&
-                    "SUCCESS".equals(wechatRefundApiResult.getResult_code())) {
+                if (WechatUtil.WXTradeState.SUCCESS.getCode().equals(wechatRefundApiResult.getReturn_code()) &&
+                        WechatUtil.WXTradeState.SUCCESS.getCode().equals(wechatRefundApiResult.getResult_code())) {
                     // 修改订单支付记录
                     orderWXPayRecordService
                             .updateWXPayRecordTradeState(orderWXPayRecordCurrent.getId(), wechatRefundApiResult);

+ 97 - 0
kmall-admin/src/main/java/com/kmall/admin/entity/OrderRefundEntity.java

@@ -115,6 +115,39 @@ public class OrderRefundEntity implements Serializable {
 
     private String userName;
 
+    /**
+     * 退款币种;微信国际退款返回数据
+     */
+    private String refundFeeType;
+    /**
+     * 标价金额;微信国际退款返回数据
+     */
+    private Integer totalFee;
+    /**
+     * 标价币种;微信国际退款返回数据
+     */
+    private String feeType;
+    /**
+     * 用户支付金额;微信国际退款返回数据
+     */
+    private Integer cashFee;
+    /**
+     * 用户支付币种;微信国际退款返回数据
+     */
+    private String cashFeeType;
+    /**
+     * 用户支付退款金额;微信国际退款返回数据
+     */
+    private Integer cashRefundFee;
+    /**
+     * 用户支付退款币种;微信国际退款返回数据
+     */
+    private String cashRefundFeeType;
+    /**
+     * 汇率
+     */
+    private String rate;
+
     public String getOrderSn() {
         return orderSn;
     }
@@ -410,4 +443,68 @@ public class OrderRefundEntity implements Serializable {
     public Date getTstm() {
         return tstm;
     }
+
+    public String getRefundFeeType() {
+        return refundFeeType;
+    }
+
+    public void setRefundFeeType(String refundFeeType) {
+        this.refundFeeType = refundFeeType;
+    }
+
+    public Integer getTotalFee() {
+        return totalFee;
+    }
+
+    public void setTotalFee(Integer totalFee) {
+        this.totalFee = totalFee;
+    }
+
+    public String getFeeType() {
+        return feeType;
+    }
+
+    public void setFeeType(String feeType) {
+        this.feeType = feeType;
+    }
+
+    public Integer getCashFee() {
+        return cashFee;
+    }
+
+    public void setCashFee(Integer cashFee) {
+        this.cashFee = cashFee;
+    }
+
+    public String getCashFeeType() {
+        return cashFeeType;
+    }
+
+    public void setCashFeeType(String cashFeeType) {
+        this.cashFeeType = cashFeeType;
+    }
+
+    public Integer getCashRefundFee() {
+        return cashRefundFee;
+    }
+
+    public void setCashRefundFee(Integer cashRefundFee) {
+        this.cashRefundFee = cashRefundFee;
+    }
+
+    public String getCashRefundFeeType() {
+        return cashRefundFeeType;
+    }
+
+    public void setCashRefundFeeType(String cashRefundFeeType) {
+        this.cashRefundFeeType = cashRefundFeeType;
+    }
+
+    public String getRate() {
+        return rate;
+    }
+
+    public void setRate(String rate) {
+        this.rate = rate;
+    }
 }

+ 8 - 0
kmall-admin/src/main/java/com/kmall/admin/service/OrderService.java

@@ -8,6 +8,7 @@ import com.kmall.common.entity.SysUserEntity;
 import com.kmall.common.utils.R;
 import com.kmall.common.utils.print.ticket.item.Ticket;
 import com.kmall.common.utils.wechat.WechatRefundApiResult;
+import com.kmall.common.utils.wechat.wxglobal.dto.WechatGlobalRefundApiResult;
 
 import java.math.BigDecimal;
 import java.util.List;
@@ -61,6 +62,13 @@ public interface OrderService {
      */
     void refund(OrderEntity orderInfo, WechatRefundApiResult result);
 
+    /**
+     * 微信国际退款逻辑处理
+     * @param order
+     * @param result
+     */
+    void globalRefund(OrderEntity order, WechatGlobalRefundApiResult result);
+
     List<OrderRefundEntity> queryRefundList(Map<String, Object> map);
 
     int queryRefundTotal(Map<String, Object> map);

+ 60 - 0
kmall-admin/src/main/java/com/kmall/admin/service/impl/OrderServiceImpl.java

@@ -22,6 +22,8 @@ import com.kmall.common.utils.RRException;
 import com.kmall.common.utils.StringUtils;
 import com.kmall.common.utils.express.kdn.KdniaoUtil;
 import com.kmall.common.utils.wechat.WechatRefundApiResult;
+import com.kmall.common.utils.wechat.wxglobal.dto.WechatGlobalRefundApiResult;
+import io.swagger.models.auth.In;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -293,6 +295,64 @@ public class OrderServiceImpl
         updateStock(order);
     }
 
+
+    /**
+     * 微信国际退款逻辑处理
+     * @param order
+     * @param result
+     */
+    @Transactional
+    public void globalRefund(OrderEntity order, WechatGlobalRefundApiResult result) {
+        boolean needUpdateStock = true;
+        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()));
+        OrderRefundEntity orderRefund = new OrderRefundEntity();
+        orderRefund.setRefundId(result.getRefund_id());
+        orderRefund.setOutRefundNo(result.getOut_refund_no());
+        orderRefund.setRefundStatus(Integer.parseInt(Dict.RefundStatus.item_5.getItem()));//退款处理中
+        orderRefund.setModTime(new Date());
+        orderRefund.setRefundMoney(BigDecimal.valueOf(Long.valueOf(result.getRefund_fee())).divide(Constant.ONE_HUNDRED));
+        orderRefund.setRefundFeeType(result.getRefund_fee_type());
+        if(org.apache.commons.lang3.StringUtils.isNotEmpty(result.getTotal_fee())) {
+            orderRefund.setTotalFee(Integer.parseInt(BigDecimal.valueOf(Long.valueOf(result.getTotal_fee())).divide(Constant.ONE_HUNDRED).toString()));
+        }
+        orderRefund.setFeeType(result.getFee_type());
+        if(org.apache.commons.lang3.StringUtils.isNotEmpty(result.getCash_fee())) {
+            orderRefund.setCashFee(Integer.parseInt(BigDecimal.valueOf(Long.valueOf(result.getCash_fee())).divide(Constant.ONE_HUNDRED).toString()));
+        }
+        orderRefund.setCashFeeType(result.getCash_fee_type());
+        if(org.apache.commons.lang3.StringUtils.isNotEmpty(result.getCash_refund_fee())) {
+            orderRefund.setCashRefundFee(Integer.parseInt(BigDecimal.valueOf(Long.valueOf(result.getCash_refund_fee())).divide(Constant.ONE_HUNDRED).toString()));
+        }
+        orderRefund.setCashRefundFeeType(result.getCash_refund_fee_type());
+
+        OrderRefundEntity mallOrderRefund = orderRefundDao.queryObjectByOrderId(order.getId());
+        if (mallOrderRefund != null) {
+            orderRefund.setRefundType(mallOrderRefund.getRefundType());
+            orderRefund.setId(mallOrderRefund.getId());
+            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);
+        }
+
+        if (!needUpdateStock) {
+            return;
+        }
+        // 更新库存
+        updateStock(order);
+    }
+
     private void updateStock(OrderEntity order){
         Map<String, Object> map = new HashMap<String, Object>();
         map.put("orderId", order.getId());

+ 41 - 0
kmall-admin/src/main/resources/mybatis/mapper/OrderRefundDao.xml

@@ -29,6 +29,15 @@
         <result property="orderStatus" column="order_status"/>
         <result property="actualPrice" column="actual_price"/>
         <result property="userName" column="username"/>
+
+        <result property="refundFeeType" column="refund_fee_type"/>
+        <result property="totalFee" column="total_fee"/>
+        <result property="feeType" column="fee_type"/>
+        <result property="cashFee" column="cash_fee"/>
+        <result property="cashFeeType" column="cash_fee_type"/>
+        <result property="cashRefundFee" column="cash_refund_fee"/>
+        <result property="cashRefundFeeType" column="cash_refund_fee_type"/>
+        <result property="rate" column="rate"/>
     </resultMap>
 
     <select id="queryObject" resultType="com.kmall.admin.entity.OrderRefundEntity">
@@ -42,6 +51,14 @@
         r.refund_time,
         r.creator,
         r.refund_money,
+		r.refund_fee_type,
+		r.total_fee,
+		r.fee_type,
+		r.cash_fee,
+		r.cash_fee_type,
+		r.cash_refund_fee,
+		r.cash_refund_fee_type,
+		r.rate,
         r.refund_status,
         r.refund_reason,
         r.wechat_refund_status_des,
@@ -173,6 +190,14 @@
 			`refund_time`,
 			`creator`,
 			`refund_money`,
+			`refund_fee_type`,
+			`total_fee`,
+			`fee_type`,
+			`cash_fee`,
+			`cash_fee_type`,
+			`cash_refund_fee`,
+			`cash_refund_fee_type`,
+			`rate`,
 			`refund_status`,
 			`wechat_refund_status_des`,
 			`approver`,
@@ -186,6 +211,14 @@
 			#{refundTime},
 			#{creator},
 			#{refundMoney},
+			#{refundFeeType},
+			#{totalFee},
+			#{feeType},
+			#{cashFee},
+			#{cashFeeType},
+			#{cashRefundFee},
+			#{cashRefundFeeType},
+			#{rate},
 			#{refundStatus},
 			#{wechatRefundStatusDes},
 			#{approver},
@@ -203,6 +236,14 @@
             <if test="refundTime != null">`refund_time` = #{refundTime},</if>
             <if test="creator != null">`creator` = #{creator},</if>
             <if test="refundMoney != null">`refund_money` = #{refundMoney},</if>
+            <if test="refundFeeType != null">`refund_fee_type` = #{refundFeeType}, </if>
+            <if test="totalFee != null">`total_fee` = #{totalFee}, </if>
+            <if test="feeType != null">`fee_type` = #{feeType}, </if>
+            <if test="cashFee != null">`cash_fee` = #{cashFee}, </if>
+            <if test="cashFeeType != null">`cash_fee_type` = #{cashFeeType}, </if>
+            <if test="cashRefundFee != null">`cash_refund_fee` = #{cashRefundFee}, </if>
+            <if test="cashRefundFeeType != null">`cash_refund_fee_type` = #{cashRefundFeeType}, </if>
+            <if test="rate != null">`rate` = #{rate}, </if>
             <if test="refundStatus != null">`refund_status` = #{refundStatus},</if>
             <if test="wechatRefundStatusDes != null">`wechat_refund_status_des` = #{wechatRefundStatusDes},</if>
             <if test="approver != null">`approver` = #{approver},</if>

+ 1 - 1
kmall-api/src/main/java/com/kmall/api/api/ApiOrderController.java

@@ -269,7 +269,7 @@ public class ApiOrderController extends ApiBaseAction {
             if (orderVo.getPay_status() == 2) {
                 WechatRefundApiResult result = WechatUtil.wxRefund(orderVo.getMerchOrderSn().toString(),
                         orderVo.getActual_price().doubleValue(), orderVo.getActual_price().doubleValue());
-                if (result.getResult_code().equals("SUCCESS")) {
+                if (result.getResult_code().equals(WechatUtil.WXTradeState.SUCCESS.getCode())) {
                     if (orderVo.getOrder_status() == 201) {
                         orderVo.setOrder_status(401);
                     } else if (orderVo.getOrder_status() == 300) {

+ 19 - 18
kmall-common/src/main/java/com/kmall/common/utils/wechat/wxglobal/WechatGlobalUtil.java

@@ -116,7 +116,7 @@ public class WechatGlobalUtil {
         }
         param.put("out_trade_no", out_trade_no);// 商户订单编号
         //支付金额
-        param.put("total_fee", actual_price.multiply(Constant.ONE_HUNDRED).intValue());// 消费金额
+        param.put("total_fee", Math.round(actual_price.multiply(Constant.ONE_HUNDRED).doubleValue()));// 消费金额
         param.put("fee_type",CommonWxGlobalPayPropertiesBuilder.instance().getFeeType());//标价币种
         param.put("spbill_create_ip", CommonWxGlobalPayPropertiesBuilder.instance().getSpbillCreateIp());
         param.put("notify_url", CommonWxGlobalPayPropertiesBuilder.instance().getNotifyUrl());// 回调地址
@@ -194,7 +194,9 @@ public class WechatGlobalUtil {
 
     /**
      * 微信境外申请退款
-     * @param
+     * @param out_trade_no 商户订单编号
+     * @param orderMoney 订单总金额
+     * @param refundMoney 申请退款金额
      * @return
      */
     public static WechatGlobalRefundApiResult wxRefund(String out_trade_no, Double orderMoney, Double refundMoney) {
@@ -209,8 +211,8 @@ public class WechatGlobalUtil {
         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("total_fee", Math.round(bdOrderMoney.multiply(Constant.ONE_HUNDRED).doubleValue()));//订单总金额,单位为分,只能为整数
+        params.put("refund_fee", Math.round(bdRefundMoney.multiply(Constant.ONE_HUNDRED).doubleValue()));//退款总金额,订单总金额,单位为分,只能为整数
         params.put("op_user_id", CommonWxGlobalPayPropertiesBuilder.instance().getMchId());//操作员帐号, 默认为商户号
         params.put("notify_url", CommonWxGlobalPayPropertiesBuilder.instance().getRefundNotifyUrl());
         //签名前必须要参数全部写在前面
@@ -234,8 +236,6 @@ public class WechatGlobalUtil {
         logger.info("*******退款(WX Response:" + xmlStr);
         return xmlStr;
     }
-
-
     /**
      * 微信境外查询退款
      * @param
@@ -265,17 +265,18 @@ public class WechatGlobalUtil {
     }
 
     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);
+//        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);
+        System.out.println(Math.round(new BigDecimal("21.6366").multiply(Constant.ONE_HUNDRED).doubleValue()));
     }
 }

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

@@ -20,10 +20,10 @@ public class WechatGlobalRefundApiResult {
 	private String out_trade_no;
 	private String out_refund_no;
 	private String refund_id;
-	private String refund_fee;//申请退款金额
+	private String refund_fee;//申请退款金额,可支持部分退款
 	private String refund_fee_type;//退款币种
-	private String total_fee;//订单金额
-	private String fee_type;
+	private String total_fee;//订单金额
+	private String fee_type;//订单总金额币种
 	private String cash_fee;//用户支付金额
 	private String cash_fee_type;//用户支付金额币种
 	private String cash_refund_fee;//用户退款金额

+ 8 - 2
kmall-schedule/src/main/java/com/kmall/schedule/service/QzOrderService.java

@@ -352,9 +352,15 @@ public class QzOrderService {
                             refundRaram.put("refundMoney",
                                     BigDecimal.valueOf(Long.valueOf(result.getRefund_fee()))
                                             .divide(Constant.ONE_HUNDRED));//退款金额
-                            refundRaram.put("totalFee", result.getTotal_fee());//标价金额
+                            if(org.apache.commons.lang3.StringUtils.isNotEmpty(result.getTotal_fee())) {
+                                refundRaram.put("totalFee", BigDecimal.valueOf(Long.valueOf(result.getTotal_fee()))
+                                        .divide(Constant.ONE_HUNDRED));//标价金额
+                            }
                             refundRaram.put("feeType", result.getFee_type());//标价币种
-                            refundRaram.put("cashFee", result.getCash_fee());//用户支付金额
+                            if(org.apache.commons.lang3.StringUtils.isNotEmpty(result.getCash_fee())) {
+                                refundRaram.put("cashFee", BigDecimal.valueOf(Long.valueOf(result.getCash_fee()))
+                                        .divide(Constant.ONE_HUNDRED));//用户支付金额
+                            }
                             refundRaram.put("cashFeeType", result.getCash_fee_type());//用户支付金额币种
                             refundRaram.put("rate", result.getRate());//汇率
                             if (result.getRefund_status().equalsIgnoreCase(WechatUtil.WXTradeState.SUCCESS.getCode())) {