对外提供查询优惠券包详情、用户优惠券接口

master
胡锐 1 month ago
parent ef533b3286
commit dd11156f0c
  1. 1
      cweb/src/main/java/com/cweb/config/AuthConfig.java
  2. 58
      cweb/src/main/java/com/cweb/controller/PhgController.java
  3. 164
      openapi/src/main/java/com/openapi/controller/BsDiscountController.java
  4. 10
      service/src/main/java/com/hfkj/config/CommonSysConfig.java
  5. 1
      service/src/main/java/com/hfkj/dao/BsDiscountUserMapperExt.java
  6. 55
      service/src/main/java/com/hfkj/openapi/model/UserDiscountModel.java
  7. 39
      service/src/main/java/com/hfkj/openapi/model/request/RequestQueryListByPhoneModel.java
  8. 40
      service/src/main/java/com/hfkj/openapi/model/request/RequestQueryPkDiscountModel.java
  9. 54
      service/src/main/java/com/hfkj/openapi/model/response/ResponseQueryPkDiscountModel.java
  10. 31
      service/src/main/java/com/hfkj/openapi/model/response/ResponseUserDiscountModel.java
  11. 3
      service/src/main/resources/dev/commonConfig.properties

@ -98,6 +98,7 @@ public class AuthConfig implements WebMvcConfigurer {
.excludePathPatterns("/user/*")
.excludePathPatterns("/notify/*")
.excludePathPatterns("/cms/*")
.excludePathPatterns("/phg/*")
;
}

@ -0,0 +1,58 @@
package com.cweb.controller;
import com.alibaba.fastjson.JSONObject;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.pay.util.SignatureUtil;
import com.hfkj.common.security.UserCenter;
import com.hfkj.common.utils.RedisUtil;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.config.CommonSysConst;
import com.hfkj.entity.CmsContent;
import com.hfkj.model.ResponseData;
import com.hfkj.model.UserSessionObject;
import com.hfkj.service.cms.CmsContentReadService;
import com.hfkj.service.cms.CmsContentService;
import com.hfkj.service.cms.impl.CmsContentServiceImpl;
import com.hfkj.sysenum.cms.CmsStatusEnum;
import com.hfkj.sysenum.cms.CmsTypeEnum;
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.*;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
@RequestMapping(value = "/phg")
@Api(value = "普惠go业务")
public class PhgController {
private static Logger log = LoggerFactory.getLogger(PhgController.class);
@RequestMapping(value="/login",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "普惠GO登录参数")
public ResponseData login(@RequestBody JSONObject body) {
try {
if (body == null || StringUtils.isBlank(body.getString("phone"))) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
Map<String,Object> param = new HashMap<>();
param.put("appid", CommonSysConst.getSysConfig().getPhgAppid());
param.put("phone", body.getString("phone"));
param.put("sign", SignatureUtil.createSign(param, CommonSysConst.getSysConfig().getPhgAppSecret()));
return ResponseMsgUtil.success(param);
} catch (Exception e) {
return ResponseMsgUtil.exception(e);
}
}
}

