admin
2019-10-22 32f925357776c46bd9e35cf9aad4fdd0f6535d1d
fanli/src/main/java/com/yeshi/fanli/service/impl/user/TokenRecordServiceImpl.java
@@ -1,6 +1,5 @@
package com.yeshi.fanli.service.impl.user;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
@@ -13,8 +12,8 @@
import org.springframework.stereotype.Service;
import com.yeshi.fanli.dao.mybatis.user.TokenRecordMapper;
import com.yeshi.fanli.dto.msg.MsgInviteContentDTO;
import com.yeshi.fanli.dto.msg.MsgOtherGiveContentDTO;
import com.yeshi.fanli.entity.bus.tlj.UserTaoLiJinGiveRecord;
import com.yeshi.fanli.entity.bus.user.TokenRecord;
import com.yeshi.fanli.entity.bus.user.TokenRecord.TokenTypeEnum;
import com.yeshi.fanli.entity.bus.user.UserInfo;
@@ -24,22 +23,20 @@
import com.yeshi.fanli.entity.bus.user.UserSystemCouponRecord;
import com.yeshi.fanli.entity.system.SystemCoupon;
import com.yeshi.fanli.entity.system.SystemCoupon.CouponTypeEnum;
import com.yeshi.fanli.exception.tlj.UserTaoLiJinOriginException;
import com.yeshi.fanli.exception.user.TokenRecordException;
import com.yeshi.fanli.exception.user.UserInfoExtraException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.config.SystemCouponService;
import com.yeshi.fanli.service.inter.hongbao.ThreeSaleSerivce;
import com.yeshi.fanli.service.inter.integral.IntegralGetService;
import com.yeshi.fanli.service.inter.msg.UserOtherMsgNotificationService;
import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinGiveRecordService;
import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinOriginService;
import com.yeshi.fanli.service.inter.user.TokenRecordService;
import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.service.inter.user.UserSystemCouponGiveRecordService;
import com.yeshi.fanli.service.inter.user.UserSystemCouponRecordService;
import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
import com.yeshi.fanli.service.inter.user.integral.IntegralGetService;
import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
import com.yeshi.fanli.service.inter.user.invite.UserInviteMsgNotificationService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.TokenUtil;
@@ -58,13 +55,11 @@
   private UserInfoService userInfoService;
   @Resource
   @Lazy
   private UserSystemCouponService userSystemCouponService;
   @Resource
   private ThreeSaleSerivce threeSaleSerivce;
   @Resource
   private UserTaoLiJinGiveRecordService userTaoLiJinGiveRecordService;
   @Resource
   private UserInfoExtraService userInfoExtraService;
@@ -76,9 +71,6 @@
   private UserSystemCouponGiveRecordService userSystemCouponGiveRecordService;
   @Resource
   private UserTaoLiJinOriginService userTaoLiJinOriginService;
   @Resource
   private UserOtherMsgNotificationService userOtherMsgNotificationService;
   
   @Lazy
@@ -87,6 +79,9 @@
   
   @Resource
   private SystemCouponService systemCouponService;
   @Resource
   private UserInviteMsgNotificationService userInviteMsgNotificationService;
   
   @Override
