提交代码

pre
胡锐 1 week 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.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<BsDiscountUser> codeDataList = discountUserService.receivePk(
List<ReceiveDiscountPkModel> codeDataList = discountUserService.receivePk(
body.getDiscountPkNo(),
body.getNumber(),
DiscountStockCodeObtainTypeEnum.type4, body.getPhone(),
@ -218,7 +207,14 @@ public class BsDiscountController {
);
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<>();
codeMap.put("discountNo", discountUser.getDiscountNo());
codeMap.put("phone", discountUser.getUserPhone());
@ -226,13 +222,15 @@ public class BsDiscountController {
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);
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, "未找到推送请求");
// 查询库存code
BsDiscountPkStockCode stockCode = discountPkStockCodeService.getDetail(Long.parseLong(body.getDiscountPkStockCode()));
if (stockCode == null) {
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.COMMON_ERROR, "未找到code");
}
if (!apiLogWithBLOBs.getRequestUrl().equals("discount/pushPk")) {
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.COMMON_ERROR, "未找到推送请求");
}
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<BsDiscountStockCode> 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 ===========");
}
}

@ -86,9 +86,11 @@ public class SignatureUtil {
public static void main(String[] args) throws Exception {
String paramStr = "{ \n" +
" \"reqId\": \"cs0007\",\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);

@ -46,7 +46,6 @@ public interface BsAgentMerMapperExt {
" a.merName," +
" a.merAddress," +
" a.agentName," +
" a.`status`," +
" a.createTime," +
" GROUP_CONCAT(a.agentStaffName) agentStaff" +
" 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
**/
@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;
/**
* 签名参数

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

@ -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;
/**
* 签名参数

@ -22,15 +22,10 @@ public class ResponsePushDiscountPkModel {
*/
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;
/**
* 推送请求id
* 优惠券编号
*/
private String pushReqId;
private String discountPkNo;
/**
* 优惠券编号
* 优惠券包库存代码
*/
private String discountPkNo;
private Long discountPkStockCode;
/**
* 优惠券code列表

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

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

@ -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<BsDiscountStockCode> getAssignCodeList(String discountNo, Integer number);
/**
* 查询优惠券库存id
* @param
* @return
*/
List<BsDiscountStockCode> getCodeListByPkStockId(Long discountPkStockId);
/**
* 查询列表
* @param param

@ -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<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.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<BsDiscountStockCode> 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();

@ -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<BsDiscountPkStockCode> 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<BsDiscountPkStockCode> getCodeList(Map<String, Object> param) {
BsDiscountPkStockCodeExample example = new BsDiscountPkStockCodeExample();

@ -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<BsDiscountStockCode> 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<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
public List<BsDiscountStockCode> getCodeList(Map<String, Object> param) {
BsDiscountStockCodeExample example = new BsDiscountStockCodeExample();

@ -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<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;
// 获取锁
Boolean lock = redisTemplate.opsForValue().setIfAbsent(lockKey, "");
List<ReceiveDiscountPkModel> 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<BsDiscountUser> receiveList = new ArrayList<>();
// 优惠券包库存编码
List<BsDiscountPkStockCode> codeList = discountPkStockCodeService.getAssignCodeList(discountPkNo, number);
for (BsDiscountPkStockCode code : codeList) {
// 库存领取数据
List<BsDiscountUser> 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);
}
}
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) {
// 释放锁
redisTemplate.delete(lockKey);

@ -78,8 +78,6 @@ 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);
@ -95,12 +93,17 @@ public class BsGasServiceImpl implements BsGasService {
serviceFeeRate = agentPrice.getServiceFeeRate();
}
}
} else {
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);

@ -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")))
);
if (!childOrder.getProductType().equals(OrderChildProductTypeEnum.type1.getCode())) {
childOrder.setProductActualPrice(childOrder.getProductTotalPrice().subtract(childOrder.getTotalDeductionPrice()));
}
orderChildService.editData(childOrder);
}
// 订单入库

Loading…
Cancel
Save