提交代码

pre
胡锐 2 weeks ago
parent 0c8c864973
commit 5c4cc6c914
  1. 114
      openapi/src/main/java/com/openapi/controller/BsDiscountController.java
  2. 6
      service/src/main/java/com/hfkj/common/pay/util/SignatureUtil.java
  3. 1
      service/src/main/java/com/hfkj/dao/BsAgentMerMapperExt.java
  4. 35
      service/src/main/java/com/hfkj/model/ReceiveDiscountPkModel.java
  5. 8
      service/src/main/java/com/hfkj/openapi/model/request/RequestQueryPkDiscountByStockCodeModel.java
  6. 4
      service/src/main/java/com/hfkj/openapi/model/request/RequestRefundDiscountModel.java
  7. 7
      service/src/main/java/com/hfkj/openapi/model/request/RequestRefundPkDiscountModel.java
  8. 7
      service/src/main/java/com/hfkj/openapi/model/response/ResponsePushDiscountPkModel.java
  9. 8
      service/src/main/java/com/hfkj/openapi/model/response/ResponseQueryPkDiscountByReqIdModel.java
  10. 6
      service/src/main/java/com/hfkj/service/discount/BsDiscountPkStockBatchService.java
  11. 6
      service/src/main/java/com/hfkj/service/discount/BsDiscountPkStockCodeService.java
  12. 13
      service/src/main/java/com/hfkj/service/discount/BsDiscountStockCodeService.java
  13. 4
      service/src/main/java/com/hfkj/service/discount/BsDiscountUserService.java
  14. 34
      service/src/main/java/com/hfkj/service/discount/impl/BsDiscountPkStockBatchServiceImpl.java
  15. 9
      service/src/main/java/com/hfkj/service/discount/impl/BsDiscountPkStockCodeServiceImpl.java
  16. 45
      service/src/main/java/com/hfkj/service/discount/impl/BsDiscountStockCodeServiceImpl.java
  17. 25
      service/src/main/java/com/hfkj/service/discount/impl/BsDiscountUserServiceImpl.java
  18. 18
      service/src/main/java/com/hfkj/service/gas/impl/BsGasServiceImpl.java
  19. 5
      service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java

