From d1be4005f8d7b48bef8ce129de6b125159e91f41 Mon Sep 17 00:00:00 2001 From: kira <164851225@qq.com> Date: Wed, 8 Aug 2018 16:01:43 +0800 Subject: [PATCH] add ctrip active --- .../appclient/core/RetailAppService.java | 4 + .../core/impls/RetailAppServiceImp.java | 25 ++++-- .../appclient/web/RetailAppController.java | 10 +++ .../ctrip/AfterPaymentFinishListener.java | 41 ++++++++++ .../ctrip/RefundFinishedEventListener.java | 46 +++++++++++ .../customers/core/CouponValidateService.java | 6 ++ .../core/impls/CouponValidateServiceImpl.java | 80 ++++++++++++++++++- .../mappers/log/CouponAccuessLogMapper.java | 11 ++- 8 files changed, 211 insertions(+), 12 deletions(-) create mode 100644 src/main/java/au/com/royalpay/payment/manage/apps/events/listeners/ctrip/AfterPaymentFinishListener.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/apps/events/listeners/ctrip/RefundFinishedEventListener.java diff --git a/src/main/java/au/com/royalpay/payment/manage/appclient/core/RetailAppService.java b/src/main/java/au/com/royalpay/payment/manage/appclient/core/RetailAppService.java index c96ee2e82..b59deeae7 100644 --- a/src/main/java/au/com/royalpay/payment/manage/appclient/core/RetailAppService.java +++ b/src/main/java/au/com/royalpay/payment/manage/appclient/core/RetailAppService.java @@ -156,4 +156,8 @@ public interface RetailAppService { JSONObject getRefunds(JSONObject device, AppQueryBean appQueryBean); + JSONObject ctripCheck(JSONObject device); + + JSONObject ctripCouponInfo(JSONObject device,String coupon_id); + } diff --git a/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailAppServiceImp.java b/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailAppServiceImp.java index 90f12b218..d903cad35 100644 --- a/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailAppServiceImp.java +++ b/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailAppServiceImp.java @@ -419,10 +419,10 @@ public class RetailAppServiceImp implements RetailAppService { @Override public JSONObject openimCheck(JSONObject device) { JSONObject account = clientAccountMapper.findById(device.getString("account_id")); - return customerServiceService.checkAndSavePartner(account); + return customerServiceService.checkAndSavePartner(account); } - //暂不使用 + // 暂不使用 @Override public void addUnreadMsg(JSONObject device, JSONObject param) { customerServiceService.addUnreadMsg(param); @@ -432,14 +432,25 @@ public class RetailAppServiceImp implements RetailAppService { public JSONObject getRefunds(JSONObject device, AppQueryBean appQueryBean) { JSONObject appParam = appQueryBean.toParams(); JSONObject param = new JSONObject(); - if(appParam.get("client_ids")==null) { + if (appParam.get("client_ids") == null) { param.put("client_id", device.getIntValue("client_id")); } - param.put("start_time",appParam.getDate("begin")); - param.put("end_time",appParam.getDate("end")); + param.put("start_time", appParam.getDate("begin")); + param.put("end_time", appParam.getDate("end")); return refundService.listUnionAllApply(param, new PageBounds(appQueryBean.getPage(), appQueryBean.getLimit())); } + @Override + public JSONObject ctripCheck(JSONObject deivce) { + return couponVerificationService.ctripCheck(deivce.getIntValue("client_id")); + } + + @Override + public JSONObject ctripCouponInfo(JSONObject device, String coupon_id) { + return couponVerificationService.ctripCouponInfo(coupon_id,device.getIntValue("client_id")); + + } + @Override public void updateClient(JSONObject device, AppClientBean appClientBean) { String clientType = device.getString("client_type"); @@ -1299,8 +1310,8 @@ public class RetailAppServiceImp implements RetailAppService { if (AlipayOnline.containsKey("channel")) { channels.add(AlipayOnline); } - JSONObject Hf = getChannel(clientId,now,"hf"); - if (Hf.containsKey("channel")){ + JSONObject Hf = getChannel(clientId, now, "hf"); + if (Hf.containsKey("channel")) { channels.add(Hf); } res.put("channels", channels); diff --git a/src/main/java/au/com/royalpay/payment/manage/appclient/web/RetailAppController.java b/src/main/java/au/com/royalpay/payment/manage/appclient/web/RetailAppController.java index b31557c8e..1be99c9a8 100644 --- a/src/main/java/au/com/royalpay/payment/manage/appclient/web/RetailAppController.java +++ b/src/main/java/au/com/royalpay/payment/manage/appclient/web/RetailAppController.java @@ -554,4 +554,14 @@ public class RetailAppController { retailAppService.addUnreadMsg(device,param); } + @RequestMapping(value = "/ctrip/check",method = RequestMethod.GET) + public void ctripCheck(@ModelAttribute(RETAIL_DEVICE) JSONObject device) { + retailAppService.ctripCheck(device); + } + + @RequestMapping(value = "/ctrip/coupon/{couponId}",method = RequestMethod.GET) + public void ctripCheck(@ModelAttribute(RETAIL_DEVICE) JSONObject device,@PathVariable String couponId) { + retailAppService.ctripCouponInfo(device,couponId); + } + } diff --git a/src/main/java/au/com/royalpay/payment/manage/apps/events/listeners/ctrip/AfterPaymentFinishListener.java b/src/main/java/au/com/royalpay/payment/manage/apps/events/listeners/ctrip/AfterPaymentFinishListener.java new file mode 100644 index 000000000..4eead5abd --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/apps/events/listeners/ctrip/AfterPaymentFinishListener.java @@ -0,0 +1,41 @@ +package au.com.royalpay.payment.manage.apps.events.listeners.ctrip; + +import au.com.royalpay.payment.core.events.AfterPaymentFinishEvent; +import au.com.royalpay.payment.manage.customers.core.CouponValidateService; +import au.com.royalpay.payment.manage.mappers.log.CouponAccuessLogMapper; + +import com.alibaba.fastjson.JSONObject; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.ApplicationListener; +import org.springframework.stereotype.Service; + +import java.util.List; + +import javax.annotation.Resource; + +/** + * Created by wangning on 17/01/2018. + */ +@Service +public class AfterPaymentFinishListener implements ApplicationListener { + Logger logger = LoggerFactory.getLogger(getClass()); + @Resource + private CouponValidateService couponValidateService; + @Resource + private CouponAccuessLogMapper couponAccuessLogMapper; + + @Override + public void onApplicationEvent(AfterPaymentFinishEvent event) { + JSONObject order = event.getFinishedEvent().getOrder(); + String orderId = order.getString("order_id"); + List accuessCouponLogs = couponAccuessLogMapper.findCouponByOrderId(orderId); + if (accuessCouponLogs != null&&accuessCouponLogs.size()>0) { + JSONObject accuessCouponLog = accuessCouponLogs.get(0); + String couponId = accuessCouponLog.getString("coupon_id"); + couponValidateService.ctripCouponLogNotice(couponId,orderId,order.getString("customer_id")); + logger.info("订单 [" + orderId + "]推送支付成功Ctrip卡券=======>[" + couponId + "]"); + } + } +} \ No newline at end of file diff --git a/src/main/java/au/com/royalpay/payment/manage/apps/events/listeners/ctrip/RefundFinishedEventListener.java b/src/main/java/au/com/royalpay/payment/manage/apps/events/listeners/ctrip/RefundFinishedEventListener.java new file mode 100644 index 000000000..7f8ba9b8b --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/apps/events/listeners/ctrip/RefundFinishedEventListener.java @@ -0,0 +1,46 @@ +package au.com.royalpay.payment.manage.apps.events.listeners.ctrip; + +import au.com.royalpay.payment.core.events.RefundFinishedEvent; +import au.com.royalpay.payment.core.mappers.PmtOrderMapper; +import au.com.royalpay.payment.manage.customers.core.CouponValidateService; +import au.com.royalpay.payment.manage.mappers.log.CouponAccuessLogMapper; + +import com.alibaba.fastjson.JSONObject; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.ApplicationListener; +import org.springframework.stereotype.Service; + +import java.util.List; + +import javax.annotation.Resource; + +/** + * @author kira + * @date 2018/8/8 + */ +@Service +public class RefundFinishedEventListener implements ApplicationListener { + Logger logger = LoggerFactory.getLogger(getClass()); + @Resource + private PmtOrderMapper orderMapper; + @Resource + private CouponValidateService couponValidateService; + @Resource + private CouponAccuessLogMapper couponAccuessLogMapper; + @Override + public void onApplicationEvent(RefundFinishedEvent event) { + JSONObject refund = event.getRefundOrder(); + JSONObject order = orderMapper.find(refund.getString("order_id")); + String orderId = order.getString("order_id"); + List accuessCouponLogs = couponAccuessLogMapper.findCouponByOrderId(orderId); + if (accuessCouponLogs != null&&accuessCouponLogs.size()>0) { + JSONObject accuessCouponLog = accuessCouponLogs.get(0); + String couponId = accuessCouponLog.getString("coupon_id"); + couponValidateService.ctripCouponLogNotice(couponId,orderId,order.getString("customer_id")); + logger.info("订单 [" + orderId + "]推送退款成功Ctrip卡券=======>[" + couponId + "]"); + } + } + +} diff --git a/src/main/java/au/com/royalpay/payment/manage/customers/core/CouponValidateService.java b/src/main/java/au/com/royalpay/payment/manage/customers/core/CouponValidateService.java index 2412014b7..bbeceeec6 100644 --- a/src/main/java/au/com/royalpay/payment/manage/customers/core/CouponValidateService.java +++ b/src/main/java/au/com/royalpay/payment/manage/customers/core/CouponValidateService.java @@ -15,4 +15,10 @@ public interface CouponValidateService { boolean useCoupon(String couponLogId); JSONObject getPaymentManager(); + + JSONObject ctripCheck(int client_id); + + JSONObject ctripCouponInfo(String coupon_log_id,int client_id); + + JSONObject ctripCouponLogNotice(String coupon_log_id,String order_id,String open_id); } diff --git a/src/main/java/au/com/royalpay/payment/manage/customers/core/impls/CouponValidateServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/customers/core/impls/CouponValidateServiceImpl.java index 1e1e5d3e8..4c9bd25c2 100644 --- a/src/main/java/au/com/royalpay/payment/manage/customers/core/impls/CouponValidateServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/customers/core/impls/CouponValidateServiceImpl.java @@ -2,12 +2,16 @@ package au.com.royalpay.payment.manage.customers.core.impls; import au.com.royalpay.payment.manage.customers.core.CouponValidateService; import au.com.royalpay.payment.manage.mappers.customers.CustomerMembershipMapper; +import au.com.royalpay.payment.manage.merchants.core.ClientManager; import au.com.royalpay.payment.tools.exceptions.BadRequestException; -import cn.yixblog.platform.http.HttpRequestGenerator; -import cn.yixblog.platform.http.HttpRequestResult; +import au.com.royalpay.payment.tools.exceptions.NotFoundException; + import com.alibaba.fastjson.JSONObject; + import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang3.time.DateUtils; +import org.apache.http.NameValuePair; +import org.apache.http.message.BasicNameValuePair; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; @@ -15,8 +19,14 @@ import org.springframework.stereotype.Service; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.util.UriComponentsBuilder; -import javax.annotation.Resource; +import java.util.ArrayList; import java.util.Date; +import java.util.List; + +import javax.annotation.Resource; + +import cn.yixblog.platform.http.HttpRequestGenerator; +import cn.yixblog.platform.http.HttpRequestResult; /** @@ -38,6 +48,8 @@ public class CouponValidateServiceImpl implements CouponValidateService { @Resource private CustomerMembershipMapper customerMembershipMapper; + @Resource + private ClientManager clientManager; @Override public JSONObject getCoupon(JSONObject partner,int page,int limit) { @@ -145,4 +157,66 @@ public class CouponValidateServiceImpl implements CouponValidateService { object.put("managers",customerMembershipMapper.listPaymentManagerByCus()); return object; } + + @Override + public JSONObject ctripCheck(int client_id) { + JSONObject client = clientManager.getClientInfo(client_id); + if(client==null){ + throw new NotFoundException("Merchant Not Found"); + } + String uri = signUrl(UriComponentsBuilder.fromHttpUrl(CUSTOMER_HOST + "coupon/"+client.getString("client_moniker")+"/enableCtrip")); + HttpRequestGenerator gen = new HttpRequestGenerator(uri, RequestMethod.GET); + try { + HttpRequestResult reqResult = gen.execute(); + if (reqResult.isSuccess()) { + return reqResult.getResponseContentJSONObj(); + } + } catch (Exception ignored) { + } + return null; + } + + @Override + public JSONObject ctripCouponInfo(String coupon_id, int client_id) { + JSONObject client = clientManager.getClientInfo(client_id); + if(client==null){ + throw new NotFoundException("Merchant Not Found"); + } + String uri = signUrl(UriComponentsBuilder.fromHttpUrl(CUSTOMER_HOST + "/coupon/"+coupon_id+"/couponLogInfo")); + HttpRequestGenerator gen = new HttpRequestGenerator(uri, RequestMethod.POST); + gen.addQueryString("client_moniker",client.getString("client_moniker")); + try { + HttpRequestResult reqResult = gen.execute(); + if (reqResult.isSuccess()) { + return reqResult.getResponseContentJSONObj(); + } + } catch (Exception ignored) { + } + return null; + } + + @Override + public JSONObject ctripCouponLogNotice(String coupon_id, String order_id, String open_id) { + String uri = signUrl(UriComponentsBuilder.fromHttpUrl(CUSTOMER_HOST + "coupon/"+coupon_id+"/addCtripCouponLog")); + HttpRequestGenerator gen = new HttpRequestGenerator(uri, RequestMethod.POST); + List params = new ArrayList<>(); + params.add(new BasicNameValuePair("order_id", order_id)); + params.add(new BasicNameValuePair("openid", open_id)); + gen.setFormStringEntity(params); + try { + HttpRequestResult reqResult = gen.execute(); + if (reqResult.isSuccess()) { + return reqResult.getResponseContentJSONObj(); + } + } catch (Exception ignored) { + } + return null; + } + + private String signUrl(UriComponentsBuilder uriComponentsBuilder) { + String timestamp = System.currentTimeMillis() + ""; + String base = CUSTOMER_APP_ID + timestamp + CUSTOMER_AUTH_CODE; + String sign = DigestUtils.sha256Hex(base).toLowerCase(); + return uriComponentsBuilder.queryParam("appid", CUSTOMER_APP_ID).queryParam("timestamp", timestamp).queryParam("sign", sign).toUriString(); + } } diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/log/CouponAccuessLogMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/log/CouponAccuessLogMapper.java index 21ca8807f..e4e593ccc 100644 --- a/src/main/java/au/com/royalpay/payment/manage/mappers/log/CouponAccuessLogMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/log/CouponAccuessLogMapper.java @@ -1,11 +1,15 @@ package au.com.royalpay.payment.manage.mappers.log; +import java.util.List; + +import org.apache.ibatis.annotations.Param; + +import com.alibaba.fastjson.JSONObject; + import cn.yixblog.support.mybatis.autosql.annotations.AdvanceSelect; import cn.yixblog.support.mybatis.autosql.annotations.AutoMapper; import cn.yixblog.support.mybatis.autosql.annotations.AutoSql; import cn.yixblog.support.mybatis.autosql.annotations.SqlType; -import com.alibaba.fastjson.JSONObject; -import org.apache.ibatis.annotations.Param; @AutoMapper(tablename = "cus_coupon_accuess_log", pkName = "accuess_id") public interface CouponAccuessLogMapper { @@ -19,4 +23,7 @@ public interface CouponAccuessLogMapper { @AutoSql(type = SqlType.SELECT) @AdvanceSelect(addonWhereClause = "is_valid = 1") JSONObject findUsedCouponByOrderId(@Param("order_id") String order_id); + + @AutoSql(type = SqlType.SELECT) + List findCouponByOrderId(@Param("order_id") String order_id); }