From 66e2db5ec85925fe9db9242f8f124db209d9efc4 Mon Sep 17 00:00:00 2001 From: Sum1Dream <418471657@qq.com> Date: Mon, 26 Dec 2022 11:27:49 +0800 Subject: [PATCH] 1 --- .../controller/BsProductConfigController.java | 1 - .../controller/HighUserCardController.java | 3 - .../cweb/controller/HighUserController.java | 4 +- .../OutRechargePriceController.java | 3 - .../java/com/hai/config/WxOrderConfig.java | 13 - .../java/com/hai/entity/ApiAmountRecord.java | 2 +- .../java/com/hai/service/ApiOpenService.java | 10 + .../hai/service/impl/ApiOpenServiceImpl.java | 143 +++++++- .../v1/controller/HighOrderController.java | 1 - .../v1/controller/ThirdPartyController.java | 329 +++++++++++++++++- 10 files changed, 469 insertions(+), 40 deletions(-) diff --git a/hai-bweb/src/main/java/com/bweb/controller/BsProductConfigController.java b/hai-bweb/src/main/java/com/bweb/controller/BsProductConfigController.java index b200bec8..24ebdd81 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/BsProductConfigController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/BsProductConfigController.java @@ -125,7 +125,6 @@ public class BsProductConfigController { apiProductService.ProductConfig(object); - return ResponseMsgUtil.success("新增成功"); } catch (Exception e) { diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighUserCardController.java b/hai-cweb/src/main/java/com/cweb/controller/HighUserCardController.java index 3ece39e1..03613caa 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighUserCardController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighUserCardController.java @@ -50,9 +50,6 @@ public class HighUserCardController { @Resource private HighUserService highUserService; - @Resource - private HighUserPayPasswordService highUserPayPasswordService; - @RequestMapping(value = "/bindCard", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "绑卡") diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighUserController.java b/hai-cweb/src/main/java/com/cweb/controller/HighUserController.java index 0bca3d78..cd90f73c 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighUserController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighUserController.java @@ -144,7 +144,7 @@ public class HighUserController { HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); if (StringUtils.isBlank(body.getString("password")) - || body.getString("password").length() != 6){ + || body.getString("password").length() != 6) { log.error("HighUserController --> setUserPayPwd() error!", "请设置6位支付密码"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请设置6位支付密码"); } @@ -178,7 +178,7 @@ public class HighUserController { @RequestMapping(value = "/updateUserPayPwd", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "修改用户支付密码") - public ResponseData updateUserPayPwd(@RequestBody JSONObject body,HttpServletRequest request, HttpServletResponse response) { + public ResponseData updateUserPayPwd(@RequestBody JSONObject body,HttpServletRequest request) { try { // 用户 SessionObject sessionObject = userCenter.getSessionObject(request); diff --git a/hai-cweb/src/main/java/com/cweb/controller/OutRechargePriceController.java b/hai-cweb/src/main/java/com/cweb/controller/OutRechargePriceController.java index af8c3cfb..3225faeb 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/OutRechargePriceController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/OutRechargePriceController.java @@ -43,9 +43,6 @@ public class OutRechargePriceController { private static Logger log = LoggerFactory.getLogger(HighMerchantStoreController.class); - @Autowired - private UserCenter userCenter; - @Resource private OutRechargePriceService outRechargePriceService; diff --git a/hai-service/src/main/java/com/hai/config/WxOrderConfig.java b/hai-service/src/main/java/com/hai/config/WxOrderConfig.java index 1e3233ee..3d06be6d 100644 --- a/hai-service/src/main/java/com/hai/config/WxOrderConfig.java +++ b/hai-service/src/main/java/com/hai/config/WxOrderConfig.java @@ -1,17 +1,9 @@ package com.hai.config; -import com.alibaba.fastjson.JSONObject; -import com.hai.common.exception.ErrorCode; -import com.hai.common.exception.ErrorHelp; -import com.hai.common.exception.SysCode; import com.hai.common.pay.util.XmlUtil; import com.hai.common.pay.util.sdk.WXPayConstants; -import com.hai.common.utils.ResponseMsgUtil; import com.hai.common.utils.WxUtils; -import com.hai.entity.OutRechargeOrder; import com.hai.model.OrderRefundModel; -import com.hai.model.ResponseData; -import io.swagger.annotations.ApiOperation; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; @@ -23,13 +15,8 @@ import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseBody; import javax.net.ssl.SSLContext; -import javax.servlet.http.HttpServletRequest; import java.io.FileInputStream; import java.math.BigDecimal; import java.security.KeyStore; 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..f38eaefc 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,7 @@ public class ApiAmountRecord implements Serializable { private String mchId; /** - * 1:充值金额 2:订单退款 3 话费消费 + * 1:充值金额 2:订单退款 3 话费消费 4: 肯德基订单 5:星巴克订单 6:会员充值 7:重庆中石油 */ private Integer sourceType; diff --git a/hai-service/src/main/java/com/hai/service/ApiOpenService.java b/hai-service/src/main/java/com/hai/service/ApiOpenService.java index e3551e48..a66dd8bc 100644 --- a/hai-service/src/main/java/com/hai/service/ApiOpenService.java +++ b/hai-service/src/main/java/com/hai/service/ApiOpenService.java @@ -23,4 +23,14 @@ public interface ApiOpenService { */ void createOrder(JSONObject object , ApiMerchants apiMerchants , ApiProductConfig productConfig) throws Exception; + + /** + * @Author Sum1Dream + * @name createOrder.java + * @Description // 充值预下单 + * @Date 17:31 2022/6/10 + * @Param [com.alibaba.fastjson.JSONObject] + * @return com.alibaba.fastjson.JSONObject + */ + void createOrder(JSONObject object , ApiMerchants apiMerchants) throws Exception; } diff --git a/hai-service/src/main/java/com/hai/service/impl/ApiOpenServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/ApiOpenServiceImpl.java index 5597abe8..4fc9dd94 100644 --- a/hai-service/src/main/java/com/hai/service/impl/ApiOpenServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/ApiOpenServiceImpl.java @@ -1,5 +1,7 @@ package com.hai.service.impl; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; @@ -7,8 +9,10 @@ import com.hai.common.exception.SysCode; import com.hai.common.utils.DateUtil; import com.hai.common.utils.IDGenerator; import com.hai.config.CommonSysConst; +import com.hai.config.QianZhuConfig; import com.hai.config.RechargeConfig; +import com.hai.dao.HighOrderMapper; import com.hai.dao.OutRechargeOrderMapper; import com.hai.entity.*; @@ -20,10 +24,8 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.math.BigDecimal; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.math.RoundingMode; +import java.util.*; @Service("apiOpenService") public class ApiOpenServiceImpl implements ApiOpenService { @@ -49,6 +51,9 @@ public class ApiOpenServiceImpl implements ApiOpenService { @Resource private BsRequestRecordService bsRequestRecordService; + @Resource + private HighOrderMapper highOrderMapper; + @Override @Transactional(rollbackFor=Exception.class,isolation = Isolation.SERIALIZABLE,propagation= Propagation.REQUIRES_NEW) @@ -263,4 +268,132 @@ public class ApiOpenServiceImpl implements ApiOpenService { } -} + @Override + @Transactional(rollbackFor=Exception.class,isolation = Isolation.SERIALIZABLE,propagation= Propagation.REQUIRES_NEW) + public void createOrder(JSONObject object , ApiMerchants apiMerchants) throws Exception { + // 定义订单 + HighOrder highOrder = new HighOrder(); + highOrder.setMerchId(object.getString("mchId")); + highOrder.setWhetherRebate(false); + highOrder.setMemPhone(apiMerchants.getPhone()); + highOrder.setMemName(apiMerchants.getMerchantName()); + highOrder.setMemId(apiMerchants.getId()); + + JSONObject jsonObject = null; + + // 获取token + JSONObject userToken = QianZhuConfig.getTokenV2(apiMerchants.getId().toString(), apiMerchants.getMerchantName(), apiMerchants.getPhone()); + + if (!userToken.getBoolean("success")) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, userToken.getString("message")); + } + + // 1 星巴克 2 肯德基 3 会员充值 + if (object.getInteger("productType") == 1) { + List List = new ArrayList<>(); + + JSONArray array = object.getJSONArray("orderItems"); + + // 组装下单数据 + for (Object o : array) { + JSONObject object1 = (JSONObject) o; + Map contentMap = new LinkedHashMap<>(); + if (!object1.getString("productId").equals("")) { + contentMap.put("productId", object1.getString("productId")); + } + if (!object1.getString("cupSize").equals("")) { + contentMap.put("cupSize", object1.getString("cupSize")); + } + if (!object1.getString("temperature").equals("")) { + contentMap.put("temperature", object1.getString("temperature")); + } + if (!object1.getString("cream").equals("")) { + contentMap.put("cream", object1.getString("cream")); + } + if (!object1.getString("espresso").equals("")) { + contentMap.put("espresso", object1.getString("espresso")); + } + if (!object1.getString("milk").equals("")) { + contentMap.put("milk", object1.getString("milk")); + } + if (!object1.getString("milkBubble").equals("")) { + contentMap.put("milkBubble", object1.getString("milkBubble")); + } + if (!"".equals(object1.getString("num"))) { + contentMap.put("num", object1.getString("num")); + } + List.add(JSON.toJSONString(contentMap)); + } + // 下单 + jsonObject = QianZhuConfig.starbucksOrders(apiMerchants.getId().toString(), object.getString("storeCode"), List.toString().replace(" ", ""), object.getString("customerMobile")); + + // 判断下单是否成功 + if (!Objects.equals(jsonObject.getString("code"), "200")) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, jsonObject.getString("message")); + } + + if (!jsonObject.getBoolean("success")) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, jsonObject.getString("message")); + } + + // 根据订单号查询订单详情 + JSONObject orderObject = QianZhuConfig.starbucksOrderByOrderNo(jsonObject.getJSONObject("data").getString("orderNo")); + + // 判断是否成功 + if (!orderObject.getBoolean("success")) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, jsonObject.getString("message")); + } + + // 插入订单内容 + highOrder.setOrderNo(jsonObject.getJSONObject("data").getString("orderNo")); + highOrder.setCreateTime(new Date()); + highOrder.setMemId(apiMerchants.getId()); + highOrder.setMemName(apiMerchants.getMerchantName()); + highOrder.setMemPhone(apiMerchants.getPhone()); + highOrder.setOrderStatus(1); + highOrderMapper.insert(highOrder); + + // 获取星巴克订单内容 + JSONArray starbucksOrder = orderObject.getJSONObject("data").getJSONArray("orderItems"); + +// for (Object starbucksObject : starbucksOrder) { +// JSONObject childObject = (JSONObject) starbucksObject; +// HighChildOrder childOrder = new HighChildOrder(); +// childOrder.setOrderId(highOrder.getId()); +// childOrder.setChildOrdeStatus(1); +// childOrder.setGoodsType(9); +// childOrder.setStoreId(object.getLong("storeCode")); +// childOrder.setGoodsId(object.getLong("productId")); +// childOrder.setStoreAddress(childObject.getString("storeAddress")); +// childOrder.setStoreName(childObject.getString("storeName")); +// childOrder.setGoodsName(childObject.getString("productName")); +// childOrder.setGoodsImg(childObject.getString("imgUrl")); +// childOrder.setSaleCount(childObject.getInteger("quantity")); +// childOrder.setGoodsPrice(childObject.getBigDecimal("marketPrice")); +// +// // 计算利润 +// BigDecimal profitPrice = childObject.getBigDecimal("marketPrice").multiply(productDetail.getBigDecimal("priceDiscount").divide(new BigDecimal(100))); +// // 计算子订单支付金额 +// BigDecimal childPrice = childObject.getBigDecimal("unitPrice").add(profitPrice).setScale(2 , RoundingMode.HALF_UP); +// if (childPrice.compareTo(childObject.getBigDecimal("marketPrice")) > 0) { +// childPrice = childObject.getBigDecimal("marketPrice"); +// } +// if (object.getLong("memDiscountId") != null) { +// childOrder.setGoodsActualPrice(childObject.getBigDecimal("marketPrice")); +// } else { +// childOrder.setGoodsActualPrice(childPrice); +// } +// childPrice = childPrice.multiply(childObject.getBigDecimal("quantity")); +// // 计算总订单实际支付金额 +// orderPayPrice = orderPayPrice.add(childPrice); +// // 计算市场价金额 +// marketPrice = marketPrice.add(childObject.getBigDecimal("marketPrice").multiply(childObject.getBigDecimal("quantity"))); +// childOrder.setTotalPrice(childPrice); +// highChildOrderMapper.insert(childOrder); +// } + + } + + } + + } diff --git a/v1/src/main/java/com/v1/controller/HighOrderController.java b/v1/src/main/java/com/v1/controller/HighOrderController.java index d74461af..59f3ad4b 100644 --- a/v1/src/main/java/com/v1/controller/HighOrderController.java +++ b/v1/src/main/java/com/v1/controller/HighOrderController.java @@ -112,7 +112,6 @@ public class HighOrderController { 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) { diff --git a/v1/src/main/java/com/v1/controller/ThirdPartyController.java b/v1/src/main/java/com/v1/controller/ThirdPartyController.java index afdcfd17..93138758 100644 --- a/v1/src/main/java/com/v1/controller/ThirdPartyController.java +++ b/v1/src/main/java/com/v1/controller/ThirdPartyController.java @@ -1,14 +1,16 @@ package com.v1.controller; +import com.alibaba.fastjson.JSONArray; 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.*; 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; @@ -22,7 +24,10 @@ import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -48,6 +53,15 @@ public class ThirdPartyController { @Resource private ApiIpAddressService apiIpAddressService; + @Resource + private ApiProductService apiProductService; + + @Resource + private ApiOpenService apiOpenService; + + @Resource + private ApiMemberProductService apiMemberProductService; + @RequestMapping(value = "/getAllCities", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "查询可用城市") @@ -62,7 +76,6 @@ public class ThirdPartyController { ip = request.getHeader("x-forwarded-for"); } - if (StringUtils.isBlank(object.getString("apiKey")) || StringUtils.isBlank(object.getString("merchId")) || StringUtils.isBlank(object.getString("sign")) @@ -144,7 +157,7 @@ public class ThirdPartyController { throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); } - if (!secConfigService.isConfig("KFC_CONFIG" , object.getString("merchId"))) { + if (!secConfigService.isConfig("STARBUCKS_CONFIG" , object.getString("merchId"))) { log.error("getAllCities error!", "当前帐户无权限查询!"); throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "当前帐户无权限查询!"); } @@ -196,8 +209,81 @@ public class ThirdPartyController { if (StringUtils.isBlank(object.getString("apiKey")) || StringUtils.isBlank(object.getString("merchId")) || - StringUtils.isBlank(object.getString("pageIndex")) || - StringUtils.isBlank(object.getString("pageSize")) || + 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("STARBUCKS_CONFIG" , 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); + } + } + + @RequestMapping(value = "/getKfcStoresList", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "查询肯德基门店") + public ResponseData getKfcStoresList(@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("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!", "请求参数校验失败!"); @@ -220,23 +306,244 @@ public class ThirdPartyController { 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.getStarbucksProducts(object.getInteger("pageIndex") , object.getInteger("pageSize")); + Map mapStores = new HashMap<>(); + List list = apiProductService.getKfcStoresList(mapStores); - 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")); + return ResponseMsgUtil.success(list); + + } catch (Exception e) { + log.error("HighOpenApiController --> getRechargeProduct() error!", e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value = "/kfcProductByStoreCode", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "根据门店编码查询KFC产品") + public ResponseData kfcProductByStoreCode(@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("getRechargeProduct error!", "非法ip地址,请联系管理人员!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.IP_ERROR, "非法ip地址,请联系管理人员!"); + } + + if (StringUtils.isBlank(object.getString("apiKey")) || + StringUtils.isBlank(object.getString("storeCode")) || + 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("KFC_CONFIG" , 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("storeCode" , object.getString("storeCode")); + + if (!secConfigService.isSignVerify(map , object.getString("sign"))) { + log.error("getRechargeProduct error!", "签名校验失败!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); + } + + JSONObject jsonObject = QianZhuConfig.listByStoreCode(object.getString("storeCode")); + JSONArray array = jsonObject.getJSONArray("data"); + if (array == null) { + log.error("kfcProductByStoreCode error!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未查询到商品"); + } + + for (Object data : array) { + JSONObject dataObject = (JSONObject) data; + if (dataObject.getJSONArray("products") != null) { + for (Object products : dataObject.getJSONArray("products")) { + JSONObject productsObject = (JSONObject) products; + productsObject.put("taxOriginalPrice" , null); + productsObject.put("taxOriginalTotalPrice" , null); + productsObject.put("price" , null); + productsObject.put("taxPrice" , null); + + if (productsObject.getJSONArray("specGroups") != null) { + for (Object specGroups : productsObject.getJSONArray("specGroups")) { + JSONObject specGroupsObject = (JSONObject) specGroups; + specGroupsObject.put("taxOriginalPrice" , null); + specGroupsObject.put("taxOriginalTotalPrice" , null); + specGroupsObject.put("price" , null); + specGroupsObject.put("taxPrice" , null); + } + } + } + } + } + + return ResponseMsgUtil.success(array); + + } catch (Exception e) { + log.error("HighOpenApiController --> getRechargeProduct() error!", e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value = "/getMemberProducts", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "查询会员产品") + public ResponseData getMemberProducts(@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("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("MEMBER_RECHARGE_CONFIG" , 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 = apiMemberProductService.getListApiMemberProduct(mapProduct); + + for (ApiMemberProduct apiMemberProduct : list) { + apiMemberProduct.setCostPrice(null); + } + + return ResponseMsgUtil.success(list); + } catch (Exception e) { log.error("HighOpenApiController --> getRechargeProduct() error!", e); return ResponseMsgUtil.exception(e); } } + + @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("customerMobile")) || + StringUtils.isBlank(object.getString("productType")) || + StringUtils.isBlank(object.getString("apiKey")) || + 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<>(); + + + + Map map = new HashMap<>(); + map.put("customerMobile" , object.getString("customerMobile")); + map.put("productType" , object.getString("productType")); + 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); + return ResponseMsgUtil.success("下单成功"); + + } catch (Exception e) { + log.error("HighOpenApiController --> createOrder() error!", e); + return ResponseMsgUtil.exception(e); + } + } + }