From 331f4a39e1bf8223fa6d304a7bc850716f920ba5 Mon Sep 17 00:00:00 2001 From: qyhdd Date: Wed, 16 Aug 2023 13:11:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=8E=B0=E9=87=91=E5=8D=B7?= =?UTF-8?q?=EF=BC=8C=E5=9B=9E=E8=B0=83=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/YunmeiServiceImpl.java | 117 ++++++++++++++---- .../com/cyjd/rights/config/YunmeiConfig.java | 2 +- 2 files changed, 91 insertions(+), 28 deletions(-) diff --git a/rights-server/src/main/java/com/cyjd/rights/business/service/impl/YunmeiServiceImpl.java b/rights-server/src/main/java/com/cyjd/rights/business/service/impl/YunmeiServiceImpl.java index 8b59daa..37cfbf6 100644 --- a/rights-server/src/main/java/com/cyjd/rights/business/service/impl/YunmeiServiceImpl.java +++ b/rights-server/src/main/java/com/cyjd/rights/business/service/impl/YunmeiServiceImpl.java @@ -101,7 +101,12 @@ public class YunmeiServiceImpl implements YunmeiService { @Override public JSONObject directBuyOrder(DirectBuyOrderDto params) { - JSONObject resJSON = checkQualification(params.getChargeAccountNumber()); + String type = "会员权益"; //权益类型 会员类 + //检查是否有领取资格 + if (10000153==params.getSkuId()) { //如果产品Id是10000153说明领取的是饿了么卷 + type = "现金卷"; //现金卷 + } + JSONObject resJSON = checkQualification(params.getChargeAccountNumber(), type); if (resJSON.getString("code").equals("000000")) { long timeMillis = System.currentTimeMillis(); String orderId = System.currentTimeMillis() + ""; @@ -123,6 +128,7 @@ public class YunmeiServiceImpl implements YunmeiService { map.put("notify_url", yunmeiConfig.getNotifyUrl()); map.put("biz_content", bizContent); map.put("sign", sign); + //发送请求进行领取 String res = HttpUtils.sendPostJSON(yunmeiConfig.getUrl() + YunmeiConstant.CREATE_ORDER, JSONObject.toJSONString(map)); JSONObject result = null; RightsOrderEntity rightsOrderEntity = new RightsOrderEntity(); @@ -131,7 +137,7 @@ public class YunmeiServiceImpl implements YunmeiService { rightsOrderEntity.setLinkId(1059); rightsOrderEntity.setLinkName("推广链接"); rightsOrderEntity.setProductNumber(params.getSkuId().toString()); - rightsOrderEntity.setRightsType("会员权益"); + rightsOrderEntity.setRightsType(type); rightsOrderEntity.setStatus(0); rightsOrderEntity.setMobile(params.getChargeAccountNumber()); if (!Objects.equals(res, "")) { @@ -153,7 +159,7 @@ public class YunmeiServiceImpl implements YunmeiService { rightsOrderEntity.setStatus(2); //只是下单成功最后以回调为准 rightsOrderService.save(rightsOrderEntity); JSONObject dataJSON = result.getJSONObject("data"); - dataJSON.put("code","000000"); + dataJSON.put("code", "000000"); return dataJSON; } else { @@ -171,11 +177,13 @@ public class YunmeiServiceImpl implements YunmeiService { } //检查是否有领取资格 - private JSONObject checkQualification(String mobile) { + private JSONObject checkQualification(String mobile, String type) { JSONObject resJSON = new JSONObject(); String code = "10026"; String reason = "暂无领取资格"; - AliPayOrderEntity aliPayOrderEntity = aliPayOrderService.getOne(new QueryWrapper().eq("mobile", mobile).eq("status",1).select("mobile,order_time").orderByDesc("order_time")); + AliPayOrderEntity aliPayOrderEntity = aliPayOrderService.getOne(new QueryWrapper() + .eq("mobile", mobile).eq("status", 1) + .select("mobile,order_time").orderByDesc("order_time")); if (aliPayOrderEntity == null) { //如果没有支付记录说明没有领取资格 code = "10024"; reason = "暂无支付订单"; @@ -183,27 +191,13 @@ public class YunmeiServiceImpl implements YunmeiService { resJSON.put("reason", reason); return resJSON; } - if (isWithin31Days(aliPayOrderEntity.getOrderTime())) { //如果支付记录在31天内说明满足条件 - //如果有支付记录查询是否31天内有过领取记录 - RightsOrderEntity rightsOrder = rightsOrderService.getOne(new QueryWrapper().eq("mobile", mobile).select("mobile,order_time").orderByDesc("order_time")); - if (rightsOrder == null) { //如果有领取记录说明可以领取 - code = "000000"; - reason = "可以领取"; - resJSON.put("code", code); - resJSON.put("reason", reason); + if (isWithinDays(aliPayOrderEntity.getOrderTime(), 31)) { //如果支付记录在31天内说明满足条件 + if ("会员权益".equals(type)) { + resJSON = checkMonthVipRightsOrder(mobile); return resJSON; } - if (isWithin31Days(rightsOrder.getOrderTime())) { //如果在31天已经领取过就不能再次领取 - code = "10025"; - reason = "已经领取过了"; - resJSON.put("code", code); - resJSON.put("reason", reason); - return resJSON; - }else { - code = "000000"; - reason = "可以领取"; - resJSON.put("code", code); - resJSON.put("reason", reason); + if ("现金卷".equals(type)) { + resJSON = checkCashRollVipRightsOrder(mobile); return resJSON; } } @@ -214,14 +208,83 @@ public class YunmeiServiceImpl implements YunmeiService { } - public static boolean isWithin31Days(LocalDateTime date) { + //检查包月会员类的产品是否有领取的权限 + private JSONObject checkMonthVipRightsOrder(String mobile) { + JSONObject resJSON = new JSONObject(); + String code; + String reason; + //如果有支付记录查询是否31天内有过领取记录 + RightsOrderEntity rightsOrder = rightsOrderService.getOne(new QueryWrapper() + .eq("mobile", mobile).eq("rights_type", "会员权益") + .select("mobile,order_time").orderByDesc("order_time")); + if (rightsOrder == null) { //如果没有领取记录说明可以领取 + code = "000000"; + reason = "可以领取"; + resJSON.put("code", code); + resJSON.put("reason", reason); + return resJSON; + } + if (isWithinDays(rightsOrder.getOrderTime(), 31)) { //如果在31天已经领取过就不能再次领取 + code = "10025"; + reason = "已经领取过了"; + } else { + code = "000000"; + reason = "可以领取"; + } + resJSON.put("code", code); + resJSON.put("reason", reason); + return resJSON; + } + + //检查包月会员类的产品是否有领取的权限 + private JSONObject checkCashRollVipRightsOrder(String mobile) { + JSONObject resJSON = new JSONObject(); + String code = "10026"; + String reason = "暂无领取资格"; + //如果有支付记录查询是否31天内有过领取记录 + RightsOrderEntity rightsOrder = rightsOrderService.getOne(new QueryWrapper() + .eq("mobile", mobile).eq("rights_type", "现金卷") + .select("mobile,order_time").orderByDesc("order_time")); + if (rightsOrder == null) { //如果没有领取记录说明可以领取 + code = "000000"; + reason = "可以领取"; + resJSON.put("code", code); + resJSON.put("reason", reason); + return resJSON; + } + if (isWithinDays(rightsOrder.getOrderTime(), 31)) { //如果在31天已经领取过就不能再次领取 + code = "10025"; + reason = "已经领取过了"; + resJSON.put("code", code); + resJSON.put("reason", reason); + return resJSON; + } + + //最早的一次签约时间要距离现在4个月以内 + AliPaySigningOrderEntity paySigningOrderEntity = aliPaySigningOrderService.getOne(new QueryWrapper() + .eq("mobile", mobile) + .select("mobile,order_time").orderByAsc("order_time")); + if (isWithinDays(paySigningOrderEntity.getOrderTime(), 4 * 31)) { + code = "000000"; + reason = "可以领取"; + resJSON.put("code", code); + resJSON.put("reason", reason); + return resJSON; + } + resJSON.put("code", code); + resJSON.put("reason", reason); + return resJSON; + } + + + public static boolean isWithinDays(LocalDateTime date, int compare_day) { LocalDateTime today = LocalDateTime.now(); long days = ChronoUnit.DAYS.between(date, today); - return days <= 31; + return days <= compare_day; } public static void main(String[] args) { - boolean within31Days = isWithin31Days(LocalDateTime.now().plusDays(-2)); + boolean within31Days = isWithinDays(LocalDateTime.now().plusMonths(-5),4*31); System.out.println(within31Days); } // @Override diff --git a/rights-server/src/main/java/com/cyjd/rights/config/YunmeiConfig.java b/rights-server/src/main/java/com/cyjd/rights/config/YunmeiConfig.java index a839cd0..b4ceb0f 100644 --- a/rights-server/src/main/java/com/cyjd/rights/config/YunmeiConfig.java +++ b/rights-server/src/main/java/com/cyjd/rights/config/YunmeiConfig.java @@ -25,5 +25,5 @@ public class YunmeiConfig { public String version="1.0"; - public String notifyUrl="http://47.114.139.101:8086/yunmei/notifyOrder"; + public String notifyUrl="http://182.42.100.27:8086/yunmei/notifyOrder"; }