| | |
| | | import com.yeshi.fanli.util.RedisManager;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.TaoBaoConstant;
|
| | | import com.yeshi.fanli.util.account.UserUtil;
|
| | | import com.yeshi.fanli.util.TokenUtil;
|
| | | import com.yeshi.fanli.util.factory.CommonGoodsFactory;
|
| | | import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoLiJinUtil;
|
| | |
| | | if (amount.compareTo(tlj) > 0)
|
| | | throw new UserTaoLiJinRecordException(1, "红包余额不足");
|
| | |
|
| | | Long giveId = null;
|
| | | Date nowDate = new Date();
|
| | | try {
|
| | | // 赠送记录
|
| | | UserTaoLiJinGiveRecord giveRecord = new UserTaoLiJinGiveRecord();
|
| | | giveRecord.setAmount(amount);
|
| | |
| | | giveRecord.setEndTime(DateUtil.plusDayDate(Constant.GIVE_DAYS, new Date()));
|
| | | userTaoLiJinGiveRecordService.insertSelective(giveRecord);
|
| | |
|
| | | giveId = giveRecord.getId();
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | throw new UserTaoLiJinRecordException(1, "赠送记录创建失败");
|
| | | }
|
| | | |
| | | String token = null;
|
| | | for (int i = 0; i < 5; i++) {
|
| | | try {
|
| | | // TODO 口令生成规则待定
|
| | | long num = 10000 + (long) (Math.random() * 10000);
|
| | | token = UserUtil.getInviteCode(num);
|
| | | |
| | | // 口令记录
|
| | | TokenRecord tokenRecord = new TokenRecord();
|
| | | tokenRecord.setUid(uid);
|
| | | tokenRecord.setIdentify(giveId + ""); // 记录id
|
| | | tokenRecord.setIdentify(giveRecord.getId() + "");
|
| | | tokenRecord.setType(TokenTypeEnum.taoLiJin);
|
| | | tokenRecord.setStartTime(nowDate);
|
| | | tokenRecord.setEndTime(DateUtil.plusDayDate(Constant.TOKEN_DAYS, new Date()));
|
| | | tokenRecord.setToken(token);
|
| | | tokenRecord.setState(0);
|
| | | tokenRecordService.insertSelective(tokenRecord);
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | token = null;
|
| | | }
|
| | |
|
| | | if(!StringUtil.isNullOrEmpty(token)) {
|
| | | break;
|
| | | }
|
| | | }
|
| | | // 创建口令
|
| | | String token = TokenUtil.createToken(tokenRecord.getId());
|
| | | tokenRecord.setToken(token);
|
| | | tokenRecordService.updateByPrimaryKeySelective(tokenRecord);
|
| | |
|
| | | if(StringUtil.isNullOrEmpty(token))
|
| | | throw new UserTaoLiJinRecordException(1, "口令生成失败");
|
| | | |
| | | // 更新余额
|
| | | UserMoneyExtra updateExtra = new UserMoneyExtra();
|
| | | updateExtra.setUid(uid);
|
| | | updateExtra.setTlj(MoneyBigDecimalUtil.sub(tlj, amount));
|