From a0a5b70e0d0df9357d09542f20dc6633a986f328 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 25 六月 2019 11:06:36 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/goods/ShareGoodsTextTemplateServiceImpl.java |   86 ++++++++++++++++++++++++++++++++++++++----
 1 files changed, 77 insertions(+), 9 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/ShareGoodsTextTemplateServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/ShareGoodsTextTemplateServiceImpl.java
index 3a62957..96f6077 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/ShareGoodsTextTemplateServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/ShareGoodsTextTemplateServiceImpl.java
@@ -1,5 +1,6 @@
 package com.yeshi.fanli.service.impl.goods;
 
+import java.math.BigDecimal;
 import java.util.Date;
 
 import javax.annotation.Resource;
@@ -7,7 +8,6 @@
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.yeshi.utils.BigDecimalUtil;
-import org.yeshi.utils.HttpUtil;
 
 import com.yeshi.fanli.dao.mybatis.goods.ShareGoodsTextTemplateMapper;
 import com.yeshi.fanli.entity.goods.ShareGoodsTextTemplate;
@@ -15,11 +15,8 @@
 import com.yeshi.fanli.exception.goods.ShareGoodsTextTemplateException;
 import com.yeshi.fanli.service.inter.config.ConfigService;
 import com.yeshi.fanli.service.inter.goods.ShareGoodsTextTemplateService;
-import com.yeshi.fanli.util.AESUtil;
-import com.yeshi.fanli.util.Constant;
-import com.yeshi.fanli.util.StringUtil;
+import com.yeshi.fanli.service.inter.tlj.GoodsTaoLiJinRateService;
 import com.yeshi.fanli.util.taobao.TaoBaoUtil;
-import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
 
 /**
  * 鍒嗕韩鍟嗗搧妯℃澘
@@ -35,6 +32,9 @@
 
 	@Resource
 	private ConfigService configService;
+	
+	@Resource
+	private GoodsTaoLiJinRateService goodsTaoLiJinRateService;
 
 	@Override
 	public void saveCommonTemplate(Long uid, String template) throws ShareGoodsTextTemplateException {
@@ -67,7 +67,9 @@
 	@Transactional
 	@Override
 	public void saveCouponTemplate(Long uid, String template) throws ShareGoodsTextTemplateException {
-		isCouponTemplateRight(template);
+		// 鏍煎紡楠岃瘉
+		isTaoLiJinTemplateRight(template);
+		
 		ShareGoodsTextTemplate old = shareGoodsTextTemplateMapper.selectByUid(uid);
 		if (old != null) {
 			ShareGoodsTextTemplate update = new ShareGoodsTextTemplate();
@@ -82,9 +84,32 @@
 			textTemplate.setUid(uid);
 			shareGoodsTextTemplateMapper.insertSelective(textTemplate);
 		}
-
 	}
 
+	
+	@Transactional
+	@Override
+	public void saveTaoLiJinTemplate(Long uid, String template) throws ShareGoodsTextTemplateException {
+		
+		isCouponTemplateRight(template);
+		
+		ShareGoodsTextTemplate old = shareGoodsTextTemplateMapper.selectByUid(uid);
+		if (old != null) {
+			ShareGoodsTextTemplate update = new ShareGoodsTextTemplate();
+			update.setId(old.getId());
+			update.setShareTaoLiJinTextTemplate(template);
+			update.setUpdateTime(new Date());
+			shareGoodsTextTemplateMapper.updateByPrimaryKeySelective(update);
+		} else {
+			ShareGoodsTextTemplate textTemplate = new ShareGoodsTextTemplate();
+			textTemplate.setCreateTime(new Date());
+			textTemplate.setShareTaoLiJinTextTemplate(template);
+			textTemplate.setUid(uid);
+			shareGoodsTextTemplateMapper.insertSelective(textTemplate);
+		}
+
+	}
+	
 	@Override
 	public String geteCouponTemplate(Long uid) {
 		ShareGoodsTextTemplate template = shareGoodsTextTemplateMapper.selectByUid(uid);
@@ -93,6 +118,15 @@
 		return null;
 	}
 
+	
+	@Override
+	public String getTaoLiJinTemplate(Long uid) {
+		ShareGoodsTextTemplate template = shareGoodsTextTemplateMapper.selectByUid(uid);
+		if (template != null)
+			return template.getShareTaoLiJinTextTemplate();
+		return null;
+	}
+	
 	@Override
 	public void isCommonTemplateRight(String template) throws ShareGoodsTextTemplateException {
 		String[] keys = new String[] { "{鏍囬}", "{搴楅摵绫诲瀷}", "{鍟嗗搧鍘熶环}", "{鏈堥攢閲弣", "{鐭摼}", "{娣樺彛浠" };
@@ -115,10 +149,32 @@
 			throw new ShareGoodsTextTemplateException(1, "妯℃澘鏍煎紡鏈夎");
 	}
 
+	
+	@Override
+	public void isTaoLiJinTemplateRight(String template) throws ShareGoodsTextTemplateException {
+		String[] keys = new String[] { "{鏍囬}", "{搴楅摵绫诲瀷}", "{鍟嗗搧鍘熶环}", "{浼樻儬鍒搁潰棰潁", "{娣樼ぜ閲戦潰棰潁", "{浼樻儬鍒镐环}", "{鏈堥攢閲弣", "{棰嗗埜鐭摼}", "{娣樺彛浠" };
+		int keysCount = 0;
+		for (String key : keys)
+			if (template != null && template.contains(key))
+				keysCount++;
+		if (keysCount == 0)
+			throw new ShareGoodsTextTemplateException(1, "妯℃澘鏍煎紡鏈夎");
+	}
+	
+	
 	@Override
 	public String createContentByTemplate(String template, Long uid, TaoBaoGoodsBrief goods, String token,
-			String shortLink, boolean hasCoupon) {
-
+			String shortLink, boolean hasCoupon, Long tljId) {
+		
+		if (tljId != null) {
+			BigDecimal spreadMoney = goodsTaoLiJinRateService.getGoodsSpreadMoney(goods);
+			return template.replace("{鏍囬}", goods.getTitle()).replace("{鍟嗗搧鍘熶环}", BigDecimalUtil.getWithNoZera( goods.getZkPrice()).toString())
+					.replace("{鏈堥攢閲弣", TaoBaoUtil.getSaleCount(goods.getBiz30day())).replace("{棰嗗埜鐭摼}", shortLink)
+					.replace("{娣樺彛浠", token).replace("{浼樻儬鍒搁潰棰潁", BigDecimalUtil.getWithNoZera(goods.getCouponAmount()).toString())
+					.replace("{娣樼ぜ閲戦潰棰潁", BigDecimalUtil.getWithNoZera(spreadMoney).toString()).replace("{浼樻儬鍒镐环}", BigDecimalUtil.getWithNoZera( TaoBaoUtil.getAfterUseCouplePrice(goods)).toString())
+					.replace("{搴楅摵绫诲瀷}", goods.getUserType() == 1 ? "澶╃尗浠�" : "娣樺疂浠�");
+		} 
+		
 		if (!hasCoupon) {
 			return template.replace("{鏍囬}", goods.getTitle()).replace("{鍟嗗搧鍘熶环}",  BigDecimalUtil.getWithNoZera(goods.getZkPrice()).toString())
 					.replace("{鏈堥攢閲弣", TaoBaoUtil.getSaleCount(goods.getBiz30day())).replace("{鐭摼}", shortLink)
@@ -158,4 +214,16 @@
 		}
 	}
 
+	@Override
+	public void resetTaoLijinTemplate(Long uid) {
+		ShareGoodsTextTemplate template = shareGoodsTextTemplateMapper.selectByUid(uid);
+		if (template != null) {
+			ShareGoodsTextTemplate update = new ShareGoodsTextTemplate();
+			update.setId(template.getId());
+			update.setShareTaoLiJinTextTemplate("");
+			update.setUpdateTime(new Date());
+			shareGoodsTextTemplateMapper.updateByPrimaryKeySelective(update);
+		}
+	}
+	
 }

--
Gitblit v1.8.0