dev-discount
胡锐 2 years ago
commit 8bd4c6366b
  1. 1
      hai-schedule/src/main/java/com/hai/schedule/HighOrderSchedule.java
  2. 1
      hai-service/src/main/java/com/hai/dao/HighOrderMapperExt.java
  3. 266
      v1/src/main/java/com/v1/controller/GzSinopecController.java

@ -451,6 +451,7 @@ public class HighOrderSchedule {
object.put("price" , highOrder.getPayRealPrice()); object.put("price" , highOrder.getPayRealPrice());
object.put("userId" , highOrder.getMemId()); object.put("userId" , highOrder.getMemId());
object.put("orderId" , highOrder.getId()); object.put("orderId" , highOrder.getId());
object.put("companyId" , highOrder.getCompanyId());
bsIntegralRebateService.integralRebate(object); bsIntegralRebateService.integralRebate(object);

@ -1274,6 +1274,7 @@ public interface HighOrderMapperExt {
@Result(column="refund_time", property="refundTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="refund_time", property="refundTime", jdbcType=JdbcType.TIMESTAMP),
@Result(column="refund_price", property="refundPrice", jdbcType=JdbcType.DECIMAL), @Result(column="refund_price", property="refundPrice", jdbcType=JdbcType.DECIMAL),
@Result(column="refund_content", property="refundContent", jdbcType=JdbcType.VARCHAR), @Result(column="refund_content", property="refundContent", jdbcType=JdbcType.VARCHAR),
@Result(column="company_id", property="companyId", jdbcType=JdbcType.BIGINT),
@Result(column="refusal_refund_content", property="refusalRefundContent", jdbcType=JdbcType.VARCHAR), @Result(column="refusal_refund_content", property="refusalRefundContent", jdbcType=JdbcType.VARCHAR),
@Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR), @Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR),
@Result(column="ext_2", property="ext2", jdbcType=JdbcType.VARCHAR), @Result(column="ext_2", property="ext2", jdbcType=JdbcType.VARCHAR),

@ -1,21 +1,27 @@
package com.v1.controller; package com.v1.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode; import com.hai.common.exception.SysCode;
import com.hai.common.utils.ResponseMsgUtil; import com.hai.common.utils.ResponseMsgUtil;
import com.hai.config.HuiLianTongConfig; import com.hai.config.HuiLianTongConfig;
import com.hai.config.HuiLianTongUnionCardConfig;
import com.hai.dao.HighGasOrderPushMapper; import com.hai.dao.HighGasOrderPushMapper;
import com.hai.entity.ApiMerchants;
import com.hai.entity.HighGasOrderPush; import com.hai.entity.HighGasOrderPush;
import com.hai.entity.HighUser; import com.hai.entity.HighUser;
import com.hai.enum_type.OrderPushType; import com.hai.enum_type.OrderPushType;
import com.hai.model.ResponseData; import com.hai.model.ResponseData;
import com.hai.service.ApiMerchantsService;
import com.hai.service.HighOpenApiService; import com.hai.service.HighOpenApiService;
import com.hai.service.HighUserService; import com.hai.service.HighUserService;
import com.hai.service.SecConfigService; import com.hai.service.SecConfigService;
import com.v1.config.ToolConfig;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
@ -41,49 +47,18 @@ public class GzSinopecController {
private HighUserService highUserService; private HighUserService highUserService;
@Resource @Resource
private HighGasOrderPushMapper highGasOrderPushMapper; private ApiMerchantsService apiMerchantsService;
@Resource @Resource
private SecConfigService secConfigService; private HighGasOrderPushMapper highGasOrderPushMapper;
@Resource @Resource
private HuiLianTongConfig huiLianTongConfig; private SecConfigService secConfigService;
@RequestMapping(value = "/getGuizhouSinopecList", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "获取专属优惠券")
public ResponseData getUserExclusiveDiscount(@RequestParam(name = "useScope", required = false) Integer useScope,
@RequestParam(name = "phone", required = true) String phone,
@RequestParam(name = "year", required = false) String year) {
try {
HighUser highUser = highUserService.findByPhone(phone);
if (highUser == null || highUser.getStatus() == 0) {
log.error("getUserOrderPreList error!", "未找到用户");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "当前手机号暂无用户");
}
Map<String, Object> map = new HashMap<>();
map.put("userId", highUser.getId());
map.put("useScope", useScope);
if (year != null) {
map.put("createTimeS", year + "-01-01 00:00:00");
map.put("createTimeE", year + "-12-31 23:59:59");
}
return ResponseMsgUtil.success(highOpenApiService.getUserCouponsList(map));
} catch (Exception e) {
log.error("HighOpenApiController --> getGuizhouSinopecList() error!", e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value = "/getGuizhouSinopecList", method = RequestMethod.POST) @RequestMapping(value = "/getGzSinopecList", method = RequestMethod.POST)
@ResponseBody @ResponseBody
@ApiOperation(value = "获取贵州中石化电子卡券") @ApiOperation(value = "获取贵州中石化电子卡券")
public ResponseData getGuizhouSinopecList(HttpServletRequest request) { public ResponseData getGzSinopecList(@RequestBody JSONObject object , HttpServletRequest request) {
try { try {
String ip = ""; String ip = "";
@ -99,60 +74,59 @@ public class GzSinopecController {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "非法ip地址,请联系管理人员!"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "非法ip地址,请联系管理人员!");
} }
// 获取token
String token = huiLianTongConfig.getToken();
// 查询电子卡券类型 if (StringUtils.isBlank(object.getString("apiKey")) ||
JSONObject corpCouTypes = HuiLianTongConfig.getCorpCouTypes(token); StringUtils.isBlank(object.getString("timetable")) ||
System.out.println(corpCouTypes.toJSONString()); StringUtils.isBlank(object.getString("merchId")) ||
if (!corpCouTypes.getString("result").equals("success")) { StringUtils.isBlank(object.getString("sign"))
log.error("HighOpenApiController -> getGuizhouSinopecList() error!", "获取电子卡券列表失败"); ) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "获取电子卡券列表失败"); log.error("getRechargeProduct error!", "请求参数校验失败!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR);
} }
return ResponseMsgUtil.success(corpCouTypes.getJSONArray("data")); Map<String , Object> map = new HashMap<>();
} catch (Exception e) { map.put("timetable" , object.getString("timetable"));
log.error("HighCouponController -> getGuizhouSinopec() error!", e); map.put("apiKey" , object.getString("apiKey"));
return ResponseMsgUtil.exception(e); 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);
} }
@RequestMapping(value = "/checkCouponStatus", method = RequestMethod.POST) ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId"));
@ResponseBody
@ApiOperation(value = "查询电子券状态")
public ResponseData checkCouponStatus(@RequestBody JSONObject object, HttpServletRequest request) {
try {
String ip = ""; if (apiMerchants == null) {
// 有的user可能使用代理,为处理用户使用代理的情况,使用x-forwarded-for log.error("getRechargeProduct error!", "错误商户,请联系管理人员!");
if (request.getHeader("x-forwarded-for") == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST);
ip = request.getRemoteAddr();
} else {
ip = request.getHeader("x-forwarded-for");
} }
if (!secConfigService.isConfig("GZ_SINOPEC_CONFIG" , object.getString("merchId"))) {
if (!secConfigService.isConfig("IP_WHITE", ip)) { log.error("getAllCities error!", "当前帐户无权限!");
log.error("getGuizhouSinopec error!", "非法ip地址,请联系管理人员!"); throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "当前帐户无权限!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "非法ip地址,请联系管理人员!");
} }
// 获取token if (!ToolConfig.timetableCheck(15L , object.getLong("timetable"))) {
String token = huiLianTongConfig.getToken(); log.error("getRechargeProduct error!", "请求时间超过15分钟!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY);
}
// 查询电子卡券类型 // 查询电子卡券类型
JSONObject data = HuiLianTongConfig.getCouState(token, object.getString("couNo")); JSONObject corpCouTypes = HuiLianTongConfig.getHltFuelCoupList();
if (!data.getString("result").equals("success")) { if (!corpCouTypes.getString("respCode").equals("0000")) {
log.error("HighOpenApiController -> insertCoupon() error!", "查询电子券状态失败"); log.error("HighCouponController -> insertCoupon() error!","获取电子卡券列表失败");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "查询电子券状态失败"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "获取电子卡券列表失败");
} }
// 参数解密
JSONObject resolveResponseData = HuiLianTongUnionCardConfig.resolveResponse(corpCouTypes.getString("data"));
return ResponseMsgUtil.success(data.getJSONObject("data")); return ResponseMsgUtil.success(resolveResponseData);
} catch (Exception e) { } catch (Exception e) {
log.error("HighCouponController -> getGuizhouSinopec() error!", e); log.error("HighCouponController -> getGuizhouSinopec() error!", e);
return ResponseMsgUtil.exception(e); return ResponseMsgUtil.exception(e);
} }
} }
@RequestMapping(value = "/couJointDist", method = RequestMethod.POST) @RequestMapping(value = "/couJointDist", method = RequestMethod.POST)
@ResponseBody @ResponseBody
@ApiOperation(value = "商户派发电子券") @ApiOperation(value = "商户派发电子券")
@ -172,51 +146,165 @@ public class GzSinopecController {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "非法ip地址,请联系管理人员!"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "非法ip地址,请联系管理人员!");
} }
// 获取token if (StringUtils.isBlank(object.getString("apiKey")) ||
String token = huiLianTongConfig.getToken(); StringUtils.isBlank(object.getString("orderNo")) ||
StringUtils.isBlank(object.getString("count")) ||
StringUtils.isBlank(object.getString("couTypeCode")) ||
StringUtils.isBlank(object.getString("phone")) ||
StringUtils.isBlank(object.getString("timetable")) ||
StringUtils.isBlank(object.getString("merchId")) ||
StringUtils.isBlank(object.getString("sign"))
) {
log.error("getRechargeProduct error!", "请求参数校验失败!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR);
}
Map<String , Object> map = new HashMap<>();
map.put("timetable" , object.getString("timetable"));
map.put("apiKey" , object.getString("apiKey"));
map.put("orderNo" , object.getString("orderNo"));
map.put("count" , object.getString("count"));
map.put("couTypeCode" , object.getString("couTypeCode"));
map.put("phone" , object.getString("phone"));
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);
}
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("GZ_SINOPEC_CONFIG" , object.getString("merchId"))) {
log.error("getAllCities error!", "当前帐户无权限!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "当前帐户无权限!");
}
if (!ToolConfig.timetableCheck(15L , object.getLong("timetable"))) {
log.error("getRechargeProduct error!", "请求时间超过15分钟!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY);
}
if (object.getInteger("count") > 5) {
log.error("getRechargeProduct error!", "下单数量限制5张!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR , "下单数量限制5张!");
}
// 下单请求
JSONObject rechargeObject = HuiLianTongConfig.recharge(object.getString("orderNo"),
object.getInteger("count"),
object.getString("couTypeCode"),
object.getString("phone"));
if (!rechargeObject.getString("respCode").equals("0000")) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "下单失败");
}
JSONObject response = HuiLianTongUnionCardConfig.resolveResponse(rechargeObject.getString("data"));
// 购买卡券
JSONObject returnParam = HuiLianTongConfig.costRechargeOrder(response.getJSONObject("data").getString("rechargeOrderId"));
if (returnParam != null && returnParam.getString("respCode").equals("0000")) {
// 解密
JSONObject jsonObject = HuiLianTongUnionCardConfig.resolveResponse(returnParam.getString("data"));
JSONArray dataArray = JSONObject.parseObject(jsonObject.getString("data"), JSONArray.class);
// 商户派发电子券
JSONObject returnParam = HuiLianTongConfig.couJointDist(token, object.getString("orderNo"), object.getString("couTypeCode"), object.getInteger("distCouCount"), object.getString("phone"), object.getString("thirdUserId"));
// 推送记录 // 推送记录
HighGasOrderPush highGasOrderPush = new HighGasOrderPush(); HighGasOrderPush highGasOrderPush = new HighGasOrderPush();
highGasOrderPush.setType(OrderPushType.type6.getType()); highGasOrderPush.setType(OrderPushType.type6.getType());
highGasOrderPush.setOrderNo(object.getString("orderNo")); highGasOrderPush.setOrderNo(object.getString("orderNo"));
highGasOrderPush.setCreateTime(new Date()); highGasOrderPush.setCreateTime(new Date());
highGasOrderPush.setCode(returnParam.getString("result")); highGasOrderPush.setCode(returnParam.getString("respCode"));
highGasOrderPush.setRequestContent(JSONObject.toJSONString(object)); highGasOrderPush.setRequestContent(object.toJSONString());
highGasOrderPush.setReturnContent(returnParam.toJSONString()); highGasOrderPush.setReturnContent(dataArray.toJSONString());
highGasOrderPushMapper.insert(highGasOrderPush); highGasOrderPushMapper.insert(highGasOrderPush);
if (!returnParam.getString("result").equals("success")) {
log.error("HighOpenApiController -> couJointDist() error!", "商户派发电子券失败"); return ResponseMsgUtil.success(dataArray);
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "商户派发电子券失败"); } else {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "下单失败");
} }
return ResponseMsgUtil.success(returnParam.getJSONArray("data"));
} catch (Exception e) { } catch (Exception e) {
log.error("HighOpenApiController -> couJointDist() error!", e); log.error("HighOpenApiController -> couJointDist() error!", e);
return ResponseMsgUtil.exception(e); return ResponseMsgUtil.exception(e);
} }
} }
@RequestMapping(value = "/getPayOrderByCouNo", method = RequestMethod.POST)
@RequestMapping(value = "/test", method = RequestMethod.POST)
@ResponseBody @ResponseBody
@ApiOperation(value = "测试") @ApiOperation(value = "查询核销状态")
public ResponseData test(HttpServletRequest request) { public ResponseData getPayOrderByCouNo(@RequestBody JSONObject object , HttpServletRequest request) {
try { try {
String ip = ""; String ip = "";
// 有的user可能使用代理,为处理用户使用代理的情况,使用x-forwarded-for
if (request.getHeader("x-forwarded-for") == null) { if (request.getHeader("x-forwarded-for") == null) {
ip = request.getRemoteAddr(); ip = request.getRemoteAddr();
} } else {
ip = request.getHeader("x-forwarded-for"); ip = request.getHeader("x-forwarded-for");
}
if (!secConfigService.isConfig("IP_WHITE", ip)) {
log.error("getGuizhouSinopec error!", "非法ip地址,请联系管理人员!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "非法ip地址,请联系管理人员!");
}
if (StringUtils.isBlank(object.getString("apiKey")) ||
StringUtils.isBlank(object.getString("timetable")) ||
StringUtils.isBlank(object.getString("merchId")) ||
StringUtils.isBlank(object.getString("couNo")) ||
StringUtils.isBlank(object.getString("sign"))
) {
log.error("getRechargeProduct error!", "请求参数校验失败!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR);
}
Map<String , Object> map = new HashMap<>();
map.put("timetable" , object.getString("timetable"));
map.put("apiKey" , object.getString("apiKey"));
map.put("couNo" , object.getString("couNo"));
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);
}
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("GZ_SINOPEC_CONFIG" , object.getString("merchId"))) {
log.error("getAllCities error!", "当前帐户无权限!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "当前帐户无权限!");
}
if (!ToolConfig.timetableCheck(15L , object.getLong("timetable"))) {
log.error("getRechargeProduct error!", "请求时间超过15分钟!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY);
}
JSONObject jsonObject = HuiLianTongConfig.getPayOrderByCouNo(object.getString("couNo"));
if (jsonObject.getString("respCode").equals("0000")) {
JSONObject data = HuiLianTongUnionCardConfig.resolveResponse(jsonObject.getString("data"));
return ResponseMsgUtil.success(data);
} else {
log.error("getRechargeProduct error!", "查询失败!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR , "查询失败");
}
return ResponseMsgUtil.success(ip);
} catch (Exception e) { } catch (Exception e) {
log.error("HighCouponController -> getGuizhouSinopec() error!", e); log.error("HighCouponController -> getGuizhouSinopec() error!", e);
return ResponseMsgUtil.exception(e); return ResponseMsgUtil.exception(e);
} }
} }
} }

Loading…
Cancel
Save