diff --git a/openapi/src/main/java/com/openapi/controller/BsDiscountController.java b/openapi/src/main/java/com/openapi/controller/BsDiscountController.java index 98ee492..ba3689c 100644 --- a/openapi/src/main/java/com/openapi/controller/BsDiscountController.java +++ b/openapi/src/main/java/com/openapi/controller/BsDiscountController.java @@ -10,6 +10,7 @@ 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.ReceiveDiscountPkModel; import com.hfkj.model.ResponseData; import com.hfkj.openapi.model.UserDiscountModel; 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.BsAgentApiParamService; import com.hfkj.service.agent.BsAgentDiscountService; -import com.hfkj.service.discount.BsDiscountPkRelService; -import com.hfkj.service.discount.BsDiscountPkService; -import com.hfkj.service.discount.BsDiscountUserService; +import com.hfkj.service.discount.*; import com.hfkj.sysenum.discount.DiscountPkStatusEnum; +import com.hfkj.sysenum.discount.DiscountPkStockCodeStatusEnum; import com.hfkj.sysenum.discount.DiscountStockCodeObtainTypeEnum; import com.hfkj.sysenum.discount.DiscountUserStatusEnum; import io.swagger.annotations.Api; @@ -47,6 +47,12 @@ public class BsDiscountController { @Resource private BsDiscountPkService discountPkService; @Resource + private BsDiscountPkStockBatchService discountPkStockBatchService; + @Resource + private BsDiscountPkStockCodeService discountPkStockCodeService; + @Resource + private BsDiscountStockCodeService discountStockCodeService; + @Resource private BsDiscountPkRelService discountPkRelService; @Resource private BsAgentApiLogService agentApiLogService; @@ -144,26 +150,9 @@ public class BsDiscountController { apiLog.setRequestId(body.getReqId()); apiLog.setRequestUrl("discount/refund"); 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"); apiLog.setResponseParam("ok"); return ResponseMsgUtil.success("ok"); @@ -210,7 +199,7 @@ public class BsDiscountController { throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未配置优惠券包"); } // 领取优惠券 - List codeDataList = discountUserService.receivePk( + List codeDataList = discountUserService.receivePk( body.getDiscountPkNo(), body.getNumber(), DiscountStockCodeObtainTypeEnum.type4, body.getPhone(), @@ -218,21 +207,30 @@ public class BsDiscountController { ); List> codeMapList = new ArrayList<>(); - for (BsDiscountUser discountUser : codeDataList) { - Map codeMap = new HashMap<>(); - codeMap.put("discountNo", discountUser.getDiscountNo()); - codeMap.put("phone", discountUser.getUserPhone()); - codeMap.put("code", discountUser.getDiscountStockCode()); - codeMap.put("status", discountUser.getStatus()); - codeMap.put("createTime", DateUtil.date2String(discountUser.getCreateTime(), DateUtil.Y_M_D_HMS)); - codeMap.put("expirationDate", DateUtil.date2String(discountUser.getExpirationDate(), DateUtil.Y_M_D_HMS)); - codeMapList.add(codeMap); + for (ReceiveDiscountPkModel receiveDiscountPk : codeDataList) { + Map discountPkMap = new HashMap<>(); + discountPkMap.put("phone", receiveDiscountPk.getPhone()); + discountPkMap.put("discountPkNo", receiveDiscountPk.getDiscountPkNo()); + discountPkMap.put("discountPkStockCode", receiveDiscountPk.getDiscountPkStockCode()); + + List> codeList = new LinkedList<>(); + for (BsDiscountUser discountUser : receiveDiscountPk.getDiscountUserList()) { + Map codeMap = new HashMap<>(); + codeMap.put("discountNo", discountUser.getDiscountNo()); + codeMap.put("phone", discountUser.getUserPhone()); + codeMap.put("code", discountUser.getDiscountStockCode()); + codeMap.put("status", discountUser.getStatus()); + codeMap.put("createTime", DateUtil.date2String(discountUser.getCreateTime(), DateUtil.Y_M_D_HMS)); + codeMap.put("expirationDate", DateUtil.date2String(discountUser.getExpirationDate(), DateUtil.Y_M_D_HMS)); + codeList.add(codeMap); + } + discountPkMap.put("codeList", codeList); + codeMapList.add(discountPkMap); } ResponsePushDiscountPkModel response = new ResponsePushDiscountPkModel(); response.setReqId(body.getReqId()); response.setAppId(body.getAppId()); - response.setDiscountPkNo(body.getDiscountPkNo()); - response.setCodeList(codeMapList); + response.setList(codeMapList); response.setSign(SignatureUtil.createSign(response, agentApiParamService.getParamByAppId(body.getAppId()).getAppSecret())); log.info("返回参数:" + JSONObject.toJSONString(response)); apiLog.setResponseParam(JSONObject.toJSONString(response)); @@ -276,25 +274,8 @@ public class BsDiscountController { apiLog.setRequestUrl("discount/refundPk"); apiLog.setRequestParam(JSONObject.toJSONString(body)); - // 查询日志 - 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); - } - } + discountPkStockBatchService.recycle(Long.parseLong(body.getDiscountPkStockCode())); + log.info("返回参数:ok"); apiLog.setResponseParam("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 - @ApiOperation(value = "根据请求id查询优惠券包详情") - public ResponseData queryPkDetailByReqId(@Validated @RequestBody RequestQueryPkDiscountByReqIdModel body) { - log.info("========= Start 根据手机号查询优惠券包详情 Start ==========="); + @ApiOperation(value = "根据库存code查询优惠券包详情") + public ResponseData queryPkDetailByStockCode(@Validated @RequestBody RequestQueryPkDiscountByStockCodeModel body) { + log.info("========= Start 根据库存code查询优惠券包详情 Start ==========="); log.info("请求参数:" + JSONObject.toJSONString(body)); BsAgentApiLogWithBLOBs apiLog = new BsAgentApiLogWithBLOBs(); try { @@ -409,34 +390,29 @@ public class BsDiscountController { } apiLog.setAppId(body.getAppId()); apiLog.setRequestId(body.getReqId()); - apiLog.setRequestUrl("discount/queryPkDetailByPhone"); + apiLog.setRequestUrl("discount/queryPkDetailByStockCode"); apiLog.setRequestParam(JSONObject.toJSONString(body)); - // 查询日志 - 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, "未找到推送请求"); + // 查询库存code + BsDiscountPkStockCode stockCode = discountPkStockCodeService.getDetail(Long.parseLong(body.getDiscountPkStockCode())); + if (stockCode == null) { + 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, "优惠券包已失效"); + if (stockCode.getStatus().equals(DiscountPkStockCodeStatusEnum.status1.getCode())) { + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.COMMON_ERROR, "未找到code"); } ResponseQueryPkDiscountByReqIdModel response = new ResponseQueryPkDiscountByReqIdModel(); response.setAppId(body.getAppId()); response.setReqId(body.getReqId()); - response.setDiscountPkNo(discountPk.getDiscountPkNo()); - response.setPushReqId(body.getPushReqId()); + response.setDiscountPkNo(stockCode.getDiscountPkNo()); + response.setDiscountPkStockCode(stockCode.getId()); response.setCodeList(new LinkedList<>()); - JSONArray codeList = data.getJSONArray("codeList"); - for (Object obj : codeList) { - JSONObject code = (JSONObject) obj; + List codeList = discountStockCodeService.getCodeListByPkStockId(stockCode.getId()); + for (BsDiscountStockCode obj : codeList) { + 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("discountType", discountUser.getDiscountType()); code.put("discountCondition", discountUser.getDiscountCondition()); @@ -467,7 +443,7 @@ public class BsDiscountController { if (apiLog.getAppId() != null) { agentApiLogService.edit(apiLog); } - log.info("========= END 根据手机号查询优惠券包详情 END ==========="); + log.info("========= END 根据库存code查询优惠券包详情 END ==========="); } } diff --git a/service/src/main/java/com/hfkj/common/pay/util/SignatureUtil.java b/service/src/main/java/com/hfkj/common/pay/util/SignatureUtil.java index 690a567..01f5703 100644 --- a/service/src/main/java/com/hfkj/common/pay/util/SignatureUtil.java +++ b/service/src/main/java/com/hfkj/common/pay/util/SignatureUtil.java @@ -85,10 +85,12 @@ public class SignatureUtil { } public static void main(String[] args) throws Exception { - String paramStr = "{\n" + - " \"reqId\": \"cs0007\",\n" + + String paramStr = "{ \n" + + " \"reqId\": \"cs0008\",\n" + " \"appId\": \"hf7356c71fb97ab0\",\n" + - " \"pushReqId\": \"cs0005\"\n" + + " \"discountPkNo\": \"DPK10018\",\n" + + " \"number\": \"1\",\n" + + " \"phone\": \"17726395120\"\n" + "}"; String sign = createSign(JSONObject.parseObject(paramStr), "8aef995ff71485dc19b36e35f04c4016"); System.out.println(sign); diff --git a/service/src/main/java/com/hfkj/dao/BsAgentMerMapperExt.java b/service/src/main/java/com/hfkj/dao/BsAgentMerMapperExt.java index 62189a5..4927e1d 100644 --- a/service/src/main/java/com/hfkj/dao/BsAgentMerMapperExt.java +++ b/service/src/main/java/com/hfkj/dao/BsAgentMerMapperExt.java @@ -46,7 +46,6 @@ public interface BsAgentMerMapperExt { " a.merName," + " a.merAddress," + " a.agentName," + - " a.`status`," + " a.createTime," + " GROUP_CONCAT(a.agentStaffName) agentStaff" + " FROM " + diff --git a/service/src/main/java/com/hfkj/model/ReceiveDiscountPkModel.java b/service/src/main/java/com/hfkj/model/ReceiveDiscountPkModel.java new file mode 100644 index 0000000..2bd882b --- /dev/null +++ b/service/src/main/java/com/hfkj/model/ReceiveDiscountPkModel.java @@ -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 discountUserList; +} diff --git a/service/src/main/java/com/hfkj/openapi/model/request/RequestQueryPkDiscountByReqIdModel.java b/service/src/main/java/com/hfkj/openapi/model/request/RequestQueryPkDiscountByStockCodeModel.java similarity index 74% rename from service/src/main/java/com/hfkj/openapi/model/request/RequestQueryPkDiscountByReqIdModel.java rename to service/src/main/java/com/hfkj/openapi/model/request/RequestQueryPkDiscountByStockCodeModel.java index 854350b..478f63a 100644 --- a/service/src/main/java/com/hfkj/openapi/model/request/RequestQueryPkDiscountByReqIdModel.java +++ b/service/src/main/java/com/hfkj/openapi/model/request/RequestQueryPkDiscountByStockCodeModel.java @@ -10,7 +10,7 @@ import javax.validation.constraints.NotBlank; * @date: 2024/9/1 **/ @Data -public class RequestQueryPkDiscountByReqIdModel { +public class RequestQueryPkDiscountByStockCodeModel { /** * 请求id必填项 @@ -25,10 +25,10 @@ public class RequestQueryPkDiscountByReqIdModel { private String appId; /** - * 推送请求id + * 优惠券包库存代码 */ - @NotBlank(message = "推送请求id必填项") - private String pushReqId; + @NotBlank(message = "优惠券包库存代码必填项") + private String discountPkStockCode; /** * 签名参数 diff --git a/service/src/main/java/com/hfkj/openapi/model/request/RequestRefundDiscountModel.java b/service/src/main/java/com/hfkj/openapi/model/request/RequestRefundDiscountModel.java index 25e405f..c09f95f 100644 --- a/service/src/main/java/com/hfkj/openapi/model/request/RequestRefundDiscountModel.java +++ b/service/src/main/java/com/hfkj/openapi/model/request/RequestRefundDiscountModel.java @@ -27,8 +27,8 @@ public class RequestRefundDiscountModel { /** * 推送请求id */ - @NotBlank(message = "推送请求id必填项") - private String pushReqId; + @NotBlank(message = "优惠券库存代码必填项") + private Long discountStockCode; /** * 签名参数 diff --git a/service/src/main/java/com/hfkj/openapi/model/request/RequestRefundPkDiscountModel.java b/service/src/main/java/com/hfkj/openapi/model/request/RequestRefundPkDiscountModel.java index 382d7c7..8b5a3b7 100644 --- a/service/src/main/java/com/hfkj/openapi/model/request/RequestRefundPkDiscountModel.java +++ b/service/src/main/java/com/hfkj/openapi/model/request/RequestRefundPkDiscountModel.java @@ -1,6 +1,7 @@ package com.hfkj.openapi.model.request; import lombok.Data; +import org.hibernate.validator.constraints.Range; import javax.validation.constraints.NotBlank; @@ -25,10 +26,10 @@ public class RequestRefundPkDiscountModel { private String appId; /** - * 推送请求id + * 优惠券包库存代码 */ - @NotBlank(message = "推送请求id必填项") - private String pushReqId; + @NotBlank(message = "优惠券包库存代码必填项") + private String discountPkStockCode; /** * 签名参数 diff --git a/service/src/main/java/com/hfkj/openapi/model/response/ResponsePushDiscountPkModel.java b/service/src/main/java/com/hfkj/openapi/model/response/ResponsePushDiscountPkModel.java index f77a90d..2c7cc4d 100644 --- a/service/src/main/java/com/hfkj/openapi/model/response/ResponsePushDiscountPkModel.java +++ b/service/src/main/java/com/hfkj/openapi/model/response/ResponsePushDiscountPkModel.java @@ -22,15 +22,10 @@ public class ResponsePushDiscountPkModel { */ private String appId; - /** - * 券包编号 - */ - private String discountPkNo; - /** * 优惠券编码列表 */ - private List> codeList; + private List> list; /** * 签名参数 diff --git a/service/src/main/java/com/hfkj/openapi/model/response/ResponseQueryPkDiscountByReqIdModel.java b/service/src/main/java/com/hfkj/openapi/model/response/ResponseQueryPkDiscountByReqIdModel.java index 734c3e3..021a727 100644 --- a/service/src/main/java/com/hfkj/openapi/model/response/ResponseQueryPkDiscountByReqIdModel.java +++ b/service/src/main/java/com/hfkj/openapi/model/response/ResponseQueryPkDiscountByReqIdModel.java @@ -24,14 +24,14 @@ public class ResponseQueryPkDiscountByReqIdModel { private String appId; /** - * 推送请求id + * 优惠券编号 */ - private String pushReqId; + private String discountPkNo; /** - * 优惠券编号 + * 优惠券包库存代码 */ - private String discountPkNo; + private Long discountPkStockCode; /** * 优惠券code列表 diff --git a/service/src/main/java/com/hfkj/service/discount/BsDiscountPkStockBatchService.java b/service/src/main/java/com/hfkj/service/discount/BsDiscountPkStockBatchService.java index af4157a..f395f4c 100644 --- a/service/src/main/java/com/hfkj/service/discount/BsDiscountPkStockBatchService.java +++ b/service/src/main/java/com/hfkj/service/discount/BsDiscountPkStockBatchService.java @@ -27,6 +27,12 @@ public interface BsDiscountPkStockBatchService { */ void addStock(String discountPkNo,Integer stockCount); + /** + * 回收优惠券包 + * @param stockCodeId 库存id + */ + void recycle(Long stockCodeId); + /** * 查询详情 * @param batchNo diff --git a/service/src/main/java/com/hfkj/service/discount/BsDiscountPkStockCodeService.java b/service/src/main/java/com/hfkj/service/discount/BsDiscountPkStockCodeService.java index a5cec6c..de18abb 100644 --- a/service/src/main/java/com/hfkj/service/discount/BsDiscountPkStockCodeService.java +++ b/service/src/main/java/com/hfkj/service/discount/BsDiscountPkStockCodeService.java @@ -32,6 +32,12 @@ public interface BsDiscountPkStockCodeService { */ List getAssignCodeList(String discountPkNo, Integer number); + /** + * 查询详情 + * @param stockId 库存id + * @return + */ + BsDiscountPkStockCode getDetail(Long stockId); /** * 查询列表 * @param param diff --git a/service/src/main/java/com/hfkj/service/discount/BsDiscountStockCodeService.java b/service/src/main/java/com/hfkj/service/discount/BsDiscountStockCodeService.java index 958c772..a45fccf 100644 --- a/service/src/main/java/com/hfkj/service/discount/BsDiscountStockCodeService.java +++ b/service/src/main/java/com/hfkj/service/discount/BsDiscountStockCodeService.java @@ -24,6 +24,12 @@ public interface BsDiscountStockCodeService { */ void update(BsDiscountStockCode data); + /** + * 回收优惠券 + * @param stockCodeId + */ + void recycle(Long stockCodeId); + /** * 查询详情 * @param id @@ -38,6 +44,13 @@ public interface BsDiscountStockCodeService { */ List getAssignCodeList(String discountNo, Integer number); + /** + * 查询优惠券库存id + * @param + * @return + */ + List getCodeListByPkStockId(Long discountPkStockId); + /** * 查询列表 * @param param diff --git a/service/src/main/java/com/hfkj/service/discount/BsDiscountUserService.java b/service/src/main/java/com/hfkj/service/discount/BsDiscountUserService.java index 95ec4c8..baab5cd 100644 --- a/service/src/main/java/com/hfkj/service/discount/BsDiscountUserService.java +++ b/service/src/main/java/com/hfkj/service/discount/BsDiscountUserService.java @@ -1,8 +1,8 @@ package com.hfkj.service.discount; -import com.hfkj.entity.BsDiscount; import com.hfkj.entity.BsDiscountUser; import com.hfkj.model.DiscountUserModel; +import com.hfkj.model.ReceiveDiscountPkModel; import com.hfkj.sysenum.discount.DiscountStockCodeObtainTypeEnum; import java.util.List; @@ -39,7 +39,7 @@ public interface BsDiscountUserService { * @param agentAppid * @return */ - List receivePk(String discountPkNo, Integer number, DiscountStockCodeObtainTypeEnum obtainType, String userPhone, String agentAppid); + List receivePk(String discountPkNo, Integer number, DiscountStockCodeObtainTypeEnum obtainType, String userPhone, String agentAppid); /** * 使用优惠券 diff --git a/service/src/main/java/com/hfkj/service/discount/impl/BsDiscountPkStockBatchServiceImpl.java b/service/src/main/java/com/hfkj/service/discount/impl/BsDiscountPkStockBatchServiceImpl.java index dcc99bf..40b430a 100644 --- a/service/src/main/java/com/hfkj/service/discount/impl/BsDiscountPkStockBatchServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/discount/impl/BsDiscountPkStockBatchServiceImpl.java @@ -6,11 +6,14 @@ import com.hfkj.common.exception.SysCode; import com.hfkj.dao.BsDiscountPkStockBatchMapper; import com.hfkj.entity.*; import com.hfkj.service.discount.*; +import com.hfkj.sysenum.discount.DiscountPkStatusEnum; import com.hfkj.sysenum.discount.DiscountPkStockCodeStatusEnum; import com.hfkj.sysenum.discount.DiscountStockCodeStatusEnum; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.ArrayList; @@ -31,6 +34,8 @@ public class BsDiscountPkStockBatchServiceImpl implements BsDiscountPkStockBatch private BsDiscountPkService discountPkService; @Resource private BsDiscountPkStockCodeService discountPkStockCodeService; + @Resource + private BsDiscountStockCodeService discountStockCodeService; @Override public void editData(BsDiscountPkStockBatch data) { @@ -84,6 +89,35 @@ public class BsDiscountPkStockBatchServiceImpl implements BsDiscountPkStockBatch 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 discountStockCodeList = discountStockCodeService.getCodeListByPkStockId(pkStockCode.getId()); + for (BsDiscountStockCode discountStockCode : discountStockCodeList) { + if (discountStockCode.getStatus().equals(DiscountStockCodeStatusEnum.status2.getCode())) { + // 退回优惠券 + discountStockCodeService.recycle(discountStockCode.getId()); + } + } + } + @Override public BsDiscountPkStockBatch getStockBatchDetail(String batchNo) { BsDiscountPkStockBatchExample example = new BsDiscountPkStockBatchExample(); diff --git a/service/src/main/java/com/hfkj/service/discount/impl/BsDiscountPkStockCodeServiceImpl.java b/service/src/main/java/com/hfkj/service/discount/impl/BsDiscountPkStockCodeServiceImpl.java index 54f505d..0e391d5 100644 --- a/service/src/main/java/com/hfkj/service/discount/impl/BsDiscountPkStockCodeServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/discount/impl/BsDiscountPkStockCodeServiceImpl.java @@ -40,7 +40,7 @@ public class BsDiscountPkStockCodeServiceImpl implements BsDiscountPkStockCodeSe @Override public void update(BsDiscountPkStockCode data) { data.setUpdateTime(new Date()); - discountPkStockCodeMapper.updateByPrimaryKeySelective(data); + discountPkStockCodeMapper.updateByPrimaryKey(data); } @Override @@ -54,11 +54,16 @@ public class BsDiscountPkStockCodeServiceImpl implements BsDiscountPkStockCodeSe PageInfo pageInfo = new PageInfo<>(discountPkStockCodeMapper.selectByExample(example)); if (pageInfo.getList().size() != number) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券库存不足"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券包库存不足"); } return pageInfo.getList(); } + @Override + public BsDiscountPkStockCode getDetail(Long stockId) { + return discountPkStockCodeMapper.selectByPrimaryKey(stockId); + } + @Override public List getCodeList(Map param) { BsDiscountPkStockCodeExample example = new BsDiscountPkStockCodeExample(); diff --git a/service/src/main/java/com/hfkj/service/discount/impl/BsDiscountStockCodeServiceImpl.java b/service/src/main/java/com/hfkj/service/discount/impl/BsDiscountStockCodeServiceImpl.java index a83b6c9..e42e309 100644 --- a/service/src/main/java/com/hfkj/service/discount/impl/BsDiscountStockCodeServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/discount/impl/BsDiscountStockCodeServiceImpl.java @@ -8,11 +8,16 @@ import com.hfkj.common.exception.SysCode; import com.hfkj.dao.BsDiscountStockCodeMapper; import com.hfkj.entity.BsDiscountStockCode; import com.hfkj.entity.BsDiscountStockCodeExample; +import com.hfkj.entity.BsDiscountUser; import com.hfkj.service.discount.BsDiscountStockCodeService; +import com.hfkj.service.discount.BsDiscountUserService; import com.hfkj.sysenum.discount.DiscountStockCodeStatusEnum; +import com.hfkj.sysenum.discount.DiscountUserStatusEnum; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.Date; @@ -29,7 +34,8 @@ public class BsDiscountStockCodeServiceImpl implements BsDiscountStockCodeServic @Resource private BsDiscountStockCodeMapper discountStockCodeMapper; - + @Resource + private BsDiscountUserService discountUserService; @Override public void insertList(List codeList) { discountStockCodeMapper.insertList(codeList); @@ -41,6 +47,33 @@ public class BsDiscountStockCodeServiceImpl implements BsDiscountStockCodeServic 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 public BsDiscountStockCode getDetail(Long id) { return discountStockCodeMapper.selectByPrimaryKey(id); @@ -62,6 +95,16 @@ public class BsDiscountStockCodeServiceImpl implements BsDiscountStockCodeServic return pageInfo.getList(); } + @Override + public List getCodeListByPkStockId(Long discountPkStockId) { + BsDiscountStockCodeExample example = new BsDiscountStockCodeExample(); + example.createCriteria() + .andStatusNotEqualTo(DiscountStockCodeStatusEnum.status0.getCode()) + .andDiscountPkStockCodeEqualTo(discountPkStockId); + example.setOrderByClause("id desc"); + return discountStockCodeMapper.selectByExample(example); + } + @Override public List getCodeList(Map param) { BsDiscountStockCodeExample example = new BsDiscountStockCodeExample(); diff --git a/service/src/main/java/com/hfkj/service/discount/impl/BsDiscountUserServiceImpl.java b/service/src/main/java/com/hfkj/service/discount/impl/BsDiscountUserServiceImpl.java index c797bd6..2df4af5 100644 --- a/service/src/main/java/com/hfkj/service/discount/impl/BsDiscountUserServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/discount/impl/BsDiscountUserServiceImpl.java @@ -7,6 +7,7 @@ import com.hfkj.common.exception.SysCode; import com.hfkj.dao.BsDiscountUserMapper; import com.hfkj.entity.*; import com.hfkj.model.DiscountUserModel; +import com.hfkj.model.ReceiveDiscountPkModel; import com.hfkj.service.discount.*; import com.hfkj.service.user.BsUserService; import com.hfkj.sysenum.discount.*; @@ -113,6 +114,7 @@ public class BsDiscountUserServiceImpl implements BsDiscountUserService { discountUser.setDiscountNo(discount.getDiscountNo()); discountUser.setDiscountName(discount.getDiscountName()); discountUser.setDiscountType(discount.getDiscountType()); + discountUser.setOverlayDiscount(discount.getOverlayDiscount()); discountUser.setDiscountCondition(discount.getDiscountCondition()); discountUser.setDiscountPrice(discount.getDiscountPrice()); discountUser.setDiscountStockCode(discountStockCode.getId()); @@ -159,11 +161,13 @@ public class BsDiscountUserServiceImpl implements BsDiscountUserService { @Override @Transactional(propagation= Propagation.REQUIRED) - public List receivePk(String discountPkNo, Integer number, DiscountStockCodeObtainTypeEnum obtainType, String userPhone, String agentAppid) { + public List receivePk(String discountPkNo, Integer number, DiscountStockCodeObtainTypeEnum obtainType, String userPhone, String agentAppid) { // 锁编号 String lockKey = RECEIVE_DISCOUNT_PK_LOCK_KEY+"_"+discountPkNo; // 获取锁 Boolean lock = redisTemplate.opsForValue().setIfAbsent(lockKey, ""); + + List list = new LinkedList<>(); if (Boolean.TRUE.equals(lock)) { try { // 锁超时时间 10秒 @@ -184,12 +188,12 @@ public class BsDiscountUserServiceImpl implements BsDiscountUserService { other.put("agentAppid", agentAppid); user = userService.register(userPhone, other); } - - List receiveList = new ArrayList<>(); - // 优惠券包库存编码 List codeList = discountPkStockCodeService.getAssignCodeList(discountPkNo, number); for (BsDiscountPkStockCode code : codeList) { + // 库存领取数据 + List receiveList = new ArrayList<>(); + code.setObtainType(obtainType.getCode()); code.setObtainTime(new Date()); code.setReceiveMerUserId(user.getId()); @@ -207,7 +211,7 @@ public class BsDiscountUserServiceImpl implements BsDiscountUserService { // 优惠券库存编码 BsDiscountStockCode discountStockCode = discountStockCodeService.getDetail(discountUser.getDiscountStockCode()); if (discountStockCode != null) { - discountStockCode.setDiscountPkStockCode(discountStockCode.getId()); + discountStockCode.setDiscountPkStockCode(code.getId()); discountStockCode.setDiscountPkId(discountPk.getId()); discountStockCode.setDiscountPkNo(discountPk.getDiscountPkNo()); discountStockCode.setDiscountPkName(discountPk.getDiscountPkName()); @@ -216,8 +220,15 @@ public class BsDiscountUserServiceImpl implements BsDiscountUserService { } receiveList.addAll(discountUsers); } + + ReceiveDiscountPkModel receiveDiscountPkModel = new ReceiveDiscountPkModel(); + receiveDiscountPkModel.setDiscountPkNo(discountPkNo); + receiveDiscountPkModel.setDiscountPkStockCode(code.getId()); + receiveDiscountPkModel.setPhone(userPhone); + receiveDiscountPkModel.setDiscountUserList(receiveList); + list.add(receiveDiscountPkModel); } - return receiveList; + return list; } catch (BaseException e) { // 释放锁 redisTemplate.delete(lockKey); diff --git a/service/src/main/java/com/hfkj/service/gas/impl/BsGasServiceImpl.java b/service/src/main/java/com/hfkj/service/gas/impl/BsGasServiceImpl.java index fb3a8d3..d20b196 100644 --- a/service/src/main/java/com/hfkj/service/gas/impl/BsGasServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/gas/impl/BsGasServiceImpl.java @@ -78,29 +78,32 @@ public class BsGasServiceImpl implements BsGasService { BigDecimal discount = new BigDecimal("100"); BigDecimal serviceFeeRate = new BigDecimal("0"); - // 没有使用优惠券,可以享受油价优惠 - if (userDiscountId == null) { - if (agentMerId != null) { - // 查询代理价格 - BsAgentPrice agentPrice = agentPriceService.getDetail(agentMerId, oilNo); - if (agentPrice != null) { - discount = agentPrice.getPriceRate(); - serviceFeeRate = agentPrice.getServiceFeeRate(); - } - } else { - // 查询平台价格 - BsAgentPrice agentPrice = agentPriceService.getDetail(AgentPriceTypeEnum.type1, merNo, oilNo); - if (agentPrice != null) { - discount = agentPrice.getPriceRate(); - serviceFeeRate = agentPrice.getServiceFeeRate(); - } + if (agentMerId != null) { + // 查询代理价格 + BsAgentPrice agentPrice = agentPriceService.getDetail(agentMerId, oilNo); + if (agentPrice != null) { + discount = agentPrice.getPriceRate(); + serviceFeeRate = agentPrice.getServiceFeeRate(); } } else { + // 查询平台价格 + BsAgentPrice agentPrice = agentPriceService.getDetail(AgentPriceTypeEnum.type1, merNo, oilNo); + if (agentPrice != null) { + discount = agentPrice.getPriceRate(); + serviceFeeRate = agentPrice.getServiceFeeRate(); + } + } + + if (userDiscountId != null) { // 查询用户优惠券 discountUser = discountUserService.getDetail(userDiscountId); if (discountUser == null) { 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); if (agentPrice != null) { @@ -141,13 +144,12 @@ public class BsGasServiceImpl implements BsGasService { BigDecimal gasStationDrop = gasOilPrice.getGasStationDrop(); // 油站优惠价 BigDecimal priceVip = gasOilPrice.getPriceVip(); - if (discountUser != null && !discountUser.getOverlayDiscount()) { - // 优惠券与油价不叠加 - priceVip = priceGun; - } - // 嗨森逛平台价 油站优惠价 * 折扣 BigDecimal pricePlatform = priceVip.multiply(discount).setScale(2, BigDecimal.ROUND_HALF_UP); + if (discountUser != null && discountUser.getOverlayDiscount().equals(false)) { + // 优惠券与油价不叠加 + pricePlatform = priceGun; + } // 加油金额 payPriceModel.setOilingPrice(refuelPrice); diff --git a/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java b/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java index b06541d..d1e0ea1 100644 --- a/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java @@ -175,6 +175,9 @@ public class BsOrderServiceImpl implements BsOrderService { order.setProductTotalPrice(productTotalPrice); 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.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() .add(new BigDecimal(childOrder.getIntegralDiscountPrice().toString()).divide(new BigDecimal("100"))) ); - childOrder.setProductActualPrice(childOrder.getProductTotalPrice().subtract(childOrder.getTotalDeductionPrice())); + if (!childOrder.getProductType().equals(OrderChildProductTypeEnum.type1.getCode())) { + childOrder.setProductActualPrice(childOrder.getProductTotalPrice().subtract(childOrder.getTotalDeductionPrice())); + } orderChildService.editData(childOrder); } // 订单入库