commit
d765e3bd16
File diff suppressed because one or more lines are too long
@ -0,0 +1,44 @@ |
||||
package com.hai.openApi.type; |
||||
|
||||
import com.hai.enum_type.DeviceTypeEnum; |
||||
import com.hai.order.type.OrderProductType; |
||||
|
||||
import java.util.Objects; |
||||
|
||||
public enum OperatorTypeEnum { |
||||
type1(1, "电信运营商"), |
||||
type2(2, "移动运营商"), |
||||
type3(3, "联通运营商"), |
||||
; |
||||
private Integer type; |
||||
|
||||
private String name; |
||||
|
||||
OperatorTypeEnum(int type, String name) { |
||||
this.type = type; |
||||
this.name = name; |
||||
} |
||||
|
||||
public static OperatorTypeEnum getDataByType(Integer type) { |
||||
for (OperatorTypeEnum ele : values()) { |
||||
if(Objects.equals(type,ele.getType())) return ele; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public Integer getType() { |
||||
return type; |
||||
} |
||||
|
||||
public void setType(Integer type) { |
||||
this.type = type; |
||||
} |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
} |
@ -1,575 +0,0 @@ |
||||
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; |
||||
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.HighChildOrderMapper; |
||||
import com.hai.dao.HighOrderMapper; |
||||
import com.hai.dao.OutRechargeOrderMapper; |
||||
import com.hai.entity.*; |
||||
|
||||
import com.hai.service.*; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.transaction.annotation.Isolation; |
||||
import org.springframework.transaction.annotation.Propagation; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.math.BigDecimal; |
||||
import java.math.RoundingMode; |
||||
import java.util.*; |
||||
|
||||
@Service("apiOpenService") |
||||
public class ApiOpenServiceImpl implements ApiOpenService { |
||||
|
||||
@Resource |
||||
private ApiOrderRecordService apiOrderRecordService; |
||||
|
||||
@Resource |
||||
private ApiMerchantsService apiMerchantsService; |
||||
|
||||
@Resource |
||||
private ApiProductService apiProductService; |
||||
|
||||
@Resource |
||||
private ApiAmountRecordService apiAmountRecordService; |
||||
|
||||
@Resource |
||||
private OutRechargeOrderMapper outRechargeOrderMapper; |
||||
|
||||
@Resource |
||||
private OutRechargeChildOrderService outRechargeChildOrderService; |
||||
|
||||
@Resource |
||||
private BsRequestRecordService bsRequestRecordService; |
||||
|
||||
@Resource |
||||
private HighOrderMapper highOrderMapper; |
||||
|
||||
@Resource |
||||
private HighChildOrderMapper highChildOrderMapper; |
||||
|
||||
@Resource |
||||
private ApiMemberProductService apiMemberProductService; |
||||
|
||||
@Resource |
||||
private SecConfigService secConfigService; |
||||
|
||||
@Resource |
||||
private HighOrderService highOrderService; |
||||
|
||||
@Override |
||||
@Transactional(rollbackFor=Exception.class,isolation = Isolation.SERIALIZABLE,propagation= Propagation.REQUIRES_NEW) |
||||
public void createOrder(JSONObject object , ApiMerchants apiMerchants , ApiProductConfig productConfig) throws Exception { |
||||
|
||||
Map<String, Object> orderMap = new HashMap<>(); |
||||
orderMap.put("sourceOrderNo" , object.getString("sourceOrderNo")); |
||||
|
||||
// 查询是否用重复订单
|
||||
ApiOrderRecord apiOrderRecord = apiOrderRecordService.queryOrderResult(orderMap); |
||||
|
||||
if (apiOrderRecord != null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.ORDER_ALREADY_EXISTS); |
||||
} |
||||
|
||||
ApiProduct apiProduct = apiProductService.findById(productConfig.getProductId()); |
||||
|
||||
// 当前账号余额是否可以充值当前金额
|
||||
if (apiMerchants.getAmounts().compareTo(productConfig.getDiscountPrice()) < 0) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.INSUFFICIENT_BALANCE); |
||||
} |
||||
|
||||
// 插入金额记录
|
||||
// 变更前金额
|
||||
BigDecimal beforeAmount = apiMerchants.getAmounts(); |
||||
// 计算金额
|
||||
apiMerchants.setAmounts(apiMerchants.getAmounts().subtract(productConfig.getDiscountPrice())); |
||||
// 变更后金额
|
||||
BigDecimal afterAmount = apiMerchants.getAmounts(); |
||||
|
||||
apiMerchantsService.updateApiMerchants(apiMerchants); |
||||
|
||||
ApiAmountRecord apiAmountRecord = new ApiAmountRecord(); |
||||
|
||||
apiAmountRecord.setCreateTime(new Date()); |
||||
apiAmountRecord.setUpdateTime(new Date()); |
||||
apiAmountRecord.setMchId(apiMerchants.getMchId()); |
||||
|
||||
apiAmountRecord.setStatus(100); |
||||
apiAmountRecord.setAmount(productConfig.getDiscountPrice()); |
||||
apiAmountRecord.setAfterAmount(afterAmount); |
||||
apiAmountRecord.setBeforeAmount(beforeAmount); |
||||
apiAmountRecord.setAmountType(2); |
||||
apiAmountRecord.setSourceType(3); |
||||
apiAmountRecord.setSourceOrderNo(object.getString("orderNo")); |
||||
apiAmountRecord.setSourceId(apiProduct.getId()); |
||||
apiAmountRecord.setSourceContent(apiMerchants.getMerchantName() + "|" + object.getString("mobile") + "充值" + apiProduct.getRechargePrice() + "|扣款" + productConfig.getDiscountPrice()); |
||||
|
||||
apiAmountRecordService.insertAmountRecord(apiAmountRecord); |
||||
|
||||
// 充值订单
|
||||
OutRechargeOrder outRechargeOrder = new OutRechargeOrder(); |
||||
outRechargeOrder.setPayStatus(102); |
||||
outRechargeOrder.setRechargeStatus(204); |
||||
outRechargeOrder.setOrderNo("RCG" + DateUtil.date2String(new Date(), "yyyyMMddHHmmss") + IDGenerator.nextId(5)); |
||||
outRechargeOrder.setPaySerialNo("22" + DateUtil.date2String(new Date(), "yyyyMMddHHmmss") + IDGenerator.nextId(5)); |
||||
outRechargeOrder.setRechargePrice(apiProduct.getRechargePrice()); |
||||
outRechargeOrder.setRechargeType(apiProduct.getPhoneRechargeType()); |
||||
outRechargeOrder.setOrderPrice(productConfig.getDiscountPrice()); |
||||
outRechargeOrder.setPayPrice(productConfig.getDiscountPrice()); |
||||
outRechargeOrder.setPayRealPrice(productConfig.getDiscountPrice()); |
||||
outRechargeOrder.setRechargeContent(object.getString("mobile")); |
||||
outRechargeOrder.setPayTime(new Date()); |
||||
outRechargeOrder.setUserName(apiMerchants.getMerchantName()); |
||||
outRechargeOrder.setUserPhone(apiMerchants.getPhone()); |
||||
outRechargeOrder.setPayType(6); |
||||
outRechargeOrder.setCompanyId(6666L); |
||||
outRechargeOrder.setType(1); |
||||
outRechargeOrder.setCreateTimed(new Date()); |
||||
outRechargeOrder.setOperatorName(apiProduct.getOperatorName()); |
||||
outRechargeOrder.setOperatorType(apiProduct.getOperatorType()); |
||||
outRechargeOrder.setGoodsId(apiProduct.getId()); |
||||
outRechargeOrder.setMerchId(apiMerchants.getMchId()); |
||||
outRechargeOrder.setUserId(apiMerchants.getId()); |
||||
|
||||
outRechargeOrderMapper.insert(outRechargeOrder); |
||||
pollRequest(outRechargeOrder); |
||||
|
||||
// 插入订单记录
|
||||
ApiOrderRecord apiOrderRecordPost = new ApiOrderRecord(); |
||||
apiOrderRecordPost.setStatus(103); |
||||
apiOrderRecordPost.setOrderNo(outRechargeOrder.getOrderNo()); |
||||
apiOrderRecordPost.setSourceOrderNo(object.getString("sourceOrderNo")); |
||||
apiOrderRecordPost.setCreateTime(new Date()); |
||||
apiOrderRecordPost.setMchId(apiMerchants.getMchId()); |
||||
apiOrderRecordPost.setOrderId(outRechargeOrder.getId()); |
||||
apiOrderRecordPost.setGoodsId(productConfig.getId().toString()); |
||||
apiOrderRecordPost.setNotifyUrl(object.getString("notifyUrl")); |
||||
apiOrderRecordPost.setUpdateTime(new Date()); |
||||
|
||||
apiOrderRecordService.insertOrderRecord(apiOrderRecordPost); |
||||
} |
||||
|
||||
private void pollRequest(OutRechargeOrder outRechargeOrder) throws Exception { |
||||
|
||||
// 查询充值产品
|
||||
ApiProduct apiProduct = apiProductService.findById(outRechargeOrder.getGoodsId()); |
||||
|
||||
// 查询充值子订单
|
||||
Map<String, Object> childOrderMap = new HashMap<>(); |
||||
|
||||
|
||||
childOrderMap.put("parent_order_id", outRechargeOrder.getId()); |
||||
childOrderMap.put("status", 102); |
||||
|
||||
List<OutRechargeChildOrder> childOrderList = outRechargeChildOrderService.getListRechargeChildOrder(childOrderMap); |
||||
|
||||
OutRechargeChildOrder childOrder = new OutRechargeChildOrder(); |
||||
|
||||
// 1:尖椒 2:龙阅 3:畅停
|
||||
int type = 0; |
||||
int rechargePlatformType = 0; |
||||
|
||||
// 判断子订单是否存在充值中订单
|
||||
if (childOrderList.size() > 0) { |
||||
childOrder = childOrderList.get(0); |
||||
childOrder.setStatus(103); |
||||
childOrder.setUpdateTime(new Date()); |
||||
outRechargeChildOrderService.updateOrder(childOrder); |
||||
type = childOrder.getRechargePlatform(); |
||||
|
||||
} else { |
||||
// 查询充值子订单
|
||||
Map<String, Object> childOrderMap103 = new HashMap<>(); |
||||
|
||||
childOrderMap103.put("parent_order_id", outRechargeOrder.getId()); |
||||
childOrderMap103.put("status", 103); |
||||
|
||||
List<OutRechargeChildOrder> childOrderList103 = outRechargeChildOrderService.getListRechargeChildOrder(childOrderMap103); |
||||
if (childOrderList103.size() > 0) { |
||||
type = childOrderList103.get(0).getRechargePlatform(); |
||||
} |
||||
} |
||||
|
||||
if (type == 2) { |
||||
type = 1; |
||||
} else { |
||||
type++; |
||||
} |
||||
|
||||
|
||||
JSONObject object = new JSONObject(); |
||||
|
||||
String orderNo = "CZ" + DateUtil.date2String(new Date(), "yyyyMMddHHmmss") + IDGenerator.nextId(5); |
||||
|
||||
String[] rechargePlatform = apiProduct.getRechargePlatform().split("-"); |
||||
|
||||
for (String s : rechargePlatform) { |
||||
// 尖椒充值
|
||||
if (s.equals("1") && type == 1) { |
||||
object.put("out_order_id", orderNo); |
||||
object.put("amount", apiProduct.getRechargePrice()); |
||||
object.put("mobile", outRechargeOrder.getRechargeContent()); |
||||
object.put("notifyUrl", CommonSysConst.getSysConfig().getJjNotifyUrl()); |
||||
if (apiProduct.getRechargeType() == 1) { |
||||
object.put("is_fast", 1); |
||||
} |
||||
JSONObject returnObject = RechargeConfig.rechargeOrderByJj(object); |
||||
object.put("return_content", returnObject); |
||||
if (returnObject != null && returnObject.getLong("code") == 200) { |
||||
childOrder.setStatus(102); |
||||
} else { |
||||
childOrder.setStatus(103); |
||||
} |
||||
rechargePlatformType = 1; |
||||
break; |
||||
} |
||||
if (s.equals("2") && type == 2) { |
||||
object.put("out_trade_num", orderNo); |
||||
object.put("product_id", apiProduct.getProductId()); |
||||
object.put("mobile", outRechargeOrder.getRechargeContent()); |
||||
object.put("notifyUrl", CommonSysConst.getSysConfig().getLyNotifyUrl()); |
||||
JSONObject returnObject = RechargeConfig.rechargeOrderByLy(object); |
||||
object.put("return_content", returnObject); |
||||
if (returnObject != null && returnObject.getLong("errno") == 0) { |
||||
childOrder.setStatus(102); |
||||
} else { |
||||
childOrder.setStatus(103); |
||||
} |
||||
rechargePlatformType = 2; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
childOrder.setOrderNo(orderNo); |
||||
childOrder.setCreateTime(new Date()); |
||||
childOrder.setParentOrderId(outRechargeOrder.getId()); |
||||
childOrder.setRechargePlatform(rechargePlatformType); |
||||
childOrder.setUpdateTime(new Date()); |
||||
outRechargeChildOrderService.insertOrder(childOrder); |
||||
|
||||
// 创建提交记录
|
||||
BsRequestRecord requestRecord = new BsRequestRecord(); |
||||
requestRecord.setCreateTime(new Date()); |
||||
requestRecord.setUpdateTime(new Date()); |
||||
requestRecord.setOrderNo(orderNo); |
||||
requestRecord.setRequestContent(object.toJSONString()); |
||||
requestRecord.setOperatorId(0L); |
||||
requestRecord.setOperatorName("系统生成"); |
||||
requestRecord.setSourceId(childOrder.getId().toString()); |
||||
requestRecord.setSourceType(1); |
||||
|
||||
bsRequestRecordService.insertRequestRecord(requestRecord); |
||||
|
||||
// 判断是否充值提交成功
|
||||
if (childOrder.getStatus() == 102) { |
||||
outRechargeOrder.setRechargeStatus(201); |
||||
} |
||||
|
||||
if (childOrder.getStatus() == 103) { |
||||
outRechargeOrder.setRechargeStatus(204); |
||||
} |
||||
outRechargeOrderMapper.updateByPrimaryKey(outRechargeOrder); |
||||
|
||||
} |
||||
|
||||
@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(apiMerchants.getMchId());
|
||||
// highOrder.setWhetherRebate(false);
|
||||
// highOrder.setMemPhone(apiMerchants.getPhone());
|
||||
// highOrder.setMemName(apiMerchants.getMerchantName());
|
||||
// highOrder.setMemId(apiMerchants.getId());
|
||||
// highOrder.setCreateTime(new Date());
|
||||
// highOrder.setOrderStatus(1);
|
||||
// highOrder.setProductType(object.getInteger("productType"));
|
||||
// highOrder.setPayType(OrderPayTypeEnum.type8.getType());
|
||||
// highOrder.setOrderNo("HF" + DateUtil.date2String(new Date(),"yyyyMMddHHmmss") + IDGenerator.nextId(5));
|
||||
// highOrderMapper.insert(highOrder);
|
||||
//
|
||||
// // 订单总金额
|
||||
// BigDecimal marketPriceTotal = new BigDecimal(0);
|
||||
//
|
||||
// // 定义下单json对象
|
||||
// JSONObject jsonObject;
|
||||
//
|
||||
// // 获取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) {
|
||||
//
|
||||
// // 判断当前商户是否有权限下单
|
||||
// if (!secConfigService.isConfig("STARBUCKS_CONFIG" , object.getString("merchId"))) {
|
||||
// throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "当前帐户无权限查询!");
|
||||
// }
|
||||
//
|
||||
// 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
|
||||
// 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"));
|
||||
// }
|
||||
//
|
||||
// // 获取星巴克订单内容
|
||||
// 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.setMemId(highOrder.getMemId());
|
||||
// childOrder.setGoodsType(9);
|
||||
// childOrder.setStoreId(object.getLong("storeCode"));
|
||||
// childOrder.setGoodsId(childObject.getLong("id"));
|
||||
// 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 childPrice = childObject.getBigDecimal("marketPrice");
|
||||
// childOrder.setGoodsActualPrice(childPrice);
|
||||
// // 计算市场价金额
|
||||
// childOrder.setTotalPrice(childPrice.multiply(childObject.getBigDecimal("quantity")));
|
||||
// marketPriceTotal = marketPriceTotal.add(childOrder.getTotalPrice());
|
||||
//
|
||||
// highChildOrderMapper.insert(childOrder);
|
||||
// }
|
||||
// // 拼接json对象
|
||||
// object.put("sourceType" , 5);
|
||||
// object.put("content" , apiMerchants.getMerchantName() + "|" + "星巴克下单" + "|扣款" + marketPriceTotal);
|
||||
// }else if (object.getInteger("productType") == 2) {
|
||||
//
|
||||
// // 判断当前商户是否有肯德基下单权限
|
||||
// if (!secConfigService.isConfig("KFC_CONFIG" , object.getString("merchId"))) {
|
||||
// throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "当前帐户无权限查询!");
|
||||
// }
|
||||
// // 判断就餐方式
|
||||
// if (object.getInteger("eatType") == null) {
|
||||
// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请选择就餐方式!");
|
||||
// }
|
||||
// // 下单
|
||||
// jsonObject = QianZhuConfig.createKfcOrder(object.getInteger("eatType"), object.getString("storeCode"), object.getString("customerMobile"), object.getString("orderItems"), apiMerchants.getId().toString());
|
||||
//
|
||||
// // 判断下单是否成功
|
||||
// if (!Objects.equals(jsonObject.getString("code"), "10000")) {
|
||||
// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, jsonObject.getString("message"));
|
||||
// }
|
||||
//
|
||||
// // 根据订单号查询订单详情
|
||||
// JSONObject orderObject = QianZhuConfig.getKfcOrderByOrderNo(jsonObject.getJSONObject("data").getString("orderNo"));
|
||||
// // 判断下单是否成功
|
||||
// if (!orderObject.getBoolean("success")) {
|
||||
// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, jsonObject.getString("message"));
|
||||
// }
|
||||
//
|
||||
// // 获取肯德基订单内容
|
||||
// JSONArray kfcOrder = orderObject.getJSONObject("data").getJSONObject("kfcPlaceOrder").getJSONArray("items");
|
||||
// for (Object kfcObject : kfcOrder) {
|
||||
//
|
||||
// JSONObject childObject = (JSONObject) kfcObject;
|
||||
// HighChildOrder childOrder = new HighChildOrder();
|
||||
// childOrder.setOrderId(highOrder.getId());
|
||||
// childOrder.setChildOrdeStatus(1);
|
||||
// childOrder.setGoodsType(4);
|
||||
// childOrder.setMemId(highOrder.getMemId());
|
||||
// childOrder.setExt6(object.getString("storeCode"));
|
||||
// childOrder.setGoodsId(childObject.getLong("productId"));
|
||||
// childOrder.setStoreAddress(orderObject.getJSONObject("data").getJSONObject("kfcPlaceOrder").getString("storeAddress"));
|
||||
// childOrder.setStoreName(orderObject.getJSONObject("data").getJSONObject("kfcPlaceOrder").getString("storeName"));
|
||||
// childOrder.setGoodsName(childObject.getString("productName"));
|
||||
// childOrder.setGoodsImg(childObject.getString("imageUrl"));
|
||||
// childOrder.setSaleCount(childObject.getInteger("quantity"));
|
||||
// childOrder.setGoodsPrice(childObject.getBigDecimal("originPrice"));
|
||||
//
|
||||
// // 计算利润
|
||||
// // 计算子订单支付金额
|
||||
// BigDecimal childPrice = childObject.getBigDecimal("originPrice");
|
||||
// childOrder.setGoodsActualPrice(childPrice);
|
||||
// // 计算市场价金额
|
||||
// childOrder.setTotalPrice(childPrice.multiply(childObject.getBigDecimal("quantity")));
|
||||
// marketPriceTotal = marketPriceTotal.add(childOrder.getTotalPrice());
|
||||
// highChildOrderMapper.insert(childOrder);
|
||||
// }
|
||||
// // 拼接json对象
|
||||
// object.put("sourceType" , 4);
|
||||
// object.put("content" , apiMerchants.getMerchantName() + "|" + "肯德基下单" + "|扣款" + marketPriceTotal);
|
||||
// } else if (object.getInteger("productType") == 3) {
|
||||
//
|
||||
// // 判断是否有会员充值下单权限
|
||||
// if (!secConfigService.isConfig("MEMBER_RECHARGE_CONFIG" , object.getString("merchId"))) {
|
||||
// throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "当前帐户无权限查询!");
|
||||
// }
|
||||
//
|
||||
// // 获取会员充值
|
||||
// ApiMemberProduct memberProduct = apiMemberProductService.findById(object.getLong("goodsId"));
|
||||
//
|
||||
// if (memberProduct == null) {
|
||||
// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "当前产品不可购买");
|
||||
// }
|
||||
//
|
||||
// object.put("productId", memberProduct.getProductId());
|
||||
//
|
||||
// HighChildOrder childOrder = new HighChildOrder();
|
||||
// childOrder.setOrderId(highOrder.getId());
|
||||
// childOrder.setChildOrdeStatus(1);
|
||||
// childOrder.setGoodsType(10);
|
||||
// childOrder.setStoreId(object.getLong("storeCode"));
|
||||
// childOrder.setGoodsId(memberProduct.getId());
|
||||
// childOrder.setGoodsName(memberProduct.getName());
|
||||
// childOrder.setSaleCount(1);
|
||||
// childOrder.setMemId(highOrder.getMemId());
|
||||
// childOrder.setGoodsPrice(memberProduct.getPrice());
|
||||
// childOrder.setGoodsActualPrice(memberProduct.getPrice());
|
||||
// // 计算市场价金额
|
||||
// childOrder.setTotalPrice(memberProduct.getPrice());
|
||||
// marketPriceTotal = marketPriceTotal.add(childOrder.getTotalPrice());
|
||||
// highChildOrderMapper.insert(childOrder);
|
||||
// object.put("sourceType" , 6);
|
||||
// object.put("content" , apiMerchants.getMerchantName() + "|" + "第三方会员充值下单" + "|扣款" + marketPriceTotal);
|
||||
// }
|
||||
// // 当前账号余额是否可以充值当前金额
|
||||
// if (apiMerchants.getAmounts().compareTo(marketPriceTotal) < 0) {
|
||||
// throw ErrorHelp.genException(SysCode.System, ErrorCode.INSUFFICIENT_BALANCE);
|
||||
// }
|
||||
//
|
||||
// highOrder.setTotalPrice(marketPriceTotal);
|
||||
// highOrder.setPayPrice(marketPriceTotal);
|
||||
// highOrder.setPayRealPrice(marketPriceTotal);
|
||||
// highOrder.setPayablePrice(marketPriceTotal);
|
||||
// ApiAmountRecord apiAmountRecord = apiMerchantAmount(highOrder , apiMerchants , object);
|
||||
//
|
||||
// highOrder.setOrderStatus(2);
|
||||
// highOrder.setPayTime(new Date());
|
||||
// highOrder.setPaySerialNo("22" + DateUtil.date2String(new Date(), "yyyyMMddHHmmss") + IDGenerator.nextId(5));
|
||||
// highOrderMapper.updateByPrimaryKey(highOrder);
|
||||
//
|
||||
// // 更新子订单状态
|
||||
// List<HighChildOrder> childOrderList = highOrderService.getChildOrderByOrder(highOrder.getId());
|
||||
//
|
||||
// for (HighChildOrder highChildOrder : childOrderList) {
|
||||
// highChildOrder.setChildOrdeStatus(2);
|
||||
// highChildOrderMapper.updateByPrimaryKey(highChildOrder);
|
||||
// }
|
||||
//
|
||||
// // 插入订单记录
|
||||
// ApiOrderRecord apiOrderRecordPost = new ApiOrderRecord();
|
||||
// apiOrderRecordPost.setStatus(103);
|
||||
// apiOrderRecordPost.setOrderNo(highOrder.getOrderNo());
|
||||
// apiOrderRecordPost.setSourceOrderNo(apiAmountRecord.getSourceOrderNo());
|
||||
// apiOrderRecordPost.setCreateTime(new Date());
|
||||
// apiOrderRecordPost.setMchId(apiMerchants.getMchId());
|
||||
// apiOrderRecordPost.setOrderId(highOrder.getId());
|
||||
// apiOrderRecordPost.setGoodsId(apiMerchants.getMchId());
|
||||
// apiOrderRecordPost.setNotifyUrl(object.getString("notifyUrl"));
|
||||
// apiOrderRecordPost.setUpdateTime(new Date());
|
||||
//
|
||||
// apiOrderRecordService.insertOrderRecord(apiOrderRecordPost);
|
||||
} |
||||
|
||||
private ApiAmountRecord apiMerchantAmount(HighOrder highOrder , ApiMerchants apiMerchants , JSONObject object) throws Exception { |
||||
// 插入金额记录
|
||||
// 变更前金额
|
||||
BigDecimal beforeAmount = apiMerchants.getAmounts(); |
||||
// 计算金额
|
||||
apiMerchants.setAmounts(apiMerchants.getAmounts().subtract(highOrder.getPayPrice())); |
||||
// 变更后金额
|
||||
BigDecimal afterAmount = apiMerchants.getAmounts(); |
||||
|
||||
apiMerchantsService.updateApiMerchants(apiMerchants); |
||||
|
||||
ApiAmountRecord apiAmountRecord = new ApiAmountRecord(); |
||||
|
||||
apiAmountRecord.setCreateTime(new Date()); |
||||
apiAmountRecord.setUpdateTime(new Date()); |
||||
apiAmountRecord.setMchId(apiMerchants.getMchId()); |
||||
|
||||
apiAmountRecord.setStatus(100); |
||||
apiAmountRecord.setAmount(highOrder.getPayPrice()); |
||||
apiAmountRecord.setAfterAmount(afterAmount); |
||||
apiAmountRecord.setBeforeAmount(beforeAmount); |
||||
apiAmountRecord.setAmountType(2); |
||||
apiAmountRecord.setSourceType(object.getInteger("sourceType")); |
||||
apiAmountRecord.setSourceOrderNo(object.getString("sourceOrderNo")); |
||||
apiAmountRecord.setSourceId(apiMerchants.getId()); |
||||
apiAmountRecord.setSourceContent(object.getString("content")); |
||||
|
||||
apiAmountRecordService.insertAmountRecord(apiAmountRecord); |
||||
|
||||
return apiAmountRecord; |
||||
} |
||||
|
||||
} |
@ -1,353 +0,0 @@ |
||||
package com.v1.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hai.common.exception.ErrorCode; |
||||
import com.hai.common.exception.ErrorHelp; |
||||
import com.hai.common.exception.SysCode; |
||||
import com.hai.common.utils.ResponseMsgUtil; |
||||
import com.hai.entity.*; |
||||
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.collections4.MapUtils; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @serviceName rechargeProductController.java |
||||
* @author Sum1Dream |
||||
* @version 1.0.0 |
||||
* @Description // 充值产品接口
|
||||
* @createTime 17:14 2022/6/9 |
||||
**/ |
||||
@Controller |
||||
@RequestMapping(value = "/rechargeProduct") |
||||
@Api(value = "充值产品接口") |
||||
public class RechargeProductController { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(RechargeProductController.class); |
||||
|
||||
@Resource |
||||
private ApiMerchantsService apiMerchantsService; |
||||
|
||||
@Resource |
||||
private SecConfigService secConfigService; |
||||
|
||||
@Resource |
||||
private OutRechargeOrderService outRechargeOrderService; |
||||
|
||||
@Resource |
||||
private ApiOrderRecordService apiOrderRecordService; |
||||
|
||||
@Resource |
||||
private ApiProductService apiProductService; |
||||
|
||||
@Resource |
||||
private ApiOpenService apiOpenService; |
||||
|
||||
@Resource |
||||
private ApiIpAddressService apiIpAddressService; |
||||
|
||||
@RequestMapping(value = "/getRechargeProduct", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "获取充值产品") |
||||
public ResponseData getRechargeProduct(@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("timetable")) || |
||||
StringUtils.isBlank(object.getString("merchId")) || |
||||
StringUtils.isBlank(object.getString("sign")) || |
||||
object.getInteger("rechargeType") == null |
||||
) { |
||||
log.error("getRechargeProduct error!", "请求参数校验失败!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); |
||||
} |
||||
|
||||
ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); |
||||
|
||||
if (apiMerchants == null) { |
||||
log.error("getRechargeProduct error!", "错误商户,请联系管理人员!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); |
||||
} |
||||
|
||||
Map<String , Object> map = new HashMap<>(); |
||||
map.put("timetable" , object.getString("timetable")); |
||||
map.put("apiKey" , object.getString("apiKey")); |
||||
map.put("merchId" , object.getString("merchId")); |
||||
map.put("rechargeType" , object.getString("rechargeType")); |
||||
|
||||
if (!secConfigService.isSignVerify(map , object.getString("sign"))) { |
||||
log.error("getRechargeProduct error!", "签名校验失败!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); |
||||
} |
||||
|
||||
if (!ToolConfig.timetableCheck(15L , object.getLong("timetable"))) { |
||||
log.error("getRechargeProduct error!", "请求时间超过15分钟!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.TIME_OUT); |
||||
} |
||||
|
||||
return ResponseMsgUtil.success(apiMerchantsService.getMerchProduct(apiMerchants.getId() , object.getInteger("rechargeType"))); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighOpenApiController --> getRechargeProduct() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/checkAccountBalance", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询帐户余额") |
||||
public ResponseData checkAccountBalance(@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("timetable")) || |
||||
StringUtils.isBlank(object.getString("sign")) |
||||
) { |
||||
log.error("getRechargeProduct error!", "请求参数校验失败!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); |
||||
} |
||||
|
||||
ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); |
||||
|
||||
if (apiMerchants == null) { |
||||
log.error("getRechargeProduct error!", "商户号错误!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); |
||||
} |
||||
|
||||
Map<String , Object> map = new HashMap<>(); |
||||
map.put("apiKey" , object.getString("apiKey")); |
||||
map.put("timetable" , object.getString("timetable")); |
||||
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); |
||||
} |
||||
|
||||
if (!ToolConfig.timetableCheck(15L , object.getLong("timetable"))) { |
||||
log.error("getRechargeProduct error!", "请求时间超过15分钟!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.TIME_OUT); |
||||
} |
||||
|
||||
return ResponseMsgUtil.success(apiMerchants.getAmounts()); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighOpenApiController --> getRechargeProduct() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/queryOrderResult", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询订单结果") |
||||
public ResponseData queryOrderResult(@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("timetable")) || |
||||
StringUtils.isBlank(object.getString("merchId")) || |
||||
StringUtils.isBlank(object.getString("sign")) || |
||||
StringUtils.isBlank(object.getString("sourceOrderNo")) |
||||
) { |
||||
log.error("getRechargeProduct error!", "请求参数校验失败!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); |
||||
} |
||||
|
||||
ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); |
||||
|
||||
if (apiMerchants == null) { |
||||
log.error("getRechargeProduct error!", "商户号错误!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); |
||||
} |
||||
|
||||
Map<String , Object> map = new HashMap<>(); |
||||
map.put("apiKey" , object.getString("apiKey")); |
||||
map.put("timetable" , object.getString("timetable")); |
||||
map.put("merchId" , object.getString("merchId")); |
||||
map.put("sourceOrderNo" , object.getString("sourceOrderNo")); |
||||
|
||||
if (!secConfigService.isSignVerify(map , object.getString("sign"))) { |
||||
log.error("getRechargeProduct error!", "签名校验失败!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); |
||||
} |
||||
|
||||
if (!ToolConfig.timetableCheck(15L , object.getLong("timetable"))) { |
||||
log.error("getRechargeProduct error!", "请求时间超过15分钟!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.TIME_OUT); |
||||
} |
||||
|
||||
ApiOrderRecord apiOrderRecord = apiOrderRecordService.queryOrderResult(map); |
||||
|
||||
OutRechargeOrder rechargeOrder = outRechargeOrderService.findByOrderNo(apiOrderRecord.getOrderNo()); |
||||
|
||||
JSONObject returnObject = new JSONObject(); |
||||
returnObject.put("sourceOrderNo" , apiOrderRecord.getSourceOrderNo()); |
||||
returnObject.put("callbackStatus" , apiOrderRecord.getStatus()); |
||||
returnObject.put("apiConfigProductId" , apiOrderRecord.getGoodsId()); |
||||
returnObject.put("type" , rechargeOrder.getType()); |
||||
returnObject.put("operatorName" , rechargeOrder.getOperatorName()); |
||||
returnObject.put("rechargeType" , rechargeOrder.getRechargeType()); |
||||
returnObject.put("rechargeContent" , rechargeOrder.getRechargeContent()); |
||||
returnObject.put("rechargePrice" , rechargeOrder.getRechargePrice()); |
||||
returnObject.put("payPrice" , rechargeOrder.getPayPrice()); |
||||
returnObject.put("createTimed" , rechargeOrder.getCreateTimed()); |
||||
returnObject.put("payStatus" , rechargeOrder.getPayStatus()); |
||||
returnObject.put("rechargeStatus" , rechargeOrder.getRechargeStatus()); |
||||
|
||||
|
||||
return ResponseMsgUtil.success(returnObject); |
||||
|
||||
} 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 (!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("mobile")) || |
||||
StringUtils.isBlank(object.getString("apiConfigProductId")) || |
||||
StringUtils.isBlank(object.getString("apiKey")) || |
||||
StringUtils.isBlank(object.getString("timetable")) || |
||||
StringUtils.isBlank(object.getString("sourceOrderNo")) || |
||||
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<>(); |
||||
|
||||
productMap.put("id" , object.getString("apiConfigProductId")); |
||||
productMap.put("merchantsId" , apiMerchants.getId()); |
||||
|
||||
ApiProductConfig apiProductConfig = apiProductService.findMchProduct(productMap); |
||||
|
||||
if (apiProductConfig == null) { |
||||
log.error("createOrder error!", " 商品错误!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.PRODUCT_ERROR); |
||||
} |
||||
|
||||
if (apiProductConfig.getStatus() == 102) { |
||||
log.error("createOrder error!", " 商品状态错误!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR , "商品状态错误"); |
||||
} |
||||
|
||||
Map<String , Object> map = new HashMap<>(); |
||||
map.put("mobile" , object.getString("mobile")); |
||||
map.put("apiConfigProductId" , object.getString("apiConfigProductId")); |
||||
map.put("timetable" , object.getString("timetable")); |
||||
map.put("sourceOrderNo" , object.getString("sourceOrderNo")); |
||||
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); |
||||
} |
||||
|
||||
if (!secConfigService.isConfig("PHONE_CONFIG" , object.getString("merchId"))) { |
||||
log.error("getAllCities error!", "当前帐户无权限查询!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "当前帐户无权限查询!"); |
||||
} |
||||
|
||||
apiOpenService.createOrder(object , apiMerchants , apiProductConfig); |
||||
return ResponseMsgUtil.success("下单成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighOpenApiController --> createOrder() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
@ -1,545 +0,0 @@ |
||||
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.*; |
||||
import com.hai.model.ResponseData; |
||||
import com.hai.service.*; |
||||
import com.v1.config.ToolConfig; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.RequestBody; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RequestMethod; |
||||
import org.springframework.web.bind.annotation.ResponseBody; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.math.BigDecimal; |
||||
import java.math.RoundingMode; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @serviceName ThirdPartyController.java |
||||
* @author Sum1Dream |
||||
* @version 1.0.0 |
||||
* @Description // 第三方产品接口
|
||||
* @createTime 14:48 2022/6/28 |
||||
**/ |
||||
@Controller |
||||
@RequestMapping(value = "/thirdParty") |
||||
@Api(value = "第三方产品接口") |
||||
public class ThirdPartyController { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(ThirdPartyController.class); |
||||
|
||||
@Resource |
||||
private ApiMerchantsService apiMerchantsService; |
||||
|
||||
@Resource |
||||
private SecConfigService secConfigService; |
||||
|
||||
@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 = "查询可用城市") |
||||
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); |
||||
} |
||||
|
||||
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")); |
||||
|
||||
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); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getStarbucksStore", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询星巴克门店") |
||||
public ResponseData getStarbucksStore(@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("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")); |
||||
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("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 (!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("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")); |
||||
|
||||
|
||||
if (!secConfigService.isSignVerify(map , object.getString("sign"))) { |
||||
log.error("getRechargeProduct error!", "签名校验失败!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); |
||||
} |
||||
|
||||
Map<String, Object> mapStores = new HashMap<>(); |
||||
List<ApiKfcStores> list = apiProductService.getKfcStoresList(mapStores); |
||||
|
||||
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 (!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("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 (!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("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) { |
||||
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 (!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("customerMobile")) || |
||||
StringUtils.isBlank(object.getString("productType")) || |
||||
StringUtils.isBlank(object.getString("apiKey")) || |
||||
StringUtils.isBlank(object.getString("timetable")) || |
||||
StringUtils.isBlank(object.getString("sourceOrderNo")) || |
||||
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> map = new HashMap<>(); |
||||
map.put("customerMobile" , object.getString("customerMobile")); |
||||
map.put("productType" , object.getString("productType")); |
||||
map.put("timetable" , object.getString("timetable")); |
||||
map.put("sourceOrderNo" , object.getString("sourceOrderNo")); |
||||
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); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,218 @@ |
||||
package com.v1.controller.business; |
||||
|
||||
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.ApiKfcStores; |
||||
import com.hai.entity.ApiMchProduct; |
||||
import com.hai.entity.ApiMerchants; |
||||
import com.hai.model.ResponseData; |
||||
import com.hai.openApi.config.PriceComputeConfig; |
||||
import com.hai.openApi.service.ApiMchProductService; |
||||
import com.hai.order.type.OrderProductType; |
||||
import com.hai.service.ApiIpAddressService; |
||||
import com.hai.service.ApiMerchantsService; |
||||
import com.hai.service.ApiProductService; |
||||
import com.hai.service.SecConfigService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.RequestBody; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RequestMethod; |
||||
import org.springframework.web.bind.annotation.ResponseBody; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
@Controller |
||||
@RequestMapping(value = "/kfc") |
||||
@Api(value = "kfc业务") |
||||
public class KfcController { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(KfcController.class); |
||||
|
||||
@Resource |
||||
private ApiMerchantsService apiMerchantsService; |
||||
|
||||
@Resource |
||||
private SecConfigService secConfigService; |
||||
|
||||
@Resource |
||||
private ApiIpAddressService apiIpAddressService; |
||||
|
||||
@Resource |
||||
private ApiProductService apiProductService; |
||||
|
||||
@Resource |
||||
private PriceComputeConfig priceComputeConfig; |
||||
|
||||
@Resource |
||||
private ApiMchProductService apiMchProductService; |
||||
|
||||
@RequestMapping(value = "/kfcStoresList", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询肯德基门店") |
||||
public ResponseData kfcStoresList(@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_TYPE2.getApiCode(), 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> mapStores = new HashMap<>(); |
||||
List<ApiKfcStores> list = apiProductService.getKfcStoresList(mapStores); |
||||
|
||||
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 (!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("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(OrderProductType.PRODUCT_TYPE2.getApiCode(), 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, "未查询到商品"); |
||||
} |
||||
|
||||
Map<String, Object> mapProduct = new HashMap<>(); |
||||
mapProduct.put("mchId" , object.getString("merchId")); |
||||
mapProduct.put("productType" , OrderProductType.PRODUCT_TYPE2.getNumber()); |
||||
|
||||
ApiMchProduct apiMchProducts = apiMchProductService.findByMap(mapProduct); |
||||
|
||||
|
||||
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" , priceComputeConfig.computationPriceCost(apiMchProducts.getDiscount() , productsObject.getBigDecimal("originalPrice") , productsObject.getBigDecimal("price"))); |
||||
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" , priceComputeConfig.computationPriceCost(apiMchProducts.getDiscount() , specGroupsObject.getBigDecimal("originalPrice") , specGroupsObject.getBigDecimal("price"))); |
||||
specGroupsObject.put("taxPrice" , null); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
return ResponseMsgUtil.success(array); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighOpenApiController --> getRechargeProduct() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,131 @@ |
||||
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.entity.ApiMchProduct; |
||||
import com.hai.entity.ApiMemberProduct; |
||||
import com.hai.entity.ApiMerchants; |
||||
import com.hai.model.ResponseData; |
||||
import com.hai.openApi.config.PriceComputeConfig; |
||||
import com.hai.openApi.service.ApiMchProductService; |
||||
import com.hai.order.type.OrderProductType; |
||||
import com.hai.service.*; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.RequestBody; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RequestMethod; |
||||
import org.springframework.web.bind.annotation.ResponseBody; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
@Controller |
||||
@RequestMapping(value = "/memberRecharge") |
||||
@Api(value = "会员充值业务") |
||||
public class MemberProductsController { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(MemberProductsController.class); |
||||
|
||||
@Resource |
||||
private ApiMerchantsService apiMerchantsService; |
||||
|
||||
@Resource |
||||
private SecConfigService secConfigService; |
||||
|
||||
@Resource |
||||
private ApiIpAddressService apiIpAddressService; |
||||
|
||||
@Resource |
||||
private ApiProductService apiProductService; |
||||
|
||||
@Resource |
||||
private PriceComputeConfig priceComputeConfig; |
||||
|
||||
@Resource |
||||
private ApiMchProductService apiMchProductService; |
||||
|
||||
@Resource |
||||
private ApiMemberProductService apiMemberProductService; |
||||
|
||||
|
||||
@RequestMapping(value = "/memberProducts", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询会员产品") |
||||
public ResponseData memberProducts(@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_TYPE3.getApiCode(), 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); |
||||
} |
||||
|
||||
|
||||
List<ApiMemberProduct> list = apiMemberProductService.getListApiMemberProduct(new HashMap<>()); |
||||
|
||||
Map<String, Object> mapProduct = new HashMap<>(); |
||||
mapProduct.put("mchId" , object.getString("merchId")); |
||||
mapProduct.put("productType" , OrderProductType.PRODUCT_TYPE3.getNumber()); |
||||
|
||||
ApiMchProduct apiMchProducts = apiMchProductService.findByMap(mapProduct); |
||||
|
||||
|
||||
for (ApiMemberProduct apiMemberProduct : list) { |
||||
apiMemberProduct.setCostPrice(priceComputeConfig.computationPriceCost(apiMchProducts.getDiscount() , apiMemberProduct.getPrice() , apiMemberProduct.getCostPrice())); |
||||
} |
||||
|
||||
return ResponseMsgUtil.success(list); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighOpenApiController --> getRechargeProduct() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue