| | |
| | | package com.yeshi.fanli.service.impl.user;
|
| | |
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
| | | import org.springframework.core.task.TaskExecutor;
|
| | | import org.springframework.stereotype.Service;
|
| | |
|
| | | import com.google.gson.Gson;
|
| | | 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.dto.msg.MsgRedPackGiveContentDTO;
|
| | | import com.yeshi.fanli.entity.accept.AcceptData;
|
| | | import com.yeshi.fanli.entity.bus.msg.MsgMoneyDetail.MsgTypeMoneyTypeEnum;
|
| | | 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.redpack.RedPackGiveRecord;
|
| | | import com.yeshi.fanli.entity.system.SystemCoupon;
|
| | | import com.yeshi.fanli.entity.system.SystemCoupon.CouponTypeEnum;
|
| | | import com.yeshi.fanli.exception.redpack.RedPackGiveRecordException;
|
| | | import com.yeshi.fanli.exception.user.TokenRecordException;
|
| | | import com.yeshi.fanli.exception.user.UserInfoExtraException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | |
| | |
|
| | | UserSystemCoupon userSystemCoupon = null;
|
| | | try {
|
| | | userSystemCoupon = userSystemCouponService.insertUserCoupon(uid, CouponTypeEnum.freeCoupon.name(),
|
| | | UserSystemCoupon.SOURCE_GIVE, null, true);
|
| | | userSystemCoupon = userSystemCouponService.freeCouponWin(giveUid, CouponTypeEnum.freeCoupon, |
| | | UserSystemCoupon.SOURCE_GIVE, 1, true);
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | throw new TokenRecordException(1, "领取失败");
|
| | |
| | | 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_COUPON);
|
| | | 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);
|
| | |
|
| | | // 激活邀请信息
|
| | | if (addTeam)
|
| | | addInviteMsg(uid, giveUid, "免单券");
|
| | | addInviteTeam(uid, giveUid, userInfoExtra);
|
| | | }
|
| | | });
|
| | | } else if (tokenType == TokenTypeEnum.rebatePercentCoupon) {
|
| | |
| | |
|
| | | UserSystemCoupon userSystemCoupon = null;
|
| | | try {
|
| | | userSystemCoupon = userSystemCouponService.insertUserCoupon(uid,
|
| | | CouponTypeEnum.rebatePercentCoupon.name(), UserSystemCoupon.SOURCE_GIVE,
|
| | | systemCoupon.getPercent(), true);
|
| | | userSystemCoupon = userSystemCouponService.rewardCouponWin(uid, UserSystemCoupon.SOURCE_GIVE, 1, true, |
| | | systemCoupon.getPercent());
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | throw new TokenRecordException(1, "领取失败");
|
| | |
| | |
|
| | | @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_COUPON);
|
| | | 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);
|
| | |
|
| | | // 激活邀请信息
|
| | | if (addTeam)
|
| | | addInviteMsg(uid, giveUid, "返利奖励券");
|
| | | addInviteTeam(uid, giveUid, userInfoExtra);
|
| | | }
|
| | | });
|
| | | } else if (tokenType == TokenTypeEnum.redPack) {
|
| | | if (!VersionUtil.greaterThan_2_0_5(acceptData.getPlatform(), acceptData.getVersion()))
|
| | | throw new TokenRecordException(1, "请升级到最新版");
|
| | |
|
| | | try {
|
| | | msg = "领取红包成功,请到[我的-红包]中查看";
|
| | | // 领取红包、更新记录
|
| | | RedPackGiveRecord giveRecord = redPackGiveRecordService.receiveFriendsGive(uid,
|
| | | Long.parseLong(identify));
|
| | | // 消息 + 队员
|
| | | 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 = "无";
|
| | | String giveBeiZhu = "无";
|
| | | if (addTeam) {
|
| | | beiZhu = "你已成为赠送人的直接粉丝";
|
| | | giveBeiZhu = "领取人已成为你的直接粉丝";
|
| | | // 激活邀请信息
|
| | | addInviteMsg(uid, giveUid, giveRecord.getAmount().setScale(2) + "元红包");
|
| | | }
|
| | |
|
| | | // 领取人消息
|
| | | String giveUserName = "无";
|
| | | UserInfo giveuser = userInfoService.selectByPKey(giveUid);
|
| | | if (giveuser != null && !StringUtil.isNullOrEmpty(giveuser.getNickName()))
|
| | | giveUserName = giveuser.getNickName();
|
| | | MsgRedPackGiveContentDTO dto = new MsgRedPackGiveContentDTO();
|
| | | dto.setTitle("红包领取");
|
| | | dto.setUserInfo("昵称:" + giveUserName + " ID:" + giveUid);
|
| | | dto.setTime(sd.format(giveRecord.getGiveTime()));
|
| | | dto.setMoney("¥" + giveRecord.getAmount().setScale(2));
|
| | | userMoneyMsgNotificationService.redPackMsg(uid, MsgTypeMoneyTypeEnum.redPackReceiveOff,
|
| | | new Gson().toJson(dto), beiZhu);
|
| | |
|
| | | // 赠送人消息
|
| | | String userName = "无";
|
| | | UserInfo user = userInfoService.selectByPKey(uid);
|
| | | if (user != null && !StringUtil.isNullOrEmpty(user.getNickName()))
|
| | | userName = user.getNickName();
|
| | | MsgRedPackGiveContentDTO givedto = new MsgRedPackGiveContentDTO();
|
| | | givedto.setTitle("红包赠送");
|
| | | givedto.setUserInfo("昵称:" + userName + " ID:" + uid);
|
| | | givedto.setTime(sd.format(new Date()));
|
| | | givedto.setMoney("¥" + giveRecord.getAmount().setScale(2));
|
| | | userMoneyMsgNotificationService.redPackMsg(giveUid, MsgTypeMoneyTypeEnum.redPackGiveOff,
|
| | | new Gson().toJson(givedto), giveBeiZhu);
|
| | | }
|
| | | });
|
| | | } catch (RedPackGiveRecordException e) {
|
| | | throw new TokenRecordException(1, e.getMsg());
|
| | | }
|
| | | msg = "领取红包成功,请到[我的-红包]中查看";
|
| | | // 消息 + 队员
|
| | | executor.execute(new Runnable() {
|
| | | @Override
|
| | | public void run() {
|
| | | addInviteTeam(uid, giveUid, userInfoExtra);
|
| | | }
|
| | | });
|
| | | } else if (tokenType == TokenTypeEnum.taoLiJin) {
|
| | | throw new TokenRecordException(1, "推广红包相关功能已下线!");
|
| | | } else {
|
| | |
| | | return invite;
|
| | | }
|
| | |
|
| | | private void addInviteMsg(Long uid, Long giveUid, String giftName) {
|
| | | try {
|
| | | UserInfo user = userInfoService.selectByPKey(giveUid);
|
| | | UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
|
| | |
|
| | | String inviteCode = null;
|
| | | if (!StringUtil.isNullOrEmpty(userInfoExtra.getInviteCodeVip())) {
|
| | | inviteCode = userInfoExtra.getInviteCodeVip();
|
| | | } else {
|
| | | inviteCode = userInfoExtra.getInviteCode();
|
| | | }
|
| | |
|
| | | MsgInviteContentDTO msgInvite = new MsgInviteContentDTO();
|
| | | msgInvite.setTitle("邀请消息");
|
| | | msgInvite.setState("成功激活邀请");
|
| | | msgInvite.setCode("你的邀请码:" + inviteCode);
|
| | | msgInvite.setInviter("昵称:" + user.getNickName());
|
| | | msgInvite.setMode("成功领取邀请人的" + giftName);
|
| | | userInviteMsgNotificationService.receiveGift(uid, "邀请关系一旦确立无法更改 ", msgInvite);
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<TokenRecord> overdueList(int count) {
|