From 89e89fe2b2a1578a94b2e2c8ee81efbfbbf85f08 Mon Sep 17 00:00:00 2001
From: yujian <yujian@123.com>
Date: 星期五, 23 八月 2019 14:18:42 +0800
Subject: [PATCH] 兑换邀请码调整

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralGetServiceImpl.java |  441 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 418 insertions(+), 23 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralGetServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralGetServiceImpl.java
index 1cca4d4..f14c15b 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralGetServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralGetServiceImpl.java
@@ -1,52 +1,119 @@
 package com.yeshi.fanli.service.impl.integral;
 
+import java.util.Date;
+
+import javax.annotation.Resource;
+
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
+import com.yeshi.fanli.entity.bus.user.UserInfo;
+import com.yeshi.fanli.entity.integral.IntegralTask;
+import com.yeshi.fanli.entity.integral.IntegralTask.FrequencyEnum;
+import com.yeshi.fanli.entity.integral.IntegralTask.TaskUniqueKeyEnum;
+import com.yeshi.fanli.entity.integral.IntegralTaskRecord;
 import com.yeshi.fanli.exception.integral.IntegralGetException;
+import com.yeshi.fanli.exception.integral.IntegralTaskRecordException;
+import com.yeshi.fanli.log.LogHelper;
+import com.yeshi.fanli.service.inter.hongbao.ThreeSaleSerivce;
 import com.yeshi.fanli.service.inter.integral.IntegralGetService;
