From cdd852f8e8eff7eb2e8f7c3fceaa955b9fc3f9d3 Mon Sep 17 00:00:00 2001 From: yujian <yujian@123.com> Date: 星期一, 29 七月 2019 10:46:32 +0800 Subject: [PATCH] 订单商品类型处理 --- fanli/src/main/java/com/yeshi/fanli/service/impl/goods/ShareGoodsTextTemplateServiceImpl.java | 247 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 246 insertions(+), 1 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 3a76084..d13741f 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 @@ -10,12 +10,19 @@ import org.yeshi.utils.BigDecimalUtil; import com.yeshi.fanli.dao.mybatis.goods.ShareGoodsTextTemplateMapper; +import com.yeshi.fanli.dto.jd.JDPingouInfo; +import com.yeshi.fanli.dto.pdd.PDDGoodsDetail; import com.yeshi.fanli.entity.goods.ShareGoodsTextTemplate; +import com.yeshi.fanli.entity.jd.JDGoods; import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief; 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.service.inter.tlj.ConfigTaoLiJinService; +import com.yeshi.fanli.util.MoneyBigDecimalUtil; +import com.yeshi.fanli.util.StringUtil; +import com.yeshi.fanli.util.jd.JDUtil; +import com.yeshi.fanli.util.pinduoduo.PinDuoDuoUtil; import com.yeshi.fanli.util.taobao.TaoBaoUtil; import com.yeshi.fanli.util.taobao.TaoLiJinUtil; @@ -56,7 +63,44 @@ textTemplate.setUid(uid); shareGoodsTextTemplateMapper.insertSelective(textTemplate); } - + } + + @Override + public void saveCommonTemplateJD(Long uid, String template) throws ShareGoodsTextTemplateException { + isCommonTemplateRight(template); + ShareGoodsTextTemplate old = shareGoodsTextTemplateMapper.selectByUid(uid); + if (old != null) { + ShareGoodsTextTemplate update = new ShareGoodsTextTemplate(); + update.setId(old.getId()); + update.setShareJDTextTemplate(template); + update.setUpdateTime(new Date()); + shareGoodsTextTemplateMapper.updateByPrimaryKeySelective(update); + } else { + ShareGoodsTextTemplate textTemplate = new ShareGoodsTextTemplate(); + textTemplate.setCreateTime(new Date()); + textTemplate.setShareJDTextTemplate(template); + textTemplate.setUid(uid); + shareGoodsTextTemplateMapper.insertSelective(textTemplate); + } + } + + @Override + public void saveCommonTemplatePDD(Long uid, String template) throws ShareGoodsTextTemplateException { + isCommonTemplateRight(template); + ShareGoodsTextTemplate old = shareGoodsTextTemplateMapper.selectByUid(uid); + if (old != null) { + ShareGoodsTextTemplate update = new ShareGoodsTextTemplate(); + update.setId(old.getId()); + update.setSharePDDTextTemplate(template); + update.setUpdateTime(new Date()); + shareGoodsTextTemplateMapper.updateByPrimaryKeySelective(update); + } else { + ShareGoodsTextTemplate textTemplate = new ShareGoodsTextTemplate(); + textTemplate.setCreateTime(new Date()); + textTemplate.setSharePDDTextTemplate(template); + textTemplate.setUid(uid); + shareGoodsTextTemplateMapper.insertSelective(textTemplate); + } } @Override @@ -84,6 +128,51 @@ ShareGoodsTextTemplate textTemplate = new ShareGoodsTextTemplate(); textTemplate.setCreateTime(new Date()); textTemplate.setShareCouponTextTemplate(template); + textTemplate.setUid(uid); + shareGoodsTextTemplateMapper.insertSelective(textTemplate); + } + } + + @Transactional + @Override + public void saveCouponTemplateJD(Long uid, String template) throws ShareGoodsTextTemplateException { + // 鏍煎紡楠岃瘉 + isTaoLiJinTemplateRight(template); + + ShareGoodsTextTemplate old = shareGoodsTextTemplateMapper.selectByUid(uid); + if (old != null) { + ShareGoodsTextTemplate update = new ShareGoodsTextTemplate(); + update.setId(old.getId()); + update.setShareJDTextTemplateCoupon(template); + update.setUpdateTime(new Date()); + shareGoodsTextTemplateMapper.updateByPrimaryKeySelective(update); + } else { + ShareGoodsTextTemplate textTemplate = new ShareGoodsTextTemplate(); + textTemplate.setCreateTime(new Date()); + textTemplate.setShareJDTextTemplateCoupon(template); + textTemplate.setUid(uid); + shareGoodsTextTemplateMapper.insertSelective(textTemplate); + } + } + + + @Transactional + @Override + public void saveCouponTemplatePDD(Long uid, String template) throws ShareGoodsTextTemplateException { + // 鏍煎紡楠岃瘉 + isTaoLiJinTemplateRight(template); + + ShareGoodsTextTemplate old = shareGoodsTextTemplateMapper.selectByUid(uid); + if (old != null) { + ShareGoodsTextTemplate update = new ShareGoodsTextTemplate(); + update.setId(old.getId()); + update.setSharePDDTextTemplateCoupon(template); + update.setUpdateTime(new Date()); + shareGoodsTextTemplateMapper.updateByPrimaryKeySelective(update); + } else { + ShareGoodsTextTemplate textTemplate = new ShareGoodsTextTemplate(); + textTemplate.setCreateTime(new Date()); + textTemplate.setSharePDDTextTemplateCoupon(template); textTemplate.setUid(uid); shareGoodsTextTemplateMapper.insertSelective(textTemplate); } @@ -131,6 +220,11 @@ } @Override + public ShareGoodsTextTemplate getShareGoodsTextTemplate(Long uid) { + return shareGoodsTextTemplateMapper.selectByUid(uid); + } + + @Override public void isCommonTemplateRight(String template) throws ShareGoodsTextTemplateException { String[] keys = new String[] { "{鏍囬}", "{搴楅摵绫诲瀷}", "{鍟嗗搧鍘熶环}", "{鏈堥攢閲弣", "{鐭摼}", "{娣樺彛浠" }; int keysCount = 0; @@ -142,8 +236,54 @@ } @Override + public void isCommonTemplateRightJD(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 void isCommonTemplateRightPDD(String template) throws ShareGoodsTextTemplateException { + String[] keys = new String[] { "{鏍囬}", "{鍟嗗搧鍘熶环}", "{鏈堥攢閲弣", "{鐭摼鎺", "{澶氬鍙d护}" }; + int keysCount = 0; + for (String key : keys) + if (template != null && template.contains(key)) + keysCount++; + if (keysCount == 0) + throw new ShareGoodsTextTemplateException(1, "妯℃澘鏍煎紡鏈夎"); + } + + @Override public void isCouponTemplateRight(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 void isCouponTemplateRightJD(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 void isCouponTemplateRightPDD(String template) throws ShareGoodsTextTemplateException { + String[] keys = new String[] { "{鏍囬}", "{鍟嗗搧鍘熶环}", "{浼樻儬鍒搁潰棰潁", "{浼樻儬鍒镐环}", "{鎬婚攢閲弣", "{鐭摼鎺"}; int keysCount = 0; for (String key : keys) if (template != null && template.contains(key)) @@ -194,6 +334,59 @@ .replace("{搴楅摵绫诲瀷}", goods.getUserType() == 1 ? "澶╃尗浠�" : "娣樺疂浠�"); } } + + + @Override + public String createContentByTemplateJD(String template, Long uid, JDGoods goods, String shortLink, boolean hasCoupon) { + BigDecimal price = goods.getPrice(); + JDPingouInfo pinGouInfo = goods.getPinGouInfo(); + if (pinGouInfo != null) { + price = pinGouInfo.getPingouPrice(); + } + + if (!hasCoupon) { + template = template.replace("{鏍囬}", goods.getSkuName()).replace("{鍟嗗搧鍘熶环}", BigDecimalUtil.getWithNoZera(price).toString()) + .replace("{鏈堥攢閲弣", JDUtil.getSaleCount(goods.getInOrderCount30Days())).replace("{鐭摼鎺", shortLink); + } else { + template = template.replace("{鏍囬}", goods.getSkuName()).replace("{鍟嗗搧鍘熶环}", BigDecimalUtil.getWithNoZera(price).toString()) + .replace("{鏈堥攢閲弣", JDUtil.getSaleCount(goods.getInOrderCount30Days())).replace("{鐭摼鎺", shortLink) + .replace("{浼樻儬鍒搁潰棰潁", BigDecimalUtil.getWithNoZera(goods.getCouponInfo().getDiscount()).toString()) + .replace("{浼樻儬鍒镐环}", BigDecimalUtil.getWithNoZera(JDUtil.getQuanPrice(goods)).toString()); + } + + if (pinGouInfo != null) { + template = template.replace("{浜笢浠穧", "鎷艰喘浠�"); + } else { + template = template.replace("{浜笢浠穧", "浜笢浠�"); + } + return template; + } + + + @Override + public String createContentByTemplatePDD(String template, Long uid, PDDGoodsDetail goods, + String shortLink, boolean hasCoupon, String token) { + BigDecimal hundred = new BigDecimal(100); + BigDecimal price = MoneyBigDecimalUtil.div(new BigDecimal(goods.getMinGroupPrice()), hundred); + if (!hasCoupon) { + template = template.replace("{鏍囬}", goods.getGoodsName()).replace("{鍟嗗搧鍘熶环}", BigDecimalUtil.getWithNoZera(price).toString()) + .replace("{鎬婚攢閲弣", goods.getSalesTip()).replace("{鐭摼鎺", shortLink); + } else { + BigDecimal amount = MoneyBigDecimalUtil.div(new BigDecimal(goods.getCouponDiscount()), hundred); + template = template.replace("{鏍囬}", goods.getGoodsName()).replace("{鍟嗗搧鍘熶环}", BigDecimalUtil.getWithNoZera(price).toString()) + .replace("{鎬婚攢閲弣", goods.getSalesTip()).replace("{鐭摼鎺", shortLink) + .replace("{浼樻儬鍒搁潰棰潁", BigDecimalUtil.getWithNoZera(amount).toString()) + .replace("{浼樻儬鍒镐环}", BigDecimalUtil.getWithNoZera(PinDuoDuoUtil.getQuanPrice(goods)).toString()); + } + + if (StringUtil.isNullOrEmpty(token)) { + template = template.replace("{澶氬鍙d护}鎵撳紑鎷煎澶氾紝", ""); + } else { + template = template.replace("{澶氬鍙d护}", token); + } + + return template; + } @Override public void resetCommonTemplate(Long uid) { @@ -219,6 +412,58 @@ shareGoodsTextTemplateMapper.updateByPrimaryKeySelective(update); } } + + + @Override + public void resetCommonTemplateJD(Long uid) { + ShareGoodsTextTemplate template = shareGoodsTextTemplateMapper.selectByUid(uid); + if (template != null) { + ShareGoodsTextTemplate update = new ShareGoodsTextTemplate(); + update.setId(template.getId()); + update.setShareJDTextTemplate(""); + update.setUpdateTime(new Date()); + shareGoodsTextTemplateMapper.updateByPrimaryKeySelective(update); + } + + } + + @Override + public void resetCouponTemplateJD(Long uid) { + ShareGoodsTextTemplate template = shareGoodsTextTemplateMapper.selectByUid(uid); + if (template != null) { + ShareGoodsTextTemplate update = new ShareGoodsTextTemplate(); + update.setId(template.getId()); + update.setShareJDTextTemplateCoupon(""); + update.setUpdateTime(new Date()); + shareGoodsTextTemplateMapper.updateByPrimaryKeySelective(update); + } + } + + + @Override + public void resetCommonTemplatePDD(Long uid) { + ShareGoodsTextTemplate template = shareGoodsTextTemplateMapper.selectByUid(uid); + if (template != null) { + ShareGoodsTextTemplate update = new ShareGoodsTextTemplate(); + update.setId(template.getId()); + update.setSharePDDTextTemplate(""); + update.setUpdateTime(new Date()); + shareGoodsTextTemplateMapper.updateByPrimaryKeySelective(update); + } + + } + + @Override + public void resetCouponTemplatePDD(Long uid) { + ShareGoodsTextTemplate template = shareGoodsTextTemplateMapper.selectByUid(uid); + if (template != null) { + ShareGoodsTextTemplate update = new ShareGoodsTextTemplate(); + update.setId(template.getId()); + update.setSharePDDTextTemplateCoupon(""); + update.setUpdateTime(new Date()); + shareGoodsTextTemplateMapper.updateByPrimaryKeySelective(update); + } + } @Override public void resetTaoLijinTemplate(Long uid) { -- Gitblit v1.8.0