From 03f9ca62a07a8d125e60c0e4d79b4188ae1b596e Mon Sep 17 00:00:00 2001 From: Sum1Dream <418471657@qq.com> Date: Mon, 6 Mar 2023 14:51:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AF=9D=E8=B4=B9=E5=AE=9A?= =?UTF-8?q?=E6=97=B6=E4=BB=BB=E5=8A=A1=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApiMchProductController.java | 10 +- .../controller/ApiMerchantsController.java | 2 +- .../bweb/controller/ApiProductController.java | 14 +- .../bweb/controller/HighTestController.java | 2 +- .../com/bweb/controller/LoginController.java | 21 ++ .../OutRechargePriceController.java | 5 +- .../com/web/controller/OrderController.java | 5 + .../MobileRechargeNotifyController.java | 4 +- .../hai/dao/OutRechargePriceMapperExt.java | 2 +- .../java/com/hai/entity/ApiAmountRecord.java | 12 +- .../openApi/config/PriceComputeConfig.java | 62 +++++ .../openApi/service/ApiMchProductService.java | 2 +- .../service/ApiOrderCreateHandleService.java | 31 +++ .../hai/openApi/service/ApiOrderService.java | 60 +++++ .../impl/ApiMchProductServiceImpl.java | 36 +-- .../impl/ApiOrderCreateHandleServiceImpl.java | 97 +++++++ .../service/impl/ApiOrderServiceImpl.java | 201 ++++++++++++++ .../order/model/CreateOrderChildModel.java | 8 +- .../com/hai/order/model/CreateOrderModel.java | 2 + .../hai/order/service/OrderPayService.java | 12 + .../service/impl/OrderPayServiceImpl.java | 22 ++ .../impl/OrderPaySuccessServiceImpl.java | 10 +- .../order/service/impl/OrderServiceImpl.java | 2 + .../java/com/hai/order/type/OrderPayType.java | 1 + .../service/impl/ApiProductServiceImpl.java | 1 - .../impl/OutRechargeOrderServiceImpl.java | 10 +- .../java/com/v1/config/ApiCommonConfig.java | 2 +- .../com/v1/controller/ApiOrderController.java | 128 --------- .../v1/controller/HighOrderController.java | 193 ------------- .../v1/controller/ThirdPartyController.java | 2 +- .../com/v1/controller/WxMsgController.java | 2 +- .../ApiMerchantsController.java | 5 +- .../{ => business}/GzSinopecController.java | 7 +- .../RefuelOnlineController.java | 14 +- .../com/v1/controller/orderController.java | 253 ++++++++++++++++++ 35 files changed, 851 insertions(+), 389 deletions(-) create mode 100644 hai-service/src/main/java/com/hai/openApi/config/PriceComputeConfig.java create mode 100644 hai-service/src/main/java/com/hai/openApi/service/ApiOrderCreateHandleService.java create mode 100644 hai-service/src/main/java/com/hai/openApi/service/ApiOrderService.java create mode 100644 hai-service/src/main/java/com/hai/openApi/service/impl/ApiOrderCreateHandleServiceImpl.java create mode 100644 hai-service/src/main/java/com/hai/openApi/service/impl/ApiOrderServiceImpl.java delete mode 100644 v1/src/main/java/com/v1/controller/ApiOrderController.java delete mode 100644 v1/src/main/java/com/v1/controller/HighOrderController.java rename v1/src/main/java/com/v1/controller/{ => business}/ApiMerchantsController.java (97%) rename v1/src/main/java/com/v1/controller/{ => business}/GzSinopecController.java (98%) rename v1/src/main/java/com/v1/controller/{ => business}/RefuelOnlineController.java (95%) create mode 100644 v1/src/main/java/com/v1/controller/orderController.java diff --git a/hai-bweb/src/main/java/com/bweb/controller/ApiMchProduct/ApiMchProductController.java b/hai-bweb/src/main/java/com/bweb/controller/ApiMchProduct/ApiMchProductController.java index d84d87d0..a0a7dd9f 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/ApiMchProduct/ApiMchProductController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/ApiMchProduct/ApiMchProductController.java @@ -123,7 +123,15 @@ public class ApiMchProductController { ApiMchProduct apiMchProduct = apiMchProductService.findById(id); - secConfigService.deleteSecConfig(apiMchProduct.getMchId() , OrderProductType.getDataByType(apiMchProduct.getProductType()).getApiCode()); + Map map = new HashMap<>(); + map.put("productType" , apiMchProduct.getProductType()); + map.put("mchId" , apiMchProduct.getMchId()); + + List list = apiMchProductService.getListMchProduct(map); + + if (list.size() == 1) { + secConfigService.deleteSecConfig(apiMchProduct.getMchId() , OrderProductType.getDataByType(apiMchProduct.getProductType()).getApiCode()); + } apiMchProductService.detailApiMchProduct(id); return ResponseMsgUtil.success("操作成功"); diff --git a/hai-bweb/src/main/java/com/bweb/controller/ApiMerchantsController.java b/hai-bweb/src/main/java/com/bweb/controller/ApiMerchantsController.java index a342e25d..5e247130 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/ApiMerchantsController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/ApiMerchantsController.java @@ -250,7 +250,7 @@ public class ApiMerchantsController { } Map map = new HashMap<>(); - map.put("sourceType", ApiAmountRecordTypeEnum.type1.getType()); + map.put("sourceType", 99); map.put("sourceContent", "充值金额:" + body.getBigDecimal("amount") + " 元"); apiMerchantsService.recharge(body.getLong("merchantId"), body.getBigDecimal("amount"), map); diff --git a/hai-bweb/src/main/java/com/bweb/controller/ApiProductController.java b/hai-bweb/src/main/java/com/bweb/controller/ApiProductController.java index 3bf2a633..85e63908 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/ApiProductController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/ApiProductController.java @@ -89,8 +89,7 @@ public class ApiProductController { if (object == null || object.getJSONArray("prices") == null || object.getInteger("operatorType") == null || - object.getJSONArray("rechargePlatform") == null || - object.getInteger("phoneRechargeType") == null + object.getJSONArray("rechargePlatform") == null ) { log.error("ApiProductController -> insertProduct() error!"); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); @@ -122,8 +121,7 @@ public class ApiProductController { if (object == null || object.getLong("id") == null || object.getInteger("operatorType") == null || - object.getJSONArray("rechargePlatform") == null || - object.getInteger("phoneRechargeType") == null + object.getJSONArray("rechargePlatform") == null ) { log.error("ApiProductController -> updateProduct() error!"); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); @@ -139,12 +137,10 @@ public class ApiProductController { apiProduct.setOperatorId(userInfoModel.getSecUser().getId()); apiProduct.setOperatorName(userInfoModel.getSecUser().getLoginName()); apiProduct.setRechargeType(object.getInteger("rechargeType")); - apiProduct.setPhoneRechargeType(object.getInteger("phoneRechargeType")); apiProduct.setOperatorType(object.getInteger("operatorType")); apiProduct.setRechargePlatform("-" + StringUtils.join(object.getJSONArray("rechargePlatform"), "-") + "-"); apiProduct.setUpdateTime(new Date()); apiProduct.setSort(object.getInteger("sort")); - apiProduct.setProductId(object.getLong("productId")); apiProduct.setOperatorName(object.getString("operatorName")); apiProduct.setOperatorId(object.getLong("operatorId")); @@ -168,10 +164,10 @@ public class ApiProductController { UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); ApiProduct apiProduct = apiProductService.findById(object.getLong("id")); - - if (object.getInteger("status") == 101 && apiProduct.getRechargePlatform().contains("-2-") && apiProduct.getProductId() == null) { + + if (object.getInteger("status") == 101 && (apiProduct.getRechargePlatform().contains("-2-") || apiProduct.getRechargePlatform().contains("-4-"))) { log.error("ApiProductController -> editProductStatus() error!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "龙阅平台需要输入商品编码!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "龙阅,城宇,畅停平台需要输入商品编码!"); } apiProduct.setStatus(object.getInteger("status")); 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 b181f661..055658e9 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.JSONArray; import com.alibaba.fastjson.JSONObject; import com.alipay.api.domain.ForbbidenTime; import com.alipay.api.domain.OfferObject; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; import com.hai.common.pay.util.sdk.WXPayConstants; import com.hai.common.utils.*; import com.hai.config.*; import com.hai.entity.*; import com.hai.model.OrderRefundModel; import com.hai.model.ResponseData; import com.hai.order.service.OrderRefundService; import com.hai.order.service.OrderService; import com.hai.order.type.OrderPayType; import com.hai.order.type.OrderRefundOpUserType; import com.hai.service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.math.BigDecimal; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * @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 OutRechargeOrderService outRechargeOrderService; @Resource private OrderService orderService; @Resource private HighOrderService highOrderService; @Resource private OrderRefundService orderRefundService; @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 = "/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, ""); } JSONArray array = HuiLianTongUnionCardConfig.resolveResponse(consumptionRecord.getString("data")).getJSONArray("records"); return ResponseMsgUtil.success(array); } catch (Exception e) { log.error("HighUserCardController --> getHuiLianTongCardConsume() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/getStationStores", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "获取油站") public ResponseData getStationStores() { try { Map mapPost = new HashMap<>(); mapPost.put("apiKey" , "0C7897EA3BD96156A5881618FF2FF645"); mapPost.put("merchId" , "20230258302"); Map map = new HashMap<>(); map.put("apiKey" , "0C7897EA3BD96156A5881618FF2FF645"); map.put("merchId" , "20230258302"); mapPost.put("sign" , WxUtils.generateSignApi(map, MapUtils.getString(map, "apiKey"), WXPayConstants.SignType.MD5)); return ResponseMsgUtil.success(HttpsUtils.doPost("http://localhost:9902/v1/refuelOnline/getStationStores" , mapPost , new HashMap<>())); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/phoneBillOrderError", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "话费订单错误") public ResponseData phoneBillOrderError() { List highOrders = orderService.phoneErrorOrder(); for (HighOrder order: highOrders) { try { outRechargeOrderService.rechargeOrderHandle(order.getOrderNo()); } catch (Exception e) { log.error("HighCouponSchedule --> expiredCoupon() error!", e); } } return ResponseMsgUtil.success("操作成功"); } @RequestMapping(value = "/checkOrderByOrderNo", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "根据订单号话费查询是否可以退款") public ResponseData checkOrderByOrderNo(@RequestParam(name = "orderNo", required = true) String orderNo) { try { // 定义话费充值业务订单模型 or 充值记录订单模型 OutRechargeOrder outRechargeOrder = outRechargeOrderService.findByOrderNo(orderNo); OutRechargeChildOrder childOrder = outRechargeOrder.getOutRechargeChildOrders().get(0); // -1 取消,0充值中 ,1充值成功,2充值失败,3部分成功 Integer status = outRechargeOrderService.getRechargeOrderLegality(outRechargeOrder , childOrder); return ResponseMsgUtil.success(status); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/orderRefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "订单退款") public ResponseData orderRefund(@RequestParam(name = "orderNo", required = true) String orderNo) { try { Calendar createTimeS = Calendar.getInstance(); createTimeS.set(Calendar.DATE, 17); createTimeS.set(Calendar.HOUR_OF_DAY , 00); createTimeS.set(Calendar.MINUTE , 00); createTimeS.set(Calendar.SECOND , 00); Calendar createTimeE = Calendar.getInstance(); createTimeE.set(Calendar.DATE, 20); createTimeE.set(Calendar.HOUR_OF_DAY , 15); createTimeE.set(Calendar.MINUTE , 25); createTimeE.set(Calendar.SECOND , 00); Map param = new HashMap<>(); // param.put("createTimeS", createTimeS.getTimeInMillis()); // param.put("createTimeE", createTimeE.getTimeInMillis()); param.put("orderNo", orderNo); List orderRefundList = orderRefundService.getRefundOrderList(param); for (HighOrderRefund orderRefund : orderRefundList) { try { orderRefundService.refundPrice( orderRefund.getRefundOrderNo(), orderService.getOrderDetailByNo(orderRefund.getOrderNo()), OrderPayType.getDataByType(orderRefund.getPayType()), orderRefund.getRefundPrice(), orderRefund.getRefundIntegral() ); orderRefund.setExt1("true"); } catch (Exception e) { orderRefund.setExt1("false"); } finally { orderRefundService.update(orderRefund); } } return ResponseMsgUtil.success("退款成功"); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } public String orderTitle(OutRechargeOrder outRechargeOrder) { // 1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 // 101.待支付 102.已支付 100.已完成 104.已取消 105.已退款 switch (outRechargeOrder.getOperatorType()) { case 1: return outRechargeOrder.getRechargeContent() + "电信话费充值" + outRechargeOrder.getRechargePrice() + "元"; case 2: return outRechargeOrder.getRechargeContent() + "移动话费充值" + outRechargeOrder.getRechargePrice() + "元"; case 3: return outRechargeOrder.getRechargeContent() + "联通话费充值" + outRechargeOrder.getRechargePrice() + "元"; default: return null; } } } \ No newline at end of file + package com.bweb.controller; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.alipay.api.domain.ForbbidenTime; import com.alipay.api.domain.OfferObject; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; import com.hai.common.pay.util.sdk.WXPayConstants; import com.hai.common.utils.*; import com.hai.config.*; import com.hai.entity.*; import com.hai.model.OrderRefundModel; import com.hai.model.ResponseData; import com.hai.order.service.OrderRefundService; import com.hai.order.service.OrderService; import com.hai.order.type.OrderPayType; import com.hai.order.type.OrderProductType; import com.hai.order.type.OrderRefundOpUserType; import com.hai.order.utils.OrderUtil; import com.hai.service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.math.BigDecimal; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * @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 OutRechargeOrderService outRechargeOrderService; @Resource private OrderService orderService; @Resource private OrderRefundService orderRefundService; @Resource private HighOrderService highOrderService; @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 = "/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, ""); } JSONArray array = HuiLianTongUnionCardConfig.resolveResponse(consumptionRecord.getString("data")).getJSONArray("records"); return ResponseMsgUtil.success(array); } catch (Exception e) { log.error("HighUserCardController --> getHuiLianTongCardConsume() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/getStationStores", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "获取油站") public ResponseData getStationStores() { try { Map mapPost = new HashMap<>(); mapPost.put("apiKey" , "0C7897EA3BD96156A5881618FF2FF645"); mapPost.put("merchId" , "20230258302"); Map map = new HashMap<>(); map.put("apiKey" , "0C7897EA3BD96156A5881618FF2FF645"); map.put("merchId" , "20230258302"); System.out.println(map); mapPost.put("sign" , WxUtils.generateSignApi(map, MapUtils.getString(map, "apiKey"), WXPayConstants.SignType.MD5)); return ResponseMsgUtil.success(HttpsUtils.doPost("http://localhost:9902/v1/refuelOnline/getStationStores" , mapPost , new HashMap<>())); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/createOrder", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "创建订单") public ResponseData createOrder() { try { Map mapPost = new HashMap<>(); mapPost.put("apiKey" , "0C7897EA3BD96156A5881618FF2FF645"); mapPost.put("merchId" , "20230258302"); mapPost.put("timetable" , new Date().getTime()); mapPost.put("orderNo" , "TEST" + OrderUtil.generateOrderNo()); mapPost.put("productType" , OrderProductType.PRODUCT_TYPE6.getNumber()); mapPost.put("notifyUrl" , "test"); JSONObject object = new JSONObject(); object.put("refuelPrice" , new BigDecimal(100)); object.put("gasOilNo" , "92"); object.put("gasGunNo" , "1"); object.put("storeCode" , "54000"); mapPost.put("content" , object.toJSONString()); System.out.println(mapPost); Map map = new HashMap<>(); map.put("apiKey" , "0C7897EA3BD96156A5881618FF2FF645"); map.put("merchId" , "20230258302"); map.put("timetable" , mapPost.get("timetable")); map.put("orderNo" , mapPost.get("orderNo")); map.put("productType" , OrderProductType.PRODUCT_TYPE6.getNumber().toString()); map.put("content" , object.toString()); System.out.println(map); mapPost.put("sign" , WxUtils.generateSignApi(map, MapUtils.getString(map, "apiKey"), WXPayConstants.SignType.MD5)); return ResponseMsgUtil.success(HttpsUtils.doPost("http://localhost:9902/v1/order/createOrder" , mapPost , new HashMap<>())); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/payOrder", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "支付订单") public ResponseData payOrder(@RequestParam(name = "mchOrderNo", required = true) String mchOrderNo) { try { Map mapPost = new HashMap<>(); mapPost.put("apiKey" , "0C7897EA3BD96156A5881618FF2FF645"); mapPost.put("merchId" , "20230258302"); mapPost.put("mchOrderNo" , mchOrderNo); Map map = new HashMap<>(); map.put("apiKey" , "0C7897EA3BD96156A5881618FF2FF645"); map.put("merchId" , "20230258302"); map.put("mchOrderNo" , mchOrderNo); System.out.println(map); mapPost.put("sign" , WxUtils.generateSignApi(map, MapUtils.getString(map, "apiKey"), WXPayConstants.SignType.MD5)); return ResponseMsgUtil.success(HttpsUtils.doPost("http://localhost:9902/v1/order/orderPay" , mapPost , new HashMap<>())); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/queryOrderDetail", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询订单详情") public ResponseData queryOrderDetail(@RequestParam(name = "mchOrderNo", required = true) String mchOrderNo) { try { Map mapPost = new HashMap<>(); mapPost.put("apiKey" , "0C7897EA3BD96156A5881618FF2FF645"); mapPost.put("merchId" , "20230258302"); mapPost.put("mchOrderNo" , mchOrderNo); Map map = new HashMap<>(); map.put("apiKey" , "0C7897EA3BD96156A5881618FF2FF645"); map.put("merchId" , "20230258302"); map.put("mchOrderNo" , mchOrderNo); System.out.println(map); mapPost.put("sign" , WxUtils.generateSignApi(map, MapUtils.getString(map, "apiKey"), WXPayConstants.SignType.MD5)); return ResponseMsgUtil.success(HttpsUtils.doPost("http://localhost:9902/v1/order/queryOrderDetail" , mapPost , new HashMap<>())); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/phoneBillOrderError", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "话费订单错误") public ResponseData phoneBillOrderError() { List highOrders = orderService.phoneErrorOrder(); for (HighOrder order: highOrders) { try { outRechargeOrderService.rechargeOrderHandle(order.getOrderNo()); } catch (Exception e) { log.error("HighCouponSchedule --> expiredCoupon() error!", e); } } return ResponseMsgUtil.success("操作成功"); } @RequestMapping(value = "/checkOrderByOrderNo", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "根据订单号话费查询是否可以退款") public ResponseData checkOrderByOrderNo(@RequestParam(name = "orderNo", required = true) String orderNo) { try { // 定义话费充值业务订单模型 or 充值记录订单模型 OutRechargeOrder outRechargeOrder = outRechargeOrderService.findByOrderNo(orderNo); OutRechargeChildOrder childOrder = outRechargeOrder.getOutRechargeChildOrders().get(0); // -1 取消,0充值中 ,1充值成功,2充值失败,3部分成功 Integer status = outRechargeOrderService.getRechargeOrderLegality(outRechargeOrder , childOrder); return ResponseMsgUtil.success(status); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } // @RequestMapping(value = "/deposit", method = RequestMethod.GET) // @ResponseBody // @ApiOperation(value = "工会卡充值") // public ResponseData deposit(@RequestParam(name = "orderNo", required = true) String orderNo) { // try { // // HighOrder order = highOrderService.getOrderByOrderNo(orderNo); // HighChildOrder highChildOrder = order.getHighChildOrderList().get(0); // // // 汇联通充值 // String goodsDesc = "汇联通充值"+order.getPayPrice()+"元"; // String tranDesc = ""; // String businessType = "ghk_deposit"; // // // // // 汇联通卡充值 // JSONObject deposit = HuiLianTongUnionCardConfig.deposit(order.getOrderNo(), highChildOrder.getGoodsSpecName(), order.getPayPrice(), businessType, order.getPaySerialNo(), goodsDesc); // // return ResponseMsgUtil.success( HuiLianTongUnionCardConfig.resolveResponse(deposit.getString("data"))); // } catch (Exception e) { // log.error("HighOrderController --> getBackendToken() error!", e); // return ResponseMsgUtil.exception(e); // } // } @RequestMapping(value = "/orderRefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "订单退款") public ResponseData orderRefund(@RequestParam(name = "orderNo", required = true) String orderNo) { try { Calendar createTimeS = Calendar.getInstance(); createTimeS.set(Calendar.DATE, 17); createTimeS.set(Calendar.HOUR_OF_DAY , 00); createTimeS.set(Calendar.MINUTE , 00); createTimeS.set(Calendar.SECOND , 00); Calendar createTimeE = Calendar.getInstance(); createTimeE.set(Calendar.DATE, 20); createTimeE.set(Calendar.HOUR_OF_DAY , 15); createTimeE.set(Calendar.MINUTE , 25); createTimeE.set(Calendar.SECOND , 00); Map param = new HashMap<>(); // param.put("createTimeS", createTimeS.getTimeInMillis()); // param.put("createTimeE", createTimeE.getTimeInMillis()); param.put("orderNo", orderNo); List orderRefundList = orderRefundService.getRefundOrderList(param); for (HighOrderRefund orderRefund : orderRefundList) { try { orderRefundService.refundPrice( orderRefund.getRefundOrderNo(), orderService.getOrderDetailByNo(orderRefund.getOrderNo()), OrderPayType.getDataByType(orderRefund.getPayType()), orderRefund.getRefundPrice(), orderRefund.getRefundIntegral() ); orderRefund.setExt1("true"); } catch (Exception e) { orderRefund.setExt1("false"); } finally { orderRefundService.update(orderRefund); } } return ResponseMsgUtil.success("退款成功"); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } public String orderTitle(OutRechargeOrder outRechargeOrder) { // 1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 // 101.待支付 102.已支付 100.已完成 104.已取消 105.已退款 switch (outRechargeOrder.getOperatorType()) { case 1: return outRechargeOrder.getRechargeContent() + "电信话费充值" + outRechargeOrder.getRechargePrice() + "元"; case 2: return outRechargeOrder.getRechargeContent() + "移动话费充值" + outRechargeOrder.getRechargePrice() + "元"; case 3: return outRechargeOrder.getRechargeContent() + "联通话费充值" + outRechargeOrder.getRechargePrice() + "元"; default: return null; } } } \ No newline at end of file diff --git a/hai-bweb/src/main/java/com/bweb/controller/LoginController.java b/hai-bweb/src/main/java/com/bweb/controller/LoginController.java index 3c9865a0..dc46a1de 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/LoginController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/LoginController.java @@ -71,6 +71,12 @@ public class LoginController { @Resource private HighGasStaffService gasStaffService; + @Resource + private ApiMerchantsService apiMerchantsService; + + @Resource + private ApiIpAddressService apiIpAddressService; + @RequestMapping(value="/userLogin",method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "机构用户登录({'loginName':'','password':''})") @@ -232,6 +238,21 @@ public class LoginController { throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_STORE_NOF_FOUND, ""); } userInfoModel.setMerchantStore(merchantStore); + } else if (secUser.getObjectType() == 21) { + // 查询APi + ApiMerchants apiMerchants = apiMerchantsService.findById(secUser.getObjectId()); + if(apiMerchants == null){ + log.error("login error!","当前账户不存在"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "当前账户不存在"); + } + if(apiMerchants.getStatus() != 100) { + log.error("login error!","账户状态异常,请联系管理员"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "账户状态异常,请联系管理员"); + } + ApiIpAddress apiIpAddress = apiIpAddressService.findByMchId(apiMerchants.getMchId()); + apiMerchants.setExt1(apiIpAddress.getIpAddress()); + userInfoModel.setApiMerchants(apiMerchants); + } else { log.error("login error!","用户信息错误"); throw ErrorHelp.genException(SysCode.System, ErrorCode.SEC_USER_EXPIRED, ""); 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 b6f2624c..d6f1fd66 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/OutRechargePriceController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/OutRechargePriceController.java @@ -323,7 +323,8 @@ public class OutRechargePriceController { @ResponseBody @ApiOperation(value = "获取充值产品编码列表") public ResponseData getRechargeCodeList(@RequestParam(value = "id", required = true) Long id, - @RequestParam(value = "codeType", required = true) String codeType) { + @RequestParam(value = "codeType", required = true) String codeType, + @RequestParam(value = "type", required = true) Integer type) { try { List list = commonService.mappingSysNameOl(codeType); @@ -334,7 +335,7 @@ public class OutRechargePriceController { JSONObject object = new JSONObject(); Map map = new HashMap<>(); - map.put("type" , 1); + map.put("type" , type); map.put("sourceId" , id); map.put("rechargePlatform" , dictionary.getCodeValue()); BsRechargeCode rechargeCode = bsRechargeCodeService.findByMap(map); diff --git a/hai-order/src/main/java/com/web/controller/OrderController.java b/hai-order/src/main/java/com/web/controller/OrderController.java index c109021b..af003187 100644 --- a/hai-order/src/main/java/com/web/controller/OrderController.java +++ b/hai-order/src/main/java/com/web/controller/OrderController.java @@ -108,6 +108,11 @@ public class OrderController { log.error("OrderController -> create() error!",""); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请输入充值内容!"); } + } else if (childModel.getGoodsType().equals(OrderChildGoodsType.TYPE4.getNumber()) || childModel.getGoodsType().equals(OrderChildGoodsType.TYPE9.getNumber())|| childModel.getGoodsType().equals(OrderChildGoodsType.TYPE10.getNumber())) { + if (childModel.getCustomerMobile() == null) { + log.error("OrderController -> create() error!",""); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请输入下单手机号!"); + } } } diff --git a/hai-order/src/main/java/com/web/controller/notify/MobileRechargeNotifyController.java b/hai-order/src/main/java/com/web/controller/notify/MobileRechargeNotifyController.java index 9a2c5b03..1388bc34 100644 --- a/hai-order/src/main/java/com/web/controller/notify/MobileRechargeNotifyController.java +++ b/hai-order/src/main/java/com/web/controller/notify/MobileRechargeNotifyController.java @@ -166,9 +166,9 @@ public class MobileRechargeNotifyController { // 充值回调结果处理 private void callbackResult(String orderNo) { + OutRechargeChildOrder childOrder = outRechargeChildOrderService.findByOrderNo(orderNo); // 查询充值订单 - OutRechargeOrder rechargeOrder = outRechargeOrderService.findByOrderNo(orderNo); - OutRechargeChildOrder childOrder = rechargeOrder.getOutRechargeChildOrders().get(0); + OutRechargeOrder rechargeOrder = outRechargeOrderService.findByOrderId(childOrder.getParentOrderId()); childOrder.setStatus(103); childOrder.setUpdateTime(new Date()); diff --git a/hai-service/src/main/java/com/hai/dao/OutRechargePriceMapperExt.java b/hai-service/src/main/java/com/hai/dao/OutRechargePriceMapperExt.java index d91bb66d..d2c8282c 100644 --- a/hai-service/src/main/java/com/hai/dao/OutRechargePriceMapperExt.java +++ b/hai-service/src/main/java/com/hai/dao/OutRechargePriceMapperExt.java @@ -24,7 +24,7 @@ public interface OutRechargePriceMapperExt { "and operator_type = #{param.operatorType} " + "and company_id = #{param.companyId} " + "and product_type = 9 " + - "order by sort asc; " + + "order by status asc ,sort asc; " + " "}) @Results({ @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), diff --git a/hai-service/src/main/java/com/hai/entity/ApiAmountRecord.java b/hai-service/src/main/java/com/hai/entity/ApiAmountRecord.java index da3277e6..266c3963 100644 --- a/hai-service/src/main/java/com/hai/entity/ApiAmountRecord.java +++ b/hai-service/src/main/java/com/hai/entity/ApiAmountRecord.java @@ -45,7 +45,17 @@ public class ApiAmountRecord implements Serializable { private String mchId; /** - * 1:充值金额 2:订单退款 3 话费消费 + * 产品类型 + * 1:星巴克 + * 2:肯德基 + * 3:会员充值 + * 4:积分充值 + * 5:购买卡券 + * 6:加油服务 + * 7:优惠券包 + * 8:汇联通充值 + * 9:话费充值 + * 99 商户充值 */ private Integer sourceType; diff --git a/hai-service/src/main/java/com/hai/openApi/config/PriceComputeConfig.java b/hai-service/src/main/java/com/hai/openApi/config/PriceComputeConfig.java new file mode 100644 index 00000000..5aa0e40a --- /dev/null +++ b/hai-service/src/main/java/com/hai/openApi/config/PriceComputeConfig.java @@ -0,0 +1,62 @@ +package com.hai.openApi.config; + +import com.hai.entity.ApiAmountRecord; +import com.hai.entity.ApiMerchants; +import com.hai.order.type.OrderProductType; +import com.hai.service.ApiAmountRecordService; +import com.hai.service.ApiMerchantsService; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.util.Date; + +@Component +public class PriceComputeConfig { + + @Resource + private ApiMerchantsService apiMerchantsService; + + @Resource + private ApiAmountRecordService apiAmountRecordService; + + public Boolean mchBalance(ApiMerchants apiMerchants , BigDecimal price , String orderNo) { + + + // 当前账号余额是否可以充值当前金额 + if (apiMerchants.getAmounts().compareTo(price) < 0) { + return false; + } + + // 插入金额记录 + // 变更前金额 + BigDecimal beforeAmount = apiMerchants.getAmounts(); + // 计算金额 + apiMerchants.setAmounts(apiMerchants.getAmounts().subtract(price)); + // 变更后金额 + BigDecimal afterAmount = apiMerchants.getAmounts(); + + apiMerchantsService.updateApiMerchants(apiMerchants); + + ApiAmountRecord apiAmountRecord = new ApiAmountRecord(); + + apiAmountRecord.setCreateTime(new Date()); + apiAmountRecord.setUpdateTime(new Date()); + apiAmountRecord.setMchId(apiMerchants.getMchId()); + + apiAmountRecord.setStatus(100); + apiAmountRecord.setAmount(price); + apiAmountRecord.setAfterAmount(afterAmount); + apiAmountRecord.setBeforeAmount(beforeAmount); + apiAmountRecord.setAmountType(2); + apiAmountRecord.setSourceType(OrderProductType.PRODUCT_TYPE6.getNumber()); + apiAmountRecord.setSourceOrderNo(orderNo); + apiAmountRecord.setSourceId(apiMerchants.getId()); + apiAmountRecord.setSourceContent(apiMerchants.getMerchantName() + "|在线加油|扣款" + price.setScale(2, BigDecimal.ROUND_HALF_DOWN)); + + apiAmountRecordService.insertAmountRecord(apiAmountRecord); + + + return true; + } +} diff --git a/hai-service/src/main/java/com/hai/openApi/service/ApiMchProductService.java b/hai-service/src/main/java/com/hai/openApi/service/ApiMchProductService.java index 8dc3013e..3d6677f7 100644 --- a/hai-service/src/main/java/com/hai/openApi/service/ApiMchProductService.java +++ b/hai-service/src/main/java/com/hai/openApi/service/ApiMchProductService.java @@ -65,7 +65,7 @@ public interface ApiMchProductService { * @Param [mchId, productType] * @Return com.hai.entity.ApiMchProduct */ - Boolean whereExistence(String mchId , Integer productType); + Boolean whereExistence(String mchId , Integer productType , Long merchantId); /** * @Author Sum1Dream diff --git a/hai-service/src/main/java/com/hai/openApi/service/ApiOrderCreateHandleService.java b/hai-service/src/main/java/com/hai/openApi/service/ApiOrderCreateHandleService.java new file mode 100644 index 00000000..49da5205 --- /dev/null +++ b/hai-service/src/main/java/com/hai/openApi/service/ApiOrderCreateHandleService.java @@ -0,0 +1,31 @@ +package com.hai.openApi.service; + +import com.alibaba.fastjson.JSONObject; +import com.hai.entity.ApiOrder; +import com.hai.entity.HighChildOrder; +import com.hai.entity.HighDiscountUserRel; +import com.hai.entity.HighOrder; +import com.hai.order.model.CreateOrderChildModel; +import com.hai.order.model.CreateOrderModel; + +import java.util.List; + +/** + * 创建订单-业务校验、组装数据 + * @className: CreateOrderCheckService + * @author: HuRui + * @date: 2022/8/25 + **/ +public interface ApiOrderCreateHandleService { + + /** + * @Author Sum1Dream + * @Name oilHandle + * @Description // 在线加油校验操作 + * @Date 13:59 2023/3/1 + * @Param [object] + * @Return com.hai.entity.ApiOrder + */ + ApiOrder oilHandle(JSONObject object) throws Exception; + +} diff --git a/hai-service/src/main/java/com/hai/openApi/service/ApiOrderService.java b/hai-service/src/main/java/com/hai/openApi/service/ApiOrderService.java new file mode 100644 index 00000000..00f8642f --- /dev/null +++ b/hai-service/src/main/java/com/hai/openApi/service/ApiOrderService.java @@ -0,0 +1,60 @@ +package com.hai.openApi.service; + +import com.alibaba.fastjson.JSONObject; +import com.hai.entity.ApiOrder; + +import java.util.List; +import java.util.Map; + + +/** + * @Author Sum1Dream + * @Name orderService + * @Description // 订单业务 + * @Date 17:43 2023/2/28 + * @Param + * @Return + */ +public interface ApiOrderService { + + /** + * @Author Sum1Dream + * @Name createOrder + * @Description // 创建订单 + * @Date 17:44 2023/2/28 + * @Param [object] + * @Return void + */ + ApiOrder createOrder(JSONObject object) throws Exception; + + + /** + * @Author Sum1Dream + * @Name payOrder + * @Description // 创建订单 + * @Date 17:44 2023/2/28 + * @Param [object] + * @Return void + */ + ApiOrder payOrder(JSONObject object) throws Exception; + + /** + * @Author Sum1Dream + * @Name getOrderByMap + * @Description // 查询订单 + * @Date 17:49 2023/2/28 + * @Param [map] + * @Return com.hai.entity.ApiOrder + */ + List getOrderByMap(Map map); + + /** + * @Author Sum1Dream + * @Name findByOrderNo + * @Description // 根据订单号查询订单 + * @Date 20:40 2023/3/1 + * @Param [mchOrderNo, orderNo] + * @Return com.hai.entity.ApiOrder + */ + ApiOrder findByOrderNo(String mchOrderNo , String orderNo); +} diff --git a/hai-service/src/main/java/com/hai/openApi/service/impl/ApiMchProductServiceImpl.java b/hai-service/src/main/java/com/hai/openApi/service/impl/ApiMchProductServiceImpl.java index 68b78092..6b4088fc 100644 --- a/hai-service/src/main/java/com/hai/openApi/service/impl/ApiMchProductServiceImpl.java +++ b/hai-service/src/main/java/com/hai/openApi/service/impl/ApiMchProductServiceImpl.java @@ -55,19 +55,6 @@ public class ApiMchProductServiceImpl implements ApiMchProductService { apiMchProduct.setCreateTime(new Date()); apiMchProduct.setUpdateTime(new Date()); - if (whereExistence((object.getString("mchId")) , Integer.valueOf(productType.toString()))) { - continue; - } - - if (secConfigService.isConfig(OrderProductType.getDataByType(Integer.valueOf(productType.toString())).getApiCode() , object.getString("mchId"))) { - continue; - } - - // 插入接口权限 - SecConfig secConfig = new SecConfig(); - secConfig.setCodeValue(object.getString("mchId")); - secConfig.setCodeType(OrderProductType.getDataByType(Integer.valueOf(productType.toString())).getApiCode()); - secConfigService.insertSecConfig(secConfig); if (Integer.valueOf(productType.toString()).equals(OrderProductType.PRODUCT_TYPE6.getNumber())) { if (object.getLong("companyId") == null || @@ -77,14 +64,30 @@ public class ApiMchProductServiceImpl implements ApiMchProductService { } JSONArray merchantIdS = object.getJSONArray("merchantId"); for (Object merchantId : merchantIdS) { + + if (whereExistence((object.getString("mchId")) , Integer.valueOf(productType.toString()) , Long.valueOf(merchantId.toString()))) { + continue; + } + apiMchProduct.setMerchantId(Long.valueOf(merchantId.toString())); apiMchProduct.setCompanyId(object.getLong("companyId")); insertMchProduct(apiMchProduct); } } else { + insertMchProduct(apiMchProduct); } + if (secConfigService.isConfig(OrderProductType.getDataByType(Integer.valueOf(productType.toString())).getApiCode() , object.getString("mchId"))) { + continue; + } + + // 插入接口权限 + SecConfig secConfig = new SecConfig(); + secConfig.setCodeValue(object.getString("mchId")); + secConfig.setCodeType(OrderProductType.getDataByType(Integer.valueOf(productType.toString())).getApiCode()); + secConfigService.insertSecConfig(secConfig); + } } @@ -116,10 +119,10 @@ public class ApiMchProductServiceImpl implements ApiMchProductService { } @Override - public Boolean whereExistence(String mchId, Integer productType) { + public Boolean whereExistence(String mchId, Integer productType , Long merchantId) { ApiMchProductExample example = new ApiMchProductExample(); - example.createCriteria().andMchIdEqualTo(mchId).andProductTypeEqualTo(productType); + example.createCriteria().andMchIdEqualTo(mchId).andProductTypeEqualTo(productType).andMerchantIdEqualTo(merchantId); return apiMchProductMapper.selectByExample(example).size() > 0; } @@ -135,6 +138,9 @@ public class ApiMchProductServiceImpl implements ApiMchProductService { if (StringUtils.isNotBlank(MapUtils.getString(map, "mchId"))) { criteria.andMchIdEqualTo(MapUtils.getString(map, "mchId")); } + if (MapUtils.getLong(map, "merchantId") != null) { + criteria.andMerchantIdEqualTo(MapUtils.getLong(map, "merchantId")); + } List list = apiMchProductMapper.selectByExample(example); diff --git a/hai-service/src/main/java/com/hai/openApi/service/impl/ApiOrderCreateHandleServiceImpl.java b/hai-service/src/main/java/com/hai/openApi/service/impl/ApiOrderCreateHandleServiceImpl.java new file mode 100644 index 00000000..909c832e --- /dev/null +++ b/hai-service/src/main/java/com/hai/openApi/service/impl/ApiOrderCreateHandleServiceImpl.java @@ -0,0 +1,97 @@ +package com.hai.openApi.service.impl; + +import com.alibaba.fastjson.JSONObject; +import com.hai.common.exception.ErrorCode; +import com.hai.common.exception.ErrorHelp; +import com.hai.common.exception.SysCode; +import com.hai.entity.*; +import com.hai.openApi.config.PriceComputeConfig; +import com.hai.openApi.service.ApiMchProductService; +import com.hai.openApi.service.ApiOrderCreateHandleService; +import com.hai.service.ApiMerchantsService; +import com.hai.service.HighGasOilPriceService; +import com.hai.service.HighMerchantStoreService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +@Service("apiOrderCreateHandleService") +public class ApiOrderCreateHandleServiceImpl implements ApiOrderCreateHandleService { + + @Resource + private ApiMerchantsService apiMerchantsService; + + @Resource + private HighGasOilPriceService highGasOilPriceService; + + @Resource + private PriceComputeConfig priceComputeConfig; + + @Resource + private HighMerchantStoreService highMerchantStoreService; + + @Resource + private ApiMchProductService apiMchProductService; + + @Override + public ApiOrder oilHandle(JSONObject object) throws Exception { + + // 获取下单内容 + JSONObject dataObject = JSONObject.parseObject(object.getString("content")); + + // 查询油枪价 + HighGasOilPrice highGasOilPrice = highGasOilPriceService.getGasOilPriceByStoreAndOilNo(dataObject.getLong("storeCode") , dataObject.getString("gasOilNo")); + + // 查询api商户 + ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); + + // 查询加油门店 + HighMerchantStore merchantStore = highMerchantStoreService.getMerchantStoreById(dataObject.getLong("storeCode")); + + // 查询折扣比例 + Map mchProductMap = new HashMap<>(); + mchProductMap.put("productType" , object.getString("productType")); + mchProductMap.put("mchId" , object.getString("merchId")); + mchProductMap.put("merchantId" , merchantStore.getMerchantId()); + ApiMchProduct mchProduct = apiMchProductService.findByMap(mchProductMap); + + BigDecimal price = dataObject.getBigDecimal("refuelPrice").multiply(mchProduct.getDiscount()).divide(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_DOWN); + + // 判断金额是否充足 + if (apiMerchants.getAmounts().compareTo(price) < 0) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.INSUFFICIENT_BALANCE); + } + + // 组装内容 + JSONObject jsonObject = new JSONObject(); + jsonObject.put("oilNo" , highGasOilPrice.getOilNo()); + jsonObject.put("oilNoName" , highGasOilPrice.getOilNoName()); + jsonObject.put("priceGun" , highGasOilPrice.getPriceGun()); + jsonObject.put("priceCost" , highGasOilPrice.getPriceGun().multiply(mchProduct.getDiscount()).divide(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP)); + jsonObject.put("oilTypeName" , highGasOilPrice.getOilTypeName()); + jsonObject.put("storeName" , merchantStore.getStoreName()); + jsonObject.put("address" , merchantStore.getAddress()); + jsonObject.put("regionName" , merchantStore.getRegionName()); + + // 组装api订单 + ApiOrder apiOrder = new ApiOrder(); + apiOrder.setCreateTime(new Date()); + apiOrder.setTitle(apiMerchants.getMerchantName() + "|在线加油|扣款" + price); + apiOrder.setFacePrice(dataObject.getBigDecimal("refuelPrice")); + apiOrder.setCostPrice(price); + apiOrder.setMchId(object.getString("merchId")); + apiOrder.setMchName(apiMerchants.getMerchantName()); + apiOrder.setUpdateTime(new Date()); + apiOrder.setProductType(object.getInteger("productType")); + apiOrder.setMchOrderNo(object.getString("orderNo")); + apiOrder.setOrderPrice(dataObject.getBigDecimal("refuelPrice")); + apiOrder.setNotifyUrl(object.getString("notifyUrl")); + apiOrder.setContent(jsonObject.toJSONString()); + + return apiOrder; + } +} diff --git a/hai-service/src/main/java/com/hai/openApi/service/impl/ApiOrderServiceImpl.java b/hai-service/src/main/java/com/hai/openApi/service/impl/ApiOrderServiceImpl.java new file mode 100644 index 00000000..687afa58 --- /dev/null +++ b/hai-service/src/main/java/com/hai/openApi/service/impl/ApiOrderServiceImpl.java @@ -0,0 +1,201 @@ +package com.hai.openApi.service.impl; + +import com.alibaba.fastjson.JSONObject; +import com.hai.common.exception.ErrorCode; +import com.hai.common.exception.ErrorHelp; +import com.hai.common.exception.SysCode; +import com.hai.common.utils.DateUtil; +import com.hai.dao.ApiOrderMapper; +import com.hai.entity.ApiMerchants; +import com.hai.entity.ApiOrder; +import com.hai.entity.ApiOrderExample; +import com.hai.entity.HighOrder; +import com.hai.openApi.service.ApiOrderCreateHandleService; +import com.hai.openApi.service.ApiOrderService; +import com.hai.order.model.CreateOrderChildModel; +import com.hai.order.model.CreateOrderModel; +import com.hai.order.service.OrderPayBeforeService; +import com.hai.order.service.OrderPayService; +import com.hai.order.service.OrderService; +import com.hai.order.type.OrderChildGoodsType; +import com.hai.order.type.OrderProductType; +import com.hai.order.type.OrderStatus; +import com.hai.order.utils.OrderUtil; +import com.hai.service.ApiMerchantsService; +import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Isolation; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.*; + +@Service("apiOrderService") +public class ApiOrderServiceImpl implements ApiOrderService { + + @Resource + private ApiMerchantsService apiMerchantsService; + + @Resource + private ApiOrderMapper apiOrderMapper; + + @Resource + private ApiOrderCreateHandleService orderCreateHandleService; + + @Resource + private OrderService orderService; + + @Resource + private OrderPayBeforeService orderPayBeforeService; + + @Resource + private OrderPayService orderPayService; + + @Resource + private ApiOrderService apiOrderService; + + @Override + @Transactional(rollbackFor=Exception.class,isolation = Isolation.SERIALIZABLE,propagation= Propagation.REQUIRES_NEW) + public ApiOrder createOrder(JSONObject object) throws Exception { + + ApiOrder apiOrder = new ApiOrder(); + + + // 获取下单内容 + JSONObject dataObject = JSONObject.parseObject(object.getString("content")); + + + CreateOrderModel createOrderModel = new CreateOrderModel(); + createOrderModel.setChildOrderList(new ArrayList<>()); + + // 查询订单 + Map orderMap = new HashMap<>(); + orderMap.put("mchOrderNo" , object.getString("orderNo")); + List apiOrderList = getOrderByMap(orderMap); + + ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); + + createOrderModel.setMemName(apiMerchants.getMerchantName()); + createOrderModel.setMemPhone(apiMerchants.getPhone()); + createOrderModel.setCompanyId(2L); + createOrderModel.setOrderNo(OrderUtil.generateOrderNo()); + + // 判断订单号是否重复 + if (apiOrderList.size() > 0) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.ORDER_ALREADY_EXISTS); + } + + // 处理加油订单 + if (OrderProductType.PRODUCT_TYPE6.getNumber().equals(object.getInteger("productType"))) { + apiOrder = orderCreateHandleService.oilHandle(object); + + // 组装子订单内容 + CreateOrderChildModel createOrderChildModel = new CreateOrderChildModel(); + createOrderChildModel.setMemName(apiMerchants.getMerchantName()); + createOrderChildModel.setMemPhone(apiMerchants.getPhone()); + createOrderChildModel.setCompanyId(2L); + createOrderChildModel.setGoodsType(OrderChildGoodsType.TYPE3.getNumber()); + createOrderChildModel.setGasGunNo(dataObject.getString("gasGunNo")); + createOrderChildModel.setGasOilNo(dataObject.getString("gasOilNo")); + createOrderChildModel.setStoreId(dataObject.getLong("storeCode")); + createOrderChildModel.setGoodsId(dataObject.getLong("storeCode")); + createOrderChildModel.setSaleCount(1); + createOrderChildModel.setIsTyAgent(false); + createOrderChildModel.setGoodsPrice(apiOrder.getOrderPrice()); + + // 组装订单 + createOrderModel.getChildOrderList().add(createOrderChildModel); + orderService.createOrder(createOrderModel); + } + apiOrder.setOrderNo(createOrderModel.getOrderNo()); + apiOrder.setStatus(1); + apiOrderMapper.insert(apiOrder); + + return apiOrder; + + } + + + @Override + @Transactional(rollbackFor=Exception.class,isolation = Isolation.SERIALIZABLE,propagation= Propagation.REQUIRES_NEW) + public ApiOrder payOrder(JSONObject object) { + + ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); + + ApiOrder apiOrder = apiOrderService.findByOrderNo(object.getString("mchOrderNo") , null); + + // 查询订单 + HighOrder order = orderService.getOrderDetailByNo(object.getString("orderNo")); + if(!order.getOrderStatus().equals(OrderStatus.STATUS1.getNumber())) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.ORDER_NO_STAY_PAY, ""); + } + + // 支付业务交易 + orderPayBeforeService.payOrderCheck(order); + + // 处理订单 + HighOrder highOrder = orderPayService.apiMchAmount(order , apiMerchants , apiOrder); + + if (highOrder.getOrderStatus() != OrderStatus.STATUS1.getNumber()) { + apiOrder.setStatus(highOrder.getOrderStatus()); + apiOrder.setUpdateTime(new Date()); + apiOrderMapper.updateByPrimaryKey(apiOrder); + } + + return apiOrder; + + } + + @Override + public List getOrderByMap(Map map) { + + ApiOrderExample example = new ApiOrderExample(); + ApiOrderExample.Criteria criteria = example.createCriteria(); + + + if (MapUtils.getInteger(map, "productType") != null) { + criteria.andProductTypeEqualTo(MapUtils.getInteger(map, "productType")); + } + if (StringUtils.isNotBlank(MapUtils.getString(map, "orderNo"))) { + criteria.andOrderNoEqualTo(MapUtils.getString(map, "orderNo")); + } + if (StringUtils.isNotBlank(MapUtils.getString(map, "mchOrderNo"))) { + criteria.andMchOrderNoEqualTo(MapUtils.getString(map, "mchOrderNo")); + } + if (StringUtils.isNotBlank(MapUtils.getString(map, "merchId"))) { + criteria.andMchIdEqualTo(MapUtils.getString(map, "merchId")); + } + if (StringUtils.isNotBlank(MapUtils.getString(map, "createTimeS")) && StringUtils.isNotBlank(MapUtils.getString(map, "createTimeE"))) { + criteria.andCreateTimeBetween( + DateUtil.format(MapUtils.getString(map, "createTimeS"), "yyyy-MM-dd HH:mm:ss"), + DateUtil.format(MapUtils.getString(map, "createTimeE"), "yyyy-MM-dd HH:mm:ss")); + } + + return apiOrderMapper.selectByExample(example); + } + + + @Override + public ApiOrder findByOrderNo(String mchOrderNo , String orderNo) { + ApiOrderExample example = new ApiOrderExample(); + ApiOrderExample.Criteria criteria = example.createCriteria(); + + if (mchOrderNo != null) { + criteria.andMchOrderNoEqualTo(mchOrderNo); + } + + if (orderNo != null) { + criteria.andOrderNoEqualTo(orderNo); + } + + List list = apiOrderMapper.selectByExample(example); + + if (list.size() > 0) { + return list.get(0); + } + + return null; + } +} diff --git a/hai-service/src/main/java/com/hai/order/model/CreateOrderChildModel.java b/hai-service/src/main/java/com/hai/order/model/CreateOrderChildModel.java index e480885f..fc090274 100644 --- a/hai-service/src/main/java/com/hai/order/model/CreateOrderChildModel.java +++ b/hai-service/src/main/java/com/hai/order/model/CreateOrderChildModel.java @@ -82,7 +82,7 @@ public class CreateOrderChildModel { /** ======================= 油站所需参数 ======================== **/ - /** ======================= 肯德基,星巴克,会员充值所需参数 ======================== **/ + /** ======================= 肯德基,星巴克,会员充值所需参数 start ======================== **/ // 下单电话 private String customerMobile; // 产品类型 1:星巴克 2:肯德基 3:会员充值 @@ -95,11 +95,11 @@ public class CreateOrderChildModel { private String storeCode; // 请求参数 private Object orderItems; - /** ======================= 肯德基,星巴克,会员充值所需参数 ======================== **/ + /** ======================= 肯德基,星巴克,会员充值所需参数 end ======================== **/ - /** ======================= 话费充值所需参数 ======================== **/ + /** ======================= 话费充值所需参数 start ======================== **/ // 充值内容 private String rechargeContent; - /** ======================= 话费充值所需参数 ======================== **/ + /** ======================= 话费充值所需参数 end ======================== **/ } diff --git a/hai-service/src/main/java/com/hai/order/model/CreateOrderModel.java b/hai-service/src/main/java/com/hai/order/model/CreateOrderModel.java index 8737882d..1124bf92 100644 --- a/hai-service/src/main/java/com/hai/order/model/CreateOrderModel.java +++ b/hai-service/src/main/java/com/hai/order/model/CreateOrderModel.java @@ -2,6 +2,7 @@ package com.hai.order.model; import lombok.Data; +import java.math.BigDecimal; import java.util.List; /** @@ -68,4 +69,5 @@ public class CreateOrderModel { */ private List childOrderList; + } diff --git a/hai-service/src/main/java/com/hai/order/service/OrderPayService.java b/hai-service/src/main/java/com/hai/order/service/OrderPayService.java index ef3447fb..ce3e977b 100644 --- a/hai-service/src/main/java/com/hai/order/service/OrderPayService.java +++ b/hai-service/src/main/java/com/hai/order/service/OrderPayService.java @@ -1,5 +1,7 @@ package com.hai.order.service; +import com.hai.entity.ApiMerchants; +import com.hai.entity.ApiOrder; import com.hai.entity.HighOrder; import com.hai.entity.HighUserCard; @@ -35,4 +37,14 @@ public interface OrderPayService { */ HighOrder oilCardFleetPay(HighOrder order, HighUserCard userCard, String carLicensePlate); + /** + * @Author Sum1Dream + * @Name apiMchAmount + * @Description // API商户金额支付 + * @Date 20:44 2023/3/1 + * @Param [order, apiMerchants] + * @Return com.hai.entity.HighOrder + */ + HighOrder apiMchAmount(HighOrder order , ApiMerchants apiMerchants , ApiOrder apiOrder); + } diff --git a/hai-service/src/main/java/com/hai/order/service/impl/OrderPayServiceImpl.java b/hai-service/src/main/java/com/hai/order/service/impl/OrderPayServiceImpl.java index 8b3055b9..60e08aa7 100644 --- a/hai-service/src/main/java/com/hai/order/service/impl/OrderPayServiceImpl.java +++ b/hai-service/src/main/java/com/hai/order/service/impl/OrderPayServiceImpl.java @@ -7,6 +7,7 @@ import com.hai.common.exception.SysCode; import com.hai.config.HuiLianTongUnionCardConfig; import com.hai.entity.*; import com.hai.enum_type.OilCardRecordSourceTypeEnum; +import com.hai.openApi.config.PriceComputeConfig; import com.hai.order.service.OrderPayService; import com.hai.order.service.OrderPaySuccessService; import com.hai.order.service.OrderService; @@ -49,6 +50,9 @@ public class OrderPayServiceImpl implements OrderPayService { @Resource private HighGasOrderService gasOrderService; + @Resource + private PriceComputeConfig priceComputeConfig; + @Override public HighOrder hltCardPay(HighOrder order, HighUserCard userCard) throws Exception { String goodsDesc = ""; @@ -151,4 +155,22 @@ public class OrderPayServiceImpl implements OrderPayService { userCard); } + @Override + public HighOrder apiMchAmount(HighOrder order, ApiMerchants apiMerchants , ApiOrder apiOrder) { + + + // 判断金额是否充足 + if (!priceComputeConfig.mchBalance(apiMerchants , apiOrder.getCostPrice() , apiOrder.getMchOrderNo())) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.INSUFFICIENT_BALANCE); + } + + // 处理订单业务 + return orderPaySuccessService.orderPaySuccessHandle( + order.getOrderNo(), + OrderPayType.PAY_TYPE9, + null, + order.getPayPrice(), + null); + + } } diff --git a/hai-service/src/main/java/com/hai/order/service/impl/OrderPaySuccessServiceImpl.java b/hai-service/src/main/java/com/hai/order/service/impl/OrderPaySuccessServiceImpl.java index 07e638e5..240f3d6f 100644 --- a/hai-service/src/main/java/com/hai/order/service/impl/OrderPaySuccessServiceImpl.java +++ b/hai-service/src/main/java/com/hai/order/service/impl/OrderPaySuccessServiceImpl.java @@ -472,16 +472,8 @@ public class OrderPaySuccessServiceImpl implements OrderPaySuccessService { // 下单 ApiMemberProduct memberProduct = apiMemberProductService.findById(order.getHighChildOrderList().get(0).getGoodsId()); - JSONObject object = QianZhuConfig.insertV2(memberProduct.getProductId() , order.getOrderNo() , order.getRemarks()); + QianZhuConfig.insertV2(memberProduct.getProductId() , order.getOrderNo() , order.getRemarks()); -// // 推送订单记录 -// HighGasOrderPush highGasOrderPush = new HighGasOrderPush(); -// highGasOrderPush.setType(OrderPushType.type8.getType()); -// highGasOrderPush.setOrderNo(order.getOrderNo()); -// highGasOrderPush.setCreateTime(new Date()); -// highGasOrderPush.setRequestContent(order.getOrderNo()); -// highGasOrderPush.setReturnContent(object.toJSONString()); -// highGasOrderPushMapper.insert(highGasOrderPush); } diff --git a/hai-service/src/main/java/com/hai/order/service/impl/OrderServiceImpl.java b/hai-service/src/main/java/com/hai/order/service/impl/OrderServiceImpl.java index 1cff5be2..ceb2f7a2 100644 --- a/hai-service/src/main/java/com/hai/order/service/impl/OrderServiceImpl.java +++ b/hai-service/src/main/java/com/hai/order/service/impl/OrderServiceImpl.java @@ -278,6 +278,7 @@ public class OrderServiceImpl implements OrderService { order.setTitle("+"+childOrder.getGoodsName()); } } + order.setRemarks(object.getString("customerMobile")); } else { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知业务类型"); } @@ -419,6 +420,7 @@ public class OrderServiceImpl implements OrderService { } } + order.setSurplusRefundPrice(new BigDecimal("0")); order.setSurplusRefundIntegral(0); order.setSearchTitle(order.getOrderNo()); diff --git a/hai-service/src/main/java/com/hai/order/type/OrderPayType.java b/hai-service/src/main/java/com/hai/order/type/OrderPayType.java index ca892b60..02355404 100644 --- a/hai-service/src/main/java/com/hai/order/type/OrderPayType.java +++ b/hai-service/src/main/java/com/hai/order/type/OrderPayType.java @@ -17,6 +17,7 @@ public enum OrderPayType { PAY_TYPE6(6, "银联分期"), PAY_TYPE7(7, "嗨森逛个人油卡"), PAY_TYPE8(8, "嗨森逛车队油卡"), + PAY_TYPE9(9, "API商户金额"), ; private Integer number; diff --git a/hai-service/src/main/java/com/hai/service/impl/ApiProductServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/ApiProductServiceImpl.java index 79ac0a15..58aeeaaf 100644 --- a/hai-service/src/main/java/com/hai/service/impl/ApiProductServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/ApiProductServiceImpl.java @@ -64,7 +64,6 @@ public class ApiProductServiceImpl implements ApiProductService { apiProduct = new ApiProduct(); apiProduct.setRechargePrice(priceBd); apiProduct.setRechargeType(object.getInteger("rechargeType")); - apiProduct.setPhoneRechargeType(object.getInteger("phoneRechargeType")); apiProduct.setOperatorType(object.getInteger("operatorType")); apiProduct.setRechargePlatform("-" + StringUtils.join(object.getJSONArray("rechargePlatform"), "-") + "-"); apiProduct.setCreateTime(new Date()); 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 66b8ee83..dec37c8a 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 @@ -903,19 +903,21 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { JSONObject jsonObject = RechargeConfig.checkOrderByHg(object); if (jsonObject.getJSONArray("data") == null) { - return -1; + return 99; } else { JSONArray objectJSONArray = jsonObject.getJSONArray("data"); JSONObject objectData; for (Object objects : objectJSONArray) { objectData = (JSONObject) objects; - // 充值中1成功2失败3已取消4部分充值5缓存订单 + // 0充值中,1成功,2失败,3已取消,4部分充值,5缓存订单 // -1取消,0充值中 ,1充值成功,2充值失败,3部分成功 - if (objectData.getInteger("status") == 1 || objectData.getInteger("status") == 5) { + if (objectData.getInteger("status") == 0 || objectData.getInteger("status") == 5) { return 0; - } else if (objectData.getInteger("status") == 2) { + } else if (objectData.getInteger("status") == 1) { return 1; + } else if (objectData.getInteger("status") == 2) { + return 2; } else if (objectData.getInteger("status") == 3) { return -1; } else if (objectData.getInteger("status") == 4) { diff --git a/v1/src/main/java/com/v1/config/ApiCommonConfig.java b/v1/src/main/java/com/v1/config/ApiCommonConfig.java index b13b60e4..d7651e28 100644 --- a/v1/src/main/java/com/v1/config/ApiCommonConfig.java +++ b/v1/src/main/java/com/v1/config/ApiCommonConfig.java @@ -31,7 +31,7 @@ public class ApiCommonConfig { ApiMchProduct apiMchProduct = ApiMchProductService.findByMap(map); - return price.multiply(apiMchProduct.getDiscount()).setScale(2, BigDecimal.ROUND_HALF_UP); + return price.multiply(apiMchProduct.getDiscount()).divide(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP); } diff --git a/v1/src/main/java/com/v1/controller/ApiOrderController.java b/v1/src/main/java/com/v1/controller/ApiOrderController.java deleted file mode 100644 index 4acee2d9..00000000 --- a/v1/src/main/java/com/v1/controller/ApiOrderController.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.v1.controller; - -import com.alibaba.fastjson.JSONObject; -import com.hai.common.exception.ErrorCode; -import com.hai.common.exception.ErrorHelp; -import com.hai.common.exception.SysCode; -import com.hai.common.utils.ResponseMsgUtil; -import com.hai.entity.ApiMerchants; -import com.hai.entity.ApiProductConfig; -import com.hai.model.ResponseData; -import com.hai.service.*; -import com.v1.config.ToolConfig; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; - -import javax.annotation.Resource; -import javax.servlet.http.HttpServletRequest; -import java.util.HashMap; -import java.util.Map; - -@Controller -@RequestMapping(value = "/apiOrder") -@Api(value = "API订单接口") -public class ApiOrderController { - - private static Logger log = LoggerFactory.getLogger(RechargeProductController.class); - - @Resource - private ApiMerchantsService apiMerchantsService; - - @Resource - private SecConfigService secConfigService; - - @Resource - private ApiProductService apiProductService; - - @Resource - private ApiOpenService apiOpenService; - - @RequestMapping(value = "/createOrder", method = RequestMethod.POST) - @ResponseBody - @ApiOperation(value = "充值预下单") - public ResponseData createOrder(@RequestBody JSONObject object , HttpServletRequest request ) { - try { - - String ip = ""; - // 有的user可能使用代理,为处理用户使用代理的情况,使用x-forwarded-for - if (request.getHeader("x-forwarded-for") == null) { - ip = request.getRemoteAddr(); - } else { - ip = request.getHeader("x-forwarded-for"); - } - - if (!secConfigService.isConfig("IP_WHITE" , ip)) { - log.error("createOrder error!", "非法ip地址,请联系管理人员!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.IP_ERROR, "非法ip地址,请联系管理人员!"); - } - - if (StringUtils.isBlank(object.getString("mobile")) || - StringUtils.isBlank(object.getString("apiProductId")) || - StringUtils.isBlank(object.getString("apiKey")) || - StringUtils.isBlank(object.getString("orderType")) || - StringUtils.isBlank(object.getString("timetable")) || - StringUtils.isBlank(object.getString("orderNo")) || - StringUtils.isBlank(object.getString("notifyUrl")) || - StringUtils.isBlank(object.getString("sign")) || - StringUtils.isBlank(object.getString("merchId")) - ) { - log.error("createOrder error!", "请求参数校验失败!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); - } - - ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); - - if (apiMerchants == null) { - log.error("createOrder error!", "商户错误!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); - } - - Map productMap = new HashMap<>(); - - productMap.put("id" , object.getString("apiConfigProductId")); - productMap.put("merchantsId" , apiMerchants.getId()); - - ApiProductConfig apiProductConfig = apiProductService.findMchProduct(productMap); - - if (apiProductConfig == null) { - log.error("createOrder error!", " 商品错误!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.PRODUCT_ERROR); - } - - Map map = new HashMap<>(); - map.put("mobile" , object.getString("mobile")); - map.put("apiConfigProductId" , object.getString("apiConfigProductId")); - map.put("timetable" , object.getString("timetable")); - map.put("orderNo" , object.getString("orderNo")); - map.put("notifyUrl" , object.getString("notifyUrl")); - map.put("apiKey" , object.getString("apiKey")); - map.put("merchId" , object.getString("merchId")); - - if (!secConfigService.isSignVerify(map, object.getString("sign"))) { - log.error("createOrder error!", "签名校验失败!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); - } - - if (!ToolConfig.timetableCheck(15L , object.getLong("timetable"))) { - log.error("getRechargeProduct error!", "请求时间超过15分钟!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.TIME_OUT); - } - - apiOpenService.createOrder(object , apiMerchants , apiProductConfig); - return ResponseMsgUtil.success("下单成功"); - - } catch (Exception e) { - log.error("HighOpenApiController --> createOrder() error!", e); - return ResponseMsgUtil.exception(e); - } - } - -} diff --git a/v1/src/main/java/com/v1/controller/HighOrderController.java b/v1/src/main/java/com/v1/controller/HighOrderController.java deleted file mode 100644 index f7f9102b..00000000 --- a/v1/src/main/java/com/v1/controller/HighOrderController.java +++ /dev/null @@ -1,193 +0,0 @@ -package com.v1.controller; - -import com.alibaba.fastjson.JSONObject; -import com.hai.common.exception.ErrorCode; -import com.hai.common.exception.ErrorHelp; -import com.hai.common.exception.SysCode; -import com.hai.common.utils.ResponseMsgUtil; -import com.hai.entity.ApiMerchants; -import com.hai.model.ResponseData; -import com.hai.service.*; -import com.v1.config.ToolConfig; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; - -import javax.annotation.Resource; -import javax.servlet.http.HttpServletRequest; -import java.text.SimpleDateFormat; -import java.util.HashMap; -import java.util.Map; - -/** - * @serviceName rechargeProductController.java - * @author Sum1Dream - * @version 1.0.0 - * @Description // 充值产品接口 - * @createTime 17:14 2022/6/9 - **/ -@Controller -@RequestMapping(value = "/order") -@Api(value = "订单") -public class HighOrderController { - - private static Logger log = LoggerFactory.getLogger(HighOrderController.class); - - @Resource - private ApiMerchantsService apiMerchantsService; - - @Resource - private SecConfigService secConfigService; - - @Resource - private OutRechargeOrderService outRechargeOrderService; - - @Resource - private HighOrderService highOrderService; - - @Resource - private ApiIpAddressService apiIpAddressService; - - @RequestMapping(value = "/getCallOrderList", method = RequestMethod.POST) - @ResponseBody - @ApiOperation(value = "获取话费订单列表") - public ResponseData getCallOrderList(@RequestBody JSONObject object , HttpServletRequest request ) { - try { - - String ip = ""; - // 有的user可能使用代理,为处理用户使用代理的情况,使用x-forwarded-for - if (request.getHeader("x-forwarded-for") == null) { - ip = request.getRemoteAddr(); - } else { - ip = request.getHeader("x-forwarded-for"); - } - - if (!apiIpAddressService.validationIpAddressLegal(object.getString("merchId") , ip)) { - log.error("getRechargeProduct error!", "非法ip地址,请联系管理人员!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.IP_ERROR, "非法ip地址,请联系管理人员!"); - } - - if (StringUtils.isBlank(object.getString("apiKey")) || - StringUtils.isBlank(object.getString("merchId")) || - StringUtils.isBlank(object.getString("createTimeS")) || - StringUtils.isBlank(object.getString("createTimeE")) || - StringUtils.isBlank(object.getString("merchId")) || - StringUtils.isBlank(object.getString("timetable")) || - StringUtils.isBlank(object.getString("sign")) - ) { - log.error("getRechargeProduct error!", "请求参数校验失败!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); - } - - ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); - - if (apiMerchants == null) { - log.error("getRechargeProduct error!", "商户号错误!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); - } - - Map map = new HashMap<>(); - map.put("apiKey" , object.getString("apiKey")); - map.put("timetable" , object.getString("timetable")); - map.put("merchId" , object.getString("merchId")); - map.put("createTimeS" , object.getString("createTimeS")); - map.put("createTimeE" , object.getString("createTimeE")); - - if (!secConfigService.isSignVerify(map , object.getString("sign"))) { - log.error("getRechargeProduct error!", "签名校验失败!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); - } - - if (!ToolConfig.timetableCheck(15L , object.getLong("timetable"))) { - log.error("getRechargeProduct error!", "请求时间超过15分钟!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.TIME_OUT); - } - - Map postMap = new HashMap<>(); - postMap.put("merchId" , object.getString("merchId")); - postMap.put("createTimeS", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(object.getLong("createTimeS"))); - postMap.put("createTimeE", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(object.getLong("createTimeE"))); - - return ResponseMsgUtil.success(outRechargeOrderService.getListRechargeOrder(postMap)); - - } catch (Exception e) { - log.error("HighOpenApiController --> getRechargeProduct() error!", e); - return ResponseMsgUtil.exception(e); - } - } - - @RequestMapping(value = "/getOrderList", method = RequestMethod.POST) - @ResponseBody - @ApiOperation(value = "获取订单列表") - public ResponseData getOrderList(@RequestBody JSONObject object , HttpServletRequest request ) { - try { - - String ip = ""; - // 有的user可能使用代理,为处理用户使用代理的情况,使用x-forwarded-for - if (request.getHeader("x-forwarded-for") == null) { - ip = request.getRemoteAddr(); - } else { - ip = request.getHeader("x-forwarded-for"); - } - - if (!apiIpAddressService.validationIpAddressLegal(object.getString("merchId") , ip)) { - log.error("getRechargeProduct error!", "非法ip地址,请联系管理人员!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.IP_ERROR, "非法ip地址,请联系管理人员!"); - } - - if (StringUtils.isBlank(object.getString("apiKey")) || - StringUtils.isBlank(object.getString("merchId")) || - StringUtils.isBlank(object.getString("createTimeS")) || - StringUtils.isBlank(object.getString("createTimeE")) || - StringUtils.isBlank(object.getString("timetable")) || - StringUtils.isBlank(object.getString("sign")) - ) { - log.error("getRechargeProduct error!", "请求参数校验失败!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); - } - - ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); - - if (apiMerchants == null) { - log.error("getRechargeProduct error!", "商户号错误!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); - } - - Map map = new HashMap<>(); - map.put("apiKey" , object.getString("apiKey")); - map.put("timetable" , object.getString("timetable")); - map.put("merchId" , object.getString("merchId")); - map.put("createTimeS" , object.getString("createTimeS")); - map.put("createTimeE" , object.getString("createTimeE")); - - if (!secConfigService.isSignVerify(map , object.getString("sign"))) { - log.error("getRechargeProduct error!", "签名校验失败!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); - } - - if (!ToolConfig.timetableCheck(15L , object.getLong("timetable"))) { - log.error("getRechargeProduct error!", "请求时间超过15分钟!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.TIME_OUT); - } - - Map postMap = new HashMap<>(); - postMap.put("merchId" , object.getString("merchId")); - postMap.put("createTimeS", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(object.getLong("createTimeS"))); - postMap.put("createTimeE", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(object.getLong("createTimeE"))); - - - return ResponseMsgUtil.success(highOrderService.getOrderList(postMap)); - - } catch (Exception e) { - log.error("HighOpenApiController --> getRechargeProduct() error!", e); - return ResponseMsgUtil.exception(e); - } - } -} diff --git a/v1/src/main/java/com/v1/controller/ThirdPartyController.java b/v1/src/main/java/com/v1/controller/ThirdPartyController.java index 722434fb..246a4fb1 100644 --- a/v1/src/main/java/com/v1/controller/ThirdPartyController.java +++ b/v1/src/main/java/com/v1/controller/ThirdPartyController.java @@ -93,7 +93,7 @@ public class ThirdPartyController { ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); if (apiMerchants == null) { - log.error("getRechargeProduct error!", "帐户号错误!"); + log.error("getRechargeProduct error!", "帐户错误!"); throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); } diff --git a/v1/src/main/java/com/v1/controller/WxMsgController.java b/v1/src/main/java/com/v1/controller/WxMsgController.java index 02a84fed..ebc0a3a1 100644 --- a/v1/src/main/java/com/v1/controller/WxMsgController.java +++ b/v1/src/main/java/com/v1/controller/WxMsgController.java @@ -121,7 +121,7 @@ public class WxMsgController { String content = null; if (eventKey != null && eventKey.length() != 0) { JSONObject object = weChatQrcodeUtils.paramPars(eventKey); - // type = 1 推广扫码 type = 2 商户门店 3:查看视频教程 + // type = 1 推广扫码 type = 2 商户门店 3:查看视频教程 4:支付扫码 if (Objects.equals(object.getString("qrscene_type"), "1") || Objects.equals(object.getString("type"), "1")) { linkContent = "点击查看更多优惠\n\n"; } else if (Objects.equals(object.getString("qrscene_type"), "2") || Objects.equals(object.getString("type"), "2")){ diff --git a/v1/src/main/java/com/v1/controller/ApiMerchantsController.java b/v1/src/main/java/com/v1/controller/business/ApiMerchantsController.java similarity index 97% rename from v1/src/main/java/com/v1/controller/ApiMerchantsController.java rename to v1/src/main/java/com/v1/controller/business/ApiMerchantsController.java index bf70a102..9c34c3e6 100644 --- a/v1/src/main/java/com/v1/controller/ApiMerchantsController.java +++ b/v1/src/main/java/com/v1/controller/business/ApiMerchantsController.java @@ -1,4 +1,4 @@ -package com.v1.controller; +package com.v1.controller.business; import com.alibaba.fastjson.JSONObject; import com.hai.common.exception.ErrorCode; @@ -9,6 +9,7 @@ import com.hai.entity.ApiMerchants; import com.hai.model.ResponseData; import com.hai.service.*; import com.v1.config.ToolConfig; +import com.v1.controller.RechargeProductController; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; @@ -27,7 +28,7 @@ import java.util.Map; @Controller @RequestMapping(value = "/apiMerchants") -@Api(value = "API商户接口") +@Api(value = "商户业务") public class ApiMerchantsController { private static Logger log = LoggerFactory.getLogger(RechargeProductController.class); diff --git a/v1/src/main/java/com/v1/controller/GzSinopecController.java b/v1/src/main/java/com/v1/controller/business/GzSinopecController.java similarity index 98% rename from v1/src/main/java/com/v1/controller/GzSinopecController.java rename to v1/src/main/java/com/v1/controller/business/GzSinopecController.java index b5a019a7..f4ebcec4 100644 --- a/v1/src/main/java/com/v1/controller/GzSinopecController.java +++ b/v1/src/main/java/com/v1/controller/business/GzSinopecController.java @@ -1,4 +1,4 @@ -package com.v1.controller; +package com.v1.controller.business; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; @@ -11,12 +11,9 @@ import com.hai.config.HuiLianTongUnionCardConfig; import com.hai.dao.HighGasOrderPushMapper; import com.hai.entity.ApiMerchants; import com.hai.entity.HighGasOrderPush; -import com.hai.entity.HighUser; import com.hai.enum_type.OrderPushType; import com.hai.model.ResponseData; import com.hai.service.ApiMerchantsService; -import com.hai.service.HighOpenApiService; -import com.hai.service.HighUserService; import com.hai.service.SecConfigService; import com.v1.config.ToolConfig; import io.swagger.annotations.Api; @@ -35,7 +32,7 @@ import java.util.Map; @Controller @RequestMapping(value = "/gzSinopec") -@Api(value = "贵州中石化") +@Api(value = "贵州中石化业务") public class GzSinopecController { private static Logger log = LoggerFactory.getLogger(GzSinopecController.class); diff --git a/v1/src/main/java/com/v1/controller/RefuelOnlineController.java b/v1/src/main/java/com/v1/controller/business/RefuelOnlineController.java similarity index 95% rename from v1/src/main/java/com/v1/controller/RefuelOnlineController.java rename to v1/src/main/java/com/v1/controller/business/RefuelOnlineController.java index 9a42dc56..7da9e36e 100644 --- a/v1/src/main/java/com/v1/controller/RefuelOnlineController.java +++ b/v1/src/main/java/com/v1/controller/business/RefuelOnlineController.java @@ -1,4 +1,4 @@ -package com.v1.controller; +package com.v1.controller.business; import com.alibaba.fastjson.JSONObject; import com.hai.common.exception.ErrorCode; @@ -26,7 +26,6 @@ import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; -import java.math.BigDecimal; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -34,7 +33,7 @@ import java.util.Map; @Controller @RequestMapping(value = "/refuelOnline") -@Api(value = "在线加油接口") +@Api(value = "在线加油业务") public class RefuelOnlineController { private static Logger log = LoggerFactory.getLogger(RefuelOnlineController.class); @@ -128,7 +127,7 @@ public class RefuelOnlineController { for (HighMerchantStore merchantStore : merchantStores) { ApiMchStoreModel apiMchStoreModel = new ApiMchStoreModel(); apiMchStoreModel.setAddress(merchantStore.getAddress()); - apiMchStoreModel.setStoreCode(merchantStore.getStoreKey()); + apiMchStoreModel.setStoreCode(merchantStore.getId().toString()); apiMchStoreModel.setLatitude(merchantStore.getLatitude()); apiMchStoreModel.setLongitude(merchantStore.getLongitude()); apiMchStoreModel.setStoreName(merchantStore.getStoreName()); @@ -136,6 +135,8 @@ public class RefuelOnlineController { List gasOilPrices = gasOilPriceService.getGasOilPriceByStore(merchantStore.getId()); + List list = new ArrayList<>(); + for (HighGasOilPrice gasOilPrice : gasOilPrices) { ApiGasOliPriceModel gasOliPriceModel = new ApiGasOliPriceModel(); gasOliPriceModel.setPriceCost(apiCommonConfig.computationPriceCost(object.getString("merchId") , OrderProductType.PRODUCT_TYPE6.getNumber() , gasOilPrice.getPriceGun())); @@ -146,9 +147,10 @@ public class RefuelOnlineController { gasOliPriceModel.setOilType(gasOilPrice.getOilType()); gasOliPriceModel.setOilTypeName(gasOilPrice.getOilTypeName()); gasOliPriceModel.setGasOliNo(apiCommonConfig.assemblyGasOilGunNo(gasOilPrice.getId())); - apiMchStoreModel.getApiGasOliPriceModels().add(gasOliPriceModel); - } + list.add(gasOliPriceModel); + } + apiMchStoreModel.setApiGasOliPriceModels(list); apiMchStoreModels.add(apiMchStoreModel); } diff --git a/v1/src/main/java/com/v1/controller/orderController.java b/v1/src/main/java/com/v1/controller/orderController.java new file mode 100644 index 00000000..739339ef --- /dev/null +++ b/v1/src/main/java/com/v1/controller/orderController.java @@ -0,0 +1,253 @@ +package com.v1.controller; + +import com.alibaba.fastjson.JSONObject; +import com.hai.common.exception.ErrorCode; +import com.hai.common.exception.ErrorHelp; +import com.hai.common.exception.SysCode; +import com.hai.common.utils.ResponseMsgUtil; +import com.hai.entity.ApiMerchants; +import com.hai.entity.ApiOrder; +import com.hai.entity.ApiProductConfig; +import com.hai.model.ResponseData; +import com.hai.openApi.service.ApiOrderService; +import com.hai.order.type.OrderProductType; +import com.hai.service.*; +import com.v1.config.ToolConfig; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.util.HashMap; +import java.util.Map; + +@Controller +@RequestMapping(value = "/order") +@Api(value = "订单业务") +public class orderController { + + private static Logger log = LoggerFactory.getLogger(RechargeProductController.class); + + @Resource + private ApiMerchantsService apiMerchantsService; + + @Resource + private SecConfigService secConfigService; + + @Resource + private ApiOrderService orderService; + + @Resource + private ApiIpAddressService apiIpAddressService; + + @Resource + private ApiOrderService apiOrderService; + + @RequestMapping(value = "/createOrder", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "充值预下单") + public ResponseData createOrder(@RequestBody JSONObject object , HttpServletRequest request ) { + try { + + String ip = ""; + // 有的user可能使用代理,为处理用户使用代理的情况,使用x-forwarded-for + if (request.getHeader("x-forwarded-for") == null) { + ip = request.getRemoteAddr(); + } else { + ip = request.getHeader("x-forwarded-for"); + } + + if (!apiIpAddressService.validationIpAddressLegal(object.getString("merchId") , ip)) { + log.error("getRechargeProduct error!", "非法ip地址,请联系管理人员!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.IP_ERROR, "非法ip地址,请联系管理人员!"); + } + + if ( + StringUtils.isBlank(object.getString("apiKey")) || + StringUtils.isBlank(object.getString("productType")) || + StringUtils.isBlank(object.getString("timetable")) || + StringUtils.isBlank(object.getString("orderNo")) || + StringUtils.isBlank(object.getString("sign")) || + StringUtils.isBlank(object.getString("content")) || + StringUtils.isBlank(object.getString("merchId")) + ) { + log.error("createOrder error!", "请求参数校验失败!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); + } + + ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); + + if (apiMerchants == null) { + log.error("getRechargeProduct error!", "帐户错误!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); + } + + if (!secConfigService.isConfig(OrderProductType.getDataByType(object.getInteger("productType")).getApiCode(), object.getString("merchId"))) { + log.error("getAllCities error!", "当前帐户无权限查询!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED); + } + + Map map = new HashMap<>(); + map.put("timetable" , object.getString("timetable")); + map.put("orderNo" , object.getString("orderNo")); + map.put("productType" , object.getString("productType")); + map.put("apiKey" , object.getString("apiKey")); + map.put("content" , object.getString("content")); + map.put("merchId" , object.getString("merchId")); + + if (!secConfigService.isSignVerify(map, object.getString("sign"))) { + log.error("createOrder error!", "签名校验失败!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); + } + + if (!ToolConfig.timetableCheck(15L , object.getLong("timetable"))) { + log.error("getRechargeProduct error!", "请求时间超过15分钟!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.TIME_OUT); + } + + if (object.getInteger("productType").equals(OrderProductType.PRODUCT_TYPE6.getNumber())) { + JSONObject dataObject = JSONObject.parseObject(object.getString("content")); + if (dataObject.getBigDecimal("refuelPrice") == null + || StringUtils.isBlank(dataObject.getString("gasOilNo")) + || StringUtils.isBlank(dataObject.getString("gasGunNo")) + || StringUtils.isBlank(dataObject.getString("storeCode")) + ) { + log.error("OrderController -> create() error!",""); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未填写加油信息;加油金额、油号、抢号"); + } + } + + return ResponseMsgUtil.success(orderService.createOrder(object)); + + } catch (Exception e) { + log.error("HighOpenApiController --> createOrder() error!", e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value = "/orderPay", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "订单支付") + public ResponseData orderPay(@RequestBody JSONObject object , HttpServletRequest request) { + try { + + String ip = ""; + // 有的user可能使用代理,为处理用户使用代理的情况,使用x-forwarded-for + if (request.getHeader("x-forwarded-for") == null) { + ip = request.getRemoteAddr(); + } else { + ip = request.getHeader("x-forwarded-for"); + } + + if (!apiIpAddressService.validationIpAddressLegal(object.getString("merchId") , ip)) { + log.error("getRechargeProduct error!", "非法ip地址,请联系管理人员!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.IP_ERROR, "非法ip地址,请联系管理人员!"); + } + + if ( + StringUtils.isBlank(object.getString("apiKey")) || + StringUtils.isBlank(object.getString("mchOrderNo")) || + StringUtils.isBlank(object.getString("sign")) || + StringUtils.isBlank(object.getString("merchId")) + ) { + log.error("createOrder error!", "请求参数校验失败!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); + } + + ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); + + if (apiMerchants == null) { + log.error("getRechargeProduct error!", "帐户错误!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); + } + + Map map = new HashMap<>(); + map.put("mchOrderNo" , object.getString("mchOrderNo")); + map.put("apiKey" , object.getString("apiKey")); + map.put("merchId" , object.getString("merchId")); + + if (!secConfigService.isSignVerify(map, object.getString("sign"))) { + log.error("createOrder error!", "签名校验失败!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); + } + + ApiOrder apiOrder = apiOrderService.findByOrderNo(object.getString("mchOrderNo") , null); + + if (apiOrder.getStatus() != 1) { + log.error("createOrder error!", "订单状态错误!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR , "订单状态错误"); + } + + object.put("orderNo" , apiOrder.getOrderNo()); + + return ResponseMsgUtil.success(orderService.payOrder(object)); + + } catch (Exception e) { + log.error("HighOpenApiController --> createOrder() error!", e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value = "/queryOrderDetail", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "查询订单详情") + public ResponseData queryOrderDetail(@RequestBody JSONObject object , HttpServletRequest request) { + try { + + String ip = ""; + // 有的user可能使用代理,为处理用户使用代理的情况,使用x-forwarded-for + if (request.getHeader("x-forwarded-for") == null) { + ip = request.getRemoteAddr(); + } else { + ip = request.getHeader("x-forwarded-for"); + } + + if (!apiIpAddressService.validationIpAddressLegal(object.getString("merchId") , ip)) { + log.error("getRechargeProduct error!", "非法ip地址,请联系管理人员!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.IP_ERROR, "非法ip地址,请联系管理人员!"); + } + + if ( + StringUtils.isBlank(object.getString("apiKey")) || + StringUtils.isBlank(object.getString("mchOrderNo")) || + StringUtils.isBlank(object.getString("sign")) || + StringUtils.isBlank(object.getString("merchId")) + ) { + log.error("createOrder error!", "请求参数校验失败!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); + } + + ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); + + if (apiMerchants == null) { + log.error("getRechargeProduct error!", "帐户错误!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); + } + + Map map = new HashMap<>(); + map.put("mchOrderNo" , object.getString("mchOrderNo")); + map.put("apiKey" , object.getString("apiKey")); + map.put("merchId" , object.getString("merchId")); + + if (!secConfigService.isSignVerify(map, object.getString("sign"))) { + log.error("createOrder error!", "签名校验失败!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); + } + + return ResponseMsgUtil.success(apiOrderService.findByOrderNo(object.getString("mchOrderNo") , null)); + + } catch (Exception e) { + log.error("HighOpenApiController --> createOrder() error!", e); + return ResponseMsgUtil.exception(e); + } + } + +}