| | |
| | | import com.lunhan.water.entity.request.pay.ReqPayRefund; |
| | | |
| | | import com.lunhan.water.repository.impl.*; |
| | | import com.lunhan.water.repository.mapper.SysDictTypeMapper; |
| | | import com.lunhan.water.repository.po.*; |
| | | import org.slf4j.Logger; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.time.LocalDateTime; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | |
| | |
| | | private UserCapitalChangeMapperImpl capitalChangeDao; |
| | | @Autowired |
| | | private TradeRecordMapperImpl tradeRecordDao; |
| | | |
| | | @Autowired |
| | | private RedisTemplate<String, Object> redisTemplate; |
| | | @Autowired |
| | | private SysDictTypeMapperImpl sysDictTypeMapper; |
| | | @Autowired |
| | | private SysDictDataMapperImpl sysDictDataMapper; |
| | | |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ExecutedResult<Map<String, Object>> weiXinPay(LoginUserDTO loginUser, ReqCreatePay request) { |
| | | //判断token是否存在,如果不存在,说明重复提交订单 |
| | | // String redisToken = redisTemplate.opsForValue().get(request.getPayToken()).toString(); |
| | | // if (StringUtil.isNullOrEmpty(redisToken)) { |
| | | // throw new RuntimeException("请勿重复提交充值订单!"); |
| | | // } |
| | | // //删除token |
| | | // redisTemplate.delete(request.getPayToken()); |
| | | |
| | | EBusinessType type = EBusinessType.getByValue(request.getBusinessType()); |
| | | if (Objects.isNull(type)) { |
| | | return ExecutedResult.failed("业务不支持." + request.getBusinessType()); |
| | |
| | | request.setBusinessComment("用户充值"); |
| | | //添加充值记录 |
| | | RechargeRecordsPO item = new RechargeRecordsPO(); |
| | | item.setUserId(user.getId()); |
| | | //将充值金额转换为水量 |
| | | List<SysDictDataPO> feesAmount = sysDictDataMapper.getListByType("fees_amount"); |
| | | if(ListUtil.isNotNullOrEmpty(feesAmount)){ |
| | | SysDictDataPO sysDictDataPO = feesAmount.get(0); |
| | | BigDecimal bigDecimal = request.getTradeAmount().multiply(new BigDecimal(sysDictDataPO.getDictValue())).setScale(2, BigDecimal.ROUND_DOWN); |
| | | item.setRechargeWater(bigDecimal); |
| | | }else { |
| | | //默认单价 |
| | | BigDecimal bigDecimal =request.getTradeAmount().multiply(new BigDecimal(3)).setScale(2, BigDecimal.ROUND_DOWN); |
| | | item.setRechargeWater(bigDecimal); |
| | | } |
| | | item.setRechargeOrder(request.getBusinessNo()); |
| | | item.setRechargeType(ERechargeType.MOBILE.getDesc()); |
| | | item.setPaymentMethod(EPayType.WX_PAY.getDesc()); |
| | | item.setRechargeStatus(EYesOrNo.NO.getValue()); |
| | | item.setRechargeAmount(request.getTradeAmount()); |
| | | item.setComment("水卡充值"); |
| | | item.setComment("余额充值"); |
| | | item.setCreateTime(LocalDateTimeUtil.nowTimeStamp()); |
| | | item.setCreateUser(loginUser.getUserId()); |
| | | item.setCreateUserName(loginUser.getNickName()); |
| | |
| | | UserLoginPO user = userLoginMapper.getById(rechargeOrderPO.getUserId()); |
| | | UserLoginPO userLoginPO = new UserLoginPO(); |
| | | userLoginPO.setId(user.getId()); |
| | | //余额加上交易金额=充值后的余额 |
| | | userLoginPO.setBalance(userLoginPO.getBalance().add(trade.getTradeAmount())); |
| | | //将充值金额转换为水量 |
| | | List<SysDictDataPO> feesAmount = sysDictDataMapper.getListByType("fees_amount"); |
| | | if(ListUtil.isNotNullOrEmpty(feesAmount)){ |
| | | SysDictDataPO sysDictDataPO = feesAmount.get(0); |
| | | BigDecimal bigDecimal = trade.getTradeAmount().multiply(new BigDecimal(sysDictDataPO.getDictValue())).setScale(2, BigDecimal.ROUND_DOWN); |
| | | userLoginPO.setBalance(userLoginPO.getBalance().add(bigDecimal)); |
| | | }else { |
| | | //默认单价 |
| | | BigDecimal bigDecimal = trade.getTradeAmount().multiply(new BigDecimal(3)).setScale(2, BigDecimal.ROUND_DOWN); |
| | | userLoginPO.setBalance(userLoginPO.getBalance().add(bigDecimal)); |
| | | } |
| | | int modify = userLoginMapper.updateById(userLoginPO); |
| | | //添加资金明细记录 |
| | | UserCapitalChangePO changePO = new UserCapitalChangePO(); |