@ -10,6 +10,7 @@ import com.hfkj.common.utils.DateUtil;
import com.hfkj.common.utils.ResponseMsgUtil; import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.entity.*; import com.hfkj.entity.*;
import com.hfkj.model.DiscountUserModel; import com.hfkj.model.DiscountUserModel;
import com.hfkj.model.ReceiveDiscountPkModel;
import com.hfkj.model.ResponseData; import com.hfkj.model.ResponseData;
import com.hfkj.openapi.model.UserDiscountModel; import com.hfkj.openapi.model.UserDiscountModel;
import com.hfkj.openapi.model.request.*; import com.hfkj.openapi.model.request.*;
@ -17,10 +18,9 @@ import com.hfkj.openapi.model.response.*;
import com.hfkj.service.agent.BsAgentApiLogService; import com.hfkj.service.agent.BsAgentApiLogService;
import com.hfkj.service.agent.BsAgentApiParamService; import com.hfkj.service.agent.BsAgentApiParamService;
import com.hfkj.service.agent.BsAgentDiscountService; import com.hfkj.service.agent.BsAgentDiscountService;
import com.hfkj.service.discount.BsDiscountPkRelService; import com.hfkj.service.discount.*;
import com.hfkj.service.discount.BsDiscountPkService;
import com.hfkj.service.discount.BsDiscountUserService;
import com.hfkj.sysenum.discount.DiscountPkStatusEnum; import com.hfkj.sysenum.discount.DiscountPkStatusEnum;
import com.hfkj.sysenum.discount.DiscountPkStockCodeStatusEnum;
import com.hfkj.sysenum.discount.DiscountStockCodeObtainTypeEnum; import com.hfkj.sysenum.discount.DiscountStockCodeObtainTypeEnum;
import com.hfkj.sysenum.discount.DiscountUserStatusEnum; import com.hfkj.sysenum.discount.DiscountUserStatusEnum;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -47,6 +47,12 @@ public class BsDiscountController {
@Resource @Resource
private BsDiscountPkService discountPkService; private BsDiscountPkService discountPkService;
@Resource @Resource
private BsDiscountPkStockBatchService discountPkStockBatchService;
@Resource
private BsDiscountPkStockCodeService discountPkStockCodeService;
@Resource
private BsDiscountStockCodeService discountStockCodeService;
@Resource
private BsDiscountPkRelService discountPkRelService; private BsDiscountPkRelService discountPkRelService;
@Resource @Resource
private BsAgentApiLogService agentApiLogService; private BsAgentApiLogService agentApiLogService;
@ -144,26 +150,9 @@ public class BsDiscountController {
apiLog.setRequestId(body.getReqId()); apiLog.setRequestId(body.getReqId());
apiLog.setRequestUrl("discount/refund"); apiLog.setRequestUrl("discount/refund");
apiLog.setRequestParam(JSONObject.toJSONString(body)); apiLog.setRequestParam(JSONObject.toJSONString(body));
// 退回优惠券
discountStockCodeService.recycle(body.getDiscountStockCode());
// 查询日志
BsAgentApiLogWithBLOBs apiLogWithBLOBs = agentApiLogService.getDetail(body.getAppId(), body.getPushReqId());
if (apiLogWithBLOBs == null) {
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.COMMON_ERROR, "未找到推送请求");
}
if (!apiLogWithBLOBs.getRequestUrl().equals("discount/push")) {
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.COMMON_ERROR, "未找到推送请求");
}
JSONObject data = JSONObject.parseObject(apiLogWithBLOBs.getResponseParam());
JSONArray codeList = data.getJSONArray("codeList");
for (Object obj : codeList) {
JSONObject code = (JSONObject) obj;
// 查询用户与优惠券信息
BsDiscountUser discountUser = discountUserService.getDetailByUserCodeId(code.getString("phone"), code.getLong("code"));
if (discountUser != null && discountUser.getStatus().equals(DiscountUserStatusEnum.type1.getCode())) {
discountUser.setStatus(DiscountUserStatusEnum.type4.getCode());
discountUserService.editData(discountUser);
}
}
log.info("返回参数:ok"); log.info("返回参数:ok");
apiLog.setResponseParam("ok"); apiLog.setResponseParam("ok");
return ResponseMsgUtil.success("ok"); return ResponseMsgUtil.success("ok");
@ -210,7 +199,7 @@ public class BsDiscountController {
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未配置优惠券包"); throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未配置优惠券包");
} }
// 领取优惠券 // 领取优惠券
List<BsDiscountUser> codeDataList = discountUserService.receivePk( List<ReceiveDiscountPkModel> codeDataList = discountUserService.receivePk(
body.getDiscountPkNo(), body.getDiscountPkNo(),
body.getNumber(), body.getNumber(),
DiscountStockCodeObtainTypeEnum.type4, body.getPhone(), DiscountStockCodeObtainTypeEnum.type4, body.getPhone(),
@ -218,7 +207,14 @@ public class BsDiscountController {
); );
List<Map<String,Object>> codeMapList = new ArrayList<>(); List<Map<String,Object>> codeMapList = new ArrayList<>();
for (BsDiscountUser discountUser : codeDataList) { for (ReceiveDiscountPkModel receiveDiscountPk : codeDataList) {
Map<String,Object> discountPkMap = new HashMap<>();
discountPkMap.put("phone", receiveDiscountPk.getPhone());
discountPkMap.put("discountPkNo", receiveDiscountPk.getDiscountPkNo());
discountPkMap.put("discountPkStockCode", receiveDiscountPk.getDiscountPkStockCode());
List<Map<String,Object>> codeList = new LinkedList<>();
for (BsDiscountUser discountUser : receiveDiscountPk.getDiscountUserList()) {
Map<String,Object> codeMap = new HashMap<>(); Map<String,Object> codeMap = new HashMap<>();
codeMap.put("discountNo", discountUser.getDiscountNo()); codeMap.put("discountNo", discountUser.getDiscountNo());
codeMap.put("phone", discountUser.getUserPhone()); codeMap.put("phone", discountUser.getUserPhone());
@ -226,13 +222,15 @@ public class BsDiscountController {
codeMap.put("status", discountUser.getStatus()); codeMap.put("status", discountUser.getStatus());
codeMap.put("createTime", DateUtil.date2String(discountUser.getCreateTime(), DateUtil.Y_M_D_HMS)); codeMap.put("createTime", DateUtil.date2String(discountUser.getCreateTime(), DateUtil.Y_M_D_HMS));
codeMap.put("expirationDate", DateUtil.date2String(discountUser.getExpirationDate(), DateUtil.Y_M_D_HMS)); codeMap.put("expirationDate", DateUtil.date2String(discountUser.getExpirationDate(), DateUtil.Y_M_D_HMS));
codeMapList.add(codeMap); codeList.add(codeMap);
}
discountPkMap.put("codeList", codeList);
codeMapList.add(discountPkMap);
} }
ResponsePushDiscountPkModel response = new ResponsePushDiscountPkModel(); ResponsePushDiscountPkModel response = new ResponsePushDiscountPkModel();
response.setReqId(body.getReqId()); response.setReqId(body.getReqId());
response.setAppId(body.getAppId()); response.setAppId(body.getAppId());
response.setDiscountPkNo(body.getDiscountPkNo()); response.setList(codeMapList);
response.setCodeList(codeMapList);
response.setSign(SignatureUtil.createSign(response, agentApiParamService.getParamByAppId(body.getAppId()).getAppSecret())); response.setSign(SignatureUtil.createSign(response, agentApiParamService.getParamByAppId(body.getAppId()).getAppSecret()));
log.info("返回参数:" + JSONObject.toJSONString(response)); log.info("返回参数:" + JSONObject.toJSONString(response));
apiLog.setResponseParam(JSONObject.toJSONString(response)); apiLog.setResponseParam(JSONObject.toJSONString(response));
@ -276,25 +274,8 @@ public class BsDiscountController {
apiLog.setRequestUrl("discount/refundPk"); apiLog.setRequestUrl("discount/refundPk");
apiLog.setRequestParam(JSONObject.toJSONString(body)); apiLog.setRequestParam(JSONObject.toJSONString(body));
// 查询日志 discountPkStockBatchService.recycle(Long.parseLong(body.getDiscountPkStockCode()));
BsAgentApiLogWithBLOBs apiLogWithBLOBs = agentApiLogService.getDetail(body.getAppId(), body.getPushReqId());
if (apiLogWithBLOBs == null) {
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.COMMON_ERROR, "未找到推送请求");
}
if (!apiLogWithBLOBs.getRequestUrl().equals("discount/pushPk")) {
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.COMMON_ERROR, "未找到推送请求");
}
JSONObject data = JSONObject.parseObject(apiLogWithBLOBs.getResponseParam());
JSONArray codeList = data.getJSONArray("codeList");
for (Object obj : codeList) {
JSONObject code = (JSONObject) obj;
// 查询用户与优惠券信息
BsDiscountUser discountUser = discountUserService.getDetailByUserCodeId(code.getString("phone"), code.getLong("code"));
if (discountUser != null && discountUser.getStatus().equals(DiscountUserStatusEnum.type1.getCode())) {
discountUser.setStatus(DiscountUserStatusEnum.type4.getCode());
discountUserService.editData(discountUser);
}
}
log.info("返回参数:ok"); log.info("返回参数:ok");
apiLog.setResponseParam("ok"); apiLog.setResponseParam("ok");
return ResponseMsgUtil.success("ok"); return ResponseMsgUtil.success("ok");
@ -390,11 +371,11 @@ public class BsDiscountController {
} }
} }
@RequestMapping(value="/queryPkDetailByReqId",method = RequestMethod.POST) @RequestMapping(value="/queryPkDetailByStockCode",method = RequestMethod.POST)
@ResponseBody @ResponseBody
@ApiOperation(value = "根据请求id查询优惠券包详情") @ApiOperation(value = "根据库存code查询优惠券包详情")
public ResponseData queryPkDetailByReqId(@Validated @RequestBody RequestQueryPkDiscountByReqIdModel body) { public ResponseData queryPkDetailByStockCode(@Validated @RequestBody RequestQueryPkDiscountByStockCodeModel body) {
log.info("========= Start 根据手机号查询优惠券包详情 Start ==========="); log.info("========= Start 根据库存code查询优惠券包详情 Start ===========");
log.info("请求参数:" + JSONObject.toJSONString(body)); log.info("请求参数:" + JSONObject.toJSONString(body));
BsAgentApiLogWithBLOBs apiLog = new BsAgentApiLogWithBLOBs(); BsAgentApiLogWithBLOBs apiLog = new BsAgentApiLogWithBLOBs();
try { try {
@ -409,34 +390,29 @@ public class BsDiscountController {
} }
apiLog.setAppId(body.getAppId()); apiLog.setAppId(body.getAppId());
apiLog.setRequestId(body.getReqId()); apiLog.setRequestId(body.getReqId());
apiLog.setRequestUrl("discount/queryPkDetailByPhone"); apiLog.setRequestUrl("discount/queryPkDetailByStockCode");
apiLog.setRequestParam(JSONObject.toJSONString(body)); apiLog.setRequestParam(JSONObject.toJSONString(body));
// 查询日志 // 查询库存code
BsAgentApiLogWithBLOBs apiLogWithBLOBs = agentApiLogService.getDetail(body.getAppId(), body.getPushReqId()); BsDiscountPkStockCode stockCode = discountPkStockCodeService.getDetail(Long.parseLong(body.getDiscountPkStockCode()));
if (apiLogWithBLOBs == null) { if (stockCode == null) {
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.COMMON_ERROR, "未找到推送请求"); throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.COMMON_ERROR, "未找到code");
} }
if (!apiLogWithBLOBs.getRequestUrl().equals("discount/pushPk")) { if (stockCode.getStatus().equals(DiscountPkStockCodeStatusEnum.status1.getCode())) {
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.COMMON_ERROR, "未找到推送请求"); throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.COMMON_ERROR, "未找到code");
}
JSONObject data = JSONObject.parseObject(apiLogWithBLOBs.getResponseParam());
BsDiscountPk discountPk = discountPkService.getDetail(data.getString("discountPkNo"));
if (discountPk == null) {
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.COMMON_ERROR, "优惠券包已失效");
} }
ResponseQueryPkDiscountByReqIdModel response = new ResponseQueryPkDiscountByReqIdModel(); ResponseQueryPkDiscountByReqIdModel response = new ResponseQueryPkDiscountByReqIdModel();
response.setAppId(body.getAppId()); response.setAppId(body.getAppId());
response.setReqId(body.getReqId()); response.setReqId(body.getReqId());
response.setDiscountPkNo(discountPk.getDiscountPkNo()); response.setDiscountPkNo(stockCode.getDiscountPkNo());
response.setPushReqId(body.getPushReqId()); response.setDiscountPkStockCode(stockCode.getId());
response.setCodeList(new LinkedList<>()); response.setCodeList(new LinkedList<>());
JSONArray codeList = data.getJSONArray("codeList"); List<BsDiscountStockCode> codeList = discountStockCodeService.getCodeListByPkStockId(stockCode.getId());
for (Object obj : codeList) { for (BsDiscountStockCode obj : codeList) {
JSONObject code = (JSONObject) obj; JSONObject code = new JSONObject();
// 查询用户与优惠券信息 // 查询用户与优惠券信息
BsDiscountUser discountUser = discountUserService.getDetailByUserCodeId(code.getString("phone"), code.getLong("code")); BsDiscountUser discountUser = discountUserService.getDetailByUserCodeId(obj.getReceiveMerUserPhone(), obj.getId());
code.put("discountNo", discountUser.getDiscountNo()); code.put("discountNo", discountUser.getDiscountNo());
code.put("discountType", discountUser.getDiscountType()); code.put("discountType", discountUser.getDiscountType());
code.put("discountCondition", discountUser.getDiscountCondition()); code.put("discountCondition", discountUser.getDiscountCondition());
@ -467,7 +443,7 @@ public class BsDiscountController {
if (apiLog.getAppId() != null) { if (apiLog.getAppId() != null) {
agentApiLogService.edit(apiLog); agentApiLogService.edit(apiLog);
} }
log.info("========= END 根据手机号查询优惠券包详情 END ==========="); log.info("========= END 根据库存code查询优惠券包详情 END ===========");
} }
} }

