|
|
|
@ -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 ==========="); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|