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.

118 lines
5.0 KiB

package com.example.demo.serviceImpl;
import com.example.demo.domain.entity.User;
import com.example.demo.domain.entity.UserGoldRecord;
import com.example.demo.domain.vo.Gold;
import com.example.demo.domain.vo.RechargeAudit;
import com.example.demo.domain.vo.RefundAudit;
import com.example.demo.mapper.AuditMapper;
import com.example.demo.service.AuditService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @program: gold-java
* @ClassName AuditServiceImpl
* @description: 审核模块
* @author: Ethan
* @create: 2025−06-19 17:38
* @Version 1.0
**/
@Service
public class AuditServiceImpl implements AuditService {
@Autowired
private AuditMapper auditMapper;
/*
审核订单并修改用户余额等
*/
@Override
public boolean auditOrder(String token, String orderCode, Integer auditId, Integer action,String rejectReason) {
UserGoldRecord order=auditMapper.selectOrderByOrderCode(orderCode);
if (order == null || order.getAuditStatus() != 0) {
throw new IllegalArgumentException("订单不存在或已被审核");
}
//更新订单的审核状态和审核人
UserGoldRecord updateOrder = new UserGoldRecord();
updateOrder.setOrderCode(orderCode);
updateOrder.setAuditId(auditId);
//判断是通过还是驳回
if (action==2){ //驳回
updateOrder.setAuditStatus(2);
updateOrder.setRejectReason(rejectReason);
auditMapper.updateOrder(updateOrder);
return true;
}else if (action==1) { //通过
updateOrder.setAuditStatus(1);
}
// 执行审核更新
auditMapper.updateOrder(updateOrder);
//判断是充值还是退款
if (order.getType()==0){ //充值
//更新用户余额
User update = new User();
update.setJwcode(order.getJwcode()); //精网号
update.setSumPermanentGold(order.getPermanentGold()); //历史永久金币
update.setSumFreeJune(order.getFreeJune()); //历史六月免费金币
update.setSumFreeDecember(order.getFreeDecember()); //历史十二月免费金币
update.setSumTaskGold(order.getTaskGold()); //历史任务金币
update.setCurrentPermanentGold(order.getPermanentGold()); //当前永久金币
update.setCurrentFreeJune(order.getFreeJune()); //当前六月免费金币
update.setCurrentFreeDecember(order.getFreeDecember()); //当前十二月免费金币
update.setCurrentTaskGold(order.getTaskGold()); //当前任务金币
auditMapper.updateUserGold(update);
}else if (order.getType()==2) { //退款
//1.更新用户余额,并标记对应的消费订单为已退款
User update = new User();
update.setJwcode(order.getJwcode());
update.setCurrentPermanentGold(order.getPermanentGold()); //当前永久金币
update.setCurrentFreeJune(order.getFreeJune()); //当前六月免费金币
update.setCurrentFreeDecember(order.getFreeDecember()); //当前十二月免费金币
update.setCurrentTaskGold(order.getTaskGold()); //当前任务金币
auditMapper.updateUserGold(update);
//2.获取对应的消费订单(退款订单号去掉开头"TK"即为对应消费订单)
String consumeOrderCode = order.getOrderCode().replaceFirst("TK", "");
//3.更新消费订单是否已退款状态为1
UserGoldRecord consumeOrder = auditMapper.selectOrderByOrderCode(consumeOrderCode);
if (consumeOrderCode != null&&consumeOrder.getType()==1){ //确保是消费订单
auditMapper.updateOrderRefund(consumeOrderCode);
}else {
throw new IllegalArgumentException("找不到对应的订单或不是有效订单");
}
}
return true;
}
/*
* 多条件查询充值订单列表
*/
@Override
public PageInfo<RechargeAudit> selectRechargeBy(Integer pageNum, Integer pageSize, RechargeAudit rechargeAudit) {
PageHelper.startPage(pageNum, pageSize);
List<RechargeAudit> rechargeAudits = auditMapper.selectRechargeBy(pageNum, pageSize, rechargeAudit);
return new PageInfo<>(rechargeAudits);
}
@Override
public PageInfo<RefundAudit> selectRefundBy(Integer pageNum, Integer pageSize, RefundAudit refundAudit) {
PageHelper.startPage(pageNum, pageSize);
List<RefundAudit> refundAudits = auditMapper.selectRefundBy(pageNum, pageSize, refundAudit);
return new PageInfo<>(refundAudits);
}
/*
金币合计数
*/
@Override
public Gold sumRechargeGold() {
Gold gold = new Gold();
//获取充值审核订单列表
List<RechargeAudit> rechargeAudits = auditMapper.selectRechargeBy(1, 1000, null);
return null;
}
}