| | |
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | | import org.yeshi.utils.BigDecimalUtil;
|
| | | import org.yeshi.utils.DateUtil;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.tlj.UserTaoLiJinRecordMapper;
|
| | | import com.yeshi.fanli.dto.msg.MsgOtherTaoLiJinContentDTO;
|
| | | import com.yeshi.fanli.dto.taobao.TaoLiJinDTO;
|
| | | import com.yeshi.fanli.entity.bus.tlj.UserTaoLiJinDetail;
|
| | | import com.yeshi.fanli.entity.bus.tlj.UserTaoLiJinDetail.TaoLiJinDetailTypeEnum;
|
| | | import com.yeshi.fanli.entity.bus.tlj.UserTaoLiJinGiveRecord;
|
| | | import com.yeshi.fanli.entity.bus.tlj.UserTaoLiJinOrigin;
|
| | | import com.yeshi.fanli.entity.bus.tlj.UserTaoLiJinRecord;
|
| | | import com.yeshi.fanli.entity.bus.user.TokenRecord;
|
| | | import com.yeshi.fanli.entity.bus.user.TokenRecord.TokenTypeEnum;
|
| | | import com.yeshi.fanli.entity.bus.user.UserMoneyExtra;
|
| | | import com.yeshi.fanli.entity.goods.CommonGoods;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
| | |
| | | import com.yeshi.fanli.exception.taobao.TaoKeApiException;
|
| | | import com.yeshi.fanli.exception.tlj.UserTaoLiJinRecordException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.config.ConfigService;
|
| | | import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
|
| | | import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
|
| | | import com.yeshi.fanli.service.inter.msg.UserOtherMsgNotificationService;
|
| | |
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoBuyRelationMapService;
|
| | | import com.yeshi.fanli.service.inter.tlj.ConfigTaoLiJinService;
|
| | | import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinDetailService;
|
| | | import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinGiveRecordService;
|
| | | import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinOriginService;
|
| | | import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinRecordService;
|
| | | import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinReportService;
|
| | | import com.yeshi.fanli.service.inter.user.TokenRecordService;
|
| | | import com.yeshi.fanli.service.inter.user.UserExtraTaoBaoInfoService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
|
| | | import com.yeshi.fanli.service.inter.user.UserMoneyExtraService;
|
| | |
| | | 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.factory.CommonGoodsFactory;
|
| | | import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoLiJinUtil;
|
| | |
| | |
|
| | | @Resource
|
| | | private RedisManager redisManager;
|
| | | |
| | | @Resource
|
| | | private ConfigService configService;
|
| | |
|
| | | @Resource
|
| | | private UserTaoLiJinRecordMapper userTaoLiJinRecordMapper;
|
| | |
| | |
|
| | | @Resource
|
| | | private ShareHotGoodsService shareHotGoodsService;
|
| | | |
| | | @Resource
|
| | | private TokenRecordService tokenRecordService;
|
| | | |
| | | @Resource
|
| | | private UserTaoLiJinGiveRecordService userTaoLiJinGiveRecordService;
|
| | | |
| | |
|
| | | @Override
|
| | | public UserTaoLiJinRecord selectByPrimaryKey(Long id) {
|
| | |
| | | perface = new BigDecimal(1);
|
| | | } else {
|
| | | // 计算推广红包
|
| | | String warningRate = configTaoLiJinService.getValueByKey("warning_value");
|
| | | String warningRate = configTaoLiJinService.getValueByKey("warning_value",new Date());
|
| | | perface = TaoLiJinUtil.getSpreadMoney(warningRate, goods);
|
| | | }
|
| | |
|
| | | UserTaoLiJinRecord record = createUserTaoLiJin(2, uid, goods.getAuctionId(), perface, totalNum, name,
|
| | | sendStartTime, sendEndTime, null, useEndTime, TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT);
|
| | | sendStartTime, sendEndTime, null, useEndTime, TaoBaoConstant.TAOBAO_TLJ_RELATION_PID_DEFAULT);
|
| | | String sendUrl = record.getSendUrl() + "&relationId=" + relationId;
|
| | | record.setSendUrl(sendUrl);
|
| | | UserTaoLiJinRecord updateRecoed=new UserTaoLiJinRecord();
|
| | |
| | | throw new UserTaoLiJinRecordException(101, "红包余额不足");
|
| | | }
|
| | |
|
| | | // 过期
|
| | | userTaoLiJinOriginService.overdueHongBao(uid);
|
| | | // 过期 -取消收回
|
| | | // userTaoLiJinOriginService.overdueHongBao(uid);
|
| | |
|
| | | // 总推广红包
|
| | | BigDecimal totalMoney = MoneyBigDecimalUtil.mul(perface, new BigDecimal(totalNum));
|
| | |
| | | public UserTaoLiJinRecord getByRightsId(String rightsId) {
|
| | | return userTaoLiJinRecordMapper.getByRightsId(rightsId);
|
| | | }
|
| | | |
| | | @Override
|
| | | public String giveTaolijin(Long uid, BigDecimal amount) throws UserTaoLiJinRecordException{
|
| | | if (uid == null || amount == null) |
| | | throw new UserTaoLiJinRecordException(1,"参数不正确");
|
| | | |
| | | String giveMin = configTaoLiJinService.getValueByKey("give_min_amount");
|
| | | if (amount.compareTo(new BigDecimal(giveMin)) < 0)
|
| | | throw new UserTaoLiJinRecordException(1,"赠送推广红包金额至少" + giveMin + "元");
|
| | | |
| | | // 用户剩余可以淘礼金验证
|
| | | UserMoneyExtra userMoneyExtra = userMoneyExtraService.selectByPrimaryKey(uid);
|
| | | if (userMoneyExtra == null || userMoneyExtra.getTlj() == null)
|
| | | throw new UserTaoLiJinRecordException(1, "红包余额不足");
|
| | | |
| | | BigDecimal tlj = userMoneyExtra.getTlj();
|
| | | 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);
|
| | | 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;
|
| | | }
|
| | | }
|
| | | |
| | | if(StringUtil.isNullOrEmpty(token))
|
| | | throw new UserTaoLiJinRecordException(1, "口令生成失败");
|
| | | |
| | | 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"));
|
| | | |
| | | executor.execute(new Runnable() {
|
| | | @Override
|
| | | public void run() {
|
| | | try {
|
| | | // 插入明细
|
| | | UserTaoLiJinDetail detail = new UserTaoLiJinDetail();
|
| | | detail.setUid(uid);
|
| | | detail.setMoney(new BigDecimal("-" + amount));
|
| | | detail.setTitle(TaoLiJinDetailTypeEnum.give.getDesc());
|
| | | detail.setType(TaoLiJinDetailTypeEnum.give);
|
| | | detail.setCreateTime(new Date());
|
| | | userTaoLiJinDetailService.insertSelective(detail);
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | |
|
| | | // 成功使用红包
|
| | | try {
|
| | | BigDecimal total = amount;
|
| | | BigDecimal lastMoney = null;
|
| | | BigDecimal zero = new BigDecimal(0);
|
| | | // 修改余额
|
| | | List<UserTaoLiJinOrigin> list = userTaoLiJinOriginService.getSurplusLiJin(uid);
|
| | | if (list != null && list.size() > 0) {
|
| | | for (UserTaoLiJinOrigin taoLiJinOrigin : list) {
|
| | | if (total.compareTo(zero) < 1) {
|
| | | break;
|
| | | }
|
| | | BigDecimal moneySurplus = taoLiJinOrigin.getMoneySurplus();
|
| | | lastMoney = total;
|
| | | total = MoneyBigDecimalUtil.sub(total, moneySurplus);
|
| | | if (total.compareTo(zero) >= 0) {
|
| | | moneySurplus = zero;
|
| | | } else {
|
| | | moneySurplus = MoneyBigDecimalUtil.sub(moneySurplus, lastMoney);
|
| | | }
|
| | |
|
| | | UserTaoLiJinOrigin usertlj = new UserTaoLiJinOrigin();
|
| | | usertlj.setId(taoLiJinOrigin.getId());
|
| | | usertlj.setMoneySurplus(moneySurplus);
|
| | | usertlj.setUpdateTime(new Date());
|
| | | userTaoLiJinOriginService.updateByPrimaryKeySelective(usertlj);
|
| | | }
|
| | | }
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | | }
|
| | | });
|
| | | |
| | | return tips;
|
| | | }
|
| | | |
| | |
|
| | | }
|