|  |  |  | 
|---|
|  |  |  | package cc.mrbird.febs.pay.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import cc.mrbird.febs.common.enumerates.AgentLevelEnum; | 
|---|
|  |  |  | import cc.mrbird.febs.common.enumerates.FlowTypeEnum; | 
|---|
|  |  |  | import cc.mrbird.febs.common.enumerates.OrderStatusEnum; | 
|---|
|  |  |  | import cc.mrbird.febs.common.exception.FebsException; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.entity.MallMember; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.entity.MallMqRecord; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.entity.MallOrderInfo; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.mapper.MallMqRecordMapper; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.mapper.MallOrderInfoMapper; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.service.IApiMallMemberService; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.service.IApiMallOrderInfoService; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.service.ICommonService; | 
|---|
|  |  |  | import cc.mrbird.febs.pay.properties.WxPayProperties; | 
|---|
|  |  |  | import cc.mrbird.febs.pay.service.IPayService; | 
|---|
|  |  |  | import cc.mrbird.febs.rabbit.producter.AgentProducer; | 
|---|
|  |  |  | import cn.hutool.core.date.DateField; | 
|---|
|  |  |  | import cn.hutool.core.date.DatePattern; | 
|---|
|  |  |  | import cn.hutool.core.date.DateUnit; | 
|---|
|  |  |  | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Value; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.math.BigDecimal; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | 
|---|
|  |  |  | public class WxPayServiceImpl implements IPayService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private IApiMallMemberService memberService; | 
|---|
|  |  |  | private ICommonService commonService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private MallOrderInfoMapper orderInfoMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WxPayProperties wxPayProperties; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private MallMqRecordMapper mallMqRecordMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private AgentProducer agentProducer; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${spring.profiles.active}") | 
|---|
|  |  |  | private String active; | 
|---|
|  |  |  | 
|---|
|  |  |  | if ("dev".equals(active) || "test".equals(active)) { | 
|---|
|  |  |  | request.setTotalFee(1); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | request.setTotalFee(orderInfo.getAmount().multiply(new BigDecimal(100)).intValue()); | 
|---|
|  |  |  | request.setTotalFee(orderInfo.getAmount().subtract(orderInfo.getScoreAmount()).multiply(new BigDecimal(100)).intValue()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public void payCallback(Map<String, String> params) { | 
|---|
|  |  |  | String orderNo = params.get("out_trade_no"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | orderInfo.setPayTime(new Date()); | 
|---|
|  |  |  | orderInfo.setPayTradeNo(params.get("transaction_id")); | 
|---|
|  |  |  | orderInfoMapper.updateById(orderInfo); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | commonService.changeWallet(orderInfo.getId(), FlowTypeEnum.WECHAT.getValue()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 插入一条待处理记录 | 
|---|
|  |  |  | * mq处理之后,更新状态 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | MallMqRecord mallMqRecord = new MallMqRecord(); | 
|---|
|  |  |  | mallMqRecord.setOrderId(orderInfo.getId()); | 
|---|
|  |  |  | mallMqRecord.setState(2); | 
|---|
|  |  |  | mallMqRecord.setRetryTimes(2); | 
|---|
|  |  |  | mallMqRecordMapper.insert(mallMqRecord); | 
|---|
|  |  |  | //发送补贴消息 | 
|---|
|  |  |  | agentProducer.sendPerkMoneyMsg(orderInfo.getId()); | 
|---|
|  |  |  | //发送代理自动升级消息 | 
|---|
|  |  |  | agentProducer.sendAutoLevelUpMsg(orderInfo.getMemberId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|