From 531d93708df8017e59830f15b41f3cc42d6126e6 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 09 七月 2019 17:53:01 +0800
Subject: [PATCH] 1.5.7版本需求

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/goods/ShareGoodsServiceImpl.java |  100 ++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 81 insertions(+), 19 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/ShareGoodsServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/ShareGoodsServiceImpl.java
index 6ec1b1a..a2bd599 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/ShareGoodsServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/ShareGoodsServiceImpl.java
@@ -23,6 +23,7 @@
 import com.yeshi.fanli.dao.mybatis.UserInfoMapper;
 import com.yeshi.fanli.dao.mybatis.UserShareGoodsHistoryMapper;
 import com.yeshi.fanli.dao.mybatis.share.PidUserMapper;
+import com.yeshi.fanli.dto.taobao.TaoLiJinDTO;
 import com.yeshi.fanli.entity.bus.share.UserShareGoodsHistory;
 import com.yeshi.fanli.entity.bus.tlj.UserTaoLiJinRecord;
 import com.yeshi.fanli.entity.bus.user.UserInfo;
@@ -33,7 +34,9 @@
 import com.yeshi.fanli.entity.taobao.TaoBaoLink;
 import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig;
 import com.yeshi.fanli.entity.taobao.TaoKeAppInfo;
+import com.yeshi.fanli.entity.taobao.UserTLJBuyHistory;
 import com.yeshi.fanli.exception.ShareGoodsException;
+import com.yeshi.fanli.exception.taobao.TaoKeApiException;
 import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
 import com.yeshi.fanli.exception.tlj.UserTaoLiJinRecordException;
 import com.yeshi.fanli.log.LogHelper;
@@ -41,7 +44,9 @@
 import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
 import com.yeshi.fanli.service.inter.goods.ShareGoodsService;
 import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
+import com.yeshi.fanli.service.inter.taobao.TLJBuyGoodsService;
 import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
+import com.yeshi.fanli.service.inter.taobao.UserTLJBuyHistoryService;
 import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinRecordService;
 import com.yeshi.fanli.service.inter.user.TBPidService;
 import com.yeshi.fanli.service.inter.user.UserAccountService;
@@ -54,6 +59,7 @@
 import com.yeshi.fanli.util.RedisManager;
 import com.yeshi.fanli.util.StringUtil;
 import com.yeshi.fanli.util.TaoBaoConstant;
+import com.yeshi.fanli.util.TimeUtil;
 import com.yeshi.fanli.util.taobao.TaoBaoUtil;
 import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
 
@@ -98,11 +104,16 @@
 
 	@Resource
 	private UserMoneyExtraService userMoneyExtraService;
-	
+
 	@Resource
 	private UserTaoLiJinRecordService userTaoLiJinRecordService;
-	
-	
+
+	@Resource
+	private UserTLJBuyHistoryService userTLJBuyHistoryService;
+
+	@Resource
+	private TLJBuyGoodsService tljBuyGoodsService;
+
 	@Override
 	public void addShareGoodsHistory(UserShareGoodsHistory history) {
 		UserShareGoodsHistory userShareGoodsHistory = userShareGoodsHistoryMapper
@@ -402,8 +413,8 @@
 		}
 		TaoBaoGoodsBrief goods = null;
 		try {
-			//娴嬭瘯
-//			info.setAdzoneId("123");
+			// 娴嬭瘯
+			// info.setAdzoneId("123");
 			goods = TaoKeApiUtil.searchGoodsDetail(auctionId, info);
 		} catch (TaobaoGoodsDownException e) {
 			throw new ShareGoodsException(4, "鍟嗗搧宸蹭笅鏋�");
@@ -560,7 +571,6 @@
 		return taoBaoLink;
 	}
 
-	
 	@Override
 	public UserShareGoodsHistory getShareGoodsHistory(Long uid, Long auctionId) {
 		return userShareGoodsHistoryMapper.selectByUidAndAuctionId(uid, auctionId);
@@ -656,7 +666,6 @@
 		return tbLink;
 	}
 
