dev-discount
袁野 2 years ago
parent 174c8fdb7e
commit 66e2db5ec8
  1. 1
      hai-bweb/src/main/java/com/bweb/controller/BsProductConfigController.java
  2. 3
      hai-cweb/src/main/java/com/cweb/controller/HighUserCardController.java
  3. 4
      hai-cweb/src/main/java/com/cweb/controller/HighUserController.java
  4. 3
      hai-cweb/src/main/java/com/cweb/controller/OutRechargePriceController.java
  5. 13
      hai-service/src/main/java/com/hai/config/WxOrderConfig.java
  6. 2
      hai-service/src/main/java/com/hai/entity/ApiAmountRecord.java
  7. 10
      hai-service/src/main/java/com/hai/service/ApiOpenService.java
  8. 143
      hai-service/src/main/java/com/hai/service/impl/ApiOpenServiceImpl.java
  9. 1
      v1/src/main/java/com/v1/controller/HighOrderController.java
  10. 329
      v1/src/main/java/com/v1/controller/ThirdPartyController.java

@ -125,7 +125,6 @@ public class BsProductConfigController {
apiProductService.ProductConfig(object); apiProductService.ProductConfig(object);
return ResponseMsgUtil.success("新增成功"); return ResponseMsgUtil.success("新增成功");
} catch (Exception e) { } catch (Exception e) {

@ -50,9 +50,6 @@ public class HighUserCardController {
@Resource @Resource
private HighUserService highUserService; private HighUserService highUserService;
@Resource
private HighUserPayPasswordService highUserPayPasswordService;
@RequestMapping(value = "/bindCard", method = RequestMethod.POST) @RequestMapping(value = "/bindCard", method = RequestMethod.POST)
@ResponseBody @ResponseBody
@ApiOperation(value = "绑卡") @ApiOperation(value = "绑卡")

@ -144,7 +144,7 @@ public class HighUserController {
HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject();
if (StringUtils.isBlank(body.getString("password")) if (StringUtils.isBlank(body.getString("password"))
|| body.getString("password").length() != 6){ || body.getString("password").length() != 6) {
log.error("HighUserController --> setUserPayPwd() error!", "请设置6位支付密码"); log.error("HighUserController --> setUserPayPwd() error!", "请设置6位支付密码");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请设置6位支付密码"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请设置6位支付密码");
} }
@ -178,7 +178,7 @@ public class HighUserController {
@RequestMapping(value = "/updateUserPayPwd", method = RequestMethod.POST) @RequestMapping(value = "/updateUserPayPwd", method = RequestMethod.POST)
@ResponseBody @ResponseBody
@ApiOperation(value = "修改用户支付密码") @ApiOperation(value = "修改用户支付密码")
public ResponseData updateUserPayPwd(@RequestBody JSONObject body,HttpServletRequest request, HttpServletResponse response) { public ResponseData updateUserPayPwd(@RequestBody JSONObject body,HttpServletRequest request) {
try { try {
// 用户 // 用户
SessionObject sessionObject = userCenter.getSessionObject(request); SessionObject sessionObject = userCenter.getSessionObject(request);

@ -43,9 +43,6 @@ public class OutRechargePriceController {
private static Logger log = LoggerFactory.getLogger(HighMerchantStoreController.class); private static Logger log = LoggerFactory.getLogger(HighMerchantStoreController.class);
@Autowired
private UserCenter userCenter;
@Resource @Resource
private OutRechargePriceService outRechargePriceService; private OutRechargePriceService outRechargePriceService;

@ -1,17 +1,9 @@
package com.hai.config; 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.XmlUtil;
import com.hai.common.pay.util.sdk.WXPayConstants; import com.hai.common.pay.util.sdk.WXPayConstants;
import com.hai.common.utils.ResponseMsgUtil;
import com.hai.common.utils.WxUtils; import com.hai.common.utils.WxUtils;
import com.hai.entity.OutRechargeOrder;
import com.hai.model.OrderRefundModel; import com.hai.model.OrderRefundModel;
import com.hai.model.ResponseData;
import io.swagger.annotations.ApiOperation;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost; 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.apache.http.util.EntityUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 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.net.ssl.SSLContext;
import javax.servlet.http.HttpServletRequest;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.security.KeyStore; import java.security.KeyStore;

@ -45,7 +45,7 @@ public class ApiAmountRecord implements Serializable {
private String mchId; private String mchId;
/** /**
* 1:充值金额 2订单退款 3 话费消费 * 1:充值金额 2订单退款 3 话费消费 4: 肯德基订单 5星巴克订单 6会员充值 7重庆中石油
*/ */
private Integer sourceType; private Integer sourceType;

@ -23,4 +23,14 @@ public interface ApiOpenService {
*/ */
void createOrder(JSONObject object , ApiMerchants apiMerchants , ApiProductConfig productConfig) throws Exception; 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;
} }

@ -1,5 +1,7 @@
package com.hai.service.impl; package com.hai.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp; 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.DateUtil;
import com.hai.common.utils.IDGenerator; import com.hai.common.utils.IDGenerator;
import com.hai.config.CommonSysConst; import com.hai.config.CommonSysConst;
import com.hai.config.QianZhuConfig;
import com.hai.config.RechargeConfig; import com.hai.config.RechargeConfig;
import com.hai.dao.HighOrderMapper;
import com.hai.dao.OutRechargeOrderMapper; import com.hai.dao.OutRechargeOrderMapper;
import com.hai.entity.*; import com.hai.entity.*;
@ -20,10 +24,8 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date; import java.math.RoundingMode;
import java.util.HashMap; import java.util.*;
import java.util.List;
import java.util.Map;
@Service("apiOpenService") @Service("apiOpenService")
public class ApiOpenServiceImpl implements ApiOpenService { public class ApiOpenServiceImpl implements ApiOpenService {
@ -49,6 +51,9 @@ public class ApiOpenServiceImpl implements ApiOpenService {
@Resource @Resource
private BsRequestRecordService bsRequestRecordService; private BsRequestRecordService bsRequestRecordService;
@Resource
private HighOrderMapper highOrderMapper;
@Override @Override
@Transactional(rollbackFor=Exception.class,isolation = Isolation.SERIALIZABLE,propagation= Propagation.REQUIRES_NEW) @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<String> List = new ArrayList<>();
JSONArray array = object.getJSONArray("orderItems");
// 组装下单数据
for (Object o : array) {
JSONObject object1 = (JSONObject) o;
Map<String, Object> 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);
// }
}
}
}

@ -112,7 +112,6 @@ public class HighOrderController {
postMap.put("createTimeS", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(object.getLong("createTimeS"))); 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"))); postMap.put("createTimeE", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(object.getLong("createTimeE")));
return ResponseMsgUtil.success(outRechargeOrderService.getListRechargeOrder(postMap)); return ResponseMsgUtil.success(outRechargeOrderService.getListRechargeOrder(postMap));
} catch (Exception e) { } catch (Exception e) {

@ -1,14 +1,16 @@
package com.v1.controller; package com.v1.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode; import com.hai.common.exception.SysCode;
import com.hai.common.utils.ResponseMsgUtil; import com.hai.common.utils.ResponseMsgUtil;
import com.hai.config.QianZhuConfig; import com.hai.config.QianZhuConfig;
import com.hai.entity.ApiMerchants; import com.hai.entity.*;
import com.hai.model.ResponseData; import com.hai.model.ResponseData;
import com.hai.service.*; import com.hai.service.*;
import com.v1.config.ToolConfig;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -22,7 +24,10 @@ import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -48,6 +53,15 @@ public class ThirdPartyController {
@Resource @Resource
private ApiIpAddressService apiIpAddressService; private ApiIpAddressService apiIpAddressService;
@Resource
private ApiProductService apiProductService;
@Resource
private ApiOpenService apiOpenService;
@Resource
private ApiMemberProductService apiMemberProductService;
@RequestMapping(value = "/getAllCities", method = RequestMethod.POST) @RequestMapping(value = "/getAllCities", method = RequestMethod.POST)
@ResponseBody @ResponseBody
@ApiOperation(value = "查询可用城市") @ApiOperation(value = "查询可用城市")
@ -62,7 +76,6 @@ public class ThirdPartyController {
ip = request.getHeader("x-forwarded-for"); ip = request.getHeader("x-forwarded-for");
} }
if (StringUtils.isBlank(object.getString("apiKey")) || if (StringUtils.isBlank(object.getString("apiKey")) ||
StringUtils.isBlank(object.getString("merchId")) || StringUtils.isBlank(object.getString("merchId")) ||
StringUtils.isBlank(object.getString("sign")) StringUtils.isBlank(object.getString("sign"))
@ -144,7 +157,7 @@ public class ThirdPartyController {
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); 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!", "当前帐户无权限查询!"); log.error("getAllCities error!", "当前帐户无权限查询!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "当前帐户无权限查询!"); throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "当前帐户无权限查询!");
} }
@ -196,8 +209,81 @@ public class ThirdPartyController {
if (StringUtils.isBlank(object.getString("apiKey")) || if (StringUtils.isBlank(object.getString("apiKey")) ||
StringUtils.isBlank(object.getString("merchId")) || StringUtils.isBlank(object.getString("merchId")) ||
StringUtils.isBlank(object.getString("pageIndex")) || StringUtils.isBlank(object.getString("sign"))
StringUtils.isBlank(object.getString("pageSize")) || ) {
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<String , Object> 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<String, Object> mapProduct = new HashMap<>();
List<ApiStarbucksProducts> 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")) StringUtils.isBlank(object.getString("sign"))
) { ) {
log.error("getRechargeProduct error!", "请求参数校验失败!"); log.error("getRechargeProduct error!", "请求参数校验失败!");
@ -220,23 +306,244 @@ public class ThirdPartyController {
map.put("apiKey" , object.getString("apiKey")); map.put("apiKey" , object.getString("apiKey"));
map.put("merchId" , object.getString("merchId")); map.put("merchId" , object.getString("merchId"));
if (!secConfigService.isSignVerify(map , object.getString("sign"))) { if (!secConfigService.isSignVerify(map , object.getString("sign"))) {
log.error("getRechargeProduct error!", "签名校验失败!"); log.error("getRechargeProduct error!", "签名校验失败!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY);
} }
JSONObject jsonObject = QianZhuConfig.getStarbucksProducts(object.getInteger("pageIndex") , object.getInteger("pageSize")); Map<String, Object> mapStores = new HashMap<>();
List<ApiKfcStores> list = apiProductService.getKfcStoresList(mapStores);
if (jsonObject.getBoolean("success")) { return ResponseMsgUtil.success(list);
return ResponseMsgUtil.success(jsonObject.getString("data"));
} else { } catch (Exception e) {
log.error("getRechargeProduct error!", "查询失败!"); log.error("HighOpenApiController --> getRechargeProduct() error!", e);
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR , jsonObject.getString("message")); 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<String , Object> 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<String , Object> 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<String, Object> mapProduct = new HashMap<>();
List<ApiMemberProduct> list = apiMemberProductService.getListApiMemberProduct(mapProduct);
for (ApiMemberProduct apiMemberProduct : list) {
apiMemberProduct.setCostPrice(null);
}
return ResponseMsgUtil.success(list);
} catch (Exception e) { } catch (Exception e) {
log.error("HighOpenApiController --> getRechargeProduct() error!", e); log.error("HighOpenApiController --> getRechargeProduct() error!", e);
return ResponseMsgUtil.exception(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<String, Object> productMap = new HashMap<>();
Map<String , Object> 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);
}
}
} }

Loading…
Cancel
Save