parent
f70899b16a
commit
03f9ca62a0
File diff suppressed because one or more lines are too long
@ -0,0 +1,62 @@ |
|||||||
|
package com.hai.openApi.config; |
||||||
|
|
||||||
|
import com.hai.entity.ApiAmountRecord; |
||||||
|
import com.hai.entity.ApiMerchants; |
||||||
|
import com.hai.order.type.OrderProductType; |
||||||
|
import com.hai.service.ApiAmountRecordService; |
||||||
|
import com.hai.service.ApiMerchantsService; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
import javax.annotation.Resource; |
||||||
|
import java.math.BigDecimal; |
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
@Component |
||||||
|
public class PriceComputeConfig { |
||||||
|
|
||||||
|
@Resource |
||||||
|
private ApiMerchantsService apiMerchantsService; |
||||||
|
|
||||||
|
@Resource |
||||||
|
private ApiAmountRecordService apiAmountRecordService; |
||||||
|
|
||||||
|
public Boolean mchBalance(ApiMerchants apiMerchants , BigDecimal price , String orderNo) { |
||||||
|
|
||||||
|
|
||||||
|
// 当前账号余额是否可以充值当前金额
|
||||||
|
if (apiMerchants.getAmounts().compareTo(price) < 0) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
// 插入金额记录
|
||||||
|
// 变更前金额
|
||||||
|
BigDecimal beforeAmount = apiMerchants.getAmounts(); |
||||||
|
// 计算金额
|
||||||
|
apiMerchants.setAmounts(apiMerchants.getAmounts().subtract(price)); |
||||||
|
// 变更后金额
|
||||||
|
BigDecimal afterAmount = apiMerchants.getAmounts(); |
||||||
|
|
||||||
|
apiMerchantsService.updateApiMerchants(apiMerchants); |
||||||
|
|
||||||
|
ApiAmountRecord apiAmountRecord = new ApiAmountRecord(); |
||||||
|
|
||||||
|
apiAmountRecord.setCreateTime(new Date()); |
||||||
|
apiAmountRecord.setUpdateTime(new Date()); |
||||||
|
apiAmountRecord.setMchId(apiMerchants.getMchId()); |
||||||
|
|
||||||
|
apiAmountRecord.setStatus(100); |
||||||
|
apiAmountRecord.setAmount(price); |
||||||
|
apiAmountRecord.setAfterAmount(afterAmount); |
||||||
|
apiAmountRecord.setBeforeAmount(beforeAmount); |
||||||
|
apiAmountRecord.setAmountType(2); |
||||||
|
apiAmountRecord.setSourceType(OrderProductType.PRODUCT_TYPE6.getNumber()); |
||||||
|
apiAmountRecord.setSourceOrderNo(orderNo); |
||||||
|
apiAmountRecord.setSourceId(apiMerchants.getId()); |
||||||
|
apiAmountRecord.setSourceContent(apiMerchants.getMerchantName() + "|在线加油|扣款" + price.setScale(2, BigDecimal.ROUND_HALF_DOWN)); |
||||||
|
|
||||||
|
apiAmountRecordService.insertAmountRecord(apiAmountRecord); |
||||||
|
|
||||||
|
|
||||||
|
return true; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,31 @@ |
|||||||
|
package com.hai.openApi.service; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
import com.hai.entity.ApiOrder; |
||||||
|
import com.hai.entity.HighChildOrder; |
||||||
|
import com.hai.entity.HighDiscountUserRel; |
||||||
|
import com.hai.entity.HighOrder; |
||||||
|
import com.hai.order.model.CreateOrderChildModel; |
||||||
|
import com.hai.order.model.CreateOrderModel; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 创建订单-业务校验、组装数据 |
||||||
|
* @className: CreateOrderCheckService |
||||||
|
* @author: HuRui |
||||||
|
* @date: 2022/8/25 |
||||||
|
**/ |
||||||
|
public interface ApiOrderCreateHandleService { |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author Sum1Dream |
||||||
|
* @Name oilHandle |
||||||
|
* @Description // 在线加油校验操作
|
||||||
|
* @Date 13:59 2023/3/1 |
||||||
|
* @Param [object] |
||||||
|
* @Return com.hai.entity.ApiOrder |
||||||
|
*/ |
||||||
|
ApiOrder oilHandle(JSONObject object) throws Exception; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,60 @@ |
|||||||
|
package com.hai.openApi.service; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
import com.hai.entity.ApiOrder; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* @Author Sum1Dream |
||||||
|
* @Name orderService |
||||||
|
* @Description // 订单业务
|
||||||
|
* @Date 17:43 2023/2/28 |
||||||
|
* @Param |
||||||
|
* @Return |
||||||
|
*/ |
||||||
|
public interface ApiOrderService { |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author Sum1Dream |
||||||
|
* @Name createOrder |
||||||
|
* @Description // 创建订单
|
||||||
|
* @Date 17:44 2023/2/28 |
||||||
|
* @Param [object] |
||||||
|
* @Return void |
||||||
|
*/ |
||||||
|
ApiOrder createOrder(JSONObject object) throws Exception; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* @Author Sum1Dream |
||||||
|
* @Name payOrder |
||||||
|
* @Description // 创建订单
|
||||||
|
* @Date 17:44 2023/2/28 |
||||||
|
* @Param [object] |
||||||
|
* @Return void |
||||||
|
*/ |
||||||
|
ApiOrder payOrder(JSONObject object) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author Sum1Dream |
||||||
|
* @Name getOrderByMap |
||||||
|
* @Description // 查询订单
|
||||||
|
* @Date 17:49 2023/2/28 |
||||||
|
* @Param [map] |
||||||
|
* @Return com.hai.entity.ApiOrder |
||||||
|
*/ |
||||||
|
List<ApiOrder> getOrderByMap(Map<String , Object> map); |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author Sum1Dream |
||||||
|
* @Name findByOrderNo |
||||||
|
* @Description // 根据订单号查询订单
|
||||||
|
* @Date 20:40 2023/3/1 |
||||||
|
* @Param [mchOrderNo, orderNo] |
||||||
|
* @Return com.hai.entity.ApiOrder |
||||||
|
*/ |
||||||
|
ApiOrder findByOrderNo(String mchOrderNo , String orderNo); |
||||||
|
} |
@ -0,0 +1,97 @@ |
|||||||
|
package com.hai.openApi.service.impl; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
import com.hai.common.exception.ErrorCode; |
||||||
|
import com.hai.common.exception.ErrorHelp; |
||||||
|
import com.hai.common.exception.SysCode; |
||||||
|
import com.hai.entity.*; |
||||||
|
import com.hai.openApi.config.PriceComputeConfig; |
||||||
|
import com.hai.openApi.service.ApiMchProductService; |
||||||
|
import com.hai.openApi.service.ApiOrderCreateHandleService; |
||||||
|
import com.hai.service.ApiMerchantsService; |
||||||
|
import com.hai.service.HighGasOilPriceService; |
||||||
|
import com.hai.service.HighMerchantStoreService; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import javax.annotation.Resource; |
||||||
|
import java.math.BigDecimal; |
||||||
|
import java.util.Date; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
@Service("apiOrderCreateHandleService") |
||||||
|
public class ApiOrderCreateHandleServiceImpl implements ApiOrderCreateHandleService { |
||||||
|
|
||||||
|
@Resource |
||||||
|
private ApiMerchantsService apiMerchantsService; |
||||||
|
|
||||||
|
@Resource |
||||||
|
private HighGasOilPriceService highGasOilPriceService; |
||||||
|
|
||||||
|
@Resource |
||||||
|
private PriceComputeConfig priceComputeConfig; |
||||||
|
|
||||||
|
@Resource |
||||||
|
private HighMerchantStoreService highMerchantStoreService; |
||||||
|
|
||||||
|
@Resource |
||||||
|
private ApiMchProductService apiMchProductService; |
||||||
|
|
||||||
|
@Override |
||||||
|
public ApiOrder oilHandle(JSONObject object) throws Exception { |
||||||
|
|
||||||
|
// 获取下单内容
|
||||||
|
JSONObject dataObject = JSONObject.parseObject(object.getString("content")); |
||||||
|
|
||||||
|
// 查询油枪价
|
||||||
|
HighGasOilPrice highGasOilPrice = highGasOilPriceService.getGasOilPriceByStoreAndOilNo(dataObject.getLong("storeCode") , dataObject.getString("gasOilNo")); |
||||||
|
|
||||||
|
// 查询api商户
|
||||||
|
ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); |
||||||
|
|
||||||
|
// 查询加油门店
|
||||||
|
HighMerchantStore merchantStore = highMerchantStoreService.getMerchantStoreById(dataObject.getLong("storeCode")); |
||||||
|
|
||||||
|
// 查询折扣比例
|
||||||
|
Map<String , Object> mchProductMap = new HashMap<>(); |
||||||
|
mchProductMap.put("productType" , object.getString("productType")); |
||||||
|
mchProductMap.put("mchId" , object.getString("merchId")); |
||||||
|
mchProductMap.put("merchantId" , merchantStore.getMerchantId()); |
||||||
|
ApiMchProduct mchProduct = apiMchProductService.findByMap(mchProductMap); |
||||||
|
|
||||||
|
BigDecimal price = dataObject.getBigDecimal("refuelPrice").multiply(mchProduct.getDiscount()).divide(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_DOWN); |
||||||
|
|
||||||
|
// 判断金额是否充足
|
||||||
|
if (apiMerchants.getAmounts().compareTo(price) < 0) { |
||||||
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.INSUFFICIENT_BALANCE); |
||||||
|
} |
||||||
|
|
||||||
|
// 组装内容
|
||||||
|
JSONObject jsonObject = new JSONObject(); |
||||||
|
jsonObject.put("oilNo" , highGasOilPrice.getOilNo()); |
||||||
|
jsonObject.put("oilNoName" , highGasOilPrice.getOilNoName()); |
||||||
|
jsonObject.put("priceGun" , highGasOilPrice.getPriceGun()); |
||||||
|
jsonObject.put("priceCost" , highGasOilPrice.getPriceGun().multiply(mchProduct.getDiscount()).divide(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP)); |
||||||
|
jsonObject.put("oilTypeName" , highGasOilPrice.getOilTypeName()); |
||||||
|
jsonObject.put("storeName" , merchantStore.getStoreName()); |
||||||
|
jsonObject.put("address" , merchantStore.getAddress()); |
||||||
|
jsonObject.put("regionName" , merchantStore.getRegionName()); |
||||||
|
|
||||||
|
// 组装api订单
|
||||||
|
ApiOrder apiOrder = new ApiOrder(); |
||||||
|
apiOrder.setCreateTime(new Date()); |
||||||
|
apiOrder.setTitle(apiMerchants.getMerchantName() + "|在线加油|扣款" + price); |
||||||
|
apiOrder.setFacePrice(dataObject.getBigDecimal("refuelPrice")); |
||||||
|
apiOrder.setCostPrice(price); |
||||||
|
apiOrder.setMchId(object.getString("merchId")); |
||||||
|
apiOrder.setMchName(apiMerchants.getMerchantName()); |
||||||
|
apiOrder.setUpdateTime(new Date()); |
||||||
|
apiOrder.setProductType(object.getInteger("productType")); |
||||||
|
apiOrder.setMchOrderNo(object.getString("orderNo")); |
||||||
|
apiOrder.setOrderPrice(dataObject.getBigDecimal("refuelPrice")); |
||||||
|
apiOrder.setNotifyUrl(object.getString("notifyUrl")); |
||||||
|
apiOrder.setContent(jsonObject.toJSONString()); |
||||||
|
|
||||||
|
return apiOrder; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,201 @@ |
|||||||
|
package com.hai.openApi.service.impl; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
import com.hai.common.exception.ErrorCode; |
||||||
|
import com.hai.common.exception.ErrorHelp; |
||||||
|
import com.hai.common.exception.SysCode; |
||||||
|
import com.hai.common.utils.DateUtil; |
||||||
|
import com.hai.dao.ApiOrderMapper; |
||||||
|
import com.hai.entity.ApiMerchants; |
||||||
|
import com.hai.entity.ApiOrder; |
||||||
|
import com.hai.entity.ApiOrderExample; |
||||||
|
import com.hai.entity.HighOrder; |
||||||
|
import com.hai.openApi.service.ApiOrderCreateHandleService; |
||||||
|
import com.hai.openApi.service.ApiOrderService; |
||||||
|
import com.hai.order.model.CreateOrderChildModel; |
||||||
|
import com.hai.order.model.CreateOrderModel; |
||||||
|
import com.hai.order.service.OrderPayBeforeService; |
||||||
|
import com.hai.order.service.OrderPayService; |
||||||
|
import com.hai.order.service.OrderService; |
||||||
|
import com.hai.order.type.OrderChildGoodsType; |
||||||
|
import com.hai.order.type.OrderProductType; |
||||||
|
import com.hai.order.type.OrderStatus; |
||||||
|
import com.hai.order.utils.OrderUtil; |
||||||
|
import com.hai.service.ApiMerchantsService; |
||||||
|
import org.apache.commons.collections4.MapUtils; |
||||||
|
import org.apache.commons.lang3.StringUtils; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
import org.springframework.transaction.annotation.Isolation; |
||||||
|
import org.springframework.transaction.annotation.Propagation; |
||||||
|
import org.springframework.transaction.annotation.Transactional; |
||||||
|
|
||||||
|
import javax.annotation.Resource; |
||||||
|
import java.util.*; |
||||||
|
|
||||||
|
@Service("apiOrderService") |
||||||
|
public class ApiOrderServiceImpl implements ApiOrderService { |
||||||
|
|
||||||
|
@Resource |
||||||
|
private ApiMerchantsService apiMerchantsService; |
||||||
|
|
||||||
|
@Resource |
||||||
|
private ApiOrderMapper apiOrderMapper; |
||||||
|
|
||||||
|
@Resource |
||||||
|
private ApiOrderCreateHandleService orderCreateHandleService; |
||||||
|
|
||||||
|
@Resource |
||||||
|
private OrderService orderService; |
||||||
|
|
||||||
|
@Resource |
||||||
|
private OrderPayBeforeService orderPayBeforeService; |
||||||
|
|
||||||
|
@Resource |
||||||
|
private OrderPayService orderPayService; |
||||||
|
|
||||||
|
@Resource |
||||||
|
private ApiOrderService apiOrderService; |
||||||
|
|
||||||
|
@Override |
||||||
|
@Transactional(rollbackFor=Exception.class,isolation = Isolation.SERIALIZABLE,propagation= Propagation.REQUIRES_NEW) |
||||||
|
public ApiOrder createOrder(JSONObject object) throws Exception { |
||||||
|
|
||||||
|
ApiOrder apiOrder = new ApiOrder(); |
||||||
|
|
||||||
|
|
||||||
|
// 获取下单内容
|
||||||
|
JSONObject dataObject = JSONObject.parseObject(object.getString("content")); |
||||||
|
|
||||||
|
|
||||||
|
CreateOrderModel createOrderModel = new CreateOrderModel(); |
||||||
|
createOrderModel.setChildOrderList(new ArrayList<>()); |
||||||
|
|
||||||
|
// 查询订单
|
||||||
|
Map<String , Object> orderMap = new HashMap<>(); |
||||||
|
orderMap.put("mchOrderNo" , object.getString("orderNo")); |
||||||
|
List<ApiOrder> apiOrderList = getOrderByMap(orderMap); |
||||||
|
|
||||||
|
ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); |
||||||
|
|
||||||
|
createOrderModel.setMemName(apiMerchants.getMerchantName()); |
||||||
|
createOrderModel.setMemPhone(apiMerchants.getPhone()); |
||||||
|
createOrderModel.setCompanyId(2L); |
||||||
|
createOrderModel.setOrderNo(OrderUtil.generateOrderNo()); |
||||||
|
|
||||||
|
// 判断订单号是否重复
|
||||||
|
if (apiOrderList.size() > 0) { |
||||||
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.ORDER_ALREADY_EXISTS); |
||||||
|
} |
||||||
|
|
||||||
|
// 处理加油订单
|
||||||
|
if (OrderProductType.PRODUCT_TYPE6.getNumber().equals(object.getInteger("productType"))) { |
||||||
|
apiOrder = orderCreateHandleService.oilHandle(object); |
||||||
|
|
||||||
|
// 组装子订单内容
|
||||||
|
CreateOrderChildModel createOrderChildModel = new CreateOrderChildModel(); |
||||||
|
createOrderChildModel.setMemName(apiMerchants.getMerchantName()); |
||||||
|
createOrderChildModel.setMemPhone(apiMerchants.getPhone()); |
||||||
|
createOrderChildModel.setCompanyId(2L); |
||||||
|
createOrderChildModel.setGoodsType(OrderChildGoodsType.TYPE3.getNumber()); |
||||||
|
createOrderChildModel.setGasGunNo(dataObject.getString("gasGunNo")); |
||||||
|
createOrderChildModel.setGasOilNo(dataObject.getString("gasOilNo")); |
||||||
|
createOrderChildModel.setStoreId(dataObject.getLong("storeCode")); |
||||||
|
createOrderChildModel.setGoodsId(dataObject.getLong("storeCode")); |
||||||
|
createOrderChildModel.setSaleCount(1); |
||||||
|
createOrderChildModel.setIsTyAgent(false); |
||||||
|
createOrderChildModel.setGoodsPrice(apiOrder.getOrderPrice()); |
||||||
|
|
||||||
|
// 组装订单
|
||||||
|
createOrderModel.getChildOrderList().add(createOrderChildModel); |
||||||
|
orderService.createOrder(createOrderModel); |
||||||
|
} |
||||||
|
apiOrder.setOrderNo(createOrderModel.getOrderNo()); |
||||||
|
apiOrder.setStatus(1); |
||||||
|
apiOrderMapper.insert(apiOrder); |
||||||
|
|
||||||
|
return apiOrder; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@Override |
||||||
|
@Transactional(rollbackFor=Exception.class,isolation = Isolation.SERIALIZABLE,propagation= Propagation.REQUIRES_NEW) |
||||||
|
public ApiOrder payOrder(JSONObject object) { |
||||||
|
|
||||||
|
ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); |
||||||
|
|
||||||
|
ApiOrder apiOrder = apiOrderService.findByOrderNo(object.getString("mchOrderNo") , null); |
||||||
|
|
||||||
|
// 查询订单
|
||||||
|
HighOrder order = orderService.getOrderDetailByNo(object.getString("orderNo")); |
||||||
|
if(!order.getOrderStatus().equals(OrderStatus.STATUS1.getNumber())) { |
||||||
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.ORDER_NO_STAY_PAY, ""); |
||||||
|
} |
||||||
|
|
||||||
|
// 支付业务交易
|
||||||
|
orderPayBeforeService.payOrderCheck(order); |
||||||
|
|
||||||
|
// 处理订单
|
||||||
|
HighOrder highOrder = orderPayService.apiMchAmount(order , apiMerchants , apiOrder); |
||||||
|
|
||||||
|
if (highOrder.getOrderStatus() != OrderStatus.STATUS1.getNumber()) { |
||||||
|
apiOrder.setStatus(highOrder.getOrderStatus()); |
||||||
|
apiOrder.setUpdateTime(new Date()); |
||||||
|
apiOrderMapper.updateByPrimaryKey(apiOrder); |
||||||
|
} |
||||||
|
|
||||||
|
return apiOrder; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public List<ApiOrder> getOrderByMap(Map<String, Object> map) { |
||||||
|
|
||||||
|
ApiOrderExample example = new ApiOrderExample(); |
||||||
|
ApiOrderExample.Criteria criteria = example.createCriteria(); |
||||||
|
|
||||||
|
|
||||||
|
if (MapUtils.getInteger(map, "productType") != null) { |
||||||
|
criteria.andProductTypeEqualTo(MapUtils.getInteger(map, "productType")); |
||||||
|
} |
||||||
|
if (StringUtils.isNotBlank(MapUtils.getString(map, "orderNo"))) { |
||||||
|
criteria.andOrderNoEqualTo(MapUtils.getString(map, "orderNo")); |
||||||
|
} |
||||||
|
if (StringUtils.isNotBlank(MapUtils.getString(map, "mchOrderNo"))) { |
||||||
|
criteria.andMchOrderNoEqualTo(MapUtils.getString(map, "mchOrderNo")); |
||||||
|
} |
||||||
|
if (StringUtils.isNotBlank(MapUtils.getString(map, "merchId"))) { |
||||||
|
criteria.andMchIdEqualTo(MapUtils.getString(map, "merchId")); |
||||||
|
} |
||||||
|
if (StringUtils.isNotBlank(MapUtils.getString(map, "createTimeS")) && StringUtils.isNotBlank(MapUtils.getString(map, "createTimeE"))) { |
||||||
|
criteria.andCreateTimeBetween( |
||||||
|
DateUtil.format(MapUtils.getString(map, "createTimeS"), "yyyy-MM-dd HH:mm:ss"), |
||||||
|
DateUtil.format(MapUtils.getString(map, "createTimeE"), "yyyy-MM-dd HH:mm:ss")); |
||||||
|
} |
||||||
|
|
||||||
|
return apiOrderMapper.selectByExample(example); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@Override |
||||||
|
public ApiOrder findByOrderNo(String mchOrderNo , String orderNo) { |
||||||
|
ApiOrderExample example = new ApiOrderExample(); |
||||||
|
ApiOrderExample.Criteria criteria = example.createCriteria(); |
||||||
|
|
||||||
|
if (mchOrderNo != null) { |
||||||
|
criteria.andMchOrderNoEqualTo(mchOrderNo); |
||||||
|
} |
||||||
|
|
||||||
|
if (orderNo != null) { |
||||||
|
criteria.andOrderNoEqualTo(orderNo); |
||||||
|
} |
||||||
|
|
||||||
|
List<ApiOrder> list = apiOrderMapper.selectByExample(example); |
||||||
|
|
||||||
|
if (list.size() > 0) { |
||||||
|
return list.get(0); |
||||||
|
} |
||||||
|
|
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
@ -1,128 +0,0 @@ |
|||||||
package com.v1.controller; |
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject; |
|
||||||
import com.hai.common.exception.ErrorCode; |
|
||||||
import com.hai.common.exception.ErrorHelp; |
|
||||||
import com.hai.common.exception.SysCode; |
|
||||||
import com.hai.common.utils.ResponseMsgUtil; |
|
||||||
import com.hai.entity.ApiMerchants; |
|
||||||
import com.hai.entity.ApiProductConfig; |
|
||||||
import com.hai.model.ResponseData; |
|
||||||
import com.hai.service.*; |
|
||||||
import com.v1.config.ToolConfig; |
|
||||||
import io.swagger.annotations.Api; |
|
||||||
import io.swagger.annotations.ApiOperation; |
|
||||||
import org.apache.commons.lang3.StringUtils; |
|
||||||
import org.slf4j.Logger; |
|
||||||
import org.slf4j.LoggerFactory; |
|
||||||
import org.springframework.stereotype.Controller; |
|
||||||
import org.springframework.web.bind.annotation.RequestBody; |
|
||||||
import org.springframework.web.bind.annotation.RequestMapping; |
|
||||||
import org.springframework.web.bind.annotation.RequestMethod; |
|
||||||
import org.springframework.web.bind.annotation.ResponseBody; |
|
||||||
|
|
||||||
import javax.annotation.Resource; |
|
||||||
import javax.servlet.http.HttpServletRequest; |
|
||||||
import java.util.HashMap; |
|
||||||
import java.util.Map; |
|
||||||
|
|
||||||
@Controller |
|
||||||
@RequestMapping(value = "/apiOrder") |
|
||||||
@Api(value = "API订单接口") |
|
||||||
public class ApiOrderController { |
|
||||||
|
|
||||||
private static Logger log = LoggerFactory.getLogger(RechargeProductController.class); |
|
||||||
|
|
||||||
@Resource |
|
||||||
private ApiMerchantsService apiMerchantsService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private SecConfigService secConfigService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private ApiProductService apiProductService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private ApiOpenService apiOpenService; |
|
||||||
|
|
||||||
@RequestMapping(value = "/createOrder", method = RequestMethod.POST) |
|
||||||
@ResponseBody |
|
||||||
@ApiOperation(value = "充值预下单") |
|
||||||
public ResponseData createOrder(@RequestBody JSONObject object , HttpServletRequest request ) { |
|
||||||
try { |
|
||||||
|
|
||||||
String ip = ""; |
|
||||||
// 有的user可能使用代理,为处理用户使用代理的情况,使用x-forwarded-for
|
|
||||||
if (request.getHeader("x-forwarded-for") == null) { |
|
||||||
ip = request.getRemoteAddr(); |
|
||||||
} else { |
|
||||||
ip = request.getHeader("x-forwarded-for"); |
|
||||||
} |
|
||||||
|
|
||||||
if (!secConfigService.isConfig("IP_WHITE" , ip)) { |
|
||||||
log.error("createOrder error!", "非法ip地址,请联系管理人员!"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.IP_ERROR, "非法ip地址,请联系管理人员!"); |
|
||||||
} |
|
||||||
|
|
||||||
if (StringUtils.isBlank(object.getString("mobile")) || |
|
||||||
StringUtils.isBlank(object.getString("apiProductId")) || |
|
||||||
StringUtils.isBlank(object.getString("apiKey")) || |
|
||||||
StringUtils.isBlank(object.getString("orderType")) || |
|
||||||
StringUtils.isBlank(object.getString("timetable")) || |
|
||||||
StringUtils.isBlank(object.getString("orderNo")) || |
|
||||||
StringUtils.isBlank(object.getString("notifyUrl")) || |
|
||||||
StringUtils.isBlank(object.getString("sign")) || |
|
||||||
StringUtils.isBlank(object.getString("merchId")) |
|
||||||
) { |
|
||||||
log.error("createOrder error!", "请求参数校验失败!"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); |
|
||||||
} |
|
||||||
|
|
||||||
ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); |
|
||||||
|
|
||||||
if (apiMerchants == null) { |
|
||||||
log.error("createOrder error!", "商户错误!"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); |
|
||||||
} |
|
||||||
|
|
||||||
Map<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); |
|
||||||
} |
|
||||||
|
|
||||||
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("orderNo" , object.getString("orderNo")); |
|
||||||
map.put("notifyUrl" , object.getString("notifyUrl")); |
|
||||||
map.put("apiKey" , object.getString("apiKey")); |
|
||||||
map.put("merchId" , object.getString("merchId")); |
|
||||||
|
|
||||||
if (!secConfigService.isSignVerify(map, object.getString("sign"))) { |
|
||||||
log.error("createOrder error!", "签名校验失败!"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); |
|
||||||
} |
|
||||||
|
|
||||||
if (!ToolConfig.timetableCheck(15L , object.getLong("timetable"))) { |
|
||||||
log.error("getRechargeProduct error!", "请求时间超过15分钟!"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.TIME_OUT); |
|
||||||
} |
|
||||||
|
|
||||||
apiOpenService.createOrder(object , apiMerchants , apiProductConfig); |
|
||||||
return ResponseMsgUtil.success("下单成功"); |
|
||||||
|
|
||||||
} catch (Exception e) { |
|
||||||
log.error("HighOpenApiController --> createOrder() error!", e); |
|
||||||
return ResponseMsgUtil.exception(e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,193 +0,0 @@ |
|||||||
package com.v1.controller; |
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject; |
|
||||||
import com.hai.common.exception.ErrorCode; |
|
||||||
import com.hai.common.exception.ErrorHelp; |
|
||||||
import com.hai.common.exception.SysCode; |
|
||||||
import com.hai.common.utils.ResponseMsgUtil; |
|
||||||
import com.hai.entity.ApiMerchants; |
|
||||||
import com.hai.model.ResponseData; |
|
||||||
import com.hai.service.*; |
|
||||||
import com.v1.config.ToolConfig; |
|
||||||
import io.swagger.annotations.Api; |
|
||||||
import io.swagger.annotations.ApiOperation; |
|
||||||
import org.apache.commons.lang3.StringUtils; |
|
||||||
import org.slf4j.Logger; |
|
||||||
import org.slf4j.LoggerFactory; |
|
||||||
import org.springframework.stereotype.Controller; |
|
||||||
import org.springframework.web.bind.annotation.RequestBody; |
|
||||||
import org.springframework.web.bind.annotation.RequestMapping; |
|
||||||
import org.springframework.web.bind.annotation.RequestMethod; |
|
||||||
import org.springframework.web.bind.annotation.ResponseBody; |
|
||||||
|
|
||||||
import javax.annotation.Resource; |
|
||||||
import javax.servlet.http.HttpServletRequest; |
|
||||||
import java.text.SimpleDateFormat; |
|
||||||
import java.util.HashMap; |
|
||||||
import java.util.Map; |
|
||||||
|
|
||||||
/** |
|
||||||
* @serviceName rechargeProductController.java |
|
||||||
* @author Sum1Dream |
|
||||||
* @version 1.0.0 |
|
||||||
* @Description // 充值产品接口
|
|
||||||
* @createTime 17:14 2022/6/9 |
|
||||||
**/ |
|
||||||
@Controller |
|
||||||
@RequestMapping(value = "/order") |
|
||||||
@Api(value = "订单") |
|
||||||
public class HighOrderController { |
|
||||||
|
|
||||||
private static Logger log = LoggerFactory.getLogger(HighOrderController.class); |
|
||||||
|
|
||||||
@Resource |
|
||||||
private ApiMerchantsService apiMerchantsService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private SecConfigService secConfigService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private OutRechargeOrderService outRechargeOrderService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighOrderService highOrderService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private ApiIpAddressService apiIpAddressService; |
|
||||||
|
|
||||||
@RequestMapping(value = "/getCallOrderList", method = RequestMethod.POST) |
|
||||||
@ResponseBody |
|
||||||
@ApiOperation(value = "获取话费订单列表") |
|
||||||
public ResponseData getCallOrderList(@RequestBody JSONObject object , HttpServletRequest request ) { |
|
||||||
try { |
|
||||||
|
|
||||||
String ip = ""; |
|
||||||
// 有的user可能使用代理,为处理用户使用代理的情况,使用x-forwarded-for
|
|
||||||
if (request.getHeader("x-forwarded-for") == null) { |
|
||||||
ip = request.getRemoteAddr(); |
|
||||||
} else { |
|
||||||
ip = request.getHeader("x-forwarded-for"); |
|
||||||
} |
|
||||||
|
|
||||||
if (!apiIpAddressService.validationIpAddressLegal(object.getString("merchId") , ip)) { |
|
||||||
log.error("getRechargeProduct error!", "非法ip地址,请联系管理人员!"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.IP_ERROR, "非法ip地址,请联系管理人员!"); |
|
||||||
} |
|
||||||
|
|
||||||
if (StringUtils.isBlank(object.getString("apiKey")) || |
|
||||||
StringUtils.isBlank(object.getString("merchId")) || |
|
||||||
StringUtils.isBlank(object.getString("createTimeS")) || |
|
||||||
StringUtils.isBlank(object.getString("createTimeE")) || |
|
||||||
StringUtils.isBlank(object.getString("merchId")) || |
|
||||||
StringUtils.isBlank(object.getString("timetable")) || |
|
||||||
StringUtils.isBlank(object.getString("sign")) |
|
||||||
) { |
|
||||||
log.error("getRechargeProduct error!", "请求参数校验失败!"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); |
|
||||||
} |
|
||||||
|
|
||||||
ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); |
|
||||||
|
|
||||||
if (apiMerchants == null) { |
|
||||||
log.error("getRechargeProduct error!", "商户号错误!"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); |
|
||||||
} |
|
||||||
|
|
||||||
Map<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("createTimeS" , object.getString("createTimeS")); |
|
||||||
map.put("createTimeE" , object.getString("createTimeE")); |
|
||||||
|
|
||||||
if (!secConfigService.isSignVerify(map , object.getString("sign"))) { |
|
||||||
log.error("getRechargeProduct error!", "签名校验失败!"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); |
|
||||||
} |
|
||||||
|
|
||||||
if (!ToolConfig.timetableCheck(15L , object.getLong("timetable"))) { |
|
||||||
log.error("getRechargeProduct error!", "请求时间超过15分钟!"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.TIME_OUT); |
|
||||||
} |
|
||||||
|
|
||||||
Map<String, Object> postMap = new HashMap<>(); |
|
||||||
postMap.put("merchId" , object.getString("merchId")); |
|
||||||
postMap.put("createTimeS", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(object.getLong("createTimeS"))); |
|
||||||
postMap.put("createTimeE", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(object.getLong("createTimeE"))); |
|
||||||
|
|
||||||
return ResponseMsgUtil.success(outRechargeOrderService.getListRechargeOrder(postMap)); |
|
||||||
|
|
||||||
} catch (Exception e) { |
|
||||||
log.error("HighOpenApiController --> getRechargeProduct() error!", e); |
|
||||||
return ResponseMsgUtil.exception(e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@RequestMapping(value = "/getOrderList", method = RequestMethod.POST) |
|
||||||
@ResponseBody |
|
||||||
@ApiOperation(value = "获取订单列表") |
|
||||||
public ResponseData getOrderList(@RequestBody JSONObject object , HttpServletRequest request ) { |
|
||||||
try { |
|
||||||
|
|
||||||
String ip = ""; |
|
||||||
// 有的user可能使用代理,为处理用户使用代理的情况,使用x-forwarded-for
|
|
||||||
if (request.getHeader("x-forwarded-for") == null) { |
|
||||||
ip = request.getRemoteAddr(); |
|
||||||
} else { |
|
||||||
ip = request.getHeader("x-forwarded-for"); |
|
||||||
} |
|
||||||
|
|
||||||
if (!apiIpAddressService.validationIpAddressLegal(object.getString("merchId") , ip)) { |
|
||||||
log.error("getRechargeProduct error!", "非法ip地址,请联系管理人员!"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.IP_ERROR, "非法ip地址,请联系管理人员!"); |
|
||||||
} |
|
||||||
|
|
||||||
if (StringUtils.isBlank(object.getString("apiKey")) || |
|
||||||
StringUtils.isBlank(object.getString("merchId")) || |
|
||||||
StringUtils.isBlank(object.getString("createTimeS")) || |
|
||||||
StringUtils.isBlank(object.getString("createTimeE")) || |
|
||||||
StringUtils.isBlank(object.getString("timetable")) || |
|
||||||
StringUtils.isBlank(object.getString("sign")) |
|
||||||
) { |
|
||||||
log.error("getRechargeProduct error!", "请求参数校验失败!"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); |
|
||||||
} |
|
||||||
|
|
||||||
ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); |
|
||||||
|
|
||||||
if (apiMerchants == null) { |
|
||||||
log.error("getRechargeProduct error!", "商户号错误!"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); |
|
||||||
} |
|
||||||
|
|
||||||
Map<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("createTimeS" , object.getString("createTimeS")); |
|
||||||
map.put("createTimeE" , object.getString("createTimeE")); |
|
||||||
|
|
||||||
if (!secConfigService.isSignVerify(map , object.getString("sign"))) { |
|
||||||
log.error("getRechargeProduct error!", "签名校验失败!"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); |
|
||||||
} |
|
||||||
|
|
||||||
if (!ToolConfig.timetableCheck(15L , object.getLong("timetable"))) { |
|
||||||
log.error("getRechargeProduct error!", "请求时间超过15分钟!"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.TIME_OUT); |
|
||||||
} |
|
||||||
|
|
||||||
Map<String, Object> postMap = new HashMap<>(); |
|
||||||
postMap.put("merchId" , object.getString("merchId")); |
|
||||||
postMap.put("createTimeS", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(object.getLong("createTimeS"))); |
|
||||||
postMap.put("createTimeE", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(object.getLong("createTimeE"))); |
|
||||||
|
|
||||||
|
|
||||||
return ResponseMsgUtil.success(highOrderService.getOrderList(postMap)); |
|
||||||
|
|
||||||
} catch (Exception e) { |
|
||||||
log.error("HighOpenApiController --> getRechargeProduct() error!", e); |
|
||||||
return ResponseMsgUtil.exception(e); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,253 @@ |
|||||||
|
package com.v1.controller; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
import com.hai.common.exception.ErrorCode; |
||||||
|
import com.hai.common.exception.ErrorHelp; |
||||||
|
import com.hai.common.exception.SysCode; |
||||||
|
import com.hai.common.utils.ResponseMsgUtil; |
||||||
|
import com.hai.entity.ApiMerchants; |
||||||
|
import com.hai.entity.ApiOrder; |
||||||
|
import com.hai.entity.ApiProductConfig; |
||||||
|
import com.hai.model.ResponseData; |
||||||
|
import com.hai.openApi.service.ApiOrderService; |
||||||
|
import com.hai.order.type.OrderProductType; |
||||||
|
import com.hai.service.*; |
||||||
|
import com.v1.config.ToolConfig; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import org.apache.commons.lang3.StringUtils; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
import org.springframework.stereotype.Controller; |
||||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestMethod; |
||||||
|
import org.springframework.web.bind.annotation.ResponseBody; |
||||||
|
|
||||||
|
import javax.annotation.Resource; |
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
@Controller |
||||||
|
@RequestMapping(value = "/order") |
||||||
|
@Api(value = "订单业务") |
||||||
|
public class orderController { |
||||||
|
|
||||||
|
private static Logger log = LoggerFactory.getLogger(RechargeProductController.class); |
||||||
|
|
||||||
|
@Resource |
||||||
|
private ApiMerchantsService apiMerchantsService; |
||||||
|
|
||||||
|
@Resource |
||||||
|
private SecConfigService secConfigService; |
||||||
|
|
||||||
|
@Resource |
||||||
|
private ApiOrderService orderService; |
||||||
|
|
||||||
|
@Resource |
||||||
|
private ApiIpAddressService apiIpAddressService; |
||||||
|
|
||||||
|
@Resource |
||||||
|
private ApiOrderService apiOrderService; |
||||||
|
|
||||||
|
@RequestMapping(value = "/createOrder", method = RequestMethod.POST) |
||||||
|
@ResponseBody |
||||||
|
@ApiOperation(value = "充值预下单") |
||||||
|
public ResponseData createOrder(@RequestBody JSONObject object , HttpServletRequest request ) { |
||||||
|
try { |
||||||
|
|
||||||
|
String ip = ""; |
||||||
|
// 有的user可能使用代理,为处理用户使用代理的情况,使用x-forwarded-for
|
||||||
|
if (request.getHeader("x-forwarded-for") == null) { |
||||||
|
ip = request.getRemoteAddr(); |
||||||
|
} else { |
||||||
|
ip = request.getHeader("x-forwarded-for"); |
||||||
|
} |
||||||
|
|
||||||
|
if (!apiIpAddressService.validationIpAddressLegal(object.getString("merchId") , ip)) { |
||||||
|
log.error("getRechargeProduct error!", "非法ip地址,请联系管理人员!"); |
||||||
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.IP_ERROR, "非法ip地址,请联系管理人员!"); |
||||||
|
} |
||||||
|
|
||||||
|
if ( |
||||||
|
StringUtils.isBlank(object.getString("apiKey")) || |
||||||
|
StringUtils.isBlank(object.getString("productType")) || |
||||||
|
StringUtils.isBlank(object.getString("timetable")) || |
||||||
|
StringUtils.isBlank(object.getString("orderNo")) || |
||||||
|
StringUtils.isBlank(object.getString("sign")) || |
||||||
|
StringUtils.isBlank(object.getString("content")) || |
||||||
|
StringUtils.isBlank(object.getString("merchId")) |
||||||
|
) { |
||||||
|
log.error("createOrder error!", "请求参数校验失败!"); |
||||||
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); |
||||||
|
} |
||||||
|
|
||||||
|
ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); |
||||||
|
|
||||||
|
if (apiMerchants == null) { |
||||||
|
log.error("getRechargeProduct error!", "帐户错误!"); |
||||||
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); |
||||||
|
} |
||||||
|
|
||||||
|
if (!secConfigService.isConfig(OrderProductType.getDataByType(object.getInteger("productType")).getApiCode(), object.getString("merchId"))) { |
||||||
|
log.error("getAllCities error!", "当前帐户无权限查询!"); |
||||||
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED); |
||||||
|
} |
||||||
|
|
||||||
|
Map<String , Object> map = new HashMap<>(); |
||||||
|
map.put("timetable" , object.getString("timetable")); |
||||||
|
map.put("orderNo" , object.getString("orderNo")); |
||||||
|
map.put("productType" , object.getString("productType")); |
||||||
|
map.put("apiKey" , object.getString("apiKey")); |
||||||
|
map.put("content" , object.getString("content")); |
||||||
|
map.put("merchId" , object.getString("merchId")); |
||||||
|
|
||||||
|
if (!secConfigService.isSignVerify(map, object.getString("sign"))) { |
||||||
|
log.error("createOrder error!", "签名校验失败!"); |
||||||
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); |
||||||
|
} |
||||||
|
|
||||||
|
if (!ToolConfig.timetableCheck(15L , object.getLong("timetable"))) { |
||||||
|
log.error("getRechargeProduct error!", "请求时间超过15分钟!"); |
||||||
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.TIME_OUT); |
||||||
|
} |
||||||
|
|
||||||
|
if (object.getInteger("productType").equals(OrderProductType.PRODUCT_TYPE6.getNumber())) { |
||||||
|
JSONObject dataObject = JSONObject.parseObject(object.getString("content")); |
||||||
|
if (dataObject.getBigDecimal("refuelPrice") == null |
||||||
|
|| StringUtils.isBlank(dataObject.getString("gasOilNo")) |
||||||
|
|| StringUtils.isBlank(dataObject.getString("gasGunNo")) |
||||||
|
|| StringUtils.isBlank(dataObject.getString("storeCode")) |
||||||
|
) { |
||||||
|
log.error("OrderController -> create() error!",""); |
||||||
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未填写加油信息;加油金额、油号、抢号"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return ResponseMsgUtil.success(orderService.createOrder(object)); |
||||||
|
|
||||||
|
} catch (Exception e) { |
||||||
|
log.error("HighOpenApiController --> createOrder() error!", e); |
||||||
|
return ResponseMsgUtil.exception(e); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@RequestMapping(value = "/orderPay", method = RequestMethod.POST) |
||||||
|
@ResponseBody |
||||||
|
@ApiOperation(value = "订单支付") |
||||||
|
public ResponseData orderPay(@RequestBody JSONObject object , HttpServletRequest request) { |
||||||
|
try { |
||||||
|
|
||||||
|
String ip = ""; |
||||||
|
// 有的user可能使用代理,为处理用户使用代理的情况,使用x-forwarded-for
|
||||||
|
if (request.getHeader("x-forwarded-for") == null) { |
||||||
|
ip = request.getRemoteAddr(); |
||||||
|
} else { |
||||||
|
ip = request.getHeader("x-forwarded-for"); |
||||||
|
} |
||||||
|
|
||||||
|
if (!apiIpAddressService.validationIpAddressLegal(object.getString("merchId") , ip)) { |
||||||
|
log.error("getRechargeProduct error!", "非法ip地址,请联系管理人员!"); |
||||||
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.IP_ERROR, "非法ip地址,请联系管理人员!"); |
||||||
|
} |
||||||
|
|
||||||
|
if ( |
||||||
|
StringUtils.isBlank(object.getString("apiKey")) || |
||||||
|
StringUtils.isBlank(object.getString("mchOrderNo")) || |
||||||
|
StringUtils.isBlank(object.getString("sign")) || |
||||||
|
StringUtils.isBlank(object.getString("merchId")) |
||||||
|
) { |
||||||
|
log.error("createOrder error!", "请求参数校验失败!"); |
||||||
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); |
||||||
|
} |
||||||
|
|
||||||
|
ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); |
||||||
|
|
||||||
|
if (apiMerchants == null) { |
||||||
|
log.error("getRechargeProduct error!", "帐户错误!"); |
||||||
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); |
||||||
|
} |
||||||
|
|
||||||
|
Map<String , Object> map = new HashMap<>(); |
||||||
|
map.put("mchOrderNo" , object.getString("mchOrderNo")); |
||||||
|
map.put("apiKey" , object.getString("apiKey")); |
||||||
|
map.put("merchId" , object.getString("merchId")); |
||||||
|
|
||||||
|
if (!secConfigService.isSignVerify(map, object.getString("sign"))) { |
||||||
|
log.error("createOrder error!", "签名校验失败!"); |
||||||
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); |
||||||
|
} |
||||||
|
|
||||||
|
ApiOrder apiOrder = apiOrderService.findByOrderNo(object.getString("mchOrderNo") , null); |
||||||
|
|
||||||
|
if (apiOrder.getStatus() != 1) { |
||||||
|
log.error("createOrder error!", "订单状态错误!"); |
||||||
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR , "订单状态错误"); |
||||||
|
} |
||||||
|
|
||||||
|
object.put("orderNo" , apiOrder.getOrderNo()); |
||||||
|
|
||||||
|
return ResponseMsgUtil.success(orderService.payOrder(object)); |
||||||
|
|
||||||
|
} catch (Exception e) { |
||||||
|
log.error("HighOpenApiController --> createOrder() error!", e); |
||||||
|
return ResponseMsgUtil.exception(e); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@RequestMapping(value = "/queryOrderDetail", method = RequestMethod.POST) |
||||||
|
@ResponseBody |
||||||
|
@ApiOperation(value = "查询订单详情") |
||||||
|
public ResponseData queryOrderDetail(@RequestBody JSONObject object , HttpServletRequest request) { |
||||||
|
try { |
||||||
|
|
||||||
|
String ip = ""; |
||||||
|
// 有的user可能使用代理,为处理用户使用代理的情况,使用x-forwarded-for
|
||||||
|
if (request.getHeader("x-forwarded-for") == null) { |
||||||
|
ip = request.getRemoteAddr(); |
||||||
|
} else { |
||||||
|
ip = request.getHeader("x-forwarded-for"); |
||||||
|
} |
||||||
|
|
||||||
|
if (!apiIpAddressService.validationIpAddressLegal(object.getString("merchId") , ip)) { |
||||||
|
log.error("getRechargeProduct error!", "非法ip地址,请联系管理人员!"); |
||||||
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.IP_ERROR, "非法ip地址,请联系管理人员!"); |
||||||
|
} |
||||||
|
|
||||||
|
if ( |
||||||
|
StringUtils.isBlank(object.getString("apiKey")) || |
||||||
|
StringUtils.isBlank(object.getString("mchOrderNo")) || |
||||||
|
StringUtils.isBlank(object.getString("sign")) || |
||||||
|
StringUtils.isBlank(object.getString("merchId")) |
||||||
|
) { |
||||||
|
log.error("createOrder error!", "请求参数校验失败!"); |
||||||
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); |
||||||
|
} |
||||||
|
|
||||||
|
ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); |
||||||
|
|
||||||
|
if (apiMerchants == null) { |
||||||
|
log.error("getRechargeProduct error!", "帐户错误!"); |
||||||
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); |
||||||
|
} |
||||||
|
|
||||||
|
Map<String , Object> map = new HashMap<>(); |
||||||
|
map.put("mchOrderNo" , object.getString("mchOrderNo")); |
||||||
|
map.put("apiKey" , object.getString("apiKey")); |
||||||
|
map.put("merchId" , object.getString("merchId")); |
||||||
|
|
||||||
|
if (!secConfigService.isSignVerify(map, object.getString("sign"))) { |
||||||
|
log.error("createOrder error!", "签名校验失败!"); |
||||||
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); |
||||||
|
} |
||||||
|
|
||||||
|
return ResponseMsgUtil.success(apiOrderService.findByOrderNo(object.getString("mchOrderNo") , null)); |
||||||
|
|
||||||
|
} catch (Exception e) { |
||||||
|
log.error("HighOpenApiController --> createOrder() error!", e); |
||||||
|
return ResponseMsgUtil.exception(e); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue