package com.hzs.activity.draw.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.activity.base.service.IAcApprovalLogService;
import com.hzs.activity.base.service.IAcBaseConfigService;
import com.hzs.activity.draw.mapper.AcDrawRewardNumMapper;
import com.hzs.activity.draw.param.AcDrawRewardNumParam;
import com.hzs.activity.draw.param.PurchasedTimesParam;
import com.hzs.activity.draw.service.IAcDrawRewardNumDetailService;
import com.hzs.activity.draw.service.IAcDrawRewardNumService;
import com.hzs.activity.draw.service.IAcDrawRuleConfigService;
import com.hzs.common.core.constant.*;
import com.hzs.common.core.constant.msg.CommonMsgConstants;
import com.hzs.common.core.domain.R;
import com.hzs.common.core.enums.*;
import com.hzs.common.core.service.RedisService;
import com.hzs.common.core.utils.CommonUtil;
import com.hzs.common.core.utils.ComputeUtil;
import com.hzs.common.core.utils.DateUtils;
import com.hzs.common.domain.activity.base.AcApprovalLog;
import com.hzs.common.domain.activity.draw.AcDrawRewardNum;
import com.hzs.common.domain.activity.draw.AcDrawRewardNumDetail;
import com.hzs.common.domain.activity.draw.AcDrawRuleConfig;
import com.hzs.common.domain.activity.draw.ext.AcDrawRewardNumExt;
import com.hzs.common.domain.member.account.CuMemberAccount;
import com.hzs.common.domain.member.base.CuMember;
import com.hzs.common.domain.member.detail.CuMemberServiceLog;
import com.hzs.common.domain.member.ext.CuMemberAccountExt;
import com.hzs.common.domain.sale.ext.SaOrderExt;
import com.hzs.common.util.TransactionUtils;
import com.hzs.member.account.IMemberAccountServiceApi;
import com.hzs.member.base.IMemberServiceApi;
import com.hzs.member.detail.ICuMemberServiceLogServiceApi;
import com.hzs.system.sys.IApprovalServiceApi;
import com.hzs.system.sys.dto.ApprovalBusinessResultDTO;
import com.hzs.system.sys.dto.ApprovalSubmitDTO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * 会员可抽奖次数记录 服务实现类
 *
 * @author hzs
 * @since 2023-04-21
 */
@Service
public class AcDrawRewardNumServiceImpl extends ServiceImpl<AcDrawRewardNumMapper, AcDrawRewardNum> implements IAcDrawRewardNumService {

    @Autowired
    private IAcApprovalLogService acApprovalLogService;

    @DubboReference
    IMemberAccountServiceApi memberAccountServiceApi;
    @DubboReference
    ICuMemberServiceLogServiceApi memberServiceLogServiceApi;
    @DubboReference
    IMemberServiceApi memberServiceApi;
    @DubboReference
    IApprovalServiceApi approvalServiceApi;

    private IAcDrawRuleConfigService acDrawRuleConfigService;

    private RedisService redisService;

    private IAcDrawRewardNumDetailService acDrawRewardNumDetailService;

    @Autowired
    public void setAcDrawRewardNumDetailService(IAcDrawRewardNumDetailService acDrawRewardNumDetailService) {
        this.acDrawRewardNumDetailService = acDrawRewardNumDetailService;
    }

    @Autowired
    public void setAcDrawRuleConfigService(IAcDrawRuleConfigService acDrawRuleConfigService) {
        this.acDrawRuleConfigService = acDrawRuleConfigService;
    }

    @Autowired
    public void setRedisService(RedisService redisService) {
        this.redisService = redisService;
    }

    @Autowired
    public IAcBaseConfigService iAcBaseConfigService;

