From 1db61f9479d537ecf2c030d8b9cb45b1e0bf0eec Mon Sep 17 00:00:00 2001 From: yujian <yujian@123.com> Date: 星期五, 16 八月 2019 11:59:39 +0800 Subject: [PATCH] 口令 --- fanli/src/main/java/com/yeshi/fanli/service/impl/user/TokenRecordServiceImpl.java | 293 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 214 insertions(+), 79 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/TokenRecordServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/TokenRecordServiceImpl.java index 4c81db5..f79dcc0 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/TokenRecordServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/TokenRecordServiceImpl.java @@ -7,16 +7,24 @@ 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; @@ -24,41 +32,45 @@ 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, "鍙d护涓嶅瓨鍦�"); String nickName = null; @@ -66,114 +78,237 @@ 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, "鍙d护宸插け鏁�"); - + 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, "鍙d护鏍囪瘑涓嶅瓨鍦�"); - + + 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, "鍙d护宸插け鏁�"); - } 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, "鍙d护宸插け鏁�"); + } 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, "鍙d护宸插け鏁�"); } } } 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, "鍙d护宸插け鏁�"); - } 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, "鍙d护宸插け鏁�"); + } 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, "鍙d护宸插け鏁�"); } } } 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, "鍙d护宸插け鏁�"); - } 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, "鍙d护涓嶈兘涓虹┖"); + + TokenRecord rokenRecord = tokenRecordMapper.getByToken(token); + if (rokenRecord == null || rokenRecord.getState() == 1) + throw new TokenRecordException(1, "鍙d护宸插け鏁�"); + + String identify = rokenRecord.getIdentify(); + if (StringUtil.isNullOrEmpty(identify)) + throw new TokenRecordException(1, "鍙d护鏍囪瘑涓嶅瓨鍦�"); + + 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, "鍙d护宸插け鏁�"); + + 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, "鍙d护宸插け鏁�"); + } + + } 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, "鍙d护宸插け鏁�"); + + 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, "鍙d护宸插け鏁�"); + } + } 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); + + } } -- Gitblit v1.8.0