fanli/src/main/java/com/yeshi/fanli/dao/mybatis/user/UserSystemCouponGiveRecordMapper.java
@@ -1,8 +1,19 @@ package com.yeshi.fanli.dao.mybatis.user; import org.apache.ibatis.annotations.Param; import com.yeshi.fanli.dao.BaseMapper; import com.yeshi.fanli.entity.bus.user.UserSystemCouponGiveRecord; public interface UserSystemCouponGiveRecordMapper extends BaseMapper<UserSystemCouponGiveRecord> { /** * 赠送记录 * @param uid 赠送人id * @param couponId 券id * @return */ UserSystemCouponGiveRecord getRecordByUidAndCouponId(@Param("uid") Long uid, @Param("couponId") Long couponId); } fanli/src/main/java/com/yeshi/fanli/mapping/user/UserSystemCouponGiveRecordMapper.xml
@@ -44,4 +44,9 @@ <if test="receiveTime != null">cgr_receive_time=#{receiveTime,jdbcType=TIMESTAMP},</if> </set> where cgr_id = #{id,jdbcType=BIGINT} </update> <select id="getRecordByUidAndCouponId"> SELECT * FROM yeshi_ec_user_system_coupon_give_record WHERE cgr_give_uid = #{uid} AND cgr_coupon_id = #{couponId} LIMIT 1 </select> </mapper> fanli/src/main/java/com/yeshi/fanli/service/impl/user/TokenRecordServiceImpl.java
@@ -7,11 +7,9 @@ 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; @@ -19,13 +17,13 @@ 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.UserSystemCouponGiveRecordService; import com.yeshi.fanli.service.inter.user.UserSystemCouponService; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.StringUtil; @@ -52,6 +50,9 @@ @Resource private UserInfoExtraService userInfoExtraService; @Resource private UserSystemCouponGiveRecordService userSystemCouponGiveRecordService; @Override public void insertSelective(TokenRecord record) { record.setCreateTime(new Date()); @@ -227,8 +228,13 @@ if (StringUtil.isNullOrEmpty(identify)) throw new TokenRecordException(1, "口令标识不存在"); boolean receive = false; Long giveUid = rokenRecord.getUid(); UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid); if (userInfoExtra == null) throw new TokenRecordException(1, "用户信息缺失"); boolean receive = false; TokenTypeEnum tokenType = rokenRecord.getType(); if (tokenType == TokenTypeEnum.freeCoupon) { UserSystemCoupon userCoupon = userSystemCouponService.selectByPrimaryKey(Long.parseLong(identify)); @@ -253,8 +259,11 @@ userSystemCouponService.insertUserCoupon(uid, CouponTypeEnum.freeCoupon.name(), UserSystemCoupon.SOURCE_GIVE); } catch (Exception e) { LogHelper.errorDetailInfo(e); throw new TokenRecordException(1, "领取失败"); } // 更新记录 userSystemCouponGiveRecordService.updateRecord(uid, giveUid, Long.parseLong(identify)); // 领取成功 receive = true; } else { @@ -285,6 +294,7 @@ userSystemCouponService.insertUserCoupon(uid, CouponTypeEnum.rebatePercentCoupon.name(), UserSystemCoupon.SOURCE_GIVE); } catch (Exception e) { LogHelper.errorDetailInfo(e); throw new TokenRecordException(1, "领取失败"); } // 领取成功 receive = true; @@ -300,6 +310,9 @@ throw new TokenRecordException(1, "哎呀,推广红包已被领取了!"); } else { } } else { throw new TokenRecordException(1, "无对应类型"); @@ -308,7 +321,12 @@ if (receive) throw new TokenRecordException(1, "领取失败啦"); UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid); if (StringUtil.isNullOrEmpty(userInfoExtra.getInviteCode())) { // 成为下级 } } } fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoExtraServiceImpl.java
@@ -650,4 +650,67 @@ } return inviter; } @Override public String activateUser(Long uid, String inviteUid) throws UserInfoExtraException{ if (uid == null || inviteUid == null) { throw new UserInfoExtraException(1, "传递id不能为空"); } // 被邀请人信息 UserInfo invitee = userInfoService.selectByPKey(uid); if (invitee == null) { throw new UserInfoExtraException(1, "用户不存在"); } UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid); if (extra != null) { String inviteCodeHas = extra.getInviteCode(); if (inviteCodeHas != null && inviteCodeHas.trim().length() > 0) { throw new UserInfoExtraException(1, "已存在邀请码,请刷新页面"); } } // 邀请人信息 UserInfo inviter = userInfoService.getInfoByPhoneOrInviteCode(inviteCode, inviteCode); if (inviter == null) { throw new UserInfoExtraException(1, "上级邀请码不存在"); } // 绑定关系 try { threeSaleSerivce.bindRelationshipByInviteCode(invitee, inviter); } catch (ThreeSaleException e) { try { LogHelper.errorDetailInfo(e); } catch (Exception e1) { e1.printStackTrace(); } throw new UserInfoExtraException(1, "激活失败"); } // 邀请码有效、生成邀请码 String code = UserUtil.getInviteCode(uid); if (code == null || code.trim().length() == 0) { throw new UserInfoExtraException(1, "激活码生成失败"); } UserInfoExtra userInfoExtra = new UserInfoExtra(); userInfoExtra.setUserInfo(invitee); userInfoExtra.setInviteCode(code); // 保存额外信息 saveUserInfoExtra(userInfoExtra); Long id = userInfoExtra.getId(); if (id == null) { throw new UserInfoExtraException(1, "激活码生成失败"); } return code; } } fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponGiveRecordServiceImpl.java
@@ -1,5 +1,7 @@ package com.yeshi.fanli.service.impl.user; import java.util.Date; import javax.annotation.Resource; import org.springframework.stereotype.Service; @@ -20,4 +22,15 @@ userSystemCouponGiveRecordMapper.insertSelective(record); } @Override public void updateRecord(Long receiveUid, Long giveUid, Long couponId) { UserSystemCouponGiveRecord record = userSystemCouponGiveRecordMapper.getRecordByUidAndCouponId(giveUid, couponId); if (record != null) { UserSystemCouponGiveRecord giveRecord = new UserSystemCouponGiveRecord(); giveRecord.setId(record.getId()); giveRecord.setReceiveUid(receiveUid); giveRecord.setReceiveTime(new Date()); userSystemCouponGiveRecordMapper.updateByPrimaryKeySelective(giveRecord); } } } fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponServiceImpl.java
@@ -198,8 +198,8 @@ } SystemCoupon coupon = null; if (couponType.equals(CouponTypeEnum.welfareFreeCoupon.name())) { // 福利免单券 if (couponType.equals(CouponTypeEnum.welfareFreeCoupon.name()) || couponType.equals(CouponTypeEnum.freeCoupon.name())) { // 免单券 coupon = systemCouponService.getCouponByType(couponType); } else if (couponType.equals(CouponTypeEnum.rebatePercentCoupon.name())) { // 随机奖励券 @@ -219,6 +219,8 @@ if (countSuccess == 0) { stateActivated = 0; } } else if (coupon.getType() == CouponTypeEnum.freeCoupon) { stateActivated = 0; } // 结束日期 fanli/src/main/java/com/yeshi/fanli/service/inter/user/UserSystemCouponGiveRecordService.java
@@ -6,5 +6,13 @@ public void insertSelective(UserSystemCouponGiveRecord record); /** * 更新领取记录 * @param receiveUid * @param giveUid * @param couponId */ public void updateRecord(Long receiveUid, Long giveUid, Long couponId); }