| | |
| | | import com.mzl.flower.config.exception.ValidationException; |
| | | import com.mzl.flower.config.security.SecurityUtils; |
| | | import com.mzl.flower.constant.Constants; |
| | | import com.mzl.flower.dto.request.menber.MemberGrowthRecordDTO; |
| | | import com.mzl.flower.dto.request.menber.MemberRecordQueryDTO; |
| | | import com.mzl.flower.dto.request.menber.TargetMemberDTO; |
| | | import com.mzl.flower.dto.request.menber.UserGrowthRecordDTO; |
| | | import com.mzl.flower.dto.request.menber.*; |
| | | import com.mzl.flower.dto.response.customer.CustomerDTO; |
| | | import com.mzl.flower.dto.response.member.MemberGrowthRecordVO; |
| | | import com.mzl.flower.dto.response.member.UserGrowthRecordVO; |
| | | 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; |
| | |
| | | |
| | | //保存会员记录逻辑: |
| | | if (Constants.GROWTH_SOURCE.consume.name().equals(memberGrowthRecordDTO.getSource())) { |
| | | //消费:成长值=消费金额/消费金额(元)*已消费产生的成长值 |
| | | //消费:成长值=消费金额/消费金额(元)*已消费产生的成长值C |
| | | BigDecimal totalAmount = memberGrowthRecordDTO.getTotalAmount(); |
| | | int consumptionAmount = memberBefore.getConsumptionAmount(); |
| | | int growthValue = memberBefore.getGrowthValue(); |
| | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public Page<UserGrowthRecordVO> queryUserPage(UserMemberRecordQueryDTO userMemberRecordQueryDTO, Page page) { |
| | | List<UserGrowthRecordVO> list = memberGrowthRecordMapper.queryUserPage(userMemberRecordQueryDTO, page); |
| | | page.setRecords(list); |
| | | return page; |
| | | } |
| | | } |