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 24706709..9803c140 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.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.beans.factory.annotation.Autowired; 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; @Autowired private WeChatQrcodeUtils weChatQrcodeUtils; @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("https://hsgcs.dctpay.com/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 { outRechargeOrderService.rechargeOrderHandle(orderNo); return ResponseMsgUtil.success("退款成功"); } 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); // // if (order.getOrderStatus() != 2) { // throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "订单状态错误"); // } // // // 汇联通充值 // String goodsDesc = "汇联通充值"+order.getPayPrice()+"元"; // String tranDesc = ""; // String businessType = "ghk_deposit"; // // String orderNoAgain = OrderUtil.generateOrderNo(); // // order.setRemarks("工会卡再次充值订单号" + orderNoAgain); // // highOrderService.updateOrder(order); // // // 汇联通卡充值 // JSONObject deposit = HuiLianTongUnionCardConfig.deposit(orderNoAgain, 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 + 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.beans.factory.annotation.Autowired; 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; @Autowired private WeChatQrcodeUtils weChatQrcodeUtils; @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/getStationStore" , mapPost , new HashMap<>())); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/getRechargeProduct", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "获取充值产品") public ResponseData getRechargeProduct() { 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/mobileRecharge/getMobileProduct" , mapPost , new HashMap<>())); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/getAllCities", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询可用城市") public ResponseData getAllCities() { 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/apiMerchants/getAllCities" , mapPost , new HashMap<>())); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/starbucksStore", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询星巴克门店") public ResponseData starbucksStore() { try { Map mapPost = new HashMap<>(); mapPost.put("apiKey" , "0C7897EA3BD96156A5881618FF2FF645"); mapPost.put("merchId" , "20230258302"); mapPost.put("lat" , "29.56900"); mapPost.put("lon" , "106.55843"); Map map = new HashMap<>(); map.put("apiKey" , "0C7897EA3BD96156A5881618FF2FF645"); map.put("merchId" , "20230258302"); map.put("lat" , "29.56900"); map.put("lon" , "106.55843"); 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/starbucks/starbucksStore" , 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 { outRechargeOrderService.rechargeOrderHandle(orderNo); return ResponseMsgUtil.success("退款成功"); } 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); // // if (order.getOrderStatus() != 2) { // throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "订单状态错误"); // } // // // 汇联通充值 // String goodsDesc = "汇联通充值"+order.getPayPrice()+"元"; // String tranDesc = ""; // String businessType = "ghk_deposit"; // // String orderNoAgain = OrderUtil.generateOrderNo(); // // order.setRemarks("工会卡再次充值订单号" + orderNoAgain); // // highOrderService.updateOrder(order); // // // 汇联通卡充值 // JSONObject deposit = HuiLianTongUnionCardConfig.deposit(orderNoAgain, 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-order/src/main/java/com/web/controller/OrderPayController.java b/hai-order/src/main/java/com/web/controller/OrderPayController.java index 548219cc..f9cb676b 100644 --- a/hai-order/src/main/java/com/web/controller/OrderPayController.java +++ b/hai-order/src/main/java/com/web/controller/OrderPayController.java @@ -104,6 +104,8 @@ public class OrderPayController { public ResponseData wechatPay(@RequestBody JSONObject body) { try { + System.out.println("微信支付===================" + body); + if (body == null || StringUtils.isBlank(body.getString("orderNo")) // || body.getInteger("openIdType") == null diff --git a/hai-order/src/main/java/com/web/controller/business/OrderTelChargeCallbackController.java b/hai-order/src/main/java/com/web/controller/business/OrderTelChargeCallbackController.java deleted file mode 100644 index a6661e85..00000000 --- a/hai-order/src/main/java/com/web/controller/business/OrderTelChargeCallbackController.java +++ /dev/null @@ -1,189 +0,0 @@ -package com.web.controller.business; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import com.hai.common.pay.WechatPayUtil; -import com.hai.common.security.UserCenter; -import com.hai.config.UnionPayConfig; -import com.hai.config.WxMsgConfig; -import com.hai.dao.HighGasOrderPushMapper; -import com.hai.entity.*; -import com.hai.enum_type.OrderPushType; -import com.hai.enum_type.OrderStatusEnum; -import com.hai.enum_type.RechargePayType; -import com.hai.order.service.OrderService; -import com.hai.order.type.OrderChildStatus; -import com.hai.service.*; -import com.hai.service.impl.OutRechargeOrderServiceImpl; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -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 javax.servlet.http.HttpServletResponse; -import java.io.PrintWriter; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; - -@Controller -@RequestMapping(value = "telChargeCallback") -@Api(value = "话费充值回调业务") -public class OrderTelChargeCallbackController { - - - private static Logger log = LoggerFactory.getLogger(OutRechargeOrderServiceImpl.class); - - @Resource - private OutRechargeOrderService outRechargeOrderService; - - @Resource - private OutRechargeChildOrderService outRechargeChildOrderService; - - - @RequestMapping(value = "/rechargeCallbackByJj", method = RequestMethod.POST) - @ApiOperation(value = "尖椒充值回调") - @ResponseBody - public void rechargeCallbackByJj(@RequestBody String reqBodyStr, HttpServletRequest request, HttpServletResponse response) { - try { - - JSONObject dataObject = JSONObject.parseObject(reqBodyStr, JSONObject.class); - - log.info("============回调任务Start============="); - log.info("尖椒订单充值-回调参数: " + dataObject); - log.info("============回调任务End============="); - - // 判断是否充值成功 - if (dataObject.getInteger("status") == 3) { - // 充值成功操作 - outRechargeOrderService.completeOrder(dataObject.getString("out_order_id")); - } else { - // 充值失败操作 - callbackResult(dataObject.getString("out_order_id")); - } - - 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); - } - } - - - @RequestMapping(value = "/rechargeCallbackByLy", method = RequestMethod.POST) - @ApiOperation(value = "龙阅充值回调") - @ResponseBody - public void rechargeCallbackByLy( - @RequestParam(name = "out_trade_num", required = true) String out_trade_num, - @RequestParam(name = "userid", required = true) Long userid, - @RequestParam(name = "state", required = true) Long state, - @RequestBody String reqBodyStr , - HttpServletRequest request, HttpServletResponse response) { - try { - - log.info("============回调任务Start============="); - log.info("龙阅订单充值-回调参数: " + reqBodyStr); - log.info("============回调任务End============="); - - // 判断是否充值成功 - if (state == 1) { - outRechargeOrderService.completeOrder(out_trade_num); - } else { - callbackResult(out_trade_num); - } - - 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); - } - } - - @RequestMapping(value = "/rechargeCallbackByHg", method = RequestMethod.POST) - @ApiOperation(value = "畅停充值回调") - @ResponseBody - public void rechargeCallbackByHg( - @RequestParam(name = "mchid", required = false) String mchid, - @RequestParam(name = "out_order_id", required = false) String out_order_id, - @RequestParam(name = "orderid", required = true) String orderid, - @RequestParam(name = "return_time", required = false) String return_time, - @RequestParam(name = "return_price", required = false) String return_price, - @RequestParam(name = "recharge_price", required = false) String recharge_price, - @RequestParam(name = "price", required = false) String price, - @RequestParam(name = "status", required = true) String status, - @RequestParam(name = "phone", required = false) String phone, - @RequestParam(name = "secret_key", required = false) String secret_key, - HttpServletResponse response) { - try { - - - - JSONObject dataObject = new JSONObject(); - - dataObject.put("mchid" , mchid); - dataObject.put("out_order_id" , out_order_id); - dataObject.put("orderid" , orderid); - dataObject.put("return_time" , return_time); - dataObject.put("return_price" , return_price); - dataObject.put("recharge_price" , recharge_price); - dataObject.put("price" , price); - dataObject.put("status" , status); - dataObject.put("phone" , phone); - dataObject.put("secret_key" , secret_key); - - log.info("============回调任务Start============="); - log.info("畅停订单充值-回调参数: " + dataObject); - log.info("============回调任务End============="); - - // 判断是否充值成功 并发送微信小程序服务通知 - if (Objects.equals(status, "1")) { - - outRechargeOrderService.completeOrder(orderid); - - } else { - // 充值失败操作 - callbackResult(orderid); - } - - 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); - } - } - - - // 充值回调结果处理 - private void callbackResult(String orderNo) { - - // 查询充值订单 - OutRechargeOrder rechargeOrder = outRechargeOrderService.findByOrderNo(orderNo); - OutRechargeChildOrder childOrder = rechargeOrder.getOutRechargeChildOrders().get(0); - - childOrder.setStatus(103); - childOrder.setUpdateTime(new Date()); - outRechargeChildOrderService.updateOrder(childOrder); - rechargeOrder.setRechargeStatus(205); - outRechargeOrderService.updateOrder(rechargeOrder); - - } - -} 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 index 5aa0e40a..4f5335a5 100644 --- a/hai-service/src/main/java/com/hai/openApi/config/PriceComputeConfig.java +++ b/hai-service/src/main/java/com/hai/openApi/config/PriceComputeConfig.java @@ -59,4 +59,23 @@ public class PriceComputeConfig { return true; } + + /** + * @Author Sum1Dream + * @Name computationPriceCost + * @Description // 计算折扣价格 + * @Date 09:25 2023/3/13 + * @Param discount 折扣 + * @Param price 原价 + * @Return java.math.BigDecimal + */ + public BigDecimal computationPriceCost(BigDecimal discount , BigDecimal price) { + return price.multiply(discount).divide(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP); + + } +// +// public BigDecimal computationPriceCost(BigDecimal discount , BigDecimal price , BigDecimal 成本) { +// return price.multiply(discount).divide(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP); +// +// } } diff --git a/hai-service/src/main/java/com/hai/openApi/model/ApiMobileProductModel.java b/hai-service/src/main/java/com/hai/openApi/model/ApiMobileProductModel.java new file mode 100644 index 00000000..ffbe769a --- /dev/null +++ b/hai-service/src/main/java/com/hai/openApi/model/ApiMobileProductModel.java @@ -0,0 +1,71 @@ +package com.hai.openApi.model; + +import java.math.BigDecimal; + +public class ApiMobileProductModel { + + + /** + * 主键 + */ + private Long productId; + + /** + * 运营商 1 电信 2.移动 3.联通 + */ + private Integer operatorType; + /** + * 折扣比例 + */ + private BigDecimal discount; + + /** + * 充值金额 + */ + private BigDecimal rechargePrice; + + /** + * 成本价格 + */ + private BigDecimal costPrice; + + public Long getProductId() { + return productId; + } + + public void setProductId(Long productId) { + this.productId = productId; + } + + public Integer getOperatorType() { + return operatorType; + } + + public void setOperatorType(Integer operatorType) { + this.operatorType = operatorType; + } + + public BigDecimal getDiscount() { + return discount; + } + + public void setDiscount(BigDecimal discount) { + this.discount = discount; + } + + public BigDecimal getRechargePrice() { + return rechargePrice; + } + + public void setRechargePrice(BigDecimal rechargePrice) { + this.rechargePrice = rechargePrice; + } + + public BigDecimal getCostPrice() { + return costPrice; + } + + public void setCostPrice(BigDecimal costPrice) { + this.costPrice = costPrice; + } +} diff --git a/hai-service/src/main/java/com/hai/openApi/service/ApiMobileRechargeProductService.java b/hai-service/src/main/java/com/hai/openApi/service/ApiMobileRechargeProductService.java new file mode 100644 index 00000000..d41432ab --- /dev/null +++ b/hai-service/src/main/java/com/hai/openApi/service/ApiMobileRechargeProductService.java @@ -0,0 +1,48 @@ +package com.hai.openApi.service; + +import com.hai.entity.ApiMerchants; +import com.hai.entity.ApiProduct; +import com.hai.openApi.model.ApiMobileProductModel; + +import java.util.List; + +/** + * @serviceName ApiMobileRechargeProductService.java + * @author Sum1Dream + * @version 1.0.0 + * @Description // 话费产品业务 + * @createTime 11:36 2023/3/10 + **/ +public interface ApiMobileRechargeProductService { + + + /** + * @Author Sum1Dream + * @Name getMobileProductByList + * @Description // 查询话费充值产品 + * @Date 11:35 2023/3/10 + * @Param [] + * @Return java.util.List + */ + List getApiProductByList(); + + /** + * @Author Sum1Dream + * @Name findMobileProduct + * @Description // 查询话费产品 + * @Date 11:36 2023/3/10 + * @Param [id] + * @Return com.hai.entity.ApiProduct + */ + ApiProduct findMobileProduct(Long id); + + /** + * @Author Sum1Dream + * @Name getMobileProductByList + * @Description // 拼装话费产品 + * @Date 11:35 2023/3/10 + * @Param [] + * @Return java.util.List + */ + List getMobileProductByList(String mchId); +} diff --git a/hai-service/src/main/java/com/hai/openApi/service/impl/ApiMobileRechargeProductServiceImpl.java b/hai-service/src/main/java/com/hai/openApi/service/impl/ApiMobileRechargeProductServiceImpl.java new file mode 100644 index 00000000..dea1e6d1 --- /dev/null +++ b/hai-service/src/main/java/com/hai/openApi/service/impl/ApiMobileRechargeProductServiceImpl.java @@ -0,0 +1,68 @@ +package com.hai.openApi.service.impl; + +import com.hai.dao.ApiProductMapper; +import com.hai.entity.*; +import com.hai.openApi.config.PriceComputeConfig; +import com.hai.openApi.model.ApiMobileProductModel; +import com.hai.openApi.service.ApiMchProductService; +import com.hai.openApi.service.ApiMobileRechargeProductService; +import com.hai.order.type.OrderProductType; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service("apiMobileRechargeProductService") +public class ApiMobileRechargeProductServiceImpl implements ApiMobileRechargeProductService { + + @Resource + private ApiProductMapper apiProductMapper; + + @Resource + private ApiMchProductService apiMchProductService; + + @Resource + private PriceComputeConfig priceComputeConfig; + + @Override + public List getApiProductByList() { + ApiProductExample example = new ApiProductExample(); + example.createCriteria().andStatusEqualTo(101); + + return apiProductMapper.selectByExample(example); + } + + @Override + public ApiProduct findMobileProduct(Long id) { + return null; + } + + @Override + public List getMobileProductByList(String mchId) { + + Map mapProduct = new HashMap<>(); + mapProduct.put("mchId" , mchId); + mapProduct.put("productType" , OrderProductType.PRODUCT_TYPE9.getNumber()); + + ApiMchProduct apiMchProducts = apiMchProductService.findByMap(mapProduct); + + List list = new ArrayList<>(); + List apiProducts = getApiProductByList(); + + for (ApiProduct product : apiProducts) { + ApiMobileProductModel productModel = new ApiMobileProductModel(); + productModel.setDiscount(apiMchProducts.getDiscount()); + productModel.setProductId(product.getId()); + productModel.setRechargePrice(product.getRechargePrice()); + productModel.setOperatorType(product.getOperatorType()); + productModel.setCostPrice(priceComputeConfig.computationPriceCost(apiMchProducts.getDiscount() , product.getRechargePrice())); + list.add(productModel); + } + + + return list; + } +} 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 index 909c832e..56c90428 100644 --- 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 @@ -59,7 +59,7 @@ public class ApiOrderCreateHandleServiceImpl implements ApiOrderCreateHandleServ 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); + BigDecimal price = priceComputeConfig.computationPriceCost(mchProduct.getDiscount() , dataObject.getBigDecimal("refuelPrice")); // 判断金额是否充足 if (apiMerchants.getAmounts().compareTo(price) < 0) { diff --git a/hai-service/src/main/java/com/hai/order/type/OrderProductType.java b/hai-service/src/main/java/com/hai/order/type/OrderProductType.java index 31cfe60b..facf27b0 100644 --- a/hai-service/src/main/java/com/hai/order/type/OrderProductType.java +++ b/hai-service/src/main/java/com/hai/order/type/OrderProductType.java @@ -19,6 +19,7 @@ public enum OrderProductType { PRODUCT_TYPE8(8, "汇联通工会卡充值", "orderLogo/hlt.png", "HLT_CONFIG"), PRODUCT_TYPE9(9, "话费充值" , "orderLogo/calls.png", "CALLS_CONFIG"), PRODUCT_TYPE10(10, "电影票" ,"" , ""), + PRODUCT_TYPE11(11, "贵州中石化" , "", "GZ_SINOPEC_CONFIG"), ; private Integer number; 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 30a3d9bd..1cf14197 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 @@ -631,7 +631,7 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { if (status == 0 || status == 3 || status == 99) { return; } else if (status == 1) { - completeOrder(outRechargeOrder.getOrderNo()); + completeOrder(childOrder.getOrderNo()); } // 修改充值记录状态 @@ -863,7 +863,7 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { if (status == 2 || status == -1) { refundOrder(outRechargeOrder.getId() , childOrder); } else if (status == 1) { - completeOrder(outRechargeOrder.getOrderNo()); + completeOrder(childOrder.getOrderNo()); } } diff --git a/v1/src/main/java/com/v1/config/ApiCommonConfig.java b/v1/src/main/java/com/v1/config/ApiCommonConfig.java index d7651e28..cfc88984 100644 --- a/v1/src/main/java/com/v1/config/ApiCommonConfig.java +++ b/v1/src/main/java/com/v1/config/ApiCommonConfig.java @@ -17,21 +17,11 @@ import java.util.Map; @Configuration public class ApiCommonConfig { - @Resource - private ApiMchProductService ApiMchProductService; - @Resource private HighGasOilGunNoService highGasOilGunNoService; - public BigDecimal computationPriceCost(String mchId , Integer productType , BigDecimal price) { - - Map map = new HashMap<>(); - map.put("mchId" , mchId); - map.put("productType" , productType); - - ApiMchProduct apiMchProduct = ApiMchProductService.findByMap(map); - - return price.multiply(apiMchProduct.getDiscount()).divide(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP); + public BigDecimal computationPriceCost(BigDecimal discount , BigDecimal price) { + return price.multiply(discount).divide(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP); } diff --git a/v1/src/main/java/com/v1/controller/business/ApiMerchantsController.java b/v1/src/main/java/com/v1/controller/business/ApiMerchantsController.java index 9c34c3e6..1a4a179f 100644 --- a/v1/src/main/java/com/v1/controller/business/ApiMerchantsController.java +++ b/v1/src/main/java/com/v1/controller/business/ApiMerchantsController.java @@ -5,8 +5,10 @@ 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.config.QianZhuConfig; import com.hai.entity.ApiMerchants; import com.hai.model.ResponseData; +import com.hai.order.type.OrderProductType; import com.hai.service.*; import com.v1.config.ToolConfig; import com.v1.controller.RechargeProductController; @@ -38,6 +40,9 @@ public class ApiMerchantsController { @Resource private SecConfigService secConfigService; + @Resource + private ApiIpAddressService apiIpAddressService; + @RequestMapping(value = "/checkAccountBalance", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "查询帐户余额") @@ -95,4 +100,60 @@ public class ApiMerchantsController { return ResponseMsgUtil.exception(e); } } + + + @RequestMapping(value = "/getAllCities", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "查询可用城市") + public ResponseData getAllCities(@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 (StringUtils.isBlank(object.getString("apiKey")) || + StringUtils.isBlank(object.getString("merchId")) || + StringUtils.isBlank(object.getString("sign")) + ) { + log.error("getRechargeProduct error!", "请求参数校验失败!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); + } + + + if (!apiIpAddressService.validationIpAddressLegal(object.getString("merchId") , ip)) { + log.error("getRechargeProduct error!", "非法ip地址,请联系管理人员!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.IP_ERROR, "非法ip地址,请联系管理人员!"); + } + + 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("merchId" , object.getString("merchId")); + + if (!secConfigService.isSignVerify(map , object.getString("sign"))) { + log.error("getRechargeProduct error!", "签名校验失败!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); + } + + JSONObject jsonObject = QianZhuConfig.getAllCities(); + + return ResponseMsgUtil.success(jsonObject.getString("data")); + + } catch (Exception e) { + log.error("HighOpenApiController --> getRechargeProduct() error!", e); + return ResponseMsgUtil.exception(e); + } + } } diff --git a/v1/src/main/java/com/v1/controller/business/GzSinopecController.java b/v1/src/main/java/com/v1/controller/business/GzSinopecController.java index e3bf0d31..f6ab3a16 100644 --- a/v1/src/main/java/com/v1/controller/business/GzSinopecController.java +++ b/v1/src/main/java/com/v1/controller/business/GzSinopecController.java @@ -13,6 +13,7 @@ import com.hai.entity.ApiMerchants; import com.hai.entity.HighGasOrderPush; import com.hai.enum_type.OrderPushType; import com.hai.model.ResponseData; +import com.hai.order.type.OrderProductType; import com.hai.service.ApiMerchantsService; import com.hai.service.SecConfigService; import com.v1.config.ToolConfig; @@ -91,9 +92,9 @@ public class GzSinopecController { log.error("getRechargeProduct error!", "错误商户,请联系管理人员!"); throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); } - if (!secConfigService.isConfig("GZ_SINOPEC_CONFIG" , object.getString("merchId"))) { - log.error("getAllCities error!", "当前帐户无权限!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "当前帐户无权限!"); + if (!secConfigService.isConfig(OrderProductType.PRODUCT_TYPE11.getApiCode(), object.getString("merchId"))) { + log.error("getAllCities error!", "当前帐户无权限查询!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, ""); } if (!ToolConfig.timetableCheck(15L , object.getLong("timetable"))) { @@ -170,9 +171,9 @@ public class GzSinopecController { log.error("getRechargeProduct error!", "错误商户,请联系管理人员!"); throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); } - if (!secConfigService.isConfig("GZ_SINOPEC_CONFIG" , object.getString("merchId"))) { - log.error("getAllCities error!", "当前帐户无权限!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "当前帐户无权限!"); + if (!secConfigService.isConfig(OrderProductType.PRODUCT_TYPE11.getApiCode(), object.getString("merchId"))) { + log.error("getAllCities error!", "当前帐户无权限查询!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, ""); } if (!ToolConfig.timetableCheck(15L , object.getLong("timetable"))) { @@ -261,9 +262,9 @@ public class GzSinopecController { log.error("getRechargeProduct error!", "错误商户,请联系管理人员!"); throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); } - if (!secConfigService.isConfig("GZ_SINOPEC_CONFIG" , object.getString("merchId"))) { - log.error("getAllCities error!", "当前帐户无权限!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "当前帐户无权限!"); + if (!secConfigService.isConfig(OrderProductType.PRODUCT_TYPE11.getApiCode(), object.getString("merchId"))) { + log.error("getAllCities error!", "当前帐户无权限查询!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, ""); } if (!ToolConfig.timetableCheck(15L , object.getLong("timetable"))) { diff --git a/v1/src/main/java/com/v1/controller/SelfOilStationController.java b/v1/src/main/java/com/v1/controller/business/MobileRechargeController.java similarity index 68% rename from v1/src/main/java/com/v1/controller/SelfOilStationController.java rename to v1/src/main/java/com/v1/controller/business/MobileRechargeController.java index a80aaf14..8955c4a0 100644 --- a/v1/src/main/java/com/v1/controller/SelfOilStationController.java +++ b/v1/src/main/java/com/v1/controller/business/MobileRechargeController.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; @@ -6,12 +6,12 @@ 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.HighOrder; -import com.hai.entity.SecConfig; import com.hai.model.ResponseData; -import com.hai.model.SelfOilStationModel; +import com.hai.openApi.service.ApiMobileRechargeProductService; +import com.hai.order.type.OrderProductType; 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; @@ -26,16 +26,14 @@ import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.util.HashMap; -import java.util.List; import java.util.Map; - @Controller -@RequestMapping(value = "/selfOilStation") -@Api(value = "自建站接口") -public class SelfOilStationController { +@RequestMapping(value = "/mobileRecharge") +@Api(value = "话费充值业务") +public class MobileRechargeController { - private static Logger log = LoggerFactory.getLogger(SelfOilStationController.class); + private static Logger log = LoggerFactory.getLogger(RechargeProductController.class); @Resource private ApiMerchantsService apiMerchantsService; @@ -44,17 +42,16 @@ public class SelfOilStationController { private SecConfigService secConfigService; @Resource - private HighOrderService highOrderService; + private ApiMobileRechargeProductService mobileRechargeProductService; @Resource private ApiIpAddressService apiIpAddressService; - - @RequestMapping(value = "/getSelfOilStationOrderList", method = RequestMethod.POST) + @RequestMapping(value = "/getMobileProduct", method = RequestMethod.POST) @ResponseBody - @ApiOperation(value = "获取自建站订单") - public ResponseData getSelfOilStationOrderList(@RequestBody JSONObject object , HttpServletRequest request ) { + @ApiOperation(value = "获取话费充值产品") + public ResponseData getMobileProduct(@RequestBody JSONObject object , HttpServletRequest request ) { try { String ip = ""; @@ -71,7 +68,6 @@ public class SelfOilStationController { } if (StringUtils.isBlank(object.getString("apiKey")) || - StringUtils.isBlank(object.getString("timetable")) || StringUtils.isBlank(object.getString("merchId")) || StringUtils.isBlank(object.getString("sign")) ) { @@ -82,12 +78,16 @@ public class SelfOilStationController { 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); } + if (!secConfigService.isConfig(OrderProductType.PRODUCT_TYPE9.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("apiKey" , object.getString("apiKey")); map.put("merchId" , object.getString("merchId")); @@ -96,24 +96,11 @@ public class SelfOilStationController { throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); } - if (!secConfigService.isConfig("SELF_OIL_STATION_CONFIG" , object.getString("merchId"))) { - log.error("getAllCities error!", "当前帐户无权限!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "当前帐户无权限!"); - } - - if (!ToolConfig.timetableCheck(15L , object.getLong("timetable"))) { - log.error("getRechargeProduct error!", "请求时间超过15分钟!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.TIME_OUT); - } - - SecConfig config = secConfigService.findByCodeType(object.getString("merchId")); - - return ResponseMsgUtil.success(highOrderService.getSelfOilStationOrderList(config.getCodeValue())); + return ResponseMsgUtil.success(mobileRechargeProductService.getMobileProductByList(object.getString("merchId"))); } catch (Exception e) { log.error("HighOpenApiController --> getRechargeProduct() error!", e); return ResponseMsgUtil.exception(e); } } - } diff --git a/v1/src/main/java/com/v1/controller/business/RefuelOnlineController.java b/v1/src/main/java/com/v1/controller/business/RefuelOnlineController.java index 973df17f..bf4b8b3b 100644 --- a/v1/src/main/java/com/v1/controller/business/RefuelOnlineController.java +++ b/v1/src/main/java/com/v1/controller/business/RefuelOnlineController.java @@ -26,6 +26,7 @@ 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; @@ -113,12 +114,13 @@ public class RefuelOnlineController { List apiMchProducts = apiMchProductService.getListMchProduct(mapProduct); - Map mapMerchant; + Map mapMerchant = new HashMap<>();; + Map discountMap = new HashMap<>(); List merchantStores = new ArrayList<>(); for (ApiMchProduct mchProduct : apiMchProducts) { - mapMerchant = new HashMap<>(); mapMerchant.put("merchantId" , mchProduct.getMerchantId()); + discountMap.put(mchProduct.getMerchantId() , mchProduct.getDiscount()); merchantStores.addAll(highMerchantStoreService.getMerchantStoreList(mapMerchant)); } @@ -135,11 +137,12 @@ 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())); + gasOliPriceModel.setPriceCost(apiCommonConfig.computationPriceCost(discountMap.get(merchantStore.getMerchantId()), gasOilPrice.getPriceGun())); gasOliPriceModel.setPriceGun(gasOilPrice.getPriceGun()); gasOliPriceModel.setPriceOfficial(gasOilPrice.getPriceOfficial()); gasOliPriceModel.setOilNo(gasOilPrice.getOilNo()); diff --git a/v1/src/main/java/com/v1/controller/business/StarbucksController.java b/v1/src/main/java/com/v1/controller/business/StarbucksController.java new file mode 100644 index 00000000..96c39c8e --- /dev/null +++ b/v1/src/main/java/com/v1/controller/business/StarbucksController.java @@ -0,0 +1,195 @@ +package com.v1.controller.business; + +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.config.QianZhuConfig; +import com.hai.entity.ApiMerchants; +import com.hai.entity.ApiStarbucksProducts; +import com.hai.model.ResponseData; +import com.hai.order.type.OrderProductType; +import com.hai.service.*; +import com.v1.controller.ThirdPartyController; +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.math.BigDecimal; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Controller +@RequestMapping(value = "/starbucks") +@Api(value = "星巴克业务") +public class StarbucksController { + + + private static Logger log = LoggerFactory.getLogger(ThirdPartyController.class); + + @Resource + private ApiMerchantsService apiMerchantsService; + + @Resource + private SecConfigService secConfigService; + + @Resource + private ApiIpAddressService apiIpAddressService; + + @Resource + private ApiProductService apiProductService; + + + @RequestMapping(value = "/starbucksStore", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "查询星巴克门店") + public ResponseData starbucksStore(@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("lat")) || + StringUtils.isBlank(object.getString("lon")) || + 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); + } + + if (!secConfigService.isConfig(OrderProductType.PRODUCT_TYPE1.getApiCode(), object.getString("merchId"))) { + log.error("getAllCities error!", "当前帐户无权限查询!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, ""); + } + + Map map = new HashMap<>(); + map.put("apiKey" , object.getString("apiKey")); + map.put("merchId" , object.getString("merchId")); + map.put("lat" , object.getString("lat")); + map.put("lon" , object.getString("lon")); + + if (!secConfigService.isSignVerify(map , object.getString("sign"))) { + log.error("getRechargeProduct error!", "签名校验失败!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); + } + + JSONObject jsonObject = QianZhuConfig.getStarbucksStore(object.getString("lat") , object.getString("lon")); + + if (jsonObject.getBoolean("success")) { + return ResponseMsgUtil.success(jsonObject.getString("data")); + } else { + log.error("getRechargeProduct error!", "查询失败!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR , jsonObject.getString("message")); + } + + } catch (Exception e) { + log.error("HighOpenApiController --> getRechargeProduct() error!", e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value = "/getStarbucksProducts", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "查询星巴克商品") + public ResponseData getStarbucksProducts(@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("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); + } + + if (!secConfigService.isConfig(OrderProductType.PRODUCT_TYPE1.getApiCode(), object.getString("merchId"))) { + log.error("getAllCities error!", "当前帐户无权限查询!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, ""); + } + + Map map = new HashMap<>(); + map.put("apiKey" , object.getString("apiKey")); + map.put("merchId" , object.getString("merchId")); + + if (!secConfigService.isSignVerify(map , object.getString("sign"))) { + log.error("getRechargeProduct error!", "签名校验失败!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); + } + + Map mapProduct = new HashMap<>(); + + List list = apiProductService.getStarbucksProducts(mapProduct); + + for (ApiStarbucksProducts starbucksProducts : list) { + if (starbucksProducts.getMarketGrandePrice().compareTo(new BigDecimal(1000)) > 0) { + starbucksProducts.setMarketGrandePrice(null); + } + if (starbucksProducts.getMarketTallPrice().compareTo(new BigDecimal(1000)) > 0) { + starbucksProducts.setMarketTallPrice(null); + } + if (starbucksProducts.getMarketVentiPrice().compareTo(new BigDecimal(1000)) > 0) { + starbucksProducts.setMarketVentiPrice(null); + } + starbucksProducts.setSalesTallPrice(starbucksProducts.getMarketTallPrice()); + starbucksProducts.setSalesVentiPrice(starbucksProducts.getMarketVentiPrice()); + starbucksProducts.setSalesGrandePrice(starbucksProducts.getMarketGrandePrice()); + } + + return ResponseMsgUtil.success(list); + + } catch (Exception e) { + log.error("HighOpenApiController --> getRechargeProduct() error!", e); + return ResponseMsgUtil.exception(e); + } + } +}