Merge branch 'develop'

master
james.zhao 6 years ago
commit f84bad16d0

@ -2,6 +2,8 @@ package au.com.royalpay.payment.manage.customers.core;
import com.alibaba.fastjson.JSONObject;
import java.util.List;
/**
* Created by yuan on 2017/10/10.
*/
@ -21,4 +23,6 @@ public interface CouponValidateService {
JSONObject ctripCouponInfo(String coupon_log_id,int client_id,boolean is_expiry);
JSONObject ctripCouponLogNotice(String coupon_log_id,String order_id,String open_id,String status);
JSONObject getHalloweenOrderInfo(String customerId, String transactionDate);
}

@ -2,6 +2,8 @@ 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.mappers.payment.OrderMapper;
import au.com.royalpay.payment.manage.mappers.system.CustomerMapper;
import au.com.royalpay.payment.manage.merchants.core.ClientManager;
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
import au.com.royalpay.payment.tools.exceptions.NotFoundException;
@ -51,6 +53,12 @@ public class CouponValidateServiceImpl implements CouponValidateService {
@Resource
private ClientManager clientManager;
@Resource
private OrderMapper orderMapper;
@Resource
private CustomerMapper customerMapper;
@Override
public JSONObject getCoupon(JSONObject partner,int page,int limit) {
String timestamp = System.currentTimeMillis() + "";
@ -217,6 +225,50 @@ public class CouponValidateServiceImpl implements CouponValidateService {
return null;
}
@Override
public JSONObject getHalloweenOrderInfo(String customerId, String transactionDate) {
// 获取万圣节活动当天支付成功的订单
JSONObject param = new JSONObject();
param.put("customer_id", customerId);
param.put("transaction_date", transactionDate);
param.put("status", 5);
List<JSONObject> orderList = orderMapper.listHalloweenActOrder(param);
JSONObject result = null;
if (orderList != null && orderList.size() > 0) {
result = new JSONObject();
result.put("orderList", orderList);
for (JSONObject order : orderList) {
String redpackOpenId = getRedpackId(order);
if (redpackOpenId != null) {
result.put("redpackOpenId", redpackOpenId);
break;
}
}
}
return result;
}
// 获取该笔订单的redpackOpenId
// TODO: 2018/10/28 有待商榷
private String getRedpackId(JSONObject order) {
String redpackOpenId = null;
String channel = order.getString("channel");
if ("Wechat".equals(channel)) {
JSONObject customerRelation = customerMapper.findCustomerByOpenId(order.getString("customer_id"));
if (customerRelation == null) {
customerRelation = customerMapper.findCustomerGlobalpayByOpenId(order.getString("customer_id"));
} else {
redpackOpenId = customerRelation.getString("redpack_openid");
if (customerRelation.getString("kanga_openid") == null) {
redpackOpenId = null;
}
}
}
return redpackOpenId;
}
private String signUrl(UriComponentsBuilder uriComponentsBuilder) {
String timestamp = System.currentTimeMillis() + "";
String base = CUSTOMER_APP_ID + timestamp + CUSTOMER_AUTH_CODE;

@ -0,0 +1,105 @@
package au.com.royalpay.payment.manage.customers.core.impls;
import au.com.royalpay.payment.core.events.AfterPaymentFinishEvent;
import au.com.royalpay.payment.manage.mappers.system.CustomerMapper;
import cn.yixblog.platform.http.HttpRequestGenerator;
import cn.yixblog.platform.http.HttpRequestResult;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.codec.digest.DigestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.util.UriComponentsBuilder;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
@Service
public class CustomerHalloweenCountServiceImpl implements ApplicationListener<AfterPaymentFinishEvent> {
private Logger logger = LoggerFactory.getLogger(getClass());
@Value("${app.customer.host}")
private String CUSTOMER_HOST;
@Value("${customer.app.appid}")
private String CUSTOMER_APP_ID;
@Value("${customer.app.auth-code}")
private String CUSTOMER_AUTH_CODE;
@Resource
private CustomerMapper customerMapper;
@Override
public void onApplicationEvent(AfterPaymentFinishEvent event) {
final JSONObject order = event.getFinishedEvent().getOrder();
//判断是否是pine测试商户若不是则判断是否在活动时间
if (order.getIntValue("client_id") != 9) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date newDay = new Date();
try {
if (newDay.compareTo(sdf.parse("2018-10-31 00:00:00")) < 0) {
return;
}
if (newDay.compareTo(sdf.parse("2018-11-02 00:00:00")) > 0) {
return;
}
} catch (ParseException e) {
}
}
BigDecimal clearAmount = event.getFinishedEvent().getAudFee();
String channel = order.getString("channel");
if ("Wechat".equals(channel)) {
JSONObject customerRelation = customerMapper.findCustomerByOpenId(order.getString("customer_id"));
if (customerRelation == null) {
customerRelation = customerMapper.findCustomerGlobalpayByOpenId(order.getString("customer_id"));
}
if (customerRelation.getString("kanga_openid") == null) {
return;
}
afterPaymentAddHalloweenCount(customerRelation.getString("kanga_openid"), order.getString("order_id"), customerRelation.getString("redpack_openid"),channel, clearAmount);
}
if ("Alipay".equals(channel)) {
afterPaymentAddHalloweenCount(order.getString("customer_id"), order.getString("order_id"), "alipay",channel, clearAmount);
}
}
private void afterPaymentAddHalloweenCount(String id, String orderId,String redPackId, String channel, BigDecimal clearAmount) {
String timestamp = System.currentTimeMillis() + "";
String base = CUSTOMER_APP_ID + timestamp + CUSTOMER_AUTH_CODE;
String sign = DigestUtils.sha256Hex(base).toLowerCase();
String uri = UriComponentsBuilder.fromHttpUrl(CUSTOMER_HOST + "activity/halloween/payment/orders")
.queryParam("appid", CUSTOMER_APP_ID)
.queryParam("timestamp", timestamp)
.queryParam("sign", sign)
.queryParam("id", id)
.queryParam("orderId", orderId)
.queryParam("channel", channel)
.queryParam("amount", clearAmount)
.queryParam("redpackId", redPackId)
.toUriString();
if(clearAmount.compareTo(new BigDecimal("1.99"))<0){
return;
}
HttpRequestGenerator gen = new HttpRequestGenerator(uri, RequestMethod.POST);
try {
HttpRequestResult result = gen.execute();
if (result.isSuccess()) {
int statusCode = result.getStatusCode();
if (statusCode == 200) {
logger.info("万圣节活动次数添加成功");
}
}
} catch (Exception ignored) {
ignored.printStackTrace();
}
}
}

@ -10,6 +10,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* Created by yuan on 2017/10/10.
@ -40,4 +41,17 @@ public class CouponValidateController {
throw new BadRequestException("卡券核销失败");
}
}
/**
*
* @param customerId
* @param actDate
* @return
*/
@GetMapping(value = "/payment/halloween")
@ResponseBody
public JSONObject getHalloweenActOrderInfo(@RequestParam("customer_id") String customerId,
@RequestParam("act_date") String actDate) {
return couponVerificationService.getHalloweenOrderInfo(customerId, actDate);
}
}

@ -79,4 +79,9 @@ public interface OrderMapper {
List<JSONObject> listAnalysisClientCustomer(JSONObject params);
PageList<JSONObject> listTransactionsForApp(JSONObject params, PageBounds pageBounds);
JSONObject findOrderById(@Param("order_id") String orderId);
@AutoSql(type = SqlType.SELECT)
List<JSONObject> listHalloweenActOrder(JSONObject param);
}

Loading…
Cancel
Save