|
|
@ -1,32 +1,7 @@
|
|
|
|
package au.com.royalpay.payment.manage.customers.core.impls;
|
|
|
|
package au.com.royalpay.payment.manage.customers.core.impls;
|
|
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
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.WeChatPayConfig;
|
|
|
|
import au.com.royalpay.payment.channels.wechat.config.WechatPayEnvironment;
|
|
|
|
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;
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.time.DateUtils;
|
|
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import org.springframework.cache.annotation.Cacheable;
|
|
|
|
|
|
|
|
import org.springframework.core.Ordered;
|
|
|
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
|
|
import com.github.miemiedev.mybatis.paginator.domain.Order;
|
|
|
|
|
|
|
|
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
|
|
|
|
|
|
|
|
import com.github.miemiedev.mybatis.paginator.domain.PageList;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.core.TransactionService;
|
|
|
|
import au.com.royalpay.payment.core.TransactionService;
|
|
|
|
import au.com.royalpay.payment.manage.customers.beans.EncourageEventParameters;
|
|
|
|
import au.com.royalpay.payment.manage.customers.beans.EncourageEventParameters;
|
|
|
|
import au.com.royalpay.payment.manage.customers.beans.ReceiveLogQueryBean;
|
|
|
|
import au.com.royalpay.payment.manage.customers.beans.ReceiveLogQueryBean;
|
|
|
@ -37,13 +12,38 @@ import au.com.royalpay.payment.manage.mappers.customers.CustomerEncourageMoneyUs
|
|
|
|
import au.com.royalpay.payment.manage.mappers.customers.CustomerMembershipMapper;
|
|
|
|
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.payment.OrderMapper;
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.CustomerMapper;
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.CustomerMapper;
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.ManagerCustomerRelationAlipayMapper;
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.ManagerMapper;
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.ManagerMapper;
|
|
|
|
import au.com.royalpay.payment.tools.CommonConsts;
|
|
|
|
import au.com.royalpay.payment.tools.CommonConsts;
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.tools.connections.mpsupport.MpWechatApi;
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.tools.connections.mpsupport.MpWechatApiProvider;
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.NotFoundException;
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.NotFoundException;
|
|
|
|
import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
|
|
|
|
import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
|
|
|
|
import au.com.royalpay.payment.tools.utils.PageListUtils;
|
|
|
|
import au.com.royalpay.payment.tools.utils.PageListUtils;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
|
|
import com.github.miemiedev.mybatis.paginator.domain.Order;
|
|
|
|
|
|
|
|
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
|
|
|
|
|
|
|
|
import com.github.miemiedev.mybatis.paginator.domain.PageList;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.RandomUtils;
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.time.DateUtils;
|
|
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import org.springframework.cache.annotation.Cacheable;
|
|
|
|
|
|
|
|
import org.springframework.core.Ordered;
|
|
|
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 鼓励金 Created by yixian on 2017-04-24.
|
|
|
|
* 鼓励金 Created by yixian on 2017-04-24.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -114,13 +114,13 @@ public class EncourageUseProcessor implements Ordered, EncourageService {
|
|
|
|
String merchantId = order.getString("merchant_id");
|
|
|
|
String merchantId = order.getString("merchant_id");
|
|
|
|
WeChatPayConfig.Merchant mch = WechatPayEnvironment.getEnv().getMerchantConfig(merchantId);
|
|
|
|
WeChatPayConfig.Merchant mch = WechatPayEnvironment.getEnv().getMerchantConfig(merchantId);
|
|
|
|
MpWechatApi api = mpWechatApiProvider.getApi(mch.getMpId());
|
|
|
|
MpWechatApi api = mpWechatApiProvider.getApi(mch.getMpId());
|
|
|
|
if (!StringUtils.equals(wxUser.getString(api.getOpenIdKey()),openId)){
|
|
|
|
if (!StringUtils.equals(wxUser.getString(api.getOpenIdKey()), openId)) {
|
|
|
|
logger.debug("不是同一人");
|
|
|
|
logger.debug("不是同一人");
|
|
|
|
return new JSONObject();
|
|
|
|
return new JSONObject();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ("Alipay".equals(channel)){
|
|
|
|
if ("Alipay".equals(channel)) {
|
|
|
|
if (!StringUtils.equals(visitorOpenId,openId)){
|
|
|
|
if (!StringUtils.equals(visitorOpenId, openId)) {
|
|
|
|
logger.debug("不是同一人");
|
|
|
|
logger.debug("不是同一人");
|
|
|
|
return new JSONObject();
|
|
|
|
return new JSONObject();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -132,7 +132,7 @@ public class EncourageUseProcessor implements Ordered, EncourageService {
|
|
|
|
JSONObject member = customerMembershipMapper.findByPaymentOpenId(visitorOpenId);
|
|
|
|
JSONObject member = customerMembershipMapper.findByPaymentOpenId(visitorOpenId);
|
|
|
|
if (member == null) {
|
|
|
|
if (member == null) {
|
|
|
|
member = new JSONObject();
|
|
|
|
member = new JSONObject();
|
|
|
|
if ("Wechat".equals(channel)){
|
|
|
|
if ("Wechat".equals(channel)) {
|
|
|
|
JSONObject relation = customerMapper.findCustomerByOpenId(visitorOpenId);
|
|
|
|
JSONObject relation = customerMapper.findCustomerByOpenId(visitorOpenId);
|
|
|
|
if (relation == null) {
|
|
|
|
if (relation == null) {
|
|
|
|
logger.debug("用户关系不存在");
|
|
|
|
logger.debug("用户关系不存在");
|
|
|
@ -146,7 +146,7 @@ public class EncourageUseProcessor implements Ordered, EncourageService {
|
|
|
|
member.put("encourage_balance", 0);
|
|
|
|
member.put("encourage_balance", 0);
|
|
|
|
customerMembershipMapper.saveMember(member);
|
|
|
|
customerMembershipMapper.saveMember(member);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ("Alipay".equals(channel)){
|
|
|
|
if ("Alipay".equals(channel)) {
|
|
|
|
JSONObject relation = managerCustomerRelationAlipayMapper.findCustomerByUserId(openId);
|
|
|
|
JSONObject relation = managerCustomerRelationAlipayMapper.findCustomerByUserId(openId);
|
|
|
|
if (relation == null) {
|
|
|
|
if (relation == null) {
|
|
|
|
logger.debug("用户关系不存在");
|
|
|
|
logger.debug("用户关系不存在");
|
|
|
@ -168,8 +168,8 @@ public class EncourageUseProcessor implements Ordered, EncourageService {
|
|
|
|
logger.debug("超出领取次数");
|
|
|
|
logger.debug("超出领取次数");
|
|
|
|
return new JSONObject();
|
|
|
|
return new JSONObject();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int rand = RandomUtils
|
|
|
|
int rand = RandomUtils.nextInt(0,
|
|
|
|
.nextInt(0,config.getBigDecimal("max_amount").subtract(config.getBigDecimal("min_amount")).multiply(CommonConsts.HUNDRED).intValue());
|
|
|
|
config.getBigDecimal("max_amount").subtract(config.getBigDecimal("min_amount")).multiply(CommonConsts.HUNDRED).intValue());
|
|
|
|
BigDecimal amount = config.getBigDecimal("min_amount").add(BigDecimal.valueOf(rand).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_DOWN));
|
|
|
|
BigDecimal amount = config.getBigDecimal("min_amount").add(BigDecimal.valueOf(rand).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_DOWN));
|
|
|
|
customerMembershipMapper.addEncourage(memberId, amount);
|
|
|
|
customerMembershipMapper.addEncourage(memberId, amount);
|
|
|
|
JSONObject customer = customerMembershipMapper.findByMemberId(memberId);
|
|
|
|
JSONObject customer = customerMembershipMapper.findByMemberId(memberId);
|
|
|
@ -209,8 +209,8 @@ public class EncourageUseProcessor implements Ordered, EncourageService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (log.getBigDecimal("factor").compareTo(BigDecimal.ONE) == 0) {
|
|
|
|
if (log.getBigDecimal("factor").compareTo(BigDecimal.ONE) == 0) {
|
|
|
|
int critRate = config.getIntValue("crit_rate");
|
|
|
|
int critRate = config.getIntValue("crit_rate");
|
|
|
|
if (RandomUtils.nextInt(0,100) < critRate) {
|
|
|
|
if (RandomUtils.nextInt(0, 100) < critRate) {
|
|
|
|
int factorInt = RandomUtils.nextInt(0,config.getBigDecimal("max_crit").multiply(CommonConsts.HUNDRED).intValue() - 100);
|
|
|
|
int factorInt = RandomUtils.nextInt(0, config.getBigDecimal("max_crit").multiply(CommonConsts.HUNDRED).intValue() - 100);
|
|
|
|
BigDecimal factor = BigDecimal.valueOf(factorInt + 100).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_DOWN);
|
|
|
|
BigDecimal factor = BigDecimal.valueOf(factorInt + 100).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_DOWN);
|
|
|
|
BigDecimal actural = log.getBigDecimal("access_amount").multiply(factor).setScale(2, BigDecimal.ROUND_DOWN);
|
|
|
|
BigDecimal actural = log.getBigDecimal("access_amount").multiply(factor).setScale(2, BigDecimal.ROUND_DOWN);
|
|
|
|
BigDecimal sub = actural.subtract(log.getBigDecimal("actural_amount"));
|
|
|
|
BigDecimal sub = actural.subtract(log.getBigDecimal("actural_amount"));
|
|
|
@ -329,4 +329,14 @@ public class EncourageUseProcessor implements Ordered, EncourageService {
|
|
|
|
PageList<JSONObject> receiveLogs = customerEncourageMoneyUseLogMapper.list(params, new PageBounds(page, limit, Order.formString("use_time.desc")));
|
|
|
|
PageList<JSONObject> receiveLogs = customerEncourageMoneyUseLogMapper.list(params, new PageBounds(page, limit, Order.formString("use_time.desc")));
|
|
|
|
return PageListUtils.buildPageListResult(receiveLogs);
|
|
|
|
return PageListUtils.buildPageListResult(receiveLogs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void prepareUserInfo(JSONObject user, String user_id) {
|
|
|
|
|
|
|
|
if ("wechat".equals(user.getString("channel"))) {
|
|
|
|
|
|
|
|
user.put("headimg", customerMapper.findCustomerByOpenId(user_id).getString("headimg"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ("alipay".equals(user.getString("channel"))) {
|
|
|
|
|
|
|
|
user.put("headimg", managerCustomerRelationAlipayMapper.findCustomerByUserId(user_id).getString("headimg"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|