|
|
|
@ -7,7 +7,11 @@ import java.util.List;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.channels.wechat.config.WeChatPayConfig;
|
|
|
|
|
import au.com.royalpay.payment.channels.wechat.config.WechatPayEnvironment;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.ManagerCustomerRelationAlipayMapper;
|
|
|
|
|
import au.com.royalpay.payment.tools.connections.mpsupport.MpWechatApi;
|
|
|
|
|
import au.com.royalpay.payment.tools.connections.mpsupport.MpWechatApiProvider;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.apache.commons.lang3.RandomUtils;
|
|
|
|
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
|
|
|
@ -58,6 +62,8 @@ public class EncourageUseProcessor implements Ordered, EncourageService {
|
|
|
|
|
@Resource
|
|
|
|
|
private TransactionService transactionService;
|
|
|
|
|
@Resource
|
|
|
|
|
private MpWechatApiProvider mpWechatApiProvider;
|
|
|
|
|
@Resource
|
|
|
|
|
private CustomerMapper customerMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private ManagerMapper managerMapper;
|
|
|
|
@ -92,28 +98,43 @@ 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"))) {
|
|
|
|
|
logger.debug("不在有效期");
|
|
|
|
|
return new JSONObject();
|
|
|
|
|
}
|
|
|
|
|
if (!StringUtils.equals(openId, visitorOpenId)) {
|
|
|
|
|
logger.debug("不是同一人");
|
|
|
|
|
return new JSONObject();
|
|
|
|
|
String channel = order.getString("channel");
|
|
|
|
|
if ("Wechat".equals(channel)) {
|
|
|
|
|
JSONObject relation = customerMapper.findCustomerByOpenId(visitorOpenId);
|
|
|
|
|
if (relation == null) {
|
|
|
|
|
logger.debug("用户关系不存在");
|
|
|
|
|
return new JSONObject();
|
|
|
|
|
}
|
|
|
|
|
JSONObject wxUser = customerMapper.findCustomerByOpenId(visitorOpenId);
|
|
|
|
|
String merchantId = order.getString("merchant_id");
|
|
|
|
|
WeChatPayConfig.Merchant mch = WechatPayEnvironment.getEnv().getMerchantConfig(merchantId);
|
|
|
|
|
MpWechatApi api = mpWechatApiProvider.getApi(mch.getMpId());
|
|
|
|
|
if (!StringUtils.equals(wxUser.getString(api.getOpenIdKey()),openId)){
|
|
|
|
|
logger.debug("不是同一人");
|
|
|
|
|
return new JSONObject();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ("Alipay".equals(channel)){
|
|
|
|
|
if (!StringUtils.equals(visitorOpenId,openId)){
|
|
|
|
|
logger.debug("不是同一人");
|
|
|
|
|
return new JSONObject();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (config.getBooleanValue("debug_mode") && !checkIsDeveloper(openId)) {
|
|
|
|
|
if (config.getBooleanValue("debug_mode") && !checkIsDeveloper(visitorOpenId)) {
|
|
|
|
|
logger.debug("测试模式,不是管理员");
|
|
|
|
|
return new JSONObject();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject member = customerMembershipMapper.findByPaymentOpenId(openId);
|
|
|
|
|
if (member == null) {
|
|
|
|
|
member = new JSONObject();
|
|
|
|
|
if ("Wechat".equals(channel)){
|
|
|
|
|
JSONObject relation = customerMapper.findCustomerByOpenId(openId);
|
|
|
|
|
JSONObject relation = customerMapper.findCustomerByOpenId(visitorOpenId);
|
|
|
|
|
if (relation == null) {
|
|
|
|
|
logger.debug("用户关系不存在");
|
|
|
|
|
return new JSONObject();
|
|
|
|
|