@ -9,19 +9,19 @@ import com.hfkj.common.pay.util.SignatureUtil;
import com.hfkj.common.utils.DateUtil;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.entity.*;
import com.hfkj.model.DiscountUserModel;
import com.hfkj.model.ResponseData;
import com.hfkj.openapi.model.request.RequestPushDiscountModel;
import com.hfkj.openapi.model.request.RequestPushPkDiscountModel;
import com.hfkj.openapi.model.request.RequestQueryCodeModel;
import com.hfkj.openapi.model.request.RequestQueryDiscountListModel;
import com.hfkj.openapi.model.response.ResponsePushDiscountModel;
import com.hfkj.openapi.model.response.ResponsePushDiscountPkModel;
import com.hfkj.openapi.model.response.ResponseQueryCodeModel;
import com.hfkj.openapi.model.UserDiscountModel;
import com.hfkj.openapi.model.request.*;
import com.hfkj.openapi.model.response.*;
import com.hfkj.service.agent.BsAgentApiLogService;
import com.hfkj.service.agent.BsAgentApiParamService;
import com.hfkj.service.agent.BsAgentDiscountService;
import com.hfkj.service.discount.BsDiscountPkRelService;
import com.hfkj.service.discount.BsDiscountPkService;
import com.hfkj.service.discount.BsDiscountService;
import com.hfkj.service.discount.BsDiscountUserService;
import com.hfkj.sysenum.discount.DiscountPkStatusEnum;
import com.hfkj.sysenum.discount.DiscountStockCodeObtainTypeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -32,10 +32,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
@Controller
@RequestMapping(value = "/discount")
@ -47,6 +44,10 @@ public class BsDiscountController {
@Resource
private BsAgentDiscountService agentDiscountService;
@Resource
private BsDiscountPkService discountPkService;
@Resource
private BsDiscountPkRelService discountPkRelService;
@Resource
private BsAgentApiLogService agentApiLogService;
@Resource
private BsDiscountUserService discountUserService;
@ -121,6 +122,82 @@ public class BsDiscountController {
}
}
@RequestMapping(value="/queryPkDetail",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "查询优惠券包详情")
public ResponseData queryPkDetail(@Validated @RequestBody RequestQueryPkDiscountModel body) {
log.info("========= Start 查询优惠券详情 Start ===========");
log.info("请求参数:" + JSONObject.toJSONString(body));
BsAgentApiLogWithBLOBs apiLog = new BsAgentApiLogWithBLOBs();
try {
// 验证签名
BsAgentApiParam apiParam = agentApiParamService.getParamByAppId(body.getAppId());
if (!SignatureUtil.checkSign(body.getSign(), body, apiParam.getAppSecret())) {
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_SIGN_ERR, "");
}
// 验证请求id
if (agentApiLogService.isExist(body.getAppId(), body.getReqId())) {
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_REQ_ID_ERR, "");
}
apiLog.setAppId(body.getAppId());
apiLog.setRequestId(body.getReqId());
apiLog.setRequestUrl("discount/queryPkDetail");
apiLog.setRequestParam(JSONObject.toJSONString(body));
// 查询代理商是否拥有优惠券包权限
if (agentDiscountService.getDetail(apiParam.getAgentId(),2,body.getDiscountPkNo()) == null) {
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未配置优惠券包");
}
// 查询优惠券包
BsDiscountPk discountPk = discountPkService.getDetail(body.getDiscountPkNo());
if (discountPk == null) {
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未找到优惠券包");
}
if (!discountPk.getStatus().equals(DiscountPkStatusEnum.status2.getCode())) {
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未找到优惠券包");
}
ResponseQueryPkDiscountModel response = new ResponseQueryPkDiscountModel();
response.setAppId(body.getAppId());
response.setReqId(body.getReqId());
response.setDiscountPkNo(discountPk.getDiscountPkNo());
response.setDiscountPkName(discountPk.getDiscountPkName());
response.setDiscountList(new LinkedList<>());
// 券包中的优惠券列表
List<BsDiscountPkRel> discountPkRelList = discountPkRelService.getList(body.getDiscountPkNo());
for (BsDiscountPkRel discount : discountPkRelList) {
JSONObject discountObj = new JSONObject();
discountObj.put("number", discount.getNumber());
discountObj.put("discountNo", discount.getDiscountNo());
discountObj.put("discountName", discount.getDiscountName());
discountObj.put("discountType", discount.getDiscountType());
discountObj.put("discountCondition", discount.getDiscountCondition());
discountObj.put("discountPrice", discount.getDiscountPrice());
discountObj.put("useScope", discount.getUseScope());
discountObj.put("receiveExpirationDate", discount.getReceiveExpirationDate());
response.getDiscountList().add(discountObj);
}
response.setSign(SignatureUtil.createSign(response, agentApiParamService.getParamByAppId(body.getAppId()).getAppSecret()));
log.info("返回参数:" + JSONObject.toJSONString(response));
apiLog.setResponseParam(JSONObject.toJSONString(response));
return ResponseMsgUtil.success(response);
} catch (Exception e) {
log.info("出现异常:", e);
// 异常内容
ResponseData exception = ResponseMsgUtil.exception(e);
apiLog.setErrorContent(JSONObject.toJSONString(exception));
return exception;
} finally {
// 记录日志
if (apiLog.getAppId() != null) {
agentApiLogService.edit(apiLog);
}
log.info("========= END 查询优惠券详情 END ===========");
}
}
@RequestMapping(value="/pushPk",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "推送优惠券包")
@ -250,5 +327,70 @@ public class BsDiscountController {
}
}
@RequestMapping(value="/queryListByPhone",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "根据手机号查询优惠券列表")
public ResponseData queryListByPhone(@Validated @RequestBody RequestQueryListByPhoneModel body) {
log.info("========= Start 根据手机号查询优惠券列表 Start ===========");
log.info("请求参数:" + JSONObject.toJSONString(body));
BsAgentApiLogWithBLOBs apiLog = new BsAgentApiLogWithBLOBs();
try {
// 验证签名
BsAgentApiParam apiParam = agentApiParamService.getParamByAppId(body.getAppId());
if (!SignatureUtil.checkSign(body.getSign(), body, apiParam.getAppSecret())) {
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_SIGN_ERR, "");
}
// 验证请求id
if (agentApiLogService.isExist(body.getAppId(), body.getReqId())) {
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_REQ_ID_ERR, "");
}
apiLog.setAppId(body.getAppId());
apiLog.setRequestId(body.getReqId());
apiLog.setRequestUrl("discount/queryListByPhone");
apiLog.setRequestParam(JSONObject.toJSONString(body));
Map<String,Object> param = new HashMap<>();
param.put("userPhone", body.getPhone());
param.put("status", body.getStatus());
List<DiscountUserModel> userDiscountList = discountUserService.getUserDiscountList(param);
ResponseUserDiscountModel response = new ResponseUserDiscountModel();
response.setReqId(body.getReqId());
response.setUserPhone(body.getPhone());
response.setDataList(new LinkedList<>());
for (DiscountUserModel model : userDiscountList) {
UserDiscountModel userDiscount = new UserDiscountModel();
userDiscount.setDiscountNo(model.getDiscountNo());
userDiscount.setDiscountName(model.getDiscountName());
userDiscount.setDiscountType(model.getDiscountType());
userDiscount.setDiscountCondition(model.getDiscountCondition());
userDiscount.setDiscountPrice(model.getDiscountPrice());
userDiscount.setCode(model.getDiscountStockCode());
userDiscount.setCreateTime(model.getCreateTime());
userDiscount.setUseTime(model.getUseDate());
userDiscount.setExpirationTime(model.getExpirationDate());
userDiscount.setStatus(model.getStatus());
response.getDataList().add(userDiscount);
}
response.setSign(SignatureUtil.createSign(response, agentApiParamService.getParamByAppId(body.getAppId()).getAppSecret()));
log.info("返回参数:" + JSONObject.toJSONString(response));
apiLog.setResponseParam(JSONObject.toJSONString(response));
return ResponseMsgUtil.success(response);
} catch (Exception e) {
log.info("出现异常:", e);
// 异常内容
ResponseData exception = ResponseMsgUtil.exception(e);
apiLog.setErrorContent(JSONObject.toJSONString(exception));
return exception;
} finally {
// 记录日志
if (apiLog.getAppId() != null) {
agentApiLogService.edit(apiLog);
}
log.info("========= END 根据手机号查询优惠券列表 END ===========");
}
}
}

