Commit 7669fce1 by 吕明尚

权益会员订单回调

parent ec816c7d
......@@ -13,6 +13,7 @@ public enum ReceiptRdeisEnum {
//房间15分钟过期
ROOM_EXPIRE_TIME(9, "ROOM_EXPIRE_TIME."),
ORDER_CANCEL_PAY(10, "ORDER_CANCEL_PAY."),
EQUITY_MEMBERS_TIME(11, "EQUITY_MEMBERS_TIME.")
;
......
......@@ -455,6 +455,19 @@ public class RedisTask {
});
}
public void AutoEquityMembers() {
Set<String> keys = redisTemplate.keys(ReceiptRdeisEnum.EQUITY_MEMBERS_TIME + "*");
if (keys.size() == 0) {
return;
}
keys.stream().forEach(key -> {
String value = redisUtil.get(String.valueOf(key));
JSONObject jsonObject = new JSONObject(value);
Date expirationTime = jsonObject.getDate("expirationTime");
Long consumerId = jsonObject.getLong("consumerId");
});
}
public void AutoAddRoomLabel() {
List<RoomLabel> roomLabelList = roomLabelService.list();
//获取roomLabelList中的roomId,去重
......
......@@ -60,4 +60,6 @@ public interface EquityMembersOrderMapper extends BaseMapper<EquityMembersOrder>
* @return 结果
*/
public int deleteEquityMembersOrderByIds(Long[] ids);
EquityMembersOrder getInfoByEntity(EquityMembersOrder equityMembersOrderParam);
}
......@@ -64,4 +64,8 @@ public interface EquityMembersOrderService extends IService<EquityMembersOrder>
public int deleteEquityMembersOrderById(Long id);
RechargePayResultResponse createEquityMembers(CreateEquityMembersRequest request);
EquityMembersOrder getInfoByEntity(EquityMembersOrder equityMembersOrderParam);
void paymentSuccessful(EquityMembersOrder equityMembersOrder);
}
......@@ -70,6 +70,9 @@ public class CallbackServiceImpl implements CallbackService {
@Autowired
private RechargeService rechargeService;
@Autowired
private EquityMembersOrderService equityMembersOrderService;
/**
* 微信支付回调
*/
......@@ -454,6 +457,83 @@ public class CallbackServiceImpl implements CallbackService {
return responseVo;
}
break;
case RIGHTS:
EquityMembersOrder equityMembersOrderParam = new EquityMembersOrder();
equityMembersOrderParam.setOutTradeNo(param.getTerminal_trace());
equityMembersOrderParam.setConsumerId(attachVo.getUserId());
EquityMembersOrder equityMembersOrder = equityMembersOrderService.getInfoByEntity(equityMembersOrderParam);
if (ObjectUtil.isNull(equityMembersOrder)) {
logger.error("saobei wechat pay error : 订单信息不存在==》" + param.getTerminal_trace());
responseVo.setReturn_code(SaobeiStatusEnum.FAIL.getCode());
responseVo.setReturn_msg("订单信息不存在!");
// 保存api日志
saobeiApiLog.setResponseParams(JSONUtil.toJsonStr(responseVo));
saobeiApiLog.setResult(responseVo.getReturn_code());
saobeiApiLog.setResultMsg(responseVo.getReturn_msg());
saobeiApiLog.setOutTradeNo(param.getOut_trade_no());
saobeiApiLogService.insertSaobeiApiLog(saobeiApiLog);
return responseVo;
}
if (YesNoEnum.yes.getIndex().equals(equityMembersOrder.getPayStatus())) {
logger.error("saobei wechat pay error : 订单已处理==》" + param.getTerminal_trace());
responseVo.setReturn_code(SaobeiStatusEnum.SUCCESS.getCode());
responseVo.setReturn_msg("success");
// 保存api日志
saobeiApiLog.setResponseParams(JSONUtil.toJsonStr(responseVo));
saobeiApiLog.setResult(responseVo.getReturn_code());
saobeiApiLog.setResultMsg(responseVo.getReturn_msg());
saobeiApiLog.setOutTradeNo(param.getOut_trade_no());
saobeiApiLogService.insertSaobeiApiLog(saobeiApiLog);
return responseVo;
}
WechatPayInfo equityPayInfo = wechatPayInfoService.getByNo(equityMembersOrder.getOutTradeNo());
if (ObjectUtil.isNull(equityPayInfo)) {
logger.error("saobei wechat pay error : 微信订单信息不存在==》" + param.getTerminal_trace());
responseVo.setReturn_code(SaobeiStatusEnum.FAIL.getCode());
responseVo.setReturn_msg("微信订单信息不存在!");
// 保存api日志
saobeiApiLog.setResponseParams(JSONUtil.toJsonStr(responseVo));
saobeiApiLog.setResult(responseVo.getReturn_code());
saobeiApiLog.setResultMsg(responseVo.getReturn_msg());
saobeiApiLog.setOutTradeNo(param.getOut_trade_no());
saobeiApiLogService.insertSaobeiApiLog(saobeiApiLog);
return responseVo;
}
// wechatPayInfo.setIsSubscribe(param.getIsSubscribe());
equityPayInfo.setBankType(param.getBank_type());
equityPayInfo.setCashFee(Integer.valueOf(param.getTotal_fee()));
// wechatPayInfo.setTransactionId(param.getOut_trade_no());
equityPayInfo.setTimeEnd(param.getEnd_time());
equityPayInfo.setTimeExpire(param.getEnd_time());
Boolean aBoolean = Boolean.FALSE;
try {
equityMembersOrder.setPayStatus(YesNoEnum.yes.getIndex());
equityMembersOrder.setPayTime(DateUtils.getNowDate());
equityMembersOrderService.paymentSuccessful(equityMembersOrder);
equityPayInfo.setTradeState("1");
equityPayInfo.setTradeStateDesc("支付成功");
wechatPayInfoService.updateById(equityPayInfo);
aBoolean = Boolean.TRUE;
} catch (Exception e) {
logger.error("微信支付回调出错");
logger.error(e.toString());
}
if (!aBoolean) {
logger.error("saobei wechat pay error : 订单更新失败==》" + param.getTerminal_trace());
responseVo.setReturn_code(SaobeiStatusEnum.FAIL.getCode());
responseVo.setReturn_msg("订单更新失败!");
// 保存api日志
saobeiApiLog.setResponseParams(JSONUtil.toJsonStr(responseVo));
saobeiApiLog.setResult(responseVo.getReturn_code());
saobeiApiLog.setResultMsg(responseVo.getReturn_msg());
saobeiApiLog.setOutTradeNo(param.getOut_trade_no());
saobeiApiLogService.insertSaobeiApiLog(saobeiApiLog);
return responseVo;
}
break;
default:
logger.error("wechat pay err : 未知的支付类型==》" + param.getTerminal_trace());
break;
......
package share.system.service.impl;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import share.common.core.redis.RedisUtil;
import share.common.enums.MemberTypeEnum;
import share.common.enums.ReceiptRdeisEnum;
import share.common.enums.YesNoEnum;
import share.common.exception.base.BaseException;
import share.common.utils.BaseUtil;
import share.common.utils.DateUtils;
import share.common.utils.bean.BeanUtils;
import share.system.domain.EquityMembersOrder;
import share.system.domain.EquityMembersOrderConfig;
import share.system.domain.SConsumer;
import share.system.domain.*;
import share.system.domain.vo.EquityMembersOrderVo;
import share.system.domain.vo.FrontTokenComponent;
import share.system.mapper.EquityMembersOrderMapper;
import share.system.request.CreateEquityMembersRequest;
import share.system.response.RechargePayResultResponse;
import share.system.service.EquityMembersOrderConfigService;
import share.system.service.EquityMembersOrderService;
import share.system.service.OrderPayService;
import share.system.service.SConsumerService;
import share.system.service.*;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 权益会员订单Service业务层处理
......@@ -41,6 +44,12 @@ public class EquityMembersOrderServiceImpl extends ServiceImpl<EquityMembersOrde
private EquityMembersOrderConfigService equityMembersOrderConfigService;
@Autowired
private OrderPayService orderPayService;
@Autowired
private ConsumerMemberService consumerMemberService;
@Autowired
private MemberConfigService memberConfigService;
@Autowired
private RedisUtil redisUtil;
/**
* 查询权益会员订单
......@@ -128,6 +137,56 @@ public class EquityMembersOrderServiceImpl extends ServiceImpl<EquityMembersOrde
return response;
}
@Override
public EquityMembersOrder getInfoByEntity(EquityMembersOrder equityMembersOrderParam) {
return equityMembersOrderMapper.getInfoByEntity(equityMembersOrderParam);
}
@Override
public void paymentSuccessful(EquityMembersOrder equityMembersOrder) {
ConsumerMember consumerMember = consumerMemberService.getOne(new LambdaQueryWrapper<ConsumerMember>().eq(ConsumerMember::getConsumerId, equityMembersOrder.getConsumerId()));
EquityMembersOrderConfig equityMembersOrderConfig = equityMembersOrderConfigService.selectEquityMembersOrderConfigById(equityMembersOrder.getEquityMembersConfigId());
if (ObjectUtil.isEmpty(consumerMember)) {
ConsumerMember newConsumerMember = new ConsumerMember();
newConsumerMember.setConsumerId(equityMembersOrder.getConsumerId());
newConsumerMember.setMembershipLevel(equityMembersOrderConfig.getDefaultLevel());
consumerMember.setMemberType(MemberTypeEnum.RIGHTS.getIndex());
MemberConfig memberConfig = memberConfigService.getOne(new LambdaQueryWrapper<MemberConfig>()
.eq(MemberConfig::getMembershipLevel, equityMembersOrderConfig.getDefaultLevel())
.eq(MemberConfig::getMemberType, MemberTypeEnum.RIGHTS.getIndex()));
consumerMember.setMemberConfigId(memberConfig.getId());
consumerMember.setExpirationDate(DateUtils.addDays(DateUtils.parseDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM, new Date())),
equityMembersOrderConfig.getValidityPeriod().intValue()));
consumerMember.setMembershipProgress(0L);
consumerMemberService.save(newConsumerMember);
} else {
if (consumerMember.getMemberType().equals(MemberTypeEnum.RECHARGE.getIndex())) {
//充值会员修改为权益会员
consumerMember.setMemberType(MemberTypeEnum.RIGHTS.getIndex());
consumerMember.setExpirationDate(DateUtils.addDays(DateUtils.parseDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM, new Date())),
equityMembersOrderConfig.getValidityPeriod().intValue()));
consumerMemberService.updateConsumerMember(consumerMember);
} else if (consumerMember.getMemberType().equals(MemberTypeEnum.RIGHTS.getIndex())) {
//在原来的基础上增加有效期
consumerMember.setExpirationDate(DateUtils.addDays(DateUtils.parseDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM, consumerMember.getExpirationDate())),
equityMembersOrderConfig.getValidityPeriod().intValue()));
consumerMemberService.updateConsumerMember(consumerMember);
} else {
//修改会员类型为权益会员
consumerMember.setMemberType(MemberTypeEnum.RIGHTS.getIndex());
consumerMember.setExpirationDate(DateUtils.addDays(DateUtils.parseDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM, new Date())),
equityMembersOrderConfig.getValidityPeriod().intValue()));
consumerMemberService.updateConsumerMember(consumerMember);
}
}
Map<String, String> map = new HashMap<>();
map.put("consumerId", String.valueOf(consumerMember.getConsumerId()));
//当前时间加15分钟
map.put("expirationTime", consumerMember.getExpirationDate().toString());
JSONObject json = new JSONObject(map);
redisUtil.set(ReceiptRdeisEnum.EQUITY_MEMBERS_TIME.getValue() + equityMembersOrder.getConsumerId(), json.toString());
}
private EquityMembersOrder generatEquityMembersOrder(CreateEquityMembersRequest request, SConsumer user) {
EquityMembersOrder equityMembersOrder = new EquityMembersOrder();
BeanUtils.copyProperties(request, equityMembersOrder);
......
......@@ -152,7 +152,7 @@ public class RechargeServiceImpl extends ServiceImpl<RechargeMapper, Recharge> i
.eq(MemberConfig::getMembershipLevel, 1L)
.eq(MemberConfig::getMemberType, MemberTypeEnum.RECHARGE.getIndex()));
consumerMember.setMemberConfigId(memberConfig.getId());
consumerMember.setMembershipProgress(recharge.getRechargeAmount().longValue());
consumerMember.setMembershipProgress(0L);
consumerMember.setExpirationDate(DateUtils.addDays(new Date(), memberConfig.getValidityPeriod().intValue()));
consumerMemberService.save(consumerMember);
extracted(recharge);
......
......@@ -1930,7 +1930,11 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
if (ObjectUtil.isNull(request.getCouponId()) || request.getCouponId() <= 0) {
priceResponse.setCouponFee(BigDecimal.ZERO);
priceResponse.setDiscountFee(priceResponse.getTotalFee().subtract(priceResponse.getPayFee()));
if (priceResponse.getTotalFee().compareTo(new BigDecimal(0)) == 0) {
priceResponse.setDiscountRatio(BigDecimal.ZERO);
} else {
priceResponse.setDiscountRatio(priceResponse.getDiscountFee().divide(priceResponse.getTotalFee(), 2, RoundingMode.HALF_UP).multiply(new BigDecimal(100)));
}
CronParser cronParser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ));
if (ObjectUtil.isNotEmpty(activity)) {
Cron cron = cronParser.parse(activity.getCronExpression());
......
......@@ -89,6 +89,10 @@
<include refid="selectEquityMembersOrderVo"/>
where id = #{id}
</select>
<select id="getInfoByEntity" resultType="share.system.domain.EquityMembersOrder">
<include refid="selectEquityMembersOrderVo"/>
where out_trade_no=#{outTradeNo} and consumer_id=#{consumerId}
</select>
<insert id="insertEquityMembersOrder" parameterType="EquityMembersOrder" useGeneratedKeys="true" keyProperty="id">
insert into s_equity_members_order
......
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