You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
package com.example.demo.serviceImpl.coin;
import com.example.demo.domain.entity.UserGoldRecord;import com.example.demo.domain.vo.bean.BeanUserCard;import com.example.demo.mapper.bean.BeanUserMapper;import com.example.demo.mapper.coin.MarketMapper;import com.example.demo.mapper.coin.RechargeMapper;import com.example.demo.mapper.coin.UserMapper;import com.example.demo.service.coin.MarketService;import com.example.demo.service.coin.RechargeService;import com.github.pagehelper.PageHelper;import com.github.pagehelper.PageInfo;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import com.example.demo.domain.vo.coin.*;
import java.math.BigDecimal;import java.time.LocalDate;import java.time.LocalDateTime;import java.time.format.DateTimeFormatter;import java.util.Date;import java.util.List;import java.util.Random;import java.util.UUID;
/** * @program: gold-java * @ClassName RechrageServceImpl * @description: * @author: Double * @create: 2025−06-29 13:40 * @Version 1.0 **/
@Servicepublic class RechargeServiceImpl implements RechargeService {
@Autowired private RechargeMapper rechargeMapper;
@Autowired private UserMapper userMapper;
@Autowired private MarketMapper marketMapper;
@Autowired private BeanUserMapper beanUserMapper;
//查询所有充值
@Override public PageInfo<RechargeUser> selectAll(Integer pageNum, Integer pageSize, RechargeUser rechargeUser) throws Exception{ //获取市场id
List<String> markets = marketMapper.getMarketIds(rechargeUser.getMarkets()); rechargeUser.setMarkets(markets); PageHelper.startPage(pageNum, pageSize); //必须要直接跟mapper
List<RechargeUser> rechargeUsers = rechargeMapper.selectAll(rechargeUser); return new PageInfo<>(rechargeUsers); }
//查询筛选充值
@Override public PageInfo<RechargeUser> selectBy(Integer pageNum, Integer pageSize, RechargeUser rechargeUser) throws Exception{ List<String> markets = marketMapper.getMarketIds(rechargeUser.getMarkets()); if (markets.contains("9") || markets.contains("9999")){ markets=null; } rechargeUser.setMarkets(markets); PageHelper.startPage(pageNum, pageSize); //必须要直接跟mapper
List<RechargeUser> rechargeUsers = rechargeMapper.selectBy(rechargeUser); return new PageInfo<>(rechargeUsers); }
//统计金币记录
@Override public Gold statsGold(RechargeUser rechargeUser) { List<String> markets = marketMapper.getMarketIds(rechargeUser.getMarkets()); if (markets.contains("9") || markets.contains("9999")){ markets=null;
} rechargeUser.setMarkets(markets); Gold gold = rechargeMapper.sumGold(rechargeUser); return gold; }
//添加充值记录
@Override public Result add(RechargeUser rechargeUser) { if(rechargeUser.getFreeGold()==null||rechargeUser.getPermanentGold()==null||rechargeUser.getMoney()==null){ return Result.error("金币和金额不能为空"); } if(rechargeUser.getFreeGold().compareTo(BigDecimal.ZERO)<0||rechargeUser.getPermanentGold().compareTo(BigDecimal.ZERO)<0||rechargeUser.getMoney().compareTo(BigDecimal.ZERO)<0){ return Result.error("充值不能为0"); } if(rechargeUser.getJwcode()<10000000||rechargeUser.getJwcode()>99999999) { return Result.error("精网号位数小于8位或大于8位"); } // 验证免费金币和永久金币是否均为0
if (rechargeUser.getFreeGold().compareTo(BigDecimal.ZERO) == 0 && rechargeUser.getPermanentGold().compareTo(BigDecimal.ZERO) == 0) { return Result.error("免费金币和永久金币不能同时为0"); } GoldUser goldUser = userMapper.selectUser(rechargeUser.getJwcode().toString()); if(goldUser==null){ return Result.error("用户不存在"); }
UserGoldRecord userGoldRecord = new UserGoldRecord();
String orderNumber = UUID.randomUUID().toString().replaceAll("-", "");
//订单号生成
userGoldRecord.setOrderCode("CZ_" + orderNumber); userGoldRecord.setJwcode(rechargeUser.getJwcode()); userGoldRecord.setActivity(rechargeUser.getActivity()); userGoldRecord.setPermanentGold(rechargeUser.getPermanentGold().intValue()); // 获取当前月份(1-12)
int currentMonth = LocalDate.now().getMonthValue(); // 根据当前月份设置对应字段
if (currentMonth >= 1 && currentMonth <= 6) { // 1-6月:设置6月额度,12月保持默认值
userGoldRecord.setFreeJune(0); userGoldRecord.setFreeDecember(rechargeUser.getFreeGold().intValue()); } else { // 7-12月:设置12月额度,6月保持默认值
userGoldRecord.setFreeJune(rechargeUser.getFreeGold().intValue()); userGoldRecord.setFreeDecember(0); } //数据输入
userGoldRecord.setSumGold(rechargeUser.getFreeGold().intValue()+rechargeUser.getPermanentGold().intValue()); userGoldRecord.setRateId(rechargeUser.getRateId()); userGoldRecord.setMoney(rechargeUser.getMoney().intValue()); userGoldRecord.setVoucher(rechargeUser.getVoucher()); userGoldRecord.setPayPlatform("金币系统"); userGoldRecord.setPayModel(rechargeUser.getPayModel()); userGoldRecord.setPayTime(rechargeUser.getPayTime()); userGoldRecord.setRemark(rechargeUser.getRemark()); userGoldRecord.setAdminId(rechargeUser.getAdminId()); userGoldRecord.setType((byte) 0); userGoldRecord.setAuditStatus(0); userGoldRecord.setCreateTime(new Date()); rechargeMapper.add(userGoldRecord); return Result.success(); }}
|