Commit 4e26a05c by YG8429

修改权益会员绑定逻辑。权益会员返佣逻辑

parent f5558b68
......@@ -120,6 +120,9 @@ public class RedisTask {
@Autowired
private EquityFundLogService equityFundLogService;
@Autowired
private DurationLogService durationLogService;
//15分钟的常量
final long FIFTEEN_MINUTES = 60 * 15;
......@@ -337,32 +340,38 @@ public class RedisTask {
redisUtil.delete(o);
throw new BaseException("订单不存在!");
}
//查询当前用户是否只有一个订单
LambdaQueryWrapper<SOrder> sOrderLambdaQueryWrapper = new LambdaQueryWrapper<>();
sOrderLambdaQueryWrapper.eq(SOrder :: getConsumerId,sOrder.getConsumerId());
sOrderLambdaQueryWrapper.eq(SOrder::getPayStatus, YesNoEnum.yes.getIndex());
sOrderLambdaQueryWrapper.notIn(SOrder::getRefundStatus, RefundStatusEnum.getRefundedStatus());
sOrderLambdaQueryWrapper.in(SOrder::getStatus, OrderStatusEnum.getUnfinishOrderStatus());
sOrderLambdaQueryWrapper.eq(SOrder::getIsDelete, YesNoEnum.no.getIndex());
List<SOrder> sOrderList = isOrderService.list(sOrderLambdaQueryWrapper);
if (sOrderList.size() == 1){
//查询是否有上级
LambdaQueryWrapper<SharingActivities> sharingActivitiesLambdaQueryWrapper = new LambdaQueryWrapper<>();
sharingActivitiesLambdaQueryWrapper.eq(SharingActivities :: getNewUid,sOrder.getConsumerId());
sharingActivitiesLambdaQueryWrapper.eq(SharingActivities :: getActivityType,"0");
sharingActivitiesLambdaQueryWrapper.eq(SharingActivities :: getIsDelete,YesNoEnum.no.getIndex());
SharingActivities sharingActivities = sharingActivitiesService.getOne(sharingActivitiesLambdaQueryWrapper);
if (ObjectUtil.isNotEmpty(sharingActivities)){
//查询是否有上级
LambdaQueryWrapper<SharingActivities> sharingActivitiesLambdaQueryWrapper = new LambdaQueryWrapper<>();
sharingActivitiesLambdaQueryWrapper.eq(SharingActivities::getNewUid, sOrder.getConsumerId());
sharingActivitiesLambdaQueryWrapper.eq(SharingActivities::getIsDelete, YesNoEnum.no.getIndex());
SharingActivities sharingActivities = sharingActivitiesService.getOne(sharingActivitiesLambdaQueryWrapper);
if (ObjectUtil.isNotEmpty(sharingActivities)) {
//查询当前用户是否只有一个订单
LambdaQueryWrapper<SOrder> sOrderLambdaQueryWrapper = new LambdaQueryWrapper<>();
sOrderLambdaQueryWrapper.eq(SOrder::getConsumerId, sOrder.getConsumerId());
sOrderLambdaQueryWrapper.eq(SOrder::getPayStatus, YesNoEnum.yes.getIndex());
sOrderLambdaQueryWrapper.notIn(SOrder::getRefundStatus, RefundStatusEnum.getRefundedStatus());
sOrderLambdaQueryWrapper.in(SOrder::getStatus, OrderStatusEnum.getUnfinishOrderStatus());
sOrderLambdaQueryWrapper.eq(SOrder::getIsDelete, YesNoEnum.no.getIndex());
List<SOrder> sOrderList = isOrderService.list(sOrderLambdaQueryWrapper);
if (sOrderList.size() == 1) {
LambdaQueryWrapper<ConsumerWallet> consumerWalletLambdaQueryWrapper = new LambdaQueryWrapper<>();
consumerWalletLambdaQueryWrapper.eq(ConsumerWallet::getConsumerId,sharingActivities.getUid());
ConsumerWallet consumerWallet = consumerWalletService.getOne(consumerWalletLambdaQueryWrapper);
if (ObjectUtil.isNotEmpty(consumerWallet)){
consumerWalletLambdaQueryWrapper.eq(ConsumerWallet::getConsumerId, sharingActivities.getUid());
ConsumerWallet consumerWallet = consumerWalletService.getOne(consumerWalletLambdaQueryWrapper);
if (ObjectUtil.isNotEmpty(consumerWallet)) {
//添加时长
BigDecimal anHour = new BigDecimal(1.0);
consumerWallet.setRemainingDuration(consumerWallet.getRemainingDuration().add(anHour));
consumerWallet.setUpdateTime(DateUtils.getNowDate());
consumerWalletService.updateConsumerWallet(consumerWallet);
}else {
DurationLog durationLog = new DurationLog();
durationLog.setConsumerId(consumerWallet.getConsumerId());
durationLog.setVariableDuration(anHour);
durationLog.setCurrentDuration(consumerWallet.getRemainingDuration());
durationLog.setOperationType(YesNoEnum.yes.getIndex());
durationLog.setOperationTime(DateUtils.getNowDate());
durationLogService.insertDurationLog(durationLog);
} else {
//新增钱包
ConsumerWallet newConsumerWallet = new ConsumerWallet();
BigDecimal defaultVlue = new BigDecimal(0.0);
......@@ -375,24 +384,28 @@ public class RedisTask {
newConsumerWallet.setRemainingDuration(newConsumerWallet.getRemainingDuration().add(anHour));
newConsumerWallet.setUpdateTime(DateUtils.getNowDate());
consumerWalletService.insertConsumerWallet(newConsumerWallet);
DurationLog newDurationLog = new DurationLog();
newDurationLog.setConsumerId(consumerWallet.getConsumerId());
newDurationLog.setVariableDuration(anHour);
newDurationLog.setCurrentDuration(consumerWallet.getRemainingDuration());
newDurationLog.setOperationType(YesNoEnum.yes.getIndex());
newDurationLog.setOperationTime(DateUtils.getNowDate());
durationLogService.insertDurationLog(newDurationLog);
}
}
}
//查询是否有上级
LambdaQueryWrapper<SharingActivities> sharingActivitiesLambdaQueryWrapper = new LambdaQueryWrapper<>();
sharingActivitiesLambdaQueryWrapper.eq(SharingActivities :: getNewUid,sOrder.getConsumerId());
sharingActivitiesLambdaQueryWrapper.eq(SharingActivities :: getActivityType,"1");
sharingActivitiesLambdaQueryWrapper.eq(SharingActivities :: getIsDelete,YesNoEnum.no.getIndex());
SharingActivities sharingActivities = sharingActivitiesService.getOne(sharingActivitiesLambdaQueryWrapper);
if (ObjectUtil.isNotEmpty(sharingActivities)){
//查询会员用户类型
LambdaQueryWrapper<ConsumerMember> consumerMemberLambdaQueryWrapper = new LambdaQueryWrapper<>();
consumerMemberLambdaQueryWrapper.eq(ConsumerMember::getConsumerId,sharingActivities.getUid());
ConsumerMember consumerMember = consumerMemberService.getOne(consumerMemberLambdaQueryWrapper);
LambdaQueryWrapper<ConsumerMember> consumerMemberWrapper = new LambdaQueryWrapper<>();
consumerMemberWrapper.eq(ConsumerMember::getConsumerId, sharingActivities.getUid());
ConsumerMember consumerMember = consumerMemberService.getOne(consumerMemberWrapper);
LambdaQueryWrapper<ConsumerMember> newConsumerMemberQueryWrapper = new LambdaQueryWrapper<>();
newConsumerMemberQueryWrapper.eq(ConsumerMember::getConsumerId, sharingActivities.getUid());
ConsumerMember newConsumerMember = consumerMemberService.getOne(newConsumerMemberQueryWrapper);
//判断是否为权益会员和会员是否有效
if ("2".equals(consumerMember.getMemberType()) && new Date().getTime() < consumerMember.getExpirationDate().getTime() ){
if ("2".equals(consumerMember.getMemberType()) && new Date().getTime() < consumerMember.getExpirationDate().getTime()
&& "2".equals(newConsumerMember.getMemberType()) && new Date().getTime() < newConsumerMember.getExpirationDate().getTime()) {
Boolean aBoolean = redisTemplate.hasKey(ReceiptRdeisEnum.EQUITY_MEMBERS_TIME + sharingActivities.getUid().toString());
if (aBoolean){
Boolean newAboolean = redisTemplate.hasKey(ReceiptRdeisEnum.EQUITY_MEMBERS_TIME + sharingActivities.getNewUid().toString());
if (aBoolean && newAboolean) {
LambdaQueryWrapper<ConsumerWallet> consumerWalletLambdaQueryWrapper = new LambdaQueryWrapper<>();
consumerWalletLambdaQueryWrapper.eq(ConsumerWallet::getConsumerId, sharingActivities.getUid());
ConsumerWallet consumerWallet = consumerWalletService.getOne(consumerWalletLambdaQueryWrapper);
......@@ -426,7 +439,6 @@ public class RedisTask {
}
}
}
}
if (extracted(o, sOrders, sOrder)) return;
......
......@@ -470,7 +470,7 @@ public class CallbackServiceImpl implements CallbackService {
wechatInfo.setTradeStateDesc("支付成功");
wechatPayInfoService.updateById(wechatInfo);
//新增权益金日志
addEquityFundLog(recharge.getConsumerId(),
addEquityFundLogRecharge(recharge.getConsumerId(),
recharge.getRechargeAmount(),recharge.getOutTradeNo(),recharge.getTerminalTrace(),"0");
aFalse = Boolean.TRUE;
} catch (Exception e) {
......@@ -552,7 +552,7 @@ public class CallbackServiceImpl implements CallbackService {
equityPayInfo.setTradeStateDesc("支付成功");
wechatPayInfoService.updateById(equityPayInfo);
//新增权益金日志
addEquityFundLog(equityMembersOrder.getConsumerId(),
addEquityFundLogRights(equityMembersOrder.getConsumerId(),
equityMembersOrder.getPayPrice(),equityMembersOrder.getEquityOrderNo(),equityMembersOrder.getTerminalTrace(),"1");
aBoolean = Boolean.TRUE;
} catch (Exception e) {
......@@ -765,7 +765,7 @@ public class CallbackServiceImpl implements CallbackService {
* @param terminalTrace 终端流水号
* @param type 权益类型
*/
private void addEquityFundLog(Long consumerId, BigDecimal payPrice, String equityOrderNo, String terminalTrace, String type) {
private void addEquityFundLogRecharge(Long consumerId, BigDecimal payPrice, String equityOrderNo, String terminalTrace, String type) {
//查询是否有上级
SharingActivities sharingActivities = sharingActivitiesService.getOne(new LambdaQueryWrapper<SharingActivities>()
.eq(SharingActivities::getNewUid, consumerId)
......@@ -774,12 +774,12 @@ public class CallbackServiceImpl implements CallbackService {
if (ObjectUtil.isNotEmpty(sharingActivities)) {
//查询会员用户类型
LambdaQueryWrapper<ConsumerMember> consumerMemberLambdaQueryWrapper = new LambdaQueryWrapper<>();
consumerMemberLambdaQueryWrapper.eq(ConsumerMember::getConsumerId,sharingActivities.getUid());
ConsumerMember consumerMember = consumerMemberService.getOne(consumerMemberLambdaQueryWrapper);
consumerMemberLambdaQueryWrapper.eq(ConsumerMember::getConsumerId, sharingActivities.getUid());
ConsumerMember consumerMember = consumerMemberService.getOne(consumerMemberLambdaQueryWrapper);
//判断是否为权益会员和会员是否有效
if ("2".equals(consumerMember.getMemberType()) && new Date().getTime() < consumerMember.getExpirationDate().getTime() ){
if ("2".equals(consumerMember.getMemberType()) && new Date().getTime() < consumerMember.getExpirationDate().getTime()) {
Boolean aBoolean = redisTemplate.hasKey(ReceiptRdeisEnum.EQUITY_MEMBERS_TIME + sharingActivities.getUid().toString());
if (aBoolean){
if (aBoolean) {
String equityFund = sysConfigService.selectConfigByKey("sys.equityFundLog.equityFund");
//查询上级用户是否有钱包
ConsumerWallet consumerWallet = consumerWalletService.getOne(new LambdaQueryWrapper<ConsumerWallet>()
......@@ -826,6 +826,81 @@ public class CallbackServiceImpl implements CallbackService {
}
}
}
/**
* 新增权益金日志
* @param consumerId 用户ID
* @param payPrice 消费金额
* @param equityOrderNo 订单编号
* @param terminalTrace 终端流水号
* @param type 权益类型
*/
private void addEquityFundLogRights(Long consumerId, BigDecimal payPrice, String equityOrderNo, String terminalTrace, String type) {
//查询是否有上级
SharingActivities sharingActivities = sharingActivitiesService.getOne(new LambdaQueryWrapper<SharingActivities>()
.eq(SharingActivities::getNewUid, consumerId)
.eq(SharingActivities::getIsDelete, YesNoEnum.no.getIndex()));
if (ObjectUtil.isNotEmpty(sharingActivities)) {
//查询会员用户类型
LambdaQueryWrapper<ConsumerMember> consumerMemberWrapper = new LambdaQueryWrapper<>();
consumerMemberWrapper.eq(ConsumerMember::getConsumerId, sharingActivities.getUid());
ConsumerMember consumerMember = consumerMemberService.getOne(consumerMemberWrapper);
LambdaQueryWrapper<ConsumerMember> newConsumerMemberWrapper = new LambdaQueryWrapper<>();
newConsumerMemberWrapper.eq(ConsumerMember::getConsumerId, sharingActivities.getUid());
ConsumerMember newConsumerMember = consumerMemberService.getOne(newConsumerMemberWrapper);
//判断是否为权益会员和会员是否有效
if ("2".equals(consumerMember.getMemberType()) && new Date().getTime() < consumerMember.getExpirationDate().getTime()
&& "2".equals(newConsumerMember.getMemberType()) && new Date().getTime() < newConsumerMember.getExpirationDate().getTime()) {
Boolean aBoolean = redisTemplate.hasKey(ReceiptRdeisEnum.EQUITY_MEMBERS_TIME + sharingActivities.getUid().toString());
Boolean newAboolean = redisTemplate.hasKey(ReceiptRdeisEnum.EQUITY_MEMBERS_TIME + sharingActivities.getNewUid().toString());
if (aBoolean && newAboolean) {
String equityFund = sysConfigService.selectConfigByKey("sys.equityFundLog.equityFund");
//查询上级用户是否有钱包
ConsumerWallet consumerWallet = consumerWalletService.getOne(new LambdaQueryWrapper<ConsumerWallet>()
.eq(ConsumerWallet::getConsumerId, sharingActivities.getUid()));
if (ObjectUtil.isNotEmpty(consumerWallet)) {
consumerWallet.setEquityFund(consumerWallet.getEquityFund().add(payPrice.multiply(new BigDecimal(equityFund))));
consumerWallet.setAccumulateEquityFund(consumerWallet.getAccumulateEquityFund().
add(payPrice.multiply(new BigDecimal(equityFund))));
consumerWallet.setUpdateTime(DateUtils.getNowDate());
consumerWalletService.updateConsumerWallet(consumerWallet);
} else {
//新增钱包
ConsumerWallet newConsumerWallet = new ConsumerWallet();
BigDecimal defaultVlue = new BigDecimal(0.0);
newConsumerWallet.setConsumerId(sharingActivities.getUid());
newConsumerWallet.setBalance(defaultVlue);
newConsumerWallet.setRemainingIntegral(defaultVlue);
newConsumerWallet.setRemainingDuration(defaultVlue);
newConsumerWallet.setEquityFund(consumerWallet.getEquityFund().add(payPrice.multiply(new BigDecimal(equityFund).setScale(2, RoundingMode.HALF_UP))));
newConsumerWallet.setAccumulateEquityFund(consumerWallet.getAccumulateEquityFund()
.add(payPrice.multiply(new BigDecimal(equityFund).setScale(2, RoundingMode.HALF_UP))));
consumerWalletService.insertConsumerWallet(newConsumerWallet);
}
//添加权益金日志记录
//下级用户
SConsumer newConsumer = consumerService.getById(consumerId);
//上级用户
SConsumer consumer = consumerService.getById(sharingActivities.getUid());
EquityFundLog equityFundLog = new EquityFundLog();
equityFundLog.setEquityFund(payPrice.multiply(new BigDecimal(equityFund).setScale(2, RoundingMode.HALF_UP)));
equityFundLog.setEquityFundType(type);
equityFundLog.setOutTradeNo(equityOrderNo);
equityFundLog.setTerminalTrace(terminalTrace);
equityFundLog.setUid(sharingActivities.getUid());
equityFundLog.setNewUid(sharingActivities.getNewUid());
equityFundLog.setPhone(consumer.getPhone());
equityFundLog.setAccount(consumer.getAccount());
equityFundLog.setNickName(consumer.getNickName());
equityFundLog.setNewPhone(newConsumer.getPhone());
equityFundLog.setNewAccount(newConsumer.getAccount());
equityFundLog.setNewNickName(newConsumer.getNickName());
equityFundLogService.insertEquityFundLog(equityFundLog);
}
}
}
}
/**
* 支付订单回调通知
......
......@@ -313,7 +313,6 @@ public class SConsumerCenterServiceImpl extends ServiceImpl<SConsumerMapper, SCo
if (uid != null){
//添加绑定关系
SharingActivities sharingActivities = new SharingActivities();
sharingActivities.setActivityType(request.getActivityType());
sharingActivities.setUid(uid);
sharingActivities.setNewUid(id);
sharingActivities.setCreateTime(DateUtils.getNowDate());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment