| | |
| | | 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, "红包余额不足");
|
| | |
|
| | | |
| | | Date nowDate = new Date();
|
| | | |
| | | // 赠送记录
|
| | | UserTaoLiJinGiveRecord giveRecord = new UserTaoLiJinGiveRecord();
|
| | | giveRecord.setAmount(amount);
|
| | | giveRecord.setGiveUid(uid);
|
| | | giveRecord.setState(UserTaoLiJinGiveRecord.STATE_INIT);
|
| | | giveRecord.setGiveTime(nowDate);
|
| | | giveRecord.setEndTime(DateUtil.plusDayDate(Constant.GIVE_DAYS, new Date()));
|
| | | userTaoLiJinGiveRecordService.insertSelective(giveRecord);
|
| | |
|
| | | 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(giveRecord.getId()+""); // 记录id
|
| | | tokenRecord.setType(TokenTypeEnum.taoLiJin);
|
| | | tokenRecord.setStartTime(nowDate);
|
| | | tokenRecord.setEndTime(DateUtil.plusDayDate(3, nowDate));
|
| | | tokenRecord.setToken(token);
|
| | | tokenRecord.setState(0);
|
| | | tokenRecordService.insertSelective(tokenRecord);
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | token = null;
|
| | | }
|
| | | |
| | | if(!StringUtil.isNullOrEmpty(token)) {
|
| | | break;
|
| | | }
|
| | | }
|
| | | // 口令记录
|
| | | TokenRecord tokenRecord = new TokenRecord();
|
| | | tokenRecord.setUid(uid);
|
| | | tokenRecord.setIdentify(giveRecord.getId() + "");
|
| | | tokenRecord.setType(TokenTypeEnum.taoLiJin);
|
| | | tokenRecord.setStartTime(nowDate);
|
| | | tokenRecord.setEndTime(DateUtil.plusDayDate(Constant.TOKEN_DAYS, new Date()));
|
| | | tokenRecord.setState(0);
|
| | | tokenRecordService.insertSelective(tokenRecord);
|
| | |
|
| | | if(StringUtil.isNullOrEmpty(token))
|
| | | throw new UserTaoLiJinRecordException(1, "口令生成失败");
|
| | | // 创建口令
|
| | | String token = TokenUtil.createToken(tokenRecord.getId());
|
| | | tokenRecord.setToken(token);
|
| | | tokenRecordService.updateByPrimaryKeySelective(tokenRecord);
|
| | |
|
| | | // 更新余额
|
| | | UserMoneyExtra updateExtra = new UserMoneyExtra();
|
| | | updateExtra.setUid(uid);
|
| | | updateExtra.setTlj(MoneyBigDecimalUtil.sub(tlj, amount));
|
| | | updateExtra.setUpdateTime(new Date());
|
| | | userMoneyExtraService.updateByPrimaryKeySelective(updateExtra);
|
| | |
|
| | | String tips = "送给你[%s]元推广红包快去领取吧,复制本条消息[&%s&],打开[返利券]App领取,用推广分享爆款商品,成单率更高哦。\r\n" |
| | | + "----------------------------\r\n"
|
| | | + "下载[返利券]App链接:%s\r\n"
|
| | | + "PS:口令将会24小时内失效,请及时领取。";
|
| | | |
| | | tips = String.format(tips, amount, token, configService.get("app_down_link"));
|
| | | String tips = configTaoLiJinService.getValueByKey("give_taolijin_tips");
|
| | | String projectChineseName = Constant.systemCommonConfig.getProjectChineseName();
|
| | | while(tips.contains("{APP名称}")) {
|
| | | tips = tips.replace("{APP名称}", projectChineseName);
|
| | | }
|
| | | tips = tips.replace("{口令}", token).replace("{下载链接}", configService.get("app_down_link"))
|
| | | .replace("{面额}", amount.setScale(0).toString());
|
| | |
|
| | | executor.execute(new Runnable() {
|
| | | @Override
|