admin
2021-07-05 2f071296b9e1d7a3aa6b6f3818196aaa40af3300
service-lijin/src/main/java/com/ks/lijin/service/remote/LijinCreateServiceImpl.java
@@ -33,6 +33,8 @@
import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.annotation.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.task.TaskExecutor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.transaction.annotation.Transactional;
@@ -51,6 +53,8 @@
@Service(version = "1.0")
public class LijinCreateServiceImpl implements LijinCreateService {
    Logger logger = LoggerFactory.getLogger(LijinCreateService.class);
    @Resource(name = "taskExecutor")
    private TaskExecutor executor;
@@ -195,6 +199,38 @@
        return money;
    }
    @Override
    public int getTodayLeftCount(String uid, Date registerDate) {
        VipGradePotence potence = vipCenterService.getVipPotence(uid);
        if (potence == null) {
            return 0;
        }
        // 每日最大次数判断
        Integer numMax = potence.getTaolijinMaxNumber();
        if (numMax == null || numMax.intValue() <= 0) {
            return 0;
        }
        // 使用次数已经超过最大次数
        int numExpend = liJinExpendRecordService.countTodayNumByExpend(uid);
        if (registerDate != null) {
            //判断新用户
            String newerHour = lijinConfigManager.getConfigValue("newer-hour");
            String dayPlusCount = lijinConfigManager.getConfigValue("newer-everyday-plus-lijin-count");
            if (!StringUtil.isNullOrEmpty(newerHour) && !StringUtil.isNullOrEmpty(dayPlusCount)) {
                //新用户每日附加次数
                if (System.currentTimeMillis() - registerDate.getTime() < 1000 * 60 * 60L * Integer.parseInt(dayPlusCount)) {
                    numMax += Integer.parseInt(dayPlusCount);
                }
            }
        }
        if (numMax.intValue() > numExpend) {
            return numMax.intValue() - numExpend;
        } else {
            return 0;
        }
    }
    @Override
    public boolean userCanCreateTBLijin(String uid, Date registerDate) throws LiJinUserException {
@@ -225,7 +261,7 @@
            if (!StringUtil.isNullOrEmpty(newerHour) && !StringUtil.isNullOrEmpty(dayPlusCount)) {
                //新用户每日附加次数
                if (System.currentTimeMillis() - registerDate.getTime() < 1000 * 60 * 60L * Integer.parseInt(dayPlusCount)) {
                    numExpend += Integer.parseInt(dayPlusCount);
                    numMax += Integer.parseInt(dayPlusCount);
                }
            }
        }
@@ -364,11 +400,15 @@
                if (e.getCode() == LiJinGoodsException.CODE_GOODS_CREATED_FULL) {
                    lijinGoodsManager.createdFullToday(auctionId, now);
                }
                redisTemplate.delete(key);
                logger.info("淘礼金创建,删除锁定成功1 key:{}",key);
                throw e;
            } finally {
                redisTemplate.delete(key);
                logger.info("淘礼金创建,删除锁定成功2 key:{}",key);
            }
        } else {
            logger.error("淘礼金创建,用户锁定失败 key:{}",key);
            throw new LiJinException(LiJinException.CODE_SERVER_BUSY, "服务器繁忙,请稍后再试");
        }
    }
@@ -402,7 +442,7 @@
        liJinProviderTaoKeAccountManager.createLijinSuccess(taoLiJinDTO.getAccount().getId(), goodsId, lijinAmount.multiply(new BigDecimal(num)), now);
        //礼金余额扣除
        try {
            lijinBalanceService.consumeLijin(uid, lijinAmount, "购物抵现", UserLijinRecord.Category.createGoodsLijin.name(), record.getId()+"");
            lijinBalanceService.consumeLijin(uid, lijinAmount, "购物抵现", UserLijinRecord.Category.createGoodsLijin.name(), record.getId() + "");
        } catch (LijinBalanceException e) {
            e.printStackTrace();
        }