| | |
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.yeshi.utils.JsonUtil;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.user.TokenRecordMapper;
|
| | | import com.yeshi.fanli.entity.bus.tlj.UserTaoLiJinGiveRecord;
|
| | | import com.yeshi.fanli.entity.bus.user.ThreeSale;
|
| | | 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;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfoExtra;
|
| | | import com.yeshi.fanli.entity.bus.user.UserSystemCoupon;
|
| | | import com.yeshi.fanli.entity.system.SystemCoupon.CouponTypeEnum;
|
| | | import com.yeshi.fanli.exception.user.TokenRecordException;
|
| | | import com.yeshi.fanli.exception.user.UserSystemCouponException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.hongbao.ThreeSaleSerivce;
|
| | | import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinGiveRecordService;
|
| | | 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.UserSystemCouponService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | |
| | | import com.yeshi.fanli.vo.msg.TokenVO;
|
| | |
|
| | | @Service
|
| | | public class TokenRecordServiceImpl implements TokenRecordService{
|
| | | public class TokenRecordServiceImpl implements TokenRecordService {
|
| | |
|
| | | @Resource
|
| | | private TokenRecordMapper tokenRecordMapper;
|
| | | |
| | |
|
| | | @Resource
|
| | | private UserInfoService userInfoService;
|
| | | |
| | |
|
| | | @Resource
|
| | | private UserSystemCouponService userSystemCouponService;
|
| | | |
| | |
|
| | | @Resource
|
| | | private ThreeSaleSerivce threeSaleSerivce;
|
| | | |
| | | |
| | | |
| | |
|
| | | @Resource
|
| | | private UserTaoLiJinGiveRecordService userTaoLiJinGiveRecordService;
|
| | |
|
| | | @Resource
|
| | | private UserInfoExtraService userInfoExtraService;
|
| | |
|
| | | @Override
|
| | | public void insertSelective(TokenRecord record) {
|
| | | record.setCreateTime(new Date());
|
| | | record.setUpdateTime(new Date());
|
| | | tokenRecordMapper.insertSelective(record);
|
| | | }
|
| | | |
| | |
|
| | | @Override
|
| | | public TokenRecord getNearByTypeAndIdentify(String type, String identify) {
|
| | | return tokenRecordMapper.getNearByTypeAndIdentify(type, identify);
|
| | | }
|
| | |
|
| | | |
| | | public void discernToken(String token, Long uid) throws TokenRecordException {
|
| | | |
| | | @Override
|
| | | public TokenVO discernToken(String token, Long uid) throws TokenRecordException {
|
| | |
|
| | | // TODO token 验证
|
| | | |
| | |
|
| | | TokenRecord rokenRecord = tokenRecordMapper.getByToken(token);
|
| | | if (rokenRecord == null) |
| | | if (rokenRecord == null)
|
| | | throw new TokenRecordException(1, "口令不存在");
|
| | |
|
| | | String nickName = null;
|
| | |
| | | Long inviteId = rokenRecord.getUid();
|
| | | if (inviteId != null) {
|
| | | UserInfo inviteUser = userInfoService.selectByPKey(inviteId);
|
| | | if (inviteUser !=null) {
|
| | | if (inviteUser != null) {
|
| | | nickName = inviteUser.getNickName();
|
| | | portrait = inviteUser.getPortrait();
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | if (StringUtil.isNullOrEmpty(nickName))
|
| | | nickName = Constant.systemCommonConfig.getDefaultNickName();
|
| | | |
| | | if (StringUtil.isNullOrEmpty(portrait)) |
| | |
|
| | | if (StringUtil.isNullOrEmpty(portrait))
|
| | | portrait = Constant.systemCommonConfig.getDefaultPortrait();
|
| | | |
| | |
|
| | | if (nickName.length() > 6) {
|
| | | nickName = nickName.substring(0, 6) + "...";
|
| | | }
|
| | | |
| | |
|
| | | Integer stateTtoken = rokenRecord.getState();
|
| | | if (stateTtoken == 1)
|
| | | throw new TokenRecordException(1, "口令已失效");
|
| | | |
| | |
|
| | | TokenVO tokenVO = new TokenVO();
|
| | | tokenVO.setNickName(nickName);
|
| | | tokenVO.setPortrait(portrait);
|
| | | |
| | |
|
| | | String identify = rokenRecord.getIdentify();
|
| | | if (StringUtil.isNullOrEmpty(identify)) |
| | | if (StringUtil.isNullOrEmpty(identify))
|
| | | throw new TokenRecordException(1, "口令标识不存在");
|
| | | |
| | |
|
| | | Integer type = 0;
|
| | | boolean state = false;
|
| | | List<String> tips = new ArrayList<String>();
|
| | | TokenTypeEnum tokenType = rokenRecord.getType();
|
| | | if (tokenType == TokenTypeEnum.freeCoupon) {
|
| | | type = 10;
|
| | | UserSystemCoupon userCoupon = userSystemCouponService.selectByPrimaryKey(Long.parseLong(identify));
|
| | | if (userCoupon == null || userCoupon.getState() == UserSystemCoupon.STATE_OVERDUE) {
|
| | | if (userCoupon == null) {
|
| | | tips.add("哎呀,这张免单券已失效了!");
|
| | | } else if (userCoupon.getState() == UserSystemCoupon.STATE_END_USE) {
|
| | | tips.add("哎呀,这张免单券已被领取了!");
|
| | | } else if (userCoupon.getState() == UserSystemCoupon.STATE_CAN_USE) {
|
| | | throw new TokenRecordException(1, "口令已失效");
|
| | | } else if (userCoupon.getState() == UserSystemCoupon.STATE_IN_USE) {
|
| | | if (uid == null || uid <= 0)
|
| | | throw new TokenRecordException(1001, "用户未登录");
|
| | | |
| | | state = true;
|
| | | ThreeSale boss = threeSaleSerivce.getMyBoss(uid);
|
| | | if (boss != null) {
|
| | | tips.add("获赠的免单券,需要激活后才能使用,详情参见免单券激活规则;");
|
| | | tips.add("成功领取后,请到“我的-福利中心”查看。");
|
| | | } else {
|
| | | Boolean give = userCoupon.getGive();
|
| | | if (give == null)
|
| | | give = false;
|
| | |
|
| | | if (userCoupon.getState() == UserSystemCoupon.STATE_OVERDUE) {
|
| | | tips.add("哎呀,这张免单券已失效了!");
|
| | | } else if (userCoupon.getState() == UserSystemCoupon.STATE_END_USE) {
|
| | | tips.add("哎呀,这张免单券已被领取了!");
|
| | | } else if (userCoupon.getState() == UserSystemCoupon.STATE_CAN_USE) {
|
| | | throw new TokenRecordException(1, "口令已失效");
|
| | | } else if (give && userCoupon.getState() == UserSystemCoupon.STATE_IN_USE) {
|
| | | if (uid == null || uid <= 0)
|
| | | throw new TokenRecordException(1001, "温馨提示,[免单券]需要登录后领取");
|
| | |
|
| | | state = true;
|
| | | UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
|
| | | if (userInfoExtra == null || StringUtil.isNullOrEmpty(userInfoExtra.getInviteCode())) {
|
| | | tips.add("确认领取后,你将成为赠送者的一级队员;");
|
| | | tips.add("获赠的免单券,需要激活后才能使用,详情参见免单券激活规则;");
|
| | | tips.add("成功领取后,请到“我的-福利中心”查看。");
|
| | | } else {
|
| | | tips.add("获赠的免单券,需要激活后才能使用,详情参见免单券激活规则;");
|
| | | tips.add("成功领取后,请到“我的-福利中心”查看。");
|
| | | }
|
| | | } else {
|
| | | tips.add("确认领取后,你将成为赠送者的一级队员;");
|
| | | tips.add("获赠的免单券,需要激活后才能使用,详情参见免单券激活规则;");
|
| | | tips.add("成功领取后,请到“我的-福利中心”查看。");
|
| | | throw new TokenRecordException(1, "口令已失效");
|
| | | }
|
| | | }
|
| | | } else if (tokenType == TokenTypeEnum.rebatePercentCoupon) {
|
| | | type = 11;
|
| | | UserSystemCoupon userCoupon = userSystemCouponService.selectByPrimaryKey(Long.parseLong(identify));
|
| | | if (userCoupon == null || userCoupon.getState() == UserSystemCoupon.STATE_OVERDUE) {
|
| | | tips.add("哎呀,这张返利奖励券已失效了!");
|
| | | } else if (userCoupon.getState() == UserSystemCoupon.STATE_END_USE) {
|
| | | tips.add("哎呀,这张返利奖励券已被领取了!");
|
| | | } else if (userCoupon.getState() == UserSystemCoupon.STATE_CAN_USE) {
|
| | | throw new TokenRecordException(1, "口令已失效");
|
| | | } else if (userCoupon.getState() == UserSystemCoupon.STATE_IN_USE) {
|
| | | if (uid == null || uid <= 0)
|
| | | throw new TokenRecordException(1001, "用户未登录");
|
| | | |
| | | state = true;
|
| | | ThreeSale boss = threeSaleSerivce.getMyBoss(uid);
|
| | | if (boss != null) {
|
| | | tips.add("返利券奖励券,可用于“已到账”的返利订单,在返利的基础上再获得一定比例的返利;");
|
| | | tips.add("成功领取后,请到“我的-福利中心”中查看。");
|
| | | if (userCoupon == null) {
|
| | |
|
| | | } else {
|
| | | Boolean give = userCoupon.getGive();
|
| | | if (give == null)
|
| | | give = false;
|
| | |
|
| | | if (userCoupon.getState() == UserSystemCoupon.STATE_OVERDUE) {
|
| | | tips.add("哎呀,这张返利奖励券已失效了!");
|
| | | } else if (userCoupon.getState() == UserSystemCoupon.STATE_END_USE) {
|
| | | tips.add("哎呀,这张返利奖励券已被领取了!");
|
| | | } else if (userCoupon.getState() == UserSystemCoupon.STATE_CAN_USE) {
|
| | | throw new TokenRecordException(1, "口令已失效");
|
| | | } else if (give && userCoupon.getState() == UserSystemCoupon.STATE_IN_USE) {
|
| | | if (uid == null || uid <= 0)
|
| | | throw new TokenRecordException(1001, "温馨提示,[返利奖励券]需要登录后领取");
|
| | |
|
| | | state = true;
|
| | | UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
|
| | | if (userInfoExtra == null || StringUtil.isNullOrEmpty(userInfoExtra.getInviteCode())) {
|
| | | tips.add("确认领取后,你将成为赠送者的一级队员;");
|
| | | tips.add("返利券奖励券,可用于“已到账”的返利订单,在返利的基础上再获得一定比例的返利;");
|
| | | tips.add("成功领取后,请到“我的-福利中心”中查看。");
|
| | | } else {
|
| | | tips.add("返利券奖励券,可用于“已到账”的返利订单,在返利的基础上再获得一定比例的返利;");
|
| | | tips.add("成功领取后,请到“我的-福利中心”中查看。");
|
| | | }
|
| | | } else {
|
| | | tips.add("确认领取后,你将成为赠送者的一级队员;");
|
| | | tips.add("返利券奖励券,可用于“已到账”的返利订单,在返利的基础上再获得一定比例的返利;");
|
| | | tips.add("成功领取后,请到“我的-福利中心”中查看。");
|
| | | throw new TokenRecordException(1, "口令已失效");
|
| | | }
|
| | | }
|
| | | } else if (tokenType == TokenTypeEnum.taoLiJin) {
|
| | | UserSystemCoupon userCoupon = userSystemCouponService.selectByPrimaryKey(Long.parseLong(identify));
|
| | | if (userCoupon == null || userCoupon.getState() == UserSystemCoupon.STATE_OVERDUE) {
|
| | | tips.add("哎呀,这张返利奖励券已失效了!");
|
| | | } else if (userCoupon.getState() == UserSystemCoupon.STATE_END_USE) {
|
| | | tips.add("哎呀,这张返利奖励券已被领取了!");
|
| | | } else if (userCoupon.getState() == UserSystemCoupon.STATE_CAN_USE) {
|
| | | throw new TokenRecordException(1, "口令已失效");
|
| | | } else if (userCoupon.getState() == UserSystemCoupon.STATE_IN_USE) {
|
| | | 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 (uid == null || uid <= 0)
|
| | | throw new TokenRecordException(1001, "用户未登录");
|
| | | |
| | | throw new TokenRecordException(1001, "温馨提示,[推广红包]需要登录后领取");
|
| | |
|
| | | state = true;
|
| | | ThreeSale boss = threeSaleSerivce.getMyBoss(uid);
|
| | | if (boss != null) {
|
| | | tips.add("返利券奖励券,可用于“已到账”的返利订单,在返利的基础上再获得一定比例的返利;");
|
| | | tips.add("成功领取后,请到“我的-福利中心”中查看。");
|
| | | } else {
|
| | | UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
|
| | | if (userInfoExtra == null || StringUtil.isNullOrEmpty(userInfoExtra.getInviteCode())) {
|
| | | tips.add("确认领取后,你将成为赠送者的一级队员;");
|
| | | tips.add("返利券奖励券,可用于“已到账”的返利订单,在返利的基础上再获得一定比例的返利;");
|
| | | tips.add("成功领取后,请到“我的-福利中心”中查看。");
|
| | | tips.add("推广红包,可分享爆款商品,让分享订单成单率更高;");
|
| | | tips.add("成功领取后,请到“我的-推广红包”中查看。");
|
| | | } else {
|
| | | tips.add("推广红包,可分享爆款商品,让分享订单成单率更高;");
|
| | | tips.add("成功领取后,请到“我的-推广红包”中查看。");
|
| | | }
|
| | | }
|
| | | } else {
|
| | | throw new TokenRecordException(1, "无对应类型");
|
| | | }
|
| | | |
| | |
|
| | | tokenVO.setTips(tips);
|
| | | tokenVO.setState(state);
|
| | | tokenVO.setType(tokenType.name());
|
| | | |
| | | tokenVO.setType(type);
|
| | | return tokenVO;
|
| | | }
|
| | | |
| | |
|
| | | @Override
|
| | | public void receiveToken(String token, Long uid) throws TokenRecordException {
|
| | | if (uid == null || uid <= 0)
|
| | | throw new TokenRecordException(1, "用户未登录");
|
| | |
|
| | | if (StringUtil.isNullOrEmpty(token))
|
| | | throw new TokenRecordException(1, "口令不能为空");
|
| | |
|
| | | TokenRecord rokenRecord = tokenRecordMapper.getByToken(token);
|
| | | if (rokenRecord == null || rokenRecord.getState() == 1)
|
| | | throw new TokenRecordException(1, "口令已失效");
|
| | |
|
| | | String identify = rokenRecord.getIdentify();
|
| | | if (StringUtil.isNullOrEmpty(identify))
|
| | | throw new TokenRecordException(1, "口令标识不存在");
|
| | | |
| | | boolean receive = false;
|
| | | |
| | | TokenTypeEnum tokenType = rokenRecord.getType();
|
| | | if (tokenType == TokenTypeEnum.freeCoupon) {
|
| | | UserSystemCoupon userCoupon = userSystemCouponService.selectByPrimaryKey(Long.parseLong(identify));
|
| | | if (userCoupon == null)
|
| | | throw new TokenRecordException(1, "该券不存在");
|
| | |
|
| | | Boolean give = userCoupon.getGive();
|
| | | if (give == null)
|
| | | give = false;
|
| | | |
| | | if (userCoupon.getState() == UserSystemCoupon.STATE_OVERDUE)
|
| | | throw new TokenRecordException(1, "哎呀,这张免单券已失效了!");
|
| | | |
| | | if (userCoupon.getState() == UserSystemCoupon.STATE_END_USE)
|
| | | throw new TokenRecordException(1, "哎呀,这张免单券已被领取了!");
|
| | | |
| | | if (userCoupon.getState() == UserSystemCoupon.STATE_CAN_USE)
|
| | | throw new TokenRecordException(1, "口令已失效");
|
| | | |
| | | if (give && userCoupon.getState() == UserSystemCoupon.STATE_IN_USE) {
|
| | | try {
|
| | | userSystemCouponService.insertUserCoupon(uid, CouponTypeEnum.freeCoupon.name(), UserSystemCoupon.SOURCE_GIVE);
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | | |
| | | // 领取成功
|
| | | receive = true;
|
| | | } else {
|
| | | throw new TokenRecordException(1, "口令已失效");
|
| | | }
|
| | |
|
| | | } else if (tokenType == TokenTypeEnum.rebatePercentCoupon) {
|
| | | UserSystemCoupon userCoupon = userSystemCouponService.selectByPrimaryKey(Long.parseLong(identify));
|
| | |
|
| | | if (userCoupon == null)
|
| | | throw new TokenRecordException(1, "该券不存在");
|
| | |
|
| | | Boolean give = userCoupon.getGive();
|
| | | if (give == null)
|
| | | give = false;
|
| | |
|
| | | if (userCoupon.getState() == UserSystemCoupon.STATE_OVERDUE)
|
| | | throw new TokenRecordException(1, "哎呀,这张返利奖励券已失效了!");
|
| | | |
| | | if (userCoupon.getState() == UserSystemCoupon.STATE_END_USE) |
| | | throw new TokenRecordException(1, "哎呀,这张返利奖励券已被领取了!");
|
| | | |
| | | if (userCoupon.getState() == UserSystemCoupon.STATE_CAN_USE)
|
| | | throw new TokenRecordException(1, "口令已失效");
|
| | | |
| | | if (give && userCoupon.getState() == UserSystemCoupon.STATE_IN_USE) {
|
| | | try {
|
| | | userSystemCouponService.insertUserCoupon(uid, CouponTypeEnum.rebatePercentCoupon.name(), UserSystemCoupon.SOURCE_GIVE);
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | | // 领取成功
|
| | | receive = true;
|
| | | } else {
|
| | | throw new TokenRecordException(1, "口令已失效");
|
| | | }
|
| | | } else if (tokenType == TokenTypeEnum.taoLiJin) {
|
| | | UserTaoLiJinGiveRecord giveRecord = userTaoLiJinGiveRecordService
|
| | | .selectByPrimaryKey(Long.parseLong(identify));
|
| | | if (giveRecord == null || giveRecord.getState() == UserTaoLiJinGiveRecord.STATE_OVERDUE) {
|
| | | throw new TokenRecordException(1, "哎呀,哎呀,推广红包已失效了!");
|
| | | } else if (giveRecord.getState() == UserTaoLiJinGiveRecord.STATE_RECEIVE) {
|
| | | throw new TokenRecordException(1, "哎呀,推广红包已被领取了!");
|
| | | } else {
|
| | |
|
| | | }
|
| | | } else {
|
| | | throw new TokenRecordException(1, "无对应类型");
|
| | | }
|
| | |
|
| | | if (receive) |
| | | throw new TokenRecordException(1, "领取失败啦");
|
| | | |
| | | UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
|
| | |
|
| | | }
|
| | | }
|