1
This commit is contained in:
parent
94f046d44c
commit
a6184dfb36
@ -25,6 +25,21 @@ public class CustomerBalanceController {
|
|||||||
@Resource
|
@Resource
|
||||||
private CustomerBalanceService customerBalanceService;
|
private CustomerBalanceService customerBalanceService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付完成回调
|
||||||
|
* @author PQZ
|
||||||
|
* @date 21:42 2024/9/23
|
||||||
|
* @param createReqVO CustomerBalanceSaveReqVO
|
||||||
|
* @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.lang.Boolean>
|
||||||
|
**/
|
||||||
|
@PostMapping("/saveBalance")
|
||||||
|
@Operation(summary = "创建用户积分(余额)")
|
||||||
|
@PreAuthorize("@ss.hasPermission('base:customer-balance:create')")
|
||||||
|
public CommonResult<Boolean> saveBalance(@RequestBody CustomerBalanceSaveReqVO createReqVO) {
|
||||||
|
customerBalanceService.saveBalance(createReqVO.getCusId(),createReqVO.getOrderId(),createReqVO.getActiveId());
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@Operation(summary = "创建用户积分(余额)")
|
@Operation(summary = "创建用户积分(余额)")
|
||||||
@PreAuthorize("@ss.hasPermission('base:customer-balance:create')")
|
@PreAuthorize("@ss.hasPermission('base:customer-balance:create')")
|
||||||
@ -40,4 +55,6 @@ public class CustomerBalanceController {
|
|||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -19,6 +19,7 @@ import cn.iocoder.yudao.module.member.vo.ActiveMainRespVO;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.mzt.logapi.service.IFunctionService;
|
import com.mzt.logapi.service.IFunctionService;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
@ -57,6 +58,7 @@ public class CustomerActiveServiceImpl extends ServiceImpl<CustomerActiveMapper,
|
|||||||
@Resource
|
@Resource
|
||||||
private CustomerCouponService customerCouponService;
|
private CustomerCouponService customerCouponService;
|
||||||
@Resource
|
@Resource
|
||||||
|
@Lazy
|
||||||
private CustomerBalanceService balanceService;
|
private CustomerBalanceService balanceService;
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,13 +8,27 @@ import cn.iocoder.yudao.module.custom.service.CustomerBalanceService;
|
|||||||
import cn.iocoder.yudao.module.custom.service.CustomerMainService;
|
import cn.iocoder.yudao.module.custom.service.CustomerMainService;
|
||||||
import cn.iocoder.yudao.module.custom.vo.CustomerBalanceSaveReqVO;
|
import cn.iocoder.yudao.module.custom.vo.CustomerBalanceSaveReqVO;
|
||||||
import cn.iocoder.yudao.module.custom.vo.CustomerMainRespVO;
|
import cn.iocoder.yudao.module.custom.vo.CustomerMainRespVO;
|
||||||
|
import cn.iocoder.yudao.module.member.entity.ActiveRule;
|
||||||
|
import cn.iocoder.yudao.module.member.service.ActiveMainService;
|
||||||
|
import cn.iocoder.yudao.module.member.vo.ActiveMainRespVO;
|
||||||
|
import cn.iocoder.yudao.module.order.entity.RepairOrderInfo;
|
||||||
|
import cn.iocoder.yudao.module.order.service.RepairOrderInfoService;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.common.BaseConstants.GENERAL_YES;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户积分(余额) Service 实现类
|
* 用户积分(余额) Service 实现类
|
||||||
@ -29,6 +43,12 @@ public class CustomerBalanceServiceImpl extends ServiceImpl<CustomerBalanceMappe
|
|||||||
private CustomerBalanceMapper customerBalanceMapper;
|
private CustomerBalanceMapper customerBalanceMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private CustomerMainService customerMainService;
|
private CustomerMainService customerMainService;
|
||||||
|
@Resource
|
||||||
|
@Lazy
|
||||||
|
private RepairOrderInfoService orderInfoService;
|
||||||
|
@Resource
|
||||||
|
@Lazy
|
||||||
|
private ActiveMainService activeMainService;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -50,9 +70,57 @@ public class CustomerBalanceServiceImpl extends ServiceImpl<CustomerBalanceMappe
|
|||||||
* @date 21:04 2024/9/23
|
* @date 21:04 2024/9/23
|
||||||
**/
|
**/
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void saveBalance(String cusId, String orderId, String activeId) {
|
public void saveBalance(String cusId, String orderId, String activeId) {
|
||||||
//查询当前登录用户信息
|
//查询当前登录用户信息
|
||||||
CustomerMainRespVO customer = customerMainService.getCustomerById(cusId);
|
CustomerMainRespVO customer = customerMainService.getCustomerById(cusId);
|
||||||
|
//查询订单表数据
|
||||||
|
RepairOrderInfo orderInfo = orderInfoService.getById(orderId);
|
||||||
|
CustomerBalance balance;
|
||||||
|
if (null != activeId) {
|
||||||
|
//获取当前活动信息
|
||||||
|
ActiveMainRespVO active = activeMainService.getActiveMain(activeId, true);
|
||||||
|
balance = transBalance(customer, orderInfo.getPayMoney(), active.getRuleList());
|
||||||
|
}
|
||||||
|
balance = transBalance(customer, orderInfo.getPayMoney(), null);
|
||||||
|
orderInfo.setOrderStatus(GENERAL_YES);
|
||||||
|
orderInfo.setPayTime(LocalDateTime.now());
|
||||||
|
orderInfoService.updateById(orderInfo);
|
||||||
|
updateByCusId(balance);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转换余额
|
||||||
|
*
|
||||||
|
* @param customer 用户信息
|
||||||
|
* @param amount 实际充值金额
|
||||||
|
* @param ruleList 规则
|
||||||
|
* @return cn.iocoder.yudao.module.custom.entity.CustomerBalance
|
||||||
|
* @author PQZ
|
||||||
|
* @date 11:30 2024/9/21
|
||||||
|
**/
|
||||||
|
CustomerBalance transBalance(CustomerMainRespVO customer, BigDecimal amount, List<ActiveRule> ruleList) {
|
||||||
|
CustomerBalance result = new CustomerBalance();
|
||||||
|
result.setCusId(customer.getId());
|
||||||
|
result.setUserId(customer.getUserId());
|
||||||
|
BigDecimal nowChange = amount;
|
||||||
|
if (null != ruleList && !ruleList.isEmpty()) {
|
||||||
|
List<ActiveRule> sortList = ruleList.stream().sorted(Comparator.comparing(ActiveRule::getRechAmount).reversed()).collect(Collectors.toList());
|
||||||
|
for (ActiveRule item : sortList) {
|
||||||
|
//如果规则匹配
|
||||||
|
if (amount.compareTo(item.getRechAmount()) >= 0) {
|
||||||
|
nowChange = amount.add(item.getGiveAmount());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//余额
|
||||||
|
result.setBalance(customer.getBalance().add(nowChange));
|
||||||
|
//累计充值金额
|
||||||
|
result.setAllBalance(customer.getBalance().add(nowChange));
|
||||||
|
//本次变动金额
|
||||||
|
result.setNowChange(nowChange);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -73,7 +141,7 @@ public class CustomerBalanceServiceImpl extends ServiceImpl<CustomerBalanceMappe
|
|||||||
@Override
|
@Override
|
||||||
public void updateByCusId(CustomerBalance balance) {
|
public void updateByCusId(CustomerBalance balance) {
|
||||||
LambdaQueryWrapper<CustomerBalance> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<CustomerBalance> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
lambdaQueryWrapper.eq(CustomerBalance::getCusId,balance.getCusId()).eq(BaseDO::getDeleted,'0');
|
lambdaQueryWrapper.eq(CustomerBalance::getCusId, balance.getCusId()).eq(BaseDO::getDeleted, '0');
|
||||||
remove(lambdaQueryWrapper);
|
remove(lambdaQueryWrapper);
|
||||||
this.save(balance);
|
this.save(balance);
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import java.math.BigDecimal;
|
|||||||
@Schema(description = "管理后台 - 用户积分(余额)新增/修改 Request VO")
|
@Schema(description = "管理后台 - 用户积分(余额)新增/修改 Request VO")
|
||||||
@Data
|
@Data
|
||||||
public class CustomerBalanceSaveReqVO extends CustomerBalance {
|
public class CustomerBalanceSaveReqVO extends CustomerBalance {
|
||||||
|
private String activeId;
|
||||||
|
private String orderId;
|
||||||
|
|
||||||
}
|
}
|
@ -75,11 +75,11 @@ public class RepairOrderInfo extends TenantBaseDO {
|
|||||||
/**
|
/**
|
||||||
* 会员优惠金额
|
* 会员优惠金额
|
||||||
*/
|
*/
|
||||||
private Long reduceMoney;
|
private BigDecimal reduceMoney;
|
||||||
/**
|
/**
|
||||||
* 使用会员储值卡的金额
|
* 使用会员储值卡的金额
|
||||||
*/
|
*/
|
||||||
private Long balance;
|
private BigDecimal balance;
|
||||||
/**
|
/**
|
||||||
* 支付时间
|
* 支付时间
|
||||||
*/
|
*/
|
||||||
@ -152,6 +152,10 @@ public class RepairOrderInfo extends TenantBaseDO {
|
|||||||
* 创建人所在部门
|
* 创建人所在部门
|
||||||
*/
|
*/
|
||||||
private Integer deptId;
|
private Integer deptId;
|
||||||
|
/**
|
||||||
|
* 创建人所在部门
|
||||||
|
*/
|
||||||
|
private String tenantName;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user