diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighRefundAuditController.java b/hai-bweb/src/main/java/com/bweb/controller/HighRefundAuditController.java index 82476f1a..5cc17b67 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighRefundAuditController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighRefundAuditController.java @@ -156,7 +156,7 @@ public class HighRefundAuditController { if (highRefundAudit.getRefundSource() == 1) { OutRechargeOrder outRechargeOrder = outRechargeOrderService.findByOrderNo(highRefundAudit.getSourceOrderNo()); - outRechargeOrder.setStatus(2); +// outRechargeOrder.setStatus(2); outRechargeOrderService.updateOrder(outRechargeOrder); } else { HighOrder highOrder = highOrderService.getOrderByOrderNo(highRefundAudit.getSourceOrderNo()); diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighTestController.java b/hai-bweb/src/main/java/com/bweb/controller/HighTestController.java index 6fb5e6c7..ae094b59 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighTestController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighTestController.java @@ -1 +1 @@ -package com.bweb.controller; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.bweb.config.SysConst; 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; import com.hai.common.utils.ResponseMsgUtil; import com.hai.common.utils.WxUtils; import com.hai.config.*; import com.hai.dao.HighGasOrderPushMapper; import com.hai.entity.*; import com.hai.model.*; import com.hai.service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; 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.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; import javax.net.ssl.SSLContext; import javax.servlet.http.HttpServletRequest; import java.io.*; import java.math.BigDecimal; import java.security.KeyStore; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.*; /** * @Auther: 胡锐 * @Description: * @Date: 2021/3/26 23:08 */ @Controller @RequestMapping(value = "/test") @Api(value = "订单接口") public class HighTestController { private static Logger log = LoggerFactory.getLogger(HighTestController.class); @Resource private HltUnionCardVipService hltUnionCardVipService; @Resource private HighTestService highTestService; @Resource private OutRechargeOrderService outRechargeOrderService; @Resource private HighOrderService highOrderService; @Resource private HighUserService highUserService; @Resource private SecSinopecConfigService secSinopecConfigService; @Resource private HighCouponCodeService highCouponCodeService; @RequestMapping(value = "/getBackendToken", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "获取访问令牌backendToken") public ResponseData getBackendToken() { try { return ResponseMsgUtil.success(null); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/sys", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "同步") public ResponseData sys(@RequestParam(name = "appId", required = true) String appId, @RequestParam(name = "appSecret", required = true) String appSecret, @RequestParam(name = "code", required = true) String code, @RequestParam(name = "signKey", required = true) String signKey ) { try { Map tokenMap = new HashMap<>(); tokenMap.put("appId", appId); tokenMap.put("appSecret", appSecret); JSONObject jsonObject = HttpsUtils.doPost("https://app.zshcqsy.com/api-provider/api/open/merchant/token", JSON.toJSONString(tokenMap)); log.error(jsonObject.toJSONString()); if (jsonObject != null && jsonObject.getBoolean("success") == true) { JSONObject data = jsonObject.getJSONObject("data"); String token = data.getString("token"); Calendar instance = Calendar.getInstance(); instance.set(2021,3,1); Map bodyMap = new HashMap<>(); bodyMap.put("appId", appId); bodyMap.put("pageNo", 1); bodyMap.put("pageSize", 999999); bodyMap.put("startTime", instance.getTime()); bodyMap.put("endTime", new Date().getTime()); bodyMap.put("customerCode", code); Long date = new Date().getTime(); String sha256 = encodeBySHA256(signKey + JSON.toJSONString(bodyMap) + date); JSONObject object = HttpsUtils.doPost("https://app.zshcqsy.com/api-provider/sapapi/open/coupon/customerRedeemcodeList", JSON.toJSONString(bodyMap), token, sha256, date); File file = new File("/home/data/" + System.currentTimeMillis() + ".txt"); if (!file.exists()) { file.createNewFile(); } FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(object.toJSONString()); bw.close(); //JSONObject object = JSONObject.parseObject("{\"code\":1000,\"data\":{\"pageNo\":1,\"pageSize\":100,\"rowCount\":\"2\",\"list\":[{\"nodeName\":\"中国石油化工股份有限公司重庆江南石油分公司大学城南二路加油加\",\"totalAmount\":150.00,\"codeId\":\"01DIhbtPzIghPP0mPWaWzO13\",\"nodeNo\":\"50000105\",\"name\":\"重庆惠昕石化有限责任公司11.02日150元券\",\"useTime\":\"2021-04-03 06:11:14\"},{\"nodeName\":\"中国石化销售有限公司重庆三峡分公司忠县经营部三台加油站\",\"totalAmount\":100.00,\"codeId\":\"201126141728001027\",\"nodeNo\":\"50000238\",\"name\":\"重庆惠昕石化有限责任公司11.26日100元券\",\"useTime\":\"2021-04-03 15:16:03\"}]},\"success\":true}"); if(Objects.equals(object.get("success"), true)) { log.error(JSONObject.toJSONString(object.get("data"))); Object dataJson = JSONObject.parse(JSONObject.toJSONString(object.get("data"))); JSONObject dataObject = JSON.parseObject(JSONObject.toJSONString(dataJson)); JSONArray list = dataObject.getJSONArray("list"); for (Object dataJsonObject : list) { try { JSONObject parseObject = JSON.parseObject(JSON.toJSONString(dataJsonObject)); String codeId = parseObject.getString("codeId"); String nodeName = parseObject.getString("nodeName"); Date useTime = DateUtil.format(parseObject.getString("useTime"), "yyyy-MM-dd HH:mm:ss"); highCouponCodeService.cnpcCallbackCouponCode(codeId, useTime, nodeName); } catch (Exception e) { log.error("HighCouponSchedule --> expiredCoupon() error!", e); } } } return ResponseMsgUtil.success("下载成功"); } return ResponseMsgUtil.success(jsonObject); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } public String encodeBySHA256(String str) { try{ MessageDigest messageDigest = MessageDigest.getInstance("SHA-256"); messageDigest.reset(); messageDigest.update(str.getBytes("UTF-8")); return getFormattedText(messageDigest.digest()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (Exception e) { throw new RuntimeException(e); } return ""; } private static final String[] HEX_DIGITS = {"0" ,"1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"}; private String getFormattedText(byte[] bytes) { int len = bytes.length; StringBuilder buf = new StringBuilder(len * 2); // 把密文转换成十六进制的字符串形式 for (int j=0;j> 4) & 0x0f]); buf.append(HEX_DIGITS[bytes[j] & 0x0f]); } return buf.toString(); } @RequestMapping(value = "/GetMembershipLevel", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "请求会员体系") public ResponseData GetMembershipLevel(@RequestParam(name = "phone", required = true) String phone , @RequestParam(name = "regionId", required = true) String regionId ) { try { return ResponseMsgUtil.success(hltUnionCardVipService.GetMembershipLevel(phone , regionId)); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/submitSms", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "请求短信") public ResponseData submitSms(@RequestParam(name = "phone", required = true) String phone , @RequestParam(name = "sms", required = true) String sms ) { try { return ResponseMsgUtil.success(HuiLianTongUnionCardConfig.submitSms(phone , sms)); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value="/resolveResponse",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "解析") public ResponseData resolveResponse( @RequestParam(name = "data", required = false) String data ) { try { JSONObject cardInfoObject = HuiLianTongUnionCardConfig.resolveResponse(data); return ResponseMsgUtil.success(cardInfoObject); } catch (Exception e) { log.error("getUserByTelephone",e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value="/getReadFile",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "存入用户信息") public ResponseData getReadFile() { try { highTestService.getReadFile(); return ResponseMsgUtil.success(null); } catch (Exception e) { log.error("getUserByTelephone",e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value="/queryAmount",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询余额") public ResponseData queryAmount() { try { // outRechargeOrderService.queryAmount(); return ResponseMsgUtil.success(null); } catch (Exception e) { log.error("getUserByTelephone",e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/getHuiLianTongCardConsume", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询汇联通工会卡消费记录") public ResponseData getHuiLianTongCardConsume(@RequestParam(name = "businessType", required = true) String businessType, @RequestParam(name = "cardNo", required = true) String cardNo, @RequestParam(name = "sdate", required = true) Long sdate, @RequestParam(name = "edate", required = true) Long edate, @RequestParam(name = "pageNum", required = true) Integer pageNum, @RequestParam(name = "pageSize", required = true) Integer pageSize, HttpServletRequest request) { try { JSONObject consumptionRecord = HuiLianTongUnionCardConfig.queryConsumptionRecordByBusiness(businessType, cardNo, sdate, edate, pageNum, pageSize); if (StringUtils.isBlank(consumptionRecord.getString("data"))) { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQUEST_ERROR, ""); } return ResponseMsgUtil.success(HuiLianTongUnionCardConfig.resolveResponse(consumptionRecord.getString("data"))); } catch (Exception e) { log.error("HighUserCardController --> getHuiLianTongCardConsume() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/orderToRefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "积分充值退款") public ResponseData orderToRefund(@RequestParam(name = "orderId", required = true) Long orderId ,HttpServletRequest request) { try { HighOrder highOrder = highOrderService.getOrderById(orderId); // 微信退款 OrderRefundModel orderRefundModel = WxOrderConfig.orderToRefund(highOrder.getPaySerialNo(), highOrder.getPayRealPrice(), highOrder.getPayRealPrice()); if(orderRefundModel.getResult_code().equals("SUCCESS")) { for (HighChildOrder childOrder : highOrder.getHighChildOrderList()) { childOrder.setChildOrdeStatus(4); } highOrder.setOrderStatus(4); highOrder.setRefundTime(new Date()); highOrder.setRefundPrice(highOrder.getPayRealPrice()); highOrderService.updateOrder(highOrder); } if (highUserService.findGoldRepeat(3 , highOrder.getId())) { highUserService.goldHandle(highOrder.getMemId(), highOrder.getPayRealPrice().multiply(BigDecimal.valueOf(100)).intValue(), 2, 3, highOrder.getId()); }else { log.error("orderToPay error!", "已有退款记录"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "已有退款记录"); } return ResponseMsgUtil.success(orderRefundModel); } catch (Exception e) { log.error("HighOrderController --> orderToRefund() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/orderToRefundByHlt", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "汇联通充值退款") public ResponseData orderToRefundByHlt(@RequestParam(name = "orderId", required = true) Long orderId ,HttpServletRequest request) { try { HighOrder highOrder = highOrderService.getOrderById(orderId); // 微信退款 OrderRefundModel orderRefundModel = WxOrderConfig.orderToRefund(highOrder.getPaySerialNo(), highOrder.getPayRealPrice(), WxOrderConfig.MCH_ID_1619676214 , highOrder.getPayRealPrice()); if(orderRefundModel.getResult_code().equals("SUCCESS")) { for (HighChildOrder childOrder : highOrder.getHighChildOrderList()) { childOrder.setChildOrdeStatus(4); } highOrder.setOrderStatus(4); highOrder.setRefundTime(new Date()); highOrder.setRefundPrice(highOrder.getPayRealPrice()); highOrderService.updateOrder(highOrder); } return ResponseMsgUtil.success(orderRefundModel); } catch (Exception e) { log.error("HighOrderController --> orderToRefund() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/zwrefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "银联退款") public ResponseData zwrefund( @RequestParam(name = "orderId", required = true) Long orderId , @RequestParam(name = "MER_ID", required = true) String MER_ID , @RequestParam(name = "TERM_ID", required = true) String TERM_ID , HttpServletRequest request) { try { OutRechargeOrder order = outRechargeOrderService.findByOrderId(orderId); // 订单退款 JSONObject refund = UnionPayConfig.zwrefund(MER_ID, TERM_ID, 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); return ResponseMsgUtil.success(refund); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/rechargeOrderToRefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "话费退款") public ResponseData rechargeOrderToRefund( @RequestParam(name = "orderId", required = true) Long orderId) { try { outRechargeOrderService.rechargeOrderToRefund(orderId); return ResponseMsgUtil.success("退款成功"); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/findByLatAndLng", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "获取定位信息") public ResponseData findByLatAndLng( @RequestParam(name = "lng", required = true) String lng, @RequestParam(name = "lat", required = true) String lat ) { try { return ResponseMsgUtil.success(highTestService.findByLatAndLng(lng , lat)); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } } \ No newline at end of file +package com.bweb.controller; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.bweb.config.SysConst; 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; import com.hai.common.utils.ResponseMsgUtil; import com.hai.common.utils.WxUtils; import com.hai.config.*; import com.hai.dao.HighGasOrderPushMapper; import com.hai.entity.*; import com.hai.model.*; import com.hai.service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; 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.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; import javax.net.ssl.SSLContext; import javax.servlet.http.HttpServletRequest; import java.io.*; import java.math.BigDecimal; import java.security.KeyStore; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.*; /** * @Auther: 胡锐 * @Description: * @Date: 2021/3/26 23:08 */ @Controller @RequestMapping(value = "/test") @Api(value = "订单接口") public class HighTestController { private static Logger log = LoggerFactory.getLogger(HighTestController.class); @Resource private HltUnionCardVipService hltUnionCardVipService; @Resource private HighTestService highTestService; @Resource private OutRechargeOrderService outRechargeOrderService; @Resource private HighOrderService highOrderService; @Resource private HighUserService highUserService; @Resource private SecSinopecConfigService secSinopecConfigService; @Resource private HighCouponCodeService highCouponCodeService; @RequestMapping(value = "/getBackendToken", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "获取访问令牌backendToken") public ResponseData getBackendToken() { try { return ResponseMsgUtil.success(null); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/sys", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "同步") public ResponseData sys(@RequestParam(name = "appId", required = true) String appId, @RequestParam(name = "appSecret", required = true) String appSecret, @RequestParam(name = "code", required = true) String code, @RequestParam(name = "signKey", required = true) String signKey ) { try { Map tokenMap = new HashMap<>(); tokenMap.put("appId", appId); tokenMap.put("appSecret", appSecret); JSONObject jsonObject = HttpsUtils.doPost("https://app.zshcqsy.com/api-provider/api/open/merchant/token", JSON.toJSONString(tokenMap)); log.error(jsonObject.toJSONString()); if (jsonObject != null && jsonObject.getBoolean("success") == true) { JSONObject data = jsonObject.getJSONObject("data"); String token = data.getString("token"); Calendar instance = Calendar.getInstance(); instance.set(2021,3,1); Map bodyMap = new HashMap<>(); bodyMap.put("appId", appId); bodyMap.put("pageNo", 1); bodyMap.put("pageSize", 999999); bodyMap.put("startTime", instance.getTime()); bodyMap.put("endTime", new Date().getTime()); bodyMap.put("customerCode", code); Long date = new Date().getTime(); String sha256 = encodeBySHA256(signKey + JSON.toJSONString(bodyMap) + date); JSONObject object = HttpsUtils.doPost("https://app.zshcqsy.com/api-provider/sapapi/open/coupon/customerRedeemcodeList", JSON.toJSONString(bodyMap), token, sha256, date); File file = new File("/home/data/" + System.currentTimeMillis() + ".txt"); if (!file.exists()) { file.createNewFile(); } FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(object.toJSONString()); bw.close(); //JSONObject object = JSONObject.parseObject("{\"code\":1000,\"data\":{\"pageNo\":1,\"pageSize\":100,\"rowCount\":\"2\",\"list\":[{\"nodeName\":\"中国石油化工股份有限公司重庆江南石油分公司大学城南二路加油加\",\"totalAmount\":150.00,\"codeId\":\"01DIhbtPzIghPP0mPWaWzO13\",\"nodeNo\":\"50000105\",\"name\":\"重庆惠昕石化有限责任公司11.02日150元券\",\"useTime\":\"2021-04-03 06:11:14\"},{\"nodeName\":\"中国石化销售有限公司重庆三峡分公司忠县经营部三台加油站\",\"totalAmount\":100.00,\"codeId\":\"201126141728001027\",\"nodeNo\":\"50000238\",\"name\":\"重庆惠昕石化有限责任公司11.26日100元券\",\"useTime\":\"2021-04-03 15:16:03\"}]},\"success\":true}"); if(Objects.equals(object.get("success"), true)) { log.error(JSONObject.toJSONString(object.get("data"))); Object dataJson = JSONObject.parse(JSONObject.toJSONString(object.get("data"))); JSONObject dataObject = JSON.parseObject(JSONObject.toJSONString(dataJson)); JSONArray list = dataObject.getJSONArray("list"); for (Object dataJsonObject : list) { try { JSONObject parseObject = JSON.parseObject(JSON.toJSONString(dataJsonObject)); String codeId = parseObject.getString("codeId"); String nodeName = parseObject.getString("nodeName"); Date useTime = DateUtil.format(parseObject.getString("useTime"), "yyyy-MM-dd HH:mm:ss"); highCouponCodeService.cnpcCallbackCouponCode(codeId, useTime, nodeName); } catch (Exception e) { log.error("HighCouponSchedule --> expiredCoupon() error!", e); } } } return ResponseMsgUtil.success("下载成功"); } return ResponseMsgUtil.success(jsonObject); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } public String encodeBySHA256(String str) { try{ MessageDigest messageDigest = MessageDigest.getInstance("SHA-256"); messageDigest.reset(); messageDigest.update(str.getBytes("UTF-8")); return getFormattedText(messageDigest.digest()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (Exception e) { throw new RuntimeException(e); } return ""; } private static final String[] HEX_DIGITS = {"0" ,"1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"}; private String getFormattedText(byte[] bytes) { int len = bytes.length; StringBuilder buf = new StringBuilder(len * 2); // 把密文转换成十六进制的字符串形式 for (int j=0;j> 4) & 0x0f]); buf.append(HEX_DIGITS[bytes[j] & 0x0f]); } return buf.toString(); } @RequestMapping(value = "/GetMembershipLevel", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "请求会员体系") public ResponseData GetMembershipLevel(@RequestParam(name = "phone", required = true) String phone , @RequestParam(name = "regionId", required = true) String regionId ) { try { return ResponseMsgUtil.success(hltUnionCardVipService.GetMembershipLevel(phone , regionId)); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/submitSms", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "请求短信") public ResponseData submitSms(@RequestParam(name = "phone", required = true) String phone , @RequestParam(name = "sms", required = true) String sms ) { try { return ResponseMsgUtil.success(HuiLianTongUnionCardConfig.submitSms(phone , sms)); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value="/resolveResponse",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "解析") public ResponseData resolveResponse( @RequestParam(name = "data", required = false) String data ) { try { JSONObject cardInfoObject = HuiLianTongUnionCardConfig.resolveResponse(data); return ResponseMsgUtil.success(cardInfoObject); } catch (Exception e) { log.error("getUserByTelephone",e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value="/getReadFile",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "存入用户信息") public ResponseData getReadFile() { try { highTestService.getReadFile(); return ResponseMsgUtil.success(null); } catch (Exception e) { log.error("getUserByTelephone",e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value="/queryAmount",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询余额") public ResponseData queryAmount() { try { // outRechargeOrderService.queryAmount(); return ResponseMsgUtil.success(null); } catch (Exception e) { log.error("getUserByTelephone",e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/getHuiLianTongCardConsume", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询汇联通工会卡消费记录") public ResponseData getHuiLianTongCardConsume(@RequestParam(name = "businessType", required = true) String businessType, @RequestParam(name = "cardNo", required = true) String cardNo, @RequestParam(name = "sdate", required = true) Long sdate, @RequestParam(name = "edate", required = true) Long edate, @RequestParam(name = "pageNum", required = true) Integer pageNum, @RequestParam(name = "pageSize", required = true) Integer pageSize, HttpServletRequest request) { try { JSONObject consumptionRecord = HuiLianTongUnionCardConfig.queryConsumptionRecordByBusiness(businessType, cardNo, sdate, edate, pageNum, pageSize); if (StringUtils.isBlank(consumptionRecord.getString("data"))) { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQUEST_ERROR, ""); } return ResponseMsgUtil.success(HuiLianTongUnionCardConfig.resolveResponse(consumptionRecord.getString("data"))); } catch (Exception e) { log.error("HighUserCardController --> getHuiLianTongCardConsume() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/orderToRefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "积分充值退款") public ResponseData orderToRefund(@RequestParam(name = "orderId", required = true) Long orderId ,HttpServletRequest request) { try { HighOrder highOrder = highOrderService.getOrderById(orderId); // 微信退款 OrderRefundModel orderRefundModel = WxOrderConfig.orderToRefund(highOrder.getPaySerialNo(), highOrder.getPayRealPrice(), highOrder.getPayRealPrice()); if(orderRefundModel.getResult_code().equals("SUCCESS")) { for (HighChildOrder childOrder : highOrder.getHighChildOrderList()) { childOrder.setChildOrdeStatus(4); } highOrder.setOrderStatus(4); highOrder.setRefundTime(new Date()); highOrder.setRefundPrice(highOrder.getPayRealPrice()); highOrderService.updateOrder(highOrder); } if (highUserService.findGoldRepeat(3 , highOrder.getId())) { highUserService.goldHandle(highOrder.getMemId(), highOrder.getPayRealPrice().multiply(BigDecimal.valueOf(100)).intValue(), 2, 3, highOrder.getId()); }else { log.error("orderToPay error!", "已有退款记录"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "已有退款记录"); } return ResponseMsgUtil.success(orderRefundModel); } catch (Exception e) { log.error("HighOrderController --> orderToRefund() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/orderToRefundByHlt", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "汇联通充值退款") public ResponseData orderToRefundByHlt(@RequestParam(name = "orderId", required = true) Long orderId ,HttpServletRequest request) { try { HighOrder highOrder = highOrderService.getOrderById(orderId); // 微信退款 OrderRefundModel orderRefundModel = WxOrderConfig.orderToRefund(highOrder.getPaySerialNo(), highOrder.getPayRealPrice(), WxOrderConfig.MCH_ID_1619676214 , highOrder.getPayRealPrice()); if(orderRefundModel.getResult_code().equals("SUCCESS")) { for (HighChildOrder childOrder : highOrder.getHighChildOrderList()) { childOrder.setChildOrdeStatus(4); } highOrder.setOrderStatus(4); highOrder.setRefundTime(new Date()); highOrder.setRefundPrice(highOrder.getPayRealPrice()); highOrderService.updateOrder(highOrder); } return ResponseMsgUtil.success(orderRefundModel); } catch (Exception e) { log.error("HighOrderController --> orderToRefund() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/zwrefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "银联退款") public ResponseData zwrefund( @RequestParam(name = "orderId", required = true) Long orderId , @RequestParam(name = "MER_ID", required = true) String MER_ID , @RequestParam(name = "TERM_ID", required = true) String TERM_ID , HttpServletRequest request) { try { OutRechargeOrder order = outRechargeOrderService.findByOrderId(orderId); // 订单退款 JSONObject refund = UnionPayConfig.zwrefund(MER_ID, TERM_ID, 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); return ResponseMsgUtil.success(refund); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/rechargeOrderToRefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "话费退款") public ResponseData rechargeOrderToRefund( @RequestParam(name = "orderId", required = true) Long orderId) { try { outRechargeOrderService.rechargeOrderToRefund(orderId); return ResponseMsgUtil.success("退款成功"); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/findByLatAndLng", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "获取定位信息") public ResponseData findByLatAndLng( @RequestParam(name = "lng", required = true) String lng, @RequestParam(name = "lat", required = true) String lat ) { try { return ResponseMsgUtil.success(highTestService.findByLatAndLng(lng , lat)); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } } \ No newline at end of file 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 43d3fb7f..5d57575e 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/OutRechargeOrderController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/OutRechargeOrderController.java @@ -98,12 +98,12 @@ public class OutRechargeOrderController { OutRechargeOrder outRechargeOrder = outRechargeOrderService.findByOrderId(orderId); - if (outRechargeOrder.getStatus() == 1) { - outRechargeOrderService.cancelOrder(orderId); - } else { - log.error("orderToPay error!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.STATUS_ERROR, ""); - } +// if (outRechargeOrder.getStatus() == 1) { +// outRechargeOrderService.cancelOrder(orderId); +// } else { +// log.error("orderToPay error!"); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.STATUS_ERROR, ""); +// } return ResponseMsgUtil.success("操作成功"); @@ -121,12 +121,12 @@ public class OutRechargeOrderController { OutRechargeOrder outRechargeOrder = outRechargeOrderService.findByOrderId(orderId); - if (outRechargeOrder.getStatus() == 2) { - outRechargeOrderService.finishOrder(orderId); - } else { - log.error("orderToPay error!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.STATUS_ERROR, ""); - } +// if (outRechargeOrder.getStatus() == 2) { +// outRechargeOrderService.finishOrder(orderId); +// } else { +// log.error("orderToPay error!"); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.STATUS_ERROR, ""); +// } return ResponseMsgUtil.success("操作成功"); @@ -301,10 +301,10 @@ public class OutRechargeOrderController { } // 订单状态 : 1.待支付 2.已支付 3.已完成 4.已取消 5.已退款 6:退款中 - if (order.getStatus() != 6) { - log.error("orderToPay error!", "无法退款,订单不处于退款中状态"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法退款,订单不处于已支付状态"); - } +// if (order.getStatus() != 6) { +// log.error("orderToPay error!", "无法退款,订单不处于退款中状态"); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法退款,订单不处于已支付状态"); +// } // 微信退款 if (order.getPayType() == 1) { @@ -324,19 +324,19 @@ public class OutRechargeOrderController { 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); - highRefundAudit.setStatus(1); - highRefundAuditService.updateRefundAudit(highRefundAudit); - } else { - log.error("orderToPay error!", "退款失败"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "退款失败!错误代码:"+orderRefundModel.getErr_code()+",错误描述"+orderRefundModel.getErr_code_des()); - } +// 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); +// highRefundAudit.setStatus(1); +// highRefundAuditService.updateRefundAudit(highRefundAudit); +// } else { +// log.error("orderToPay error!", "退款失败"); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "退款失败!错误代码:"+orderRefundModel.getErr_code()+",错误描述"+orderRefundModel.getErr_code_des()); +// } } // 工会卡退款 @@ -350,21 +350,21 @@ public class OutRechargeOrderController { 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")); - - highRefundAudit.setStatus(1); - highRefundAuditService.updateRefundAudit(highRefundAudit); - outRechargeOrderService.updateOrder(order); - - } else { - log.error("orderToPay error!", dataObject.getString("message")); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, dataObject.getString("message")); - } +// 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")); +// +// highRefundAudit.setStatus(1); +// highRefundAuditService.updateRefundAudit(highRefundAudit); +// outRechargeOrderService.updateOrder(order); +// +// } else { +// log.error("orderToPay error!", dataObject.getString("message")); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, dataObject.getString("message")); +// } } // 积分退款 @@ -374,7 +374,7 @@ public class OutRechargeOrderController { }else { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "已有退款记录"); } - order.setStatus(5); +// order.setStatus(5); order.setRefundTime(new Date()); order.setOutRefundNo("HFR"+new Date().getTime() ); order.setRefundFee(order.getPayRealPrice()); @@ -390,7 +390,7 @@ public class OutRechargeOrderController { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, refund.getString("returnmsg")); } - order.setStatus(5); +// order.setStatus(5); order.setRefundTime(new Date()); order.setOutRefundNo(refund.getString("oriwtorderid")); order.setRefundFee(order.getPayRealPrice()); @@ -585,31 +585,31 @@ public class OutRechargeOrderController { try { OutRechargeOrderRecord rechargeOrderRecord = rechargeOrderRecordService.findByOrderId(orderId); - if (rechargeOrderRecord == null) { - rechargeOrderRecord = new OutRechargeOrderRecord(); - // 查询订单 - OutRechargeOrder order = outRechargeOrderService.findByOrderId(orderId); - if (order.getRechargeType() == 1) { - String orderNo = "CZ" + DateUtil.date2String(new Date(),"yyyyMMddHHmmss") + IDGenerator.nextId(5); - JSONObject object = outRechargeOrderService.getMobile(order.getRechargeContent() , order.getOrderPrice().intValue() , orderNo , order.getRechargeType()); - if (object.getInteger("code") != 200) { - order.setRechargeStatus(1); - order.setAbnormalMsg(object.getString("message")); - } - outRechargeOrderService.updateOrder(order); - rechargeOrderRecord.setRechargeOrderId(order.getId()); - rechargeOrderRecord.setRechargeOrderNo(orderNo); - rechargeOrderRecord.setCreateTime(new Date()); - rechargeOrderRecord.setStatus(1); - rechargeOrderRecordService.insertOrder(rechargeOrderRecord); - } - } else { - // 查询订单 - OutRechargeOrder order = outRechargeOrderService.findByOrderId(rechargeOrderRecord.getRechargeOrderId()); - if (order.getStatus() == 2) { - outRechargeOrderService.rechargeOrderToRefund(order.getId()); - } - } +// if (rechargeOrderRecord == null) { +// rechargeOrderRecord = new OutRechargeOrderRecord(); +// // 查询订单 +// OutRechargeOrder order = outRechargeOrderService.findByOrderId(orderId); +// if (order.getRechargeType() == 1) { +// String orderNo = "CZ" + DateUtil.date2String(new Date(),"yyyyMMddHHmmss") + IDGenerator.nextId(5); +// JSONObject object = outRechargeOrderService.getMobile(order.getRechargeContent() , order.getOrderPrice().intValue() , orderNo , order.getRechargeType()); +// if (object.getInteger("code") != 200) { +// order.setRechargeStatus(1); +// order.setAbnormalMsg(object.getString("message")); +// } +// outRechargeOrderService.updateOrder(order); +// rechargeOrderRecord.setRechargeOrderId(order.getId()); +// rechargeOrderRecord.setRechargeOrderNo(orderNo); +// rechargeOrderRecord.setCreateTime(new Date()); +// rechargeOrderRecord.setStatus(1); +// rechargeOrderRecordService.insertOrder(rechargeOrderRecord); +// } +// } else { +// // 查询订单 +// OutRechargeOrder order = outRechargeOrderService.findByOrderId(rechargeOrderRecord.getRechargeOrderId()); +// if (order.getStatus() == 2) { +// outRechargeOrderService.rechargeOrderToRefund(order.getId()); +// } +// } return ResponseMsgUtil.success("操作成功"); 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 79eab735..75ac6473 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/OutRechargePriceController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/OutRechargePriceController.java @@ -1,5 +1,7 @@ package com.bweb.controller; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.hai.common.exception.ErrorCode; @@ -9,8 +11,10 @@ import com.hai.common.security.SessionObject; import com.hai.common.security.UserCenter; import com.hai.common.utils.ResponseMsgUtil; import com.hai.entity.OutRechargePrice; +import com.hai.entity.SecDictionary; import com.hai.model.ResponseData; import com.hai.model.UserInfoModel; +import com.hai.service.CommonService; import com.hai.service.OutRechargePriceService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -22,6 +26,8 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -40,13 +46,18 @@ public class OutRechargePriceController { @Resource private OutRechargePriceService outRechargePriceService; + @Resource + private CommonService commonService; + @RequestMapping(value = "/getListOutRechargePrice", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询充值金额列表") 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(value = "operatorType", required = false) Integer operatorType, + @RequestParam(value = "rechargePlatform", required = false) Integer rechargePlatform, + @RequestParam(value = "rechargeType", required = false) Integer rechargeType, + @RequestParam(value = "rechargeWay", required = false) Integer rechargeWay, + @RequestParam(value = "status", required = false) Integer status, @RequestParam(name = "pageNum", required = true) Integer pageNum, @RequestParam(name = "pageSize", required = true) Integer pageSize, HttpServletRequest request ) { @@ -55,27 +66,21 @@ public class OutRechargePriceController { SessionObject sessionObject = userCenter.getSessionObject(request); UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); - Map map = new HashMap<>(); - - if (type != null ) { - map.put("type", String.valueOf(type)); - } - - if (showType != null ) { - map.put("showType", String.valueOf(showType)); - } + Map map = new HashMap<>(); - if (rechargeType != null ) { - map.put("rechargeType", String.valueOf(rechargeType)); - } + map.put("operatorType", operatorType); + map.put("rechargePlatform", rechargePlatform); + map.put("rechargeType", rechargeType); + map.put("rechargeWay", rechargeWay); + map.put("status", status); - map.put("companyId" , String.valueOf(userInfoModel.getBsCompany().getId())); + map.put("companyId", String.valueOf(userInfoModel.getBsCompany().getId())); PageHelper.startPage(pageNum, pageSize); List outRechargePrices = outRechargePriceService.getListRechargePrice(map); - return ResponseMsgUtil.success(new PageInfo<>(outRechargePrices)); + return ResponseMsgUtil.success(new PageInfo<>(outRechargePrices)); } catch (Exception e) { log.error("OutRechargePriceController --> getListUser() error!", e); return ResponseMsgUtil.exception(e); @@ -85,29 +90,32 @@ public class OutRechargePriceController { @RequestMapping(value = "/insertPrice", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "新增金额") - public ResponseData insertAgent(@RequestBody OutRechargePrice outRechargePrice, HttpServletRequest request) { + public ResponseData insertPrice(@RequestBody JSONObject object, HttpServletRequest request) { try { SessionObject sessionObject = userCenter.getSessionObject(request); UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); - if (outRechargePrice.getType() == null - || outRechargePrice.getPrice() == null - || outRechargePrice.getRealPrice() == null - || outRechargePrice.getShowType() == null - || outRechargePrice.getRechargeType() == null - || outRechargePrice.getSort() == null + if (object == null || + object.getJSONArray("rechargePrices") == null || + object.getBigDecimal("discount") == null || + object.getString("operatorType") == null || + object.getJSONArray("rechargePlatform") == null || + object.getJSONArray("productPlatform") == null || + object.getInteger("rechargeType") == null || + object.getJSONArray("payType") == null || + object.getInteger("rechargeWay") == null || + object.getBigDecimal("integralDiscount") == null ) { - log.error("SecOrganizationController -> insertPrice() error!"); + log.error("OutRechargePriceController -> insertPrice() error!"); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } + object.put("operatorId", userInfoModel.getSecUser().getId()); + object.put("operatorName", userInfoModel.getSecUser().getLoginName()); + object.put("companyId", userInfoModel.getBsCompany().getId()); - outRechargePrice.setCompanyId(userInfoModel.getBsCompany().getId()); - outRechargePrice.setCreateTime(new Date()); - outRechargePrice.setStatus(0); - - outRechargePriceService.insertRechargePrice(outRechargePrice); + outRechargePriceService.insertRechargePrice(object); return ResponseMsgUtil.success("新增成功"); @@ -120,33 +128,60 @@ public class OutRechargePriceController { @RequestMapping(value = "/updatePrice", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "修改金额") - public ResponseData updatePrice(@RequestBody OutRechargePrice outRechargePrice) { + public ResponseData updatePrice(@RequestBody JSONObject object, HttpServletRequest request) { try { - if (outRechargePrice.getType() == null - || outRechargePrice.getId() == null - || outRechargePrice.getPrice() == null - || outRechargePrice.getRealPrice() == null - || outRechargePrice.getRechargeType() == null - || outRechargePrice.getShowType() == null - || outRechargePrice.getSort() == null + + SessionObject sessionObject = userCenter.getSessionObject(request); + UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); + + if (object == null || + object.getString("rechargePrices") == null || + object.getLong("id") == null || + object.getBigDecimal("discount") == null || + object.getString("operatorType") == null || + object.getString("rechargePlatform") == null || + object.getInteger("rechargeType") == null || + object.getString("payType") == null || + object.getString("rechargeWay") == null || + object.getString("platformType") == null || + object.getBigDecimal("integralDiscount") == null ) { - log.error("SecOrganizationController -> updatePrice() error!"); + log.error("OutRechargePriceController -> insertPrice() error!"); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } - OutRechargePrice outRechargePrice1 = outRechargePriceService.findById(outRechargePrice.getId()); + OutRechargePrice outRechargePrice = outRechargePriceService.findById(object.getLong("id")); - if (outRechargePrice1 == null ) { - log.error("SecOrganizationController -> updatePrice() error!"); + if (outRechargePrice == null) { + log.error("OutRechargePriceController -> updatePrice() error!"); throw ErrorHelp.genException(SysCode.System, ErrorCode.UPDATE_DATA_ERROR, ""); } - outRechargePrice.setCompanyId(outRechargePrice1.getCompanyId()); - outRechargePrice.setStatus(0); - outRechargePrice.setCreateTime(outRechargePrice1.getCreateTime()); + outRechargePrice.setPayPrice(outRechargePrice.getRechargePrice().multiply(object.getBigDecimal("discount").divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_UP))); + outRechargePrice.setRechargeType(object.getInteger("rechargeType")); + outRechargePrice.setOperatorType(object.getInteger("operatorType")); + outRechargePrice.setRechargePlatform(object.getString("rechargePlatform")); + outRechargePrice.setRechargeWay(object.getInteger("rechargeWay")); + outRechargePrice.setUpdateTime(new Date()); + outRechargePrice.setStatus(3); outRechargePriceService.updateRechargePrice(outRechargePrice); + JSONObject postObject = new JSONObject(); + postObject.put("payType", object.getString("payType")); + postObject.put("integralDiscount", object.getBigDecimal("integralDiscount")); + postObject.put("productPlatform", object.getString("productPlatform")); + postObject.put("operatorId", userInfoModel.getSecUser().getId()); + postObject.put("operatorName", userInfoModel.getSecUser().getLoginName()); + postObject.put("sourceId", outRechargePrice.getId()); + + // 配置支付方式 + commonService.configPayType(postObject); + // 配置积分折扣比例 + commonService.configPayType(postObject); + // 配置展示平台 + commonService.configPlatform(postObject); + return ResponseMsgUtil.success("修改成功"); } catch (Exception e) { @@ -165,7 +200,7 @@ public class OutRechargePriceController { return ResponseMsgUtil.success(outRechargePrice); } catch (Exception e) { - log.error("HighUserController --> findByUserId() error!", e); + log.error("OutRechargePriceController --> findById() error!", e); return ResponseMsgUtil.exception(e); } } @@ -176,35 +211,30 @@ public class OutRechargePriceController { public ResponseData deletePrice(@RequestParam(value = "id", required = true) Long id) { try { - outRechargePriceService.deletePrice(id); + outRechargePriceService.deletePrice(id); return ResponseMsgUtil.success("删除成功"); } catch (Exception e) { - log.error("HighUserController --> findByUserId() error!", e); + log.error("OutRechargePriceController --> deletePrice() error!", e); return ResponseMsgUtil.exception(e); } } - @RequestMapping(value = "/onAndOffShelves", method = RequestMethod.GET) + @RequestMapping(value = "/editPriceStatus", method = RequestMethod.GET) @ResponseBody - @ApiOperation(value = "上下架") - public ResponseData onAndOffShelves(@RequestParam(value = "id", required = true) Long id) { + @ApiOperation(value = "修改价格状态") + public ResponseData editPriceStatus(@RequestParam(value = "id", required = true) Long id, + @RequestParam(value = "status", required = true) Integer status) { try { OutRechargePrice outRechargePrice = outRechargePriceService.findById(id); - - if (outRechargePrice.getStatus() == 1) { - outRechargePrice.setStatus(0); - } else { - outRechargePrice.setStatus(1); - } - + outRechargePrice.setStatus(status); outRechargePriceService.updateRechargePrice(outRechargePrice); return ResponseMsgUtil.success("修改成功"); } catch (Exception e) { - log.error("HighUserController --> findByUserId() error!", e); + log.error("OutRechargePriceController --> editPriceStatus() error!", e); return ResponseMsgUtil.exception(e); } } diff --git a/hai-bweb/src/main/java/com/bweb/excelListener/ImportRechargeOrderListener.java b/hai-bweb/src/main/java/com/bweb/excelListener/ImportRechargeOrderListener.java index 643a0e7d..923ba542 100644 --- a/hai-bweb/src/main/java/com/bweb/excelListener/ImportRechargeOrderListener.java +++ b/hai-bweb/src/main/java/com/bweb/excelListener/ImportRechargeOrderListener.java @@ -40,11 +40,11 @@ public class ImportRechargeOrderListener extends AnalysisEventListener getHuiLianTongCardInfo() error!", e); return ResponseMsgUtil.exception(e); } } public void wxGasProfitsharing(String appid,String transaction_id,String out_order_no, BigDecimal amount) { try { Map param = new LinkedHashMap<>(); param.put("appid", appid); param.put("mch_id", "1289663601"); param.put("sub_mch_id" , "1624126902"); // 个体户黎杨珍 param.put("transaction_id" , transaction_id); param.put("out_order_no" , out_order_no); param.put("nonce_str" , WxUtils.makeNonStr()); // 分账金额 BigDecimal porofitSharingAmount = amount; List> receiversList = new ArrayList<>(); Map receiversMap = new LinkedHashMap<>(); receiversMap.put("type", "MERCHANT_ID"); receiversMap.put("account", "1603942866"); receiversMap.put("amount", porofitSharingAmount.multiply(new BigDecimal("100")).intValue()); receiversMap.put("description", "分给商户【惠昕石化】"); receiversList.add(receiversMap); param.put("receivers" , JSONObject.toJSONString(receiversList)); String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); param.put("sign" , signStr); String resultXmL = this.doRefundRequest(param.get("mch_id"),null, WxUtils.mapToXml(param)); // 请求分账返回的结果 ResultProfitSharing resultProfitSharing = XmlUtil.getObjectFromXML(resultXmL, ResultProfitSharing.class); HighProfitSharingRecord sharingRecord = new HighProfitSharingRecord(); sharingRecord.setOutOrderNo(out_order_no); sharingRecord.setTransactionId(transaction_id); sharingRecord.setOrderId(resultProfitSharing.getOrder_id()); sharingRecord.setStatus(resultProfitSharing.getResult_code()); sharingRecord.setPrice(amount); sharingRecord.setCreateTime(new Date()); sharingRecord.setContent(resultXmL); highProfitSharingRecordService.insert(sharingRecord); } catch (Exception e) { log.error("CmsContentController --> getCorporateAdvertising() error!", e); } } @RequestMapping(value = "/getHuiLianTongCardInfo", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询汇联通工会卡详情") public ResponseData getHuiLianTongCardInfo(@RequestParam(name = "cardNo", required = true) String cardNo, HttpServletRequest request) { try { // 用户 // JSONObject cardInfo = HuiLianTongUnionCardConfig.queryCardInfo(cardNo); if (StringUtils.isBlank(cardInfo.getString("data"))) { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQUEST_ERROR, ""); } return ResponseMsgUtil.success(HuiLianTongUnionCardConfig.resolveResponse(cardInfo.getString("data"))); } catch (Exception e) { log.error("HighUserCardController --> getHuiLianTongCardInfo() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/oilCardRefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "油卡退款") public ResponseData oilCardRefund(@RequestParam(name = "orderNo", required = true) String orderNo, HttpServletRequest request) { try { oilCardService.refund(orderNo); return ResponseMsgUtil.success(""); } catch (Exception e) { log.error("HighUserCardController --> getHuiLianTongCardInfo() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/queryGasInfoByGasId", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "根据油站 id 拉取最新的油站数据") public ResponseData queryGasInfoByGasId(@RequestParam(name = "gasId", required = true) String gasId, HttpServletRequest request) { try { return ResponseMsgUtil.success(TuanYouConfig.queryGasInfoByGasId(gasId)); } catch (Exception e) { log.error("HighUserCardController --> getHuiLianTongCardInfo() error!", e); return ResponseMsgUtil.exception(e); } } // // @RequestMapping(value = "/getMobile", method = RequestMethod.GET) // @ResponseBody // @ApiOperation(value = "话费充值") // public ResponseData getMobile( // @RequestParam(name = "orderNo", required = true) String orderNo, // @RequestParam(name = "amount", required = true) Integer amount, // @RequestParam(name = "phone", required = true) String phone, // HttpServletRequest request) { // try { // return ResponseMsgUtil.success(outRechargeOrderService.getMobile(phone,amount,orderNo)); // // } catch (Exception e) { // log.error("HighUserCardController --> getHuiLianTongCardInfo() error!", e); // return ResponseMsgUtil.exception(e); // } // } @RequestMapping(value = "/initTYMerchantStore", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "初始化加油站") public ResponseData initTYMerchantStore(@RequestParam(name = "merchantId", required = true) Long merchantId) throws Exception { HighMerchantModel merchant = highMerchantService.getMerchantById(merchantId); if (merchant == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到商户"); } JSONObject jsonObjectP = TuanYouConfig.queryGasInfoListByPage(1, 1000); JSONObject resultObjectP = jsonObjectP.getObject("result", JSONObject.class); for (int i = 1; i <= resultObjectP.getInteger("totalPageNum").intValue();i++) { JSONObject jsonObject = TuanYouConfig.queryGasInfoListByPage(i, 1000); JSONObject resultObject = jsonObject.getObject("result", JSONObject.class); JSONArray jsonArray = resultObject.getJSONArray("gasInfoList"); HighMerchantStore highMerchantStore; HighGasOilPrice highGasOilPrice; for (Object gasObject : jsonArray) { JSONObject object = JSONObject.parseObject(JSONObject.toJSONString(gasObject)); HighMerchantStoreModel store = highMerchantStoreService.getMerchantStoreByKey(object.getString("gasId")); if (store != null) { store.setType(1); store.setMerchantId(merchant.getId()); store.setCompanyId(merchant.getCompanyId()); store.setStoreKey(object.getString("gasId")); store.setStoreName(object.getString("gasName")); store.setStoreLogo(object.getString("gasLogoSmall")); store.setRegionId(object.getLong("provinceCode")); store.setRegionName(object.getString("provinceName")); store.setAddress(object.getString("gasAddress")); store.setLongitude(object.getString("gasAddressLongitude")); store.setLatitude(object.getString("gasAddressLatitude")); store.setStatus(object.getInteger("gasStatus")); store.setOperatorId(0L); store.setOperatorName("系统创建"); store.setUpdateTime(new Date()); store.setExt1(object.getString("gasSourceId")); highMerchantStoreService.updateMerchantStoreDetail(store); JSONArray oilPriceList = object.getJSONArray("oilPriceList"); for (Object oilPrice : oilPriceList) { JSONObject oilPriceObject = JSONObject.parseObject(JSONObject.toJSONString(oilPrice)); // 查询门店油号 highGasOilPrice = highGasOilPriceService.getGasOilPriceByStoreAndOilNo(store.getId(), oilPriceObject.getInteger("oilNo")); if (highGasOilPrice == null) { highGasOilPrice = new HighGasOilPrice(); highGasOilPrice.setMerchantStoreId(store.getId()); highGasOilPrice.setOilNo(oilPriceObject.getInteger("oilNo")); highGasOilPrice.setOilNoName(oilPriceObject.getString("oilNoName")); highGasOilPrice.setPriceVip(oilPriceObject.getBigDecimal("priceVip")); highGasOilPrice.setPriceGun(oilPriceObject.getBigDecimal("priceGun")); highGasOilPrice.setPriceOfficial(oilPriceObject.getBigDecimal("priceOfficial")); highGasOilPrice.setOilType(oilPriceObject.getInteger("oilType")); highGasOilPrice.setOilTypeName(oilPriceObject.getString("oilTypeName")); } else { highGasOilPrice.setMerchantStoreId(store.getId()); highGasOilPrice.setOilNo(oilPriceObject.getInteger("oilNo")); highGasOilPrice.setOilNoName(oilPriceObject.getString("oilNoName")); highGasOilPrice.setPriceVip(oilPriceObject.getBigDecimal("priceVip")); highGasOilPrice.setPriceGun(oilPriceObject.getBigDecimal("priceGun")); highGasOilPrice.setPriceOfficial(oilPriceObject.getBigDecimal("priceOfficial")); highGasOilPrice.setOilType(oilPriceObject.getInteger("oilType")); highGasOilPrice.setOilTypeName(oilPriceObject.getString("oilTypeName")); } highGasOilPriceService.editGasOilPrice(highGasOilPrice); } } else { highMerchantStore = new HighMerchantStore(); highMerchantStore.setType(1); highMerchantStore.setMerchantId(merchant.getId()); highMerchantStore.setCompanyId(merchant.getCompanyId()); highMerchantStore.setStoreKey(object.getString("gasId")); highMerchantStore.setStoreName(object.getString("gasName")); highMerchantStore.setStoreLogo(object.getString("gasLogoSmall")); highMerchantStore.setRegionId(object.getLong("provinceCode")); highMerchantStore.setRegionName(object.getString("provinceName")); highMerchantStore.setAddress(object.getString("gasAddress")); highMerchantStore.setLongitude(object.getString("gasAddressLongitude")); highMerchantStore.setLatitude(object.getString("gasAddressLatitude")); highMerchantStore.setStatus(1); highMerchantStore.setOperatorId(0L); highMerchantStore.setOperatorName("系统创建"); highMerchantStore.setCreateTime(new Date()); highMerchantStore.setUpdateTime(new Date()); highMerchantStore.setExt1(object.getString("gasSourceId")); HighMerchantStoreModel merchantStoreModel = new HighMerchantStoreModel(); BeanUtils.copyProperties(highMerchantStore, merchantStoreModel); highMerchantStoreService.insertMerchantStore(merchantStoreModel); JSONArray oilPriceList = object.getJSONArray("oilPriceList"); for (Object oilPrice : oilPriceList) { JSONObject oilPriceObject = JSONObject.parseObject(JSONObject.toJSONString(oilPrice)); highGasOilPrice = new HighGasOilPrice(); highGasOilPrice.setMerchantStoreId(merchantStoreModel.getId()); highGasOilPrice.setOilNo(oilPriceObject.getInteger("oilNo")); highGasOilPrice.setOilNoName(oilPriceObject.getString("oilNoName")); highGasOilPrice.setPriceVip(oilPriceObject.getBigDecimal("priceVip")); highGasOilPrice.setPriceGun(oilPriceObject.getBigDecimal("priceGun")); highGasOilPrice.setPriceOfficial(oilPriceObject.getBigDecimal("priceOfficial")); highGasOilPrice.setOilType(oilPriceObject.getInteger("oilType")); highGasOilPrice.setOilTypeName(oilPriceObject.getString("oilTypeName")); highGasOilPriceService.editGasOilPrice(highGasOilPrice); } } } } return ResponseMsgUtil.success("初始化完成"); } @RequestMapping(value = "/detectTYMerchantStore", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "检测加油站") public ResponseData detectTYMerchantStore(@RequestParam(name = "merchantId", required = true) Long merchantId) throws Exception { HighMerchantModel merchant = highMerchantService.getMerchantById(merchantId); if (merchant == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到商户"); } Map param = new HashMap<>(); param.put("merchantId", merchant.getId()); List stores = highMerchantStoreService.getMerchantStoreList(param); for (HighMerchantStore store : stores) { JSONObject jsonObject = TuanYouConfig.queryGasInfoByGasId(store.getStoreKey()); if (jsonObject != null && jsonObject.getString("code").equals("200")) { JSONObject result = jsonObject.getJSONObject("result"); store.setStatus(result.getInteger("gasStatus")); } else { store.setStatus(0); } highMerchantStoreService.updateMerchantStoreDetail(store); } return ResponseMsgUtil.success("初始化完成"); } @RequestMapping(value = "/pushTuanYouOrder", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "推送团油订单") public ResponseData pushTuanYouOrder(@RequestParam(name = "orderNo", required = true) String orderNo) { try { HighOrder order = highOrderService.getOrderByOrderNo(orderNo); for (HighChildOrder highChildOrder : order.getHighChildOrderList()) { HighMerchantStoreModel store = highMerchantStoreService.getMerchantStoreById(highChildOrder.getGoodsId()); // 推送团油订单 Map paramMap = new HashMap<>(); paramMap.put("gasId", store.getStoreKey()); paramMap.put("oilNo", highChildOrder.getGasOilNo()); paramMap.put("gunNo", highChildOrder.getGasGunNo()); BigDecimal priceGun = highChildOrder.getGasPriceGun(); BigDecimal priceVip = highChildOrder.getGasPriceVip(); paramMap.put("priceGun", priceGun); // 枪单价 paramMap.put("priceVip", priceVip); // 优惠价 paramMap.put("driverPhone", order.getMemPhone()); // paramMap.put("driverPhone", "17726395120"); paramMap.put("thirdSerialNo", order.getOrderNo()); paramMap.put("refuelingAmount", highChildOrder.getTotalPrice()); // 油品类型 1:汽油:2:柴油;3:天然气 if (highChildOrder.getGasOilType() == 1) { paramMap.put("accountNo", CommonSysConst.getSysConfig().getTuanYouGasolineAccount()); } else if (highChildOrder.getGasOilType() == 2) { paramMap.put("accountNo", CommonSysConst.getSysConfig().getTuanYouDieselAccount()); } JSONObject orderPushObject = TuanYouConfig.refuelingOrderPush(paramMap); // 推送团油订单记录 HighGasOrderPush highGasOrderPush = new HighGasOrderPush(); highGasOrderPush.setCreateTime(new Date()); highGasOrderPush.setCode(orderPushObject.getString("code")); highGasOrderPush.setRequestContent(JSONObject.toJSONString(paramMap)); highGasOrderPush.setReturnContent(orderPushObject.toJSONString()); highGasOrderPushMapper.insert(highGasOrderPush); if (orderPushObject != null && orderPushObject.getString("code").equals("200")) { highChildOrder.setGasOrderNo(orderPushObject.getJSONObject("result").getString("orderNo")); } highOrderService.updateOrder(order); } return ResponseMsgUtil.success(order); } catch (Exception e) { log.error("HighOrderController --> getOrderById() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/queryCompanyAccountInfo2JD", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询团油余额") public ResponseData queryCompanyAccountInfo2JD() { try { return ResponseMsgUtil.success(TuanYouConfig.queryCompanyAccountInfo2JD()); } catch (Exception e) { log.error("HighOrderController --> queryCompanyAccountInfo2JD() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/queryCompanyPriceDetail", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询团油余额") public ResponseData queryCompanyPriceDetail() { try { return ResponseMsgUtil.success(TuanYouConfig.queryCompanyPriceDetail("LW000115995", "92")); } catch (Exception e) { log.error("HighOrderController --> queryCompanyAccountInfo2JD() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/couJointDist", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "派发贵州卡券") public ResponseData couJointDist(@RequestParam(name = "token", required = true) String token) { try { return ResponseMsgUtil.success(HuiLianTongConfig.couJointDist(token,"HF2022031509263475105","20JY000575",1,"18385214742", "oArhO6QZSIJAcawo1Wwx5cKKZ0ns")); } catch (Exception e) { log.error("HighOrderController --> getOrderById() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/tradeQuery", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "派发贵州卡券") public ResponseData tradeQuery(@RequestParam(name = "token", required = true) String token) { try { return ResponseMsgUtil.success(UnionPayConfig.tradeQuery(UnionPayConfig.MER_ID3,UnionPayConfig.TERM_ID3,"HF2022031215130820400")); } catch (Exception e) { log.error("HighOrderController --> getOrderById() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/zwrefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "派发贵州卡券") public ResponseData zwrefund() { try { return ResponseMsgUtil.success(UnionPayConfig.zwrefund(UnionPayConfig.MER_ID3,UnionPayConfig.TERM_ID3,"HF2022031215130820400", "31720220312151311876232", new BigDecimal("270").multiply(new BigDecimal("100")).longValue())); } catch (Exception e) { log.error("HighOrderController --> getOrderById() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/unionPay", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "银联支付") public ResponseData unionPay(HttpServletRequest request) { try { // return ResponseMsgUtil.success(RequestUtils.getIpAddress(request)); return ResponseMsgUtil.success(unionPayConfig.upPreOrder(UnionPayConfig.MER_ID3, UnionPayConfig.TERM_ID3, "HF"+System.currentTimeMillis(), new BigDecimal("1"), "test",CommonSysConst.getSysConfig().getUnionPayNotifyUrl(), request)); } catch (Exception e) { log.error("HighOrderController --> unionPay() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/getToken", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "获取贵州中石化token") public ResponseData getToken() { try { return ResponseMsgUtil.success(huiLianTongConfig.getToken()); } catch (Exception e) { log.error("HighOrderController --> getToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/unionTradeQuery", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "银联交易查询") public ResponseData unionTradeQuery(@RequestParam(name = "paySerialNo", required = true) String paySerialNo) { try { return ResponseMsgUtil.success(UnionPayConfig.tradeQuery(UnionPayConfig.MER_ID1, UnionPayConfig.TERM_ID1, paySerialNo)); } catch (Exception e) { log.error("HighOrderController --> unionTradeQuery() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/getBackendToken", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "获取访问令牌backendToken") public ResponseData getBackendToken() { try { return ResponseMsgUtil.success(unionUserConfig.getBackendToken()); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/wxSplitAccount", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "微信分账") public ResponseData wxSplitAccount() { try { HighOrder orderNo = highOrderService.getOrderByOrderNo("HF2021101812025050304"); wxProfitsharing(orderNo.getOrderNo(),orderNo.getPaySerialNo(),orderNo.getPayRealPrice()); return ResponseMsgUtil.success("分账成功"); } catch (Exception e) { log.error("HighOrderController --> getOrderById() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/unionStagingPay", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "银联分期支付") public ResponseData unionStagingPay(HttpServletRequest request) { try { /* String orderNo = DateUtil.format(new Date(), DateUtil.YMDHMS); orderNo += IDGenerator.nextId(28 - orderNo.length());*/ String orgTrace = CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(0,4) +CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length() - 4,CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length()) +DateUtil.format(new Date(), DateUtil.YMDHMS) +IDGenerator.nextId(6); return ResponseMsgUtil.success(unionStagingPayConfig.advancePay( orgTrace, orgTrace, new BigDecimal("1"), CommonSysConst.getSysConfig().getUnionStagingPayNotifyUrl(), request)); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/queryStaging", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "分期查询") public ResponseData queryStaging(@RequestParam(name = "oriOrgTrace", required = true) String oriOrgTrace,HttpServletRequest request) { try { String orgTrace = CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(0,4) +CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length() - 4,CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length()) +DateUtil.format(new Date(), DateUtil.YMDHMS) +IDGenerator.nextId(6); return ResponseMsgUtil.success(UnionStagingPayConfig.queryStaging(orgTrace,oriOrgTrace ,"", new Date(), request)); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } /* @RequestMapping(value = "/orderToRefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "退款") public ResponseData orderToRefund(HttpServletRequest request) { try { OrderRefundModel orderRefundModel = WxOrderConfig.orderToRefund("4200001301202202035413938093", new BigDecimal("30.80"), new BigDecimal("16.90")); return ResponseMsgUtil.success(orderRefundModel); } catch (Exception e) { log.error("HighOrderController --> orderToRefund() error!", e); return ResponseMsgUtil.exception(e); } }*/ @RequestMapping(value = "/query", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "订单查询") public ResponseData query(@RequestParam(name = "oriOrgTrace", required = true) String oriOrgTrace,HttpServletRequest request) { try { String orgTrace = CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(0,4) +CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length() - 4,CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length()) +DateUtil.format(new Date(), DateUtil.YMDHMS) +IDGenerator.nextId(6); return ResponseMsgUtil.success(UnionStagingPayConfig.query(orgTrace,oriOrgTrace ,"", new Date(), request)); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/mposrefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "分期退款") public ResponseData mposrefund(@RequestParam(name = "oriOrgTrace", required = true) String oriOrgTrace,HttpServletRequest request) { try { String orgTrace = CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(0,4) +CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length() - 4,CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length()) +DateUtil.format(new Date(), DateUtil.YMDHMS) +IDGenerator.nextId(6); return ResponseMsgUtil.success(UnionStagingPayConfig.standardRefund(orgTrace,oriOrgTrace ,new BigDecimal("1"), "", new Date(), request)); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/mposfindrefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "分期退款查询") public ResponseData mposfindrefund(@RequestParam(name = "oriOrgTrace", required = true) String oriOrgTrace,HttpServletRequest request) { try { String orgTrace = CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(0,4) +CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length() - 4,CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length()) +DateUtil.format(new Date(), DateUtil.YMDHMS) +IDGenerator.nextId(6); return ResponseMsgUtil.success(UnionStagingPayConfig.mposfindrefund(orgTrace,oriOrgTrace ,"", new Date(), request)); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } public void wxProfitsharing(String transaction_id,String out_order_no, BigDecimal amount) { try { Map param = new LinkedHashMap<>(); param.put("appid", "wx637bd6f7314daa46"); param.put("mch_id", "1289663601"); param.put("sub_mch_id" , "1609882817"); // 个体户黎杨珍 param.put("transaction_id" , transaction_id); param.put("out_order_no" , out_order_no); param.put("nonce_str" , WxUtils.makeNonStr()); // 分账金额 BigDecimal porofitSharingAmount = amount; List> receiversList = new ArrayList<>(); Map receiversMap = new LinkedHashMap<>(); receiversMap.put("type", "MERCHANT_ID"); receiversMap.put("account", "1603942866"); receiversMap.put("amount", porofitSharingAmount.multiply(new BigDecimal("100")).intValue()); receiversMap.put("description", "分给商户【惠昕石化】"); receiversList.add(receiversMap); param.put("receivers" , JSONObject.toJSONString(receiversList)); String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); param.put("sign" , signStr); String resultXmL = this.doRefundRequest(param.get("mch_id"),null, WxUtils.mapToXml(param)); // 请求分账返回的结果 ResultProfitSharing resultProfitSharing = XmlUtil.getObjectFromXML(resultXmL, ResultProfitSharing.class); if (!resultProfitSharing.getResult_code().equals("FAIL")) { HighProfitSharingRecord sharingRecord = new HighProfitSharingRecord(); sharingRecord.setOutOrderNo(resultProfitSharing.getOut_order_no()); sharingRecord.setTransactionId(resultProfitSharing.getTransaction_id()); sharingRecord.setOrderId(resultProfitSharing.getOrder_id()); sharingRecord.setStatus(resultProfitSharing.getResult_code()); sharingRecord.setPrice(amount); sharingRecord.setCreateTime(new Date()); sharingRecord.setContent(resultXmL); highProfitSharingRecordService.insert(sharingRecord); } } catch (Exception e) { log.error("CmsContentController --> getCorporateAdvertising() error!", e); } } public CloseableHttpClient readCertificate(String mchId) throws Exception{ /** * 注意PKCS12证书 是从微信商户平台-》账户设置-》 API安全 中下载的 */ KeyStore keyStore = KeyStore.getInstance("PKCS12"); //P12文件目录 证书路径,这里需要你自己修改,linux下还是windows下的根路径 FileInputStream instream = new FileInputStream("/home/project/wx_cert/1289663601_apiclient_cert.p12"); // FileInputStream instream = new FileInputStream("G:\\hurui-project/hai-parent/hai-service/src/main/java/privatekey/1289663601_apiclient_cert.p12"); try { keyStore.load(instream, "1289663601".toCharArray());//这里写密码..默认是你的MCHID } finally { instream.close(); } SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, "1289663601".toCharArray()).build();//这里也是写密码的 SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, SSLConnectionSocketFactory.getDefaultHostnameVerifier()); // Allow TLSv1 protocol only return HttpClients.custom().setSSLSocketFactory(sslsf).build(); } public String doRefundRequest(String mchId, String url, String data) throws Exception { //小程序退款需要调用双向证书的认证 CloseableHttpClient httpClient = readCertificate(mchId); try { HttpPost httpost = new HttpPost("https://api.mch.weixin.qq.com/secapi/pay/profitsharing"); // 设置响应头信息 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(); } } } \ No newline at end of file +package com.cweb.controller; import cn.binarywang.wx.miniapp.api.WxMaMsgService; import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.cweb.config.SysConst; import com.cweb.config.WxMaConfiguration; 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.security.SessionObject; import com.hai.common.utils.*; import com.hai.config.*; import com.hai.dao.HighGasOrderPushMapper; import com.hai.entity.*; import com.hai.model.*; import com.hai.service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; 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.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Controller; import org.springframework.util.IdGenerator; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.net.ssl.SSLContext; import javax.servlet.http.HttpServletRequest; import java.io.FileInputStream; import java.math.BigDecimal; import java.security.KeyStore; import java.util.*; /** * @Auther: 胡锐 * @Description: * @Date: 2021/3/26 23:08 */ @Controller @RequestMapping(value = "/test") @Api(value = "订单接口") public class HighTestController { private static Logger log = LoggerFactory.getLogger(HighTestController.class); @Resource private HighMerchantService highMerchantService; @Resource private HighMerchantStoreService highMerchantStoreService; @Resource private HighGasOilPriceService highGasOilPriceService; @Resource private HighOrderService highOrderService; @Resource private HighProfitSharingRecordService highProfitSharingRecordService; @Resource private HighGasOrderPushMapper highGasOrderPushMapper; @Resource private HuiLianTongConfig huiLianTongConfig; @Resource private UnionPayConfig unionPayConfig; @Resource private UnionStagingPayConfig unionStagingPayConfig; @Resource private UnionUserConfig unionUserConfig; @Resource private OutRechargeOrderService outRechargeOrderService; @Resource private HighOilCardService oilCardService; @RequestMapping(value = "/wxGasProfitsharing", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "wxGasProfitsharing") public ResponseData wxGasProfitsharing(@RequestParam(name = "orderNo", required = true) String orderNo, HttpServletRequest request) { try { // 查询订单 HighOrder order = highOrderService.getOrderByOrderNo(orderNo); BigDecimal rake = new BigDecimal("0.05"); // 计算微信收取的手续费 支付金额 * 0.002 注:如果与两个相邻数字的距离相等,则为上舍入的舍入模式。 BigDecimal wxHandlingFee = order.getPayRealPrice().multiply(new BigDecimal("0.002")).setScale(2,BigDecimal.ROUND_HALF_DOWN); BigDecimal price = order.getPayRealPrice().subtract(wxHandlingFee); // 计算分账金额 手续费后的价格 * 0.05 注:如果与两个相邻数字的距离相等,则为上舍入的舍入模式。 BigDecimal profitSharingAmount = price.multiply(rake).setScale(2,BigDecimal.ROUND_DOWN); this.wxGasProfitsharing(order.getExt1(), order.getPaySerialNo(),order.getOrderNo(),profitSharingAmount); return ResponseMsgUtil.success(null); } catch (Exception e) { log.error("HighUserCardController --> getHuiLianTongCardInfo() error!", e); return ResponseMsgUtil.exception(e); } } public void wxGasProfitsharing(String appid,String transaction_id,String out_order_no, BigDecimal amount) { try { Map param = new LinkedHashMap<>(); param.put("appid", appid); param.put("mch_id", "1289663601"); param.put("sub_mch_id" , "1624126902"); // 个体户黎杨珍 param.put("transaction_id" , transaction_id); param.put("out_order_no" , out_order_no); param.put("nonce_str" , WxUtils.makeNonStr()); // 分账金额 BigDecimal porofitSharingAmount = amount; List> receiversList = new ArrayList<>(); Map receiversMap = new LinkedHashMap<>(); receiversMap.put("type", "MERCHANT_ID"); receiversMap.put("account", "1603942866"); receiversMap.put("amount", porofitSharingAmount.multiply(new BigDecimal("100")).intValue()); receiversMap.put("description", "分给商户【惠昕石化】"); receiversList.add(receiversMap); param.put("receivers" , JSONObject.toJSONString(receiversList)); String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); param.put("sign" , signStr); String resultXmL = this.doRefundRequest(param.get("mch_id"),null, WxUtils.mapToXml(param)); // 请求分账返回的结果 ResultProfitSharing resultProfitSharing = XmlUtil.getObjectFromXML(resultXmL, ResultProfitSharing.class); HighProfitSharingRecord sharingRecord = new HighProfitSharingRecord(); sharingRecord.setOutOrderNo(out_order_no); sharingRecord.setTransactionId(transaction_id); sharingRecord.setOrderId(resultProfitSharing.getOrder_id()); sharingRecord.setStatus(resultProfitSharing.getResult_code()); sharingRecord.setPrice(amount); sharingRecord.setCreateTime(new Date()); sharingRecord.setContent(resultXmL); highProfitSharingRecordService.insert(sharingRecord); } catch (Exception e) { log.error("CmsContentController --> getCorporateAdvertising() error!", e); } } @RequestMapping(value = "/getHuiLianTongCardInfo", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询汇联通工会卡详情") public ResponseData getHuiLianTongCardInfo(@RequestParam(name = "cardNo", required = true) String cardNo, HttpServletRequest request) { try { // 用户 // JSONObject cardInfo = HuiLianTongUnionCardConfig.queryCardInfo(cardNo); if (StringUtils.isBlank(cardInfo.getString("data"))) { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQUEST_ERROR, ""); } return ResponseMsgUtil.success(HuiLianTongUnionCardConfig.resolveResponse(cardInfo.getString("data"))); } catch (Exception e) { log.error("HighUserCardController --> getHuiLianTongCardInfo() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/oilCardRefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "油卡退款") public ResponseData oilCardRefund(@RequestParam(name = "orderNo", required = true) String orderNo, HttpServletRequest request) { try { oilCardService.refund(orderNo); return ResponseMsgUtil.success(""); } catch (Exception e) { log.error("HighUserCardController --> getHuiLianTongCardInfo() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/queryGasInfoByGasId", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "根据油站 id 拉取最新的油站数据") public ResponseData queryGasInfoByGasId(@RequestParam(name = "gasId", required = true) String gasId, HttpServletRequest request) { try { return ResponseMsgUtil.success(TuanYouConfig.queryGasInfoByGasId(gasId)); } catch (Exception e) { log.error("HighUserCardController --> getHuiLianTongCardInfo() error!", e); return ResponseMsgUtil.exception(e); } } // // @RequestMapping(value = "/getMobile", method = RequestMethod.GET) // @ResponseBody // @ApiOperation(value = "话费充值") // public ResponseData getMobile( // @RequestParam(name = "orderNo", required = true) String orderNo, // @RequestParam(name = "amount", required = true) Integer amount, // @RequestParam(name = "phone", required = true) String phone, // HttpServletRequest request) { // try { // return ResponseMsgUtil.success(outRechargeOrderService.getMobile(phone,amount,orderNo)); // // } catch (Exception e) { // log.error("HighUserCardController --> getHuiLianTongCardInfo() error!", e); // return ResponseMsgUtil.exception(e); // } // } @RequestMapping(value = "/initTYMerchantStore", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "初始化加油站") public ResponseData initTYMerchantStore(@RequestParam(name = "merchantId", required = true) Long merchantId) throws Exception { HighMerchantModel merchant = highMerchantService.getMerchantById(merchantId); if (merchant == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到商户"); } JSONObject jsonObjectP = TuanYouConfig.queryGasInfoListByPage(1, 1000); JSONObject resultObjectP = jsonObjectP.getObject("result", JSONObject.class); for (int i = 1; i <= resultObjectP.getInteger("totalPageNum").intValue();i++) { JSONObject jsonObject = TuanYouConfig.queryGasInfoListByPage(i, 1000); JSONObject resultObject = jsonObject.getObject("result", JSONObject.class); JSONArray jsonArray = resultObject.getJSONArray("gasInfoList"); HighMerchantStore highMerchantStore; HighGasOilPrice highGasOilPrice; for (Object gasObject : jsonArray) { JSONObject object = JSONObject.parseObject(JSONObject.toJSONString(gasObject)); HighMerchantStoreModel store = highMerchantStoreService.getMerchantStoreByKey(object.getString("gasId")); if (store != null) { store.setType(1); store.setMerchantId(merchant.getId()); store.setCompanyId(merchant.getCompanyId()); store.setStoreKey(object.getString("gasId")); store.setStoreName(object.getString("gasName")); store.setStoreLogo(object.getString("gasLogoSmall")); store.setRegionId(object.getLong("provinceCode")); store.setRegionName(object.getString("provinceName")); store.setAddress(object.getString("gasAddress")); store.setLongitude(object.getString("gasAddressLongitude")); store.setLatitude(object.getString("gasAddressLatitude")); store.setStatus(object.getInteger("gasStatus")); store.setOperatorId(0L); store.setOperatorName("系统创建"); store.setUpdateTime(new Date()); store.setExt1(object.getString("gasSourceId")); highMerchantStoreService.updateMerchantStoreDetail(store); JSONArray oilPriceList = object.getJSONArray("oilPriceList"); for (Object oilPrice : oilPriceList) { JSONObject oilPriceObject = JSONObject.parseObject(JSONObject.toJSONString(oilPrice)); // 查询门店油号 highGasOilPrice = highGasOilPriceService.getGasOilPriceByStoreAndOilNo(store.getId(), oilPriceObject.getInteger("oilNo")); if (highGasOilPrice == null) { highGasOilPrice = new HighGasOilPrice(); highGasOilPrice.setMerchantStoreId(store.getId()); highGasOilPrice.setOilNo(oilPriceObject.getInteger("oilNo")); highGasOilPrice.setOilNoName(oilPriceObject.getString("oilNoName")); highGasOilPrice.setPriceVip(oilPriceObject.getBigDecimal("priceVip")); highGasOilPrice.setPriceGun(oilPriceObject.getBigDecimal("priceGun")); highGasOilPrice.setPriceOfficial(oilPriceObject.getBigDecimal("priceOfficial")); highGasOilPrice.setOilType(oilPriceObject.getInteger("oilType")); highGasOilPrice.setOilTypeName(oilPriceObject.getString("oilTypeName")); } else { highGasOilPrice.setMerchantStoreId(store.getId()); highGasOilPrice.setOilNo(oilPriceObject.getInteger("oilNo")); highGasOilPrice.setOilNoName(oilPriceObject.getString("oilNoName")); highGasOilPrice.setPriceVip(oilPriceObject.getBigDecimal("priceVip")); highGasOilPrice.setPriceGun(oilPriceObject.getBigDecimal("priceGun")); highGasOilPrice.setPriceOfficial(oilPriceObject.getBigDecimal("priceOfficial")); highGasOilPrice.setOilType(oilPriceObject.getInteger("oilType")); highGasOilPrice.setOilTypeName(oilPriceObject.getString("oilTypeName")); } highGasOilPriceService.editGasOilPrice(highGasOilPrice); } } else { highMerchantStore = new HighMerchantStore(); highMerchantStore.setType(1); highMerchantStore.setMerchantId(merchant.getId()); highMerchantStore.setCompanyId(merchant.getCompanyId()); highMerchantStore.setStoreKey(object.getString("gasId")); highMerchantStore.setStoreName(object.getString("gasName")); highMerchantStore.setStoreLogo(object.getString("gasLogoSmall")); highMerchantStore.setRegionId(object.getLong("provinceCode")); highMerchantStore.setRegionName(object.getString("provinceName")); highMerchantStore.setAddress(object.getString("gasAddress")); highMerchantStore.setLongitude(object.getString("gasAddressLongitude")); highMerchantStore.setLatitude(object.getString("gasAddressLatitude")); highMerchantStore.setStatus(1); highMerchantStore.setOperatorId(0L); highMerchantStore.setOperatorName("系统创建"); highMerchantStore.setCreateTime(new Date()); highMerchantStore.setUpdateTime(new Date()); highMerchantStore.setExt1(object.getString("gasSourceId")); HighMerchantStoreModel merchantStoreModel = new HighMerchantStoreModel(); BeanUtils.copyProperties(highMerchantStore, merchantStoreModel); highMerchantStoreService.insertMerchantStore(merchantStoreModel); JSONArray oilPriceList = object.getJSONArray("oilPriceList"); for (Object oilPrice : oilPriceList) { JSONObject oilPriceObject = JSONObject.parseObject(JSONObject.toJSONString(oilPrice)); highGasOilPrice = new HighGasOilPrice(); highGasOilPrice.setMerchantStoreId(merchantStoreModel.getId()); highGasOilPrice.setOilNo(oilPriceObject.getInteger("oilNo")); highGasOilPrice.setOilNoName(oilPriceObject.getString("oilNoName")); highGasOilPrice.setPriceVip(oilPriceObject.getBigDecimal("priceVip")); highGasOilPrice.setPriceGun(oilPriceObject.getBigDecimal("priceGun")); highGasOilPrice.setPriceOfficial(oilPriceObject.getBigDecimal("priceOfficial")); highGasOilPrice.setOilType(oilPriceObject.getInteger("oilType")); highGasOilPrice.setOilTypeName(oilPriceObject.getString("oilTypeName")); highGasOilPriceService.editGasOilPrice(highGasOilPrice); } } } } return ResponseMsgUtil.success("初始化完成"); } @RequestMapping(value = "/detectTYMerchantStore", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "检测加油站") public ResponseData detectTYMerchantStore(@RequestParam(name = "merchantId", required = true) Long merchantId) throws Exception { HighMerchantModel merchant = highMerchantService.getMerchantById(merchantId); if (merchant == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到商户"); } Map param = new HashMap<>(); param.put("merchantId", merchant.getId()); List stores = highMerchantStoreService.getMerchantStoreList(param); for (HighMerchantStore store : stores) { JSONObject jsonObject = TuanYouConfig.queryGasInfoByGasId(store.getStoreKey()); if (jsonObject != null && jsonObject.getString("code").equals("200")) { JSONObject result = jsonObject.getJSONObject("result"); store.setStatus(result.getInteger("gasStatus")); } else { store.setStatus(0); } highMerchantStoreService.updateMerchantStoreDetail(store); } return ResponseMsgUtil.success("初始化完成"); } @RequestMapping(value = "/pushTuanYouOrder", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "推送团油订单") public ResponseData pushTuanYouOrder(@RequestParam(name = "orderNo", required = true) String orderNo) { try { HighOrder order = highOrderService.getOrderByOrderNo(orderNo); for (HighChildOrder highChildOrder : order.getHighChildOrderList()) { HighMerchantStoreModel store = highMerchantStoreService.getMerchantStoreById(highChildOrder.getGoodsId()); // 推送团油订单 Map paramMap = new HashMap<>(); paramMap.put("gasId", store.getStoreKey()); paramMap.put("oilNo", highChildOrder.getGasOilNo()); paramMap.put("gunNo", highChildOrder.getGasGunNo()); BigDecimal priceGun = highChildOrder.getGasPriceGun(); BigDecimal priceVip = highChildOrder.getGasPriceVip(); paramMap.put("priceGun", priceGun); // 枪单价 paramMap.put("priceVip", priceVip); // 优惠价 paramMap.put("driverPhone", order.getMemPhone()); // paramMap.put("driverPhone", "17726395120"); paramMap.put("thirdSerialNo", order.getOrderNo()); paramMap.put("refuelingAmount", highChildOrder.getTotalPrice()); // 油品类型 1:汽油:2:柴油;3:天然气 if (highChildOrder.getGasOilType() == 1) { paramMap.put("accountNo", CommonSysConst.getSysConfig().getTuanYouGasolineAccount()); } else if (highChildOrder.getGasOilType() == 2) { paramMap.put("accountNo", CommonSysConst.getSysConfig().getTuanYouDieselAccount()); } JSONObject orderPushObject = TuanYouConfig.refuelingOrderPush(paramMap); // 推送团油订单记录 HighGasOrderPush highGasOrderPush = new HighGasOrderPush(); highGasOrderPush.setCreateTime(new Date()); highGasOrderPush.setCode(orderPushObject.getString("code")); highGasOrderPush.setRequestContent(JSONObject.toJSONString(paramMap)); highGasOrderPush.setReturnContent(orderPushObject.toJSONString()); highGasOrderPushMapper.insert(highGasOrderPush); if (orderPushObject != null && orderPushObject.getString("code").equals("200")) { highChildOrder.setGasOrderNo(orderPushObject.getJSONObject("result").getString("orderNo")); } highOrderService.updateOrder(order); } return ResponseMsgUtil.success(order); } catch (Exception e) { log.error("HighOrderController --> getOrderById() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/queryCompanyAccountInfo2JD", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询团油余额") public ResponseData queryCompanyAccountInfo2JD() { try { return ResponseMsgUtil.success(TuanYouConfig.queryCompanyAccountInfo2JD()); } catch (Exception e) { log.error("HighOrderController --> queryCompanyAccountInfo2JD() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/queryCompanyPriceDetail", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询团油余额") public ResponseData queryCompanyPriceDetail() { try { return ResponseMsgUtil.success(TuanYouConfig.queryCompanyPriceDetail("LW000115995", "92")); } catch (Exception e) { log.error("HighOrderController --> queryCompanyAccountInfo2JD() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/couJointDist", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "派发贵州卡券") public ResponseData couJointDist(@RequestParam(name = "token", required = true) String token) { try { return ResponseMsgUtil.success(HuiLianTongConfig.couJointDist(token,"HF2022031509263475105","20JY000575",1,"18385214742", "oArhO6QZSIJAcawo1Wwx5cKKZ0ns")); } catch (Exception e) { log.error("HighOrderController --> getOrderById() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/tradeQuery", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "派发贵州卡券") public ResponseData tradeQuery(@RequestParam(name = "token", required = true) String token) { try { return ResponseMsgUtil.success(UnionPayConfig.tradeQuery(UnionPayConfig.MER_ID3,UnionPayConfig.TERM_ID3,"HF2022031215130820400")); } catch (Exception e) { log.error("HighOrderController --> getOrderById() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/zwrefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "派发贵州卡券") public ResponseData zwrefund() { try { return ResponseMsgUtil.success(UnionPayConfig.zwrefund(UnionPayConfig.MER_ID3,UnionPayConfig.TERM_ID3,"HF2022031215130820400", "31720220312151311876232", new BigDecimal("270").multiply(new BigDecimal("100")).longValue())); } catch (Exception e) { log.error("HighOrderController --> getOrderById() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/unionPay", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "银联支付") public ResponseData unionPay(HttpServletRequest request) { try { // return ResponseMsgUtil.success(RequestUtils.getIpAddress(request)); return ResponseMsgUtil.success(unionPayConfig.upPreOrder(UnionPayConfig.MER_ID3, UnionPayConfig.TERM_ID3, "HF"+System.currentTimeMillis(), new BigDecimal("1"), "test",CommonSysConst.getSysConfig().getUnionPayNotifyUrl(), request)); } catch (Exception e) { log.error("HighOrderController --> unionPay() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/getToken", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "获取贵州中石化token") public ResponseData getToken() { try { return ResponseMsgUtil.success(huiLianTongConfig.getToken()); } catch (Exception e) { log.error("HighOrderController --> getToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/unionTradeQuery", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "银联交易查询") public ResponseData unionTradeQuery(@RequestParam(name = "paySerialNo", required = true) String paySerialNo) { try { return ResponseMsgUtil.success(UnionPayConfig.tradeQuery(UnionPayConfig.MER_ID1, UnionPayConfig.TERM_ID1, paySerialNo)); } catch (Exception e) { log.error("HighOrderController --> unionTradeQuery() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/getBackendToken", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "获取访问令牌backendToken") public ResponseData getBackendToken() { try { return ResponseMsgUtil.success(unionUserConfig.getBackendToken()); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/wxSplitAccount", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "微信分账") public ResponseData wxSplitAccount() { try { HighOrder orderNo = highOrderService.getOrderByOrderNo("HF2021101812025050304"); wxProfitsharing(orderNo.getOrderNo(),orderNo.getPaySerialNo(),orderNo.getPayRealPrice()); return ResponseMsgUtil.success("分账成功"); } catch (Exception e) { log.error("HighOrderController --> getOrderById() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/unionStagingPay", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "银联分期支付") public ResponseData unionStagingPay(HttpServletRequest request) { try { /* String orderNo = DateUtil.format(new Date(), DateUtil.YMDHMS); orderNo += IDGenerator.nextId(28 - orderNo.length());*/ String orgTrace = CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(0,4) +CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length() - 4,CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length()) +DateUtil.format(new Date(), DateUtil.YMDHMS) +IDGenerator.nextId(6); return ResponseMsgUtil.success(unionStagingPayConfig.advancePay( orgTrace, orgTrace, new BigDecimal("1"), CommonSysConst.getSysConfig().getUnionStagingPayNotifyUrl(), request)); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/queryStaging", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "分期查询") public ResponseData queryStaging(@RequestParam(name = "oriOrgTrace", required = true) String oriOrgTrace,HttpServletRequest request) { try { String orgTrace = CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(0,4) +CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length() - 4,CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length()) +DateUtil.format(new Date(), DateUtil.YMDHMS) +IDGenerator.nextId(6); return ResponseMsgUtil.success(UnionStagingPayConfig.queryStaging(orgTrace,oriOrgTrace ,"", new Date(), request)); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } /* @RequestMapping(value = "/orderToRefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "退款") public ResponseData orderToRefund(HttpServletRequest request) { try { OrderRefundModel orderRefundModel = WxOrderConfig.orderToRefund("4200001301202202035413938093", new BigDecimal("30.80"), new BigDecimal("16.90")); return ResponseMsgUtil.success(orderRefundModel); } catch (Exception e) { log.error("HighOrderController --> orderToRefund() error!", e); return ResponseMsgUtil.exception(e); } }*/ @RequestMapping(value = "/query", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "订单查询") public ResponseData query(@RequestParam(name = "oriOrgTrace", required = true) String oriOrgTrace,HttpServletRequest request) { try { String orgTrace = CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(0,4) +CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length() - 4,CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length()) +DateUtil.format(new Date(), DateUtil.YMDHMS) +IDGenerator.nextId(6); return ResponseMsgUtil.success(UnionStagingPayConfig.query(orgTrace,oriOrgTrace ,"", new Date(), request)); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/mposrefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "分期退款") public ResponseData mposrefund(@RequestParam(name = "oriOrgTrace", required = true) String oriOrgTrace,HttpServletRequest request) { try { String orgTrace = CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(0,4) +CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length() - 4,CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length()) +DateUtil.format(new Date(), DateUtil.YMDHMS) +IDGenerator.nextId(6); return ResponseMsgUtil.success(UnionStagingPayConfig.standardRefund(orgTrace,oriOrgTrace ,new BigDecimal("1"), "", new Date(), request)); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/mposfindrefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "分期退款查询") public ResponseData mposfindrefund(@RequestParam(name = "oriOrgTrace", required = true) String oriOrgTrace,HttpServletRequest request) { try { String orgTrace = CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(0,4) +CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length() - 4,CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length()) +DateUtil.format(new Date(), DateUtil.YMDHMS) +IDGenerator.nextId(6); return ResponseMsgUtil.success(UnionStagingPayConfig.mposfindrefund(orgTrace,oriOrgTrace ,"", new Date(), request)); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } public void wxProfitsharing(String transaction_id,String out_order_no, BigDecimal amount) { try { Map param = new LinkedHashMap<>(); param.put("appid", "wx637bd6f7314daa46"); param.put("mch_id", "1289663601"); param.put("sub_mch_id" , "1609882817"); // 个体户黎杨珍 param.put("transaction_id" , transaction_id); param.put("out_order_no" , out_order_no); param.put("nonce_str" , WxUtils.makeNonStr()); // 分账金额 BigDecimal porofitSharingAmount = amount; List> receiversList = new ArrayList<>(); Map receiversMap = new LinkedHashMap<>(); receiversMap.put("type", "MERCHANT_ID"); receiversMap.put("account", "1603942866"); receiversMap.put("amount", porofitSharingAmount.multiply(new BigDecimal("100")).intValue()); receiversMap.put("description", "分给商户【惠昕石化】"); receiversList.add(receiversMap); param.put("receivers" , JSONObject.toJSONString(receiversList)); String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); param.put("sign" , signStr); String resultXmL = this.doRefundRequest(param.get("mch_id"),null, WxUtils.mapToXml(param)); // 请求分账返回的结果 ResultProfitSharing resultProfitSharing = XmlUtil.getObjectFromXML(resultXmL, ResultProfitSharing.class); if (!resultProfitSharing.getResult_code().equals("FAIL")) { HighProfitSharingRecord sharingRecord = new HighProfitSharingRecord(); sharingRecord.setOutOrderNo(resultProfitSharing.getOut_order_no()); sharingRecord.setTransactionId(resultProfitSharing.getTransaction_id()); sharingRecord.setOrderId(resultProfitSharing.getOrder_id()); sharingRecord.setStatus(resultProfitSharing.getResult_code()); sharingRecord.setPrice(amount); sharingRecord.setCreateTime(new Date()); sharingRecord.setContent(resultXmL); highProfitSharingRecordService.insert(sharingRecord); } } catch (Exception e) { log.error("CmsContentController --> getCorporateAdvertising() error!", e); } } public CloseableHttpClient readCertificate(String mchId) throws Exception{ /** * 注意PKCS12证书 是从微信商户平台-》账户设置-》 API安全 中下载的 */ KeyStore keyStore = KeyStore.getInstance("PKCS12"); //P12文件目录 证书路径,这里需要你自己修改,linux下还是windows下的根路径 FileInputStream instream = new FileInputStream("/home/project/wx_cert/1289663601_apiclient_cert.p12"); // FileInputStream instream = new FileInputStream("G:\\hurui-project/hai-parent/hai-service/src/main/java/privatekey/1289663601_apiclient_cert.p12"); try { keyStore.load(instream, "1289663601".toCharArray());//这里写密码..默认是你的MCHID } finally { instream.close(); } SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, "1289663601".toCharArray()).build();//这里也是写密码的 SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, SSLConnectionSocketFactory.getDefaultHostnameVerifier()); // Allow TLSv1 protocol only return HttpClients.custom().setSSLSocketFactory(sslsf).build(); } public String doRefundRequest(String mchId, String url, String data) throws Exception { //小程序退款需要调用双向证书的认证 CloseableHttpClient httpClient = readCertificate(mchId); try { HttpPost httpost = new HttpPost("https://api.mch.weixin.qq.com/secapi/pay/profitsharing"); // 设置响应头信息 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(); } } @RequestMapping(value = "/mssage", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "分期退款查询") public ResponseData mssage() { try { List list = new ArrayList<>(); Map m = new HashMap<>(); m.put("thing2", "orderName"); // 充值项目 m.put("time3", DateUtil.date2String(new Date() , "yyyy年MM月dd日 HH:mm:ss")); // 充值项目 m.put("phrase4", "充值"); // 充值项目 m.put("amount5", "20"); // 充值项目 for (String key: m.keySet()) { WxMaSubscribeMessage.Data msgElement = new WxMaSubscribeMessage.Data(); msgElement.setName(key); msgElement.setValue(m.get(key)); list.add(msgElement); } WxMaSubscribeMessage subscribeMessage = new WxMaSubscribeMessage(); subscribeMessage.setToUser("oUGn_4kW4K1R73G_kK7ibuWID_VA"); // 小程序openId subscribeMessage.setTemplateId("d4ciZ6lqjExqH6AOZtQeUbT-sHLC4BHB0UgQ-DoIqfw"); subscribeMessage.setData(list); final WxMaService wxService = WxMaConfiguration.getMaService(); WxMaMsgService maMsgService = wxService.getMsgService(); maMsgService.sendSubscribeMsg(subscribeMessage); return ResponseMsgUtil.success("null"); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } } \ No newline at end of file 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 d4d81ad8..ca563108 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/OutRechargeOrderController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/OutRechargeOrderController.java @@ -94,616 +94,616 @@ public class OutRechargeOrderController { @Resource private HighDiscountUserRelService highDiscountUserRelService; - - @RequestMapping(value="/addOrder",method = RequestMethod.POST) - @ResponseBody - @ApiOperation(value = "增加订单") - public ResponseData addOrder(@RequestBody OutRechargeOrder outRechargeOrder, HttpServletRequest request) { - try { - - // 用户 - SessionObject sessionObject = userCenter.getSessionObject(request); - HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); - if (StringUtils.isBlank(outRechargeOrder.getRechargeContent()) || - outRechargeOrder.getPayPrice() == null || - outRechargeOrder.getObjectId() == null || - outRechargeOrder.getOrderPrice() == null - ) { - log.error("addOrder error!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); - } - - if (!secConfigService.isConfig("RECHARGE" , "1")) { - log.error("addOrder error!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.RECHARGE_CLOSE, ""); - } - - String remarks = ""; - // 支付类型 1.微信支付 - outRechargeOrder.setPayType(1); - // 判断充值模式:1 电信 2. 移动 3. 联通 - // 拼接内容 - remarks = outRechargeOrder.getRechargeContent() + "充值" + outRechargeOrder.getOrderPrice() + "元"; - - HighDiscountUserRel highDiscountUserRel = null; - if (outRechargeOrder.getMemDiscountId() != null) { - // 卡优惠券信息 - highDiscountUserRel = highDiscountUserRelService.getRelById(outRechargeOrder.getMemDiscountId()); - if (highDiscountUserRel == null || highDiscountUserRel.getStatus() != 1) { - log.error("HighOrderController --> addOrder() error!", "优惠券状态错误"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券状态错误"); - } - if (!highDiscountUserRel.getHighDiscount().getUseScope().equals(DiscountUseScope.type1.getType()) - && !highDiscountUserRel.getHighDiscount().getUseScope().equals(DiscountUseScope.type3.getType())) { - log.error("HighOrderController --> addOrder() error!", "无法使用此优惠券"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法使用此优惠券"); - } - } - - // 优惠券抵扣 - if (highDiscountUserRel != null) { - outRechargeOrder.setMemDiscountName(highDiscountUserRel.getHighDiscount().getDiscountName()); - - // 卡卷类型 1:满减 2:抵扣 3:折扣 - if (highDiscountUserRel.getHighDiscount().getDiscountType() == 1) { - // 如果订单总额 小于 满减价格 - if (outRechargeOrder.getOrderPrice().compareTo(highDiscountUserRel.getHighDiscount().getDiscountCondition()) > 1) { - log.error("HighOrderController --> addOrder() error!", "订单未达到满减额度"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.UN_MEMBER_ERROR, "订单未达到"+highDiscountUserRel.getHighDiscount().getDiscountCondition()+"元,无法使用此优惠券"); - } - // 订单总额 - 满减额度 - BigDecimal payPrice = outRechargeOrder.getOrderPrice().subtract(highDiscountUserRel.getHighDiscount().getDiscountPrice()); - - outRechargeOrder.setDeductionPrice(highDiscountUserRel.getHighDiscount().getDiscountPrice()); - // 如果总额小于0 - if (payPrice.compareTo(new BigDecimal("0")) == -1) { - outRechargeOrder.setPayPrice(new BigDecimal("0")); - } else { - outRechargeOrder.setPayPrice(payPrice); - } - } - - // 卡卷类型 1:满减 2:抵扣 3:折扣 - if (highDiscountUserRel.getHighDiscount().getDiscountType() == 2) { - // 订单总额 - 满减额度 - BigDecimal payPrice = outRechargeOrder.getOrderPrice().subtract(highDiscountUserRel.getHighDiscount().getDiscountPrice()); - outRechargeOrder.setDeductionPrice(highDiscountUserRel.getHighDiscount().getDiscountPrice()); - - // 如果总额小于0 - if (payPrice.compareTo(new BigDecimal("0")) == -1) { - outRechargeOrder.setPayPrice(new BigDecimal("0")); - } else { - outRechargeOrder.setPayPrice(payPrice); - } - } - - // 卡卷类型 1:满减 2:抵扣 3:折扣 - if (highDiscountUserRel.getHighDiscount().getDiscountType() == 3) { - BigDecimal discountPrice = highDiscountUserRel.getHighDiscount().getDiscountPrice(); - // 订单总额 * 折扣 - BigDecimal payPrice = outRechargeOrder.getOrderPrice().multiply(discountPrice); - outRechargeOrder.setDeductionPrice(outRechargeOrder.getOrderPrice().subtract(payPrice)); - outRechargeOrder.setPayPrice(payPrice); - } - } - - OutRechargePrice outRechargePrice = outRechargePriceService.findById(outRechargeOrder.getObjectId().longValue()); - - HighUserCard highUserCard = highUserCardService.getUserHtlCardNo(userInfoModel.getHighUser().getId()); - if (highUserCard != null) { - outRechargeOrder.setIdCard(highUserCard.getCardNo()); - } - outRechargeOrder.setRemarks(remarks); - outRechargeOrder.setRechargeName(remarks); - outRechargeOrder.setOrderNo("CZ" + DateUtil.date2String(new Date(),"yyyyMMddHHmmss") + IDGenerator.nextId(5)); - outRechargeOrder.setUserId(userInfoModel.getHighUser().getId()); - outRechargeOrder.setUserName(userInfoModel.getHighUser().getName()); - outRechargeOrder.setRechargeType(outRechargePrice.getRechargeType()); - outRechargeOrder.setUserPhone(userInfoModel.getHighUser().getPhone()); - - outRechargeOrder.setCreateTimed(new Date()); - outRechargeOrder.setStatus(1); - outRechargeOrderService.insertOrder(outRechargeOrder); - return ResponseMsgUtil.success(outRechargeOrder); - - } catch (Exception e) { - log.error("HighOrderController -> addOrder() error!",e); - return ResponseMsgUtil.exception(e); - } - } - - - @RequestMapping(value = "/getOrderById", method = RequestMethod.GET) - @ResponseBody - @ApiOperation(value = "根据id查询订单详情") - public ResponseData getOrderById(@RequestParam(name = "orderId", required = true) Long orderId) { - try { - - return ResponseMsgUtil.success(outRechargeOrderService.findByOrderId(orderId)); - - } catch (Exception e) { - log.error("HighOrderController --> getOrderById() error!", e); - return ResponseMsgUtil.exception(e); - } - } - - @RequestMapping(value = "/cancelOrder", method = RequestMethod.GET) - @ResponseBody - @ApiOperation(value = "取消订单") - public ResponseData cancelOrder(@RequestParam(name = "orderId", required = true) Long orderId) { - try { - - OutRechargeOrder outRechargeOrder = outRechargeOrderService.findByOrderId(orderId); - - if (outRechargeOrder.getStatus() == 1) { - outRechargeOrderService.cancelOrder(orderId); - } else { - log.error("orderToPay error!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.STATUS_ERROR, ""); - } - - return ResponseMsgUtil.success("操作成功"); - - } catch (Exception e) { - log.error("HighOrderController --> cancelOrder() error!", e); - return ResponseMsgUtil.exception(e); - } - } - - @RequestMapping(value = "/getUserOrderList", method = RequestMethod.GET) - @ResponseBody - @ApiOperation(value = "获取用户订单") - public ResponseData getUserOrderList( - @RequestParam(name = "status", required = false) Integer status, - @RequestParam(name = "orderNo", required = false) String orderNo, - @RequestParam(name = "rechargeModel", required = false) String rechargeModel, - @RequestParam(name = "pageNum", required = true) Integer pageNum, - @RequestParam(name = "pageSize", required = true) Integer pageSize, - HttpServletRequest request) { - try { - - // 用户 - SessionObject sessionObject = userCenter.getSessionObject(request); - HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); - - Map map = new HashMap<>(); - map.put("userId", userInfoModel.getHighUser().getId().toString()); - if (status != null) { - map.put("status", status.toString()); - } - if (StringUtils.isNotBlank(orderNo)) { - map.put("orderNo", orderNo); - } - if (StringUtils.isNotBlank(rechargeModel)) { - map.put("rechargeModel", rechargeModel); - } - - PageHelper.startPage(pageNum,pageSize); - return ResponseMsgUtil.success(new PageInfo<>(outRechargeOrderService.getListRechargeOrder(map))); - - } catch (Exception e) { - log.error("HighOrderController --> getUserOrderList() error!", e); - return ResponseMsgUtil.exception(e); - } - } - - - @RequestMapping(value="/orderToPay",method = RequestMethod.POST) - @ResponseBody - @ApiOperation(value = "订单支付发起支付") - public ResponseData orderToPay(@RequestBody String reqBodyStr) { - try { - if (StringUtils.isBlank(reqBodyStr)) { - log.error("orderToPay error!", "参数错误"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); - } - JSONObject jsonObject = JSONObject.parseObject(reqBodyStr); - Long orderId = jsonObject.getLong("orderId"); - Integer openIdType = jsonObject.getInteger("openIdType"); // openId类型 1:小程序 2:公众号 - String openId = jsonObject.getString("openId"); // openId - if (orderId == null || StringUtils.isBlank(openId)) { - log.error("orderToPay error!", "参数错误"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); - } - - // 订单 - 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() != 1) { - log.error("orderToPay error!", "无法支付,订单不处于待支付状态"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法支付,订单不处于待支付状态"); - } - - Map map = new HashMap<>(); - map.put("orderNo", order.getOrderNo()); - map.put("payPrice", order.getPayPrice()); - map.put("orderScene", "RECHARGE_ORDER"); - map.put("body","充值话费"); - map.put("subject","充值话费"); - - //微信支付 - String nonce_str = MD5Util.MD5Encode(String.valueOf(ThreadLocalRandom.current().nextInt(10000)), "UTF-8"); - int total_fee = MathUtils.objectConvertBigDecimal(map.get("payPrice")).multiply(new BigDecimal("100")).intValue(); - WeChatPayReqInfo weChatPayReqInfo = new WeChatPayReqInfo(); - weChatPayReqInfo.setAppid(SysConst.getSysConfig().getWxMchAppId()); //公众号id - weChatPayReqInfo.setMch_id(SysConst.getSysConfig().getWxMchId()); //商户号 - if (openIdType != null && openIdType.equals(2)) { - weChatPayReqInfo.setSub_appid("wxa075e8509802f826"); //商户号公众号 - } else { - weChatPayReqInfo.setSub_appid(SysConst.getSysConfig().getWxSubAppId());//小程序 - } - weChatPayReqInfo.setSub_mch_id("1614670195"); - weChatPayReqInfo.setSub_openid(openId); - weChatPayReqInfo.setNonce_str(nonce_str); //随机字符串 - weChatPayReqInfo.setBody(map.get("body").toString()); //商品描述 - weChatPayReqInfo.setOut_trade_no(map.get("orderNo").toString()); //商户订单号 - weChatPayReqInfo.setTotal_fee(total_fee); //总金额 - weChatPayReqInfo.setSpbill_create_ip("139.159.177.244"); //终端ip - weChatPayReqInfo.setNotify_url(SysConst.getSysConfig().getNotifyUrl()); //通知url - weChatPayReqInfo.setTrade_type("JSAPI"); //交易类型 - weChatPayReqInfo.setAttach(map.get("orderScene").toString()); - weChatPayReqInfo.setProfit_sharing("N"); - //附加数据,区分订单类型 - Map payMap = new HashMap<>(); - - payMap.put("app_id", weChatPayReqInfo.getSub_appid()); - payMap.put("api_key",SysConst.getSysConfig().getWxApiKey()); - payMap.put("unified_order_url",SysConst.getSysConfig().getWxUnifiedOrderUrl()); - SortedMap sortedMap = wechatPayUtil.goWechatPay(weChatPayReqInfo,payMap); - return ResponseMsgUtil.success(sortedMap); - } catch (Exception e) { - log.error("orderToPay error!", e); - return ResponseMsgUtil.exception(e); - } - } - - @RequestMapping(value="/hltUnionCardPay",method = RequestMethod.POST) - @ResponseBody - @ApiOperation(value = "工会卡支付") - public ResponseData hltUnionCardPay(@RequestBody JSONObject body,HttpServletRequest request) { - try { - // 用户 - SessionObject sessionObject = userCenter.getSessionObject(request); - HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); - - if (body == null - || body.getLong("orderId") == null - || StringUtils.isBlank(body.getString("cardNo")) - ) { - log.error("orderToPay error!", "参数错误"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); - } - - // 查询用户支付密码 - HighUserPayPassword userPayPassword = highUserPayPasswordService.getDetailByUser(userInfoModel.getHighUser().getId()); - if (userPayPassword == null) { - log.error("orderToPay error!", "未设置支付密码"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_SET_USER_PAY_PWD, ""); - } - if (StringUtils.isBlank(body.getString("password"))) { - log.error("hltUnionCardPay error!", "未输入支付密码"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_ENTER_USER_PAY_PWD, ""); - } - // 校验支付密码是否一直 - if (!AESEncodeUtil.aesEncrypt(body.getString("password")).equals(userPayPassword.getPassword())) { - log.error("hltUnionCardPay error!", ""); - throw ErrorHelp.genException(SysCode.System, ErrorCode.USER_PAY_PWD_ERROR, ""); - } - - // 查询用户与卡号的关系 - HighUserCard userCard = highUserCardService.getDetailByUserCardNo(userInfoModel.getHighUser().getId(), body.getString("cardNo")); - if (userCard == null) { - log.error("hltUnionCardPay() ERROR", "未绑定卡号"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未绑定卡号"); - } - - // 订单 - OutRechargeOrder order = outRechargeOrderService.findByOrderId(body.getLong("orderId")); - if (order == null) { - log.error("hltUnionCardPay error!", "未找到订单信息"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到订单信息"); - } - - // 订单状态 : 1.待支付 2.已支付 3.已完成 4.已退款 5.已取消 - if (order.getStatus() != 1) { - log.error("hltUnionCardPay error!", "无法支付,订单不处于待支付状态"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法支付,订单不处于待支付状态"); - } - - outRechargeOrderService.hltUnionCardPay(userCard.getId(), order.getId()); - - return ResponseMsgUtil.success(outRechargeOrderService.findByOrderId(body.getLong("orderId"))); - } catch (Exception e) { - log.error("hltUnionCardPay error!", e); - return ResponseMsgUtil.exception(e); - } - } - - @RequestMapping(value="/orderToGoldPay",method = RequestMethod.POST) - @ResponseBody - @ApiOperation(value = "订单支付发起金币支付") - public ResponseData orderToGoldPay(@RequestBody String reqBodyStr,HttpServletRequest request) { - try { - // 用户 - SessionObject sessionObject = userCenter.getSessionObject(request); - HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); - - if (StringUtils.isBlank(reqBodyStr)) { - log.error("orderToPay error!", "参数错误"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); - } - JSONObject jsonObject = JSONObject.parseObject(reqBodyStr); - Long orderId = jsonObject.getLong("orderId"); - String password = jsonObject.getString("password"); - - if (orderId == null) { - log.error("orderToPay error!", "参数错误"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); - } - - // 查询用户支付密码 - HighUserPayPassword userPayPassword = highUserPayPasswordService.getDetailByUser(userInfoModel.getHighUser().getId()); - if (userPayPassword == null) { - log.error("orderToPay error!", "未设置支付密码"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_SET_USER_PAY_PWD, ""); - } - if (StringUtils.isBlank(password)) { - log.error("orderToPay error!", "未输入支付密码"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_ENTER_USER_PAY_PWD, ""); - } - // 校验支付密码是否一直 - if (!AESEncodeUtil.aesEncrypt(password).equals(userPayPassword.getPassword())) { - log.error("orderToPay error!", ""); - throw ErrorHelp.genException(SysCode.System, ErrorCode.USER_PAY_PWD_ERROR, ""); - } - - // 订单 - OutRechargeOrder order = outRechargeOrderService.findByOrderId(orderId); - if (order == null) { - log.error("hltUnionCardPay error!", "未找到订单信息"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到订单信息"); - } - - // 订单状态 : 1.待支付 2.已支付 3.已完成 4.已退款 5.已取消 - if (order.getStatus() != 1) { - log.error("hltUnionCardPay error!", "无法支付,订单不处于待支付状态"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法支付,订单不处于待支付状态"); - } - - outRechargeOrderService.goldPayOrder(userInfoModel.getHighUser().getId(), order.getId()); - - if (order.getRechargeType() == 1) { - JSONObject object = outRechargeOrderService.getMobile(order.getRechargeContent() , order.getOrderPrice().intValue() , order.getOrderNo() , order.getRechargeType()); - if (object.getInteger("code") != 200) { - order.setRechargeStatus(1); - order.setStatus(2); - order.setPayType(3); - order.setPayTime(new Date()); // 支付时间 - order.setAbnormalMsg(object.getString("message")); - outRechargeOrderService.updateOrder(order); - } - } - - return ResponseMsgUtil.success("充值成功"); - } catch (Exception e) { - log.error("orderToPay error!", e); - return ResponseMsgUtil.exception(e); - } - } - - - - - @RequestMapping(value="/orderToUnionPay",method = RequestMethod.POST) - @ResponseBody - @ApiOperation(value = "订单支付发起银联支付") - public ResponseData orderToUnionPay(@RequestBody String reqBodyStr,HttpServletRequest request) { - try { - // 用户 - SessionObject sessionObject = userCenter.getSessionObject(request); - HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); - - if (StringUtils.isBlank(reqBodyStr)) { - log.error("orderToPay error!", "参数错误"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); - } - JSONObject jsonObject = JSONObject.parseObject(reqBodyStr); - Long orderId = jsonObject.getLong("orderId"); - - if (orderId == null) { - log.error("orderToPay error!", "参数错误"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); - } - // 订单 - OutRechargeOrder order = outRechargeOrderService.findByOrderId(orderId); - if (order == null) { - log.error("hltUnionCardPay error!", "未找到订单信息"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到订单信息"); - } - - // 订单状态 : 1.待支付 2.已支付 3.已完成 4.已退款 5.已取消 - if (order.getStatus() != 1) { - log.error("hltUnionCardPay error!", "无法支付,订单不处于待支付状态"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法支付,订单不处于待支付状态"); - } - - return ResponseMsgUtil.success(unionPayConfig.upPreOrder(UnionPayConfig.MER_ID2, UnionPayConfig.TERM_ID2, order.getOrderNo(), order.getPayPrice(), "话费充值", CommonSysConst.getSysConfig().getUnionPayTelNotifyUrl(), request)); - - } catch (Exception e) { - log.error("orderToPay error!", e); - return ResponseMsgUtil.exception(e); - } - } - - - @RequestMapping(value = "/wxProfitsharing", method = RequestMethod.GET) - @ResponseBody - @ApiOperation(value = "分账") - public ResponseData wxProfitsharing() { - try { - HighOrder order = highOrderService.getOrderByOrderNo("20211019173044475879505"); - BigDecimal rake = new BigDecimal("0.01"); - // 计算微信收取的手续费 支付金额 * 0.002 注:如果与两个相邻数字的距离相等,则为上舍入的舍入模式。 - BigDecimal wxHandlingFee = order.getPayPrice().multiply(new BigDecimal("0.002")).setScale(2,BigDecimal.ROUND_HALF_DOWN); - BigDecimal price = order.getPayPrice().subtract(wxHandlingFee); - - Map param = new LinkedHashMap<>(); - param.put("appid", "wx637bd6f7314daa46"); - param.put("mch_id", "1289663601"); - param.put("sub_mch_id" , "1609882817"); // 个体户黎杨珍 - param.put("transaction_id" , order.getPaySerialNo()); - param.put("out_order_no" , order.getOrderNo()); - param.put("nonce_str" , WxUtils.makeNonStr()); - - // 计算分账金额 手续费后的价格 * 0.01 注:如果与两个相邻数字的距离相等,则为上舍入的舍入模式。 - BigDecimal porofitSharingAmount = price.multiply(rake).setScale(2,BigDecimal.ROUND_DOWN); - - List> receiversList = new ArrayList<>(); - Map receiversMap = new LinkedHashMap<>(); - receiversMap.put("type", "MERCHANT_ID"); - receiversMap.put("account", "1603942866"); - receiversMap.put("amount", porofitSharingAmount.multiply(new BigDecimal("100")).intValue()); - receiversMap.put("description", "分给商户【惠昕石化】"); - receiversList.add(receiversMap); - param.put("receivers" , JSONObject.toJSONString(receiversList)); - String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); - param.put("sign" , signStr); - String resultXmL = this.doRefundRequest(param.get("mch_id"),null, WxUtils.mapToXml(param)); - - // 请求分账返回的结果 - ResultProfitSharing resultProfitSharing = XmlUtil.getObjectFromXML(resultXmL, ResultProfitSharing.class); - - HighProfitSharingRecord sharingRecord = new HighProfitSharingRecord(); - sharingRecord.setOutOrderNo(resultProfitSharing.getOut_order_no()); - sharingRecord.setTransactionId(resultProfitSharing.getTransaction_id()); - sharingRecord.setOrderId(resultProfitSharing.getOrder_id()); - sharingRecord.setStatus(resultProfitSharing.getResult_code()); - sharingRecord.setPrice(porofitSharingAmount); - sharingRecord.setCreateTime(new Date()); - sharingRecord.setContent(resultXmL); - highProfitSharingRecordService.insert(sharingRecord); - - return ResponseMsgUtil.success("操作成功"); - - } catch (Exception e) { - log.error("CmsContentController --> getCorporateAdvertising() error!", e); - return ResponseMsgUtil.success(e); - } - } - - @RequestMapping(value = "/wxEndProfitsharing", method = RequestMethod.GET) - @ResponseBody - @ApiOperation(value = "完结分账") - public ResponseData wxEndProfitsharing(String transaction_id,String out_order_no, BigDecimal amount) { - try { - - HighOrder orderNo = highOrderService.getOrderByOrderNo("HF2021101812025050304"); - Map param = new LinkedHashMap<>(); - 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" , orderNo.getPaySerialNo()); - param.put("out_order_no" , orderNo.getOrderNo()); - param.put("description" , "系统自动完结分账"); - String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); - param.put("sign" , signStr); - - String resultXmL = this.doRefundRequest2(param.get("mch_id"),"https://api.mch.weixin.qq.com/secapi/pay/profitsharingfinish", WxUtils.mapToXml(param)); - // 请求分账返回的结果 - ResultProfitSharing resultProfitSharing = XmlUtil.getObjectFromXML(resultXmL, ResultProfitSharing.class); - return ResponseMsgUtil.success(resultXmL); - - } catch (Exception e) { - log.error("CmsContentController --> getCorporateAdvertising() error!", e); - return ResponseMsgUtil.success(e); - } - } - - @RequestMapping(value = "/wxSelectProfitsharing", method = RequestMethod.GET) - @ResponseBody - @ApiOperation(value = "查询剩余分账金额") - public ResponseData wxSelectProfitsharing(String transaction_id,String out_order_no, BigDecimal amount) { - try { - Map param = new LinkedHashMap<>(); - param.put("mch_id", "1289663601"); - //param.put("sub_mch_id" , "1609882817"); // 个体户黎杨珍 - param.put("transaction_id" , "4200001175202108102870717911"); - ///param.put("out_order_no" , String.valueOf(new Date().getTime())); - param.put("nonce_str" , WxUtils.makeNonStr()); - String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); - param.put("sign", signStr); - String unifiedXmL = WxUtils.mapToXml(param); - return ResponseMsgUtil.success(HttpReqUtil.HttpsDefaultExecute("POST", "https://api.mch.weixin.qq.com/pay/profitsharingorderamountquery", null, unifiedXmL, null)); - - } catch (Exception e) { - log.error("CmsContentController --> getCorporateAdvertising() error!", e); - return ResponseMsgUtil.success(e); - } - } - - public String doRefundRequest(String mchId, String url, String data) throws Exception { - - //小程序退款需要调用双向证书的认证 - CloseableHttpClient httpClient = goodsOrderService.readCertificate(mchId); - try { - HttpPost httpost = new HttpPost("https://api.mch.weixin.qq.com/secapi/pay/profitsharing"); // 设置响应头信息 - 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(); - } - } - - public String doRefundRequest2(String mchId, String url, String data) throws Exception { - - //小程序退款需要调用双向证书的认证 - CloseableHttpClient httpClient = goodsOrderService.readCertificate(mchId); - try { - HttpPost httpost = new HttpPost(url); // 设置响应头信息 - 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(); - } - } +// +// @RequestMapping(value="/addOrder",method = RequestMethod.POST) +// @ResponseBody +// @ApiOperation(value = "增加订单") +// public ResponseData addOrder(@RequestBody OutRechargeOrder outRechargeOrder, HttpServletRequest request) { +// try { +// +// // 用户 +// SessionObject sessionObject = userCenter.getSessionObject(request); +// HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); +// if (StringUtils.isBlank(outRechargeOrder.getRechargeContent()) || +// outRechargeOrder.getPayPrice() == null || +// outRechargeOrder.getObjectId() == null || +// outRechargeOrder.getOrderPrice() == null +// ) { +// log.error("addOrder error!"); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); +// } +// +// if (!secConfigService.isConfig("RECHARGE" , "1")) { +// log.error("addOrder error!"); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.RECHARGE_CLOSE, ""); +// } +// +// String remarks = ""; +// // 支付类型 1.微信支付 +// outRechargeOrder.setPayType(1); +// // 判断充值模式:1 电信 2. 移动 3. 联通 +// // 拼接内容 +// remarks = outRechargeOrder.getRechargeContent() + "充值" + outRechargeOrder.getOrderPrice() + "元"; +// +// HighDiscountUserRel highDiscountUserRel = null; +// if (outRechargeOrder.getMemDiscountId() != null) { +// // 卡优惠券信息 +// highDiscountUserRel = highDiscountUserRelService.getRelById(outRechargeOrder.getMemDiscountId()); +// if (highDiscountUserRel == null || highDiscountUserRel.getStatus() != 1) { +// log.error("HighOrderController --> addOrder() error!", "优惠券状态错误"); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券状态错误"); +// } +// if (!highDiscountUserRel.getHighDiscount().getUseScope().equals(DiscountUseScope.type1.getType()) +// && !highDiscountUserRel.getHighDiscount().getUseScope().equals(DiscountUseScope.type3.getType())) { +// log.error("HighOrderController --> addOrder() error!", "无法使用此优惠券"); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法使用此优惠券"); +// } +// } +// +// // 优惠券抵扣 +// if (highDiscountUserRel != null) { +// outRechargeOrder.setMemDiscountName(highDiscountUserRel.getHighDiscount().getDiscountName()); +// +// // 卡卷类型 1:满减 2:抵扣 3:折扣 +// if (highDiscountUserRel.getHighDiscount().getDiscountType() == 1) { +// // 如果订单总额 小于 满减价格 +// if (outRechargeOrder.getOrderPrice().compareTo(highDiscountUserRel.getHighDiscount().getDiscountCondition()) > 1) { +// log.error("HighOrderController --> addOrder() error!", "订单未达到满减额度"); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.UN_MEMBER_ERROR, "订单未达到"+highDiscountUserRel.getHighDiscount().getDiscountCondition()+"元,无法使用此优惠券"); +// } +// // 订单总额 - 满减额度 +// BigDecimal payPrice = outRechargeOrder.getOrderPrice().subtract(highDiscountUserRel.getHighDiscount().getDiscountPrice()); +// +// outRechargeOrder.setDeductionPrice(highDiscountUserRel.getHighDiscount().getDiscountPrice()); +// // 如果总额小于0 +// if (payPrice.compareTo(new BigDecimal("0")) == -1) { +// outRechargeOrder.setPayPrice(new BigDecimal("0")); +// } else { +// outRechargeOrder.setPayPrice(payPrice); +// } +// } +// +// // 卡卷类型 1:满减 2:抵扣 3:折扣 +// if (highDiscountUserRel.getHighDiscount().getDiscountType() == 2) { +// // 订单总额 - 满减额度 +// BigDecimal payPrice = outRechargeOrder.getOrderPrice().subtract(highDiscountUserRel.getHighDiscount().getDiscountPrice()); +// outRechargeOrder.setDeductionPrice(highDiscountUserRel.getHighDiscount().getDiscountPrice()); +// +// // 如果总额小于0 +// if (payPrice.compareTo(new BigDecimal("0")) == -1) { +// outRechargeOrder.setPayPrice(new BigDecimal("0")); +// } else { +// outRechargeOrder.setPayPrice(payPrice); +// } +// } +// +// // 卡卷类型 1:满减 2:抵扣 3:折扣 +// if (highDiscountUserRel.getHighDiscount().getDiscountType() == 3) { +// BigDecimal discountPrice = highDiscountUserRel.getHighDiscount().getDiscountPrice(); +// // 订单总额 * 折扣 +// BigDecimal payPrice = outRechargeOrder.getOrderPrice().multiply(discountPrice); +// outRechargeOrder.setDeductionPrice(outRechargeOrder.getOrderPrice().subtract(payPrice)); +// outRechargeOrder.setPayPrice(payPrice); +// } +// } +// +// OutRechargePrice outRechargePrice = outRechargePriceService.findById(outRechargeOrder.getObjectId().longValue()); +// +// HighUserCard highUserCard = highUserCardService.getUserHtlCardNo(userInfoModel.getHighUser().getId()); +// if (highUserCard != null) { +// outRechargeOrder.setIdCard(highUserCard.getCardNo()); +// } +// outRechargeOrder.setRemarks(remarks); +// outRechargeOrder.setRechargeName(remarks); +// outRechargeOrder.setOrderNo("CZ" + DateUtil.date2String(new Date(),"yyyyMMddHHmmss") + IDGenerator.nextId(5)); +// outRechargeOrder.setUserId(userInfoModel.getHighUser().getId()); +// outRechargeOrder.setUserName(userInfoModel.getHighUser().getName()); +// outRechargeOrder.setRechargeType(outRechargePrice.getRechargeType()); +// outRechargeOrder.setUserPhone(userInfoModel.getHighUser().getPhone()); +// +// outRechargeOrder.setCreateTimed(new Date()); +// outRechargeOrder.setStatus(1); +// outRechargeOrderService.insertOrder(outRechargeOrder); +// return ResponseMsgUtil.success(outRechargeOrder); +// +// } catch (Exception e) { +// log.error("HighOrderController -> addOrder() error!",e); +// return ResponseMsgUtil.exception(e); +// } +// } +// +// +// @RequestMapping(value = "/getOrderById", method = RequestMethod.GET) +// @ResponseBody +// @ApiOperation(value = "根据id查询订单详情") +// public ResponseData getOrderById(@RequestParam(name = "orderId", required = true) Long orderId) { +// try { +// +// return ResponseMsgUtil.success(outRechargeOrderService.findByOrderId(orderId)); +// +// } catch (Exception e) { +// log.error("HighOrderController --> getOrderById() error!", e); +// return ResponseMsgUtil.exception(e); +// } +// } +// +// @RequestMapping(value = "/cancelOrder", method = RequestMethod.GET) +// @ResponseBody +// @ApiOperation(value = "取消订单") +// public ResponseData cancelOrder(@RequestParam(name = "orderId", required = true) Long orderId) { +// try { +// +// OutRechargeOrder outRechargeOrder = outRechargeOrderService.findByOrderId(orderId); +// +// if (outRechargeOrder.getStatus() == 1) { +// outRechargeOrderService.cancelOrder(orderId); +// } else { +// log.error("orderToPay error!"); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.STATUS_ERROR, ""); +// } +// +// return ResponseMsgUtil.success("操作成功"); +// +// } catch (Exception e) { +// log.error("HighOrderController --> cancelOrder() error!", e); +// return ResponseMsgUtil.exception(e); +// } +// } +// +// @RequestMapping(value = "/getUserOrderList", method = RequestMethod.GET) +// @ResponseBody +// @ApiOperation(value = "获取用户订单") +// public ResponseData getUserOrderList( +// @RequestParam(name = "status", required = false) Integer status, +// @RequestParam(name = "orderNo", required = false) String orderNo, +// @RequestParam(name = "rechargeModel", required = false) String rechargeModel, +// @RequestParam(name = "pageNum", required = true) Integer pageNum, +// @RequestParam(name = "pageSize", required = true) Integer pageSize, +// HttpServletRequest request) { +// try { +// +// // 用户 +// SessionObject sessionObject = userCenter.getSessionObject(request); +// HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); +// +// Map map = new HashMap<>(); +// map.put("userId", userInfoModel.getHighUser().getId().toString()); +// if (status != null) { +// map.put("status", status.toString()); +// } +// if (StringUtils.isNotBlank(orderNo)) { +// map.put("orderNo", orderNo); +// } +// if (StringUtils.isNotBlank(rechargeModel)) { +// map.put("rechargeModel", rechargeModel); +// } +// +// PageHelper.startPage(pageNum,pageSize); +// return ResponseMsgUtil.success(new PageInfo<>(outRechargeOrderService.getListRechargeOrder(map))); +// +// } catch (Exception e) { +// log.error("HighOrderController --> getUserOrderList() error!", e); +// return ResponseMsgUtil.exception(e); +// } +// } +// +// +// @RequestMapping(value="/orderToPay",method = RequestMethod.POST) +// @ResponseBody +// @ApiOperation(value = "订单支付发起支付") +// public ResponseData orderToPay(@RequestBody String reqBodyStr) { +// try { +// if (StringUtils.isBlank(reqBodyStr)) { +// log.error("orderToPay error!", "参数错误"); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); +// } +// JSONObject jsonObject = JSONObject.parseObject(reqBodyStr); +// Long orderId = jsonObject.getLong("orderId"); +// Integer openIdType = jsonObject.getInteger("openIdType"); // openId类型 1:小程序 2:公众号 +// String openId = jsonObject.getString("openId"); // openId +// if (orderId == null || StringUtils.isBlank(openId)) { +// log.error("orderToPay error!", "参数错误"); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); +// } +// +// // 订单 +// 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() != 1) { +// log.error("orderToPay error!", "无法支付,订单不处于待支付状态"); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法支付,订单不处于待支付状态"); +// } +// +// Map map = new HashMap<>(); +// map.put("orderNo", order.getOrderNo()); +// map.put("payPrice", order.getPayPrice()); +// map.put("orderScene", "RECHARGE_ORDER"); +// map.put("body","充值话费"); +// map.put("subject","充值话费"); +// +// //微信支付 +// String nonce_str = MD5Util.MD5Encode(String.valueOf(ThreadLocalRandom.current().nextInt(10000)), "UTF-8"); +// int total_fee = MathUtils.objectConvertBigDecimal(map.get("payPrice")).multiply(new BigDecimal("100")).intValue(); +// WeChatPayReqInfo weChatPayReqInfo = new WeChatPayReqInfo(); +// weChatPayReqInfo.setAppid(SysConst.getSysConfig().getWxMchAppId()); //公众号id +// weChatPayReqInfo.setMch_id(SysConst.getSysConfig().getWxMchId()); //商户号 +// if (openIdType != null && openIdType.equals(2)) { +// weChatPayReqInfo.setSub_appid("wxa075e8509802f826"); //商户号公众号 +// } else { +// weChatPayReqInfo.setSub_appid(SysConst.getSysConfig().getWxSubAppId());//小程序 +// } +// weChatPayReqInfo.setSub_mch_id("1614670195"); +// weChatPayReqInfo.setSub_openid(openId); +// weChatPayReqInfo.setNonce_str(nonce_str); //随机字符串 +// weChatPayReqInfo.setBody(map.get("body").toString()); //商品描述 +// weChatPayReqInfo.setOut_trade_no(map.get("orderNo").toString()); //商户订单号 +// weChatPayReqInfo.setTotal_fee(total_fee); //总金额 +// weChatPayReqInfo.setSpbill_create_ip("139.159.177.244"); //终端ip +// weChatPayReqInfo.setNotify_url(SysConst.getSysConfig().getNotifyUrl()); //通知url +// weChatPayReqInfo.setTrade_type("JSAPI"); //交易类型 +// weChatPayReqInfo.setAttach(map.get("orderScene").toString()); +// weChatPayReqInfo.setProfit_sharing("N"); +// //附加数据,区分订单类型 +// Map payMap = new HashMap<>(); +// +// payMap.put("app_id", weChatPayReqInfo.getSub_appid()); +// payMap.put("api_key",SysConst.getSysConfig().getWxApiKey()); +// payMap.put("unified_order_url",SysConst.getSysConfig().getWxUnifiedOrderUrl()); +// SortedMap sortedMap = wechatPayUtil.goWechatPay(weChatPayReqInfo,payMap); +// return ResponseMsgUtil.success(sortedMap); +// } catch (Exception e) { +// log.error("orderToPay error!", e); +// return ResponseMsgUtil.exception(e); +// } +// } +// +// @RequestMapping(value="/hltUnionCardPay",method = RequestMethod.POST) +// @ResponseBody +// @ApiOperation(value = "工会卡支付") +// public ResponseData hltUnionCardPay(@RequestBody JSONObject body,HttpServletRequest request) { +// try { +// // 用户 +// SessionObject sessionObject = userCenter.getSessionObject(request); +// HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); +// +// if (body == null +// || body.getLong("orderId") == null +// || StringUtils.isBlank(body.getString("cardNo")) +// ) { +// log.error("orderToPay error!", "参数错误"); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); +// } +// +// // 查询用户支付密码 +// HighUserPayPassword userPayPassword = highUserPayPasswordService.getDetailByUser(userInfoModel.getHighUser().getId()); +// if (userPayPassword == null) { +// log.error("orderToPay error!", "未设置支付密码"); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_SET_USER_PAY_PWD, ""); +// } +// if (StringUtils.isBlank(body.getString("password"))) { +// log.error("hltUnionCardPay error!", "未输入支付密码"); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_ENTER_USER_PAY_PWD, ""); +// } +// // 校验支付密码是否一直 +// if (!AESEncodeUtil.aesEncrypt(body.getString("password")).equals(userPayPassword.getPassword())) { +// log.error("hltUnionCardPay error!", ""); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.USER_PAY_PWD_ERROR, ""); +// } +// +// // 查询用户与卡号的关系 +// HighUserCard userCard = highUserCardService.getDetailByUserCardNo(userInfoModel.getHighUser().getId(), body.getString("cardNo")); +// if (userCard == null) { +// log.error("hltUnionCardPay() ERROR", "未绑定卡号"); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未绑定卡号"); +// } +// +// // 订单 +// OutRechargeOrder order = outRechargeOrderService.findByOrderId(body.getLong("orderId")); +// if (order == null) { +// log.error("hltUnionCardPay error!", "未找到订单信息"); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到订单信息"); +// } +// +// // 订单状态 : 1.待支付 2.已支付 3.已完成 4.已退款 5.已取消 +// if (order.getStatus() != 1) { +// log.error("hltUnionCardPay error!", "无法支付,订单不处于待支付状态"); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法支付,订单不处于待支付状态"); +// } +// +// outRechargeOrderService.hltUnionCardPay(userCard.getId(), order.getId()); +// +// return ResponseMsgUtil.success(outRechargeOrderService.findByOrderId(body.getLong("orderId"))); +// } catch (Exception e) { +// log.error("hltUnionCardPay error!", e); +// return ResponseMsgUtil.exception(e); +// } +// } +// +// @RequestMapping(value="/orderToGoldPay",method = RequestMethod.POST) +// @ResponseBody +// @ApiOperation(value = "订单支付发起金币支付") +// public ResponseData orderToGoldPay(@RequestBody String reqBodyStr,HttpServletRequest request) { +// try { +// // 用户 +// SessionObject sessionObject = userCenter.getSessionObject(request); +// HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); +// +// if (StringUtils.isBlank(reqBodyStr)) { +// log.error("orderToPay error!", "参数错误"); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); +// } +// JSONObject jsonObject = JSONObject.parseObject(reqBodyStr); +// Long orderId = jsonObject.getLong("orderId"); +// String password = jsonObject.getString("password"); +// +// if (orderId == null) { +// log.error("orderToPay error!", "参数错误"); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); +// } +// +// // 查询用户支付密码 +// HighUserPayPassword userPayPassword = highUserPayPasswordService.getDetailByUser(userInfoModel.getHighUser().getId()); +// if (userPayPassword == null) { +// log.error("orderToPay error!", "未设置支付密码"); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_SET_USER_PAY_PWD, ""); +// } +// if (StringUtils.isBlank(password)) { +// log.error("orderToPay error!", "未输入支付密码"); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_ENTER_USER_PAY_PWD, ""); +// } +// // 校验支付密码是否一直 +// if (!AESEncodeUtil.aesEncrypt(password).equals(userPayPassword.getPassword())) { +// log.error("orderToPay error!", ""); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.USER_PAY_PWD_ERROR, ""); +// } +// +// // 订单 +// OutRechargeOrder order = outRechargeOrderService.findByOrderId(orderId); +// if (order == null) { +// log.error("hltUnionCardPay error!", "未找到订单信息"); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到订单信息"); +// } +// +// // 订单状态 : 1.待支付 2.已支付 3.已完成 4.已退款 5.已取消 +// if (order.getStatus() != 1) { +// log.error("hltUnionCardPay error!", "无法支付,订单不处于待支付状态"); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法支付,订单不处于待支付状态"); +// } +// +// outRechargeOrderService.goldPayOrder(userInfoModel.getHighUser().getId(), order.getId()); +// +// if (order.getRechargeType() == 1) { +// JSONObject object = outRechargeOrderService.getMobile(order.getRechargeContent() , order.getOrderPrice().intValue() , order.getOrderNo() , order.getRechargeType()); +// if (object.getInteger("code") != 200) { +// order.setRechargeStatus(1); +// order.setStatus(2); +// order.setPayType(3); +// order.setPayTime(new Date()); // 支付时间 +// order.setAbnormalMsg(object.getString("message")); +// outRechargeOrderService.updateOrder(order); +// } +// } +// +// return ResponseMsgUtil.success("充值成功"); +// } catch (Exception e) { +// log.error("orderToPay error!", e); +// return ResponseMsgUtil.exception(e); +// } +// } +// +// +// +// +// @RequestMapping(value="/orderToUnionPay",method = RequestMethod.POST) +// @ResponseBody +// @ApiOperation(value = "订单支付发起银联支付") +// public ResponseData orderToUnionPay(@RequestBody String reqBodyStr,HttpServletRequest request) { +// try { +// // 用户 +// SessionObject sessionObject = userCenter.getSessionObject(request); +// HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); +// +// if (StringUtils.isBlank(reqBodyStr)) { +// log.error("orderToPay error!", "参数错误"); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); +// } +// JSONObject jsonObject = JSONObject.parseObject(reqBodyStr); +// Long orderId = jsonObject.getLong("orderId"); +// +// if (orderId == null) { +// log.error("orderToPay error!", "参数错误"); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); +// } +// // 订单 +// OutRechargeOrder order = outRechargeOrderService.findByOrderId(orderId); +// if (order == null) { +// log.error("hltUnionCardPay error!", "未找到订单信息"); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到订单信息"); +// } +// +// // 订单状态 : 1.待支付 2.已支付 3.已完成 4.已退款 5.已取消 +// if (order.getStatus() != 1) { +// log.error("hltUnionCardPay error!", "无法支付,订单不处于待支付状态"); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法支付,订单不处于待支付状态"); +// } +// +// return ResponseMsgUtil.success(unionPayConfig.upPreOrder(UnionPayConfig.MER_ID2, UnionPayConfig.TERM_ID2, order.getOrderNo(), order.getPayPrice(), "话费充值", CommonSysConst.getSysConfig().getUnionPayTelNotifyUrl(), request)); +// +// } catch (Exception e) { +// log.error("orderToPay error!", e); +// return ResponseMsgUtil.exception(e); +// } +// } +// +// +// @RequestMapping(value = "/wxProfitsharing", method = RequestMethod.GET) +// @ResponseBody +// @ApiOperation(value = "分账") +// public ResponseData wxProfitsharing() { +// try { +// HighOrder order = highOrderService.getOrderByOrderNo("20211019173044475879505"); +// BigDecimal rake = new BigDecimal("0.01"); +// // 计算微信收取的手续费 支付金额 * 0.002 注:如果与两个相邻数字的距离相等,则为上舍入的舍入模式。 +// BigDecimal wxHandlingFee = order.getPayPrice().multiply(new BigDecimal("0.002")).setScale(2,BigDecimal.ROUND_HALF_DOWN); +// BigDecimal price = order.getPayPrice().subtract(wxHandlingFee); +// +// Map param = new LinkedHashMap<>(); +// param.put("appid", "wx637bd6f7314daa46"); +// param.put("mch_id", "1289663601"); +// param.put("sub_mch_id" , "1609882817"); // 个体户黎杨珍 +// param.put("transaction_id" , order.getPaySerialNo()); +// param.put("out_order_no" , order.getOrderNo()); +// param.put("nonce_str" , WxUtils.makeNonStr()); +// +// // 计算分账金额 手续费后的价格 * 0.01 注:如果与两个相邻数字的距离相等,则为上舍入的舍入模式。 +// BigDecimal porofitSharingAmount = price.multiply(rake).setScale(2,BigDecimal.ROUND_DOWN); +// +// List> receiversList = new ArrayList<>(); +// Map receiversMap = new LinkedHashMap<>(); +// receiversMap.put("type", "MERCHANT_ID"); +// receiversMap.put("account", "1603942866"); +// receiversMap.put("amount", porofitSharingAmount.multiply(new BigDecimal("100")).intValue()); +// receiversMap.put("description", "分给商户【惠昕石化】"); +// receiversList.add(receiversMap); +// param.put("receivers" , JSONObject.toJSONString(receiversList)); +// String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); +// param.put("sign" , signStr); +// String resultXmL = this.doRefundRequest(param.get("mch_id"),null, WxUtils.mapToXml(param)); +// +// // 请求分账返回的结果 +// ResultProfitSharing resultProfitSharing = XmlUtil.getObjectFromXML(resultXmL, ResultProfitSharing.class); +// +// HighProfitSharingRecord sharingRecord = new HighProfitSharingRecord(); +// sharingRecord.setOutOrderNo(resultProfitSharing.getOut_order_no()); +// sharingRecord.setTransactionId(resultProfitSharing.getTransaction_id()); +// sharingRecord.setOrderId(resultProfitSharing.getOrder_id()); +// sharingRecord.setStatus(resultProfitSharing.getResult_code()); +// sharingRecord.setPrice(porofitSharingAmount); +// sharingRecord.setCreateTime(new Date()); +// sharingRecord.setContent(resultXmL); +// highProfitSharingRecordService.insert(sharingRecord); +// +// return ResponseMsgUtil.success("操作成功"); +// +// } catch (Exception e) { +// log.error("CmsContentController --> getCorporateAdvertising() error!", e); +// return ResponseMsgUtil.success(e); +// } +// } +// +// @RequestMapping(value = "/wxEndProfitsharing", method = RequestMethod.GET) +// @ResponseBody +// @ApiOperation(value = "完结分账") +// public ResponseData wxEndProfitsharing(String transaction_id,String out_order_no, BigDecimal amount) { +// try { +// +// HighOrder orderNo = highOrderService.getOrderByOrderNo("HF2021101812025050304"); +// Map param = new LinkedHashMap<>(); +// 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" , orderNo.getPaySerialNo()); +// param.put("out_order_no" , orderNo.getOrderNo()); +// param.put("description" , "系统自动完结分账"); +// String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); +// param.put("sign" , signStr); +// +// String resultXmL = this.doRefundRequest2(param.get("mch_id"),"https://api.mch.weixin.qq.com/secapi/pay/profitsharingfinish", WxUtils.mapToXml(param)); +// // 请求分账返回的结果 +// ResultProfitSharing resultProfitSharing = XmlUtil.getObjectFromXML(resultXmL, ResultProfitSharing.class); +// return ResponseMsgUtil.success(resultXmL); +// +// } catch (Exception e) { +// log.error("CmsContentController --> getCorporateAdvertising() error!", e); +// return ResponseMsgUtil.success(e); +// } +// } +// +// @RequestMapping(value = "/wxSelectProfitsharing", method = RequestMethod.GET) +// @ResponseBody +// @ApiOperation(value = "查询剩余分账金额") +// public ResponseData wxSelectProfitsharing(String transaction_id,String out_order_no, BigDecimal amount) { +// try { +// Map param = new LinkedHashMap<>(); +// param.put("mch_id", "1289663601"); +// //param.put("sub_mch_id" , "1609882817"); // 个体户黎杨珍 +// param.put("transaction_id" , "4200001175202108102870717911"); +// ///param.put("out_order_no" , String.valueOf(new Date().getTime())); +// param.put("nonce_str" , WxUtils.makeNonStr()); +// String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); +// param.put("sign", signStr); +// String unifiedXmL = WxUtils.mapToXml(param); +// return ResponseMsgUtil.success(HttpReqUtil.HttpsDefaultExecute("POST", "https://api.mch.weixin.qq.com/pay/profitsharingorderamountquery", null, unifiedXmL, null)); +// +// } catch (Exception e) { +// log.error("CmsContentController --> getCorporateAdvertising() error!", e); +// return ResponseMsgUtil.success(e); +// } +// } +// +// public String doRefundRequest(String mchId, String url, String data) throws Exception { +// +// //小程序退款需要调用双向证书的认证 +// CloseableHttpClient httpClient = goodsOrderService.readCertificate(mchId); +// try { +// HttpPost httpost = new HttpPost("https://api.mch.weixin.qq.com/secapi/pay/profitsharing"); // 设置响应头信息 +// 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(); +// } +// } +// +// public String doRefundRequest2(String mchId, String url, String data) throws Exception { +// +// //小程序退款需要调用双向证书的认证 +// CloseableHttpClient httpClient = goodsOrderService.readCertificate(mchId); +// try { +// HttpPost httpost = new HttpPost(url); // 设置响应头信息 +// 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-cweb/src/main/java/com/cweb/controller/SendSmsController.java b/hai-cweb/src/main/java/com/cweb/controller/SendSmsController.java index d3ec31fc..018de4b2 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/SendSmsController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/SendSmsController.java @@ -53,11 +53,7 @@ public class SendSmsController { smsMsgId = MessageConfig.HWMSG_ID5; break; default : - smsMsgId = "错误"; - } - - if (HWMSG > 3) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "暂无当前模版"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "暂无当前模版"); } return ResponseMsgUtil.success(messageConfig.sendSmsCodeHw(phone , smsMsgId)); 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 4429b0d1..e8f463e5 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 @@ -76,248 +76,248 @@ public class CzOrderController { @Resource private OutRechargeOrderRecordService rechargeOrderRecordService; - @RequestMapping(value = "/rechargeCallback", method = RequestMethod.POST) - @ApiOperation(value = "话费充值回调") - @ResponseBody - public void rechargeCallback(@RequestBody String reqBodyStr, HttpServletRequest request, HttpServletResponse response) { - try { - - - JSONObject dataObject = JSONObject.parseObject(reqBodyStr, JSONObject.class); - - HighGasOrderRefund highGasOrderRefund = new HighGasOrderRefund(); - highGasOrderRefund.setCreateTime(new Date()); - highGasOrderRefund.setReturnContent(String.valueOf(dataObject)); - - highGasOrderRefundMapper.insert(highGasOrderRefund); - - if (dataObject.getInteger("status") == 3) { - OutRechargeOrder order; - OutRechargeOrderRecord rechargeOrderRecord = rechargeOrderRecordService.findByOrderNo(dataObject.getString("out_order_id")); - if (rechargeOrderRecord == null) { - // 查询订单 - order = outRechargeOrderService.findByOrderNo(dataObject.getString("out_order_id")); - order.setStatus(3); - order.setFinishTime(new Date()); - outRechargeOrderService.updateOrder(order); - } else { - // 查询订单 - order = outRechargeOrderService.findByOrderId(rechargeOrderRecord.getRechargeOrderId()); - order.setStatus(3); - order.setFinishTime(new Date()); - outRechargeOrderService.updateOrder(order); - } - - new Thread(() -> { - HighUser highUser = highUserService.findByUserId(order.getUserId()); - WxMsgConfig.rechargedSuccess( - order.getRechargeName() + "充值成功", - String.valueOf(order.getPayRealPrice()), - order.getOrderNo(), - order.getFinishTime(), - RechargePayType.getNameByType(order.getPayType()), - highUser.getOpenId()); - }).start(); - - } else { - OutRechargeOrderRecord rechargeOrderRecord = rechargeOrderRecordService.findByOrderNo(dataObject.getString("out_order_id")); - if (rechargeOrderRecord == null) { - rechargeOrderRecord = new OutRechargeOrderRecord(); - // 查询订单 - OutRechargeOrder order = outRechargeOrderService.findByOrderNo(dataObject.getString("out_order_id")); - if (order.getStatus() == 2) { - if (order.getRechargeType() == 1) { - String orderNo = "CZ" + DateUtil.date2String(new Date(),"yyyyMMddHHmmss") + IDGenerator.nextId(5); - JSONObject object = outRechargeOrderService.getMobile(order.getRechargeContent() , order.getOrderPrice().intValue() , orderNo , order.getRechargeType()); - if (object.getInteger("code") != 200) { - order.setRechargeStatus(1); - order.setAbnormalMsg(object.getString("message")); - } - outRechargeOrderService.updateOrder(order); - rechargeOrderRecord.setRechargeOrderId(order.getId()); - rechargeOrderRecord.setRechargeOrderNo(orderNo); - rechargeOrderRecord.setCreateTime(new Date()); - rechargeOrderRecord.setStatus(1); - rechargeOrderRecordService.insertOrder(rechargeOrderRecord); - } - } - - } else { - // 查询订单 - OutRechargeOrder order = outRechargeOrderService.findByOrderId(rechargeOrderRecord.getRechargeOrderId()); - if (order.getStatus() == 2) { - orderToRefund(order.getId()); - order.setStatus(5); - outRechargeOrderService.updateOrder(order); - } - } - - } - - response.setCharacterEncoding("UTF-8"); - response.setContentType("text/html;charset=utf-8"); - PrintWriter writer= response.getWriter(); - writer.write("SUCCESS"); - - - } catch (Exception e) { - log.error("WechatPayController --> wechatNotify() error!", e); - } - } - - - public Boolean orderToRefund(Long orderId) { - try { - - OutRechargeOrder order = outRechargeOrderService.findByOrderId(orderId); - - - // 订单状态 : 1.待支付 2.已支付 3.已完成 4.已取消 5.已退款 6:退款中 - if (order.getStatus() != 2) { - log.error("orderToPay error!", "无法退款,订单状态错误!"); - 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 { - log.error("orderToPay error!", "退款失败"); - 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) { - log.error("orderToPay error!", "请求超时"); - 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 { - log.error("orderToPay error!", dataObject.getString("message")); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, dataObject.getString("message")); - } - } - - // 积分退款 - if (order.getPayType() == 3) { - - if (highUserService.findGoldRepeat(3 , order.getId())) { - highUserService.goldHandle(order.getUserId(), order.getPayRealPrice().multiply(BigDecimal.valueOf(100)).intValue(), 1, 3, order.getId()); - }else { - log.error("orderToPay error!", "已有退款记录"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "已有退款记录"); - } - - } - - // 银联退款 - if (order.getPayType() == 4) { - // 订单退款 - JSONObject refund = UnionPayConfig.zwrefund(UnionPayConfig.MER_ID2, UnionPayConfig.TERM_ID2, 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); - } - - if (order.getMemDiscountId() != null) { - HighDiscountUserRel rel = highDiscountUserRelService.getRelById(order.getMemDiscountId()); - if (rel != null) { - rel.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用 - rel.setUseTime(null); - highDiscountUserRelService.updateDiscountUserRel(rel); - - HighDiscountAgentCode code = highDiscountAgentCodeService.getCodeById(rel.getDiscountAgentCodeId()); - code.setStatus(2); - highDiscountAgentCodeService.updateCode(code); - } - } - - new Thread(() -> { - HighUser highUser = highUserService.findByUserId(order.getUserId()); - WxMsgConfig.rechargedFail( - "订单号:" + order.getOrderNo() + "-" + order.getRechargeName(), - String.valueOf(order.getPayRealPrice()), - highUser.getOpenId()); - }).start(); - - return true; - } catch (Exception e) { - log.error("HighOrderController --> getUserOrderList() error!", e); - return false; - } - } - - - 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(); - } - } +// @RequestMapping(value = "/rechargeCallback", method = RequestMethod.POST) +// @ApiOperation(value = "话费充值回调") +// @ResponseBody +// public void rechargeCallback(@RequestBody String reqBodyStr, HttpServletRequest request, HttpServletResponse response) { +// try { +// +// +// JSONObject dataObject = JSONObject.parseObject(reqBodyStr, JSONObject.class); +// +// HighGasOrderRefund highGasOrderRefund = new HighGasOrderRefund(); +// highGasOrderRefund.setCreateTime(new Date()); +// highGasOrderRefund.setReturnContent(String.valueOf(dataObject)); +// +// highGasOrderRefundMapper.insert(highGasOrderRefund); +// +// if (dataObject.getInteger("status") == 3) { +// OutRechargeOrder order; +// OutRechargeOrderRecord rechargeOrderRecord = rechargeOrderRecordService.findByOrderNo(dataObject.getString("out_order_id")); +// if (rechargeOrderRecord == null) { +// // 查询订单 +// order = outRechargeOrderService.findByOrderNo(dataObject.getString("out_order_id")); +// order.setStatus(3); +// order.setFinishTime(new Date()); +// outRechargeOrderService.updateOrder(order); +// } else { +// // 查询订单 +// order = outRechargeOrderService.findByOrderId(rechargeOrderRecord.getRechargeOrderId()); +// order.setStatus(3); +// order.setFinishTime(new Date()); +// outRechargeOrderService.updateOrder(order); +// } +// +// new Thread(() -> { +// HighUser highUser = highUserService.findByUserId(order.getUserId()); +// WxMsgConfig.rechargedSuccess( +// order.getRechargeName() + "充值成功", +// String.valueOf(order.getPayRealPrice()), +// order.getOrderNo(), +// order.getFinishTime(), +// RechargePayType.getNameByType(order.getPayType()), +// highUser.getOpenId()); +// }).start(); +// +// } else { +// OutRechargeOrderRecord rechargeOrderRecord = rechargeOrderRecordService.findByOrderNo(dataObject.getString("out_order_id")); +// if (rechargeOrderRecord == null) { +// rechargeOrderRecord = new OutRechargeOrderRecord(); +// // 查询订单 +// OutRechargeOrder order = outRechargeOrderService.findByOrderNo(dataObject.getString("out_order_id")); +// if (order.getStatus() == 2) { +// if (order.getRechargeType() == 1) { +// String orderNo = "CZ" + DateUtil.date2String(new Date(),"yyyyMMddHHmmss") + IDGenerator.nextId(5); +// JSONObject object = outRechargeOrderService.getMobile(order.getRechargeContent() , order.getOrderPrice().intValue() , orderNo , order.getRechargeType()); +// if (object.getInteger("code") != 200) { +// order.setRechargeStatus(1); +// order.setAbnormalMsg(object.getString("message")); +// } +// outRechargeOrderService.updateOrder(order); +// rechargeOrderRecord.setRechargeOrderId(order.getId()); +// rechargeOrderRecord.setRechargeOrderNo(orderNo); +// rechargeOrderRecord.setCreateTime(new Date()); +// rechargeOrderRecord.setStatus(1); +// rechargeOrderRecordService.insertOrder(rechargeOrderRecord); +// } +// } +// +// } else { +// // 查询订单 +// OutRechargeOrder order = outRechargeOrderService.findByOrderId(rechargeOrderRecord.getRechargeOrderId()); +// if (order.getStatus() == 2) { +// orderToRefund(order.getId()); +// order.setStatus(5); +// outRechargeOrderService.updateOrder(order); +// } +// } +// +// } +// +// response.setCharacterEncoding("UTF-8"); +// response.setContentType("text/html;charset=utf-8"); +// PrintWriter writer= response.getWriter(); +// writer.write("SUCCESS"); +// +// +// } catch (Exception e) { +// log.error("WechatPayController --> wechatNotify() error!", e); +// } +// } +// +// +// public Boolean orderToRefund(Long orderId) { +// try { +// +// OutRechargeOrder order = outRechargeOrderService.findByOrderId(orderId); +// +// +// // 订单状态 : 1.待支付 2.已支付 3.已完成 4.已取消 5.已退款 6:退款中 +// if (order.getStatus() != 2) { +// log.error("orderToPay error!", "无法退款,订单状态错误!"); +// 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 { +//// log.error("orderToPay error!", "退款失败"); +//// 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) { +// log.error("orderToPay error!", "请求超时"); +// 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 { +// log.error("orderToPay error!", dataObject.getString("message")); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, dataObject.getString("message")); +// } +// } +// +// // 积分退款 +// if (order.getPayType() == 3) { +// +// if (highUserService.findGoldRepeat(3 , order.getId())) { +// highUserService.goldHandle(order.getUserId(), order.getPayRealPrice().multiply(BigDecimal.valueOf(100)).intValue(), 1, 3, order.getId()); +// }else { +// log.error("orderToPay error!", "已有退款记录"); +// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "已有退款记录"); +// } +// +// } +// +// // 银联退款 +// if (order.getPayType() == 4) { +// // 订单退款 +// JSONObject refund = UnionPayConfig.zwrefund(UnionPayConfig.MER_ID2, UnionPayConfig.TERM_ID2, 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); +// } +// +// if (order.getMemDiscountId() != null) { +// HighDiscountUserRel rel = highDiscountUserRelService.getRelById(order.getMemDiscountId()); +// if (rel != null) { +// rel.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用 +// rel.setUseTime(null); +// highDiscountUserRelService.updateDiscountUserRel(rel); +// +// HighDiscountAgentCode code = highDiscountAgentCodeService.getCodeById(rel.getDiscountAgentCodeId()); +// code.setStatus(2); +// highDiscountAgentCodeService.updateCode(code); +// } +// } +// +// new Thread(() -> { +// HighUser highUser = highUserService.findByUserId(order.getUserId()); +// WxMsgConfig.rechargedFail( +// "订单号:" + order.getOrderNo() + "-" + order.getRechargeName(), +// String.valueOf(order.getPayRealPrice()), +// highUser.getOpenId()); +// }).start(); +// +// return true; +// } catch (Exception e) { +// log.error("HighOrderController --> getUserOrderList() error!", e); +// return false; +// } +// } +// +// +// 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-cweb/src/main/java/com/cweb/controller/pay/UnionPayController.java b/hai-cweb/src/main/java/com/cweb/controller/pay/UnionPayController.java index 38f60250..d621d2cb 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/pay/UnionPayController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/pay/UnionPayController.java @@ -383,27 +383,27 @@ public class UnionPayController { // 转换成JSON格式 JSONObject body = JSONObject.parseObject(paramsStr.substring(0, paramsStr.length() - 1)); - if (StringUtils.isNotBlank(body.getString("tradetrace"))) { - OutRechargeOrder order = outRechargeOrderService.findByOrderNo(body.getString("tradetrace")); - if (order == null) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到订单信息"); - } - - order.setPaySerialNo(body.getString("wtorderid")); // 支付流水号 - order.setPayRealPrice(order.getPayPrice()); // 实付金额 - - order.setStatus(2); - order.setPayType(4); - order.setPayTime(new Date()); // 支付时间 - if (order.getRechargeType() == 1) { - JSONObject object = outRechargeOrderService.getMobile(order.getRechargeContent() , order.getOrderPrice().intValue() , order.getOrderNo() , order.getRechargeType()); - if (object.getInteger("code") != 200) { - order.setRechargeStatus(1); - order.setAbnormalMsg(object.getString("message")); - } - } - outRechargeOrderService.updateOrder(order); - } +// if (StringUtils.isNotBlank(body.getString("tradetrace"))) { +// OutRechargeOrder order = outRechargeOrderService.findByOrderNo(body.getString("tradetrace")); +// if (order == null) { +// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到订单信息"); +// } +// +// order.setPaySerialNo(body.getString("wtorderid")); // 支付流水号 +// order.setPayRealPrice(order.getPayPrice()); // 实付金额 +// +// order.setStatus(2); +// order.setPayType(4); +// order.setPayTime(new Date()); // 支付时间 +// if (order.getRechargeType() == 1) { +// JSONObject object = outRechargeOrderService.getMobile(order.getRechargeContent() , order.getOrderPrice().intValue() , order.getOrderNo() , order.getRechargeType()); +// if (object.getInteger("code") != 200) { +// order.setRechargeStatus(1); +// order.setAbnormalMsg(object.getString("message")); +// } +// } +// outRechargeOrderService.updateOrder(order); +// } } BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream()); diff --git a/hai-service/src/main/java/com/hai/entity/OutRechargePrice.java b/hai-service/src/main/java/com/hai/entity/OutRechargePrice.java index a6efd2e4..0447fc2f 100644 --- a/hai-service/src/main/java/com/hai/entity/OutRechargePrice.java +++ b/hai-service/src/main/java/com/hai/entity/OutRechargePrice.java @@ -80,7 +80,7 @@ public class OutRechargePrice implements Serializable { private Date updateTime; /** - * 0:删除 1:上线 2:已售空 + * 0:删除 1:上线 2:已售空 3:编辑中 */ private Integer status; @@ -310,4 +310,4 @@ public class OutRechargePrice implements Serializable { sb.append("]"); return sb.toString(); } -} \ No newline at end of file +} diff --git a/hai-service/src/main/java/com/hai/service/CommonService.java b/hai-service/src/main/java/com/hai/service/CommonService.java index ce9c6251..5415662e 100644 --- a/hai-service/src/main/java/com/hai/service/CommonService.java +++ b/hai-service/src/main/java/com/hai/service/CommonService.java @@ -239,4 +239,34 @@ public interface CommonService { */ JSONObject findByLatAndLng( String lng , String lat) throws Exception; + /** + * @Author Sum1Dream + * @name configPayType.java + * @Description // 配置支付方式 + * @Date 15:00 2022/5/12 + * @Param [com.alibaba.fastjson.JSONObject] + * @return void + */ + void configPayType(JSONObject object); + + /** + * @Author Sum1Dream + * @name configIntegralDiscount.java + * @Description // 配置积分折扣比例 + * @Date 15:00 2022/5/12 + * @Param [com.alibaba.fastjson.JSONObject] + * @return void + */ + void configIntegralDiscount(JSONObject object); + + /** + * @Author Sum1Dream + * @name configPlatform.java + * @Description // 配置展示平台 + * @Date 15:00 2022/5/12 + * @Param [com.alibaba.fastjson.JSONObject] + * @return void + */ + void configPlatform(JSONObject object); + } diff --git a/hai-service/src/main/java/com/hai/service/OutRechargePriceService.java b/hai-service/src/main/java/com/hai/service/OutRechargePriceService.java index 447e211d..05d14782 100644 --- a/hai-service/src/main/java/com/hai/service/OutRechargePriceService.java +++ b/hai-service/src/main/java/com/hai/service/OutRechargePriceService.java @@ -1,5 +1,6 @@ package com.hai.service; +import com.alibaba.fastjson.JSONObject; import com.hai.entity.OutRechargePrice; import java.util.List; @@ -14,7 +15,7 @@ public interface OutRechargePriceService { * @Param [map] * @return java.util.List **/ - List getListRechargePrice(Map map); + List getListRechargePrice(Map map); /** * @Author Sum1Dream @@ -41,7 +42,7 @@ public interface OutRechargePriceService { * @Param [outRechargePrice] * @return void **/ - void insertRechargePrice(OutRechargePrice outRechargePrice); + void insertRechargePrice(JSONObject object); /** * @Author Sum1Dream diff --git a/hai-service/src/main/java/com/hai/service/impl/CommonServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/CommonServiceImpl.java index 2801bdc7..a78328a4 100644 --- a/hai-service/src/main/java/com/hai/service/impl/CommonServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/CommonServiceImpl.java @@ -1,13 +1,15 @@ package com.hai.service.impl; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; import com.hai.common.utils.HttpsUtils; -import com.hai.dao.SecDictionaryMapper; -import com.hai.dao.SecRegionMapper; +import com.hai.dao.*; import com.hai.entity.*; import com.hai.model.IndexCountModel; import com.hai.model.LineCountModel; @@ -17,6 +19,8 @@ import com.hai.service.HighUserService; import com.hai.service.SecConfigService; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.math.BigDecimal; @@ -27,213 +31,222 @@ import java.util.concurrent.locks.ReentrantLock; @Service("iCommonService") public class CommonServiceImpl implements CommonService { - private long READ_STEP = 30*60*1000; //半小时刷新一次缓存的字典数据 - - private ReentrantLock lock = new ReentrantLock(); - - private ReentrantLock regionLock = new ReentrantLock(); - - private long lastReadTime = 0; - - private long regionLastReadTime = 0; - - @Resource - private SecRegionMapper regionMapper; - - @Resource - private SecDictionaryMapper dicMapper; - - @Resource - private SecConfigService secConfigService; - - @Resource - private HighUserService highUserService; - - @Resource - private HighOrderService highOrderService; - - private Map> dicCache = new HashMap>(); - - private List citiesCache = new ArrayList<>(); - - private Map> regionsCache = new HashMap<>(); - - private Map> streetCache = new HashMap<>(); - - private Map> communityCache = new HashMap<>(); - - private Map singleRegionCache = new HashMap<>(); - - @Override - public Map> getDictionaries() { - refreshDic(); - return dicCache; - } - - /** - * @param codeType - * @param codeValue - * @throws - * @Title: getDictionary - * @Description: 精确查找数据字典值 - * @author: 机器猫 - * @param: @param codeType - * @param: @param codeValue - * @param: @return - * @param: @throws Exception - * @return: SysDictionary - */ - @Override - public String getDictionaryCodeName(String codeType, String codeValue) { - refreshDic(); - if(StringUtils.isBlank(codeType)){ - throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); - } - Map m = dicCache.get(codeType); - if (null == m) { - return ""; - } - SecDictionary sd = m.get(codeValue); - if (null == sd) { - return ""; - } - return sd.getCodeName(); - } - - /** - * @param codeType - * @param codeValue - * @throws - * @Title: mappingSysCode - * @Description: 根据codetype,codevalue获取系统字典数据 - * @author: 机器猫 - * @param: @param codeType - * @param: @param codeValue - * @param: @return - * @param: @throws Exception - * @return: SysDictionary - */ - @Override - public SecDictionary mappingSysCode(String codeType, String codeValue) { - refreshDic(); - if(StringUtils.isBlank(codeType)){ - throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); - } - Map m = dicCache.get(codeType); - if (null == m) { - return null; - } - SecDictionary sd = m.get(codeValue); - return sd; - } - - @Override - public SecDictionary mappingSysName(String codeType, String codeName) { - refreshDic(); - if(StringUtils.isBlank(codeType)){ - throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); - } - Map m = dicCache.get(codeType); - if (null == m) { - return null; - } - for(Map.Entry entry : m.entrySet()){ - String mapKey = entry.getKey(); - SecDictionary mapValue = entry.getValue(); - if (mapValue.getCodeName().equals(codeName)) { - return mapValue; - } - } - return null; - } - - /** - * 根据codeType获取该类的所有字典数据 - * - * @param codeType - * @return - */ - @Override - public List getDictionarys(String codeType) { - refreshDic(); - if (StringUtils.isEmpty(codeType)) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "codeType is null"); - } - Map maps = dicCache.get(codeType); - if (null == maps) { - return new ArrayList<>(); - } - List rtn = new ArrayList<>(); - rtn.addAll(maps.values()); - return rtn; - } - - @Override - public List getDictionarysAndExt(String codeType, String ext1) { - refreshDic(); - if (StringUtils.isEmpty(codeType)) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "codeType is null"); - } - Map maps = dicCache.get(codeType); - if (null == maps) { - return new ArrayList<>(); - } - List rtn = new ArrayList<>(); - for(SecDictionary dictionary : maps.values()){ + private long READ_STEP = 30 * 60 * 1000; //半小时刷新一次缓存的字典数据 + + private ReentrantLock lock = new ReentrantLock(); + + private ReentrantLock regionLock = new ReentrantLock(); + + private long lastReadTime = 0; + + private long regionLastReadTime = 0; + + @Resource + private SecRegionMapper regionMapper; + + @Resource + private SecDictionaryMapper dicMapper; + + @Resource + private SecConfigService secConfigService; + + @Resource + private HighUserService highUserService; + + @Resource + private HighOrderService highOrderService; + + @Resource + private BsProductPlatformMapper bsProductPlatformMapper; + + @Resource + private BsProductDiscountMapper bsProductDiscountMapper; + + @Resource + private BsProductPayTypeMapper bsProductPayTypeMapper; + + private Map> dicCache = new HashMap>(); + + private List citiesCache = new ArrayList<>(); + + private Map> regionsCache = new HashMap<>(); + + private Map> streetCache = new HashMap<>(); + + private Map> communityCache = new HashMap<>(); + + private Map singleRegionCache = new HashMap<>(); + + @Override + public Map> getDictionaries() { + refreshDic(); + return dicCache; + } + + /** + * @param codeType + * @param codeValue + * @throws + * @Title: getDictionary + * @Description: 精确查找数据字典值 + * @author: 机器猫 + * @param: @param codeType + * @param: @param codeValue + * @param: @return + * @param: @throws Exception + * @return: SysDictionary + */ + @Override + public String getDictionaryCodeName(String codeType, String codeValue) { + refreshDic(); + if (StringUtils.isBlank(codeType)) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + Map m = dicCache.get(codeType); + if (null == m) { + return ""; + } + SecDictionary sd = m.get(codeValue); + if (null == sd) { + return ""; + } + return sd.getCodeName(); + } + + /** + * @param codeType + * @param codeValue + * @throws + * @Title: mappingSysCode + * @Description: 根据codetype,codevalue获取系统字典数据 + * @author: 机器猫 + * @param: @param codeType + * @param: @param codeValue + * @param: @return + * @param: @throws Exception + * @return: SysDictionary + */ + @Override + public SecDictionary mappingSysCode(String codeType, String codeValue) { + refreshDic(); + if (StringUtils.isBlank(codeType)) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + Map m = dicCache.get(codeType); + if (null == m) { + return null; + } + SecDictionary sd = m.get(codeValue); + return sd; + } + + @Override + public SecDictionary mappingSysName(String codeType, String codeName) { + refreshDic(); + if (StringUtils.isBlank(codeType)) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + Map m = dicCache.get(codeType); + if (null == m) { + return null; + } + for (Map.Entry entry : m.entrySet()) { + String mapKey = entry.getKey(); + SecDictionary mapValue = entry.getValue(); + if (mapValue.getCodeName().equals(codeName)) { + return mapValue; + } + } + return null; + } + + /** + * 根据codeType获取该类的所有字典数据 + * + * @param codeType + * @return + */ + @Override + public List getDictionarys(String codeType) { + refreshDic(); + if (StringUtils.isEmpty(codeType)) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "codeType is null"); + } + Map maps = dicCache.get(codeType); + if (null == maps) { + return new ArrayList<>(); + } + List rtn = new ArrayList<>(); + rtn.addAll(maps.values()); + return rtn; + } + + @Override + public List getDictionarysAndExt(String codeType, String ext1) { + refreshDic(); + if (StringUtils.isEmpty(codeType)) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "codeType is null"); + } + Map maps = dicCache.get(codeType); + if (null == maps) { + return new ArrayList<>(); + } + List rtn = new ArrayList<>(); + for (SecDictionary dictionary : maps.values()) { if (ext1.equals(dictionary.getExt1())) { rtn.add(dictionary); } } - return rtn; - } - - @Override - public List getIdAndName(String codeType) { - refreshDic(); - if (StringUtils.isEmpty(codeType)) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "codeType is null"); - } - Map maps = dicCache.get(codeType); - if (null == maps) { - return new ArrayList<>(); - } - List rtn = new ArrayList<>(); - for(SecDictionary dictionary : maps.values()){ - JSONObject jo = new JSONObject(); - jo.put("codeValue",dictionary.getCodeValue()); - jo.put("codeName",dictionary.getCodeName()); - rtn.add(jo); - } - return rtn; - } - - private void getDicFormDB(){ - SecDictionaryExample example = new SecDictionaryExample(); - example.createCriteria().andStatusEqualTo(1); - example.setOrderByClause(" sort_id asc"); - List dicList = dicMapper.selectByExample(example); - for(SecDictionary dic : dicList){ - if(dicCache.get(dic.getCodeType()) != null){ - Map typeList = dicCache.get(dic.getCodeType()); - typeList.put(dic.getCodeValue(), dic); - }else{ - Map temp = new HashMap(); - temp.put(dic.getCodeValue(), dic); - dicCache.put(dic.getCodeType(), temp); - } - } - lastReadTime = System.currentTimeMillis(); - } - - private void refreshDic() { - if (System.currentTimeMillis() - lastReadTime < READ_STEP) { - return; + return rtn; + } + + @Override + public List getIdAndName(String codeType) { + refreshDic(); + if (StringUtils.isEmpty(codeType)) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "codeType is null"); + } + Map maps = dicCache.get(codeType); + if (null == maps) { + return new ArrayList<>(); + } + List rtn = new ArrayList<>(); + for (SecDictionary dictionary : maps.values()) { + JSONObject jo = new JSONObject(); + jo.put("codeValue", dictionary.getCodeValue()); + jo.put("codeName", dictionary.getCodeName()); + rtn.add(jo); + } + return rtn; + } + + private void getDicFormDB() { + SecDictionaryExample example = new SecDictionaryExample(); + example.createCriteria().andStatusEqualTo(1); + example.setOrderByClause(" sort_id asc"); + List dicList = dicMapper.selectByExample(example); + for (SecDictionary dic : dicList) { + if (dicCache.get(dic.getCodeType()) != null) { + Map typeList = dicCache.get(dic.getCodeType()); + typeList.put(dic.getCodeValue(), dic); + } else { + Map temp = new HashMap(); + temp.put(dic.getCodeValue(), dic); + dicCache.put(dic.getCodeType(), temp); + } + } + lastReadTime = System.currentTimeMillis(); + } + + private void refreshDic() { + if (System.currentTimeMillis() - lastReadTime < READ_STEP) { + return; } if (lock.isLocked()) { //说明有线程已经在刷数据了 if (null != dicCache && dicCache.size() > 0) { //如果有数据说明已经初始化过了,直接返回老数据 return; } - while (null == dicCache || dicCache.size()<1) { //说明初始化刷数据 等待10毫秒 + while (null == dicCache || dicCache.size() < 1) { //说明初始化刷数据 等待10毫秒 try { Thread.sleep(10); //此处是否需要添加一个超时机制? @@ -244,32 +257,33 @@ public class CommonServiceImpl implements CommonService { return; } try { - lock.lock(); + lock.lock(); if (System.currentTimeMillis() - lastReadTime < READ_STEP) { return; } getDicFormDB(); } finally { if (lock.isLocked()) { - lock.unlock(); + lock.unlock(); } } } - @Override - public List getCities() { - refreshRegion(); - return citiesCache; - } - private void refreshRegion(){ - if (System.currentTimeMillis() - regionLastReadTime < READ_STEP) { - return; + @Override + public List getCities() { + refreshRegion(); + return citiesCache; + } + + private void refreshRegion() { + if (System.currentTimeMillis() - regionLastReadTime < READ_STEP) { + return; } if (regionLock.isLocked()) { //说明有线程已经在刷数据了 if (null != dicCache && dicCache.size() > 0) { //如果有数据说明已经初始化过了,直接返回老数据 return; } - while (null == dicCache || dicCache.size()<1) { //说明初始化刷数据 等待10毫秒 + while (null == dicCache || dicCache.size() < 1) { //说明初始化刷数据 等待10毫秒 try { Thread.sleep(10); //此处是否需要添加一个超时机制? @@ -280,235 +294,367 @@ public class CommonServiceImpl implements CommonService { return; } try { - regionLock.lock(); + regionLock.lock(); if (System.currentTimeMillis() - regionLastReadTime < READ_STEP) { return; } getRegionFromDB(); } finally { if (regionLock.isLocked()) { - regionLock.unlock(); + regionLock.unlock(); + } + } + } + + private void getRegionFromDB() { + SecRegionExample example = new SecRegionExample(); + example.createCriteria().andStatusEqualTo(1).andParentIdIsNull(); + citiesCache = regionMapper.selectByExample(example); + for (SecRegion city : citiesCache) {//市 + singleRegionCache.put(city.getRegionId(), city); + List regions = getRegions(city.getRegionId()); + regionsCache.put(city.getRegionId(), regions); + for (SecRegion region : regions) {//区 + singleRegionCache.put(region.getRegionId(), region); + List streets = getRegions(region.getRegionId()); + streetCache.put(region.getRegionId(), streets); + for (SecRegion street : streets) { + singleRegionCache.put(street.getRegionId(), street); + List communities = getRegions(street.getRegionId()); + communityCache.put(street.getRegionId(), communities); + for (SecRegion community : communities) { + singleRegionCache.put(community.getRegionId(), community); + } + } + } + } + regionLastReadTime = System.currentTimeMillis(); + } + + private List getRegions(Long parentId) { + SecRegionExample example = new SecRegionExample(); + example.createCriteria().andStatusEqualTo(1).andParentIdEqualTo(parentId); + return regionMapper.selectByExample(example); + } + + @Override + public List getRegionsByParentId(Long parentId) { + if (parentId == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); + } + refreshRegion(); + if (null != regionsCache.get(parentId)) { + return regionsCache.get(parentId); + } else if (null != streetCache.get(parentId)) { + return streetCache.get(parentId); + } else if (null != communityCache.get(parentId)) { + return communityCache.get(parentId); + } else { + return null; + } + } + + @Override + public Map getParentInfoByRegionId(Long regionId) { + if (regionId == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); + } + refreshRegion(); + Map map = new HashMap(); + Stack regionStack = getRegionStack(regionId, new Stack<>()); + if (regionStack.size() == 4) { + map.put("city", regionStack.pop()); + map.put("region", regionStack.pop()); + map.put("street", regionStack.pop()); + map.put("community", regionStack.pop()); + } else if (regionStack.size() == 3) { + map.put("city", regionStack.pop()); + map.put("region", regionStack.pop()); + map.put("street", regionStack.pop()); + } else if (regionStack.size() == 2) { + map.put("city", regionStack.pop()); + map.put("region", regionStack.pop()); + } else if (regionStack.size() == 1) { + map.put("city", regionStack.pop()); + } + return map; + } + + @Override + public String getRegionName(Long regionId) { + String regionName = ""; + Map map = getParentInfoByRegionId(regionId); + if (map.get("city") != null) { + regionName += map.get("city").getRegionName(); + } + if (map.get("region") != null) { + regionName += map.get("region").getRegionName(); + } + if (map.get("street") != null) { + regionName += map.get("street").getRegionName(); + } + if (map.get("community") != null) { + regionName += map.get("community").getRegionName(); + } + return regionName; + } + + private Stack getRegionStack(Long regionId, Stack regionStack) { + SecRegion region = singleRegionCache.get(regionId); + if (region != null) { + regionStack.push(region); + getRegionStack(region.getParentId(), regionStack); + } + return regionStack; + } + + @Override + public SecRegion getRegionsById(Long regionId) { + return regionMapper.selectByPrimaryKey(regionId); + } + + + @Override + public List findByName(String name) { + SecRegionExample example = new SecRegionExample(); + example.createCriteria().andStatusEqualTo(1).andRegionNameEqualTo(name); + return regionMapper.selectByExample(example); + } + + @Override + public SecRegion getParentByRegion(Long regionId) { + SecRegion secRegion = getRegionsById(regionId); + if (secRegion != null && secRegion.getParentId() != null) { + while (true) { + secRegion = getRegionsById(secRegion.getParentId()); + if (secRegion.getParentId() == null) { + return secRegion; + } } } - } - private void getRegionFromDB(){ - SecRegionExample example = new SecRegionExample(); - example.createCriteria().andStatusEqualTo(1).andParentIdIsNull(); - citiesCache = regionMapper.selectByExample(example); - for(SecRegion city : citiesCache){//市 - singleRegionCache.put(city.getRegionId(), city); - List regions = getRegions(city.getRegionId()); - regionsCache.put(city.getRegionId(),regions); - for(SecRegion region : regions){//区 - singleRegionCache.put(region.getRegionId(), region); - List streets = getRegions(region.getRegionId()); - streetCache.put(region.getRegionId(), streets); - for(SecRegion street : streets){ - singleRegionCache.put(street.getRegionId(), street); - List communities = getRegions(street.getRegionId()); - communityCache.put(street.getRegionId(),communities); - for (SecRegion community : communities){ - singleRegionCache.put(community.getRegionId(),community); - } - } - } - } - regionLastReadTime = System.currentTimeMillis(); - } - - private List getRegions(Long parentId) { - SecRegionExample example = new SecRegionExample(); - example.createCriteria().andStatusEqualTo(1).andParentIdEqualTo(parentId); - return regionMapper.selectByExample(example); - } - @Override - public List getRegionsByParentId(Long parentId) { - if(parentId == null){ - throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); - } - refreshRegion(); - if(null != regionsCache.get(parentId)){ - return regionsCache.get(parentId); - }else if(null != streetCache.get(parentId)){ - return streetCache.get(parentId); - }else if(null != communityCache.get(parentId)){ - return communityCache.get(parentId); - }else{ - return null; - } - } - - @Override - public Map getParentInfoByRegionId(Long regionId) { - if(regionId == null){ - throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); - } - refreshRegion(); - Map map = new HashMap(); - Stack regionStack = getRegionStack(regionId,new Stack<>()); - if (regionStack.size() == 4){ - map.put("city",regionStack.pop()); - map.put("region",regionStack.pop()); - map.put("street",regionStack.pop()); - map.put("community",regionStack.pop()); - }else if (regionStack.size() == 3){ - map.put("city",regionStack.pop()); - map.put("region",regionStack.pop()); - map.put("street",regionStack.pop()); - }else if (regionStack.size() == 2){ - map.put("city",regionStack.pop()); - map.put("region",regionStack.pop()); - }else if (regionStack.size() == 1){ - map.put("city",regionStack.pop()); - } - return map; - } - - @Override - public String getRegionName(Long regionId) { - String regionName = ""; - Map map = getParentInfoByRegionId(regionId); - if (map.get("city") != null) { - regionName += map.get("city").getRegionName(); - } - if (map.get("region") != null) { - regionName += map.get("region").getRegionName(); - } - if (map.get("street") != null) { - regionName += map.get("street").getRegionName(); - } - if (map.get("community") != null) { - regionName += map.get("community").getRegionName(); - } - return regionName; - } - - private Stack getRegionStack(Long regionId, Stack regionStack){ - SecRegion region = singleRegionCache.get(regionId); - if (region != null){ - regionStack.push(region); - getRegionStack(region.getParentId(),regionStack); - } - return regionStack; - } - - @Override - public SecRegion getRegionsById(Long regionId) { - return regionMapper.selectByPrimaryKey(regionId); - } - - - @Override - public List findByName(String name) { - SecRegionExample example = new SecRegionExample(); - example.createCriteria().andStatusEqualTo(1).andRegionNameEqualTo(name); - return regionMapper.selectByExample(example); - } - - @Override - public SecRegion getParentByRegion(Long regionId) { - SecRegion secRegion = getRegionsById(regionId); - if (secRegion != null && secRegion.getParentId() != null) { - while (true) { - secRegion = getRegionsById(secRegion.getParentId()); - if (secRegion.getParentId() == null) { - return secRegion; - } - } - } - return secRegion; - } - - @Override - public Boolean findValue(String codeType, String codeValue) { - SecDictionaryExample example = new SecDictionaryExample(); - example.createCriteria().andCodeTypeEqualTo(codeType).andCodeValueEqualTo(codeValue); - - List list = dicMapper.selectByExample(example); - - return list.size() > 0; - } - - @Override - public List mappingSysNameOl(String codeType) { - SecDictionaryExample example = new SecDictionaryExample(); - example.createCriteria().andCodeTypeEqualTo(codeType); - return dicMapper.selectByExample(example); - } - - @Override - public void updateDictionary(SecDictionary secDictionary) { - dicMapper.updateByPrimaryKeySelective(secDictionary); - } - - @Override - public BigDecimal getHLTBalance(String codeType) { - - SecConfig secConfig = secConfigService.findByCodeType(codeType); - return new BigDecimal(secConfig.getCodeValue()); - } - - - @Override - public void addHLTBalance(String codeType , BigDecimal price) { - SecConfig secConfig = secConfigService.findByCodeType(codeType); - - BigDecimal balance = new BigDecimal(secConfig.getCodeValue()); - - secConfig.setCodeValue(String.valueOf(price.add(balance))); - - secConfigService.updateSecConfig(secConfig); - } - - @Override - public IndexCountModel getIndexCount() { - - Map map = new HashMap<>(); - Map mapToDay = new HashMap<>(); - - mapToDay.put("today" , "1"); - - IndexCountModel countModel = new IndexCountModel(); - - // 获取注册总人数 - countModel.setRegistrantNum(highUserService.countUser()); - // 获取订单总金额 - countModel.setTransactionNum(highOrderService.orderPriceTotal(map).add(highOrderService.rechargePriceTotal(map))); - // 获取当天订单总金额 - countModel.setTransactionToday(highOrderService.orderPriceTotal(mapToDay).add(highOrderService.rechargePriceTotal(mapToDay))); - // 获取订单数量 - countModel.setTransactionOrder(highOrderService.orderPriceCount(map) + highOrderService.rechargePriceCount(map)); - //获取订单当天数量 - countModel.setTransactionOrderToday(highOrderService.orderPriceCount(mapToDay) + highOrderService.rechargePriceCount(mapToDay)); - return countModel; - } - - @Override - public LineCountModel getLineCount() { - - LineCountModel lineCount = new LineCountModel(); - - lineCount.setOrderPriceSum(highOrderService.getOrderSumOrderByDate()); - lineCount.setOrderRechargePriceSum(highOrderService.getOrderSumRechargeByDate()); - lineCount.setOrderCount(highOrderService.getDateCountByOrder()); - lineCount.setOrderRechargeCount(highOrderService.getDateCountByRecharge()); - lineCount.setUserCount(highOrderService.getDateCountByUser()); - return lineCount; - } + return secRegion; + } + + @Override + public Boolean findValue(String codeType, String codeValue) { + SecDictionaryExample example = new SecDictionaryExample(); + example.createCriteria().andCodeTypeEqualTo(codeType).andCodeValueEqualTo(codeValue); + + List list = dicMapper.selectByExample(example); + + return list.size() > 0; + } + + @Override + public List mappingSysNameOl(String codeType) { + SecDictionaryExample example = new SecDictionaryExample(); + example.createCriteria().andCodeTypeEqualTo(codeType); + return dicMapper.selectByExample(example); + } + + @Override + public void updateDictionary(SecDictionary secDictionary) { + dicMapper.updateByPrimaryKeySelective(secDictionary); + } + + @Override + public BigDecimal getHLTBalance(String codeType) { + + SecConfig secConfig = secConfigService.findByCodeType(codeType); + return new BigDecimal(secConfig.getCodeValue()); + } + + + @Override + public void addHLTBalance(String codeType, BigDecimal price) { + SecConfig secConfig = secConfigService.findByCodeType(codeType); + + BigDecimal balance = new BigDecimal(secConfig.getCodeValue()); + + secConfig.setCodeValue(String.valueOf(price.add(balance))); + + secConfigService.updateSecConfig(secConfig); + } + + @Override + public IndexCountModel getIndexCount() { + + Map map = new HashMap<>(); + Map mapToDay = new HashMap<>(); + + mapToDay.put("today", "1"); + + IndexCountModel countModel = new IndexCountModel(); + + // 获取注册总人数 + countModel.setRegistrantNum(highUserService.countUser()); + // 获取订单总金额 + countModel.setTransactionNum(highOrderService.orderPriceTotal(map).add(highOrderService.rechargePriceTotal(map))); + // 获取当天订单总金额 + countModel.setTransactionToday(highOrderService.orderPriceTotal(mapToDay).add(highOrderService.rechargePriceTotal(mapToDay))); + // 获取订单数量 + countModel.setTransactionOrder(highOrderService.orderPriceCount(map) + highOrderService.rechargePriceCount(map)); + //获取订单当天数量 + countModel.setTransactionOrderToday(highOrderService.orderPriceCount(mapToDay) + highOrderService.rechargePriceCount(mapToDay)); + return countModel; + } + + @Override + public LineCountModel getLineCount() { + + LineCountModel lineCount = new LineCountModel(); + + lineCount.setOrderPriceSum(highOrderService.getOrderSumOrderByDate()); + lineCount.setOrderRechargePriceSum(highOrderService.getOrderSumRechargeByDate()); + lineCount.setOrderCount(highOrderService.getDateCountByOrder()); + lineCount.setOrderRechargeCount(highOrderService.getDateCountByRecharge()); + lineCount.setUserCount(highOrderService.getDateCountByUser()); + return lineCount; + } @Override public JSONObject findByLatAndLng(String lng, String lat) throws Exception { - Map map = new HashMap<>();//参数 + Map map = new HashMap<>();//参数 map.put("ak", "SfrwGH7INvjPq7BwCrYrioBQZm9XXxrR");//申请百度开放平台KEY(ak) map.put("output", "json");// 输出Json数据 map.put("extensions_town", "true");// 行政区划返回乡镇级数据(town),仅国内召回乡镇数据 map.put("coordtype", "wgs84ll"); // GPS 经纬度类型 - map.put("location", lat+","+lng+"");//百度经纬度 + map.put("location", lat + "," + lng + "");//百度经纬度 String url = "http://api.map.baidu.com/reverse_geocoding/v3/"; - return HttpsUtils.doGet(url , map); + return HttpsUtils.doGet(url, map); + + } + + @Override + @Transactional(propagation= Propagation.REQUIRES_NEW) + public void configPayType(JSONObject object) { + // 删除原支付方式 + deletePayType(object.getLong("sourceId")); + // 支付方式 + BsProductPayType productPayType; + // 配置支付方式 + JSONArray payTypeArray = object.getJSONArray("payType"); + for (Object payType : payTypeArray) { + SecDictionary dictionary = mappingSysCode("PAY_TYPE", String.valueOf(payType)); + productPayType = new BsProductPayType(); + productPayType.setCreateTime(new Date()); + productPayType.setUpdateTime(new Date()); + productPayType.setPayTypeId(Integer.valueOf(String.valueOf(payType))); + productPayType.setPayTypeLogo(dictionary.getExt1()); + productPayType.setPayTypeName(dictionary.getCodeName()); + productPayType.setProductType(3); + productPayType.setOperatorId(object.getLong("operatorId")); + productPayType.setOperatorName(object.getString("operatorName")); + productPayType.setSourceId(object.getLong("sourceId")); + bsProductPayTypeMapper.insert(productPayType); + } + } + + @Override + @Transactional(propagation= Propagation.REQUIRES_NEW) + public void configIntegralDiscount(JSONObject object) { + // 清空原积分抵扣比例 + deleteIntegralDiscount(object.getLong("sourceId")); + // 折扣比例 + BsProductDiscount productDiscount; + // 配置积分折扣比例 + productDiscount = new BsProductDiscount(); + productDiscount.setDiscount(object.getBigDecimal("integralDiscount")); + productDiscount.setProductType(3); + productDiscount.setCreateTime(new Date()); + productDiscount.setUpdateTime(new Date()); + productDiscount.setOperatorId(object.getLong("operatorId")); + productDiscount.setOperatorName(object.getString("operatorName")); + productDiscount.setSourceId(object.getLong("sourceId")); + bsProductDiscountMapper.insert(productDiscount); + + } + + @Override + @Transactional(propagation= Propagation.REQUIRES_NEW) + public void configPlatform(JSONObject object) { + + deletePlatform(object.getLong("sourceId")); + + BsProductPlatform productPlatform; + // 配置展示平台 + JSONArray productPlatformArray = object.getJSONArray("productPlatform"); + for (Object platform : productPlatformArray) { + productPlatform = new BsProductPlatform(); + SecDictionary dictionary = mappingSysCode("SHOW_PLATFORM", String.valueOf(platform)); + productPlatform.setProductType(3); + productPlatform.setPlatformId(Integer.valueOf(String.valueOf(platform))); + productPlatform.setPlatformName(dictionary.getCodeName()); + productPlatform.setCreateTime(new Date()); + productPlatform.setUpdateTime(new Date()); + productPlatform.setOperatorId(object.getLong("operatorId")); + productPlatform.setOperatorName(object.getString("operatorName")); + productPlatform.setSourceId(object.getLong("sourceId")); + + bsProductPlatformMapper.insert(productPlatform); + } + } + + // 清空支付方式配置 + private void deletePayType(Long sourceId) { + + if (sourceId == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + BsProductPayTypeExample example = new BsProductPayTypeExample(); + example.createCriteria().andSourceIdEqualTo(sourceId); + + List list = bsProductPayTypeMapper.selectByExample(example); + + if (list.size() > 0) { + for (BsProductPayType productPayType : list) { + bsProductPayTypeMapper.deleteByPrimaryKey(productPayType.getId()); + } + } + + } + + // 清空配置积分抵扣比例 + private void deleteIntegralDiscount(Long sourceId) { + + if (sourceId == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + BsProductDiscountExample example = new BsProductDiscountExample(); + example.createCriteria().andSourceIdEqualTo(sourceId); + + List list = bsProductDiscountMapper.selectByExample(example); + + if (list.size() > 0) { + for (BsProductDiscount bsProductDiscount : list) { + bsProductDiscountMapper.deleteByPrimaryKey(bsProductDiscount.getId()); + } + } + + } + + // 清空配置展示平台 + private void deletePlatform(Long sourceId) { + + if (sourceId == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + BsProductPlatformExample example = new BsProductPlatformExample(); + example.createCriteria().andSourceIdEqualTo(sourceId); + + List list = bsProductPlatformMapper.selectByExample(example); + + if (list.size() > 0) { + for (BsProductPlatform productPlatform : list) { + bsProductDiscountMapper.deleteByPrimaryKey(productPlatform.getId()); + } + } } } diff --git a/hai-service/src/main/java/com/hai/service/impl/HighRefundAuditServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighRefundAuditServiceImpl.java index 6705d819..0a9d69c4 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighRefundAuditServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighRefundAuditServiceImpl.java @@ -92,11 +92,11 @@ public class HighRefundAuditServiceImpl implements HighRefundAuditService { if (highRefundAudit.getRefundSource() == 1) { OutRechargeOrder outRechargeOrder = outRechargeOrderService.findByOrderNo(highRefundAudit.getSourceOrderNo()); - highRefundAudit.setRefundPrice(outRechargeOrder.getPayPrice()); +// highRefundAudit.setRefundPrice(outRechargeOrder.getPayPrice()); highRefundAudit.setPayType(outRechargeOrder.getPayType()); highRefundAudit.setPayTime(outRechargeOrder.getPayTime()); highRefundAudit.setExt1(String.valueOf(outRechargeOrder.getId())); - outRechargeOrder.setStatus(6); +// outRechargeOrder.setStatus(6); outRechargeOrderService.updateOrder(outRechargeOrder); } else { HighOrder highOrder = highOrderService.getOrderByOrderNo(highRefundAudit.getSourceOrderNo()); 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 764a5cd0..8bac02e6 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 @@ -78,25 +78,14 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { criteria.andUserIdEqualTo(MapUtils.getLong(map, "userId")); } - if (MapUtils.getInteger(map, "status") != null) { - criteria.andStatusEqualTo(MapUtils.getInteger(map, "status")); - } if (MapUtils.getInteger(map, "payType") != null) { criteria.andPayTypeEqualTo(MapUtils.getInteger(map, "payType")); } - if (MapUtils.getInteger(map, "code") != null) { - criteria.andIdentificationCodeEqualTo(MapUtils.getLong(map, "code")); - } if (MapUtils.getString(map, "orderNo") != null) { criteria.andOrderNoLike("%" + MapUtils.getString(map, "orderNo") + "%"); } - - if (MapUtils.getString(map, "idCard") != null) { - criteria.andIdCardLike("%" + MapUtils.getString(map, "idCard") + "%"); - } - if (MapUtils.getString(map, "userPhone") != null) { criteria.andUserPhoneEqualTo(MapUtils.getString(map, "userPhone")); } @@ -104,17 +93,11 @@ 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")); } - if (MapUtils.getString(map, "rechargeModel") != null) { - criteria.andRechargeModelEqualTo(Integer.valueOf(MapUtils.getString(map, "rechargeModel"))); - } if (StringUtils.isNotBlank(map.get("payTimeS")) && StringUtils.isNotBlank(map.get("payTimeE"))) { criteria.andPayTimeBetween( @@ -170,11 +153,11 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { @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()); - } +// if (list.getStatus() == 3) { +// outRechargeOrderMapper.updateByPrimaryKey(list); +// } else if (list.getStatus() == 6) { +// rechargeOrderToRefund(list.getId()); +// } } } @@ -183,25 +166,25 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { @Transactional(propagation= Propagation.REQUIRES_NEW) public void cancelOrder(Long orderId) { OutRechargeOrder order = findByOrderId(orderId); - if (order != null && order.getStatus() == 1) { - order.setStatus(4); // 订单状态:1 待支付 2 已支付 3.已完成 4. 已取消 5.已退款 - order.setCancelTime(new Date()); - - if (order.getMemDiscountId() != null) { - HighDiscountUserRel rel = highDiscountUserRelService.getRelById(order.getMemDiscountId()); - if (rel != null) { - rel.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用 - rel.setUseTime(null); - highDiscountUserRelService.updateDiscountUserRel(rel); - - HighDiscountAgentCode code = highDiscountAgentCodeService.getCodeById(rel.getDiscountAgentCodeId()); - code.setStatus(2); - highDiscountAgentCodeService.updateCode(code); - } - } - - updateOrder(order); - } +// if (order != null && order.getStatus() == 1) { +// order.setStatus(4); // 订单状态:1 待支付 2 已支付 3.已完成 4. 已取消 5.已退款 +// order.setCancelTime(new Date()); +// +// if (order.getMemDiscountId() != null) { +// HighDiscountUserRel rel = highDiscountUserRelService.getRelById(order.getMemDiscountId()); +// if (rel != null) { +// rel.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用 +// rel.setUseTime(null); +// highDiscountUserRelService.updateDiscountUserRel(rel); +// +// HighDiscountAgentCode code = highDiscountAgentCodeService.getCodeById(rel.getDiscountAgentCodeId()); +// code.setStatus(2); +// highDiscountAgentCodeService.updateCode(code); +// } +// } +// +// updateOrder(order); +// } } @@ -210,7 +193,7 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { public void finishOrder(Long orderId) { OutRechargeOrder order = findByOrderId(orderId); if (order != null) { - order.setStatus(3); // 订单状态:1 待支付 2 已支付 3.已完成 4. 已取消 5.已退款 +// order.setStatus(3); // 订单状态:1 待支付 2 已支付 3.已完成 4. 已取消 5.已退款 order.setFinishTime(new Date()); updateOrder(order); } @@ -242,7 +225,7 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { @Override public Long CountOrder() { OutRechargeOrderExample example = new OutRechargeOrderExample(); - example.createCriteria().andStatusEqualTo(2); +// example.createCriteria().andStatusEqualTo(2); return outRechargeOrderMapper.countByExample(example); } @@ -336,51 +319,51 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { } String goodsDesc = "充值话费"; - String tranDesc = order.getRechargeContent() + "充值" + order.getPayPrice() +"元话费"; +// String tranDesc = order.getRechargeContent() + "充值" + order.getPayPrice() +"元话费"; String instCode = "11101290"; String businessType = "hisen_consume"; // 工会卡支付 - JSONObject consumption = HuiLianTongUnionCardConfig.consumption(order.getOrderNo(), userCard.getCardNo(), order.getPayPrice(), businessType, instCode, goodsDesc, tranDesc); - System.out.println("工会卡支付响应参数" + consumption.toJSONString()); +// JSONObject consumption = HuiLianTongUnionCardConfig.consumption(order.getOrderNo(), userCard.getCardNo(), order.getPayPrice(), businessType, instCode, goodsDesc, tranDesc); +// System.out.println("工会卡支付响应参数" + consumption.toJSONString()); Map dataMap = new HashMap<>(); dataMap.put("orderNo", order.getOrderNo()); dataMap.put("cardType", "ghk"); dataMap.put("cardNo", userCard.getCardNo()); dataMap.put("checkPassword", "N"); - dataMap.put("tranAmount", order.getPayPrice()); +// dataMap.put("tranAmount", order.getPayPrice()); dataMap.put("tranChannel", "HiSen"); dataMap.put("businessType", businessType); dataMap.put("instCode", instCode); dataMap.put("goodsDesc", goodsDesc); - dataMap.put("tranDesc", tranDesc); +// dataMap.put("tranDesc", tranDesc); HighGasOrderPush payPush = new HighGasOrderPush(); payPush.setType(OrderPushType.type5.getType()); payPush.setOrderNo(order.getOrderNo()); payPush.setCreateTime(new Date()); - payPush.setCode(consumption.getString("respCode")); - payPush.setRequestContent(JSON.toJSONString(dataMap)); - payPush.setReturnContent(consumption.toJSONString()); +// payPush.setCode(consumption.getString("respCode")); +// payPush.setRequestContent(JSON.toJSONString(dataMap)); +// payPush.setReturnContent(consumption.toJSONString()); highGasOrderPushMapper.insert(payPush); - if(!consumption.getString("respCode").equals("0000")) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, consumption.getString("respMessage")); - } - JSONObject consumptionResult = HuiLianTongUnionCardConfig.resolveResponse(consumption.getString("data")); - if (!consumptionResult.getBoolean("success")) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, consumptionResult.getString("message")); - } - order.setPaySerialNo(consumptionResult.getString("orderId")); // 支付流水号 - order.setPayRealPrice(order.getPayPrice()); // 实付金额 - if (order.getRechargeType() == 1) { - JSONObject object = outRechargeOrderService.getMobile(order.getRechargeContent() , order.getOrderPrice().intValue() , order.getOrderNo() ,order.getRechargeType()); - if (object.getInteger("code") != 200) { - order.setRechargeStatus(1); - order.setAbnormalMsg(object.getString("message")); - } - } - order.setStatus(2); +// if(!consumption.getString("respCode").equals("0000")) { +// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, consumption.getString("respMessage")); +// } +// JSONObject consumptionResult = HuiLianTongUnionCardConfig.resolveResponse(consumption.getString("data")); +// if (!consumptionResult.getBoolean("success")) { +// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, consumptionResult.getString("message")); +// } +// order.setPaySerialNo(consumptionResult.getString("orderId")); // 支付流水号 +// order.setPayRealPrice(order.getPayPrice()); // 实付金额 +// if (order.getRechargeType() == 1) { +// JSONObject object = outRechargeOrderService.getMobile(order.getRechargeContent() , order.getOrderPrice().intValue() , order.getOrderNo() ,order.getRechargeType()); +// if (object.getInteger("code") != 200) { +// order.setRechargeStatus(1); +// order.setAbnormalMsg(object.getString("message")); +// } +// } +// order.setStatus(2); order.setPayType(2); order.setPayTime(new Date()); // 支付时间 updateOrder(order); @@ -389,21 +372,21 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { @Override @Transactional(propagation= Propagation.REQUIRES_NEW) public void goldPayOrder(Long userId, Long orderId) throws Exception { - OutRechargeOrder order = findByOrderId(orderId); - if(order == null) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_ORDER, ""); - } - // 查询用户 - HighUser highUser = highUserService.findByUserId(userId); - - // 金币 1:100 - Integer goldNum = new BigDecimal(order.getPayPrice().toString()).multiply(new BigDecimal("100")).intValue(); - highUserService.goldHandle(userId, goldNum, 2, 2, order.getId()); - order.setPayRealPrice(order.getPayPrice()); // 实付金额 - order.setStatus(2); - order.setPayType(3); - order.setPayTime(new Date()); // 支付时间 - outRechargeOrderService.updateOrder(order); +// OutRechargeOrder order = findByOrderId(orderId); +// if(order == null) { +// throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_ORDER, ""); +// } +// // 查询用户 +// HighUser highUser = highUserService.findByUserId(userId); +// +// // 金币 1:100 +// Integer goldNum = new BigDecimal(order.getPayPrice().toString()).multiply(new BigDecimal("100")).intValue(); +// highUserService.goldHandle(userId, goldNum, 2, 2, order.getId()); +// order.setPayRealPrice(order.getPayPrice()); // 实付金额 +// order.setStatus(2); +// order.setPayType(3); +// order.setPayTime(new Date()); // 支付时间 +// outRechargeOrderService.updateOrder(order); } @Override @@ -444,107 +427,107 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { @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) { - if (highUserService.findGoldRepeat(3 , order.getId())) { - highUserService.goldHandle(order.getUserId(), order.getPayRealPrice().multiply(BigDecimal.valueOf(100)).intValue(), 1, 3, order.getId()); - }else { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "已有退款记录"); - } - order.setStatus(5); - order.setRefundTime(new Date()); - order.setOutRefundNo("HFR"+new Date().getTime() ); - order.setRefundFee(order.getPayRealPrice()); - outRechargeOrderService.updateOrder(order); - } - - // 银联退款 - if (order.getPayType() == 4) { - // 订单退款 - JSONObject refund = UnionPayConfig.zwrefund(UnionPayConfig.MER_ID2, UnionPayConfig.TERM_ID2, 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); - } - - if (order.getMemDiscountId() != null) { - HighDiscountUserRel rel = highDiscountUserRelService.getRelById(order.getMemDiscountId()); - if (rel != null) { - rel.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用 - rel.setUseTime(null); - highDiscountUserRelService.updateDiscountUserRel(rel); - - HighDiscountAgentCode code = highDiscountAgentCodeService.getCodeById(rel.getDiscountAgentCodeId()); - code.setStatus(2); - highDiscountAgentCodeService.updateCode(code); - } - } +// 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) { +// if (highUserService.findGoldRepeat(3 , order.getId())) { +// highUserService.goldHandle(order.getUserId(), order.getPayRealPrice().multiply(BigDecimal.valueOf(100)).intValue(), 1, 3, order.getId()); +// }else { +// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "已有退款记录"); +// } +// order.setStatus(5); +// order.setRefundTime(new Date()); +// order.setOutRefundNo("HFR"+new Date().getTime() ); +// order.setRefundFee(order.getPayRealPrice()); +// outRechargeOrderService.updateOrder(order); +// } +// +// // 银联退款 +// if (order.getPayType() == 4) { +// // 订单退款 +// JSONObject refund = UnionPayConfig.zwrefund(UnionPayConfig.MER_ID2, UnionPayConfig.TERM_ID2, 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); +// } +// +// if (order.getMemDiscountId() != null) { +// HighDiscountUserRel rel = highDiscountUserRelService.getRelById(order.getMemDiscountId()); +// if (rel != null) { +// rel.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用 +// rel.setUseTime(null); +// highDiscountUserRelService.updateDiscountUserRel(rel); +// +// HighDiscountAgentCode code = highDiscountAgentCodeService.getCodeById(rel.getDiscountAgentCodeId()); +// code.setStatus(2); +// highDiscountAgentCodeService.updateCode(code); +// } +// } } 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 d9953add..cf445ebd 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 @@ -1,13 +1,22 @@ package com.hai.service.impl; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.hai.dao.OutRechargePriceMapper; import com.hai.entity.*; +import com.hai.service.CommonService; import com.hai.service.OutRechargePriceService; import io.swagger.models.auth.In; +import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.Date; import java.util.List; import java.util.Map; @@ -17,26 +26,30 @@ public class OutRechargePriceServiceImpl implements OutRechargePriceService { @Resource private OutRechargePriceMapper outRechargePriceMapper; + @Resource + private CommonService commonService; + @Override - public List getListRechargePrice(Map map) { + public List getListRechargePrice(Map map) { OutRechargePriceExample example = new OutRechargePriceExample(); OutRechargePriceExample.Criteria criteria = example.createCriteria(); - if (StringUtils.isNotBlank(map.get("type"))) { - criteria.andTypeEqualTo(Integer.valueOf(map.get("type"))); + if (MapUtils.getLong(map , "companyId") != null) { + criteria.andCompanyIdEqualTo(MapUtils.getLong(map , "companyId")); } - if (StringUtils.isNotBlank(map.get("showType"))) { - criteria.andShowTypeEqualTo(Integer.valueOf(map.get("showType"))); + + if (MapUtils.getLong(map , "rechargePlatform") != null) { + criteria.andRechargePlatformLike("%-" +MapUtils.getLong(map , "rechargePlatform") + "-%"); } - if (StringUtils.isNotBlank(map.get("companyId"))) { - criteria.andCompanyIdEqualTo(Long.valueOf(map.get("companyId"))); + if (MapUtils.getLong(map , "rechargeType") != null) { + criteria.andRechargeTypeEqualTo(MapUtils.getInteger(map , "rechargeType")); } - if (StringUtils.isNotBlank(map.get("rechargeType"))) { - criteria.andRechargeTypeEqualTo(Integer.valueOf(map.get("rechargeType"))); + if (MapUtils.getLong(map , "rechargeType") != null) { + criteria.andRechargeTypeEqualTo(MapUtils.getInteger(map , "rechargeType")); } - example.setOrderByClause("type asc"); + example.setOrderByClause("recharge_price asc"); return outRechargePriceMapper.selectByExample(example); } @Override @@ -46,12 +59,6 @@ public class OutRechargePriceServiceImpl implements OutRechargePriceService { criteria.andStatusNotEqualTo(0); - if (StringUtils.isNotBlank(map.get("type"))) { - criteria.andTypeEqualTo(Integer.valueOf(map.get("type"))); - } - if (StringUtils.isNotBlank(map.get("showType"))) { - criteria.andShowTypeEqualTo(Integer.valueOf(map.get("showType"))); - } if (StringUtils.isNotBlank(map.get("companyId"))) { criteria.andCompanyIdEqualTo(Long.valueOf(map.get("companyId"))); } @@ -70,8 +77,50 @@ public class OutRechargePriceServiceImpl implements OutRechargePriceService { } @Override - public void insertRechargePrice(OutRechargePrice outRechargePrice) { - outRechargePriceMapper.insert(outRechargePrice); + @Transactional(propagation= Propagation.REQUIRES_NEW) + public void insertRechargePrice(JSONObject object) { + + // 转换金额数组 + JSONArray priceArray = object.getJSONArray("rechargePrices"); + + // 充值金额 + OutRechargePrice outRechargePrice; + + for (Object price : priceArray) { + SecDictionary dictionary = commonService.mappingSysCode("RECHARGE_AMOUNT", String.valueOf(price)); + BigDecimal priceBd = new BigDecimal(dictionary.getCodeName()); + outRechargePrice = new OutRechargePrice(); + outRechargePrice.setRechargePrice(priceBd); + outRechargePrice.setPayPrice(priceBd.multiply(object.getBigDecimal("discount").divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_UP))); + outRechargePrice.setDiscount(object.getBigDecimal("discount")); + outRechargePrice.setRechargeType(object.getInteger("rechargeType")); + outRechargePrice.setOperatorType(object.getInteger("operatorType")); + outRechargePrice.setRechargePlatform("-" + StringUtils.join(object.getJSONArray("rechargePlatform") , "-") + "-"); + outRechargePrice.setRechargeWay(object.getInteger("rechargeWay")); + outRechargePrice.setCompanyId(object.getLong("companyId")); + outRechargePrice.setCreateTime(new Date()); + outRechargePrice.setUpdateTime(new Date()); + outRechargePrice.setStatus(3); + outRechargePrice.setSort(1); + outRechargePriceMapper.insert(outRechargePrice); + + JSONObject postObject = new JSONObject(); + postObject.put("payType", object.getJSONArray("payType")); + postObject.put("integralDiscount", object.getBigDecimal("integralDiscount")); + postObject.put("productPlatform", object.getJSONArray("productPlatform")); + postObject.put("operatorId", object.getLong("operatorId")); + postObject.put("operatorName", object.getString("operatorName")); + postObject.put("sourceId", outRechargePrice.getId()); + + // 配置支付方式 + commonService.configPayType(postObject); + // 配置积分折扣比例 + commonService.configIntegralDiscount(postObject); + // 配置展示平台 + commonService.configPlatform(postObject); + } + + } @Override diff --git a/hai-service/src/main/java/com/hai/service/pay/impl/RechargeOrderServiceImpl.java b/hai-service/src/main/java/com/hai/service/pay/impl/RechargeOrderServiceImpl.java index 11ab3cb5..97025893 100644 --- a/hai-service/src/main/java/com/hai/service/pay/impl/RechargeOrderServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/pay/impl/RechargeOrderServiceImpl.java @@ -65,28 +65,28 @@ public class RechargeOrderServiceImpl implements PayService { if (payType.equals("WechatPay")) { // 查询订单信息 OutRechargeOrder order = outRechargeOrderService.findByOrderNo(map.get("out_trade_no")); - if (order != null && order.getStatus() == 1) { - order.setPaySerialNo(map.get("transaction_id")); // 支付流水号 - order.setPayRealPrice(new BigDecimal(map.get("total_fee")).divide(new BigDecimal("100"))); // 实付金额 - order.setPayTime(new Date()); // 支付时间 - order.setStatus(2); // 订单状态 : 1.待支付 2.已支付 3.已完成 4.已取消 5.已退款 - if (order.getRechargeType() == 1) { - JSONObject object = outRechargeOrderService.getMobile(order.getRechargeContent() , order.getOrderPrice().intValue() , order.getOrderNo() , order.getRechargeType()); - if (object.getInteger("code") != 200) { - order.setRechargeStatus(1); - order.setAbnormalMsg(object.getString("message")); - } - } - outRechargeOrderService.updateOrder(order); - // 推送订单记录 - HighGasOrderPush highGasOrderPush = new HighGasOrderPush(); - highGasOrderPush.setType(OrderPushType.type2.getType()); - highGasOrderPush.setOrderNo(order.getOrderNo()); - highGasOrderPush.setCreateTime(new Date()); - highGasOrderPush.setRequestContent(order.getOrderNo()); - highGasOrderPush.setReturnContent(String.valueOf(map)); - highGasOrderPushMapper.insert(highGasOrderPush); - } +// if (order != null && order.getStatus() == 1) { +// order.setPaySerialNo(map.get("transaction_id")); // 支付流水号 +// order.setPayRealPrice(new BigDecimal(map.get("total_fee")).divide(new BigDecimal("100"))); // 实付金额 +// order.setPayTime(new Date()); // 支付时间 +// order.setStatus(2); // 订单状态 : 1.待支付 2.已支付 3.已完成 4.已取消 5.已退款 +// if (order.getRechargeType() == 1) { +// JSONObject object = outRechargeOrderService.getMobile(order.getRechargeContent() , order.getOrderPrice().intValue() , order.getOrderNo() , order.getRechargeType()); +// if (object.getInteger("code") != 200) { +// order.setRechargeStatus(1); +// order.setAbnormalMsg(object.getString("message")); +// } +// } +// outRechargeOrderService.updateOrder(order); +// // 推送订单记录 +// HighGasOrderPush highGasOrderPush = new HighGasOrderPush(); +// highGasOrderPush.setType(OrderPushType.type2.getType()); +// highGasOrderPush.setOrderNo(order.getOrderNo()); +// highGasOrderPush.setCreateTime(new Date()); +// highGasOrderPush.setRequestContent(order.getOrderNo()); +// highGasOrderPush.setReturnContent(String.valueOf(map)); +// highGasOrderPushMapper.insert(highGasOrderPush); +// } } }