From 01e773cf27e572b8fb83538d85f31130930d93d1 Mon Sep 17 00:00:00 2001
From: yujian <yujian@123.com>
Date: 星期四, 15 八月 2019 15:57:23 +0800
Subject: [PATCH] 券赠送

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/user/TokenRecordServiceImpl.java |  154 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 154 insertions(+), 0 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 600614f..4c81db5 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
@@ -1,14 +1,27 @@
 package com.yeshi.fanli.service.impl.user;
 
+import java.util.ArrayList;
 import java.util.Date;
+import java.util.List;
 
 import javax.annotation.Resource;
 
 import org.springframework.stereotype.Service;
 
 import com.yeshi.fanli.dao.mybatis.user.TokenRecordMapper;
+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.UserSystemCoupon;
+import com.yeshi.fanli.exception.user.TokenRecordException;
+import com.yeshi.fanli.service.inter.hongbao.ThreeSaleSerivce;
 import com.yeshi.fanli.service.inter.user.TokenRecordService;
+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.util.StringUtil;
+import com.yeshi.fanli.vo.msg.TokenVO;
 
 @Service
 public class TokenRecordServiceImpl implements TokenRecordService{
@@ -16,10 +29,151 @@
 	@Resource
 	private TokenRecordMapper tokenRecordMapper;
 	
+	@Resource
+	private UserInfoService userInfoService;
+	
+	@Resource
+	private UserSystemCouponService userSystemCouponService;
+	
+	@Resource
+	private ThreeSaleSerivce threeSaleSerivce;
+	
+	
+	
 	@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 {
+		
+		// TODO token 楠岃瘉
+		
+		TokenRecord rokenRecord = tokenRecordMapper.getByToken(token);
+		if (rokenRecord == null) 
+			throw new TokenRecordException(1, "鍙d护涓嶅瓨鍦�");
+
+		String nickName = null;
+		String portrait = null;
+		Long inviteId = rokenRecord.getUid();
+		if (inviteId != null) {
+			UserInfo inviteUser = userInfoService.selectByPKey(inviteId);
+			if (inviteUser !=null) {
+				nickName = inviteUser.getNickName();
+				portrait = inviteUser.getPortrait();
+			}
+		}
+		
+		if (StringUtil.isNullOrEmpty(nickName))
+			nickName = Constant.systemCommonConfig.getDefaultNickName();
+			
+		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)) 
+			throw new TokenRecordException(1, "鍙d护鏍囪瘑涓嶅瓨鍦�");
+		
+		boolean state = false;
+		List<String> tips = new ArrayList<String>();
+		TokenTypeEnum tokenType = rokenRecord.getType();
+		if (tokenType == TokenTypeEnum.freeCoupon) {
+			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("鎴愬姛棰嗗彇鍚庯紝璇峰埌鈥滄垜鐨�-绂忓埄涓績鈥濇煡鐪嬨��");
+				} else {
+					tips.add("纭棰嗗彇鍚庯紝浣犲皢鎴愪负璧犻�佽�呯殑涓�绾ч槦鍛橈紱");
+					tips.add("鑾疯禒鐨勫厤鍗曞埜锛岄渶瑕佹縺娲诲悗鎵嶈兘浣跨敤锛岃鎯呭弬瑙佸厤鍗曞埜婵�娲昏鍒欙紱");
+					tips.add("鎴愬姛棰嗗彇鍚庯紝璇峰埌鈥滄垜鐨�-绂忓埄涓績鈥濇煡鐪嬨��");
+				}
+			}
+		} else if (tokenType == TokenTypeEnum.rebatePercentCoupon) {
+			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("鎴愬姛棰嗗彇鍚庯紝璇峰埌鈥滄垜鐨�-绂忓埄涓績鈥濅腑鏌ョ湅銆�");
+				} else {
+					tips.add("纭棰嗗彇鍚庯紝浣犲皢鎴愪负璧犻�佽�呯殑涓�绾ч槦鍛橈紱");
+					tips.add("杩斿埄鍒稿鍔卞埜锛屽彲鐢ㄤ簬鈥滃凡鍒拌处鈥濈殑杩斿埄璁㈠崟锛屽湪杩斿埄鐨勫熀纭�涓婂啀鑾峰緱涓�瀹氭瘮渚嬬殑杩斿埄锛�");
+					tips.add("鎴愬姛棰嗗彇鍚庯紝璇峰埌鈥滄垜鐨�-绂忓埄涓績鈥濅腑鏌ョ湅銆�");
+				}
+			}
+		} 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) {
+				if (uid == null || uid <= 0)
+					throw new TokenRecordException(1001, "鐢ㄦ埛鏈櫥褰�");
+				
+				state = true;
+				ThreeSale boss = threeSaleSerivce.getMyBoss(uid);
+				if (boss != null) {
+					tips.add("杩斿埄鍒稿鍔卞埜锛屽彲鐢ㄤ簬鈥滃凡鍒拌处鈥濈殑杩斿埄璁㈠崟锛屽湪杩斿埄鐨勫熀纭�涓婂啀鑾峰緱涓�瀹氭瘮渚嬬殑杩斿埄锛�");
+					tips.add("鎴愬姛棰嗗彇鍚庯紝璇峰埌鈥滄垜鐨�-绂忓埄涓績鈥濅腑鏌ョ湅銆�");
+				} else {
+					tips.add("纭棰嗗彇鍚庯紝浣犲皢鎴愪负璧犻�佽�呯殑涓�绾ч槦鍛橈紱");
+					tips.add("杩斿埄鍒稿鍔卞埜锛屽彲鐢ㄤ簬鈥滃凡鍒拌处鈥濈殑杩斿埄璁㈠崟锛屽湪杩斿埄鐨勫熀纭�涓婂啀鑾峰緱涓�瀹氭瘮渚嬬殑杩斿埄锛�");
+					tips.add("鎴愬姛棰嗗彇鍚庯紝璇峰埌鈥滄垜鐨�-绂忓埄涓績鈥濅腑鏌ョ湅銆�");
+				}
+			}
+		} else {
+			throw new TokenRecordException(1, "鏃犲搴旂被鍨�");
+		}
+		
+		tokenVO.setTips(tips);
+		tokenVO.setState(state);
+		tokenVO.setType(tokenType.name());
+		
+	}
+	
 }

--
Gitblit v1.8.0