| | |
| | | import com.ks.lijin.service.LiJinProviderNoticeService; |
| | | import com.ks.lijin.service.LijinCreateService; |
| | | import com.ks.lijin.service.manager.LiJinProviderTaoKeAccountManager; |
| | | import com.ks.lijin.service.manager.LijinConfigManager; |
| | | import com.ks.lijin.service.manager.LijinDangerGoodsManager; |
| | | import com.ks.lijin.service.manager.LijinGoodsManager; |
| | | import com.ks.lijin.util.Constant; |
| | | import com.ks.lijin.utils.taobao.TaoBaoUtil; |
| | | import com.ks.lijin.utils.taobao.TaoKeApiUtil; |
| | | import com.ks.vip.exception.LijinBalanceException; |
| | | import com.ks.vip.pojo.DO.UserLijinRecord; |
| | | import com.ks.vip.pojo.DO.VipGradePotence; |
| | | import com.ks.vip.pojo.Enums.VIPEnum; |
| | | import com.ks.vip.service.LijinBalanceService; |
| | | import com.ks.vip.service.VipCenterService; |
| | | import com.ks.vip.service.VipGradePotenceService; |
| | | import com.ks.vip.service.VipGradeService; |
| | | 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.data.redis.core.StringRedisTemplate; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.yeshi.utils.MoneyBigDecimalUtil; |
| | | import org.yeshi.utils.StringUtil; |
| | |
| | | @Service(version = "1.0") |
| | | public class LijinCreateServiceImpl implements LijinCreateService { |
| | | |
| | | Logger logger = LoggerFactory.getLogger(LijinCreateService.class); |
| | | |
| | | @Resource(name = "taskExecutor") |
| | | private TaskExecutor executor; |
| | | |
| | |
| | | @Resource |
| | | private LiJinProviderAccountService liJinProviderAccountService; |
| | | |
| | | @Reference(version = "1.0") |
| | | @Reference(version = "1.0", check = false) |
| | | private VipCenterService vipCenterService; |
| | | |
| | | @Reference(version = "1.0") |
| | | @Reference(version = "1.0", check = false) |
| | | private VipGradePotenceService vipGradePotenceService; |
| | | |
| | | @Reference(version = "1.0") |
| | | @Reference(version = "1.0", check = false) |
| | | private VipGradeService vipGradeService; |
| | | |
| | | @Reference(version = "1.0", check = false) |
| | | private LijinBalanceService lijinBalanceService; |
| | | |
| | | @Resource |
| | | private LiJinExpendRecordService liJinExpendRecordService; |
| | |
| | | private LiJinProviderTaoKeAccountManager liJinProviderTaoKeAccountManager; |
| | | |
| | | @Resource |
| | | private RedisTemplate redisTemplate; |
| | | private StringRedisTemplate redisTemplate; |
| | | |
| | | @Resource |
| | | private LijinGoodsManager lijinGoodsManager; |
| | | |
| | | @Resource |
| | | private LijinDangerGoodsManager lijinDangerGoodsManager; |
| | | |
| | | @Resource |
| | | private LijinConfigManager lijinConfigManager; |
| | | |
| | | @Override |
| | | public List<MoneyInfo> getMoneyInfo(String uid, List<TaoBaoGoodsBrief> goodsBriefList) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public boolean userCanCreateTBLijin(String uid) throws LiJinUserException { |
| | | 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 { |
| | | VipGradePotence potence = vipCenterService.getVipPotence(uid); |
| | | if (potence == null) { |
| | | return false; |
| | | } |
| | | |
| | | |
| | | // 每日最大次数判断 |
| | | Integer numMax = potence.getTaolijinMaxNumber(); |
| | |
| | | |
| | | // 使用次数已经超过最大次数 |
| | | 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) { |
| | | throw new LiJinUserException(LiJinUserException.CODE_USER_CREATE_NUM_LIMIT, "用户创建淘礼金的次数超限"); |
| | | } |
| | |
| | | if (potence == null) { |
| | | return false; |
| | | } |
| | | //查询礼金余额 |
| | | BigDecimal balance = lijinBalanceService.getBalance(uid); |
| | | if (balance != null) { |
| | | if (money.compareTo(balance) > 0) { |
| | | throw new LiJinUserException(LiJinUserException.CODE_USER_BALANCE_NOT_ENOUGH, "礼金余额不足"); |
| | | } |
| | | } |
| | | |
| | | |
| | | // 每日最大次数判断 |
| | | Integer numMax = potence.getTaolijinMaxNumber(); |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public LiJinExpendRecord createTBLijin(String uid, Long goodsId) throws LiJinException, LiJinGoodsException, LiJinUserException, LiJinAmountException { |
| | | return createTBLijin(uid, null, goodsId); |
| | | } |
| | | |
| | | userCanCreateTBLijin(uid); |
| | | @Override |
| | | public LiJinExpendRecord createTBLijin(String uid, Date registerDate, Long auctionId) throws LiJinException, LiJinGoodsException, LiJinUserException, LiJinAmountException { |
| | | |
| | | //用户是否有创建权限 |
| | | userCanCreateTBLijin(uid, registerDate); |
| | | //商品是否在危险商品中 |
| | | boolean dangerous = lijinDangerGoodsManager.isDangerous(auctionId + "", 1); |
| | | if (dangerous) { |
| | | throw new LiJinGoodsException(LiJinGoodsException.CODE_GOODS_NOT_SUPPORT, "该商品暂无法创建礼金"); |
| | | } |
| | | |
| | | |
| | | // 获取用户等级 |
| | | VIPEnum vipRank = vipCenterService.getVIPEnumByUid(uid); |
| | |
| | | //淘礼金创建 |
| | | TaoBaoGoodsBrief goods = null; |
| | | try { |
| | | goods = TaoKeApiUtil.searchGoodsDetail(goodsId); |
| | | goods = TaoKeApiUtil.searchGoodsDetail(auctionId); |
| | | } catch (TaoBaoGoodsDownException e) { |
| | | throw new LiJinGoodsException(LiJinGoodsException.CODE_GOODS_OFFLINE, "商品下线"); |
| | | } |
| | |
| | | // 创建的淘礼金-金额 |
| | | BigDecimal lijinAmount = getTBLijinAmount(goods, vipRank); |
| | | |
| | | //查询礼金余额 |
| | | BigDecimal balance = lijinBalanceService.getBalance(uid); |
| | | if (balance != null && lijinAmount != null) { |
| | | if (lijinAmount.compareTo(balance) > 0) { |
| | | throw new LiJinUserException(LiJinUserException.CODE_USER_BALANCE_NOT_ENOUGH, "礼金余额不足"); |
| | | } |
| | | } |
| | | |
| | | // 执行创建淘礼金 |
| | | LiJinCreateParam params = getLiJinCreateBaseParam(); |
| | | |
| | |
| | | if (redisTemplate.opsForValue().setIfAbsent(key, "1", 120, TimeUnit.SECONDS)) { |
| | | Date now = new Date(); |
| | | try { |
| | | TaoLijinCreateResultDTO taoLiJinDTO = executeTaoLiJin(goodsId, lijinAmount, params); |
| | | TaoLijinCreateResultDTO taoLiJinDTO = executeTaoLiJin(auctionId, lijinAmount, params); |
| | | if (taoLiJinDTO == null) { |
| | | throw new LiJinException(1, "淘宝API推广红包创建失败"); |
| | | } |
| | | //添加账号的 |
| | | return addCreateSuccessRecord(uid, goodsId, lijinAmount, params.getTitle(), params.getNum(), taoLiJinDTO); |
| | | return addCreateSuccessRecord(uid, auctionId, lijinAmount, params.getTitle(), params.getNum(), taoLiJinDTO); |
| | | } catch (LiJinGoodsException e) { |
| | | if (e.getCode() == LiJinGoodsException.CODE_GOODS_CREATED_FULL) { |
| | | lijinGoodsManager.createdFullToday(goodsId, now); |
| | | 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, "服务器繁忙,请稍后再试"); |
| | | } |
| | | } |
| | |
| | | liJinExpendRecordMapper.insertSelective(record); |
| | | //添加 |
| | | liJinProviderTaoKeAccountManager.createLijinSuccess(taoLiJinDTO.getAccount().getId(), goodsId, lijinAmount.multiply(new BigDecimal(num)), now); |
| | | //礼金余额扣除 |
| | | try { |
| | | lijinBalanceService.consumeLijin(uid, lijinAmount, "购物抵现", UserLijinRecord.Category.createGoodsLijin.name(), record.getId() + ""); |
| | | } catch (LijinBalanceException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | return record; |
| | | } |
| | | |