-	
 	@Override
 	public TaoBaoLink getTaoLiJinLinkForBuy(Long uid, String specialId, Long auctionId) throws ShareGoodsException {
 		if (uid == null || uid <= 0) {
@@ -669,11 +678,10 @@
 
 		// 鐢ㄦ埛鍓╀綑鍙互娣樼ぜ閲戦獙璇�
 		UserMoneyExtra userMoneyExtra = userMoneyExtraService.selectByPrimaryKey(uid);
-		if (userMoneyExtra == null ||  userMoneyExtra.getTlj() == null) {
+		if (userMoneyExtra == null || userMoneyExtra.getTlj() == null) {
 			throw new ShareGoodsException(101, "绾㈠寘浣欓涓嶈冻");
 		}
-		
-		
+
 		TaoKeAppInfo app = new TaoKeAppInfo();
 		app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY);
 		app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
@@ -682,17 +690,16 @@
 		if (goods == null) {
 			throw new ShareGoodsException(1, "");
 		}
-		
+
 		String taoLiJinLink = null;
 		try {
-			 goods.setAuctionId(auctionId);
-			 UserTaoLiJinRecord createUserTaoLiJin = userTaoLiJinRecordService.createSelfBuyTaoLiJin(uid, 1, goods);
-			 taoLiJinLink = createUserTaoLiJin.getSendUrl();
+			goods.setAuctionId(auctionId);
+			UserTaoLiJinRecord createUserTaoLiJin = userTaoLiJinRecordService.createSelfBuyTaoLiJin(uid, 1, goods);
+			taoLiJinLink = createUserTaoLiJin.getSendUrl();
 		} catch (UserTaoLiJinRecordException e) {
 			throw new ShareGoodsException(e.getCode(), e.getMsg());
 		}
-		
-		
+
 		TaoBaoLink taoBaoLink = new TaoBaoLink();
 		taoBaoLink.setAuctionId(auctionId);
 		taoBaoLink.setClickUrl(goods.getAuctionUrl());
@@ -701,8 +708,7 @@
 
 		return taoBaoLink;
 	}
-	
-	
+
 	@Override
 	public TaoBaoLink getTaoLiJinLinkForShare(Long uid, Long auctionId, String relationId) throws ShareGoodsException {
 
@@ -767,7 +773,6 @@
 				goods.setCouponLink(goods.getCouponLink() + "&relationId=" + relationId);
 		}
 
-
 		// 鍒涘缓娣樺彛浠�
 		TaoBaoLink tbLink = new TaoBaoLink();
 		tbLink.setAuctionId(goods.getAuctionId());
@@ -781,4 +786,61 @@
 
 		return tbLink;
 	}
+
+	@Override
+	public TaoBaoLink getTaoLiJinLinkForBuyWithOutFanLi(Long uid, Long auctionId) throws ShareGoodsException {
+		if (uid == null || uid <= 0) {
+			throw new ShareGoodsException(1, "鐢ㄦ埛ID涓嶈兘涓虹┖");
+		}
+
+		if (auctionId == null || auctionId <= 0) {
+			throw new ShareGoodsException(2, "鍟嗗搧ID涓嶈兘涓虹┖");
+		}
+
+		boolean canBuy = userTLJBuyHistoryService.canBuy(uid, auctionId);
+		if (!canBuy) {
+			throw new ShareGoodsException(3, "鍚屼竴鍟嗗搧姣忔棩鍙兘棰嗗彇涓夋");
+		}
+
+		long currentTime = System.currentTimeMillis();
+		Date sendEndTime = new Date(TimeUtil.convertToTimeTemp(
+				TimeUtil.getGernalTime(currentTime + 1000 * 60 * 60 * 24L, "yyyy-MM-dd"), "yyyy-MM-dd"));
+		TaoBaoGoodsBrief goods = null;
+		try {
+			goods = TaoKeApiUtil.searchGoodsDetail(auctionId);
+		} catch (TaobaoGoodsDownException e) {
+			throw new ShareGoodsException(4, "鍟嗗搧宸蹭笅鏋�");
+		}
+
+		BigDecimal perface = TaoBaoUtil.getGoodsHongBaoMoney(goods, new BigDecimal(70));
+		TaoKeAppInfo app = TaoBaoConstant.ownBuyApp;
+		TaoLiJinDTO taoLiJinDTO = null;
+		try {
+			taoLiJinDTO = TaoKeApiUtil.createTaoLiJin(auctionId, "鑷喘绔嬪噺", perface, 1, new Date(currentTime), sendEndTime,
+					new Date(currentTime), sendEndTime, app);
+		} catch (TaoKeApiException e) {
+			throw new ShareGoodsException(5, "鐢熸垚鎺ㄥ箍閾炬帴澶辫触");
+		}
+		if (taoLiJinDTO == null)
+			throw new ShareGoodsException(5, "鐢熸垚鎺ㄥ箍閾炬帴澶辫触");
+
+		// 鍑忓幓鍓╀綑涓暟(闅忔満鍑忓幓8鍒�10涓�)
+		tljBuyGoodsService.subHongBaoLeftCount(auctionId, TimeUtil.getGernalTime(currentTime, "yyyy-MM-dd"),
+				8 + (int) (3 * Math.random()));
+
+		// 鎻掑叆璁板綍
+		try {
+			userTLJBuyHistoryService.addHistory(new UserTLJBuyHistory(null, uid, auctionId,
+					TimeUtil.getGernalTime(currentTime, "yyyy-MM-dd"), taoLiJinDTO.getRightsId(), new Date()));
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+		}
+
+		TaoBaoLink taoBaoLink = new TaoBaoLink();
+		taoBaoLink.setAuctionId(auctionId);
+		taoBaoLink.setClickUrl(goods.getAuctionUrl());
+		taoBaoLink.setCouponLink(taoLiJinDTO.getSendUrl());
+		taoBaoLink.setGoods(goods);
+		return taoBaoLink;
+	}
 }

--
Gitblit v1.8.0