diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighCouponController.java b/hai-bweb/src/main/java/com/bweb/controller/HighCouponController.java index 8977e0a3..008b1699 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighCouponController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighCouponController.java @@ -152,8 +152,10 @@ public class HighCouponController { salesEndTime.set(Calendar.SECOND, 59); highCoupon.setSalesEndTime(salesEndTime.getTime()); - String setCouponKey = DateUtil.date2String(new Date(), "yyyyMMddHHmmss"); //订单号生成 年月日小时分秒 + 5位随机数 - highCoupon.setCouponKey(setCouponKey); + if (StringUtils.isBlank(highCoupon.getCouponKey())) { + String setCouponKey = DateUtil.date2String(new Date(), "yyyyMMddHHmmss"); //订单号生成 年月日小时分秒 + 5位随机数 + highCoupon.setCouponKey(setCouponKey); + } highCoupon.setCompanyId(merchant.getCompanyId()); highCoupon.setOperatorId(userInfoModel.getSecUser().getId()); highCoupon.setOperatorName(userInfoModel.getSecUser().getUserName()); @@ -258,6 +260,7 @@ public class HighCouponController { log.error("HighCouponController -> updateCoupon() error!","未找到商户"); throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOF_FOUND, ""); } + coupon.setCouponKey(highCoupon.getCouponKey()); coupon.setCouponSource(highCoupon.getCouponSource()); coupon.setMerchantId(highCoupon.getMerchantId()); coupon.setCouponName(highCoupon.getCouponName()); @@ -307,7 +310,7 @@ public class HighCouponController { } // 中石化 - if (coupon.getCouponSource() != null && coupon.getCouponSource() != 4) { + if (coupon.getCouponSource() != null && (coupon.getCouponSource() != 4 && coupon.getCouponSource() != 5)) { // 根据卡卷查询 销售码库存 if (highCouponCodeService.getStockCountByCoupon(coupon.getId()) == 0) { log.error("HighCouponController -> upShelfApprove() error!","卡卷库存数量错误"); diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighCouponController.java b/hai-cweb/src/main/java/com/cweb/controller/HighCouponController.java index faebbc10..1a9546c4 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighCouponController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighCouponController.java @@ -1,17 +1,21 @@ package com.cweb.controller; +import com.alibaba.fastjson.JSONObject; +import com.cweb.config.SysConst; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; +import com.hai.common.QRCodeGenerator; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; import com.hai.common.security.SessionObject; import com.hai.common.security.UserCenter; +import com.hai.common.utils.DateUtil; +import com.hai.common.utils.IDGenerator; import com.hai.common.utils.ResponseMsgUtil; -import com.hai.entity.BsCompany; -import com.hai.entity.HighCoupon; -import com.hai.entity.HighUserCoupon; -import com.hai.entity.SecRegion; +import com.hai.config.ChongQingCNPCService; +import com.hai.config.CommonSysConst; +import com.hai.entity.*; import com.hai.model.HighUserCouponModel; import com.hai.model.HighUserModel; import com.hai.model.ResponseData; @@ -27,6 +31,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import java.net.URLEncoder; import java.util.*; /** @@ -56,6 +61,12 @@ public class HighCouponController { @Resource private HighUserCouponService highUserCouponService; + @Resource + private HighCouponCodeOtherService couponCodeOtherService; + + @Resource + private HighOrderService orderService; + @Resource private HighMerchantStoreService highMerchantStoreService; @@ -201,6 +212,58 @@ public class HighCouponController { } } + @RequestMapping(value = "/getVerifyQRCode", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "获取核销二维码") + public ResponseData getVerifyQRCode(@RequestParam(name = "userCouponId", required = true) Long userCouponId) { + try { + // 用户 + HighUserModel userInfoModel = userCenter.getSessionModel(HighUserModel.class); + if (userInfoModel == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "用户信息错误"); + } + + // 查询最新一张可用的卡券 + HighUserCoupon userCoupon = highUserCouponService.getDetailById(userCouponId); + if (userCoupon == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "验证码错误"); + } + if (!userCoupon.getStatus().equals(1)) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "状态异常,无法生成"); + } + if (!userCoupon.getUserId().equals(userInfoModel.getHighUser().getId())) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "用户异常,无法生成"); + } + + HighCouponCodeOther couponCodeOther = couponCodeOtherService.getDetailByCouNo(userCoupon.getQrCodeImg()); + if (couponCodeOther == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到卡券订单"); + } + + HighOrder order = orderService.getOrderById(couponCodeOther.getOrderId()); + if (order == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到交易订单"); + } + + // 类型: 1 贵州中石化 2 重庆中石油 + if (couponCodeOther.getType() != null && couponCodeOther.getType().equals(2)) { + // 获取动态核销码 + JSONObject code = ChongQingCNPCService.getCNPCCheckCode(couponCodeOther.getCouNo(), order.getOrderNo()); + + // 生成二维码 + String qrCodeImgUrl = DateUtil.date2String(new Date(),"yyyyMMddHHmmss") + IDGenerator.nextId(1) +".jpg"; + QRCodeGenerator.generateQRCodeImage(code.getString("checkCode"), 350, 350, SysConst.getSysConfig().getFileUrl()+"/temporary/"+qrCodeImgUrl); + return ResponseMsgUtil.success(qrCodeImgUrl); + } + + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "生成失败"); + + } catch (Exception e) { + log.error("HighCouponController --> getVerifyQRCode() error!", e); + return ResponseMsgUtil.exception(e); + } + } + @RequestMapping(value = "/againReceiveCoupon", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "卡卷过期,再次领取") diff --git a/hai-service/src/main/java/com/hai/config/ChongQingCNPCService.java b/hai-service/src/main/java/com/hai/config/ChongQingCNPCService.java index f39ce9a7..38dd8f38 100644 --- a/hai-service/src/main/java/com/hai/config/ChongQingCNPCService.java +++ b/hai-service/src/main/java/com/hai/config/ChongQingCNPCService.java @@ -128,7 +128,7 @@ public class ChongQingCNPCService { public static void main(String[] args) { //System.out.println(AESTool.Decrypt("A9D356D4614F874586EAF8678C8C3E7D8CD0EEF031ADA44DDAA3B342CE4BBE44F115AABE27324A6A1F049619139A1A889FCA0FB48EB6E1EA4B1B50F041961B2D686FE8B9696C02DF95BA99B342747D67ECC7847646C87993CF924F33C1308829","n2j30jxhl3rhuoci")); - System.out.println(AESTool.Decrypt("12AEA963896A18F78D0AD9A1103BD0C07E5F6ED88477C49F59192296FC59A07CB046D702CFC72522258A3097138B88F6FBDBEA1130F0D2D72F8C7351A6BA6A17DEAF3605450202D746BFCD6B35373A7BCF10101966AB79E118BDE0155B982299A76614DDCB885158A18C1AE672DE3CB912AEA963896A18F78D0AD9A1103BD0C07E5F6ED88477C49F59192296FC59A07CB046D702CFC72522258A3097138B88F6FBDBEA1130F0D2D72F8C7351A6BA6A17DEAF3605450202D746BFCD6B35373A7BCF10101966AB79E118BDE0155B982299A76614DDCB885158A18C1AE672DE3CB9","n2j30jxhl3rhuoci")); + System.out.println(AESTool.Decrypt("FD65F7651FF24F67FCCC2690F03650ABEEEFA7681C9C98A45BF82C7E17776A728B68E6E6C87A4C9F444A6D64CCB025604AC6E8CD4ACB2D2EF266857191370B205FFBAA95958C4801050E3B4AE2057220","n2j30jxhl3rhuoci")); //System.out.println(AESTool.Decrypt("3549AD565800370205265D7518D26E5F40C90A61FDEB5DD73966126A5D25F5E9","5ojldakiz343a6yk")); } } diff --git a/hai-service/src/main/java/com/hai/service/HighCouponAgentService.java b/hai-service/src/main/java/com/hai/service/HighCouponAgentService.java index 198b87f5..8289479e 100644 --- a/hai-service/src/main/java/com/hai/service/HighCouponAgentService.java +++ b/hai-service/src/main/java/com/hai/service/HighCouponAgentService.java @@ -79,7 +79,7 @@ public interface HighCouponAgentService { * @Description 生成二维码 * @Date 2021/4/21 22:35 **/ - Map generateCode(Long couponAgentCodeId,String remark); + Map generateCode(Long couponAgentCodeId,String remark) throws Exception; /** * @Author 胡锐 diff --git a/hai-service/src/main/java/com/hai/service/HighCouponCodeOtherService.java b/hai-service/src/main/java/com/hai/service/HighCouponCodeOtherService.java index 1be265e5..313b3e18 100644 --- a/hai-service/src/main/java/com/hai/service/HighCouponCodeOtherService.java +++ b/hai-service/src/main/java/com/hai/service/HighCouponCodeOtherService.java @@ -21,4 +21,11 @@ public interface HighCouponCodeOtherService { */ HighCouponCodeOther getDetailByCouponAgentCodeId(Long couponAgentCodeId); + /** + * 根据卡券号查询 + * @param couNo + * @return + */ + HighCouponCodeOther getDetailByCouNo(String couNo); + } diff --git a/hai-service/src/main/java/com/hai/service/HighOrderService.java b/hai-service/src/main/java/com/hai/service/HighOrderService.java index bcc36c5c..a5088d21 100644 --- a/hai-service/src/main/java/com/hai/service/HighOrderService.java +++ b/hai-service/src/main/java/com/hai/service/HighOrderService.java @@ -83,6 +83,13 @@ public interface HighOrderService { **/ Integer getUndoneChildOrder(Long orderId); + /** + * 查询交易订单 + * @param orderId + * @return + */ + HighOrder getDetailById(Long orderId); + /** * @Author 胡锐 * @Description 查询子商品 diff --git a/hai-service/src/main/java/com/hai/service/impl/HighCouponAgentServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighCouponAgentServiceImpl.java index 863eeaf8..284f228c 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighCouponAgentServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighCouponAgentServiceImpl.java @@ -9,6 +9,7 @@ import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; import com.hai.common.utils.DateUtil; import com.hai.common.utils.ResponseMsgUtil; +import com.hai.config.ChongQingCNPCService; import com.hai.config.HuiLianTongConfig; import com.hai.config.HuiLianTongUnionCardConfig; import com.hai.dao.*; @@ -292,7 +293,7 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService { @Override @Transactional(propagation= Propagation.REQUIRES_NEW) - public Map generateCode(Long couponAgentCodeId,String remark) { + public Map generateCode(Long couponAgentCodeId,String remark) throws Exception { // 查询卡券销售码 HighCouponAgentCode couponAgentCode = getCodeById(couponAgentCodeId); if (couponAgentCode == null) { @@ -311,6 +312,11 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService { couponAgent.setSalesCount(couponAgent.getSalesCount() + 1); highCouponAgentRelMapper.updateByPrimaryKey(couponAgent); + // 卡券信息 + HighCoupon coupon = highCouponService.getCouponById(couponAgentCode.getCouponId()); + if (coupon == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到卡券"); + } HighCouponCode couponCode = null; if (couponAgentCode.getType() == 1) { @@ -320,6 +326,28 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService { highCouponCodeService.updateCouponCode(couponCode); } + + if (coupon.getCouponSource().equals(5)) { + // 给用户发码 + JSONObject response = ChongQingCNPCService.sendCNPCTicket(coupon.getCouponKey(), couponAgentCode.getCouponCode(), 1, ""); + JSONObject couponDetail = response.getJSONObject("ticketDetail"); + JSONArray codeList = response.getJSONArray("codeList"); + + for (Object data : codeList) { + HighCouponCodeOther couponCodeOther = new HighCouponCodeOther(); + couponCodeOther.setType(2); + couponCodeOther.setCouponAgentCodeId(couponAgentCodeId); + couponCodeOther.setCouTypeCode(couponDetail.getString("requestCode")); + couponCodeOther.setCouNo(String.valueOf(data)); + couponCodeOther.setActiveTime(DateUtil.format(couponDetail.getString("effectiveTime"), "yyyy-MM-dd")); + couponCodeOther.setValidStartDate(DateUtil.format(couponDetail.getString("effectiveTime"), "yyyy-MM-dd")); + couponCodeOther.setValidEndDate(DateUtil.format(couponDetail.getString("expiredDate"), "yyyy-MM-dd")); + couponCodeOther.setStatus(20); + couponCodeOther.setCreateTime(new Date()); + highCouponCodeOtherMapper.insert(couponCodeOther); + } + } + Map map = new HashMap<>(); map.put("couponInfo", highCouponService.getCouponById(couponAgentCode.getCouponId())); map.put("couponCode", couponCode); diff --git a/hai-service/src/main/java/com/hai/service/impl/HighCouponCodeOtherServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighCouponCodeOtherServiceImpl.java index 22090a80..78ed6c7f 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighCouponCodeOtherServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighCouponCodeOtherServiceImpl.java @@ -46,4 +46,15 @@ public class HighCouponCodeOtherServiceImpl implements HighCouponCodeOtherServic } return null; } + + @Override + public HighCouponCodeOther getDetailByCouNo(String couNo) { + HighCouponCodeOtherExample example = new HighCouponCodeOtherExample(); + example.createCriteria().andCouNoEqualTo(couNo); + List list = highCouponCodeOtherMapper.selectByExample(example); + if (list.size() > 0) { + return list.get(0); + } + return null; + } } diff --git a/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java index 18b9bfc6..7b3a3501 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java @@ -417,7 +417,7 @@ public class HighOrderServiceImpl implements HighOrderService { orderPre.setStatus(1); highOrderPreService.insertOrderPre(orderPre); } - // 贵州高速 + // 贵州中石化 if (coupon.getCouponSource() == 4) { Map push = new HashMap<>(); push.put("couTypeCode", coupon.getCouponKey()); @@ -469,6 +469,40 @@ public class HighOrderServiceImpl implements HighOrderService { highUserCouponMapper.insert(highUserCoupon); } } + + // 重庆中石油 + } else if (coupon.getCouponSource() == 5) { + + // 给用户发码 + JSONObject response = ChongQingCNPCService.sendCNPCTicket(coupon.getCouponKey(), highOrder.getOrderNo(), highChildOrder.getSaleCount(), highOrder.getMemPhone()); + JSONObject couponDetail = response.getJSONObject("ticketDetail"); + JSONArray codeList = response.getJSONArray("codeList"); + + for (Object data : codeList) { + HighCouponCodeOther couponCodeOther = new HighCouponCodeOther(); + couponCodeOther.setType(1); + couponCodeOther.setOrderId(highOrder.getId()); + couponCodeOther.setChildOrderId(highChildOrder.getId()); + couponCodeOther.setCouTypeCode(couponDetail.getString("requestCode")); + couponCodeOther.setCouNo(String.valueOf(data)); + couponCodeOther.setActiveTime(DateUtil.format(couponDetail.getString("effectiveTime"), "yyyy-MM-dd")); + couponCodeOther.setValidStartDate(DateUtil.format(couponDetail.getString("effectiveTime"), "yyyy-MM-dd")); + couponCodeOther.setValidEndDate(DateUtil.format(couponDetail.getString("expiredDate"), "yyyy-MM-dd")); + couponCodeOther.setStatus(20); + couponCodeOther.setCreateTime(new Date()); + highCouponCodeOtherMapper.insert(couponCodeOther); + + // 卡卷关联用户 + HighUserCoupon highUserCoupon = new HighUserCoupon(); + highUserCoupon.setMerchantId(coupon.getMerchantId()); + highUserCoupon.setCouponId(coupon.getId()); + highUserCoupon.setUserId(highOrder.getMemId()); + highUserCoupon.setCreateTime(new Date()); + highUserCoupon.setQrCodeImg(couponCodeOther.getCouNo()); + highUserCoupon.setUseEndTime(couponCodeOther.getValidEndDate()); + highUserCoupon.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用 + highUserCouponMapper.insert(highUserCoupon); + } } else { HighCouponCode code = highCouponCodeService.getCouponCodeByOrderId(highChildOrder.getId()); code.setStatus(2); // 状态:1.待销售 2.未使用 3.已使用 99.预支付 @@ -1496,6 +1530,11 @@ public class HighOrderServiceImpl implements HighOrderService { return count; } + @Override + public HighOrder getDetailById(Long orderId) { + return highOrderMapper.selectByPrimaryKey(orderId); + } + @Override public HighChildOrder getChildOrderById(Long childOrderId) { return highChildOrderMapper.selectByPrimaryKey(childOrderId);