+import com.yeshi.fanli.service.inter.integral.IntegralTaskRecordService;
+import com.yeshi.fanli.service.inter.integral.IntegralTaskService;
+import com.yeshi.fanli.util.RedisManager;
 
 import net.sf.json.JSONObject;
 
 @Service
 public class IntegralGetServiceImpl implements IntegralGetService {
 
+	@Resource
+	private IntegralTaskService integralTaskService;
+
+	@Resource
+	private IntegralTaskRecordService integralTaskRecordService;
+	
+	@Resource
+	private ThreeSaleSerivce threeSaleSerivce;
+
+	@Resource
+	private RedisManager redisManager;
+
 	@Override
-	public void addEventStatistic(Long uid, String event, JSONObject params) throws IntegralGetException {
-		switch (event) {
-		case "recommendSearch":
-			break;
-		case "shareInvite":
-			break;
-		case "inShop":
-			break;
-		case "scanPush":
-			break;
-		case "scanGoods":
-			break;
-		case "scanHomeBanner":
-			break;
-		case "scanSpecial":
-			break;
-		case "scanTBCart":
-			break;
+	public IntegralTaskRecord addEventStatistic(Long uid, String event, JSONObject params) throws IntegralGetException {
+		Date nowDate = new Date();
+		IntegralTask task = integralTaskService.getByCidAndUniqueKey(null, event);
+		if (task == null)
+			throw new IntegralGetException(1, "浜嬩欢绫诲瀷涓嶅瓨鍦�");
+		if (task.getFrequency() == FrequencyEnum.everyday) {
+			int count = integralTaskRecordService.countGetCountByTaskIdAndDay(task.getId(), uid, nowDate);
+			if (count >= task.getUpperLimit())
+				throw new IntegralGetException(2, "浜嬩欢瑙﹀彂杈惧埌涓婇檺");
+		} else if (task.getFrequency() == FrequencyEnum.onlyOne) {
+			int count = integralTaskRecordService.countGetCountByTaskIdAndDay(task.getId(), uid, null);
+			if (count > 0)
+				throw new IntegralGetException(2, "浜嬩欢瑙﹀彂杈惧埌涓婇檺");
 		}
+
+		int goldCoin = task.getGoldCoin();
+		if (task.getDoubleNum() != null && task.getDoubleNum() > 0)
+			goldCoin = task.getDoubleNum() * goldCoin;
+
+		IntegralTaskRecord record = new IntegralTaskRecord();
+		record.setCid(task.getTaskClass().getId());
+		record.setGoldCoin(goldCoin);
+		record.setState(IntegralTaskRecord.STATE_WAITING_RECIEVE);
+		record.setTaskId(task.getId());
+		record.setUid(uid);
+
+		try {
+			 IntegralTaskRecord addRecord = integralTaskRecordService.addRecord(record);
+			 if (TaskUniqueKeyEnum.inShop == TaskUniqueKeyEnum.valueOf(event)) {
+				 UserInfo boss = threeSaleSerivce.getBoss(uid);
+				 if (boss != null) 
+					 addInShopLevelOne(boss.getId()); // 涓嬬骇娴忚搴楅摵
+			 }
+			 return addRecord;
+		} catch (IntegralTaskRecordException e) {
+			throw new IntegralGetException(3, "娣诲姞璁板綍澶辫触");
+		}
+		
+		
+		
+
+		// switch (event) {
+		// case "recommendSearch":
+		// break;
+		// case "shareInvite":
+		// break;
+		// case "inShop":
+		// break;
+		// case "scanPush":
+		// break;
+		// case "scanGoods":
+		// break;
+		// case "scanHomeBanner":
+		// break;
+		// case "scanSpecial":
+		// break;
+		// case "scanTBCart":
+		// break;
+		// }
 	}
 
 	@Override
 	public void addRecommendSearch(Long uid) throws IntegralGetException {
-		// TODO Auto-generated method stub
 
 	}
 
+	@Cacheable(value = "integralGetCache", key = "'addSearchResultScan-'+#uid+'-'+#kw")
 	@Override
-	public void addSearchResultScan(Long uid) throws IntegralGetException {
-		// TODO Auto-generated method stub
-
+	public void addSearchResultScan(Long uid, String kw) throws IntegralGetException {
+		System.out.println("鎼滅储");
 	}
 
 	@Override
 	public void addShareInvite(Long uid) throws IntegralGetException {
-		// TODO Auto-generated method stub
 
 	}
 
@@ -55,6 +122,28 @@
 		// TODO Auto-generated method stub
 
 	}
+	
+	@Async()
+	private void addInShopLevelOne(Long uid) {
+		try {
+			addEventStatistic(uid, TaskUniqueKeyEnum.inShopLevelOne.name(), null);
+			UserInfo boss = threeSaleSerivce.getBoss(uid);
+			if (boss != null) 
+				addInShopLevelTwo(boss.getId()); // 浜岀骇闃熷憳
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+		}
+	}
+	
+	@Async()
+	private void addInShopLevelTwo(Long uid) {
+		try {
+			addEventStatistic(uid, TaskUniqueKeyEnum.inShopLevelTwo.name(), null);
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+		}
+	}
+	
 
 	@Override
 	public void addScanPushHistory(Long uid) throws IntegralGetException {
@@ -86,4 +175,310 @@
 
 	}
 
+	@Async()
+	@Override
+	public void addTaoLiJinBuy(Long uid, Long goodsId) {
+		try {
+			addEventStatistic(uid, TaskUniqueKeyEnum.taoLiJinBuy.name(), null);
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+		}
+	}
+
+	@Async()
+	@Override
+	public void addInviteLevelOne(Long uid, Long workerId) {
+		try {
+			addEventStatistic(uid, TaskUniqueKeyEnum.inviteLevelOne.name(), null);
+			UserInfo boss = threeSaleSerivce.getBoss(uid);
+			if (boss != null)
+				addInviteLevelTwo(boss.getId());
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+		}
+	}
+	
+	/**
+	 * 闂存帴閭�璇�
+	 * @param uid
+	 */
+	@Async()
+	private void addInviteLevelTwo(Long uid) {
+		try {
+			addEventStatistic(uid, TaskUniqueKeyEnum.inviteLevelTwo.name(), null);
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+		}
+	}
+	
+	@Async()
+	@Override
+	public void addShareSingleGoods(Long uid) {
+		try {
+			addEventStatistic(uid, TaskUniqueKeyEnum.shareSingleGoods.name(), null);
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+		}
+	}
+	
+	
+	@Async()
+	@Override
+	public void addShareMultipleGoods(Long uid) {
+		try {
+			addEventStatistic(uid, TaskUniqueKeyEnum.shareMultipleGoods.name(), null);
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+		}
+	}
+	
+	
+	@Async()
+	@Override
+	public void addShareTLJGoods(Long uid) {
+		try {
+			addEventStatistic(uid, TaskUniqueKeyEnum.shareTLJGoods.name(), null);
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+		}
+	}
+	
+	@Async()
+	@Override
+	public void addGiveRebateCoupon(Long uid) {
+		try {
+			addEventStatistic(uid, TaskUniqueKeyEnum.giveRebateCoupon.name(), null);
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+		}
+	}
+	
+	
+	@Async()
+	@Override
+	public void addGiveFreeCoupon(Long uid) {
+		try {
+			addEventStatistic(uid, TaskUniqueKeyEnum.giveFreeCoupon.name(), null);
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+		}
+	}
+	
+	
+	@Async()
+	@Override
+	public void addGiveTaoLiJin(Long uid) {
+		try {
+			addEventStatistic(uid, TaskUniqueKeyEnum.giveTaoLiJin.name(), null);
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+		}
+	}
+	
+	
+	@Async()
+	@Override
+	public void addCloseRecommendGoods(Long uid) {
+		try {
+			addEventStatistic(uid, TaskUniqueKeyEnum.closeRecommendGoods.name(), null);
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+		}
+	}
+	
+	
+	@Async()
+	@Override
+	public void addCouponRebate(Long uid) {
+		try {
+			addEventStatistic(uid, TaskUniqueKeyEnum.couponRebate.name(), null);
+			UserInfo boss = threeSaleSerivce.getBoss(uid);
+			if (boss != null)
+				addCouponRebateLevelOne(boss.getId());
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+		}
+	}
+	
+	
+	/**
+	 * 涓�绾ч槦鍛橀鍒歌繑鍒�
+	 * @param uid
+	 */
+	@Async()
+	private void addCouponRebateLevelOne(Long uid) {
+		try {
+			addEventStatistic(uid, TaskUniqueKeyEnum.couponRebateLevelOne.name(), null);
+			UserInfo boss = threeSaleSerivce.getBoss(uid);
+			if (boss != null)
+				addCouponRebateLevelTwo(boss.getId()); // 浜岀骇闃熷憳
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+		}
+	}
+	
+	/**
+	 *  浜岀骇闃熷憳棰嗗埜杩斿埄
+	 * @param uid
+	 */
+	@Async()
+	private void addCouponRebateLevelTwo(Long uid) {
+		try {
+			addEventStatistic(uid, TaskUniqueKeyEnum.couponRebateLevelTwo.name(), null);
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+		}
+	}
+	
+	@Async()
+	@Override
+	public void addRebateOrder(Long uid) {
+		try {
+			addEventStatistic(uid, TaskUniqueKeyEnum.rebateOrder.name(), null);
+			UserInfo boss = threeSaleSerivce.getBoss(uid);
+			if (boss != null)
+				addInviteOrderLevelOne(boss.getId());
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+		}
+	}
+	
+	
+	/**
+	 * 涓�绾ч槦鍛橀個璇疯鍗�
+	 * @param uid
+	 */
+	@Async()
+	private void addInviteOrderLevelOne(Long uid) {
+		try {
+			addEventStatistic(uid, TaskUniqueKeyEnum.inviteOrderLevelOne.name(), null);
+			UserInfo boss = threeSaleSerivce.getBoss(uid);
+			if (boss != null)
+				addInviteOrderLevelTwo(boss.getId());
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+		}
+	}
+	
+	
+	/**
+	 * 浜岀骇闃熷憳閭�璇疯鍗�
+	 * @param uid
+	 */
+	@Async()
+	private void addInviteOrderLevelTwo(Long uid) {
+		try {
+			addEventStatistic(uid, TaskUniqueKeyEnum.inviteOrderLevelTwo.name(), null);
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+		}
+	}
+	
+	@Async()
+	@Override
+	public void addShareOrder(Long uid) {
+		try {
+			addEventStatistic(uid, TaskUniqueKeyEnum.shareOrder.name(), null);
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+		}
+	}
+	
+	
+	@Async()
+	@Override
+	public void addBindWeiXin(Long uid) {
+		try {
+			addEventStatistic(uid, TaskUniqueKeyEnum.bindWeiXin.name(), null);
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+		}
+	}
+	
+	@Async()
+	@Override
+	public void addBindPhone(Long uid) {
+		try {
+			addEventStatistic(uid, TaskUniqueKeyEnum.bindPhone.name(), null);
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+		}
+	}
+	
+	
+	@Async()
+	@Override
+	public void addBindTaoBao(Long uid) {
+		try {
+			addEventStatistic(uid, TaskUniqueKeyEnum.bindTaoBao.name(), null);
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+		}
+	}
+	
+	
+	@Async()
+	@Override
+	public void addSetWeiXinNum(Long uid) {
+		try {
+			addEventStatistic(uid, TaskUniqueKeyEnum.setWeiXinNum.name(), null);
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+		}
+	}
+	
+	@Async()
+	@Override
+	public void addSetGender(Long uid) {
+		try {
+			addEventStatistic(uid, TaskUniqueKeyEnum.setGender.name(), null);
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+		}
+	}
+	
+	
+	@Async()
+	@Override
+	public void addSetPortrait(Long uid) {
+		try {
+			addEventStatistic(uid, TaskUniqueKeyEnum.setPortrait.name(), null);
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+		}
+	}
+	
+	
+	@Async()
+	@Override
+	public void addSetNickname(Long uid) {
+		try {
+			addEventStatistic(uid, TaskUniqueKeyEnum.setNickname.name(), null);
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+		}
+	}
+	
+	
+	@Async()
+	@Override
+	public void addBindAlipay(Long uid) {
+		try {
+			addEventStatistic(uid, TaskUniqueKeyEnum.bindAlipay.name(), null);
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+		}
+	}
+	
+	
+	@Async()
+	@Override
+	public void addInviteActivate(Long uid) {
+		try {
+			addEventStatistic(uid, TaskUniqueKeyEnum.inviteActivate.name(), null);
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+		}
+	}
+	
 }

--
Gitblit v1.8.0