    @Override
    public AcDrawRewardNum queryAcDrawRewardNum(AcDrawRewardNumParam acDrawRewardNumParam) {
        LambdaQueryWrapper<AcDrawRewardNum> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AcDrawRewardNum::getPkMember, acDrawRewardNumParam.getPkMember());
        queryWrapper.eq(AcDrawRewardNum::getPkCountry, acDrawRewardNumParam.getPkCountry());
        queryWrapper.eq(AcDrawRewardNum::getPkBaseId, acDrawRewardNumParam.getPkBaseId());
        return baseMapper.selectOne(queryWrapper);
    }

    @Override
    public List<AcDrawRewardNumExt> queryDrawRewardExtNumByCondition(AcDrawRewardNumParam acDrawRewardNumParam) {
        return baseMapper.queryDrawRewardExtNumByCondition(acDrawRewardNumParam);
    }

    @Override
    public Boolean updateAcDrawRewardNum(AcDrawRewardNum acDrawRewardNum) {
        String key = CacheConstants.DRAW_REWARD_NUMBER + acDrawRewardNum.getPkMember();
        boolean flag = redisService.lockKeyMany(key);
        try {
            if (flag) {
                LambdaUpdateWrapper<AcDrawRewardNum> updateWrapper = new LambdaUpdateWrapper<>();
                updateWrapper.eq(AcDrawRewardNum::getPkId, acDrawRewardNum.getPkId());
                updateWrapper.gt(AcDrawRewardNum::getAvailableSurplusNum, 0);
                updateWrapper.set(AcDrawRewardNum::getAvailableUsedNum, acDrawRewardNum.getAvailableUsedNum() + 1);
                updateWrapper.set(AcDrawRewardNum::getAvailableSurplusNum, acDrawRewardNum.getAvailableSurplusNum() - 1);
                update(updateWrapper);
            }
        } finally {
            redisService.unlock(key);
        }
        return null;
    }

    @Override
    public List<CuMemberAccountExt> queryMemberAccountByCondition(CuMemberAccount cuMemberAccount) {
        return memberAccountServiceApi.queryMemberAccountByCondition(cuMemberAccount).getData();
    }

    @Override
    public AcDrawRewardNumExt queryDrawRewardNumByCondition(AcDrawRewardNumParam acDrawRewardNumParam) {
        return baseMapper.queryDrawRewardNumByCondition(acDrawRewardNumParam);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void payDrawRewardNum(CuMemberAccountExt cuMemberAccountExt, Integer payNum, AcDrawRewardNumExt acDrawRewardNumExt) {
        // 更新次数，可用总次数 + 次数 剩余可抽奖总次数 +次数 已用用次数-次数 可用总次数-次数
        updateDrawRewardNum(payNum, acDrawRewardNumExt);
        // 更新会员账户、交易流水
        if (!memberServiceApi.updateCuMemberAccountByDraw(cuMemberAccountExt, ComputeUtil.computeMultiply(acDrawRewardNumExt.getPayMoney(), payNum)).getData()) {
            throw new RuntimeException();
        }
    }

    private void updateDrawRewardNum(Integer payNum, AcDrawRewardNumExt acDrawRewardNumExt) {
        LambdaUpdateWrapper<AcDrawRewardNum> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(AcDrawRewardNum::getPkId, acDrawRewardNumExt.getPkId());
        updateWrapper.set(AcDrawRewardNum::getTotalUsedNum, acDrawRewardNumExt.getTotalUsedNum() + payNum);
        updateWrapper.set(AcDrawRewardNum::getTotalSurplusNum, acDrawRewardNumExt.getTotalSurplusNum() - payNum);
        updateWrapper.set(AcDrawRewardNum::getAvailableNum, acDrawRewardNumExt.getAvailableNum() + payNum);
        updateWrapper.set(AcDrawRewardNum::getAvailableSurplusNum, acDrawRewardNumExt.getAvailableSurplusNum() + payNum);
        update(updateWrapper);
    }

    @Override
    public String confirmDrawRewardPayNum(AcDrawRewardNumParam acDrawRewardNumParam, AcDrawRewardNumExt acDrawRewardNum) {
        String orderCode = CommonUtil.createSerialNumber(EOrderPrefix.ON_LINE.getValue());
        acDrawRewardNumParam.setActCode(orderCode);
        acDrawRewardNumParam.setActType(EActType.LOTTERY_DRAW.getValue());
        acDrawRewardNumParam.setAcDrawRewardNum(acDrawRewardNum);
        // 放入redis
        redisService.setCacheObject(CacheConstants.TEMP_ORDER + acDrawRewardNumParam.getPkMember() + orderCode, acDrawRewardNumParam, CacheConstants.MEMBER_REFRESH_TIME, TimeUnit.MINUTES);
        return orderCode;
    }

    @Override
    public BigDecimal queryDrawRewardPayNumMoney(Long pkMember, String orderCode) {
        AcDrawRewardNumParam acDrawRewardNumParam = redisService.getCacheObject(CacheConstants.TEMP_ORDER + pkMember + orderCode);
        if (acDrawRewardNumParam == null) {
            return null;
        }
        AcDrawRewardNumExt acDrawRewardNum = acDrawRewardNumParam.getAcDrawRewardNum();
        return ComputeUtil.computeMultiply(acDrawRewardNum.getPayMoney(), acDrawRewardNumParam.getPayNum());
    }

    @Override
    public Boolean callBackOnlinePay(Long pkMember, String orderCode) {
        AcDrawRewardNumParam acDrawRewardNumParam = redisService.getCacheObject(CacheConstants.TEMP_ORDER + pkMember + orderCode);
        if (acDrawRewardNumParam == null) {
            return Boolean.FALSE;
        }
        // 支付
        // 更新次数，可用总次数 + 次数 剩余可抽奖总次数 +次数 已用用次数-次数 可用总次数-次数
        updateDrawRewardNum(acDrawRewardNumParam.getPayNum(), acDrawRewardNumParam.getAcDrawRewardNum());
        // 更新会员账户、交易流水
        if (!memberServiceApi.updateCuMemberAccountByDraw(acDrawRewardNumParam.getPayNum(), acDrawRewardNumParam.getAcDrawRewardNum()).getData()) {
            throw new RuntimeException();
        }
        return null;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean giveMemberDrawNum(SaOrderExt saOrderExt) {
        AcDrawRuleConfig acDrawRuleConfig = AcDrawRuleConfig.builder().orderType(saOrderExt.getOrderType()).orderAmount(saOrderExt.getOrderAmount()).orderAchieve(saOrderExt.getOrderAchieve()).build();
        acDrawRuleConfig.setPkCountry(saOrderExt.getPkCountry());
        List<AcDrawRuleConfig> acDrawRuleConfigList = acDrawRuleConfigService.queryDrawRuleConfigByCondition(acDrawRuleConfig);
        if (CollectionUtil.isNotEmpty(acDrawRuleConfigList)) {
            // 保存抽奖次数
            for (AcDrawRuleConfig drawRuleConfig : acDrawRuleConfigList) {
                // 购买人
                updateMemberDrawNum(saOrderExt.getPkMember(), saOrderExt, drawRuleConfig);
                // 推荐人
                updateMemberDrawNum(saOrderExt.getPkReference(), saOrderExt, drawRuleConfig);
            }
        }
        return Boolean.TRUE;
    }

    @Override
    public Boolean backGiveMemberDrawNum(SaOrderExt saOrderExt) {
        // 查询订单是否赠送过抽奖次数
        List<AcDrawRewardNumDetail> drawRewardNumDetailList = acDrawRewardNumDetailService.queryAcDrawRewardNumBySaOrder(saOrderExt.getPkId());
        if (CollectionUtil.isNotEmpty(drawRewardNumDetailList)) {
            for (AcDrawRewardNumDetail drawRewardNumDetail : drawRewardNumDetailList) {
                AcDrawRewardNum acDrawRewardNum = baseMapper.selectById(drawRewardNumDetail.getPkDrawRewardNum());
                acDrawRewardNum.setTotalNum(acDrawRewardNum.getTotalNum() - drawRewardNumDetail.getGiveNum());
                acDrawRewardNum.setTotalSurplusNum(acDrawRewardNum.getTotalSurplusNum() - drawRewardNumDetail.getGiveNum());
                acDrawRewardNum.setPkModified(saOrderExt.getPkCreator());
                acDrawRewardNum.setModifiedTime(DateUtils.currentDateTime());
                updateById(acDrawRewardNum);
                drawRewardNumDetail.setPkModified(saOrderExt.getPkCreator());
                acDrawRewardNumDetailService.deleteAcDrawRewardNumDetail(drawRewardNumDetail);
            }
        }
        return true;
    }

    /**
     * 充值已购买次数
     *
     * @param purchasedTimesParam
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void purchasedTimes(PurchasedTimesParam purchasedTimesParam) {
        purchasedTimesParam.setControlType(EControlType.MODIFY.getValue());
        //业务单号
        EApprovalBusiness approvalBusiness = EApprovalBusiness.PUR_CHASED_TIMES;
        submitApproval(purchasedTimesParam, approvalBusiness);
    }

    /**
     * 提交审批
     *
     * @param recommendParam 抽奖参数
     */
    public Boolean submitApproval(PurchasedTimesParam recommendParam, EApprovalBusiness approvalBusiness) {
        //保存审批日志
        AcApprovalLog approvalLog = saveApprovalLog(recommendParam, approvalBusiness);
        ApprovalSubmitDTO approvalSubmitDTO = ApprovalSubmitDTO.builder().eApprovalBusiness(approvalBusiness)
                .businessCode(approvalLog.getBusinessCode())
                .businessData(JSONObject.toJSONString(recommendParam)).fileList(recommendParam.getFileList())
                .signType(ESignType.getEnumByValue(recommendParam.getSignType())).userIdList(recommendParam.getUserIdList())
                .sendIdList(recommendParam.getSendIdList()).remark(recommendParam.getRemark()).fileList(recommendParam.getFileList())
                .build();
        R<String> submit = approvalServiceApi.submit(approvalSubmitDTO, recommendParam.getLoginUser());
        if (!submit.isSuccess()) {
            throw new RuntimeException("旅游活动参数提交审批失败！");
        }
        return submit.isSuccess();
    }

    /**
     * 保存活动审批日志信息
     *
     * @param recommendParam   直推赠送参数
     * @param approvalBusiness 审批业务
     * @return boolean
     */
    public AcApprovalLog saveApprovalLog(PurchasedTimesParam recommendParam, EApprovalBusiness approvalBusiness) {
        Integer controlType = recommendParam.getControlType();
        String afterData = JSONUtil.toJsonStr(recommendParam);
        String beforeData = controlType.equals(EControlType.SAVE.getValue()) ? JSONUtil.toJsonStr(recommendParam) : null;
        //业务单号
        String businessCode = CommonUtil.createSerialNumber(EOrderPrefix.ACTIVITY_CODE.getValue());
        recommendParam.setBusinessCode(businessCode);
        AcApprovalLog approvalLog = AcApprovalLog.builder().approvalType(approvalBusiness.getValue())
                .beforeData(beforeData).businessCode(businessCode).controlType(controlType)
                .approvalStatus(EApproveRechargeStatus.WAIT.getValue()).afterData(afterData)
                .build();
        approvalLog.setPkCreator(recommendParam.getPkMember());
        approvalLog.setPkCountry(recommendParam.getPkCountry());

        acApprovalLogService.save(approvalLog);
        return approvalLog;
    }

    /**
     * 修改已购买次数 （更新）
     *
     * @param pkMember
     * @param num
     * @param pkBaseId
     */
    @Override
    public Boolean updatePurchasedTimesByBaseId(Long pkMember, Integer num, Long pkBaseId) {
        try {
            baseMapper.updatePurchasedTimesByBaseId(pkMember, num, pkBaseId);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    /**
     * 修改已购买次数 审批通过
     *
     * @param approvalBusinessResultDTO
     * @return
     */
    @Override
    public String approvalAgree(ApprovalBusinessResultDTO approvalBusinessResultDTO) {
        R<CuMemberServiceLog> cuMemberServiceLogR = memberServiceLogServiceApi.selectByBusinessNo(approvalBusinessResultDTO.getBusinessCode());

        if (null == cuMemberServiceLogR) {
            log.error("修改已购买次数失败: 签呈不存在!");
            return TransactionUtils.getContent(CommonMsgConstants.APPROVAL_NOT_EXIST);
        }
        CuMemberServiceLog memberServiceLog = cuMemberServiceLogR.getData();
        JSONObject json = JSONObject.parseObject(memberServiceLog.getNewValue());
        Long pkMember = json.getLong("pkMember");
        Integer num = json.getInteger("num");
        Long pkBaseId = json.getLong("pkBaseId");
        updateTotalUsedNum(pkMember, num, pkBaseId, memberServiceLog.getPkCreator(), memberServiceLog.getPkCountry());
        // 更新 日志
        memberServiceLog.setApproveStatus(EApproveStatus.FINISH.getValue());
        memberServiceLogServiceApi.updateByBusinessNo(memberServiceLog);
        return null;
    }

    /**
     * 修改已购买次数 审批驳回
     *
     * @param approvalBusinessResultDTO
     * @return
     */
    @Override
    public String approvalReject(ApprovalBusinessResultDTO approvalBusinessResultDTO) {
        R<CuMemberServiceLog> cuMemberServiceLogR = memberServiceLogServiceApi.selectByBusinessNo(approvalBusinessResultDTO.getBusinessCode());

        if (null == cuMemberServiceLogR) {
            log.error("修改已购买次数失败: 签呈不存在!");
            return TransactionUtils.getContent(CommonMsgConstants.APPROVAL_NOT_EXIST);
        }
        // 更新 日志
        CuMemberServiceLog memberServiceLog = cuMemberServiceLogR.getData();
        memberServiceLog.setApproveStatus(EApproveStatus.REJECTED.getValue());
        memberServiceLogServiceApi.updateByBusinessNo(memberServiceLog);
        return null;
    }

    /**
     * 修改未购买次数 (审批发起)
     *
     * @param purchasedTimesParam
     * @return
     */
    @Override
    public void unpurchasedTimes(PurchasedTimesParam purchasedTimesParam) {
        purchasedTimesParam.setControlType(EControlType.MODIFY.getValue());
        //业务单号
        EApprovalBusiness approvalBusiness = EApprovalBusiness.UN_PUR_CHASED_TIMES;
        submitApproval(purchasedTimesParam, approvalBusiness);
    }

    /**
     * 充值已购买次数
     *
     * @param approvalBusinessResultDTO
     */
    @Override
    public void rechargePurchasedTimes(ApprovalBusinessResultDTO approvalBusinessResultDTO) {
        String businessData = approvalBusinessResultDTO.getBusinessData();
        JSONObject js = JSONObject.parseObject(businessData);
        String memberCode = js.getString("memberCode");
        Integer num = js.getInteger("num");
        Long pkBaseId = js.getLong("pkBaseId");
        R<CuMember> memberDto = memberServiceApi.getMember(memberCode);
        Long pkMember = memberDto.getData().getPkId();

        LambdaQueryWrapper<AcDrawRewardNum> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AcDrawRewardNum::getPkBaseId, pkBaseId);
        queryWrapper.eq(AcDrawRewardNum::getPkMember, pkMember);
        AcDrawRewardNum drawRewardNum = this.getOne(queryWrapper);
        if (drawRewardNum != null) {
            baseMapper.updatePurchasedTimesByBaseId(pkMember, num, pkBaseId);
        } else {
            drawRewardNum = new AcDrawRewardNum();
            drawRewardNum.setPkBaseId(pkBaseId);
            drawRewardNum.setPkMember(pkMember);
            drawRewardNum.setTotalUsedNum(num);
            drawRewardNum.setAvailableNum(num);
            drawRewardNum.setTotalNum(num);
            drawRewardNum.setAvailableSurplusNum(num);
            drawRewardNum.setCreationTime(DateUtils.currentDateTime());
            drawRewardNum.setPkCreator(memberDto.getData().getPkCreator());
            drawRewardNum.setPkCountry(memberDto.getData().getPkCountry());
            this.save(drawRewardNum);
        }
    }

    /**
     * 充值未购买次数
     *
     * @param approvalBusinessResultDTO
     */
    @Override
    public void unRechargePurchasedTimes(ApprovalBusinessResultDTO approvalBusinessResultDTO) {
        String businessData = approvalBusinessResultDTO.getBusinessData();
        JSONObject js = JSONObject.parseObject(businessData);
        String memberCode = js.getString("memberCode");
        Integer num = js.getInteger("num");
        Long pkBaseId = js.getLong("pkBaseId");
        R<CuMember> memberDto = memberServiceApi.getMember(memberCode);
        Long pkMember = memberDto.getData().getPkId();

        LambdaQueryWrapper<AcDrawRewardNum> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AcDrawRewardNum::getPkBaseId, pkBaseId);
        queryWrapper.eq(AcDrawRewardNum::getPkMember, pkMember);
        AcDrawRewardNum drawRewardNum = this.getOne(queryWrapper);
        if (drawRewardNum != null) {
            baseMapper.updateUnpurchasedTimesByPkbaseId(pkMember, num, pkBaseId);
        } else {
            drawRewardNum = new AcDrawRewardNum();
            drawRewardNum.setPkBaseId(pkBaseId);
            drawRewardNum.setPkMember(pkMember);
            drawRewardNum.setTotalNum(num);
            drawRewardNum.setTotalSurplusNum(num);
            drawRewardNum.setCreationTime(DateUtils.currentDateTime());
            drawRewardNum.setPkCreator(memberDto.getData().getPkCreator());
            drawRewardNum.setPkCountry(memberDto.getData().getPkCountry());
            this.save(drawRewardNum);
        }
    }

    /**
     * 修改已购买总次数 （已购买次数）
     *
     * @param pkMember
     * @param num
     */
    private void updateTotalUsedNum(Long pkMember, Integer num, Long pkBaseId, Long userId, Integer pkCountry) {
        LambdaQueryWrapper<AcDrawRewardNum> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AcDrawRewardNum::getPkBaseId, pkBaseId);
        queryWrapper.eq(AcDrawRewardNum::getPkMember, pkMember);

        AcDrawRewardNum drawRewardNum = this.getOne(queryWrapper);
        if (drawRewardNum == null) {
            AcDrawRewardNum dr = new AcDrawRewardNum();
            dr.setPkBaseId(pkBaseId);
            dr.setPkMember(pkMember);
            dr.setTotalUsedNum(num);
            dr.setAvailableNum(num);
            dr.setAvailableSurplusNum(num);
            dr.setCreationTime(DateUtils.currentDateTime());
            dr.setPkCreator(userId);
            dr.setPkCountry(pkCountry);
            this.save(dr);
        } else {
            //   修改已购买总次数
            this.updatePurchasedTimesByBaseId(pkMember, num, pkBaseId);
        }
    }

    private void updateMemberDrawNum(Long pkMember, SaOrderExt saOrderExt, AcDrawRuleConfig drawRuleConfig) {
        // 验证是否已经存在抽奖，存在的修改
        AcDrawRewardNum acDrawRewardNum = queryAcDrawRewardNum(AcDrawRewardNumParam.builder().pkMember(pkMember)
                .pkBaseId(drawRuleConfig.getPkBaseId()).pkCountry(saOrderExt.getPkCountry()).build());
        if (acDrawRewardNum == null) {
            acDrawRewardNum = AcDrawRewardNum.builder()
                    .pkBaseId(drawRuleConfig.getPkBaseId())
                    .pkMember(pkMember)
                    .totalNum(drawRuleConfig.getGiveNumber())
                    .totalSurplusNum(drawRuleConfig.getGiveNumber())
                    .build();
            acDrawRewardNum.setPkCountry(saOrderExt.getPkCountry());
            acDrawRewardNum.setPkCreator(saOrderExt.getPkCreator());
            save(acDrawRewardNum);
        } else {
            acDrawRewardNum.setTotalNum(acDrawRewardNum.getTotalNum() + drawRuleConfig.getGiveNumber());
            acDrawRewardNum.setTotalSurplusNum(acDrawRewardNum.getTotalSurplusNum() + drawRuleConfig.getGiveNumber());
            acDrawRewardNum.setPkModified(saOrderExt.getPkCreator());
            acDrawRewardNum.setModifiedTime(DateUtils.currentDateTime());
            updateById(acDrawRewardNum);
        }
        acDrawRewardNumDetailService.saveAcDrawRewardNumDetail(acDrawRewardNum, drawRuleConfig.getGiveNumber(), saOrderExt);
    }
}