@ -72,6 +72,16 @@ public class CommonSysConfig {
*/
private String huiPayPreorderNotifyUrl;
/**
* 普惠GOappid
*/
private String phgAppid;
/**
* 普惠GOappSecret
*/
private String phgAppSecret;
/**
* 嗨加油域名
*/

@ -34,6 +34,7 @@ public interface BsDiscountUserMapperExt {
" from bs_discount_user " +
" where 1 = 1" +
" <if test='param.userId != null'> and user_id = #{param.userId} </if>" +
" <if test='param.userPhone != null'> and user_phone = #{param.userPhone} </if>" +
" <if test='param.useScope != null'> and FIND_IN_SET(#{param.useScope} ,use_scope) </if>" +
" <if test='param.status != null'> and `status` = #{param.status} </if>" +
" <if test='param.useMerNo != null'> and discount_id in (select discount_id from bs_discount_use_mer where mer_no = #{param.useMerNo} GROUP BY discount_id) </if>" +

@ -0,0 +1,55 @@
package com.hfkj.openapi.model;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
/**
* @className: RequestQueryDiscountListModel
* @author: HuRui
* @date: 2024/9/1
**/
@Data
public class UserDiscountModel {
/**
* 优惠券编号
*/
private String discountNo;
/**
* 优惠券名称
*/
private String discountName;
/**
* 优惠券类型
*/
private Integer discountType;
/**
* 满减金额
*/
private BigDecimal discountCondition;
/**
* 优惠券金额
*/
private BigDecimal discountPrice;
/**
* 领取优惠券code
*/
private Long code;
/**
* 领取时间
*/
private Date createTime;
/**
* 使用时间
*/
private Date useTime;
/**
* 过期时间
*/
private Date expirationTime;
/**
* 状态
*/
private Integer status;
}

@ -0,0 +1,39 @@
package com.hfkj.openapi.model.request;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
@Data
public class RequestQueryListByPhoneModel {
/**
* appid
*/
@NotBlank(message = "请求id必填项")
private String reqId;
/**
* appid
*/
@NotBlank(message = "appId必填项")
private String appId;
/**
* 手机号
*/
@NotNull(message = "手机号必填项")
private String phone;
/**
* 使用状态
*/
private Integer status;
/**
* 签名参数
*/
@NotBlank(message = "签名必填项")
private String sign;
}

@ -0,0 +1,40 @@
package com.hfkj.openapi.model.request;
import lombok.Data;
import org.hibernate.validator.constraints.Range;
import javax.validation.constraints.NotBlank;
/**
* @className: RequestQueryDiscountListModel
* @author: HuRui
* @date: 2024/9/1
**/
@Data
public class RequestQueryPkDiscountModel {
/**
* appid
*/
@NotBlank(message = "请求id必填项")
private String reqId;
/**
* appid
*/
@NotBlank(message = "appId必填项")
private String appId;
/**
* 优惠券编号
*/
@NotBlank(message = "券包编号必填项")
private String discountPkNo;
/**
* 签名参数
*/
@NotBlank(message = "签名必填项")
private String sign;
}

@ -0,0 +1,54 @@
package com.hfkj.openapi.model.response;
import lombok.Data;
import org.hibernate.validator.constraints.Range;
import javax.validation.constraints.NotBlank;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* @className: RequestQueryDiscountListModel
* @author: HuRui
* @date: 2024/9/1
**/
@Data
public class ResponseQueryPkDiscountModel {
/**
* appid
*/
private String reqId;
/**
* appid
*/
private String appId;
/**
* 优惠券编号
*/
private String discountPkNo;
/**
* 优惠券名称
*/
private String discountPkName;
/**
* 结束时间
*/
private Date endTime;
/**
* 优惠券列表
*/
List<Object> discountList;
/**
* 签名参数
*/
private String sign;
}

@ -0,0 +1,31 @@
package com.hfkj.openapi.model.response;
import com.hfkj.openapi.model.UserDiscountModel;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**
* 推送订单模型
*/
@Data
public class ResponseUserDiscountModel {
/**
* 请求id
*/
private String reqId;
/**
* 手机号
*/
private String userPhone;
/**
* 数据列表
*/
private List<UserDiscountModel> dataList;
/**
* 签名参数
*/
private String sign;
}

@ -15,3 +15,6 @@ cqShellReqUrl=http://openapi.ngrok.xinyebang.cn/gateway.html
cqShellPartnerId=S0302207281600105753
cqShellPlatMerchantId=S0302206141000105717
cqShellPlatMerchantKey=wqisfmkzea6mwd7ogbyh3488jv0hqhdj
phgAppid=20241266600
phgAppSecret=BCB83776BDA7F609FBE99BBB8AC33840

Loading…
Cancel
Save