| | |
| | | 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; |
| | |
| | | @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; |
| | |
| | | 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 { |
| | |
| | | if (potence == null) { |
| | | return false; |
| | | } |
| | | |
| | | |
| | | // 每日最大次数判断 |
| | | Integer numMax = potence.getTaolijinMaxNumber(); |
| | |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | |
| | | 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(); |
| | |
| | | // 创建的淘礼金-金额 |
| | | 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 (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, "服务器繁忙,请稍后再试"); |
| | | } |
| | | } |
| | |
| | | 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; |
| | | } |
| | | |