From 446f394428bbf374cfa5b5c88a559c97ae999bad Mon Sep 17 00:00:00 2001 From: eason Date: Fri, 13 Jul 2018 09:47:08 +0800 Subject: [PATCH] fix encourage --- .../core/impls/EncourageUseProcessor.java | 46 ++++++++++++++----- .../web/EncourageMoneyController.java | 23 +++++++++- 2 files changed, 57 insertions(+), 12 deletions(-) diff --git a/src/main/java/au/com/royalpay/payment/manage/customers/core/impls/EncourageUseProcessor.java b/src/main/java/au/com/royalpay/payment/manage/customers/core/impls/EncourageUseProcessor.java index c6aa8a30b..b1e705055 100644 --- a/src/main/java/au/com/royalpay/payment/manage/customers/core/impls/EncourageUseProcessor.java +++ b/src/main/java/au/com/royalpay/payment/manage/customers/core/impls/EncourageUseProcessor.java @@ -7,6 +7,7 @@ import java.util.List; import javax.annotation.Resource; +import au.com.royalpay.payment.manage.mappers.system.ManagerCustomerRelationAlipayMapper; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.RandomUtils; import org.apache.commons.lang3.time.DateFormatUtils; @@ -62,6 +63,8 @@ public class EncourageUseProcessor implements Ordered, EncourageService { private ManagerMapper managerMapper; @Resource private OrderMapper orderMapper; + @Resource + private ManagerCustomerRelationAlipayMapper managerCustomerRelationAlipayMapper; @Override public int getOrder() { @@ -76,6 +79,7 @@ public class EncourageUseProcessor implements Ordered, EncourageService { @Override public JSONObject takeEncourageMoney(String orderId, String visitorOpenId) { + logger.info("=====takeEncourageMoney+"+orderId); JSONObject config = currentEncourageConfig(); if (config != null) { if (customerEncourageMoneyAccessLogMapper.findByOrderId(orderId) != null) { @@ -88,6 +92,7 @@ public class EncourageUseProcessor implements Ordered, EncourageService { return new JSONObject(); } JSONObject order = orderMapper.find(orderId); + String channel = order.getString("channel"); String openId = order.getString("customer_id"); Date tradeDate = DateUtils.truncate(order.getDate("create_time"), Calendar.DATE); if (tradeDate.before(config.getDate("from_date")) || !tradeDate.before(config.getDate("to_date"))) { @@ -102,21 +107,40 @@ public class EncourageUseProcessor implements Ordered, EncourageService { logger.debug("测试模式,不是管理员"); return new JSONObject(); } + + JSONObject member = customerMembershipMapper.findByPaymentOpenId(openId); if (member == null) { member = new JSONObject(); - JSONObject relation = customerMapper.findCustomerByOpenId(openId); - if (relation == null) { - logger.debug("用户关系不存在"); - return new JSONObject(); + if ("Wechat".equals(channel)){ + JSONObject relation = customerMapper.findCustomerByOpenId(openId); + if (relation == null) { + logger.debug("用户关系不存在"); + return new JSONObject(); + } + member.put("payment_openid", openId); + member.put("kanga_openid", relation.getString("kanga_openid")); + member.put("redpack_openid", relation.getString("redpack_openid")); + member.put("attend_time", new Date()); + member.put("member_point", -1); + member.put("encourage_balance", 0); + customerMembershipMapper.saveMember(member); } - member.put("payment_openid", openId); - member.put("kanga_openid", relation.getString("kanga_openid")); - member.put("redpack_openid", relation.getString("redpack_openid")); - member.put("attend_time", new Date()); - member.put("member_point", -1); - member.put("encourage_balance", 0); - customerMembershipMapper.saveMember(member); + if ("Alipay".equals(channel)){ + JSONObject relation = managerCustomerRelationAlipayMapper.findCustomerByUserId(openId); + if (relation == null) { + logger.debug("用户关系不存在"); + return new JSONObject(); + } + member.put("payment_openid", openId); + member.put("kanga_openid", openId.concat("-kanga_openid")); + member.put("redpack_openid", openId.concat("-redpack_openid")); + member.put("attend_time", new Date()); + member.put("member_point", -1); + member.put("encourage_balance", 0); + customerMembershipMapper.saveMember(member); + } + } String memberId = member.getString("member_id"); int usedOrders = customerEncourageMoneyAccessLogMapper.countOrders(memberId, new Date()); diff --git a/src/main/java/au/com/royalpay/payment/manage/customers/web/EncourageMoneyController.java b/src/main/java/au/com/royalpay/payment/manage/customers/web/EncourageMoneyController.java index 6aa15d077..841bc9b33 100644 --- a/src/main/java/au/com/royalpay/payment/manage/customers/web/EncourageMoneyController.java +++ b/src/main/java/au/com/royalpay/payment/manage/customers/web/EncourageMoneyController.java @@ -20,13 +20,34 @@ public class EncourageMoneyController { private EncourageService encourageService; @RequestMapping(value = "/orders/{orderId}", method = RequestMethod.PUT) - public JSONObject takeEncourageMoney(@PathVariable String orderId, @ModelAttribute(CommonConsts.WECHATINFO) JSONObject wxUser) { + public String takeEncourageMoney(@PathVariable String orderId,@RequestHeader("User-Agent") String ua) { + ua = ua.toLowerCase(); + if (ua.contains("micromessenger")) { + return "redirect:/act/encourage_money/orders/" + orderId + "/wechat"; + } + if (ua.contains("alipayclient")) { + return "redirect:/act/encourage_money/orders/" + orderId + "/alipay"; + } + return null; + } + + + @RequestMapping(value = "/orders/{orderId}/wechat", method = RequestMethod.PUT) + public JSONObject takeEncourageMoneyWeChat(@PathVariable String orderId, @ModelAttribute(CommonConsts.WECHATINFO) JSONObject wxUser) { if (wxUser == null) { return new JSONObject(); } return encourageService.takeEncourageMoney(orderId, wxUser.getString("openid")); } + @RequestMapping(value = "/orders/{orderId}/alipay", method = RequestMethod.PUT) + public JSONObject takeEncourageMoneyAlipay(@PathVariable String orderId, @ModelAttribute(CommonConsts.ALIUSER) JSONObject alipayInfo) { + if (alipayInfo == null) { + return new JSONObject(); + } + return encourageService.takeEncourageMoney(orderId, alipayInfo.getString("user_id")); + } + @RequestMapping(value = "/orders/{orderId}/crit", method = RequestMethod.PUT) public JSONObject takeEncourageMoneyCrit(@PathVariable String orderId) { return encourageService.doubleEncourageMoney(orderId);