diff --git a/hai-bweb/src/main/java/com/bweb/controller/OutRechargeOrderController.java b/hai-bweb/src/main/java/com/bweb/controller/OutRechargeOrderController.java index afb35821..dd005af4 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/OutRechargeOrderController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/OutRechargeOrderController.java @@ -3,9 +3,12 @@ package com.bweb.controller; import com.alibaba.excel.EasyExcel; import com.alibaba.fastjson.JSONObject; import com.bweb.config.SysConst; +import com.bweb.excelListener.ImportCouponListener; +import com.bweb.excelListener.ImportRechargeOrderListener; import com.bweb.model.ExportOutRechargeOrder; import com.bweb.model.ExportOutRechargeOrderCount; import com.bweb.model.ExportOutRechargeUserOrderCount; +import com.bweb.model.ImportCouponModel; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.hai.common.exception.ErrorCode; @@ -13,10 +16,12 @@ import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; import com.hai.common.pay.util.XmlUtil; import com.hai.common.pay.util.sdk.WXPayConstants; +import com.hai.common.security.SessionObject; import com.hai.common.utils.ResponseMsgUtil; import com.hai.common.utils.WxUtils; import com.hai.config.HuiLianTongUnionCardConfig; import com.hai.config.UnionPayConfig; +import com.hai.entity.HighCoupon; import com.hai.entity.HighRefundAudit; import com.hai.entity.OutRechargeOrder; import com.hai.model.*; @@ -36,6 +41,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; @@ -119,6 +125,29 @@ public class OutRechargeOrderController { } } + @RequestMapping(value="/importRechargeOrder",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "导入话费充值订单") + public ResponseData importRechargeOrder( @RequestParam(value = "file" , required = true) MultipartFile files, + HttpServletRequest request) { + try { + + ImportRechargeOrderListener importRechargeOrderListener = new ImportRechargeOrderListener(); + importRechargeOrderListener.initData(outRechargeOrderService); + EasyExcel.read(files.getInputStream(), ExportOutRechargeOrder.class, importRechargeOrderListener).sheet().doRead(); + + Map map = new HashMap<>(); + map.put("errorData", importRechargeOrderListener.getErrorData()); + map.put("errorTotal", importRechargeOrderListener.getErrorData().size()); + + return ResponseMsgUtil.success(map); + + } catch (Exception e) { + log.error("HighCouponController -> importStock() error!",e); + return ResponseMsgUtil.exception(e); + } + } + @RequestMapping(value = "/getOrderList", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "获取订单") @@ -127,6 +156,7 @@ public class OutRechargeOrderController { @RequestParam(name = "orderNo", required = false) String orderNo, @RequestParam(name = "rechargeModel", required = false) String rechargeModel, @RequestParam(name = "rechargeContent", required = false) String rechargeContent, + @RequestParam(name = "rechargeType", required = false) String rechargeType, @RequestParam(name = "userPhone", required = false) String userPhone, @RequestParam(name = "idCard", required = false) String idCard, @RequestParam(name = "payType", required = false) Integer payType, @@ -153,6 +183,9 @@ public class OutRechargeOrderController { if (StringUtils.isNotBlank(rechargeContent)) { map.put("rechargeContent", rechargeContent); } + if (StringUtils.isNotBlank(rechargeType)) { + map.put("rechargeType", rechargeType); + } if (StringUtils.isNotBlank(userPhone)) { map.put("userPhone", userPhone); @@ -205,6 +238,7 @@ public class OutRechargeOrderController { @RequestParam(name = "rechargeContent", required = false) String rechargeContent, @RequestParam(name = "userPhone", required = false) String userPhone, @RequestParam(name = "idCard", required = false) String idCard, + @RequestParam(name = "rechargeType", required = false) String rechargeType, @RequestParam(name = "payType", required = false) Integer payType, @RequestParam(name = "code", required = false) Integer code, @RequestParam(name = "createTimeS", required = false) Long createTimeS, @@ -222,6 +256,7 @@ public class OutRechargeOrderController { map.put("idCard", idCard); map.put("payType", payType); map.put("code", code); + map.put("rechargeType", rechargeType); map.put("createTimeS", createTimeS); map.put("createTimeE", createTimeE); map.put("payTimeS", payTimeS); diff --git a/hai-bweb/src/main/java/com/bweb/controller/OutRechargePriceController.java b/hai-bweb/src/main/java/com/bweb/controller/OutRechargePriceController.java index 9c52a8b9..79eab735 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/OutRechargePriceController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/OutRechargePriceController.java @@ -46,6 +46,7 @@ public class OutRechargePriceController { public ResponseData getListOutRechargePrice( @RequestParam(value = "type", required = false) Integer type , @RequestParam(value = "showType", required = false) Integer showType , + @RequestParam(value = "rechargeType", required = false) Integer rechargeType , @RequestParam(name = "pageNum", required = true) Integer pageNum, @RequestParam(name = "pageSize", required = true) Integer pageSize, HttpServletRequest request ) { @@ -64,6 +65,10 @@ public class OutRechargePriceController { map.put("showType", String.valueOf(showType)); } + if (rechargeType != null ) { + map.put("rechargeType", String.valueOf(rechargeType)); + } + map.put("companyId" , String.valueOf(userInfoModel.getBsCompany().getId())); PageHelper.startPage(pageNum, pageSize); @@ -90,6 +95,7 @@ public class OutRechargePriceController { || outRechargePrice.getPrice() == null || outRechargePrice.getRealPrice() == null || outRechargePrice.getShowType() == null + || outRechargePrice.getRechargeType() == null || outRechargePrice.getSort() == null ) { log.error("SecOrganizationController -> insertPrice() error!"); @@ -120,6 +126,7 @@ public class OutRechargePriceController { || outRechargePrice.getId() == null || outRechargePrice.getPrice() == null || outRechargePrice.getRealPrice() == null + || outRechargePrice.getRechargeType() == null || outRechargePrice.getShowType() == null || outRechargePrice.getSort() == null ) { diff --git a/hai-bweb/src/main/java/com/bweb/excelListener/ImportRechargeOrderListener.java b/hai-bweb/src/main/java/com/bweb/excelListener/ImportRechargeOrderListener.java new file mode 100644 index 00000000..14a478e9 --- /dev/null +++ b/hai-bweb/src/main/java/com/bweb/excelListener/ImportRechargeOrderListener.java @@ -0,0 +1,85 @@ +package com.bweb.excelListener; + +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.event.AnalysisEventListener; +import com.bweb.model.ExportOutRechargeOrder; +import com.bweb.model.ImportCouponModel; +import com.hai.common.utils.DateUtil; +import com.hai.entity.OutRechargeOrder; +import com.hai.service.OutRechargeOrderService; +import org.apache.commons.lang3.StringUtils; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Objects; + +public class ImportRechargeOrderListener extends AnalysisEventListener { + + List errorData = new ArrayList<>(); + List successData = new ArrayList<>(); + + private OutRechargeOrderService outRechargeOrderService; + + /** + * @Author Sum1Dream + * @name invoke.java + * @Description // 解析到的每一条数据都会调用此方法 + * @Date 4:03 下午 2022/1/24 + * @Param [com.bweb.model.ExportOutRechargeOrder, com.alibaba.excel.context.AnalysisContext] + * @return void + */ + @Override + public void invoke(ExportOutRechargeOrder data, AnalysisContext context) { + if (StringUtils.isBlank(data.getOrderNo()) + || StringUtils.isBlank(data.getStatusName()) ) { + data.setErrorMessage("有必填项未填写"); + errorData.add(data); + return; + } + + OutRechargeOrder rechargeOrder = outRechargeOrderService.findByOrderNo(data.getOrderNo()); + + if (rechargeOrder.getStatus() != 2) { + data.setErrorMessage("当前订单状态错误。"); + errorData.add(data); + return; + } + + if (rechargeOrder.getRechargeType() != 2) { + data.setErrorMessage("当前话费订单充值类型为快充。"); + errorData.add(data); + return; + } + + if (Objects.equals(data.getStatusName(), "已完成")) { + rechargeOrder.setStatus(3); + rechargeOrder.setFinishTime(new Date()); + } else if (Objects.equals(data.getStatusName(), "失败")){ + rechargeOrder.setStatus(6); + } + + + successData.add(rechargeOrder); + } + + @Override + public void doAfterAllAnalysed(AnalysisContext context) { + if (successData.size() > 0) { + try { + outRechargeOrderService.updateOrderList(successData); + } catch (Exception e) { + e.printStackTrace(); + } + } + this.successData.clear(); + } + + public List getErrorData() { + return errorData; + } + + public void initData(OutRechargeOrderService outRechargeOrderService) { + this.outRechargeOrderService = outRechargeOrderService; + } +} diff --git a/hai-bweb/src/main/java/com/bweb/model/ExportOutRechargeOrder.java b/hai-bweb/src/main/java/com/bweb/model/ExportOutRechargeOrder.java index 039fb5be..179803a7 100644 --- a/hai-bweb/src/main/java/com/bweb/model/ExportOutRechargeOrder.java +++ b/hai-bweb/src/main/java/com/bweb/model/ExportOutRechargeOrder.java @@ -37,6 +37,9 @@ public class ExportOutRechargeOrder { @ExcelProperty("应付金额") private BigDecimal payPrice; + @ExcelProperty("充值类型") + private String rechargeTypeName; + @ExcelProperty("实付金额") private BigDecimal payRealPrice; @@ -67,6 +70,9 @@ public class ExportOutRechargeOrder { @ExcelProperty("第三方退款订单号") private String refundId; + // 错误消息 + private String errorMessage; + public String getOrderNo() { return orderNo; } @@ -226,4 +232,21 @@ public class ExportOutRechargeOrder { public void setCardNo(String cardNo) { this.cardNo = cardNo; } + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public String getRechargeTypeName() { + return rechargeTypeName; + } + + public void setRechargeTypeName(String rechargeTypeName) { + this.rechargeTypeName = rechargeTypeName; + } + } diff --git a/hai-cweb/src/main/java/com/cweb/controller/OutRechargeOrderController.java b/hai-cweb/src/main/java/com/cweb/controller/OutRechargeOrderController.java index 997b2d38..5a3c4146 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/OutRechargeOrderController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/OutRechargeOrderController.java @@ -527,57 +527,57 @@ public class OutRechargeOrderController { } - @RequestMapping(value = "/orderToRefund", method = RequestMethod.GET) - @ResponseBody - @ApiOperation(value = "订单退款") - public ResponseData orderToRefund(@RequestParam(name = "orderId", required = false) Long orderId, - HttpServletRequest request) { - try { - - OutRechargeOrder order = outRechargeOrderService.findByOrderId(orderId); - if (order == null) { - log.error("orderToPay error!", "未找到充值订单"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到充值订单"); - } - - // 订单状态 : 1.待支付 2.已支付 3.已完成 4.已取消 5.已退款 - if (order.getStatus() != 2) { - log.error("orderToPay error!", "无法退款,订单不处于已支付状态"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法退款,订单不处于已支付状态"); - } - - Map param = new HashMap<>(); - param.put("appid", "wx637bd6f7314daa46"); - param.put("mch_id", "1289663601"); - param.put("sub_mch_id" , "1609882817"); - param.put("nonce_str", WxUtils.makeNonStr()); - param.put("transaction_id", order.getPaySerialNo()); - param.put("out_refund_no", "HFR"+new Date().getTime()); - param.put("total_fee", String.valueOf(order.getPayRealPrice().multiply(new BigDecimal("100")).intValue())); - param.put("refund_fee", String.valueOf(order.getPayRealPrice().multiply(new BigDecimal("100")).intValue())); - param.put("sign_type", "HMAC-SHA256"); - - String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); - param.put("sign", signStr); - - String resultXmL = doRefundRequest(param.get("mch_id"), null, WxUtils.mapToXml(param)); - OrderRefundModel orderRefundModel = XmlUtil.getObjectFromXML(resultXmL, OrderRefundModel.class); - if(orderRefundModel.getResult_code().equals("SUCCESS")) { - order.setStatus(5); - order.setRefundTime(new Date()); - order.setOutRefundNo(orderRefundModel.getOut_refund_no()); - order.setRefundId(orderRefundModel.getRefund_id()); - order.setRefundFee(new BigDecimal(orderRefundModel.getRefund_fee()).divide(new BigDecimal("100"))); - outRechargeOrderService.updateOrder(order); - return ResponseMsgUtil.success("退款成功"); - } - return ResponseMsgUtil.success("退款失败!错误代码:"+orderRefundModel.getErr_code()+",错误描述"+orderRefundModel.getErr_code_des()); - - } catch (Exception e) { - log.error("HighOrderController --> getUserOrderList() error!", e); - return ResponseMsgUtil.exception(e); - } - } +// @RequestMapping(value = "/orderToRefund", method = RequestMethod.GET) +// @ResponseBody +// @ApiOperation(value = "订单退款") +// public ResponseData orderToRefund(@RequestParam(name = "orderId", required = false) Long orderId, +// HttpServletRequest request) { +// try { +// +// OutRechargeOrder order = outRechargeOrderService.findByOrderId(orderId); +// if (order == null) { +// log.error("orderToPay error!", "未找到充值订单"); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到充值订单"); +// } +// +// // 订单状态 : 1.待支付 2.已支付 3.已完成 4.已取消 5.已退款 +// if (order.getStatus() != 2) { +// log.error("orderToPay error!", "无法退款,订单不处于已支付状态"); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法退款,订单不处于已支付状态"); +// } +// +// Map param = new HashMap<>(); +// param.put("appid", "wx637bd6f7314daa46"); +// param.put("mch_id", "1289663601"); +// param.put("sub_mch_id" , "1609882817"); +// param.put("nonce_str", WxUtils.makeNonStr()); +// param.put("transaction_id", order.getPaySerialNo()); +// param.put("out_refund_no", "HFR"+new Date().getTime()); +// param.put("total_fee", String.valueOf(order.getPayRealPrice().multiply(new BigDecimal("100")).intValue())); +// param.put("refund_fee", String.valueOf(order.getPayRealPrice().multiply(new BigDecimal("100")).intValue())); +// param.put("sign_type", "HMAC-SHA256"); +// +// String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); +// param.put("sign", signStr); +// +// String resultXmL = doRefundRequest(param.get("mch_id"), null, WxUtils.mapToXml(param)); +// OrderRefundModel orderRefundModel = XmlUtil.getObjectFromXML(resultXmL, OrderRefundModel.class); +// if(orderRefundModel.getResult_code().equals("SUCCESS")) { +// order.setStatus(5); +// order.setRefundTime(new Date()); +// order.setOutRefundNo(orderRefundModel.getOut_refund_no()); +// order.setRefundId(orderRefundModel.getRefund_id()); +// order.setRefundFee(new BigDecimal(orderRefundModel.getRefund_fee()).divide(new BigDecimal("100"))); +// outRechargeOrderService.updateOrder(order); +// return ResponseMsgUtil.success("退款成功"); +// } +// return ResponseMsgUtil.success("退款失败!错误代码:"+orderRefundModel.getErr_code()+",错误描述"+orderRefundModel.getErr_code_des()); +// +// } catch (Exception e) { +// log.error("HighOrderController --> getUserOrderList() error!", e); +// return ResponseMsgUtil.exception(e); +// } +// } @RequestMapping(value = "/wxProfitsharing", method = RequestMethod.GET) diff --git a/hai-cweb/src/main/java/com/cweb/controller/OutRechargePriceController.java b/hai-cweb/src/main/java/com/cweb/controller/OutRechargePriceController.java index a64a7445..2894c0d0 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/OutRechargePriceController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/OutRechargePriceController.java @@ -72,11 +72,11 @@ public class OutRechargePriceController { map.put("companyId", String.valueOf(bsCompany.getId())); } - if (type != null ) { + if (showType != null ) { map.put("showType", String.valueOf(showType)); } - if (type != null ) { + if (rechargeType != null ) { map.put("rechargeType", String.valueOf(rechargeType)); } diff --git a/hai-cweb/src/main/java/com/cweb/controller/pay/CzOrderController.java b/hai-cweb/src/main/java/com/cweb/controller/pay/CzOrderController.java index 4bd0f5d8..aa70e65e 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/pay/CzOrderController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/pay/CzOrderController.java @@ -21,6 +21,7 @@ import com.hai.entity.OutRechargeOrder; import com.hai.model.OrderRefundModel; import com.hai.model.ResponseData; import com.hai.service.HighRefundAuditService; +import com.hai.service.HighUserService; import com.hai.service.OutRechargeOrderService; import com.hai.service.pay.impl.GoodsOrderServiceImpl; import io.swagger.annotations.Api; @@ -62,6 +63,9 @@ public class CzOrderController { @Resource private GoodsOrderServiceImpl goodsOrderService; + @Resource + private HighUserService highUserService; + @RequestMapping(value = "/rechargeCallback", method = RequestMethod.POST) @ApiOperation(value = "话费充值回调") @ResponseBody @@ -168,6 +172,10 @@ public class CzOrderController { } } + if (order.getPayType() == 3) { + highUserService.goldHandle(order.getUserId(), order.getPayRealPrice().intValue() * 100, 1, 3, order.getId()); + } + // 银联退款 if (order.getPayType() == 4) { // 订单退款 diff --git a/hai-service/src/main/java/com/hai/dao/OutRechargeOrderMapperExt.java b/hai-service/src/main/java/com/hai/dao/OutRechargeOrderMapperExt.java index f28e72aa..83357fd4 100644 --- a/hai-service/src/main/java/com/hai/dao/OutRechargeOrderMapperExt.java +++ b/hai-service/src/main/java/com/hai/dao/OutRechargeOrderMapperExt.java @@ -68,6 +68,7 @@ public interface OutRechargeOrderMapperExt { " a.user_name userName," + " a.user_phone userPhone," + " case a.recharge_model when 1 then '电信话费' when 2 then '移动话费' when 3 then '联通话费' end rechargeModelName," + + " case a.recharge_type when 1 then '快充' when 2 then '慢充' end getRechargeTypeName," + " a.recharge_content rechargeContent," + " a.remarks remarks," + " a.id_card cardNo," + @@ -91,6 +92,7 @@ public interface OutRechargeOrderMapperExt { " and a.`pay_type` = #{map.payType} ", " and a.`Identification_code` = #{map.code} ", " and a.`order_no` = #{map.orderNo} ", + " and a.`recharge_type` = #{map.rechargeType} ", " and a.`recharge_model` = #{map.rechargeModel} ", " and a.`recharge_content` LIKE '%${map.rechargeContent}%' ", " and a.`id_card` LIKE '%${map.idCard}%' ", diff --git a/hai-service/src/main/java/com/hai/model/OutRechargeOrderModel.java b/hai-service/src/main/java/com/hai/model/OutRechargeOrderModel.java index 5d80f508..35f1ccbf 100644 --- a/hai-service/src/main/java/com/hai/model/OutRechargeOrderModel.java +++ b/hai-service/src/main/java/com/hai/model/OutRechargeOrderModel.java @@ -28,6 +28,7 @@ public class OutRechargeOrderModel extends OutRechargeOrder { private String outRefundNo; private String refundId; private String cardNo; + private String rechargeTypeName; public String getOrderNo() { return orderNo; @@ -196,4 +197,12 @@ public class OutRechargeOrderModel extends OutRechargeOrder { public void setCardNo(String cardNo) { this.cardNo = cardNo; } + + public String getRechargeTypeName() { + return rechargeTypeName; + } + + public void setRechargeTypeName(String rechargeTypeName) { + this.rechargeTypeName = rechargeTypeName; + } } diff --git a/hai-service/src/main/java/com/hai/service/OutRechargeOrderService.java b/hai-service/src/main/java/com/hai/service/OutRechargeOrderService.java index cffb6cb0..b2eb6d10 100644 --- a/hai-service/src/main/java/com/hai/service/OutRechargeOrderService.java +++ b/hai-service/src/main/java/com/hai/service/OutRechargeOrderService.java @@ -58,6 +58,8 @@ public interface OutRechargeOrderService { **/ void updateOrder(OutRechargeOrder outRechargeOrder); + void updateOrderList(List rechargeOrders) throws Exception; + /** * @Author Sum1Dream * @Description //取消订单 Administrator @@ -146,12 +148,21 @@ public interface OutRechargeOrderService { /** * @Author Sum1Dream * @name getMobile.java - * @Description // 请求话费 + * @Description // 请求话费充值 * @Date 5:02 下午 2022/1/17 * @Param [java.lang.String] * @return com.alibaba.fastjson.JSONObject */ JSONObject getMobile(String phone , Integer amount , String orderNo) throws Exception; + /** + * @Author Sum1Dream + * @name orderToRefund.java + * @Description // 话费订单退款 + * @Date 4:44 下午 2022/1/24 + * @Param [java.lang.Long] + * @return void + */ + void rechargeOrderToRefund(Long orderId) throws Exception; } diff --git a/hai-service/src/main/java/com/hai/service/impl/OutRechargeOrderServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/OutRechargeOrderServiceImpl.java index 6e8bb7c5..3a61b9e0 100644 --- a/hai-service/src/main/java/com/hai/service/impl/OutRechargeOrderServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/OutRechargeOrderServiceImpl.java @@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; +import com.hai.common.pay.util.XmlUtil; import com.hai.common.pay.util.sdk.WXPayConstants; import com.hai.common.utils.DateUtil; import com.hai.common.utils.HttpsUtils; @@ -13,21 +14,26 @@ import com.hai.common.utils.WxUtils; import com.hai.config.CommonSysConfig; import com.hai.config.CommonSysConst; import com.hai.config.HuiLianTongUnionCardConfig; +import com.hai.config.UnionPayConfig; import com.hai.dao.HighGasOrderPushMapper; import com.hai.dao.OutRechargeOrderMapper; import com.hai.dao.OutRechargeOrderMapperExt; import com.hai.entity.*; import com.hai.enum_type.OrderPushType; -import com.hai.model.OrderCountModel; -import com.hai.model.OutOrderModel; -import com.hai.model.OutRechargeOrderModel; -import com.hai.model.OutUserOrderModel; +import com.hai.model.*; import com.hai.service.HighUserCardService; import com.hai.service.HighUserService; import com.hai.service.OutRechargeOrderService; +import com.hai.service.pay.impl.GoodsOrderServiceImpl; import io.swagger.models.auth.In; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.util.EntityUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; @@ -59,6 +65,9 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { @Resource private OutRechargeOrderService outRechargeOrderService; + @Resource + private GoodsOrderServiceImpl goodsOrderService; + @Override public List getListRechargeOrder(Map map) { OutRechargeOrderExample example = new OutRechargeOrderExample(); @@ -94,6 +103,9 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { if (MapUtils.getString(map, "rechargeContent") != null) { criteria.andRechargeContentLike("%" + MapUtils.getString(map, "rechargeContent") + "%"); } + if (MapUtils.getString(map, "rechargeType") != null) { + criteria.andRechargeTypeEqualTo(MapUtils.getInteger(map, "rechargeType")); + } if (MapUtils.getString(map, "phone") != null) { criteria.andUserPhoneEqualTo(MapUtils.getString(map, "phone")); @@ -142,6 +154,19 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { outRechargeOrderMapper.updateByPrimaryKey(outRechargeOrder); } + @Override + @Transactional(propagation= Propagation.REQUIRES_NEW) + public void updateOrderList(List rechargeOrders) throws Exception { + for (OutRechargeOrder list:rechargeOrders) { + if (list.getStatus() == 3) { + outRechargeOrderMapper.updateByPrimaryKey(list); + } else if (list.getStatus() == 6) { + rechargeOrderToRefund(list.getId()); + } + + } + } + @Override @Transactional(propagation= Propagation.REQUIRES_NEW) public void cancelOrder(Long orderId) { @@ -383,4 +408,118 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { return HttpsUtils.doPost(CommonSysConst.getSysConfig().getCzUrl() , map); } + + @Override + public void rechargeOrderToRefund(Long orderId) throws Exception { + OutRechargeOrder order = outRechargeOrderService.findByOrderId(orderId); + + + // 订单状态 : 1.待支付 2.已支付 3.已完成 4.已取消 5.已退款 6:退款中 + if (order.getStatus() != 2) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法退款,订单不处于已支付状态"); + } + + // 微信退款 + if (order.getPayType() == 1) { + Map param = new HashMap<>(); + param.put("appid", "wx637bd6f7314daa46"); + param.put("mch_id", "1289663601"); + param.put("sub_mch_id" , "1614670195"); + param.put("nonce_str", WxUtils.makeNonStr()); + param.put("transaction_id", order.getPaySerialNo()); + param.put("out_refund_no", "HFR"+new Date().getTime()); + param.put("total_fee", String.valueOf(order.getPayRealPrice().multiply(new BigDecimal("100")).intValue())); + param.put("refund_fee", String.valueOf(order.getPayRealPrice().multiply(new BigDecimal("100")).intValue())); + param.put("sign_type", "HMAC-SHA256"); + + String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); + param.put("sign", signStr); + + String resultXmL = doRefundRequest(param.get("mch_id"), WxUtils.mapToXml(param)); + OrderRefundModel orderRefundModel = XmlUtil.getObjectFromXML(resultXmL, OrderRefundModel.class); + if(orderRefundModel.getResult_code().equals("SUCCESS")) { + order.setStatus(5); + order.setRefundTime(new Date()); + order.setOutRefundNo(orderRefundModel.getOut_refund_no()); + order.setRefundId(orderRefundModel.getRefund_id()); + order.setRefundFee(new BigDecimal(orderRefundModel.getRefund_fee()).divide(new BigDecimal("100"))); + outRechargeOrderService.updateOrder(order); + } else { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "退款失败!错误代码:"+orderRefundModel.getErr_code()+",错误描述"+orderRefundModel.getErr_code_des()); + } + } + + // 工会卡退款 + if (order.getPayType() == 2) { + JSONObject jsonObject = HuiLianTongUnionCardConfig.refund( "HFR"+new Date().getTime() , order.getOrderNo()); + + if (jsonObject == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请求超时,请重新点击"); + } + + JSONObject dataObject = HuiLianTongUnionCardConfig.resolveResponse(jsonObject.getString("data")); + + if (dataObject.getBoolean("success") || Objects.equals(dataObject.getString("message"), "原交易已撤销,不可再次操作")) { + order.setStatus(5); + order.setRefundTime(new Date()); + order.setOutRefundNo("HFR"+new Date().getTime() ); + order.setRefundFee(order.getPayRealPrice()); + order.setRefundId(dataObject.getString("orderId")); + outRechargeOrderService.updateOrder(order); + + } else { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, dataObject.getString("message")); + } + } + + // 金币退款 + if (order.getPayType() == 3) { + highUserService.goldHandle(order.getUserId(), order.getPayRealPrice().intValue() * 100, 1, 3, order.getId()); + } + + // 银联退款 + if (order.getPayType() == 4) { + // 订单退款 + JSONObject refund = UnionPayConfig.zwrefund(order.getOrderNo(), order.getPaySerialNo(), order.getPayRealPrice().multiply(new BigDecimal("100")).longValue()); + if (!refund.getString("resultcode").equals("W6")) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, refund.getString("returnmsg")); + } + + order.setStatus(5); + order.setRefundTime(new Date()); + order.setOutRefundNo(refund.getString("oriwtorderid")); + order.setRefundFee(order.getPayRealPrice()); + outRechargeOrderService.updateOrder(order); + } + } + + public String doRefundRequest(String mchId,String data) throws Exception { + + //小程序退款需要调用双向证书的认证 + CloseableHttpClient httpClient = goodsOrderService.readCertificate(mchId); + try { + HttpPost httpost = new HttpPost("https://api.mch.weixin.qq.com/secapi/pay/refund"); // 设置响应头信息 + httpost.addHeader("Connection", "keep-alive"); + httpost.addHeader("Accept", "*/*"); + httpost.addHeader("Content-Type", "text/xml"); + 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(data, "UTF-8")); + CloseableHttpResponse response = httpClient.execute(httpost); + try { + HttpEntity entity = response.getEntity(); + String jsonStr = EntityUtils.toString(response.getEntity(), "UTF-8"); + EntityUtils.consume(entity); + return jsonStr; + } finally { + response.close(); + } + } catch (Exception e){ + throw new RuntimeException(e); + } finally { + httpClient.close(); + } + } } diff --git a/hai-service/src/main/java/com/hai/service/impl/OutRechargePriceServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/OutRechargePriceServiceImpl.java index b2f6bc7f..d9953add 100644 --- a/hai-service/src/main/java/com/hai/service/impl/OutRechargePriceServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/OutRechargePriceServiceImpl.java @@ -32,6 +32,9 @@ public class OutRechargePriceServiceImpl implements OutRechargePriceService { if (StringUtils.isNotBlank(map.get("companyId"))) { criteria.andCompanyIdEqualTo(Long.valueOf(map.get("companyId"))); } + if (StringUtils.isNotBlank(map.get("rechargeType"))) { + criteria.andRechargeTypeEqualTo(Integer.valueOf(map.get("rechargeType"))); + } example.setOrderByClause("type asc"); return outRechargePriceMapper.selectByExample(example); diff --git a/hai-service/src/main/resources/prod/commonConfig.properties b/hai-service/src/main/resources/prod/commonConfig.properties index 08c687a0..1b1e4654 100644 --- a/hai-service/src/main/resources/prod/commonConfig.properties +++ b/hai-service/src/main/resources/prod/commonConfig.properties @@ -46,4 +46,5 @@ TelMemberId=d13091df65d64aafbf0f35d2093157b7 // Mobile CzNotifyUrl = https://hsg.dctpay.com/crest/czOrder/orderRefundNotify CzAppKey = p429mlj3cvn5hb07 -CzUrl = https://hfcs.dmjvip.com/index.php/third/mobile/createOrder \ No newline at end of file +CzUrl = https://jj.dmjvip.com/index.php/third/mobile/createOrder +CzAppSecret = bf57pnqy8mkexr0v169c3g4odazwu2ij