doum
8 小时以前 eec6d612475e5080a9d3148d9c6ef20104a77b13
server/dmmall_service/src/main/java/com/doumee/service/business/impl/IntegralServiceImpl.java
@@ -422,7 +422,86 @@
        return PageData.from(result);
    }
    @Override
    @Transactional
    public void updateIntegral(Integral param) {
        if(param.getMemberId()==null || param.getType()==null
                || param.getType()<0
                || param.getType()>2
                || Constants.formatBigdecimal(param.getNum()).compareTo(new BigDecimal(0))<=0){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        Date date = new Date();
        Integral integral = new Integral();
        Constants.IntegralObjType integralObjType =null;
        if(Constants.equalsInteger(param.getUserType(), Constants.ZERO)){
            MPJLambdaWrapper<Member> queryWrapper =new MPJLambdaWrapper<>();
            queryWrapper.selectAll(Member.class);
            queryWrapper.selectAs(Shop::getName,Member::getShopName);
            queryWrapper.leftJoin(Shop.class, Shop::getId,Member::getBindShopId);
            queryWrapper.eq(Member::getId,param.getMemberId());
            Member model = memberMapper.selectJoinOne(Member.class,queryWrapper);
            if(model == null ||Constants.equalsObject(model.getIsdeleted(),Constants.ONE)){
                throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"客户信息查询无效!");
            }
            BigDecimal num = param.getNum();
            if(param.getType() == 1 &&Constants.formatBigdecimal(model.getIntegral()).compareTo(param.getNum())<0){
                //如果是减少,判断用户余额是否满足
                num = num.multiply(new BigDecimal(-1));//减少
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"用户账户余额不足!");
            }
            //账户余额
            memberMapper.update(null,new UpdateWrapper<Member>().lambda()
                    .eq(Member::getId,model.getId())
                    .set(Member::getEditDate,date)
                    .set(Member::getEditor,user.getId())
                    .setSql(param.getType() == 0,"total_integral = ifnull(total_integral,0)+" + num)//累计增加
                    .setSql(param.getType() == 0,"integral = ifnull(integral,0)+" + param.getNum())
                    .setSql(param.getType() == 1,"integral = ifnull(integral,0)-" + param.getNum()));
            integralObjType = param.getType()==0?Constants.IntegralObjType.SYSTEM_RECHARGE:Constants.IntegralObjType.SYSTEM_DEDUCT;
            integral.setTotalNum(param.getType() == 0? Constants.formatBigdecimal(model.getIntegral()).add(integral.getNum()):Constants.formatBigdecimal(model.getIntegral()).subtract(integral.getNum()));
        }else{
            Shop model = shopMapper.selectById(param.getMemberId());
            if(model == null ||Constants.equalsObject(model.getIsdeleted(),Constants.ONE)){
                throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"经销商信息查询无效!");
            }
            BigDecimal num = param.getNum();
            if(param.getType() == 1 &&Constants.formatBigdecimal(model.getIntegral()).compareTo(param.getNum())<0){
                //如果是减少,判断用户余额是否满足
                num = num.multiply(new BigDecimal(-1));//减少
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"经销商账户积分余额不足!");
            }
            //账户余额
            shopMapper.update(null,new UpdateWrapper<Shop>().lambda()
                    .eq(Shop::getId,model.getId())
                    .set(Shop::getEditDate,date)
                    .set(Shop::getEditor,user.getId())
                    .setSql(param.getType() == 0,"total_integral = ifnull(total_integral,0)+" + num)//累计增加
                    .setSql(param.getType() == 0,"integral = ifnull(integral,0)+" + param.getNum())
                    .setSql(param.getType() == 1,"integral = ifnull(integral,0)-" + param.getNum()));
             integralObjType = param.getType()==0?Constants.IntegralObjType.SHOP_SYSTEM_RECHARGE:Constants.IntegralObjType.SHOP_SYSTEM_DEDUCT;
            integral.setTotalNum(param.getType() == 0? Constants.formatBigdecimal(model.getIntegral()).add(integral.getNum()):Constants.formatBigdecimal(model.getIntegral()).subtract(integral.getNum()));
        }
        integral.setCreateDate(new Date());
        integral.setCreator(user.getId());
        integral.setIsdeleted(Constants.ZERO);
        integral.setNum(param.getNum());
        integral.setTitle(integralObjType.getName());
        integral.setContent(integralObjType.getNoteinfo().replace("${param}",integral.getNum().toString()));
        integral.setMemberId(param.getMemberId());
        integral.setObjId(param.getMemberId());
        integral.setObjType(integralObjType.getKey());
        integral.setType(param.getType());
        integral.setRemark(param.getRemark());
        integral.setOrderCode(null);
        integral.setUserType(Constants.ZERO);
        integralMapper.insert(integral);
    }
    @Override
    public IntegralDataResponse getIntegralData(IntegralRecordDTO model){
        IntegralDataResponse integralDataResponse = new IntegralDataResponse();