陶杰
2024-11-14 d94e7d6bbf23698c27147a60ee866c64b2d43775
Merge remote-tracking branch 'origin/master-v4' into master-v4
已修改5个文件
92 ■■■■■ 文件已修改
src/main/java/com/mzl/flower/dto/response/customer/CustomerDTO.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/service/point/CustomerPointService.java 79 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/customer/CustomerMapper.xml 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/payment/OrderItemMapper.xml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/payment/OrderMapper.xml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/dto/response/customer/CustomerDTO.java
@@ -58,4 +58,6 @@
    private Boolean isEnabled;
    private UserGrowthRecordDTO userGrowthRecord;
    private Integer orderNum;
}
src/main/java/com/mzl/flower/service/point/CustomerPointService.java
@@ -15,6 +15,7 @@
import com.mzl.flower.mapper.point.CustomerPointDetailMapper;
import com.mzl.flower.mapper.point.CustomerPointMapper;
import com.mzl.flower.service.BaseService;
import com.mzl.flower.service.payment.RedisLockService;
import com.mzl.flower.utils.DateUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
@@ -36,10 +37,13 @@
    private final CustomerPointDetailMapper customerPointDetailMapper;
    private final  RedisLockService redisLockService;
    public CustomerPointService(CustomerPointMapper customerPointMapper, CustomerPointDetailMapper customerPointDetailMapper) {
    public CustomerPointService(CustomerPointMapper customerPointMapper, CustomerPointDetailMapper customerPointDetailMapper, RedisLockService redisLockService) {
        this.customerPointMapper = customerPointMapper;
        this.customerPointDetailMapper = customerPointDetailMapper;
        this.redisLockService = redisLockService;
    }
    public Page<CustomerPointDTO> queryPage(QueryCustomerPointDTO dto, Page page) {
@@ -79,44 +83,51 @@
    }
    public void updateCustomerPoint(CustomerPointDetail detail) {
        CustomerPoint point = customerPointMapper.selectOne(new LambdaQueryWrapper<CustomerPoint>()
                .eq(CustomerPoint::getCustomerId, detail.getCustomerId()));
        boolean isAdd = false;
        if(point == null){
            isAdd = true;
            point = new CustomerPoint();
            point.setCustomerId(detail.getCustomerId());
            point.setUserId(detail.getUserId());
            point.setTotalPoint(0);
            point.setUsedPoint(0);
            point.setExpiredPoint(0);
            point.setDeductionPoint(0);
            point.create(SecurityUtils.getUserId());
        boolean lock = redisLockService.getObjectLock("LOCK_KEY_CUSTOMER_POINT_", detail.getUserId());
        if(!lock){
            return;
        }
        try {
            CustomerPoint point = customerPointMapper.selectOne(new LambdaQueryWrapper<CustomerPoint>()
                    .eq(CustomerPoint::getCustomerId, detail.getCustomerId()));
            boolean isAdd = false;
            if(point == null){
                isAdd = true;
                point = new CustomerPoint();
                point.setCustomerId(detail.getCustomerId());
                point.setUserId(detail.getUserId());
                point.setTotalPoint(0);
                point.setUsedPoint(0);
                point.setExpiredPoint(0);
                point.setDeductionPoint(0);
                point.create(SecurityUtils.getUserId());
            }
        if(POINT_CHANGE_TYPE.add.name().equals(detail.getChangeType())){
            point.setTotalPoint(point.getTotalPoint() + detail.getPoint());
        }else if(POINT_CHANGE_TYPE.reduce.name().equals(detail.getChangeType())){
            Integer detailPoint = detail.getPoint();
            if(POINT_TYPE.deduction.name().equals(detail.getType())){ //积分扣减
                Integer balancePoint = point.getTotalPoint() - point.getUsedPoint()-point.getExpiredPoint()-point.getDeductionPoint();//可用积分
                balancePoint = balancePoint.intValue()>0?balancePoint.intValue():0;
                if(balancePoint.intValue() >= detail.getPoint().intValue()){
                    point.setDeductionPoint(point.getDeductionPoint() + detail.getPoint());
                }else{
                    //积分不足,直接清0
                    point.setDeductionPoint(point.getDeductionPoint() + balancePoint);
                    detail.setPoint(balancePoint);
                    detail.setRemarks(detail.getRemarks()+",当前积分不足"+detailPoint+",实际扣除积分"+balancePoint);
            if(POINT_CHANGE_TYPE.add.name().equals(detail.getChangeType())){
                point.setTotalPoint(point.getTotalPoint() + detail.getPoint());
            }else if(POINT_CHANGE_TYPE.reduce.name().equals(detail.getChangeType())){
                Integer detailPoint = detail.getPoint();
                if(POINT_TYPE.deduction.name().equals(detail.getType())){ //积分扣减
                    Integer balancePoint = point.getTotalPoint() - point.getUsedPoint()-point.getExpiredPoint()-point.getDeductionPoint();//可用积分
                    balancePoint = balancePoint.intValue()>0?balancePoint.intValue():0;
                    if(balancePoint.intValue() >= detail.getPoint().intValue()){
                        point.setDeductionPoint(point.getDeductionPoint() + detail.getPoint());
                    }else{
                        //积分不足,直接清0
                        point.setDeductionPoint(point.getDeductionPoint() + balancePoint);
                        detail.setPoint(balancePoint);
                        detail.setRemarks(detail.getRemarks()+",当前积分不足"+detailPoint+",实际扣除积分"+balancePoint);
                    }
                }
            }
            if(isAdd){
                customerPointMapper.insert(point);
            }else{
                customerPointMapper.updateById(point);
            }
        }finally {
            redisLockService.releaseObjectLock("LOCK_KEY_CUSTOMER_POINT_", detail.getUserId());
        }
        if(isAdd){
            customerPointMapper.insert(point);
        }else{
            customerPointMapper.updateById(point);
        }
    }
    public void deductionPoint(ChangePointDTO dto) {
src/main/resources/mapper/customer/CustomerMapper.xml
@@ -9,7 +9,8 @@
            c.*,
            p.name as partnerName,
            u.nick_name,
            u.tel
            u.tel,
            (select count(o.id) from t_order o where o.create_by = c.user_id  and o.deleted=0 and o.status_backend not in ('PENDING','CANCEL','REFUND')) as orderNum
        FROM
            t_customer_info c
                LEFT JOIN t_user u ON c.user_id = u.id left join t_partner_info p on c.partner_id = p.id where c.deleted = 0
src/main/resources/mapper/payment/OrderItemMapper.xml
@@ -76,8 +76,8 @@
        SELECT sum(oi.num)
        FROM t_order_item oi
        JOIN t_order o on oi.order_id = o.id
        WHERE o.payment_time is not null
        and o.refund_time is null
        WHERE o.deleted=0
        and o.status_backend not in ('PENDING','CANCEL','REFUND')
        <if test="startTime != null">
            and o.create_time &gt; #{startTime}
        </if>
src/main/resources/mapper/payment/OrderMapper.xml
@@ -374,8 +374,8 @@
    <select id="getOrderSaleAmount" resultType="java.math.BigDecimal">
        SELECT sum(o.payment_amount)
        FROM t_order o
        WHERE o.payment_time is not null
        and o.refund_time is null
        WHERE o.deleted=0
        and o.status_backend not in ('PENDING','CANCEL','REFUND')
        <if test="startTime != null">
            and o.create_time &gt; #{startTime}
        </if>