@ -86,9 +86,11 @@ public class SignatureUtil {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
String paramStr = "{ \n" + String paramStr = "{ \n" +
" \"reqId\": \"cs0007\",\n" + " \"reqId\": \"cs0008\",\n" +
" \"appId\": \"hf7356c71fb97ab0\",\n" + " \"appId\": \"hf7356c71fb97ab0\",\n" +
" \"pushReqId\": \"cs0005\"\n" + " \"discountPkNo\": \"DPK10018\",\n" +
" \"number\": \"1\",\n" +
" \"phone\": \"17726395120\"\n" +
"}"; "}";
String sign = createSign(JSONObject.parseObject(paramStr), "8aef995ff71485dc19b36e35f04c4016"); String sign = createSign(JSONObject.parseObject(paramStr), "8aef995ff71485dc19b36e35f04c4016");
System.out.println(sign); System.out.println(sign);

@ -46,7 +46,6 @@ public interface BsAgentMerMapperExt {
" a.merName," + " a.merName," +
" a.merAddress," + " a.merAddress," +
" a.agentName," + " a.agentName," +
" a.`status`," +
" a.createTime," + " a.createTime," +
" GROUP_CONCAT(a.agentStaffName) agentStaff" + " GROUP_CONCAT(a.agentStaffName) agentStaff" +
" FROM " + " FROM " +

@ -0,0 +1,35 @@
package com.hfkj.model;
import com.hfkj.entity.BsDiscountUser;
import lombok.Data;
import java.util.List;
/**
* 领取优惠券包返回参数
* @className: receiveDiscountPk
* @author: HuRui
* @date: 2025/1/13
**/
@Data
public class ReceiveDiscountPkModel {
/**
* 用户手机号
*/
private String phone;
/**
* 优惠券包编码
*/
private String discountPkNo;
/**
* 优惠券包库存id
*/
private Long discountPkStockCode;
/**
* 用户优惠券
*/
private List<BsDiscountUser> discountUserList;
}

@ -10,7 +10,7 @@ import javax.validation.constraints.NotBlank;
* @date: 2024/9/1 * @date: 2024/9/1
**/ **/
@Data @Data
public class RequestQueryPkDiscountByReqIdModel { public class RequestQueryPkDiscountByStockCodeModel {
/** /**
* 请求id必填项 * 请求id必填项
@ -25,10 +25,10 @@ public class RequestQueryPkDiscountByReqIdModel {
private String appId; private String appId;
/** /**
* 推送请求id * 优惠券包库存代码
*/ */
@NotBlank(message = "推送请求id必填项") @NotBlank(message = "优惠券包库存代码必填项")
private String pushReqId; private String discountPkStockCode;
/** /**
* 签名参数 * 签名参数

@ -27,8 +27,8 @@ public class RequestRefundDiscountModel {
/** /**
* 推送请求id * 推送请求id
*/ */
@NotBlank(message = "推送请求id必填项") @NotBlank(message = "优惠券库存代码必填项")
private String pushReqId; private Long discountStockCode;
/** /**
* 签名参数 * 签名参数

@ -1,6 +1,7 @@
package com.hfkj.openapi.model.request; package com.hfkj.openapi.model.request;
import lombok.Data; import lombok.Data;
import org.hibernate.validator.constraints.Range;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
@ -25,10 +26,10 @@ public class RequestRefundPkDiscountModel {
private String appId; private String appId;
/** /**
* 推送请求id * 优惠券包库存代码
*/ */
@NotBlank(message = "推送请求id必填项") @NotBlank(message = "优惠券包库存代码必填项")
private String pushReqId; private String discountPkStockCode;
/** /**
* 签名参数 * 签名参数

@ -22,15 +22,10 @@ public class ResponsePushDiscountPkModel {
*/ */
private String appId; private String appId;
/**
* 券包编号
*/
private String discountPkNo;
/** /**
* 优惠券编码列表 * 优惠券编码列表
*/ */
private List<Map<String,Object>> codeList; private List<Map<String,Object>> list;
/** /**
* 签名参数 * 签名参数

@ -24,14 +24,14 @@ public class ResponseQueryPkDiscountByReqIdModel {
private String appId; private String appId;
/** /**
* 推送请求id * 优惠券编号
*/ */
private String pushReqId; private String discountPkNo;
/** /**
* 优惠券编号 * 优惠券包库存代码
*/ */
private String discountPkNo; private Long discountPkStockCode;
/** /**
* 优惠券code列表 * 优惠券code列表

@ -27,6 +27,12 @@ public interface BsDiscountPkStockBatchService {
*/ */
void addStock(String discountPkNo,Integer stockCount); void addStock(String discountPkNo,Integer stockCount);
/**
* 回收优惠券包
* @param stockCodeId 库存id
*/
void recycle(Long stockCodeId);
/** /**
* 查询详情 * 查询详情
* @param batchNo * @param batchNo

@ -32,6 +32,12 @@ public interface BsDiscountPkStockCodeService {
*/ */
List<BsDiscountPkStockCode> getAssignCodeList(String discountPkNo, Integer number); List<BsDiscountPkStockCode> getAssignCodeList(String discountPkNo, Integer number);
/**
* 查询详情
* @param stockId 库存id
* @return
*/
BsDiscountPkStockCode getDetail(Long stockId);
/** /**
* 查询列表 * 查询列表
* @param param * @param param

@ -24,6 +24,12 @@ public interface BsDiscountStockCodeService {
*/ */
void update(BsDiscountStockCode data); void update(BsDiscountStockCode data);
/**
* 回收优惠券
* @param stockCodeId
*/
void recycle(Long stockCodeId);
/** /**
* 查询详情 * 查询详情
* @param id * @param id
@ -38,6 +44,13 @@ public interface BsDiscountStockCodeService {
*/ */
List<BsDiscountStockCode> getAssignCodeList(String discountNo, Integer number); List<BsDiscountStockCode> getAssignCodeList(String discountNo, Integer number);
/**
* 查询优惠券库存id
* @param
* @return
*/
List<BsDiscountStockCode> getCodeListByPkStockId(Long discountPkStockId);
/** /**
* 查询列表 * 查询列表
* @param param * @param param

@ -1,8 +1,8 @@
package com.hfkj.service.discount; package com.hfkj.service.discount;
import com.hfkj.entity.BsDiscount;
import com.hfkj.entity.BsDiscountUser; import com.hfkj.entity.BsDiscountUser;
import com.hfkj.model.DiscountUserModel; import com.hfkj.model.DiscountUserModel;
import com.hfkj.model.ReceiveDiscountPkModel;
import com.hfkj.sysenum.discount.DiscountStockCodeObtainTypeEnum; import com.hfkj.sysenum.discount.DiscountStockCodeObtainTypeEnum;
import java.util.List; import java.util.List;
@ -39,7 +39,7 @@ public interface BsDiscountUserService {
* @param agentAppid * @param agentAppid
* @return * @return
*/ */
List<BsDiscountUser> receivePk(String discountPkNo, Integer number, DiscountStockCodeObtainTypeEnum obtainType, String userPhone, String agentAppid); List<ReceiveDiscountPkModel> receivePk(String discountPkNo, Integer number, DiscountStockCodeObtainTypeEnum obtainType, String userPhone, String agentAppid);
/** /**
* 使用优惠券 * 使用优惠券

@ -6,11 +6,14 @@ import com.hfkj.common.exception.SysCode;
import com.hfkj.dao.BsDiscountPkStockBatchMapper; import com.hfkj.dao.BsDiscountPkStockBatchMapper;
import com.hfkj.entity.*; import com.hfkj.entity.*;
import com.hfkj.service.discount.*; import com.hfkj.service.discount.*;
import com.hfkj.sysenum.discount.DiscountPkStatusEnum;
import com.hfkj.sysenum.discount.DiscountPkStockCodeStatusEnum; import com.hfkj.sysenum.discount.DiscountPkStockCodeStatusEnum;
import com.hfkj.sysenum.discount.DiscountStockCodeStatusEnum; import com.hfkj.sysenum.discount.DiscountStockCodeStatusEnum;
import org.apache.commons.collections4.MapUtils; import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
@ -31,6 +34,8 @@ public class BsDiscountPkStockBatchServiceImpl implements BsDiscountPkStockBatch
private BsDiscountPkService discountPkService; private BsDiscountPkService discountPkService;
@Resource @Resource
private BsDiscountPkStockCodeService discountPkStockCodeService; private BsDiscountPkStockCodeService discountPkStockCodeService;
@Resource
private BsDiscountStockCodeService discountStockCodeService;
@Override @Override
public void editData(BsDiscountPkStockBatch data) { public void editData(BsDiscountPkStockBatch data) {
@ -84,6 +89,35 @@ public class BsDiscountPkStockBatchServiceImpl implements BsDiscountPkStockBatch
editData(batch); editData(batch);
} }
@Override
@Transactional(propagation= Propagation.REQUIRES_NEW, rollbackFor= {RuntimeException.class})
public void recycle(Long stockCodeId) {
// 查询优惠券包库存编号
BsDiscountPkStockCode pkStockCode = discountPkStockCodeService.getDetail(stockCodeId);
if (pkStockCode == null) {
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未找到优惠券包库存编码");
}
if (!pkStockCode.getStatus().equals(DiscountPkStockCodeStatusEnum.status2.getCode())) {
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "优惠券包状态错误");
}
pkStockCode.setObtainType(null);
pkStockCode.setObtainTime(null);
pkStockCode.setReceiveMerUserId(null);
pkStockCode.setReceiveMerUserPhone(null);
pkStockCode.setStatus(DiscountPkStockCodeStatusEnum.status1.getCode());
pkStockCode.setAgentAppid(null);
discountPkStockCodeService.update(pkStockCode);
// 查询优惠券包下的优惠券
List<BsDiscountStockCode> discountStockCodeList = discountStockCodeService.getCodeListByPkStockId(pkStockCode.getId());
for (BsDiscountStockCode discountStockCode : discountStockCodeList) {
if (discountStockCode.getStatus().equals(DiscountStockCodeStatusEnum.status2.getCode())) {
// 退回优惠券
discountStockCodeService.recycle(discountStockCode.getId());
}
}
}
@Override @Override
public BsDiscountPkStockBatch getStockBatchDetail(String batchNo) { public BsDiscountPkStockBatch getStockBatchDetail(String batchNo) {
BsDiscountPkStockBatchExample example = new BsDiscountPkStockBatchExample(); BsDiscountPkStockBatchExample example = new BsDiscountPkStockBatchExample();

@ -40,7 +40,7 @@ public class BsDiscountPkStockCodeServiceImpl implements BsDiscountPkStockCodeSe
@Override @Override
public void update(BsDiscountPkStockCode data) { public void update(BsDiscountPkStockCode data) {
data.setUpdateTime(new Date()); data.setUpdateTime(new Date());
discountPkStockCodeMapper.updateByPrimaryKeySelective(data); discountPkStockCodeMapper.updateByPrimaryKey(data);
} }
@Override @Override
@ -54,11 +54,16 @@ public class BsDiscountPkStockCodeServiceImpl implements BsDiscountPkStockCodeSe
PageInfo<BsDiscountPkStockCode> pageInfo = new PageInfo<>(discountPkStockCodeMapper.selectByExample(example)); PageInfo<BsDiscountPkStockCode> pageInfo = new PageInfo<>(discountPkStockCodeMapper.selectByExample(example));
if (pageInfo.getList().size() != number) { if (pageInfo.getList().size() != number) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券库存不足"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券库存不足");
} }
return pageInfo.getList(); return pageInfo.getList();
} }
@Override
public BsDiscountPkStockCode getDetail(Long stockId) {
return discountPkStockCodeMapper.selectByPrimaryKey(stockId);
}
@Override @Override
public List<BsDiscountPkStockCode> getCodeList(Map<String, Object> param) { public List<BsDiscountPkStockCode> getCodeList(Map<String, Object> param) {
BsDiscountPkStockCodeExample example = new BsDiscountPkStockCodeExample(); BsDiscountPkStockCodeExample example = new BsDiscountPkStockCodeExample();

@ -8,11 +8,16 @@ import com.hfkj.common.exception.SysCode;
import com.hfkj.dao.BsDiscountStockCodeMapper; import com.hfkj.dao.BsDiscountStockCodeMapper;
import com.hfkj.entity.BsDiscountStockCode; import com.hfkj.entity.BsDiscountStockCode;
import com.hfkj.entity.BsDiscountStockCodeExample; import com.hfkj.entity.BsDiscountStockCodeExample;
import com.hfkj.entity.BsDiscountUser;
import com.hfkj.service.discount.BsDiscountStockCodeService; import com.hfkj.service.discount.BsDiscountStockCodeService;
import com.hfkj.service.discount.BsDiscountUserService;
import com.hfkj.sysenum.discount.DiscountStockCodeStatusEnum; import com.hfkj.sysenum.discount.DiscountStockCodeStatusEnum;
import com.hfkj.sysenum.discount.DiscountUserStatusEnum;
import org.apache.commons.collections4.MapUtils; import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date; import java.util.Date;
@ -29,7 +34,8 @@ public class BsDiscountStockCodeServiceImpl implements BsDiscountStockCodeServic
@Resource @Resource
private BsDiscountStockCodeMapper discountStockCodeMapper; private BsDiscountStockCodeMapper discountStockCodeMapper;
@Resource
private BsDiscountUserService discountUserService;
@Override @Override
public void insertList(List<BsDiscountStockCode> codeList) { public void insertList(List<BsDiscountStockCode> codeList) {
discountStockCodeMapper.insertList(codeList); discountStockCodeMapper.insertList(codeList);
@ -41,6 +47,33 @@ public class BsDiscountStockCodeServiceImpl implements BsDiscountStockCodeServic
discountStockCodeMapper.updateByPrimaryKey(data); discountStockCodeMapper.updateByPrimaryKey(data);
} }
@Override
@Transactional(propagation= Propagation.REQUIRED, rollbackFor= {RuntimeException.class})
public void recycle(Long stockCodeId) {
// 查询库存记录
BsDiscountStockCode stockCode = getDetail(stockCodeId);
if (stockCode == null) {
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "位置优惠券库存id");
}
if (stockCode.getStatus().equals(DiscountStockCodeStatusEnum.status2.getCode())) {
// 退回优惠券库存
stockCode.setObtainType(null);
stockCode.setObtainTime(null);
stockCode.setReceiveMerUserId(null);
stockCode.setReceiveMerUserPhone(null);
stockCode.setStatus(DiscountStockCodeStatusEnum.status1.getCode());
stockCode.setAgentAppid(null);
update(stockCode);
// 用户优惠券
BsDiscountUser discountUser = discountUserService.getDetailByCodeId(stockCodeId);
if (discountUser != null) {
discountUser.setStatus(DiscountUserStatusEnum.type4.getCode());
discountUserService.editData(discountUser);
}
}
}
@Override @Override
public BsDiscountStockCode getDetail(Long id) { public BsDiscountStockCode getDetail(Long id) {
return discountStockCodeMapper.selectByPrimaryKey(id); return discountStockCodeMapper.selectByPrimaryKey(id);
@ -62,6 +95,16 @@ public class BsDiscountStockCodeServiceImpl implements BsDiscountStockCodeServic
return pageInfo.getList(); return pageInfo.getList();
} }
@Override
public List<BsDiscountStockCode> getCodeListByPkStockId(Long discountPkStockId) {
BsDiscountStockCodeExample example = new BsDiscountStockCodeExample();
example.createCriteria()
.andStatusNotEqualTo(DiscountStockCodeStatusEnum.status0.getCode())
.andDiscountPkStockCodeEqualTo(discountPkStockId);
example.setOrderByClause("id desc");
return discountStockCodeMapper.selectByExample(example);
}
@Override @Override
public List<BsDiscountStockCode> getCodeList(Map<String, Object> param) { public List<BsDiscountStockCode> getCodeList(Map<String, Object> param) {
BsDiscountStockCodeExample example = new BsDiscountStockCodeExample(); BsDiscountStockCodeExample example = new BsDiscountStockCodeExample();

@ -7,6 +7,7 @@ import com.hfkj.common.exception.SysCode;
import com.hfkj.dao.BsDiscountUserMapper; import com.hfkj.dao.BsDiscountUserMapper;
import com.hfkj.entity.*; import com.hfkj.entity.*;
import com.hfkj.model.DiscountUserModel; import com.hfkj.model.DiscountUserModel;
import com.hfkj.model.ReceiveDiscountPkModel;
import com.hfkj.service.discount.*; import com.hfkj.service.discount.*;
import com.hfkj.service.user.BsUserService; import com.hfkj.service.user.BsUserService;
import com.hfkj.sysenum.discount.*; import com.hfkj.sysenum.discount.*;
@ -113,6 +114,7 @@ public class BsDiscountUserServiceImpl implements BsDiscountUserService {
discountUser.setDiscountNo(discount.getDiscountNo()); discountUser.setDiscountNo(discount.getDiscountNo());
discountUser.setDiscountName(discount.getDiscountName()); discountUser.setDiscountName(discount.getDiscountName());
discountUser.setDiscountType(discount.getDiscountType()); discountUser.setDiscountType(discount.getDiscountType());
discountUser.setOverlayDiscount(discount.getOverlayDiscount());
discountUser.setDiscountCondition(discount.getDiscountCondition()); discountUser.setDiscountCondition(discount.getDiscountCondition());
discountUser.setDiscountPrice(discount.getDiscountPrice()); discountUser.setDiscountPrice(discount.getDiscountPrice());
discountUser.setDiscountStockCode(discountStockCode.getId()); discountUser.setDiscountStockCode(discountStockCode.getId());
@ -159,11 +161,13 @@ public class BsDiscountUserServiceImpl implements BsDiscountUserService {
@Override @Override
@Transactional(propagation= Propagation.REQUIRED) @Transactional(propagation= Propagation.REQUIRED)
public List<BsDiscountUser> receivePk(String discountPkNo, Integer number, DiscountStockCodeObtainTypeEnum obtainType, String userPhone, String agentAppid) { public List<ReceiveDiscountPkModel> receivePk(String discountPkNo, Integer number, DiscountStockCodeObtainTypeEnum obtainType, String userPhone, String agentAppid) {
// 锁编号 // 锁编号
String lockKey = RECEIVE_DISCOUNT_PK_LOCK_KEY+"_"+discountPkNo; String lockKey = RECEIVE_DISCOUNT_PK_LOCK_KEY+"_"+discountPkNo;
// 获取锁 // 获取锁
Boolean lock = redisTemplate.opsForValue().setIfAbsent(lockKey, ""); Boolean lock = redisTemplate.opsForValue().setIfAbsent(lockKey, "");
List<ReceiveDiscountPkModel> list = new LinkedList<>();
if (Boolean.TRUE.equals(lock)) { if (Boolean.TRUE.equals(lock)) {
try { try {
// 锁超时时间 10秒 // 锁超时时间 10秒
@ -184,12 +188,12 @@ public class BsDiscountUserServiceImpl implements BsDiscountUserService {
other.put("agentAppid", agentAppid); other.put("agentAppid", agentAppid);
user = userService.register(userPhone, other); user = userService.register(userPhone, other);
} }
List<BsDiscountUser> receiveList = new ArrayList<>();
// 优惠券包库存编码 // 优惠券包库存编码
List<BsDiscountPkStockCode> codeList = discountPkStockCodeService.getAssignCodeList(discountPkNo, number); List<BsDiscountPkStockCode> codeList = discountPkStockCodeService.getAssignCodeList(discountPkNo, number);
for (BsDiscountPkStockCode code : codeList) { for (BsDiscountPkStockCode code : codeList) {
// 库存领取数据
List<BsDiscountUser> receiveList = new ArrayList<>();
code.setObtainType(obtainType.getCode()); code.setObtainType(obtainType.getCode());
code.setObtainTime(new Date()); code.setObtainTime(new Date());
code.setReceiveMerUserId(user.getId()); code.setReceiveMerUserId(user.getId());
@ -207,7 +211,7 @@ public class BsDiscountUserServiceImpl implements BsDiscountUserService {
// 优惠券库存编码 // 优惠券库存编码
BsDiscountStockCode discountStockCode = discountStockCodeService.getDetail(discountUser.getDiscountStockCode()); BsDiscountStockCode discountStockCode = discountStockCodeService.getDetail(discountUser.getDiscountStockCode());
if (discountStockCode != null) { if (discountStockCode != null) {
discountStockCode.setDiscountPkStockCode(discountStockCode.getId()); discountStockCode.setDiscountPkStockCode(code.getId());
discountStockCode.setDiscountPkId(discountPk.getId()); discountStockCode.setDiscountPkId(discountPk.getId());
discountStockCode.setDiscountPkNo(discountPk.getDiscountPkNo()); discountStockCode.setDiscountPkNo(discountPk.getDiscountPkNo());
discountStockCode.setDiscountPkName(discountPk.getDiscountPkName()); discountStockCode.setDiscountPkName(discountPk.getDiscountPkName());
@ -216,8 +220,15 @@ public class BsDiscountUserServiceImpl implements BsDiscountUserService {
} }
receiveList.addAll(discountUsers); receiveList.addAll(discountUsers);
} }
}
return receiveList; ReceiveDiscountPkModel receiveDiscountPkModel = new ReceiveDiscountPkModel();
receiveDiscountPkModel.setDiscountPkNo(discountPkNo);
receiveDiscountPkModel.setDiscountPkStockCode(code.getId());
receiveDiscountPkModel.setPhone(userPhone);
receiveDiscountPkModel.setDiscountUserList(receiveList);
list.add(receiveDiscountPkModel);
}
return list;
} catch (BaseException e) { } catch (BaseException e) {
// 释放锁 // 释放锁
redisTemplate.delete(lockKey); redisTemplate.delete(lockKey);

@ -78,8 +78,6 @@ public class BsGasServiceImpl implements BsGasService {
BigDecimal discount = new BigDecimal("100"); BigDecimal discount = new BigDecimal("100");
BigDecimal serviceFeeRate = new BigDecimal("0"); BigDecimal serviceFeeRate = new BigDecimal("0");
// 没有使用优惠券,可以享受油价优惠
if (userDiscountId == null) {
if (agentMerId != null) { if (agentMerId != null) {
// 查询代理价格 // 查询代理价格
BsAgentPrice agentPrice = agentPriceService.getDetail(agentMerId, oilNo); BsAgentPrice agentPrice = agentPriceService.getDetail(agentMerId, oilNo);
@ -95,12 +93,17 @@ public class BsGasServiceImpl implements BsGasService {
serviceFeeRate = agentPrice.getServiceFeeRate(); serviceFeeRate = agentPrice.getServiceFeeRate();
} }
} }
} else {
if (userDiscountId != null) {
// 查询用户优惠券 // 查询用户优惠券
discountUser = discountUserService.getDetail(userDiscountId); discountUser = discountUserService.getDetail(userDiscountId);
if (discountUser == null) { if (discountUser == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到用户优惠券"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到用户优惠券");
} }
if (discountUser.getOverlayDiscount().equals(false)) {
// 优惠券与油价不叠加
discount = new BigDecimal("100");
}
// 查询平台服务费 // 查询平台服务费
BsAgentPrice agentPrice = agentPriceService.getDetail(AgentPriceTypeEnum.type1, merNo, oilNo); BsAgentPrice agentPrice = agentPriceService.getDetail(AgentPriceTypeEnum.type1, merNo, oilNo);
if (agentPrice != null) { if (agentPrice != null) {
@ -141,13 +144,12 @@ public class BsGasServiceImpl implements BsGasService {
BigDecimal gasStationDrop = gasOilPrice.getGasStationDrop(); BigDecimal gasStationDrop = gasOilPrice.getGasStationDrop();
// 油站优惠价 // 油站优惠价
BigDecimal priceVip = gasOilPrice.getPriceVip(); BigDecimal priceVip = gasOilPrice.getPriceVip();
if (discountUser != null && !discountUser.getOverlayDiscount()) {
// 优惠券与油价不叠加
priceVip = priceGun;
}
// 嗨森逛平台价 油站优惠价 * 折扣 // 嗨森逛平台价 油站优惠价 * 折扣
BigDecimal pricePlatform = priceVip.multiply(discount).setScale(2, BigDecimal.ROUND_HALF_UP); BigDecimal pricePlatform = priceVip.multiply(discount).setScale(2, BigDecimal.ROUND_HALF_UP);
if (discountUser != null && discountUser.getOverlayDiscount().equals(false)) {
// 优惠券与油价不叠加
pricePlatform = priceGun;
}
// 加油金额 // 加油金额
payPriceModel.setOilingPrice(refuelPrice); payPriceModel.setOilingPrice(refuelPrice);

@ -175,6 +175,9 @@ public class BsOrderServiceImpl implements BsOrderService {
order.setProductTotalPrice(productTotalPrice); order.setProductTotalPrice(productTotalPrice);
BigDecimal payRealPrice = totalPrice.subtract(order.getDeduction().getTotalDeductionPrice()); BigDecimal payRealPrice = totalPrice.subtract(order.getDeduction().getTotalDeductionPrice());
if (order.getOrderChildList().get(0).getProductType().equals(OrderChildProductTypeEnum.type1.getCode())) {
payRealPrice = totalPrice;
}
order.setPayRealPrice(payRealPrice.compareTo(new BigDecimal("0")) > 0 ? payRealPrice : new BigDecimal("0")); order.setPayRealPrice(payRealPrice.compareTo(new BigDecimal("0")) > 0 ? payRealPrice : new BigDecimal("0"));
order.setOrderStatus(order.getPayRealPrice().compareTo(new BigDecimal("0")) == 0?OrderStatusEnum.status2.getCode():OrderStatusEnum.status1.getCode()); order.setOrderStatus(order.getPayRealPrice().compareTo(new BigDecimal("0")) == 0?OrderStatusEnum.status2.getCode():OrderStatusEnum.status1.getCode());
// 订单入库前处理 // 订单入库前处理
@ -219,7 +222,9 @@ public class BsOrderServiceImpl implements BsOrderService {
childOrder.getCouponDiscountPrice() childOrder.getCouponDiscountPrice()
.add(new BigDecimal(childOrder.getIntegralDiscountPrice().toString()).divide(new BigDecimal("100"))) .add(new BigDecimal(childOrder.getIntegralDiscountPrice().toString()).divide(new BigDecimal("100")))
); );
if (!childOrder.getProductType().equals(OrderChildProductTypeEnum.type1.getCode())) {
childOrder.setProductActualPrice(childOrder.getProductTotalPrice().subtract(childOrder.getTotalDeductionPrice())); childOrder.setProductActualPrice(childOrder.getProductTotalPrice().subtract(childOrder.getTotalDeductionPrice()));
}
orderChildService.editData(childOrder); orderChildService.editData(childOrder);
} }
// 订单入库 // 订单入库

Loading…
Cancel
Save