@@ -204,43 +199,17 @@
            UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
            if (userInfoExtra == null || StringUtil.isNullOrEmpty(userInfoExtra.getInviteCode())) {
               tips.add("确认领取后,你将成为赠送者的一级队员;");
               tips.add("返利券奖励券,可用于“已到账”的返利订单,在返利的基础上再获得一定比例的返利;");
               tips.add("板栗快省奖励券,可用于“已到账”的返利订单,在返利的基础上再获得一定比例的返利;");
               tips.add("成功领取后,请到“我的-福利中心”中查看。");
            } else {
               tips.add("返利券奖励券,可用于“已到账”的返利订单,在返利的基础上再获得一定比例的返利;");
               tips.add("板栗快省奖励券,可用于“已到账”的返利订单,在返利的基础上再获得一定比例的返利;");
               tips.add("成功领取后,请到“我的-福利中心”中查看。");
            }
         } else {
            throw new TokenRecordException(1, "口令已失效");
         }
      } else if (tokenType == TokenTypeEnum.taoLiJin) {
         type = 12;
         UserTaoLiJinGiveRecord giveRecord = userTaoLiJinGiveRecordService
               .selectByPrimaryKey(Long.parseLong(identify));
         if (giveRecord == null || giveRecord.getState() == UserTaoLiJinGiveRecord.STATE_OVERDUE) {
            tips.add("哎呀,推广红包已失效了!");
         } else if (giveRecord.getState() == UserTaoLiJinGiveRecord.STATE_RECEIVE) {
            tips.add("哎呀,推广红包已被领取了!");
         } else if (giveRecord.getState() == UserTaoLiJinGiveRecord.STATE_INIT) {
            if (uid == null || uid <= 0)
               throw new TokenRecordException(1001, "温馨提示,[推广红包]需要登录后领取");
            state = true;
            BigDecimal amount = giveRecord.getAmount();
            num = Integer.parseInt(amount.setScale(0).toString());
            UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
            if (userInfoExtra == null || StringUtil.isNullOrEmpty(userInfoExtra.getInviteCode())) {
               tips.add("确认领取后,你将成为赠送者的一级队员;");
               tips.add("推广红包,可分享爆款商品,让分享订单成单率更高;");
               tips.add("成功领取后,请到“我的-推广红包”中查看。");
            } else {
               tips.add("推广红包,可分享爆款商品,让分享订单成单率更高;");
               tips.add("成功领取后,请到“我的-推广红包”中查看。");
            }
         } else {
            throw new TokenRecordException(1, "口令失效");
         }
         throw new TokenRecordException(1, "推广红包相关功能已下线!");
      } else {
         throw new TokenRecordException(1, "无对应类型");
      }
@@ -257,7 +226,7 @@
      }
      if (StringUtil.isNullOrEmpty(nickName))
         nickName = Constant.systemCommonConfig.getDefaultNickName();
         nickName = Constant.systemCommonConfig.getDefaultNickName() + inviteId;
      if (StringUtil.isNullOrEmpty(portrait))
         portrait = Constant.systemCommonConfig.getDefaultPortrait();
