cloudroam
2024-09-03 e32fe26a1945fb44100d06b7049ccce865b11d4a
src/main/java/com/mzl/flower/service/menber/impl/MemberGrowthRecordServiceImpl.java
@@ -14,6 +14,7 @@
import com.mzl.flower.entity.customer.Customer;
import com.mzl.flower.entity.menber.Member;
import com.mzl.flower.entity.menber.MemberGrowthRecord;
import com.mzl.flower.entity.payment.Order;
import com.mzl.flower.mapper.customer.CustomerMapper;
import com.mzl.flower.mapper.member.MemberGrowthRecordMapper;
import com.mzl.flower.mapper.member.MemberMapper;
@@ -77,7 +78,7 @@
        //保存会员记录逻辑:
        if (Constants.GROWTH_SOURCE.consume.name().equals(memberGrowthRecordDTO.getSource())) {
            //消费:成长值=消费金额/消费金额(元)*已消费产生的成长值
            //消费:成长值=消费金额/消费金额(元)*已消费产生的成长值C
            BigDecimal totalAmount = memberGrowthRecordDTO.getTotalAmount();
            int consumptionAmount = memberBefore.getConsumptionAmount();
            int growthValue = memberBefore.getGrowthValue();
@@ -169,4 +170,39 @@
        page.setRecords(list);
        return page;
    }
    @Override
    public void growthValueDeduct(Order order) {
        //超过30天不到90天,每天处理当前会员等级的成长值
        CustomerDTO customerDTO = customerMapper.getCurrentCustomer(order.getCreateBy());
        Customer customer = customerMapper.selectById(customerDTO.getId());
        Member member = memberMapper.selectById(customer.getLevelId());
        if(ObjectUtils.isEmpty(member)){
            throw new ValidationException("用户会员等级未维护");
        }
        int deductGrowthValue = member.getDowngradeValue();
        Integer sumGrowthByUserId = memberGrowthRecordMapper.getSumGrowthByUsertId(order.getCreateBy());
        //当前成长值如果是等于0不需要走扣除逻辑
        if (sumGrowthByUserId != 0) {
        int waitDeductGrowthValue = 0;
        //判断当前用户的成长值是够扣除,如果够扣除直接减去成长值,如果不够扣除则全部减去
        if (sumGrowthByUserId - deductGrowthValue > 0) {
            waitDeductGrowthValue = deductGrowthValue;
        } else {
            waitDeductGrowthValue = sumGrowthByUserId;
        }
        //保存会员成长记录到记录表
        MemberGrowthRecordDTO memberGrowthRecordDTO = new MemberGrowthRecordDTO();
        memberGrowthRecordDTO.setUserId(order.getCreateBy());
        memberGrowthRecordDTO.setRecordDate(new Date());
        memberGrowthRecordDTO.setGrowth(-waitDeductGrowthValue);
        memberGrowthRecordDTO.setSource(Constants.GROWTH_SOURCE.downgrading.name());
        memberGrowthRecordDTO.setType(Constants.GROWTH_TYPE.reduce.name());
        memberGrowthRecordDTO.setRemarks("自动扣除");
        saveMemberGrowthRecord(memberGrowthRecordDTO);
        }
    }
}