@@ -335,7 +304,7 @@
         UserSystemCoupon userSystemCoupon= null;
         try {
            userSystemCoupon = userSystemCouponService.insertUserCoupon(uid, CouponTypeEnum.freeCoupon.name(),
                  UserSystemCoupon.SOURCE_GIVE, null);
                  UserSystemCoupon.SOURCE_GIVE, null,true);
         } catch (Exception e) {
            LogHelper.errorDetailInfo(e);
            throw new TokenRecordException(1, "领取失败");
@@ -396,6 +365,10 @@
               msgOther.setGiveTime(sd.format(giveRecord.getGiveTime()));
               msgOther.setReceiveTime(sd.format(new Date()));
               userOtherMsgNotificationService.tokenGiveMsg(giveUid, beiZhu, msgOther);
               // 激活邀请信息
               if (addTeam)
                   addInviteMsg(uid, giveUid, "免单券");
            }
         });
      } else if (tokenType == TokenTypeEnum.rebatePercentCoupon) {
@@ -425,7 +398,7 @@
         UserSystemCoupon userSystemCoupon= null;
         try {
            userSystemCoupon = userSystemCouponService.insertUserCoupon(uid, CouponTypeEnum.rebatePercentCoupon.name(),
                  UserSystemCoupon.SOURCE_GIVE, systemCoupon.getPercent());
                  UserSystemCoupon.SOURCE_GIVE, systemCoupon.getPercent(),true);
         } catch (Exception e) {
            LogHelper.errorDetailInfo(e);
            throw new TokenRecordException(1, "领取失败");
@@ -486,63 +459,14 @@
               msgOther.setGiveTime(sd.format(giveRecord.getGiveTime()));
               msgOther.setReceiveTime(sd.format(new Date()));
               userOtherMsgNotificationService.tokenGiveMsg(giveUid, beiZhu, msgOther);
               // 激活邀请信息
               if (addTeam)
                   addInviteMsg(uid, giveUid, "返利奖励券");
            }
         });
      } else if (tokenType == TokenTypeEnum.taoLiJin) {
         UserTaoLiJinGiveRecord giveRecord = userTaoLiJinGiveRecordService
               .selectByPrimaryKey(Long.parseLong(identify));
         if (giveRecord == null || giveRecord.getState() != UserTaoLiJinGiveRecord.STATE_INIT)
            throw new TokenRecordException(1, "赠送记录失效或已被领取");
         Date endTime = giveRecord.getEndTime();
         if (endTime != null && endTime.getTime() < now.getTime())
            throw new TokenRecordException(1, "推广红包已失效了");
         BigDecimal amount = giveRecord.getAmount();
         try {
            // 领取
            userTaoLiJinOriginService.receiveFriendsGive(uid, amount);
            // 更新记录
            UserTaoLiJinGiveRecord updateRecord = new UserTaoLiJinGiveRecord();
            updateRecord.setId(Long.parseLong(identify));
            updateRecord.setReceiveTime(new Date());
            updateRecord.setReceiveUid(uid);
            updateRecord.setState(UserTaoLiJinGiveRecord.STATE_RECEIVE);
            userTaoLiJinGiveRecordService.updateByPrimaryKeySelective(updateRecord);
            integralGetService.addGiveTaoLiJin(giveUid);
            msg = "领取成功[推广红包]成功,请到[我的-推广红包]中查看";
            // 消息 + 队员
            executor.execute(new Runnable() {
               @Override
               public void run() {
                  SimpleDateFormat sd = new SimpleDateFormat("yyyy.MM.dd HH:mm");
                  boolean addTeam = addInviteTeam(uid, giveUid, userInfoExtra);
                  String beiZhu = "无";
                  if (addTeam)
                     beiZhu = "领取人已经成为你的一级队员";
                  String userName = "无";
                  UserInfo user = userInfoService.selectByPKey(uid);
                  if (user != null && !StringUtil.isNullOrEmpty(user.getNickName()))
                     userName = user.getNickName();
                  MsgOtherGiveContentDTO msgOther = new MsgOtherGiveContentDTO();
                  msgOther.setType(MsgOtherGiveContentDTO.TYEP_TLJ);
                  msgOther.setTitle("赠送推广红包");
                  msgOther.setGiveType("你赠送的推广红包被成功领取");
                  msgOther.setReceiveInfo("昵称:" + userName + " ID:" + uid);
                  msgOther.setGiveTime(sd.format(giveRecord.getGiveTime()));
                  msgOther.setReceiveTime(sd.format(new Date()));
                  userOtherMsgNotificationService.tokenGiveMsg(giveUid, beiZhu, msgOther);
               }
            });
         } catch (UserTaoLiJinOriginException e) {
            e.printStackTrace();
         }
         throw new TokenRecordException(1, "推广红包相关功能已下线!");
      } else {
         throw new TokenRecordException(1, "无对应类型");
      }
@@ -578,6 +502,22 @@
   }
   
   
   private void addInviteMsg(Long uid, Long giveUid, String giftName) {
      try {
         UserInfo user = userInfoService.selectByPKey(giveUid);
         UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
         MsgInviteContentDTO msgInvite = new MsgInviteContentDTO();
         msgInvite.setTitle("邀请消息");
         msgInvite.setState("成功激活邀请");
         msgInvite.setCode("你的邀请码:" + userInfoExtra.getInviteCode());
         msgInvite.setInviter("昵称:"+user.getNickName());
         msgInvite.setMode("成功领取邀请人的" + giftName);
         userInviteMsgNotificationService.receiveGift(uid, "邀请关系一旦确立无法更改 ", msgInvite);
      } catch (Exception e) {
         LogHelper.errorDetailInfo(e);
      }
   }
   @Override
   public List<TokenRecord> overdueList(int count) {
      return tokenRecordMapper.overdueList(count);