admin
2021-05-21 aeae4b32ba980c7701b6870611462a4095453e72
PID管理
3个文件已添加
43个文件已修改
10430 ■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/controller/admin/GoodsEvaluateAdminController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/admin/config/PDDAuthAdminController.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/admin/goods/ConvertLinkController.java 54 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/lijin/GoodsControllerLijin.java 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/GoodsController.java 29 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/RecommendController.java 3990 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/ShareController.java 1993 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/UserInfoController.java 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/ConfigControllerV2.java 34 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/ConvertLinkController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/DynamicControllerV2.java 26 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/GoodsControllerV2.java 58 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/PinDuoDuoControllerV2.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/SearchControllerV2.java 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/ShareControllerV2.java 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/h5/H5PDDGoodsController.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/h5/H5RecommendController.java 917 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/wxmp/v1/DynamicController.java 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/wxmp/v1/GoodsController.java 1546 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/mongo/system/SystemPIDInfoDao.java 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/user/UserExtraTaoBaoInfoMapper.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/entity/SystemPIDInfo.java 105 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/job/DynamicInfoJob.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/dynamic/GoodsEvaluateServiceImpl.java 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/dynamic/WXMPDynamicInfoServiceImpl.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/CommonShareInfoServiceImpl.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderProcessServiceImpl.java 216 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/taobao/TaoBaoBuyRelationMapServiceImpl.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/tlj/UserTaoLiJinNewbiesServiceImpl.java 728 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/tlj/UserTaoLiJinRecordServiceImpl.java 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/user/TBPidServiceImpl.java 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/user/cloud/UserCloudServiceImpl.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/user/tb/UserExtraTaoBaoInfoServiceImpl.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/dynamic/GoodsEvaluateService.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/user/TBPidService.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/user/tb/UserExtraTaoBaoInfoService.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/manger/PIDManager.java 95 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/manger/goods/ConvertLinkManager.java 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/manger/goods/TaoBaoLinkManager.java 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/TaoBaoConstant.java 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/jd/JDApiUtil.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/pinduoduo/PinDuoDuoApiUtil.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/suning/SuningApiUtil.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoKeApiUtil.java 134 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoKeScApiUtil.java 116 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/resource/mapping/user/UserExtraTaoBaoInfoMapper.xml 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/admin/GoodsEvaluateAdminController.java
@@ -286,7 +286,7 @@
    @RequestMapping(value = "saveCurrencyCoupon")
    public void saveCurrencyCoupon(AdminAcceptData acceptData,String callback, String pid, int kind, CommentInfo commentInfo, PrintWriter out) {
        try {
            goodsEvaluateService.saveCurrencyCoupon(pid, kind, commentInfo);
            goodsEvaluateService.saveCurrencyCoupon(acceptData.getSystem(),pid, kind, commentInfo);
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("保存成功"));
        } catch (GoodsEvaluateException e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
fanli/src/main/java/com/yeshi/fanli/controller/admin/config/PDDAuthAdminController.java
@@ -1,7 +1,10 @@
package com.yeshi.fanli.controller.admin.config;
import com.yeshi.fanli.entity.SystemPIDInfo;
import com.yeshi.fanli.entity.accept.AdminAcceptData;
import com.yeshi.fanli.service.inter.pdd.PDDAuthService;
import com.yeshi.fanli.service.manger.PIDManager;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -16,6 +19,9 @@
    @Resource
    private PDDAuthService pddAuthService;
    @Resource
    private PIDManager pidManager;
    @RequestMapping("getAuthLink")
@@ -25,7 +31,7 @@
        }
        try {
            String link = pddAuthService.createPDDAuthLink(uid, PinDuoDuoApiUtil.PID_FANLI);
            String link = pddAuthService.createPDDAuthLink(uid, pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_PDD, SystemPIDInfo.PidType.fanli));
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(link));
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMessage()));
fanli/src/main/java/com/yeshi/fanli/controller/admin/goods/ConvertLinkController.java
@@ -16,37 +16,37 @@
@RequestMapping("admin/new/api/v1/convertLink")
public class ConvertLinkController {
    @Resource
    private ConvertLinkManager convertLinkManager;
    @Resource
    private ConvertLinkManager convertLinkManager;
    @RequestMapping(value = "convertLink")
    public void convertLink(AdminAcceptData acceptData, String callback, String uid, String content, Boolean share, PrintWriter out) {
        if (StringUtil.isNullOrEmpty(uid)) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请上传用户ID"));
            return;
        }
    @RequestMapping(value = "convertLink")
    public void convertLink(AdminAcceptData acceptData, String callback, String uid, String content, Boolean share, PrintWriter out) {
        if (StringUtil.isNullOrEmpty(uid)) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请上传用户ID"));
            return;
        }
        if (StringUtil.isNullOrEmpty(content)) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请上传文本内容"));
            return;
        }
        if (StringUtil.isNullOrEmpty(content)) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请上传文本内容"));
            return;
        }
        if (share == null) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选择是分享还是自购"));
            return;
        }
        if (share == null) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选择是分享还是自购"));
            return;
        }
        String result = null;
        try {
            result = convertLinkManager.convertLinkFromText(content, Long.parseLong(uid), share,true);
        } catch (NumberFormatException e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("用户ID转换出错"));
        }catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMessage()));
            return;
        }
        String result = null;
        try {
            result = convertLinkManager.convertLinkFromText(acceptData.getSystem(), content, Long.parseLong(uid), share, true);
        } catch (NumberFormatException e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("用户ID转换出错"));
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMessage()));
            return;
        }
        JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(result));
    }
        JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(result));
    }
}
fanli/src/main/java/com/yeshi/fanli/controller/client/lijin/GoodsControllerLijin.java
@@ -14,6 +14,8 @@
import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
import com.yeshi.fanli.dto.suning.SuningGoodsInfo;
import com.yeshi.fanli.dto.vip.goods.VIPGoodsInfo;
import com.yeshi.fanli.entity.SystemEnum;
import com.yeshi.fanli.entity.SystemPIDInfo;
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.user.ShamUser;
import com.yeshi.fanli.entity.goods.CollectionGoodsV2;
@@ -26,6 +28,7 @@
import com.yeshi.fanli.service.inter.taobao.TaoBaoGoodsUpdateService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoShopService;
import com.yeshi.fanli.service.inter.user.ShamUserService;
import com.yeshi.fanli.service.manger.PIDManager;
import com.yeshi.fanli.util.*;
import com.yeshi.fanli.util.cache.TaoBaoGoodsCacheUtil;
import com.yeshi.fanli.util.factory.goods.GoodsDetailVOLijinFactory;
@@ -77,6 +80,9 @@
    @Resource
    private GoodsLijinMnager goodsLijinMnager;
    @Resource
    private PIDManager pidManager;
    /**
     * 获取商品详情
     *
@@ -125,7 +131,7 @@
            case Constant
                    .SOURCE_TYPE_PDD:
                PDDGoodsDetail pddGoodsDetail = getPDDGoods(Long.parseLong(goodsId), uid);
                PDDGoodsDetail pddGoodsDetail = getPDDGoods(acceptData.getSystem(), Long.parseLong(goodsId), uid);
                goodsDetailVO.setGoods(GoodsDetailVOLijinFactory.convertPDDGoods(pddGoodsDetail, paramsDTO));
                extraVO.setDetailUrl("http://apph5.banliapp.com/apppage/goods_img_pdd.html?id=" + goodsId);
                break;
@@ -208,7 +214,7 @@
                out.print(JsonUtil.loadFalseResult(e.getMsg()));
                return;
            } catch (LiJinUserException e) {
                out.print(JsonUtil.loadFalseResult(2001,"今日领取红包次数超限"));
                out.print(JsonUtil.loadFalseResult(2001, "今日领取红包次数超限"));
                return;
            }
        }
@@ -272,15 +278,16 @@
        return jdGoods;
    }
    private PDDGoodsDetail getPDDGoods(Long id, Long uid) {
    private PDDGoodsDetail getPDDGoods(SystemEnum system, Long id, Long uid) {
        String pid = pidManager.getPidCache(system, Constant.SOURCE_TYPE_PDD, SystemPIDInfo.PidType.fanli);
        PDDGoodsDetail pddGoods = null;
        try {
            pddGoods = PinDuoDuoApiUtil.getGoodsDetail(id, PinDuoDuoApiUtil.PID_FANLI, pddAuthService.getFanliCustomParams(uid));
            pddGoods = PinDuoDuoApiUtil.getGoodsDetail(id, pid, pddAuthService.getFanliCustomParams(uid));
        } catch (PDDApiException e) {
            e.printStackTrace();
            if (e.getCode() == PDDApiException.CODE_NOT_AUTH) {
                try {
                    pddGoods = PinDuoDuoApiUtil.getGoodsDetail(id, PinDuoDuoApiUtil.PID_FANLI, Constant.PDD_SEARCH_CUSTOMER_PARAMS);
                    pddGoods = PinDuoDuoApiUtil.getGoodsDetail(id, pid, Constant.PDD_SEARCH_CUSTOMER_PARAMS);
                } catch (PDDApiException e1) {
                }
            }
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/GoodsController.java
@@ -7,7 +7,9 @@
import com.yeshi.fanli.entity.SystemEnum;
import com.yeshi.fanli.entity.SystemFunction;
import com.yeshi.fanli.entity.SystemPIDInfo;
import com.yeshi.fanli.exception.taobao.TaoBaoConvertLinkException;
import com.yeshi.fanli.service.manger.PIDManager;
import com.yeshi.fanli.service.manger.goods.TaoBaoLinkManager;
import com.yeshi.fanli.util.SystemInfoUtil;
import org.springframework.stereotype.Controller;
@@ -93,6 +95,9 @@
    @Resource
    private TaoBaoLinkManager taoBaoLinkManager;
    @Resource
    private PIDManager pidManager;
    private void doTaoLiJinBuy(AcceptData acceptData, Long uid, Long auctionId, PrintWriter out) {
        JSONObject data = new JSONObject();
        TaoBaoLink taoBaoLink = null;
@@ -135,13 +140,9 @@
                                           HttpServletRequest request, PrintWriter out) {
        try {
            String pid =  TaoBaoConstant.TAOBAO_COUPON_PID;
            String pid = pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.coupon);
            if (acceptData.getSystem() == SystemEnum.yhqjx) {
                pid="mm_124933865_56750082_19510050154";
            }
            TaoBaoLink taoBaoLink = taoBaoLinkManager.getTaoBaoLinkForRecieveCoupon(auctionId, null, pid);
            TaoBaoLink taoBaoLink = taoBaoLinkManager.getTaoBaoLinkForRecieveCoupon(acceptData.getSystem(), auctionId, null, pid);
            JSONObject data = new JSONObject();
            JSONObject link = new JSONObject();
            link.put("clickUrl", taoBaoLink.getClickUrl());
@@ -222,9 +223,9 @@
        String dpid = null;
        if (TaoBaoUtil.isSpecialGoods(goods.getMaterialLibType())) {
            dpid = TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT;
            dpid = pidManager.getPid(acceptData.getSystem(), Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.fanli);
        } else {
            dpid = TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID;
            dpid = pidManager.getPid(acceptData.getSystem(), Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.fanliChannel);
        }
        String psiteId = dpid.split("_")[2];
        String padzoneId = dpid.split("_")[3];
@@ -256,7 +257,7 @@
            } else
                isNative = false;
            pid = TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT;
            pid = pidManager.getPid(acceptData.getSystem(), Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.fanli);
        } else {// 尚未绑定
            isNative = true;
@@ -278,7 +279,7 @@
                    }
                    if (taoBaoLink == null) {
                        taoBaoLink = taoBaoLinkManager.getTaoBaoLinkForBuy(uid, auctionId, specialId, null);
                        taoBaoLink = taoBaoLinkManager.getTaoBaoLinkForBuy(acceptData.getSystem(), uid, auctionId, specialId, null);
                        if (taoBaoLink != null)
                            clientTBPid = null;
                    }
@@ -293,7 +294,7 @@
                            taoBaoLink = shareGoodsService.getTaoBaoLink(uid, auctionId,
                                    tbPidService.getIOSDefault().getPid());
                    } else
                        taoBaoLink = taoBaoLinkManager.getTaoBaoLinkForBuy(uid, auctionId, specialId, null);
                        taoBaoLink = taoBaoLinkManager.getTaoBaoLinkForBuy(acceptData.getSystem(), uid, auctionId, specialId, null);
                    LogHelper.test("购买转链:默认PID转链-" + uid + ":" + auctionId);
                }
            } else {// 不是返利库的商品,用特殊PID替代
@@ -305,10 +306,10 @@
                if (!StringUtil.isNullOrEmpty(relationId)) {//
                    if (source != null && "taolijin_free_buy".equals(source)) {
                        taoBaoLink = taoBaoLinkManager.getTaoLiJinLinkForBuy(uid, auctionId,
                                TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID);
                                pidManager.getPid(acceptData.getSystem(), Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.fanliChannel));
                    } else {
                        taoBaoLink = taoBaoLinkManager.getTaoBaoLinkForShare(uid, auctionId, relationId,
                                TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID);
                        taoBaoLink = taoBaoLinkManager.getTaoBaoLinkForShare(acceptData.getSystem(), uid, auctionId, relationId,
                                pidManager.getPid(acceptData.getSystem(), Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.fanliChannel));
                    }
                    data.put("native", true);
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/RecommendController.java
Diff too large
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/ShareController.java
@@ -11,7 +11,9 @@
import javax.servlet.http.HttpServletRequest;
import com.yeshi.fanli.entity.SystemEnum;
import com.yeshi.fanli.entity.SystemPIDInfo;
import com.yeshi.fanli.exception.taobao.TaoBaoConvertLinkException;
import com.yeshi.fanli.service.manger.PIDManager;
import com.yeshi.fanli.service.manger.goods.TaoBaoLinkManager;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Controller;
@@ -87,1145 +89,1142 @@
@RequestMapping("api/v1/share")
public class ShareController {
    @Resource(name = "taskExecutor")
    private TaskExecutor executor;
    @Resource(name = "taskExecutor")
    private TaskExecutor executor;
    @Resource
    private ShareGoodsService shareGoodsService;
    @Resource
    private ShareGoodsService shareGoodsService;
    @Resource
    private TaoBaoLinkManager taoBaoLinkManager;
    @Resource
    private TaoBaoLinkManager taoBaoLinkManager;
    @Resource
    private ConfigService configService;
    @Resource
    private ConfigService configService;
    @Resource
    private HongBaoManageService hongBaoManageService;
    @Resource
    private HongBaoManageService hongBaoManageService;
    @Resource
    private MonitorService monitorService;
    @Resource
    private MonitorService monitorService;
    @Resource
    private UserShareGoodsRecordService userShareGoodsRecordService;
    @Resource
    private UserShareGoodsRecordService userShareGoodsRecordService;
    @Resource
    private UserShareGoodsGroupService userShareGoodsGroupService;
    @Resource
    private UserShareGoodsGroupService userShareGoodsGroupService;
    @Resource
    private CommonGoodsService commonGoodsService;
    @Resource
    private CommonGoodsService commonGoodsService;
    @Resource
    private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService;
    @Resource
    private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService;
    @Resource
    private UserInfoService userInfoService;
    @Resource
    private UserInfoService userInfoService;
    @Resource
    private TaoBaoGoodsCacheUtil taoBaoGoodsCacheUtil;
    @Resource
    private TaoBaoGoodsCacheUtil taoBaoGoodsCacheUtil;
    @Resource
    private RedisManager redisManager;
    @Resource
    private RedisManager redisManager;
    @Resource
    private ShareGoodsTextTemplateService shareGoodsTextTemplateService;
    @Resource
    private ShareGoodsTextTemplateService shareGoodsTextTemplateService;
    @Resource
    private SystemClientParamsService systemClientParamsService;
    @Resource
    private SystemClientParamsService systemClientParamsService;
    @Resource
    private DynamicInfoService dynamicInfoService;
    @Resource
    private DynamicInfoService dynamicInfoService;
    @Resource
    private UserInfoExtraService userInfoExtraService;
    @Resource
    private UserInfoExtraService userInfoExtraService;
    @Resource
    private SpreadUserImgService spreadUserImgService;
    @Resource
    private SpreadUserImgService spreadUserImgService;
    @Resource
    private BusinessEmergent110Service businessEmergent110Service;
    @Resource
    private BusinessEmergent110Service businessEmergent110Service;
    @Resource
    private ConfigTaoLiJinService configTaoLiJinService;
    @Resource
    private ConfigTaoLiJinService configTaoLiJinService;
    @Resource
    private UserTaoLiJinRecordService userTaoLiJinRecordService;
    @Resource
    private UserTaoLiJinRecordService userTaoLiJinRecordService;
    // 获取商品分享链接
    @RequestMapping(value = "getGoodsShareUrl")
    public void getGoodsShareUrl(AcceptData acceptData, long id, PrintWriter out) {
        out.print(JsonUtil
                .loadTrueResult(String.format("%s?id=" + id, Constant.systemCommonConfig.getAppShareInfoUrl())));
    }
    @Resource
    private PIDManager pidManager;
    /**
     * 获取淘宝的分享链接
     *
     * @param acceptData
     * @param uid
     *            -用户ID
     * @param auctionId-商品ID
     * @param out
     */
    @RequestMapping(value = "gettaobaosharelink")
    public void getTaobaoShareLink(AcceptData acceptData, Long uid, Long auctionId, String source, Integer totalNum,
            HttpServletRequest request, PrintWriter out) {
    // 获取商品分享链接
    @RequestMapping(value = "getGoodsShareUrl")
    public void getGoodsShareUrl(AcceptData acceptData, long id, PrintWriter out) {
        out.print(JsonUtil
                .loadTrueResult(String.format("%s?id=" + id, Constant.systemCommonConfig.getAppShareInfoUrl())));
    }
        if (uid == null || uid <= 0) {
            out.print(JsonUtil.loadFalseResult(1, "用户ID不能为空"));
            return;
        }
    /**
     * 获取淘宝的分享链接
     *
     * @param acceptData
     * @param uid            -用户ID
     * @param auctionId-商品ID
     * @param out
     */
    @RequestMapping(value = "gettaobaosharelink")
    public void getTaobaoShareLink(AcceptData acceptData, Long uid, Long auctionId, String source, Integer totalNum,
                                   HttpServletRequest request, PrintWriter out) {
        UserInfo user = userInfoService.getUserByIdWithMybatis(uid);
        if (user != null && user.getState() != UserInfo.STATE_NORMAL) {
            out.print(JsonUtil.loadFalseResult(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC));
            return;
        }
        if (uid == null || uid <= 0) {
            out.print(JsonUtil.loadFalseResult(1, "用户ID不能为空"));
            return;
        }
        if (auctionId == null || auctionId <= 0) {
            out.print(JsonUtil.loadFalseResult(2, "商品ID不能为空"));
            return;
        }
        UserInfo user = userInfoService.getUserByIdWithMybatis(uid);
        if (user != null && user.getState() != UserInfo.STATE_NORMAL) {
            out.print(JsonUtil.loadFalseResult(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC));
            return;
        }
        UserExtraTaoBaoInfo extraInfo = userExtraTaoBaoInfoService.getByUid(uid);
        String relationId = null;
        if (extraInfo != null && extraInfo.getRelationId() != null && extraInfo.getRelationValid() != null
                && extraInfo.getRelationValid() == true)
            relationId = extraInfo.getRelationId();
        if (auctionId == null || auctionId <= 0) {
            out.print(JsonUtil.loadFalseResult(2, "商品ID不能为空"));
            return;
        }
        if (StringUtil.isNullOrEmpty(relationId)) {
            out.print(JsonUtil.loadFalseResult(3, "淘宝未授权,请前往\"我的\"绑定淘宝账号"));
            return;
        }
        UserExtraTaoBaoInfo extraInfo = userExtraTaoBaoInfoService.getByUid(uid);
        String relationId = null;
        if (extraInfo != null && extraInfo.getRelationId() != null && extraInfo.getRelationValid() != null
                && extraInfo.getRelationValid() == true)
            relationId = extraInfo.getRelationId();
        if (source != null && "taolijin".equals(source)) {
            createTaoLijin(uid, auctionId, totalNum, relationId,acceptData.getSystem(), request, out);
            return;
        }
        if (StringUtil.isNullOrEmpty(relationId)) {
            out.print(JsonUtil.loadFalseResult(3, "淘宝未授权,请前往\"我的\"绑定淘宝账号"));
            return;
        }
        try {
            TaoBaoLink taoBaoLink = taoBaoLinkManager.getTaoBaoLinkForShare(uid, auctionId, relationId,null);
        if (source != null && "taolijin".equals(source)) {
            createTaoLijin(uid, auctionId, totalNum, relationId, acceptData.getSystem(), request, out);
            return;
        }
            JSONObject data = new JSONObject();
            String url = String.format("http://%s%s?uid=%s&id=%s&appType=flq", configService.getH5Host(acceptData.getSystem()),
                    Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY),
                    auctionId + "");
        try {
            TaoBaoLink taoBaoLink = taoBaoLinkManager.getTaoBaoLinkForShare(acceptData.getSystem(), uid, auctionId, relationId, null);
            String shortLink = HttpUtil.getShortLink(url);
            if (!StringUtil.isNullOrEmpty(shortLink)) {
                url = shortLink;
            }
            JSONObject data = new JSONObject();
            String url = String.format("http://%s%s?uid=%s&id=%s&appType=flq", configService.getH5Host(acceptData.getSystem()),
                    Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY),
                    auctionId + "");
            data.put("clickUrl", url);
            data.put("token", TaoBaoUtil.filterTaoToken(taoBaoLink.getTaoToken()));
            data.put("rule", configService.getValue(ConfigKeyEnum.shareSingleGoodsRule.getKey(),acceptData.getSystem()));
            data.put("pictUrl", TbImgUtil.getTBSizeImg(taoBaoLink.getGoods().getPictUrl(), 500));
            String shortLink = HttpUtil.getShortLink(url);
            if (!StringUtil.isNullOrEmpty(shortLink)) {
                url = shortLink;
            }
            String shareText = "";
            // 无券
            String shopType = taoBaoLink.getGoods().getUserType() == 0 ? TaoBaoConstant.SHARE_PRICE_TAOBAO
                    : TaoBaoConstant.SHARE_PRICE_TM;
            data.put("clickUrl", url);
            data.put("token", TaoBaoUtil.filterTaoToken(taoBaoLink.getTaoToken()));
            data.put("rule", configService.getValue(ConfigKeyEnum.shareSingleGoodsRule.getKey(), acceptData.getSystem()));
            data.put("pictUrl", TbImgUtil.getTBSizeImg(taoBaoLink.getGoods().getPictUrl(), 500));
            if (StringUtil.isNullOrEmpty(taoBaoLink.getGoods().getCouponInfo())) {
                String text = shareGoodsTextTemplateService.getCommonTemplate(uid);
                if (StringUtil.isNullOrEmpty(text))
                    text = configService.getValue(ConfigKeyEnum.goodsShareTextNoCoupon.getKey(),acceptData.getSystem());
                shareText = text.replace("{标题}", taoBaoLink.getGoods().getTitle()).replace("{商品原价}",
                        MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getZkPrice()) + "");
            } else// 有券
            {
                String text = shareGoodsTextTemplateService.geteCouponTemplate(uid);
                if (StringUtil.isNullOrEmpty(text))
                    text = configService.getValue(ConfigKeyEnum.goodsShareTextCoupon.getKey(),acceptData.getSystem());
            String shareText = "";
            // 无券
            String shopType = taoBaoLink.getGoods().getUserType() == 0 ? TaoBaoConstant.SHARE_PRICE_TAOBAO
                    : TaoBaoConstant.SHARE_PRICE_TM;
                shareText = text.replace("{标题}", taoBaoLink.getGoods().getTitle())
                        .replace("{商品原价}", MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getZkPrice()) + "")
                        .replace("{优惠券面额}",
                                MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getCouponAmount()).toString())
                        .replace("{优惠券价}", TaoBaoUtil.getCouponPrice(taoBaoLink.getGoods()) + "");
            }
            if (StringUtil.isNullOrEmpty(taoBaoLink.getGoods().getCouponInfo())) {
                String text = shareGoodsTextTemplateService.getCommonTemplate(uid);
                if (StringUtil.isNullOrEmpty(text))
                    text = configService.getValue(ConfigKeyEnum.goodsShareTextNoCoupon.getKey(), acceptData.getSystem());
                shareText = text.replace("{标题}", taoBaoLink.getGoods().getTitle()).replace("{商品原价}",
                        MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getZkPrice()) + "");
            } else// 有券
            {
                String text = shareGoodsTextTemplateService.geteCouponTemplate(uid);
                if (StringUtil.isNullOrEmpty(text))
                    text = configService.getValue(ConfigKeyEnum.goodsShareTextCoupon.getKey(), acceptData.getSystem());
            shareText = shareText.replace("{店铺类型}", shopType)
                    .replace("{月销量}", TaoBaoUtil.getSaleCount(taoBaoLink.getGoods().getBiz30day()))
                    .replace("{领券短链}", shortLink).replace("{淘口令}", TaoBaoUtil.filterTaoToken(taoBaoLink.getTaoToken()));
            data.put("shareText", shareText);
            String descText = shareText.replace(taoBaoLink.getGoods().getTitle(), "").trim();
            if (descText.startsWith("\\r\\n"))
                descText = descText.substring(0);
            data.put("descText", descText);
            //
            String imgs = configService.getValue(ConfigKeyEnum.goodsShareNotifyImgs.getKey(),acceptData.getSystem());
            JSONArray array = JSONArray.fromObject(imgs);
            int p = (int) (array.size() * Math.random());
            if (p < array.size())
                data.put("notifyPicture", array.optString(p));
            data.put("notifyDesc", configService.getValue(ConfigKeyEnum.goodsShareNotify.getKey(),acceptData.getSystem()));
                shareText = text.replace("{标题}", taoBaoLink.getGoods().getTitle())
                        .replace("{商品原价}", MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getZkPrice()) + "")
                        .replace("{优惠券面额}",
                                MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getCouponAmount()).toString())
                        .replace("{优惠券价}", TaoBaoUtil.getCouponPrice(taoBaoLink.getGoods()) + "");
            }
            // 添加分享记录
            BigDecimal rate = hongBaoManageService.getShareRate(acceptData.getSystem());
            BigDecimal shareMoney = TaoBaoUtil.getShareGoodsHongBaoInfo(taoBaoLink.getGoods(), rate);
            shareText = shareText.replace("{店铺类型}", shopType)
                    .replace("{月销量}", TaoBaoUtil.getSaleCount(taoBaoLink.getGoods().getBiz30day()))
                    .replace("{领券短链}", shortLink).replace("{淘口令}", TaoBaoUtil.filterTaoToken(taoBaoLink.getTaoToken()));
            data.put("shareText", shareText);
            String descText = shareText.replace(taoBaoLink.getGoods().getTitle(), "").trim();
            if (descText.startsWith("\\r\\n"))
                descText = descText.substring(0);
            data.put("descText", descText);
            //
            String imgs = configService.getValue(ConfigKeyEnum.goodsShareNotifyImgs.getKey(), acceptData.getSystem());
            JSONArray array = JSONArray.fromObject(imgs);
            int p = (int) (array.size() * Math.random());
            if (p < array.size())
                data.put("notifyPicture", array.optString(p));
            data.put("notifyDesc", configService.getValue(ConfigKeyEnum.goodsShareNotify.getKey(), acceptData.getSystem()));
            data.put("shareMoney", "¥" + shareMoney.toString());
            try {
                ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, auctionId,
                        Constant.SOURCE_TYPE_TAOBAO, false);
                data.put("shareId", shareRecord.getRedisKey());
            } catch (Exception e) {
                try {
                    LogHelper.errorDetailInfo(e);
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
            out.print(JsonUtil.loadTrueResult(data));
            // 添加分享记录
            BigDecimal rate = hongBaoManageService.getShareRate(acceptData.getSystem());
            BigDecimal shareMoney = TaoBaoUtil.getShareGoodsHongBaoInfo(taoBaoLink.getGoods(), rate);
            final TaoBaoLink taobaoLink = taoBaoLink;
            // 异步操作
            com.yeshi.fanli.util.ThreadUtil.run(new Runnable() {
                @Override
                public void run() {
                    // 异步操作 添加分享记录
                    UserShareGoodsHistory history = new UserShareGoodsHistory();
                    history.setUser(new UserInfo(uid));
                    history.setHongbao(shareMoney);
                    history.setCreateTime(new Date());
                    history.setGoodsType(UserShareGoodsHistory.TYPE_TAOBAO);
                    history.setTkCode(TaoBaoUtil.filterTaoToken(taobaoLink.getTaoToken()));
                    history.setLink(taobaoLink.getClickUrl());
                    history.setQuanLink(taobaoLink.getCouponLink());
                    history.setGoodsId(taobaoLink.getGoods().getAuctionId());
                    history.setPostPicture(taobaoLink.getGoods().getPictUrl());
            data.put("shareMoney", "¥" + shareMoney.toString());
            try {
                ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, auctionId,
                        Constant.SOURCE_TYPE_TAOBAO, false);
                data.put("shareId", shareRecord.getRedisKey());
            } catch (Exception e) {
                try {
                    LogHelper.errorDetailInfo(e);
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
            out.print(JsonUtil.loadTrueResult(data));
                    List<String> imgList = taobaoLink.getGoods().getImgList();
                    if (imgList == null) {
                        imgList = new ArrayList<>();
                    }
                    history.setPictures(JsonUtil.getGson().toJson(imgList));
                    shareGoodsService.addShareGoodsHistory(history);
                }
            });
            return;
        } catch (TaoBaoConvertLinkException e) {
            LogHelper.errorDetailInfo(e, "分享出错:uid:" + uid + "auctionId:" + auctionId, "");
            // 分享出错报警
            try {
                monitorService.addClientAPIMonitor(MonitorFactory.createClientAPI(request, e.getCode(), 0, "分享出错"));
            } catch (Exception e1) {
            }
            out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMessage()));
            businessEmergent110Service.shareTaoBaoGoodsError(StringUtil.Md5(auctionId + ""),acceptData.getSystem());
        }
    }
            final TaoBaoLink taobaoLink = taoBaoLink;
            // 异步操作
            com.yeshi.fanli.util.ThreadUtil.run(new Runnable() {
                @Override
                public void run() {
                    // 异步操作 添加分享记录
                    UserShareGoodsHistory history = new UserShareGoodsHistory();
                    history.setUser(new UserInfo(uid));
                    history.setHongbao(shareMoney);
                    history.setCreateTime(new Date());
                    history.setGoodsType(UserShareGoodsHistory.TYPE_TAOBAO);
                    history.setTkCode(TaoBaoUtil.filterTaoToken(taobaoLink.getTaoToken()));
                    history.setLink(taobaoLink.getClickUrl());
                    history.setQuanLink(taobaoLink.getCouponLink());
                    history.setGoodsId(taobaoLink.getGoods().getAuctionId());
                    history.setPostPicture(taobaoLink.getGoods().getPictUrl());
    /**
     * 淘礼金创建分享
     *
     * @param uid
     * @param auctionId
     * @param totalNum
     * @param relationId
     * @param request
     * @param out
     */
    public void createTaoLijin(Long uid, Long auctionId, int totalNum, String relationId, SystemEnum system, HttpServletRequest request,
                               PrintWriter out) {
        try {
            TaoBaoLink taoBaoLink = taoBaoLinkManager.getTaoLiJinLinkForShare(uid, auctionId, relationId,null);
                    List<String> imgList = taobaoLink.getGoods().getImgList();
                    if (imgList == null) {
                        imgList = new ArrayList<>();
                    }
                    history.setPictures(JsonUtil.getGson().toJson(imgList));
                    shareGoodsService.addShareGoodsHistory(history);
                }
            });
            return;
        } catch (TaoBaoConvertLinkException e) {
            LogHelper.errorDetailInfo(e, "分享出错:uid:" + uid + "auctionId:" + auctionId, "");
            // 分享出错报警
            try {
                monitorService.addClientAPIMonitor(MonitorFactory.createClientAPI(request, e.getCode(), 0, "分享出错"));
            } catch (Exception e1) {
            }
            out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMessage()));
            businessEmergent110Service.shareTaoBaoGoodsError(StringUtil.Md5(auctionId + ""), acceptData.getSystem());
        }
    }
            TaoBaoGoodsBrief goods = taoBaoLink.getGoods();
    /**
     * 淘礼金创建分享
     *
     * @param uid
     * @param auctionId
     * @param totalNum
     * @param relationId
     * @param request
     * @param out
     */
    public void createTaoLijin(Long uid, Long auctionId, int totalNum, String relationId, SystemEnum system, HttpServletRequest request,
                               PrintWriter out) {
        try {
            TaoBaoLink taoBaoLink = taoBaoLinkManager.getTaoLiJinLinkForShare(system, uid, auctionId, relationId, null);
            // 计算推广红包
            String warningRate = configTaoLiJinService.getValueByKey("warning_value", null);
            BigDecimal spreadMoney = TaoLiJinUtil.getSpreadMoney(warningRate, goods);
            TaoBaoGoodsBrief goods = taoBaoLink.getGoods();
            // 推广红包 不能小于1
            if (spreadMoney.compareTo(new BigDecimal(1.1)) < 0) {
                out.print(JsonUtil.loadFalseResult(1, "该商品淘礼金不足"));
                return;
            }
            // 计算推广红包
            String warningRate = configTaoLiJinService.getValueByKey("warning_value", null);
            BigDecimal spreadMoney = TaoLiJinUtil.getSpreadMoney(warningRate, goods);
            JSONObject data = new JSONObject();
            data.put("spreadMoney", " ¥" + spreadMoney.toString());
            // 推广红包 不能小于1
            if (spreadMoney.compareTo(new BigDecimal(1.1)) < 0) {
                out.print(JsonUtil.loadFalseResult(1, "该商品淘礼金不足"));
                return;
            }
            String taoLiJinLink = null;
            Long tljId = null;
            try {
                UserTaoLiJinRecord record = userTaoLiJinRecordService.createShareTaoLiJin(uid, totalNum, goods);
                tljId = record.getId();
                taoLiJinLink = record.getSendUrl();
                data.put("tljId", tljId);
                data.put("surplusMoney", record.getSurplusMoney());
            } catch (UserTaoLiJinRecordException e) {
                out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
                return;
            }
            JSONObject data = new JSONObject();
            data.put("spreadMoney", " ¥" + spreadMoney.toString());
            String url = String.format("http://%s%s?uid=%s&id=%s&appType=flq&tid=%s", configService.getH5Host(system),
                    Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY),
                    auctionId + "", AESUtil.encrypt(tljId + "", Constant.UIDAESKEY));
            String shortLink = HttpUtil.getShortLink(url);
            if (!StringUtil.isNullOrEmpty(shortLink)) {
                url = shortLink;
            }
            data.put("clickUrl", url);
            String taoLiJinLink = null;
            Long tljId = null;
            try {
                UserTaoLiJinRecord record = userTaoLiJinRecordService.createShareTaoLiJin(uid, totalNum, goods);
                tljId = record.getId();
                taoLiJinLink = record.getSendUrl();
                data.put("tljId", tljId);
                data.put("surplusMoney", record.getSurplusMoney());
            } catch (UserTaoLiJinRecordException e) {
                out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
                return;
            }
            // 创建淘口令
            if (!StringUtil.isNullOrEmpty(taoLiJinLink)) {// 通过立即推广方式获取淘口令成功
                String quanToken = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), taoLiJinLink);
                if (!StringUtil.isNullOrEmpty(quanToken)) {
                    taoBaoLink.setTaoToken(quanToken);
                }
            } else if (!StringUtil.isNullOrEmpty(taoBaoLink.getClickUrl())) {
                String quanToken = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(),
                        taoBaoLink.getClickUrl());
                if (!StringUtil.isNullOrEmpty(quanToken)) {
                    taoBaoLink.setTaoToken(quanToken);
                }
            }
            data.put("token", TaoBaoUtil.filterTaoToken(taoBaoLink.getTaoToken()));
            String url = String.format("http://%s%s?uid=%s&id=%s&appType=flq&tid=%s", configService.getH5Host(system),
                    Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY),
                    auctionId + "", AESUtil.encrypt(tljId + "", Constant.UIDAESKEY));
            String shortLink = HttpUtil.getShortLink(url);
            if (!StringUtil.isNullOrEmpty(shortLink)) {
                url = shortLink;
            }
            data.put("clickUrl", url);
            data.put("rule",
                    "http://apph5.banliapp.com/apppage/all_help_content.html?id=148&from=singlemessage&isappinstalled=0");
            data.put("pictUrl", TbImgUtil.getTBSizeImg(taoBaoLink.getGoods().getPictUrl(), 500));
            // 创建淘口令
            if (!StringUtil.isNullOrEmpty(taoLiJinLink)) {// 通过立即推广方式获取淘口令成功
                String quanToken = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), taoLiJinLink);
                if (!StringUtil.isNullOrEmpty(quanToken)) {
                    taoBaoLink.setTaoToken(quanToken);
                }
            } else if (!StringUtil.isNullOrEmpty(taoBaoLink.getClickUrl())) {
                String quanToken = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(),
                        taoBaoLink.getClickUrl());
                if (!StringUtil.isNullOrEmpty(quanToken)) {
                    taoBaoLink.setTaoToken(quanToken);
                }
            }
            data.put("token", TaoBaoUtil.filterTaoToken(taoBaoLink.getTaoToken()));
            // 无券
            String shopType = taoBaoLink.getGoods().getUserType() == 0 ? TaoBaoConstant.SHARE_PRICE_TAOBAO
                    : TaoBaoConstant.SHARE_PRICE_TM;
            String shareText = "";
            data.put("rule",
                    "http://apph5.banliapp.com/apppage/all_help_content.html?id=148&from=singlemessage&isappinstalled=0");
            data.put("pictUrl", TbImgUtil.getTBSizeImg(taoBaoLink.getGoods().getPictUrl(), 500));
            if (StringUtil.isNullOrEmpty(taoBaoLink.getGoods().getCouponInfo())) {
                String text = shareGoodsTextTemplateService.getCommonTemplate(uid);
                if (StringUtil.isNullOrEmpty(text))
                    text = configService.getValue(ConfigKeyEnum.goodsShareTextNoCoupon.getKey(),system);
                shareText = text.replace("{标题}", taoBaoLink.getGoods().getTitle()).replace("{商品原价}",
                        MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getZkPrice()) + "");
            } else// 有券
            {
                String text = shareGoodsTextTemplateService.getTaoLiJinTemplate(uid);
                if (StringUtil.isNullOrEmpty(text))
                    text = configTaoLiJinService.getValueByKey("goods_share_text", new Date());
            // 无券
            String shopType = taoBaoLink.getGoods().getUserType() == 0 ? TaoBaoConstant.SHARE_PRICE_TAOBAO
                    : TaoBaoConstant.SHARE_PRICE_TM;
            String shareText = "";
                shareText = text.replace("{标题}", taoBaoLink.getGoods().getTitle())
                        .replace("{商品原价}", MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getZkPrice()) + "")
                        .replace("{优惠券面额}",
                                MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getCouponAmount()).toString())
                        .replace("{淘礼金面额}", MoneyBigDecimalUtil.getWithNoZera(spreadMoney).toString())
                        .replace("{优惠券价}", TaoBaoUtil.getCouponPrice(taoBaoLink.getGoods()) + "");
            }
            if (StringUtil.isNullOrEmpty(taoBaoLink.getGoods().getCouponInfo())) {
                String text = shareGoodsTextTemplateService.getCommonTemplate(uid);
                if (StringUtil.isNullOrEmpty(text))
                    text = configService.getValue(ConfigKeyEnum.goodsShareTextNoCoupon.getKey(), system);
                shareText = text.replace("{标题}", taoBaoLink.getGoods().getTitle()).replace("{商品原价}",
                        MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getZkPrice()) + "");
            } else// 有券
            {
                String text = shareGoodsTextTemplateService.getTaoLiJinTemplate(uid);
                if (StringUtil.isNullOrEmpty(text))
                    text = configTaoLiJinService.getValueByKey("goods_share_text", new Date());
            shareText = shareText.replace("{店铺类型}", shopType)
                    .replace("{月销量}", TaoBaoUtil.getSaleCount(taoBaoLink.getGoods().getBiz30day()))
                    .replace("{领券短链}", shortLink).replace("{淘口令}", TaoBaoUtil.filterTaoToken(taoBaoLink.getTaoToken()));
            data.put("shareText", shareText);
            String descText = shareText.replace(taoBaoLink.getGoods().getTitle(), "").trim();
            if (descText.startsWith("\\r\\n"))
                descText = descText.substring(0);
            data.put("descText", descText);
                shareText = text.replace("{标题}", taoBaoLink.getGoods().getTitle())
                        .replace("{商品原价}", MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getZkPrice()) + "")
                        .replace("{优惠券面额}",
                                MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getCouponAmount()).toString())
                        .replace("{淘礼金面额}", MoneyBigDecimalUtil.getWithNoZera(spreadMoney).toString())
                        .replace("{优惠券价}", TaoBaoUtil.getCouponPrice(taoBaoLink.getGoods()) + "");
            }
            String imgs = configService.getValue(ConfigKeyEnum.goodsShareNotifyImgs.getKey(),system);
            JSONArray array = JSONArray.fromObject(imgs);
            int p = (int) (array.size() * Math.random());
            if (p < array.size())
                data.put("notifyPicture", array.optString(p));
            data.put("notifyDesc", configService.getValue(ConfigKeyEnum.goodsShareNotify.getKey(),system));
            shareText = shareText.replace("{店铺类型}", shopType)
                    .replace("{月销量}", TaoBaoUtil.getSaleCount(taoBaoLink.getGoods().getBiz30day()))
                    .replace("{领券短链}", shortLink).replace("{淘口令}", TaoBaoUtil.filterTaoToken(taoBaoLink.getTaoToken()));
            data.put("shareText", shareText);
            String descText = shareText.replace(taoBaoLink.getGoods().getTitle(), "").trim();
            if (descText.startsWith("\\r\\n"))
                descText = descText.substring(0);
            data.put("descText", descText);
            // 添加分享记录
            BigDecimal rate = hongBaoManageService.getShareRate(system);
            BigDecimal shareMoney = TaoBaoUtil.getShareGoodsHongBaoInfo(taoBaoLink.getGoods(), rate);
            String imgs = configService.getValue(ConfigKeyEnum.goodsShareNotifyImgs.getKey(), system);
            JSONArray array = JSONArray.fromObject(imgs);
            int p = (int) (array.size() * Math.random());
            if (p < array.size())
                data.put("notifyPicture", array.optString(p));
            data.put("notifyDesc", configService.getValue(ConfigKeyEnum.goodsShareNotify.getKey(), system));
            data.put("shareMoney", "¥" + shareMoney.toString());
            try {
                ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, auctionId,
                        Constant.SOURCE_TYPE_TAOBAO, true);
                data.put("shareId", shareRecord.getRedisKey());
            } catch (Exception e) {
                try {
                    LogHelper.errorDetailInfo(e);
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
            out.print(JsonUtil.loadTrueResult(data));
            // 添加分享记录
            BigDecimal rate = hongBaoManageService.getShareRate(system);
            BigDecimal shareMoney = TaoBaoUtil.getShareGoodsHongBaoInfo(taoBaoLink.getGoods(), rate);
            final TaoBaoLink taobaoLink = taoBaoLink;
            // 异步操作
            com.yeshi.fanli.util.ThreadUtil.run(new Runnable() {
                @Override
                public void run() {
                    // 异步操作 添加分享记录
                    UserShareGoodsHistory history = new UserShareGoodsHistory();
                    history.setUser(new UserInfo(uid));
                    history.setHongbao(shareMoney);
                    history.setCreateTime(new Date());
                    history.setGoodsType(UserShareGoodsHistory.TYPE_TAOBAO);
                    history.setTkCode(TaoBaoUtil.filterTaoToken(taobaoLink.getTaoToken()));
                    history.setLink(taobaoLink.getClickUrl());
                    history.setQuanLink(taobaoLink.getCouponLink());
                    history.setGoodsId(taobaoLink.getGoods().getAuctionId());
                    history.setPostPicture(taobaoLink.getGoods().getPictUrl());
            data.put("shareMoney", "¥" + shareMoney.toString());
            try {
                ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, auctionId,
                        Constant.SOURCE_TYPE_TAOBAO, true);
                data.put("shareId", shareRecord.getRedisKey());
            } catch (Exception e) {
                try {
                    LogHelper.errorDetailInfo(e);
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
            out.print(JsonUtil.loadTrueResult(data));
                    List<String> imgList = taobaoLink.getGoods().getImgList();
                    if (imgList == null) {
                        imgList = new ArrayList<>();
                    }
                    history.setPictures(JsonUtil.getGson().toJson(imgList));
                    shareGoodsService.addShareGoodsHistory(history);
                }
            });
            return;
        } catch (TaoBaoConvertLinkException e) {
            LogHelper.errorDetailInfo(e, "分享出错:uid:" + uid + "auctionId:" + auctionId, "");
            // 分享出错报警
            try {
                monitorService.addClientAPIMonitor(MonitorFactory.createClientAPI(request, e.getCode(), 0, "分享出错"));
            } catch (Exception e1) {
            }
            out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMessage()));
            businessEmergent110Service.shareTaoBaoGoodsError(StringUtil.Md5(auctionId + ""),system);
        }
    }
            final TaoBaoLink taobaoLink = taoBaoLink;
            // 异步操作
            com.yeshi.fanli.util.ThreadUtil.run(new Runnable() {
                @Override
                public void run() {
                    // 异步操作 添加分享记录
                    UserShareGoodsHistory history = new UserShareGoodsHistory();
                    history.setUser(new UserInfo(uid));
                    history.setHongbao(shareMoney);
                    history.setCreateTime(new Date());
                    history.setGoodsType(UserShareGoodsHistory.TYPE_TAOBAO);
                    history.setTkCode(TaoBaoUtil.filterTaoToken(taobaoLink.getTaoToken()));
                    history.setLink(taobaoLink.getClickUrl());
                    history.setQuanLink(taobaoLink.getCouponLink());
                    history.setGoodsId(taobaoLink.getGoods().getAuctionId());
                    history.setPostPicture(taobaoLink.getGoods().getPictUrl());
    /**
     * 分享记录统计列表
     *
     * @param acceptData
     * @param page
     *            初始1
     * @param uid
     * @param source
     * @param out
     */
    @RequestMapping(value = "getlistrecord", method = RequestMethod.POST)
    public void getListRecord(AcceptData acceptData, Integer page, Long uid, String source, PrintWriter out) {
                    List<String> imgList = taobaoLink.getGoods().getImgList();
                    if (imgList == null) {
                        imgList = new ArrayList<>();
                    }
                    history.setPictures(JsonUtil.getGson().toJson(imgList));
                    shareGoodsService.addShareGoodsHistory(history);
                }
            });
            return;
        } catch (TaoBaoConvertLinkException e) {
            LogHelper.errorDetailInfo(e, "分享出错:uid:" + uid + "auctionId:" + auctionId, "");
            // 分享出错报警
            try {
                monitorService.addClientAPIMonitor(MonitorFactory.createClientAPI(request, e.getCode(), 0, "分享出错"));
            } catch (Exception e1) {
            }
            out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMessage()));
            businessEmergent110Service.shareTaoBaoGoodsError(StringUtil.Md5(auctionId + ""), system);
        }
    }
        if (page == null || page < 1) {
            out.print(JsonUtil.loadFalseResult("页码不正确"));
        }
    /**
     * 分享记录统计列表
     *
     * @param acceptData
     * @param page       初始1
     * @param uid
     * @param source
     * @param out
     */
    @RequestMapping(value = "getlistrecord", method = RequestMethod.POST)
    public void getListRecord(AcceptData acceptData, Integer page, Long uid, String source, PrintWriter out) {
        if (uid == null) {
            out.print(JsonUtil.loadFalseResult("用户未登录"));
        }
        if (page == null || page < 1) {
            out.print(JsonUtil.loadFalseResult("页码不正确"));
        }
        if ("all".equals(source)) {
            source = null;// 查询全部
        }
        if (uid == null) {
            out.print(JsonUtil.loadFalseResult("用户未登录"));
        }
        try {
            int pageSize = Constant.PAGE_SIZE;
        if ("all".equals(source)) {
            source = null;// 查询全部
        }
            JSONObject data = new JSONObject();
            List<UserShareGoodsRecord> list = new ArrayList<UserShareGoodsRecord>();
        try {
            int pageSize = Constant.PAGE_SIZE;
            long count = userShareGoodsRecordService.countQueryByUid(uid, source);
            if (count > 0) {
                list = userShareGoodsRecordService.getMyShareGoodsRecords((page - 1) * pageSize, pageSize, uid, source);
            }
            JSONObject data = new JSONObject();
            List<UserShareGoodsRecord> list = new ArrayList<UserShareGoodsRecord>();
            GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
            gsonBuilder.registerTypeAdapter(BigDecimal.class, new JsonSerializer<BigDecimal>() {
                @Override
                public JsonElement serialize(BigDecimal value, Type theType, JsonSerializationContext context) {
                    if (value == null) {
                        return new JsonPrimitive("");
                    } else {
                        // 保留2位小数
                        value = value.setScale(2);
                        return new JsonPrimitive(value.toString());
                    }
                }
            });
            Gson gson = gsonBuilder.create();
            long count = userShareGoodsRecordService.countQueryByUid(uid, source);
            if (count > 0) {
                list = userShareGoodsRecordService.getMyShareGoodsRecords((page - 1) * pageSize, pageSize, uid, source);
            }
            data.put("count", count);
            data.put("result_list", gson.toJson(list));
            out.print(JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseResult("加载失败"));
            e.printStackTrace();
        }
    }
            GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
            gsonBuilder.registerTypeAdapter(BigDecimal.class, new JsonSerializer<BigDecimal>() {
                @Override
                public JsonElement serialize(BigDecimal value, Type theType, JsonSerializationContext context) {
                    if (value == null) {
                        return new JsonPrimitive("");
                    } else {
                        // 保留2位小数
                        value = value.setScale(2);
                        return new JsonPrimitive(value.toString());
                    }
                }
            });
            Gson gson = gsonBuilder.create();
    /**
     * 获取分享商品
     *
     * @param acceptData
     * @param recordId
     * @param out
     */
    @RequestMapping(value = "getrecordgoods", method = RequestMethod.POST)
    public void getRecordGoods(AcceptData acceptData, Long recordId, PrintWriter out) {
            data.put("count", count);
            data.put("result_list", gson.toJson(list));
            out.print(JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseResult("加载失败"));
            e.printStackTrace();
        }
    }
        if (recordId == null) {
            out.print(JsonUtil.loadFalseResult("参数不正确"));
        }
    /**
     * 获取分享商品
     *
     * @param acceptData
     * @param recordId
     * @param out
     */
    @RequestMapping(value = "getrecordgoods", method = RequestMethod.POST)
    public void getRecordGoods(AcceptData acceptData, Long recordId, PrintWriter out) {
        try {
            JSONObject data = userShareGoodsRecordService.getGoodsGroup(recordId,acceptData.getSystem());
            out.print(JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseResult("加载失败"));
            e.printStackTrace();
        }
    }
        if (recordId == null) {
            out.print(JsonUtil.loadFalseResult("参数不正确"));
        }
    /**
     * 获取分享商品单个统计信息
     *
     * @param acceptData
     * @param groupId
     * @param out
     */
    @RequestMapping(value = "getgoodsdata", method = RequestMethod.POST)
    public void getGoodsData(AcceptData acceptData, Long groupId, PrintWriter out) {
        try {
            JSONObject data = userShareGoodsRecordService.getGoodsGroup(recordId, acceptData.getSystem());
            out.print(JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseResult("加载失败"));
            e.printStackTrace();
        }
    }
        if (groupId == null) {
            out.print(JsonUtil.loadFalseResult("参数不正确"));
        }
    /**
     * 获取分享商品单个统计信息
     *
     * @param acceptData
     * @param groupId
     * @param out
     */
    @RequestMapping(value = "getgoodsdata", method = RequestMethod.POST)
    public void getGoodsData(AcceptData acceptData, Long groupId, PrintWriter out) {
        try {
            UserShareGoodsGroup userShareGoodsGroup = userShareGoodsGroupService.selectByPrimaryKey(groupId);
            if (userShareGoodsGroup != null) {
                userShareGoodsGroup.setBrowseTime(null);
                userShareGoodsGroup.setCreateTime(null);
                userShareGoodsGroup.setUpdateTime(null);
                userShareGoodsGroup.setRecordId(null);
            }
        if (groupId == null) {
            out.print(JsonUtil.loadFalseResult("参数不正确"));
        }
            JSONObject data = new JSONObject();
            data.put("goodsData", userShareGoodsGroup);
            out.print(JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseResult("加载失败"));
            e.printStackTrace();
        }
    }
        try {
            UserShareGoodsGroup userShareGoodsGroup = userShareGoodsGroupService.selectByPrimaryKey(groupId);
            if (userShareGoodsGroup != null) {
                userShareGoodsGroup.setBrowseTime(null);
                userShareGoodsGroup.setCreateTime(null);
                userShareGoodsGroup.setUpdateTime(null);
                userShareGoodsGroup.setRecordId(null);
            }
    /**
     * 商品详情分享
     *
     * @param acceptData
     * @param uid
     *            用户id
     * @param auctionId
     *            商品id
     * @param type
     *            图片分享类型 单图single 多图many
     * @param out
     */
    @RequestMapping(value = "sharedetail", method = RequestMethod.POST)
    public void shareDetail(AcceptData acceptData, Long uid, Long auctionId, String type, PrintWriter out) {
        try {
            userShareGoodsRecordService.saveSingleShareRecord(uid, auctionId, Constant.SOURCE_TYPE_TAOBAO);
            out.print(JsonUtil.loadTrueResult("分享成功"));
        } catch (UserShareGoodsRecordException e) {
            out.print(JsonUtil.loadFalseResult(e.getMsg()));
            e.printStackTrace();
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseResult("加载失败"));
            e.printStackTrace();
        }
    }
            JSONObject data = new JSONObject();
            data.put("goodsData", userShareGoodsGroup);
            out.print(JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseResult("加载失败"));
            e.printStackTrace();
        }
    }
    /**
     * 更新分享记录
     *
     * @param acceptData
     * @param shareId
     * @param out
     */
    @RequestMapping(value = "updaterecord", method = RequestMethod.POST)
    public void updateRecord(AcceptData acceptData, String shareId, String type, PrintWriter out) {
        if (StringUtil.isNullOrEmpty(shareId)) {
            out.print(JsonUtil.loadFalseResult("参数不正确"));
            return;
        }
    /**
     * 商品详情分享
     *
     * @param acceptData
     * @param uid        用户id
     * @param auctionId  商品id
     * @param type       图片分享类型 单图single 多图many
     * @param out
     */
    @RequestMapping(value = "sharedetail", method = RequestMethod.POST)
    public void shareDetail(AcceptData acceptData, Long uid, Long auctionId, String type, PrintWriter out) {
        try {
            userShareGoodsRecordService.saveSingleShareRecord(uid, auctionId, Constant.SOURCE_TYPE_TAOBAO);
            out.print(JsonUtil.loadTrueResult("分享成功"));
        } catch (UserShareGoodsRecordException e) {
            out.print(JsonUtil.loadFalseResult(e.getMsg()));
            e.printStackTrace();
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseResult("加载失败"));
            e.printStackTrace();
        }
    }
        // 更新分享生效
        executor.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    userShareGoodsRecordService.takeEffectShareRecord(acceptData, shareId);
                } catch (UserShareGoodsRecordException eu) {
    /**
     * 更新分享记录
     *
     * @param acceptData
     * @param shareId
     * @param out
     */
    @RequestMapping(value = "updaterecord", method = RequestMethod.POST)
    public void updateRecord(AcceptData acceptData, String shareId, String type, PrintWriter out) {
        if (StringUtil.isNullOrEmpty(shareId)) {
            out.print(JsonUtil.loadFalseResult("参数不正确"));
            return;
        }
                } catch (Exception e) {
                    try {
                        LogHelper.errorDetailInfo(e);
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }
            }
        });
        out.print(JsonUtil.loadTrueResult("分享成功"));
    }
        // 更新分享生效
        executor.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    userShareGoodsRecordService.takeEffectShareRecord(acceptData, shareId);
                } catch (UserShareGoodsRecordException eu) {
    /**
     * 预览分享模板
     *
     * @param acceptData
     * @param uid
     * @param template
     * @param goodsId
     * @param hasCoupon
     * @param out
     */
    @RequestMapping(value = "viewShareTextTemplate", method = RequestMethod.POST)
    public void preViewShareTextTemplate(AcceptData acceptData, Long uid, String template, Long goodsId, Long tljId,
            Boolean hasCoupon, PrintWriter out) {
        if (uid == null) {
            out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
            return;
        }
                } catch (Exception e) {
                    try {
                        LogHelper.errorDetailInfo(e);
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }
            }
        });
        out.print(JsonUtil.loadTrueResult("分享成功"));
    }
    /**
     * 预览分享模板
     *
     * @param acceptData
     * @param uid
     * @param template
     * @param goodsId
     * @param hasCoupon
     * @param out
     */
    @RequestMapping(value = "viewShareTextTemplate", method = RequestMethod.POST)
    public void preViewShareTextTemplate(AcceptData acceptData, Long uid, String template, Long goodsId, Long tljId,
                                         Boolean hasCoupon, PrintWriter out) {
        if (uid == null) {
            out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
            return;
        }
        if (goodsId == null) {
            out.print(JsonUtil.loadFalseResult(3, "商品ID不能为空"));
            return;
        }
        if (goodsId == null) {
            out.print(JsonUtil.loadFalseResult(3, "商品ID不能为空"));
            return;
        }
        TaoBaoGoodsBrief goods = taoBaoGoodsCacheUtil.getCommonTaoBaoGoodsInfo(goodsId);
        if (goods == null)
            try {
                goods = redisManager.getTaoBaoGoodsBrief(goodsId);
            } catch (TaobaoGoodsDownException e) {
                goods = null;
            }
        TaoBaoGoodsBrief goods = taoBaoGoodsCacheUtil.getCommonTaoBaoGoodsInfo(goodsId);
        if (goods == null)
            try {
                goods = redisManager.getTaoBaoGoodsBrief(goodsId);
            } catch (TaobaoGoodsDownException e) {
                goods = null;
            }
        if (goods == null) {
            out.print(JsonUtil.loadFalseResult(4, "商品已下架"));
            return;
        }
        if (goods == null) {
            out.print(JsonUtil.loadFalseResult(4, "商品已下架"));
            return;
        }
        if (StringUtil.isNullOrEmpty(template))
            template = getShareTemplate(uid, hasCoupon, tljId,acceptData.getSystem());
        if (StringUtil.isNullOrEmpty(template))
            template = getShareTemplate(uid, hasCoupon, tljId, acceptData.getSystem());
        // 校验券模板是否正确
        if (hasCoupon) {
            // 有券商品
            if (tljId != null) {
                try {
                    shareGoodsTextTemplateService.isTaoLiJinTemplateRight(template);
                } catch (ShareGoodsTextTemplateException e) {
                    out.print(JsonUtil.loadFalseResult(5, e.getMsg()));
                    return;
                }
            } else {
                try {
                    shareGoodsTextTemplateService.isCouponTemplateRight(template);
                } catch (ShareGoodsTextTemplateException e) {
                    out.print(JsonUtil.loadFalseResult(5, e.getMsg()));
                    return;
                }
            }
        } else {
            // 普通商品
            try {
                shareGoodsTextTemplateService.isCommonTemplateRight(template);
            } catch (ShareGoodsTextTemplateException e) {
                out.print(JsonUtil.loadFalseResult(5, e.getMsg()));
                return;
            }
        }
        // 校验券模板是否正确
        if (hasCoupon) {
            // 有券商品
            if (tljId != null) {
                try {
                    shareGoodsTextTemplateService.isTaoLiJinTemplateRight(template);
                } catch (ShareGoodsTextTemplateException e) {
                    out.print(JsonUtil.loadFalseResult(5, e.getMsg()));
                    return;
                }
            } else {
                try {
                    shareGoodsTextTemplateService.isCouponTemplateRight(template);
                } catch (ShareGoodsTextTemplateException e) {
                    out.print(JsonUtil.loadFalseResult(5, e.getMsg()));
                    return;
                }
            }
        } else {
            // 普通商品
            try {
                shareGoodsTextTemplateService.isCommonTemplateRight(template);
            } catch (ShareGoodsTextTemplateException e) {
                out.print(JsonUtil.loadFalseResult(5, e.getMsg()));
                return;
            }
        }
        String url = null;
        if (tljId != null) {
            UserTaoLiJinRecord userTaoLiJinRecord = userTaoLiJinRecordService.selectByPrimaryKey(tljId);
            if (userTaoLiJinRecord == null) {
                out.print(JsonUtil.loadFalseResult(5, "淘礼金领取链接不存在"));
                return;
            }
            url = userTaoLiJinRecord.getSendUrl();
        } else {
            url = String.format("http://%s%s?uid=%s&id=%s&appType=flq", configService.getH5Host(acceptData.getSystem()),
                    Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY),
                    goods.getAuctionId() + "");
        }
        String url = null;
        if (tljId != null) {
            UserTaoLiJinRecord userTaoLiJinRecord = userTaoLiJinRecordService.selectByPrimaryKey(tljId);
            if (userTaoLiJinRecord == null) {
                out.print(JsonUtil.loadFalseResult(5, "淘礼金领取链接不存在"));
                return;
            }
            url = userTaoLiJinRecord.getSendUrl();
        } else {
            url = String.format("http://%s%s?uid=%s&id=%s&appType=flq", configService.getH5Host(acceptData.getSystem()),
                    Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY),
                    goods.getAuctionId() + "");
        }
        String shortLink = HttpUtil.getShortLink(url);
        String shortLink = HttpUtil.getShortLink(url);
        // 查询是否有分享
        UserShareGoodsHistory userShareHistory = shareGoodsService.getShareGoodsHistory(uid, goods.getAuctionId());
        String token = "";
        if (userShareHistory != null) {
            token = userShareHistory.getTkCode();
        }
        // 查询是否有分享
        UserShareGoodsHistory userShareHistory = shareGoodsService.getShareGoodsHistory(uid, goods.getAuctionId());
        String token = "";
        if (userShareHistory != null) {
            token = userShareHistory.getTkCode();
        }
        if (StringUtil.isNullOrEmpty(token)) {
            TaoKeAppInfo app = new TaoKeAppInfo();
            app.setAdzoneId(TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT.split("_")[3]);
            app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY);
            app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
            app.setPid(TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT);
            TaoBaoGoodsBrief goodsLink = TaoKeApiUtil.specialConvertCoupon(goods.getAuctionId(), app,null,null);
            if (goodsLink != null)
                token = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(),
                        StringUtil.isNullOrEmpty(goodsLink.getCouponLink()) ? goodsLink.getAuctionUrl()
                                : goodsLink.getCouponLink());
        }
        String content = shareGoodsTextTemplateService.createContentByTemplate(template, uid, goods, token, shortLink,
                hasCoupon, tljId);
        JSONObject data = new JSONObject();
        data.put("content", content);
        out.print(JsonUtil.loadTrueResult(data));
    }
        if (StringUtil.isNullOrEmpty(token)) {
            TaoKeAppInfo app = new TaoKeAppInfo();
            app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY);
            app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
            app.setPid(pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.share));
            app.setAdzoneId(app.getPid().split("_")[3]);
            TaoBaoGoodsBrief goodsLink = TaoKeApiUtil.specialConvertCoupon(goods.getAuctionId(), app, null, null);
            if (goodsLink != null)
                token = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(),
                        StringUtil.isNullOrEmpty(goodsLink.getCouponLink()) ? goodsLink.getAuctionUrl()
                                : goodsLink.getCouponLink());
        }
        String content = shareGoodsTextTemplateService.createContentByTemplate(template, uid, goods, token, shortLink,
                hasCoupon, tljId);
        JSONObject data = new JSONObject();
        data.put("content", content);
        out.print(JsonUtil.loadTrueResult(data));
    }
    /**
     * 保存模板
     *
     * @param acceptData
     * @param uid
     * @param hasCoupon
     * @param template
     * @param out
     */
    @RequestMapping(value = "saveShareTextTemplate", method = RequestMethod.POST)
    public void saveShareTextTemplate(AcceptData acceptData, Long uid, Long tljId, Boolean hasCoupon, String template,
            PrintWriter out) {
        if (StringUtil.isNullOrEmpty(template)) {
            out.print(JsonUtil.loadFalseResult(1, "分享模板为空"));
            return;
        }
        // 校验券模板是否正确
        if (hasCoupon) {
            // 有券商品
            if (tljId != null) {
                try {
                    shareGoodsTextTemplateService.isTaoLiJinTemplateRight(template);
                    shareGoodsTextTemplateService.saveTaoLiJinTemplate(uid, template);
                    out.print(JsonUtil.loadTrueResult(""));
                } catch (ShareGoodsTextTemplateException e) {
                    out.print(JsonUtil.loadFalseResult(5, e.getMsg()));
                    return;
                }
            } else {
                try {
                    shareGoodsTextTemplateService.isCouponTemplateRight(template);
                    shareGoodsTextTemplateService.saveCouponTemplate(uid, template);
                    out.print(JsonUtil.loadTrueResult(""));
                } catch (ShareGoodsTextTemplateException e) {
                    out.print(JsonUtil.loadFalseResult(5, e.getMsg()));
                    return;
                }
            }
        } else {
            // 普通商品
            try {
                shareGoodsTextTemplateService.isCommonTemplateRight(template);
                shareGoodsTextTemplateService.saveCommonTemplate(uid, template);
                out.print(JsonUtil.loadTrueResult(""));
            } catch (ShareGoodsTextTemplateException e) {
                out.print(JsonUtil.loadFalseResult(5, e.getMsg()));
                return;
            }
        }
    /**
     * 保存模板
     *
     * @param acceptData
     * @param uid
     * @param hasCoupon
     * @param template
     * @param out
     */
    @RequestMapping(value = "saveShareTextTemplate", method = RequestMethod.POST)
    public void saveShareTextTemplate(AcceptData acceptData, Long uid, Long tljId, Boolean hasCoupon, String template,
                                      PrintWriter out) {
        if (StringUtil.isNullOrEmpty(template)) {
            out.print(JsonUtil.loadFalseResult(1, "分享模板为空"));
            return;
        }
        // 校验券模板是否正确
        if (hasCoupon) {
            // 有券商品
            if (tljId != null) {
                try {
                    shareGoodsTextTemplateService.isTaoLiJinTemplateRight(template);
                    shareGoodsTextTemplateService.saveTaoLiJinTemplate(uid, template);
                    out.print(JsonUtil.loadTrueResult(""));
                } catch (ShareGoodsTextTemplateException e) {
                    out.print(JsonUtil.loadFalseResult(5, e.getMsg()));
                    return;
                }
            } else {
                try {
                    shareGoodsTextTemplateService.isCouponTemplateRight(template);
                    shareGoodsTextTemplateService.saveCouponTemplate(uid, template);
                    out.print(JsonUtil.loadTrueResult(""));
                } catch (ShareGoodsTextTemplateException e) {
                    out.print(JsonUtil.loadFalseResult(5, e.getMsg()));
                    return;
                }
            }
        } else {
            // 普通商品
            try {
                shareGoodsTextTemplateService.isCommonTemplateRight(template);
                shareGoodsTextTemplateService.saveCommonTemplate(uid, template);
                out.print(JsonUtil.loadTrueResult(""));
            } catch (ShareGoodsTextTemplateException e) {
                out.print(JsonUtil.loadFalseResult(5, e.getMsg()));
                return;
            }
        }
    }
    }
    /**
     * 还原模板
     *
     * @param acceptData
     * @param uid
     * @param hasCoupon
     *            -是否有券
     * @param out
     */
    @RequestMapping(value = "resetShareTextTemplate", method = RequestMethod.POST)
    public void resetShareTextTemplate(AcceptData acceptData, Long uid, Long goodsId, Long tljId, Boolean hasCoupon,
            PrintWriter out) {
        if (uid == null) {
            out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
            return;
        }
    /**
     * 还原模板
     *
     * @param acceptData
     * @param uid
     * @param hasCoupon  -是否有券
     * @param out
     */
    @RequestMapping(value = "resetShareTextTemplate", method = RequestMethod.POST)
    public void resetShareTextTemplate(AcceptData acceptData, Long uid, Long goodsId, Long tljId, Boolean hasCoupon,
                                       PrintWriter out) {
        if (uid == null) {
            out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
            return;
        }
        if (hasCoupon) {
            if (tljId != null) {
                shareGoodsTextTemplateService.resetTaoLijinTemplate(uid);
            } else {
                shareGoodsTextTemplateService.resetCouponTemplate(uid);
            }
        } else {
            shareGoodsTextTemplateService.resetCommonTemplate(uid);
        }
        if (hasCoupon) {
            if (tljId != null) {
                shareGoodsTextTemplateService.resetTaoLijinTemplate(uid);
            } else {
                shareGoodsTextTemplateService.resetCouponTemplate(uid);
            }
        } else {
            shareGoodsTextTemplateService.resetCommonTemplate(uid);
        }
        if (goodsId != null) {
            preViewShareTextTemplate(acceptData, uid, null, goodsId, tljId, hasCoupon, out);
            return;
        }
        if (goodsId != null) {
            preViewShareTextTemplate(acceptData, uid, null, goodsId, tljId, hasCoupon, out);
            return;
        }
        out.print(JsonUtil.loadTrueResult(""));
    }
        out.print(JsonUtil.loadTrueResult(""));
    }
    private String getShareTemplate(Long uid, boolean hasCoupon, Long tljId,SystemEnum system) {
        if (hasCoupon) {
            if (tljId != null) {
                String template = shareGoodsTextTemplateService.getTaoLiJinTemplate(uid);
                if (StringUtil.isNullOrEmpty(template))
                    template = configTaoLiJinService.getValueByKey("goods_share_text", new Date());
                return template;
            } else {
                String template = shareGoodsTextTemplateService.geteCouponTemplate(uid);
                if (StringUtil.isNullOrEmpty(template))
                    template = configService.getValue(ConfigKeyEnum.goodsShareTextCoupon.getKey(),system);
                return template;
            }
    private String getShareTemplate(Long uid, boolean hasCoupon, Long tljId, SystemEnum system) {
        if (hasCoupon) {
            if (tljId != null) {
                String template = shareGoodsTextTemplateService.getTaoLiJinTemplate(uid);
                if (StringUtil.isNullOrEmpty(template))
                    template = configTaoLiJinService.getValueByKey("goods_share_text", new Date());
                return template;
            } else {
                String template = shareGoodsTextTemplateService.geteCouponTemplate(uid);
                if (StringUtil.isNullOrEmpty(template))
                    template = configService.getValue(ConfigKeyEnum.goodsShareTextCoupon.getKey(), system);
                return template;
            }
        } else {
            String template = shareGoodsTextTemplateService.getCommonTemplate(uid);
            if (StringUtil.isNullOrEmpty(template))
                template = configService.getValue(ConfigKeyEnum.goodsShareTextNoCoupon.getKey(),system);
            return template;
        }
    }
        } else {
            String template = shareGoodsTextTemplateService.getCommonTemplate(uid);
            if (StringUtil.isNullOrEmpty(template))
                template = configService.getValue(ConfigKeyEnum.goodsShareTextNoCoupon.getKey(), system);
            return template;
        }
    }
    /**
     * 获取分享模板
     *
     * @param acceptData
     * @param uid
     * @param hasCoupon
     * @param out
     */
    @RequestMapping(value = "getShareTextTemplate", method = RequestMethod.POST)
    public void getShareTextTemplate(AcceptData acceptData, Long uid, Long tljId, Boolean hasCoupon, PrintWriter out) {
        if (uid == null) {
            out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
            return;
        }
    /**
     * 获取分享模板
     *
     * @param acceptData
     * @param uid
     * @param hasCoupon
     * @param out
     */
    @RequestMapping(value = "getShareTextTemplate", method = RequestMethod.POST)
    public void getShareTextTemplate(AcceptData acceptData, Long uid, Long tljId, Boolean hasCoupon, PrintWriter out) {
        if (uid == null) {
            out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
            return;
        }
        if (hasCoupon == null) {
            out.print(JsonUtil.loadFalseResult(1, "是否有券字段为空"));
            return;
        }
        if (hasCoupon == null) {
            out.print(JsonUtil.loadFalseResult(1, "是否有券字段为空"));
            return;
        }
        JSONObject data = new JSONObject();
        data.put("template", getShareTemplate(uid, hasCoupon, tljId,acceptData.getSystem()));
        out.print(JsonUtil.loadTrueResult(data));
    }
        JSONObject data = new JSONObject();
        data.put("template", getShareTemplate(uid, hasCoupon, tljId, acceptData.getSystem()));
        out.print(JsonUtil.loadTrueResult(data));
    }
    /**
     * 获取分享模板编辑规则
     *
     * @param acceptData
     * @param out
     */
    @RequestMapping(value = "getShareTextTemplateRules", method = RequestMethod.POST)
    public void getShareTextTemplateRules(AcceptData acceptData, Long tljId, PrintWriter out) {
        if (tljId != null) {
            out.print(JsonUtil.loadTrueResult(configTaoLiJinService.getValueByKey("share_goods_rules", new Date())));
        } else {
            out.print(JsonUtil.loadTrueResult(configService.getValue(ConfigKeyEnum.shareGoodsTemplateRules.getKey(),acceptData.getSystem())));
        }
    }
    /**
     * 获取分享模板编辑规则
     *
     * @param acceptData
     * @param out
     */
    @RequestMapping(value = "getShareTextTemplateRules", method = RequestMethod.POST)
    public void getShareTextTemplateRules(AcceptData acceptData, Long tljId, PrintWriter out) {
        if (tljId != null) {
            out.print(JsonUtil.loadTrueResult(configTaoLiJinService.getValueByKey("share_goods_rules", new Date())));
        } else {
            out.print(JsonUtil.loadTrueResult(configService.getValue(ConfigKeyEnum.shareGoodsTemplateRules.getKey(), acceptData.getSystem())));
        }
    }
    /**
     * 查询顶部分类
     *
     * @param acceptData
     * @param id
     * @param uid
     * @param out
     */
    @RequestMapping(value = "shareDynamic", method = RequestMethod.POST)
    public void shareDynamic(AcceptData acceptData, String id, Long uid, PrintWriter out) {
        try {
    /**
     * 查询顶部分类
     *
     * @param acceptData
     * @param id
     * @param uid
     * @param out
     */
    @RequestMapping(value = "shareDynamic", method = RequestMethod.POST)
    public void shareDynamic(AcceptData acceptData, String id, Long uid, PrintWriter out) {
        try {
            if (uid == null || uid <= 0) {
                out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
                return;
            }
            if (uid == null || uid <= 0) {
                out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
                return;
            }
            if (StringUtil.isNullOrEmpty(id)) {
                out.print(JsonUtil.loadFalseResult("参数不能为空"));
                return;
            }
            if (StringUtil.isNullOrEmpty(id)) {
                out.print(JsonUtil.loadFalseResult("参数不能为空"));
                return;
            }
            DynamicInfo dynamicInfo = dynamicInfoService.getById(id);
            if (dynamicInfo == null) {
                out.print(JsonUtil.loadFalseResult("该动态信息已不存在"));
                return;
            }
            DynamicInfo dynamicInfo = dynamicInfoService.getById(id);
            if (dynamicInfo == null) {
                out.print(JsonUtil.loadFalseResult("该动态信息已不存在"));
                return;
            }
            JSONObject data = new JSONObject();
            // 分类id
            long cid = dynamicInfo.getClassId();
            JSONObject data = new JSONObject();
            // 分类id
            long cid = dynamicInfo.getClassId();
            if (cid == 1 || cid == 2) { // 1 热销单品 2 推荐好货
                if (cid == 1) {
                    List<GoodsPicture> imgs = dynamicInfo.getImgs();
                    if (imgs == null || imgs.size() == 0) {
                        out.print(JsonUtil.loadFalseResult("该商品已下架"));
                        return;
                    }
            if (cid == 1 || cid == 2) { // 1 热销单品 2 推荐好货
                if (cid == 1) {
                    List<GoodsPicture> imgs = dynamicInfo.getImgs();
                    if (imgs == null || imgs.size() == 0) {
                        out.print(JsonUtil.loadFalseResult("该商品已下架"));
                        return;
                    }
                    GoodsPicture goodsPicture = imgs.get(0);
                    if (goodsPicture.getGoodState() == 1) {
                        out.print(JsonUtil.loadFalseResult("该商品已下架"));
                        return;
                    }
                    GoodsPicture goodsPicture = imgs.get(0);
                    if (goodsPicture.getGoodState() == 1) {
                        out.print(JsonUtil.loadFalseResult("该商品已下架"));
                        return;
                    }
                    TaoBaoGoodsBriefExtra goods = goodsPicture.getGoods();
                    if (goods == null) {
                        out.print(JsonUtil.loadFalseResult("该商品已下架"));
                        return;
                    }
                    TaoBaoGoodsBriefExtra goods = goodsPicture.getGoods();
                    if (goods == null) {
                        out.print(JsonUtil.loadFalseResult("该商品已下架"));
                        return;
                    }
                    if (goods.getState() != null && goods.getState() == 1) {
                        out.print(JsonUtil.loadFalseResult("该商品已下架"));
                        return;
                    }
                    if (goods.getState() != null && goods.getState() == 1) {
                        out.print(JsonUtil.loadFalseResult("该商品已下架"));
                        return;
                    }
                    if (!goods.isCoupon()) {
                        out.print(JsonUtil.loadFalseResult("该商品已下架"));
                        return;
                    }
                    if (!goods.isCoupon()) {
                        out.print(JsonUtil.loadFalseResult("该商品已下架"));
                        return;
                    }
                    try {
                        TaoKeApiUtil.getSimpleGoodsInfo(goods.getAuctionId());
                    } catch (TaobaoGoodsDownException e) {
                        out.print(JsonUtil.loadFalseResult("该商品已下架"));
                        return;
                    }
                    try {
                        TaoKeApiUtil.getSimpleGoodsInfo(goods.getAuctionId());
                    } catch (TaobaoGoodsDownException e) {
                        out.print(JsonUtil.loadFalseResult("该商品已下架"));
                        return;
                    }
                } else {
                    List<GoodsPicture> imgs = dynamicInfo.getImgs();
                    if (imgs == null || imgs.size() == 0) {
                        out.print(JsonUtil.loadFalseResult("所有商品已抢光"));
                        return;
                    }
                } else {
                    List<GoodsPicture> imgs = dynamicInfo.getImgs();
                    if (imgs == null || imgs.size() == 0) {
                        out.print(JsonUtil.loadFalseResult("所有商品已抢光"));
                        return;
                    }
                    int count = 0;
                    for (GoodsPicture goodsPicture : imgs) {
                        if (goodsPicture.getGoodState() == 1) {
                            count++;
                            continue;
                        }
                    int count = 0;
                    for (GoodsPicture goodsPicture : imgs) {
                        if (goodsPicture.getGoodState() == 1) {
                            count++;
                            continue;
                        }
                        TaoBaoGoodsBriefExtra goods = goodsPicture.getGoods();
                        if (goods == null) {
                            count++;
                            continue;
                        }
                        TaoBaoGoodsBriefExtra goods = goodsPicture.getGoods();
                        if (goods == null) {
                            count++;
                            continue;
                        }
                        if (goods.getState() != null && goods.getState() == 1) {
                            count++;
                            continue;
                        }
                        if (goods.getState() != null && goods.getState() == 1) {
                            count++;
                            continue;
                        }
                        if (!goods.isCoupon()) {
                            count++;
                            continue;
                        }
                    }
                        if (!goods.isCoupon()) {
                            count++;
                            continue;
                        }
                    }
                    if (count >= imgs.size()) {
                        out.print(JsonUtil.loadFalseResult("所有商品已抢光"));
                        return;
                    }
                }
                    if (count >= imgs.size()) {
                        out.print(JsonUtil.loadFalseResult("所有商品已抢光"));
                        return;
                    }
                }
                // 分享文字
                String title = null;
                List<ClientTextStyleVO> listTitle = dynamicInfo.getTitle();
                if (listTitle != null && listTitle.size() > 0) {
                    title = "";
                    for (ClientTextStyleVO textStyleVO : listTitle) {
                        title += textStyleVO.getContent();
                    }
                }
                // 分享文字
                String title = null;
                List<ClientTextStyleVO> listTitle = dynamicInfo.getTitle();
                if (listTitle != null && listTitle.size() > 0) {
                    title = "";
                    for (ClientTextStyleVO textStyleVO : listTitle) {
                        title += textStyleVO.getContent();
                    }
                }
                if (StringUtil.isNullOrEmpty(title)) {
                    title = "给你推荐精选好物优惠券,购物前先领券,别错过优惠哦~";
                }
                data.put("title", title);
                data.put("content", String.format("我在%s发现了一个很好的商品,快来看看~",
                        Constant.getAppName(acceptData.getPlatform(), acceptData.getVersion())));
                if (StringUtil.isNullOrEmpty(title)) {
                    title = "给你推荐精选好物优惠券,购物前先领券,别错过优惠哦~";
                }
                data.put("title", title);
                data.put("content", String.format("我在%s发现了一个很好的商品,快来看看~",
                        Constant.getAppName(acceptData.getPlatform(), acceptData.getVersion())));
                // 分享奖金
                ClientTextStyleVO desc = dynamicInfo.getDesc();
                String content = desc.getContent();
                int index = content.indexOf("¥");
                data.put("shareMoney", new BigDecimal(content.substring(index + 1, content.length())).toString());
                // 分享奖金
                ClientTextStyleVO desc = dynamicInfo.getDesc();
                String content = desc.getContent();
                int index = content.indexOf("¥");
                data.put("shareMoney", new BigDecimal(content.substring(index + 1, content.length())).toString());
                // 分享提醒
                data.put("notifyDesc", configService.getValue(ConfigKeyEnum.goodsShareNotify.getKey(),acceptData.getSystem()));
                // 分享提醒
                data.put("notifyDesc", configService.getValue(ConfigKeyEnum.goodsShareNotify.getKey(), acceptData.getSystem()));
                // 分享提示语
                String imgs = configService.getValue(ConfigKeyEnum.goodsShareNotifyImgs.getKey(),acceptData.getSystem());
                JSONArray array = JSONArray.fromObject(imgs);
                int p = (int) (array.size() * Math.random());
                if (p < array.size()) {
                    data.put("notifyPicture", array.optString(p));
                }
                // 分享提示语
                String imgs = configService.getValue(ConfigKeyEnum.goodsShareNotifyImgs.getKey(), acceptData.getSystem());
                JSONArray array = JSONArray.fromObject(imgs);
                int p = (int) (array.size() * Math.random());
                if (p < array.size()) {
                    data.put("notifyPicture", array.optString(p));
                }
                // 分享出去的图片
                String pictUrl = dynamicInfo.getImgs().get(0).getUrl();
                data.put("pictUrl", TbImgUtil.getTBSizeImg(pictUrl, 500));
                // 分享出去的图片
                String pictUrl = dynamicInfo.getImgs().get(0).getUrl();
                data.put("pictUrl", TbImgUtil.getTBSizeImg(pictUrl, 500));
                // 帮助链接
                data.put("helpLink",
                        "http://apph5.banliapp.com/apppage/all_help_content.html?id=148&from=singlemessage&isappinstalled=0");
                // 帮助链接
                data.put("helpLink",
                        "http://apph5.banliapp.com/apppage/all_help_content.html?id=148&from=singlemessage&isappinstalled=0");
                if (cid == 2) { // 2 推荐好货
                    ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordDynamic(uid,
                            dynamicInfo.getListGoodsBrief());
                    data.put("shareId", shareRecord.getRedisKey());
                    data.put("clickUrl", shareRecord.getShareUrl());
                } else {
                    // 分享id
                    ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordDynamic(uid,
                            dynamicInfo.getListGoodsBrief());
                    data.put("shareId", shareRecord.getRedisKey());
                if (cid == 2) { // 2 推荐好货
                    ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordDynamic(uid,
                            dynamicInfo.getListGoodsBrief());
                    data.put("shareId", shareRecord.getRedisKey());
                    data.put("clickUrl", shareRecord.getShareUrl());
                } else {
                    // 分享id
                    ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordDynamic(uid,
                            dynamicInfo.getListGoodsBrief());
                    data.put("shareId", shareRecord.getRedisKey());
                    Long auctionId = dynamicInfo.getImgs().get(0).getGoods().getAuctionId();
                    // 商品分享链接
                    String url = String.format("http://%s%s?uid=%s&id=%s&appType=flq", configService.getH5Host(acceptData.getSystem()),
                            Constant.systemCommonConfig.getShareGoodsPagePath(),
                            AESUtil.encrypt(uid + "", Constant.UIDAESKEY), auctionId + "");
                    String shortLink = HttpUtil.getShortLink(url);
                    if (!StringUtil.isNullOrEmpty(shortLink)) {
                        url = shortLink;
                    }
                    Long auctionId = dynamicInfo.getImgs().get(0).getGoods().getAuctionId();
                    // 商品分享链接
                    String url = String.format("http://%s%s?uid=%s&id=%s&appType=flq", configService.getH5Host(acceptData.getSystem()),
                            Constant.systemCommonConfig.getShareGoodsPagePath(),
                            AESUtil.encrypt(uid + "", Constant.UIDAESKEY), auctionId + "");
                    String shortLink = HttpUtil.getShortLink(url);
                    if (!StringUtil.isNullOrEmpty(shortLink)) {
                        url = shortLink;
                    }
                    data.put("clickUrl", url);
                    data.put("clickUrl", url);
                    // 淘宝口令
                    UserExtraTaoBaoInfo extraInfo = userExtraTaoBaoInfoService.getByUid(uid);
                    String relationId = null;
                    if (extraInfo != null && extraInfo.getRelationId() != null && extraInfo.getRelationValid() != null
                            && extraInfo.getRelationValid() == true) {
                        relationId = extraInfo.getRelationId();
                    }
                    TaoBaoLink taoBaoLink = taoBaoLinkManager.getTaoBaoLinkForShare(uid, auctionId, relationId,null);
                    TaoBaoGoodsBrief goods = taoBaoLink.getGoods();
                    if (!com.yeshi.fanli.util.VersionUtil.greaterThan_2_0_2(acceptData.getPlatform(),
                            acceptData.getVersion()))
                        data.put("clickUrl",
                                ShareControllerV2.getERCodeContentNew(
                                        configService.getValue(ConfigKeyEnum.taobaoShareQrcodeText.getKey(),acceptData.getSystem()), goods,
                                        taoBaoLink.getTaoToken()));
                    // 淘宝口令
                    UserExtraTaoBaoInfo extraInfo = userExtraTaoBaoInfoService.getByUid(uid);
                    String relationId = null;
                    if (extraInfo != null && extraInfo.getRelationId() != null && extraInfo.getRelationValid() != null
                            && extraInfo.getRelationValid() == true) {
                        relationId = extraInfo.getRelationId();
                    }
                    TaoBaoLink taoBaoLink = taoBaoLinkManager.getTaoBaoLinkForShare(acceptData.getSystem(), uid, auctionId, relationId, null);
                    TaoBaoGoodsBrief goods = taoBaoLink.getGoods();
                    if (!com.yeshi.fanli.util.VersionUtil.greaterThan_2_0_2(acceptData.getPlatform(),
                            acceptData.getVersion()))
                        data.put("clickUrl",
                                ShareControllerV2.getERCodeContentNew(
                                        configService.getValue(ConfigKeyEnum.taobaoShareQrcodeText.getKey(), acceptData.getSystem()), goods,
                                        taoBaoLink.getTaoToken()));
                    data.put("token", TaoBaoUtil.filterTaoToken(taoBaoLink.getTaoToken()));
                    data.put("token", TaoBaoUtil.filterTaoToken(taoBaoLink.getTaoToken()));
                    String inviteCode = userInfoExtraService.getInviteCodeByUid(uid);
                    // 测试
                    List<String> commentTexts = new ArrayList<>();
                    String commentTextStr = configService.getValue(ConfigKeyEnum.shareSingleGoodsCommentText.getKey(),acceptData.getSystem());
                    if (!StringUtil.isNullOrEmpty(commentTextStr)) {
                        JSONArray arr = JSONArray.fromObject(commentTextStr);
                        for (int i = 0; i < arr.size(); i++) {
                            if (StringUtil.isNullOrEmpty(inviteCode)) {
                                if (arr.optString(i).contains("[邀请码]")) {
                                    continue;
                                }
                            }
                            if (StringUtil.isNullOrEmpty(inviteCode))
                                commentTexts.add(arr.optString(i).replace("[下载链接]", Constant.YINGYONGBAO_LINK)
                                        .replace("[淘口令]", data.optString("token")));
                            else
                                commentTexts.add(arr.optString(i).replace("[下载链接]", Constant.YINGYONGBAO_LINK)
                                        .replace("[邀请码]", inviteCode).replace("[淘口令]", data.optString("token")));
                        }
                    }
                    data.put("commentTexts", commentTexts);
                    data.put("wxErCode",
                            ShareControllerV2.getERCodeContentNew(
                                    configService.getValue(ConfigKeyEnum.taobaoShareQrcodeText.getKey(),acceptData.getSystem()), goods,
                                    taoBaoLink.getTaoToken()));
                }
                    String inviteCode = userInfoExtraService.getInviteCodeByUid(uid);
                    // 测试
                    List<String> commentTexts = new ArrayList<>();
                    String commentTextStr = configService.getValue(ConfigKeyEnum.shareSingleGoodsCommentText.getKey(), acceptData.getSystem());
                    if (!StringUtil.isNullOrEmpty(commentTextStr)) {
                        JSONArray arr = JSONArray.fromObject(commentTextStr);
                        for (int i = 0; i < arr.size(); i++) {
                            if (StringUtil.isNullOrEmpty(inviteCode)) {
                                if (arr.optString(i).contains("[邀请码]")) {
                                    continue;
                                }
                            }
                            if (StringUtil.isNullOrEmpty(inviteCode))
                                commentTexts.add(arr.optString(i).replace("[下载链接]", Constant.YINGYONGBAO_LINK)
                                        .replace("[淘口令]", data.optString("token")));
                            else
                                commentTexts.add(arr.optString(i).replace("[下载链接]", Constant.YINGYONGBAO_LINK)
                                        .replace("[邀请码]", inviteCode).replace("[淘口令]", data.optString("token")));
                        }
                    }
                    data.put("commentTexts", commentTexts);
                    data.put("wxErCode",
                            ShareControllerV2.getERCodeContentNew(
                                    configService.getValue(ConfigKeyEnum.taobaoShareQrcodeText.getKey(), acceptData.getSystem()), goods,
                                    taoBaoLink.getTaoToken()));
                }
            } else if (cid == 4) { // 邀请分享
            } else if (cid == 4) { // 邀请分享
                String inviteCode = userInfoExtraService.getInviteCodeByUid(uid);
                if (StringUtil.isNullOrEmpty(inviteCode)) {
                    out.print(JsonUtil.loadFalseResult(9001, "邀请码未激活"));
                    return;
                }
                String inviteCode = userInfoExtraService.getInviteCodeByUid(uid);
                if (StringUtil.isNullOrEmpty(inviteCode)) {
                    out.print(JsonUtil.loadFalseResult(9001, "邀请码未激活"));
                    return;
                }
                Integer showType = dynamicInfo.getShowType();
                if (showType == 0) { // 无图分享
                    String title = null;
                    List<ClientTextStyleVO> listTitle = dynamicInfo.getTitle();
                    if (listTitle != null && listTitle.size() > 0) {
                        title = "";
                        for (ClientTextStyleVO textStyleVO : listTitle) {
                            title += textStyleVO.getContent();
                        }
                    }
                    title = title.replace("【邀请码】", inviteCode);
                    title = title.replace("【邀请链接】", Constant.YINGYONGBAO_LINK);
                    data.put("title", title);
                Integer showType = dynamicInfo.getShowType();
                if (showType == 0) { // 无图分享
                    String title = null;
                    List<ClientTextStyleVO> listTitle = dynamicInfo.getTitle();
                    if (listTitle != null && listTitle.size() > 0) {
                        title = "";
                        for (ClientTextStyleVO textStyleVO : listTitle) {
                            title += textStyleVO.getContent();
                        }
                    }
                    title = title.replace("【邀请码】", inviteCode);
                    title = title.replace("【邀请链接】", Constant.YINGYONGBAO_LINK);
                    data.put("title", title);
                } else { // 有图分享
                    List<GoodsPicture> imgs = dynamicInfo.getImgs();
                } else { // 有图分享
                    List<GoodsPicture> imgs = dynamicInfo.getImgs();
                    GoodsPicture goodsPicture = imgs.get(0);
                    String bgUrl = goodsPicture.getUrlOriginal();
                    GoodsPicture goodsPicture = imgs.get(0);
                    String bgUrl = goodsPicture.getUrlOriginal();
                    if (StringUtil.isNullOrEmpty(bgUrl)) {
                        out.print(JsonUtil.loadFalseResult("图片路径不存在"));
                        return;
                    }
                    if (StringUtil.isNullOrEmpty(bgUrl)) {
                        out.print(JsonUtil.loadFalseResult("图片路径不存在"));
                        return;
                    }
                    // 用户信息
                    UserInfo userInfo = userInfoService.selectByPKey(uid);
                    String portrait = userInfo.getPortrait();
                    // 画邀请图片
                    // 用户信息
                    UserInfo userInfo = userInfoService.selectByPKey(uid);
                    String portrait = userInfo.getPortrait();
                    // 画邀请图片
                    Long activityId = dynamicInfo.getActivityId();
                    if (activityId != null) {
                        Integer pX = goodsPicture.getPx();
                        ;
                        Integer pY = goodsPicture.getPy();
                        ;
                        Integer size = goodsPicture.getSize();
                    Long activityId = dynamicInfo.getActivityId();
                    if (activityId != null) {
                        Integer pX = goodsPicture.getPx();
                        ;
                        Integer pY = goodsPicture.getPy();
                        ;
                        Integer size = goodsPicture.getSize();
                        String imgLink = spreadUserImgService.drawInviteQrCodeNew(bgUrl, uid, portrait, pX, pY, size,
                                inviteCode);
                        String imgLink = spreadUserImgService.drawInviteQrCodeNew(bgUrl, uid, portrait, pX, pY, size,
                                inviteCode);
                        data.put("imgLink", imgLink);
                    } else {
                        String title = imgs.get(0).getTitleOriginal();
                        String imgLink = spreadUserImgService.getInviteImgToGreet(bgUrl, uid, portrait, inviteCode,
                                title, new Date());
                        data.put("imgLink", imgLink);
                    }
                        data.put("imgLink", imgLink);
                    } else {
                        String title = imgs.get(0).getTitleOriginal();
                        String imgLink = spreadUserImgService.getInviteImgToGreet(bgUrl, uid, portrait, inviteCode,
                                title, new Date());
                        data.put("imgLink", imgLink);
                    }
                    // 邀请规则
                    BusinessSystem system = new BusinessSystem();
                    system.setCreatetime(java.lang.System.currentTimeMillis());
                    system.setPlatform(1);
                    system.setId(4L);
                    String key = "inviteRules"; // key值
                    SystemClientParams values = systemClientParamsService.getSystemClientParamsBySystemAndKey(system,
                            key);
                    String valueN = values.getValue();
                    String valueBr = valueN.replace("\n", "<br><br>");
                    data.put("inviteRules", valueBr);
                    // 邀请规则
                    BusinessSystem system = new BusinessSystem();
                    system.setCreatetime(java.lang.System.currentTimeMillis());
                    system.setPlatform(1);
                    system.setId(4L);
                    String key = "inviteRules"; // key值
                    SystemClientParams values = systemClientParamsService.getSystemClientParamsBySystemAndKey(system,
                            key);
                    String valueN = values.getValue();
                    String valueBr = valueN.replace("\n", "<br><br>");
                    data.put("inviteRules", valueBr);
                    data.put("inviteLink", Constant.YINGYONGBAO_LINK);
                    data.put("inviteCode", inviteCode);
                    data.put("helpLink", configService.getValue(ConfigKeyEnum.inviteHelpLink.getKey(),acceptData.getSystem()));
                }
            }
            out.print(JsonUtil.loadTrueResult(data));
                    data.put("inviteLink", Constant.YINGYONGBAO_LINK);
                    data.put("inviteCode", inviteCode);
                    data.put("helpLink", configService.getValue(ConfigKeyEnum.inviteHelpLink.getKey(), acceptData.getSystem()));
                }
            }
            out.print(JsonUtil.loadTrueResult(data));
            // 更新分享次数
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    Integer shareCount = dynamicInfo.getShareCount();
                    dynamicInfo.setShareCount(shareCount + 1);
                    dynamicInfoService.updateShareCount(dynamicInfo);
                }
            });
            // 更新分享次数
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    Integer shareCount = dynamicInfo.getShareCount();
                    dynamicInfo.setShareCount(shareCount + 1);
                    dynamicInfoService.updateShareCount(dynamicInfo);
                }
            });
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseResult("分享记录失败"));
            try {
                LogHelper.errorDetailInfo(e);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
    }
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseResult("分享记录失败"));
            try {
                LogHelper.errorDetailInfo(e);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
    }
}
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/UserInfoController.java
@@ -19,7 +19,9 @@
import javax.servlet.http.HttpServletRequest;
import com.yeshi.fanli.entity.SystemFunction;
import com.yeshi.fanli.entity.SystemPIDInfo;
import com.yeshi.fanli.service.inter.pdd.PDDAuthService;
import com.yeshi.fanli.service.manger.PIDManager;
import com.yeshi.fanli.util.*;
import com.yeshi.fanli.util.GsonUtil;
import com.yeshi.fanli.util.StringUtil;
@@ -258,6 +260,9 @@
    @Resource
    private PDDAuthService pddAuthService;
    @Resource
    private PIDManager pidManager;
    private static final String EXTRACT_MIN_MONEY = ConfigKeyEnum.extractMoneyMin.getKey();
    private static final String EXTRACT_MAX_MONEY = ConfigKeyEnum.extractMoneyMAX.getKey();
@@ -2274,8 +2279,8 @@
            data.put("user", JsonUtil.getConvertBigDecimalToStringBuilder(gsonBuilder).create().toJson(userInfo));
            //拼多多是否绑定
            if (VersionUtil.greaterThan_2_1_5(acceptData.getPlatform(), acceptData.getVersion())) {
                boolean pddBuyBind = PinDuoDuoApiUtil.isAuth(PinDuoDuoApiUtil.PID_FANLI, pddAuthService.getFanliCustomParams(uid));
                boolean pddShareBind = PinDuoDuoApiUtil.isAuth(PinDuoDuoApiUtil.PID_SHARE, pddAuthService.getFanliCustomParams(uid));
                boolean pddBuyBind = PinDuoDuoApiUtil.isAuth(pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_PDD, SystemPIDInfo.PidType.fanli), pddAuthService.getFanliCustomParams(uid));
                boolean pddShareBind = PinDuoDuoApiUtil.isAuth(pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_PDD, SystemPIDInfo.PidType.share), pddAuthService.getFanliCustomParams(uid));
                data.put("pddBuyBind", pddBuyBind);
                data.put("pddShareBind", pddShareBind);
            }
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/ConfigControllerV2.java
@@ -8,6 +8,9 @@
import javax.annotation.Resource;
import com.yeshi.fanli.entity.SystemEnum;
import com.yeshi.fanli.entity.SystemPIDInfo;
import com.yeshi.fanli.service.manger.PIDManager;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@@ -104,6 +107,9 @@
    @Resource
    private RedisManager redisManager;
    @Resource
    private PIDManager pidManager;
    /**
     * s 首页配置信息
@@ -459,17 +465,19 @@
     */
    @RequestMapping(value = "getElemeLink")
    public void getElemeLink(AcceptData acceptData, Long uid, String callback, PrintWriter out) {
        UserExtraTaoBaoInfo userInfoExtra = userExtraTaoBaoInfoService.getByUid(uid);
        if (userInfoExtra == null || StringUtil.isNullOrEmpty(userInfoExtra.getRelationId())) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult(1001, "请绑定淘宝")));
            return;
        }
        String elmePid = pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_ELME, SystemPIDInfo.PidType.fanli);
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.elmeLink, uid + "");
        String elmeLink = redisManager.getCommonString(key);
        if (StringUtil.isNullOrEmpty(elmeLink)) {
            TaoKeOfficialActivityConvertResultDTO dto = TaoKeApiUtil.officialActivityConvert(
                    TaoBaoConstant.TAOBAO_ELEME_PID.split("_")[3], "1571715733668", userInfoExtra.getRelationId());
                    elmePid.split("_")[3], "1571715733668", userInfoExtra.getRelationId());
            if (dto != null)
                elmeLink = dto.getShort_click_url();
            if (!StringUtil.isNullOrEmpty(elmeLink)) {
@@ -487,8 +495,8 @@
        data.put("hongBao", elmeLink);
        data.put("goods", elmeLink);
        ClientTBPid clientTBPid1 = new ClientTBPid(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_ELEME_PID,
                null, TaoBaoConstant.TAOBAO_ELEME_PID.split("_")[3]);
        ClientTBPid clientTBPid1 = new ClientTBPid(TaoBaoConstant.TAOBAO_AUTH_APPKEY, elmePid,
                null, elmePid.split("_")[3]);
        data.put("taoKeParams", clientTBPid1);
        if (StringUtil.isNullOrEmpty(callback))
            out.print(JsonUtil.loadTrueResult(data));
@@ -516,16 +524,20 @@
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult(1001, "请绑定淘宝")));
            return;
        }
        String elmePid = pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_ELME, SystemPIDInfo.PidType.fanli);
        String relationPid = pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.share);
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.elmeLink, uid + "-" + activityId + "-" + share);
        String elmeResult = redisManager.getCommonString(key);
        JSONObject data = new JSONObject();
        TaoKeOfficialActivityConvertResultDTO dto = null;
        if (StringUtil.isNullOrEmpty(elmeResult)) {
            if (share) {
                dto = TaoKeApiUtil.officialActivityConvert(TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT.split("_")[3],
                dto = TaoKeApiUtil.officialActivityConvert(relationPid.split("_")[3],
                        activityId, userInfoExtra.getRelationId());
            } else {
                dto = TaoKeApiUtil.officialActivityConvert(TaoBaoConstant.TAOBAO_ELEME_PID.split("_")[3], activityId,
                dto = TaoKeApiUtil.officialActivityConvert(elmePid.split("_")[3], activityId,
                        userInfoExtra.getRelationId());
            }
@@ -572,8 +584,8 @@
        data.put("info", info);
        ClientTBPid clientTBPid1 = new ClientTBPid(TaoBaoConstant.TAOBAO_AUTH_APPKEY,
                share ? TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT : TaoBaoConstant.TAOBAO_ELEME_PID, null,
                TaoBaoConstant.TAOBAO_ELEME_PID.split("_")[3]);
                share ? relationPid : elmePid, null,
                elmePid.split("_")[3]);
        clientTBPid1.setAdZoneId(clientTBPid1.getPid().split("_")[3]);
        data.put("taoKeParams", clientTBPid1);
        if (StringUtil.isNullOrEmpty(callback))
@@ -586,6 +598,8 @@
    public void getKouBeiLink(AcceptData acceptData, Long uid, String activityId, boolean share, boolean shareImg,
                              String callback, PrintWriter out) {
        String relationPid = pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.share);
        UserExtraTaoBaoInfo userInfoExtra = userExtraTaoBaoInfoService.getByUid(uid);
        if (userInfoExtra == null || StringUtil.isNullOrEmpty(userInfoExtra.getRelationId())) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult(1001, "请绑定淘宝")));
@@ -597,7 +611,7 @@
        TaoKeOfficialActivityConvertResultDTO dto = null;
        if (StringUtil.isNullOrEmpty(elmeResult)) {
            if (share) {
                dto = TaoKeApiUtil.officialActivityConvert(TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT.split("_")[3],
                dto = TaoKeApiUtil.officialActivityConvert(relationPid.split("_")[3],
                        activityId, userInfoExtra.getRelationId());
            } else {
                dto = TaoKeApiUtil.officialActivityConvert(TaoBaoConstant.TAOBAO_KOUBEI_PID.split("_")[3], activityId,
@@ -647,7 +661,7 @@
        data.put("info", info);
        ClientTBPid clientTBPid1 = new ClientTBPid(TaoBaoConstant.TAOBAO_AUTH_APPKEY,
                share ? TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT : TaoBaoConstant.TAOBAO_KOUBEI_PID, null,
                share ? relationPid : TaoBaoConstant.TAOBAO_KOUBEI_PID, null,
                TaoBaoConstant.TAOBAO_KOUBEI_PID.split("_")[3]);
        clientTBPid1.setAdZoneId(clientTBPid1.getPid().split("_")[3]);
        data.put("taoKeParams", clientTBPid1);
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/ConvertLinkController.java
@@ -243,7 +243,7 @@
        try {
            String key = RedisKeyEnum.convertLinkDocResultTemp.getKey() + uid + "-"
                    + StringUtil.Md5(UUID.randomUUID().toString());
            String result = convertLinkManager.convertLinkFromText(text, uid, true,true);
            String result = convertLinkManager.convertLinkFromText(acceptData.getSystem(),text, uid, true,true);
            redisManager.cacheCommonString(key, result, 60);
            JSONObject data = new JSONObject();
            data.put("id", key);
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/DynamicControllerV2.java
@@ -19,7 +19,9 @@
import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
import com.yeshi.fanli.entity.SystemEnum;
import com.yeshi.fanli.entity.SystemFunction;
import com.yeshi.fanli.entity.SystemPIDInfo;
import com.yeshi.fanli.exception.taobao.TaoBaoConvertLinkException;
import com.yeshi.fanli.service.manger.PIDManager;
import com.yeshi.fanli.service.manger.goods.TaoBaoLinkManager;
import com.yeshi.fanli.util.*;
import com.yeshi.fanli.util.StringUtil;
@@ -143,16 +145,15 @@
    private ConvertLinkManager convertLinkManager;
    @Resource
    private ShareGoodsService shareGoodsService;
    @Resource
    private DailyCountMomentsService dailyCountMomentsService;
    @Resource
    private CommonShareInfoService commonShareInfoService;
    @Resource
    private UserCloudService userCloudService;
    private PIDManager pidManager;
    @Resource(name = "taskExecutor")
    private TaskExecutor executor;
@@ -998,7 +999,7 @@
        if (goodsVO.getGoodsType() == Constant.SOURCE_TYPE_TAOBAO) {
            TaoBaoLink taoBaoLink = null;
            try {
                taoBaoLink = taoBaoLinkManager.getTaoBaoLinkForShare(user.getId(), Long.parseLong(goodsVO.getGoodsId()),
                taoBaoLink = taoBaoLinkManager.getTaoBaoLinkForShare(system,user.getId(), Long.parseLong(goodsVO.getGoodsId()),
                        relationId, null);
            } catch (TaoBaoConvertLinkException e) {
                e.printStackTrace();
@@ -1018,7 +1019,7 @@
                couponUrl = couponInfo.getLink();
            }
            String materialId = "https://item.jd.com/" + goodsVO.getGoodsId() + ".html";
            jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, null, JDApiUtil.POSITION_SHARE + "",
            jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, null,  pidManager.getPidCache(system, Constant.SOURCE_TYPE_JD, SystemPIDInfo.PidType.share),
                    user.getId() + "");
        } else if (goodsVO.getGoodsType() == Constant.SOURCE_TYPE_PDD) {
            PDDGoodsDetail pddGoodsDetail = PinDuoDuoApiUtil.getGoodsDetail(Long.parseLong(goodsVO.getGoodsId()));
@@ -1026,8 +1027,7 @@
                return null;
            }
            jumpLink = PinDuoDuoApiUtil.getPromotionUrl(pddGoodsDetail.getGoodsSign(),
                    PinDuoDuoApiUtil.PID_SHARE + "", user.getId() + "");
            jumpLink = PinDuoDuoApiUtil.getPromotionUrl(pddGoodsDetail.getGoodsSign(), pidManager.getPidCache(system, Constant.SOURCE_TYPE_PDD, SystemPIDInfo.PidType.share), user.getId() + "");
        }
        FileUploadResult uploadResult = qrCodeService.drawDynamicGoodsPoster(jumpLink, user.getPortrait(), inviteCode,
@@ -1097,7 +1097,7 @@
        String newText = text; // 非通用券需要验证
        if (comment != null && (comment.getNeedSpin() == null || comment.getNeedSpin())) {
            try {
                newText = convertLinkManager.convertLinkFromText(text, uid, true, true);
                newText = convertLinkManager.convertLinkFromText(acceptData.getSystem(), text, uid, true, true);
            } catch (ConvertLinkExceptionException e) {
                if (e.getCode() != ConvertLinkExceptionException.CODE_NONE) {
                    out.print(JsonUtil.loadFalseResult("评论生成失败"));
@@ -1181,7 +1181,7 @@
        String newText = text;
        if (shareInfo.getNeedSpin() != null && shareInfo.getNeedSpin()) {
            try {
                newText = convertLinkManager.convertLinkFromText(text, uid, true, true);
                newText = convertLinkManager.convertLinkFromText(acceptData.getSystem(), text, uid, true, true);
            } catch (ConvertLinkExceptionException e) {
                if (e.getCode() != ConvertLinkExceptionException.CODE_NONE) {
                    out.print(JsonUtil.loadFalseResult("评论生成失败"));
@@ -1376,7 +1376,7 @@
        String newText = text;
        if (shareInfo.getNeedSpin() != null && shareInfo.getNeedSpin()) {
            try {
                newText = convertLinkManager.convertLinkFromText(text, uid, true, true);
                newText = convertLinkManager.convertLinkFromText(acceptData.getSystem(), text, uid, true, true);
            } catch (ConvertLinkExceptionException e) {
                if (e.getCode() != ConvertLinkExceptionException.CODE_NONE) {
                    JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("评论生成失败"));
@@ -1508,7 +1508,7 @@
        if (shareInfo.getNeedSpin() != null && shareInfo.getNeedSpin()) {
            try {
                String erCodeContent = "";
                newText = convertLinkManager.convertLinkFromText(text, uid, true, true);
                newText = convertLinkManager.convertLinkFromText(acceptData.getSystem(), text, uid, true, true);
                // 获取口令
                List<String> tokenList = TaoBaoUtil.getTokenListFromTextWithKuoHao(newText);
                if (tokenList != null && tokenList.size() > 0) {
@@ -1605,7 +1605,7 @@
        String newText = text; // 非通用券需要验证
        if (comment != null && (comment.getNeedSpin() == null || comment.getNeedSpin())) {
            try {
                newText = convertLinkManager.convertLinkFromText(text, uid, true, true);
                newText = convertLinkManager.convertLinkFromText(acceptData.getSystem(), text, uid, true, true);
            } catch (ConvertLinkExceptionException e) {
                if (e.getCode() != ConvertLinkExceptionException.CODE_NONE) {
                    JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("评论生成失败"));
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/GoodsControllerV2.java
@@ -14,10 +14,12 @@
import com.yeshi.fanli.entity.SystemEnum;
import com.yeshi.fanli.entity.SystemFunction;
import com.yeshi.fanli.entity.SystemPIDInfo;
import com.yeshi.fanli.exception.pdd.PDDApiException;
import com.yeshi.fanli.lijin.manager.GoodsLijinMnager;
import com.yeshi.fanli.service.inter.pdd.PDDAuthService;
import com.yeshi.fanli.service.inter.user.tb.UserExtraTaoBaoInfoService;
import com.yeshi.fanli.service.manger.PIDManager;
import com.yeshi.fanli.util.*;
import com.yeshi.fanli.vo.common.WXXCXJumpInfoVO;
import com.yeshi.fanli.vo.pdd.PDDConvertLinkResultVO;
@@ -221,6 +223,9 @@
    @Resource
    private GoodsLijinMnager goodsLijinMnager;
    @Resource
    private PIDManager pidManager;
    private GoodsMoneyConfigParamsDTO getParamsDTO(String platform, String version, Long uid, SystemEnum system) {
        UserLevelEnum level = UserLevelEnum.daRen;
        if (uid != null && uid > 0) {
@@ -236,7 +241,10 @@
        return orderHongBaoMoneyComputeService.getShowComputeRate(platform, version, level, system);
    }
    private TaoBaoGoodsBrief filterDaTaoKeGoodsInfo(TaoBaoGoodsBrief goods) {
    private TaoBaoGoodsBrief filterDaTaoKeGoodsInfo(SystemEnum system, TaoBaoGoodsBrief goods) {
        String specialPid = pidManager.getPidCache(system, Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.fanli);
        String relationPid = pidManager.getPidCache(system, Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.fanliChannel);
        try {
            DaTaoKeFilterResult result = daTaoKeGoodsDetailV2Service.filterTaoBaoGoods(goods);
            if (result.getFilterType() == DaTaoKeFilterResult.FILTER_TYPE_COUPON
@@ -244,9 +252,9 @@
                // 缓存基础链接
                String dpid = null;
                if (TaoBaoUtil.isSpecialGoods(goods.getMaterialLibType())) {
                    dpid = TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT;
                    dpid = specialPid;
                } else {
                    dpid = TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID;
                    dpid = relationPid;
                }
                String link = taoBaoGoodsCacheUtil.getBaseConvertLink(goods.getAuctionId(), dpid);
                if (!StringUtil.isNullOrEmpty(link)) {
@@ -415,7 +423,7 @@
        if (uid != null && uid > 0) {
            String specialId = userExtraTaoBaoInfoService.getSpecialIdByUid(uid);
            //获取最新的比例
            TaoBaoGoodsBrief rateGoods = TaoKeApiUtil.specialConvertCoupon(tb.getAuctionId(), TaoBaoConstant.getSpecialAuthAppInfo(), specialId, null);
            TaoBaoGoodsBrief rateGoods = TaoKeApiUtil.specialConvertCoupon(tb.getAuctionId(), TaoBaoConstant.getSpecialAuthAppInfo(pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.fanli)), specialId, null);
            if (rateGoods != null)
                tb.setMinTkRate(rateGoods.getTkRate());
        }
@@ -446,7 +454,7 @@
        // 大淘客商品过滤
        try {
            goods = filterDaTaoKeGoodsInfo(goods);
            goods = filterDaTaoKeGoodsInfo(acceptData.getSystem(), goods);
        } catch (Exception e) {
            LogHelper.errorDetailInfo(e);
        }
@@ -802,7 +810,7 @@
            // 券链接处理
            String materialId = "https://item.jd.com/" + id + ".html";
            String url = JDApiUtil.convertLinkWithSubUnionId(materialId, couponInfo.getLink(), null,
                    JDApiUtil.POSITION_COUPON + "", null);
                    pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_JD, SystemPIDInfo.PidType.coupon), null);
            couponInfo.setLink(url);
        }
@@ -934,14 +942,16 @@
            return;
        }
        String pid = pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_PDD, SystemPIDInfo.PidType.fanli);
        PDDGoodsDetail pddGoods = null;
        try {
            pddGoods = PinDuoDuoApiUtil.getGoodsDetail(id, PinDuoDuoApiUtil.PID_FANLI, pddAuthService.getFanliCustomParams(uid));
            pddGoods = PinDuoDuoApiUtil.getGoodsDetail(id, pid, pddAuthService.getFanliCustomParams(uid));
        } catch (PDDApiException e) {
            e.printStackTrace();
            if (e.getCode() == PDDApiException.CODE_NOT_AUTH) {
                try {
                    pddGoods = PinDuoDuoApiUtil.getGoodsDetail(id, PinDuoDuoApiUtil.PID_FANLI, Constant.PDD_SEARCH_CUSTOMER_PARAMS);
                    pddGoods = PinDuoDuoApiUtil.getGoodsDetail(id, pid, Constant.PDD_SEARCH_CUSTOMER_PARAMS);
                } catch (PDDApiException e1) {
                }
            }
@@ -992,7 +1002,7 @@
        CouponInfoVO couponInfo = goodsDetail.getCouponInfo();
        PDDConvertLinkResultVO convertUrl = null;
        if (couponInfo != null) {
            convertUrl = PinDuoDuoApiUtil.convert(pddGoods.getGoodsSign(), PinDuoDuoApiUtil.PID_COUPON + "", null, false);
            convertUrl = PinDuoDuoApiUtil.convert(pddGoods.getGoodsSign(), pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_PDD, SystemPIDInfo.PidType.coupon), null, false);
            if (convertUrl != null)
                couponInfo.setLink(convertUrl.getUrl());
        }
@@ -1650,19 +1660,22 @@
        }
        String jumpLink = null;
        String materialId = "https://item.jd.com/" + id + ".html";
        String pid = pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_JD, SystemPIDInfo.PidType.coupon);
        if (StringUtil.isNullOrEmpty(couponUrl)) {
            JDCouponInfo couponInfo = JDUtil.getShowCouponInfo(goods.getCouponInfoList(), goods.getPrice());
            if (couponInfo != null) {
                couponUrl = couponInfo.getLink();
            }
            jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, null, JDApiUtil.POSITION_COUPON + "",
            jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, null, pid,
                    "");
            if (jumpLink == null) {
                jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, null, null, JDApiUtil.POSITION_COUPON + "",
                jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, null, null, pid,
                        "");
            }
        } else {
            jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, null, JDApiUtil.POSITION_COUPON + "",
            jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, null, pid,
                    "");
            if (StringUtil.isNullOrEmpty(jumpLink)) {
                jumpLink = couponUrl;
@@ -1731,19 +1744,22 @@
        String jumpLink = null;
        String materialId = "https://item.jd.com/" + id + ".html";
        String pid = pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_JD, SystemPIDInfo.PidType.fanli);
        if (StringUtil.isNullOrEmpty(couponUrl)) {
            JDCouponInfo couponInfo = JDUtil.getShowCouponInfo(goods.getCouponInfoList(), goods.getPrice());
            if (couponInfo != null) {
                couponUrl = couponInfo.getLink();
            }
            jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, null, JDApiUtil.POSITION_FANLI + "",
            jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, null, pid,
                    uid + "");
            if (jumpLink == null) {
                jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, null, null, JDApiUtil.POSITION_FANLI + "",
                jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, null, null, pid,
                        uid + "");
            }
        } else {
            jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, null, JDApiUtil.POSITION_FANLI + "",
            jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, null, pid,
                    uid + "");
            if (StringUtil.isNullOrEmpty(jumpLink)) {
                jumpLink = couponUrl;
@@ -1786,7 +1802,7 @@
        String jumpLink = null;
        String materialId = "https://item.jd.com/" + id + ".html";
        jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, null, JDApiUtil.POSITION_FANLI + "", null);
        jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, null, pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_JD, SystemPIDInfo.PidType.fanli), null);
        if (StringUtil.isNullOrEmpty(jumpLink)) {
            jumpLink = couponUrl;
        }
@@ -1814,10 +1830,10 @@
            return;
        }
        String pid = PinDuoDuoApiUtil.PID_FANLI;
        String pid = pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_PDD, SystemPIDInfo.PidType.fanli);
        //只是领券
        if (!SystemInfoUtil.hasFunctions(acceptData.getSystem(), SystemFunction.fanli)) {
            pid = PinDuoDuoApiUtil.PID_COUPON;
            pid = pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_PDD, SystemPIDInfo.PidType.coupon);
            uid = null;
        } else {
            if (uid == null || uid <= 0) {
@@ -1937,9 +1953,9 @@
            return;
        }
        String pid = SuningApiUtil.PID_BUY;
        String pid = pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_SUNING, SystemPIDInfo.PidType.fanli);
        if (!SystemInfoUtil.hasFunctions(acceptData.getSystem(), SystemFunction.fanli)) {
            pid = SuningApiUtil.PID_COUPON;
            pid = pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_SUNING, SystemPIDInfo.PidType.coupon);
            uid = null;
        } else {
            if (uid == null || uid <= 0) {
@@ -2175,7 +2191,7 @@
            return;
        }
        link = JDApiUtil.convertLinkWithSubUnionId(link, null, null, JDApiUtil.POSITION_FANLI + "", uid + "");
        link = JDApiUtil.convertLinkWithSubUnionId(link, null, null, pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_JD, SystemPIDInfo.PidType.fanli), uid + "");
        GoodsJumpLinkVO vo = new GoodsJumpLinkVO();
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/PinDuoDuoControllerV2.java
@@ -6,7 +6,9 @@
import javax.annotation.Resource;
import com.yeshi.fanli.entity.SystemPIDInfo;
import com.yeshi.fanli.service.inter.pdd.PDDAuthService;
import com.yeshi.fanli.service.manger.PIDManager;
import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil;
import com.yeshi.fanli.util.pinduoduo.PinDuoDuoUtil;
import com.yeshi.fanli.vo.common.WXXCXJumpInfoVO;
@@ -57,6 +59,9 @@
    @Resource
    private PDDAuthService pddAuthService;
    @Resource
    private PIDManager pidManager;
    /**
@@ -127,9 +132,9 @@
        String pid = null;
        //自购
        if (type == 1) {
            pid = PinDuoDuoApiUtil.PID_FANLI;
            pid = pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_PDD, SystemPIDInfo.PidType.fanli);
        } else {//分享
            pid = PinDuoDuoApiUtil.PID_SHARE;
            pid = pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_PDD, SystemPIDInfo.PidType.share);
        }
        PDDConvertLinkResultVO authLink = PinDuoDuoApiUtil.getAuthLink(pid, pddAuthService.getFanliCustomParams(uid));
@@ -161,9 +166,9 @@
        String pid = null;
        //自购
        if (type == 1) {
            pid = PinDuoDuoApiUtil.PID_FANLI;
            pid = pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_PDD, SystemPIDInfo.PidType.fanli);
        } else {//分享
            pid = PinDuoDuoApiUtil.PID_SHARE;
            pid = pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_PDD, SystemPIDInfo.PidType.share);
        }
        String customParams = pddAuthService.getFanliCustomParams(uid);
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/SearchControllerV2.java
@@ -9,10 +9,12 @@
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import com.yeshi.fanli.entity.SystemPIDInfo;
import com.yeshi.fanli.exception.pdd.PDDApiException;
import com.yeshi.fanli.lijin.manager.GoodsLijinMnager;
import com.yeshi.fanli.service.inter.pdd.PDDAuthService;
import com.yeshi.fanli.service.inter.user.tb.UserExtraTaoBaoInfoService;
import com.yeshi.fanli.service.manger.PIDManager;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -141,6 +143,9 @@
    @Resource
    private GoodsLijinMnager goodsLijinMnager;
    @Resource
    private PIDManager pidManager;
    /**
@@ -990,7 +995,7 @@
        if (uid != null) {
            String cp = pddAuthService.getFanliCustomParams(uid);
            if (PinDuoDuoApiUtil.isAuth(PinDuoDuoApiUtil.PID_FANLI, cp)) {
            if (PinDuoDuoApiUtil.isAuth(pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_PDD, SystemPIDInfo.PidType.fanli), cp)) {
                customParams = cp;
            }
        }
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/ShareControllerV2.java
@@ -11,8 +11,10 @@
import javax.servlet.http.HttpServletRequest;
import com.yeshi.fanli.entity.SystemEnum;
import com.yeshi.fanli.entity.SystemPIDInfo;
import com.yeshi.fanli.exception.taobao.TaoBaoConvertLinkException;
import com.yeshi.fanli.service.inter.pdd.PDDAuthService;
import com.yeshi.fanli.service.manger.PIDManager;
import com.yeshi.fanli.service.manger.goods.TaoBaoLinkManager;
import com.yeshi.fanli.util.*;
import com.yeshi.fanli.util.StringUtil;
@@ -148,6 +150,9 @@
    @Resource
    private PDDAuthService pddAuthService;
    @Resource
    private PIDManager pidManager;
    private List<ShareGoodsCommentChoiceInfo> getCommentChoiceList(String token, String link, String inviteCode,
                                                                   BigDecimal fanliMoney) {
@@ -501,7 +506,7 @@
        try {
            ShareInfoVO shareInfo = new ShareInfoVO();
            TaoBaoLink taoBaoLink = taoBaoLinkManager.getTaoBaoLinkForShare(uid, goodsId, relationId, null);
            TaoBaoLink taoBaoLink = taoBaoLinkManager.getTaoBaoLinkForShare(acceptData.getSystem(), uid, goodsId, relationId, null);
            if (taoBaoLink != null && taoBaoLink.getGoods() != null && needGoods) {
                GoodsMoneyConfigParamsDTO dto = orderHongBaoMoneyComputeService.getShowComputeRate(platform, version, acceptData.getSystem());
@@ -738,9 +743,10 @@
            couponUrl = couponInfo.getLink();
        }
        String materialId = "https://item.jd.com/" + goodsId + ".html";
        String jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, null, JDApiUtil.POSITION_SHARE + "", uid + "");
        String pid = pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_JD, SystemPIDInfo.PidType.share);
        String jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, null, pid, uid + "");
        if (StringUtil.isNullOrEmpty(jumpLink)) {
            jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, null, null, JDApiUtil.POSITION_SHARE + "", uid + "");
            jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, null, null, pid, uid + "");
        }
        ShareInfoVO shareInfo = new ShareInfoVO();
@@ -895,13 +901,15 @@
        //查询当前用户是否授权
        String pid = pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_PDD, SystemPIDInfo.PidType.share);
        if (VersionUtil.greaterThan_2_1_5(acceptData.getPlatform(), acceptData.getVersion())) {
            if (!PinDuoDuoApiUtil.isAuth(PinDuoDuoApiUtil.PID_SHARE, pddAuthService.getFanliCustomParams(uid))) {
            if (!PinDuoDuoApiUtil.isAuth(pid, pddAuthService.getFanliCustomParams(uid))) {
                out.print(JsonUtil.loadFalseResult(20001, "尚未备案,请先备案"));
                return;
            }
        } else {
            if (System.currentTimeMillis() > TimeUtil.convertToTimeTemp("2021-05-01", "yyyy-MM-dd") && !PinDuoDuoApiUtil.isAuth(PinDuoDuoApiUtil.PID_SHARE, pddAuthService.getFanliCustomParams(uid))) {
            if (System.currentTimeMillis() > TimeUtil.convertToTimeTemp("2021-05-01", "yyyy-MM-dd") && !PinDuoDuoApiUtil.isAuth(pid, pddAuthService.getFanliCustomParams(uid))) {
                out.print(JsonUtil.loadFalseResult(20001, "请升级到最新版"));
                return;
            }
@@ -920,7 +928,7 @@
        // AESUtil.encrypt(uid + "", Constant.UIDAESKEY),
        // goodsId + "");
        String jumpLink = PinDuoDuoApiUtil.getPromotionUrl(goods.getGoodsSign(), PinDuoDuoApiUtil.PID_SHARE + "", uid + "");
        String jumpLink = PinDuoDuoApiUtil.getPromotionUrl(goods.getGoodsSign(), pid, uid + "");
        SystemEnum system = SystemInfoUtil.getSystem(acceptData);
@@ -1224,7 +1232,7 @@
        String couponLink = goods.getCouponInfo().getCouponUrl();
        String jumpLink = SuningApiUtil.convertLink(SuningUtil.getProductUrl(sts[0], sts[1]),
                StringUtil.isNullOrEmpty(couponLink) ? null : couponLink, SuningApiUtil.PID_SHARE, uid + "");
                StringUtil.isNullOrEmpty(couponLink) ? null : couponLink, pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_SUNING, SystemPIDInfo.PidType.share), uid + "");
        ShareInfoVO shareInfo = new ShareInfoVO();
        shareInfo.setClickUrl(jumpLink);
@@ -1401,17 +1409,17 @@
        }
        if (goodsType == Constant.SOURCE_TYPE_TAOBAO) {
            createTaoBaoViewText(goodsType, uid, template, Long.parseLong(goodsId), tljId, hasCoupon, out);
            createTaoBaoViewText(acceptData.getSystem(), goodsType, uid, template, Long.parseLong(goodsId), tljId, hasCoupon, out);
            return;
        }
        if (goodsType == Constant.SOURCE_TYPE_JD) {
            createJDViewText(goodsType, uid, template, Long.parseLong(goodsId), hasCoupon, out);
            createJDViewText(acceptData.getSystem(), goodsType, uid, template, Long.parseLong(goodsId), hasCoupon, out);
            return;
        }
        if (goodsType == Constant.SOURCE_TYPE_PDD) {
            createPDDViewText(goodsType, uid, template, Long.parseLong(goodsId), hasCoupon, out);
            createPDDViewText(acceptData.getSystem(), goodsType, uid, template, Long.parseLong(goodsId), hasCoupon, out);
            return;
        }
@@ -1421,7 +1429,7 @@
        }
        if (goodsType == Constant.SOURCE_TYPE_SUNING) {
            createSuNingViewText(goodsType, uid, template, goodsId, hasCoupon, out);
            createSuNingViewText(acceptData.getSystem(), goodsType, uid, template, goodsId, hasCoupon, out);
            return;
        }
    }
@@ -1437,7 +1445,7 @@
     * @param hasCoupon
     * @param out
     */
    private void createTaoBaoViewText(Integer goodsType, Long uid, String template, Long goodsId, Long tljId,
    private void createTaoBaoViewText(SystemEnum system, Integer goodsType, Long uid, String template, Long goodsId, Long tljId,
                                      Boolean hasCoupon, PrintWriter out) {
        TaoBaoGoodsBrief goods = taoBaoGoodsCacheUtil.getCommonTaoBaoGoodsInfo(goodsId);
        if (goods == null)
@@ -1472,11 +1480,12 @@
        }
        if (StringUtil.isNullOrEmpty(token)) {
            String pid = pidManager.getPidCache(system, Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.share);
            TaoKeAppInfo app = new TaoKeAppInfo();
            app.setAdzoneId(TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT.split("_")[3]);
            app.setAdzoneId(pid.split("_")[3]);
            app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY);
            app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
            app.setPid(TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT);
            app.setPid(pid);
            TaoBaoGoodsBrief goodsLink = TaoKeApiUtil.specialConvertCoupon(goods.getAuctionId(), app, null, null);
            if (goodsLink != null)
                token = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(),
@@ -1499,7 +1508,7 @@
     * @param hasCoupon
     * @param out
     */
    private void createJDViewText(Integer goodsType, Long uid, String template, Long goodsId, Boolean hasCoupon,
    private void createJDViewText(SystemEnum system, Integer goodsType, Long uid, String template, Long goodsId, Boolean hasCoupon,
                                  PrintWriter out) {
        JDGoods goods = jdGoodsCacheUtil.getGoodsInfo(goodsId);
        if (goods == null) {
@@ -1525,7 +1534,7 @@
            couponUrl = couponInfo.getLink();
        }
        String materialId = "https://item.jd.com/" + goodsId + ".html";
        String shortLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, null, JDApiUtil.POSITION_SHARE + "",
        String shortLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, null, pidManager.getPidCache(system, Constant.SOURCE_TYPE_JD, SystemPIDInfo.PidType.share),
                uid + "");
        String content = shareGoodsTextTemplateService.createContentJD(template, goods, shortLink, hasCoupon);
@@ -1544,7 +1553,7 @@
     * @param hasCoupon
     * @param out
     */
    private void createPDDViewText(Integer goodsType, Long uid, String template, Long goodsId, Boolean hasCoupon,
    private void createPDDViewText(SystemEnum system, Integer goodsType, Long uid, String template, Long goodsId, Boolean hasCoupon,
                                   PrintWriter out) {
        PDDGoodsDetail goods = pinDuoDuoCacheUtil.getGoodsInfo(goodsId);
        if (goods == null) {
@@ -1572,7 +1581,7 @@
        // goodsId + "");
        // String shortLink = HttpUtil.getShortLink(url);
        String shortLink = PinDuoDuoApiUtil.getPromotionUrl(goods.getGoodsSign(), PinDuoDuoApiUtil.PID_SHARE + "", uid + "");
        String shortLink = PinDuoDuoApiUtil.getPromotionUrl(goods.getGoodsSign(), pidManager.getPidCache(system, Constant.SOURCE_TYPE_PDD, SystemPIDInfo.PidType.share), uid + "");
        // // 创建口令
        // String token = PinDuoDuoApiUtil.createGenerate(goodsId);
@@ -1626,7 +1635,7 @@
    }
    private void createSuNingViewText(Integer goodsType, Long uid, String template, String goodsId, Boolean hasCoupon,
    private void createSuNingViewText(SystemEnum system, Integer goodsType, Long uid, String template, String goodsId, Boolean hasCoupon,
                                      PrintWriter out) {
        String[] ids = SuningUtil.getGoodsIdDetail(goodsId);
        SuningGoodsInfo goods = SuningApiUtil.getGoodsDetail(ids[1], ids[0]);
@@ -1649,7 +1658,7 @@
        String couponLink = goods.getCouponInfo().getCouponUrl();
        String jumpLink = SuningApiUtil.convertLink(SuningUtil.getProductUrl(ids[0], ids[1]),
                StringUtil.isNullOrEmpty(couponLink) ? null : couponLink, SuningApiUtil.PID_SHARE, uid + "");
                StringUtil.isNullOrEmpty(couponLink) ? null : couponLink, pidManager.getPidCache(system, Constant.SOURCE_TYPE_SUNING, SystemPIDInfo.PidType.share), uid + "");
        // 生成普通分享内容
        String content = shareGoodsTextTemplateService.createCommonShareTextSuNing(template, goods, jumpLink);
fanli/src/main/java/com/yeshi/fanli/controller/h5/H5PDDGoodsController.java
@@ -7,7 +7,9 @@
import javax.annotation.Resource;
import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
import com.yeshi.fanli.entity.SystemPIDInfo;
import com.yeshi.fanli.exception.pdd.PDDApiException;
import com.yeshi.fanli.service.manger.PIDManager;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil;
import org.springframework.stereotype.Controller;
@@ -24,6 +26,10 @@
    @Resource
    private PDDGoodsService pddGoodsService;
    @Resource
    private PIDManager pidManager;
    /**
     * 获取拼多多的图文详情
@@ -42,7 +48,7 @@
        PDDGoodsDetail pddGoods = null;
        try {
            pddGoods = PinDuoDuoApiUtil.getGoodsDetail(id, PinDuoDuoApiUtil.PID_FANLI, Constant.PDD_SEARCH_CUSTOMER_PARAMS);
            pddGoods = PinDuoDuoApiUtil.getGoodsDetail(id, pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_PDD, SystemPIDInfo.PidType.fanli), Constant.PDD_SEARCH_CUSTOMER_PARAMS);
        } catch (PDDApiException e) {
            e.printStackTrace();
        }
fanli/src/main/java/com/yeshi/fanli/controller/h5/H5RecommendController.java
@@ -8,6 +8,8 @@
import javax.annotation.Resource;
import com.yeshi.fanli.entity.SystemPIDInfo;
import com.yeshi.fanli.service.manger.PIDManager;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@@ -68,524 +70,525 @@
@RequestMapping("api/h5/v1/webRecommend")
public class H5RecommendController {
    @Resource
    private H5ControllerUtil h5ControllerUtil;
    @Resource
    private H5ControllerUtil h5ControllerUtil;
    @Resource
    private SuperRecommendBannerService superRecommendBannerService;
    @Resource
    private SuperRecommendBannerService superRecommendBannerService;
    @Resource
    private HongBaoManageService hongBaoManageService;
    @Resource
    private HongBaoManageService hongBaoManageService;
    @Resource
    private RedisManager redisManager;
    @Resource
    private RedisManager redisManager;
    @Resource
    private BusinessSystemService businessSystemService;
    @Resource
    private BusinessSystemService businessSystemService;
    @Resource
    private ConfigService configService;
    @Resource
    private ConfigService configService;
    @Resource
    private SystemConfigService systemConfigService;
    @Resource
    private SystemConfigService systemConfigService;
    @Resource
    private TaoBaoGoodsBriefService taoBaoGoodsBriefService;
    @Resource
    private TaoBaoGoodsBriefService taoBaoGoodsBriefService;
    @Resource
    private TBPidService tbPidService;
    @Resource
    private TBPidService tbPidService;
    @Resource
    private ShareGoodsService shareGoodsService;
    @Resource
    private ShareGoodsService shareGoodsService;
    @Resource
    private TaoBaoUnionConfigService taoBaoUnionConfigService;
    @Resource
    private TaoBaoUnionConfigService taoBaoUnionConfigService;
    @Resource
    private UserShareGoodsGroupService userShareGoodsGroupService;
    @Resource
    private UserShareGoodsGroupService userShareGoodsGroupService;
    @Resource
    private UserTaoLiJinRecordService userTaoLiJinRecordService;
    @Resource
    private UserTaoLiJinRecordService userTaoLiJinRecordService;
    @Resource
    private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService;
    @Resource
    private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService;
    /**
     *
     * 方法说明: 推荐轮播商品信息
     *
     * @author mawurui createTime 2018年5月11日 上午11:13:47
     * @param acceptData
     * @param out
     */
    @RequestMapping(value = "getRecommenBanner", method = RequestMethod.GET)
    public void getRecommendBanner(AcceptData acceptData, String callback, PrintWriter out) {
    @Resource
    private PIDManager pidManager;
        BusinessSystem system = businessSystemService.getBusinessSystem("WEB",
                Constant.systemCommonConfig.getH5PackageName(),acceptData.getSystem());
        JSONObject json = new JSONObject();
        if (system == null) {
            out.print(JsonUtil.loadFalseResult(1, H5ControllerUtil.NOSYSTEM));
            return;
        }
        List<SuperRecommendBanner> superRecommendBanners = superRecommendBannerService
                .getSuperRecommendBannersBySystem(system);
        List<RecommendBanner> list = null;
        for (SuperRecommendBanner superRecommendBanner : superRecommendBanners) {
            if (list == null) {
                list = new ArrayList<RecommendBanner>();
            }
            RecommendBanner recommendBanner = superRecommendBanner.getRecommendBanner();
            // 淘特价暂时修改
            if (system.getId() == 7) {
                recommendBanner.getJumpDetail().setActivity(recommendBanner.getJumpDetail().getActivity()
                        .replace("com.yeshi.ec.rebate.myapplication", "com.yeshi.ec.taospecial"));
            }
    /**
     * 方法说明: 推荐轮播商品信息
     *
     * @param acceptData
     * @param out
     * @author mawurui createTime 2018年5月11日 上午11:13:47
     */
    @RequestMapping(value = "getRecommenBanner", method = RequestMethod.GET)
    public void getRecommendBanner(AcceptData acceptData, String callback, PrintWriter out) {
            list.add(recommendBanner);
        }
        BusinessSystem system = businessSystemService.getBusinessSystem("WEB",
                Constant.systemCommonConfig.getH5PackageName(), acceptData.getSystem());
        JSONObject json = new JSONObject();
        if (system == null) {
            out.print(JsonUtil.loadFalseResult(1, H5ControllerUtil.NOSYSTEM));
            return;
        }
        List<SuperRecommendBanner> superRecommendBanners = superRecommendBannerService
                .getSuperRecommendBannersBySystem(system);
        List<RecommendBanner> list = null;
        for (SuperRecommendBanner superRecommendBanner : superRecommendBanners) {
            if (list == null) {
                list = new ArrayList<RecommendBanner>();
            }
            RecommendBanner recommendBanner = superRecommendBanner.getRecommendBanner();
            // 淘特价暂时修改
            if (system.getId() == 7) {
                recommendBanner.getJumpDetail().setActivity(recommendBanner.getJumpDetail().getActivity()
                        .replace("com.yeshi.ec.rebate.myapplication", "com.yeshi.ec.taospecial"));
            }
        if (list == null) {
            json.put("code", "1");
            json.put("msg", H5ControllerUtil.NODATA);
            out.print(json);
            java.lang.System.out.println("json-" + json);
            return;
        }
        json.put("code", 0);
        JSONObject data = new JSONObject();
        data.put("count", list.size());
        Gson gson = new Gson();
        data.put("data", gson.toJson(list));
        json.put("data", data);
        // jsonp方式返回
        out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(json)));
        return;
    }
            list.add(recommendBanner);
        }
    /**
     * 处理条件
     *
     * @param uid
     * @param tid
     * @param out
     */
    private void doTaoLiJin(String callback, Long uid, Long tid, PrintWriter out) {
        // 查询商品淘礼金
        UserTaoLiJinRecord record = userTaoLiJinRecordService.selectByPrimaryKey(tid);
        if (record == null) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("商品信息获取失败")));
            return;
        }
        if (list == null) {
            json.put("code", "1");
            json.put("msg", H5ControllerUtil.NODATA);
            out.print(json);
            java.lang.System.out.println("json-" + json);
            return;
        }
        json.put("code", 0);
        JSONObject data = new JSONObject();
        data.put("count", list.size());
        Gson gson = new Gson();
        data.put("data", gson.toJson(list));
        json.put("data", data);
        // jsonp方式返回
        out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(json)));
        return;
    }
        Long auctionId = record.getGoodsId();
        String tljLink = record.getSendUrl();
        BigDecimal tljMoney = record.getPerFace();
    /**
     * 处理条件
     *
     * @param uid
     * @param tid
     * @param out
     */
    private void doTaoLiJin(String callback, Long uid, Long tid, PrintWriter out) {
        // 查询商品淘礼金
        UserTaoLiJinRecord record = userTaoLiJinRecordService.selectByPrimaryKey(tid);
        if (record == null) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("商品信息获取失败")));
            return;
        }
        TaoBaoGoodsBrief goods = null;
        try {
            goods = redisManager.getTaoBaoGoodsBrief(auctionId);
        } catch (TaobaoGoodsDownException e) {
        }
        Long auctionId = record.getGoodsId();
        String tljLink = record.getSendUrl();
        BigDecimal tljMoney = record.getPerFace();
        if (goods == null) {// 已经下线
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("商品信息获取失败")));
            return;
        }
        TaoBaoGoodsBrief goods = null;
        try {
            goods = redisManager.getTaoBaoGoodsBrief(auctionId);
        } catch (TaobaoGoodsDownException e) {
        }
        String token = redisManager.getTLJToken(tljLink);
        if (StringUtil.isNullOrEmpty(token)) {
            token = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), tljLink);
        }
        if (goods == null) {// 已经下线
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("商品信息获取失败")));
            return;
        }
        // 券后价
        BigDecimal afterCouponPrice = TaoBaoUtil.getCouponPrice(goods);
        TaoBaoLink link = new TaoBaoLink();
        link.setTaoToken(token);
        String token = redisManager.getTLJToken(tljLink);
        if (StringUtil.isNullOrEmpty(token)) {
            token = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), tljLink);
        }
        JSONObject data = new JSONObject();
        data.put("title", goods.getTitle());
        if (goods.getImgList() == null)
            goods.setImgList(new ArrayList<>());
        goods.getImgList().add(0, TbImgUtil.getTBSizeImg(goods.getPictUrl(), 300));
        data.put("imgs", goods.getImgList());
        data.put("couponPrice", afterCouponPrice);
        // 老版本兼容
        data.put("quanPrice", afterCouponPrice);
        data.put("zkPrice", goods.getZkPrice());
        data.put("shareContent", "长按复制本段文字,打开【手机淘宝】即可领取【特别优惠券】购买下单,");
        data.put("token", TaoBaoUtil.filterTaoToken(link.getTaoToken()));
        data.put("reservePrice", goods.getReservePrice());
        data.put("shopType", goods.getUserType() == 1 ? 2 : 1);
        if (!StringUtil.isNullOrEmpty(goods.getCouponInfo()) && !"无".equalsIgnoreCase(goods.getCouponInfo())) {
            data.put("couponAmount", MoneyBigDecimalUtil.getWithNoZera(goods.getCouponAmount()));
            data.put("coupon", true);
        } else {
            data.put("coupon", false);
        }
        // 券后价
        BigDecimal afterCouponPrice = TaoBaoUtil.getCouponPrice(goods);
        TaoBaoLink link = new TaoBaoLink();
        link.setTaoToken(token);
        data.put("tljMoney", tljMoney);
        JSONObject data = new JSONObject();
        data.put("title", goods.getTitle());
        if (goods.getImgList() == null)
            goods.setImgList(new ArrayList<>());
        goods.getImgList().add(0, TbImgUtil.getTBSizeImg(goods.getPictUrl(), 300));
        data.put("imgs", goods.getImgList());
        data.put("couponPrice", afterCouponPrice);
        // 老版本兼容
        data.put("quanPrice", afterCouponPrice);
        data.put("zkPrice", goods.getZkPrice());
        data.put("shareContent", "长按复制本段文字,打开【手机淘宝】即可领取【特别优惠券】购买下单,");
        data.put("token", TaoBaoUtil.filterTaoToken(link.getTaoToken()));
        data.put("reservePrice", goods.getReservePrice());
        data.put("shopType", goods.getUserType() == 1 ? 2 : 1);
        if (!StringUtil.isNullOrEmpty(goods.getCouponInfo()) && !"无".equalsIgnoreCase(goods.getCouponInfo())) {
            data.put("couponAmount", MoneyBigDecimalUtil.getWithNoZera(goods.getCouponAmount()));
            data.put("coupon", true);
        } else {
            data.put("coupon", false);
        }
        out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data)));
    }
        data.put("tljMoney", tljMoney);
    /**
     *
     * 方法说明: 获取商品详情
     *
     * @author mawurui createTime 2018年5月11日 上午11:37:02
     * @param acceptData
     * @param id
     * @param uid
     * @param out
     */
        out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data)));
    }
    @SuppressWarnings("unused")
    @RequestMapping(value = "getGoodsDetail", method = RequestMethod.GET)
    public void getGoodsDetail(final AcceptData acceptData, final String id, String tid, String uid, String callback,
            PrintWriter out) {
        if (!StringUtil.isNullOrEmpty(uid))
            uid = uid.replace(" ", "+");
    /**
     * 方法说明: 获取商品详情
     *
     * @param acceptData
     * @param id
     * @param uid
     * @param out
     * @author mawurui createTime 2018年5月11日 上午11:37:02
     */
        LogManager.getLogger(LogType.taobaoTrade)
                .info(String.format("淘宝分享商品H5访问:\n  商品ID:%s \n  原始用户ID:%s \n", id, uid));
        long begin = java.lang.System.currentTimeMillis();
        if (StringUtil.isNullOrEmpty(id)) {
            out.print(JsonUtil.loadFalseResult(1, "请上传id"));
            return;
        }
    @SuppressWarnings("unused")
    @RequestMapping(value = "getGoodsDetail", method = RequestMethod.GET)
    public void getGoodsDetail(final AcceptData acceptData, final String id, String tid, String uid, String callback,
                               PrintWriter out) {
        if (!StringUtil.isNullOrEmpty(uid))
            uid = uid.replace(" ", "+");
        if (!StringUtil.isNullOrEmpty(uid)) {
            uid = AESUtil.decrypt(uid, Constant.UIDAESKEY);
        }
        LogManager.getLogger(LogType.taobaoTrade)
                .info(String.format("淘宝分享商品H5访问:\n  商品ID:%s \n  原始用户ID:%s \n", id, uid));
        if (!StringUtil.isNullOrEmpty(tid)) {
            tid = AESUtil.decrypt(tid, Constant.UIDAESKEY);
            doTaoLiJin(callback, StringUtil.isNullOrEmpty(uid) || Long.parseLong(uid) == 0 ? null : Long.parseLong(uid),
                    Long.parseLong(tid), out);
            return;
        }
        long begin = java.lang.System.currentTimeMillis();
        if (StringUtil.isNullOrEmpty(id)) {
            out.print(JsonUtil.loadFalseResult(1, "请上传id"));
            return;
        }
        TaoBaoGoodsBrief goods = null;
        String token = null;
        if (!StringUtil.isNullOrEmpty(uid)) {
            // 查询是否有分享记录
            UserShareGoodsHistory shareHistory = null;
            try {
                shareHistory = shareGoodsService.getShareGoodsHistoryDetail(Long.parseLong(uid), Long.parseLong(id));
            } catch (NumberFormatException e) {
                e.printStackTrace();
            } catch (ShareGoodsException e) {
                e.printStackTrace();
            }
        if (!StringUtil.isNullOrEmpty(uid)) {
            uid = AESUtil.decrypt(uid, Constant.UIDAESKEY);
        }
            if (shareHistory != null) {// 有分享记录
                token = shareHistory.getTkCode();
                goods = redisManager.getTaoBaoGoodsTemp(Long.parseLong(id));
                if (goods == null)
                    try {
                        goods = TaoKeApiUtil.searchGoodsDetail(Long.parseLong(id));
                    } catch (NumberFormatException e) {
                        e.printStackTrace();
                    } catch (TaobaoGoodsDownException e) {
                        e.printStackTrace();
                    }
        if (!StringUtil.isNullOrEmpty(tid)) {
            tid = AESUtil.decrypt(tid, Constant.UIDAESKEY);
            doTaoLiJin(callback, StringUtil.isNullOrEmpty(uid) || Long.parseLong(uid) == 0 ? null : Long.parseLong(uid),
                    Long.parseLong(tid), out);
            return;
        }
            } else {// 没有分享记录,需要直接分享
                LogHelper.test("没有分享记录:uid:" + uid + "  actionid:" + id);
                // 获取
                TaoKeAppInfo app = new TaoKeAppInfo();
                app.setPid(TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT);
                app.setAdzoneId(app.getPid().split("_")[3]);
                app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY);
                app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
        TaoBaoGoodsBrief goods = null;
        String token = null;
        if (!StringUtil.isNullOrEmpty(uid)) {
            // 查询是否有分享记录
            UserShareGoodsHistory shareHistory = null;
            try {
                shareHistory = shareGoodsService.getShareGoodsHistoryDetail(Long.parseLong(uid), Long.parseLong(id));
            } catch (NumberFormatException e) {
                e.printStackTrace();
            } catch (ShareGoodsException e) {
                e.printStackTrace();
            }
                try {
                    goods = TaoKeApiUtil.searchGoodsDetail(Long.parseLong(id), app);
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                } catch (TaobaoGoodsDownException e) {
                    e.printStackTrace();
                }
                if (goods != null) {
                    String url = goods.getAuctionUrl();
                    if (!StringUtil.isNullOrEmpty(goods.getCouponLink())) {
                        url = goods.getCouponLink();
                    }
                    String relationId = userExtraTaoBaoInfoService.getRelationIdByUid(Long.parseLong(uid));
                    if (!StringUtil.isNullOrEmpty(relationId))
                        url += "&relationId=" + relationId;
                    token = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), url);
                }
            }
            if (shareHistory != null) {// 有分享记录
                token = shareHistory.getTkCode();
                goods = redisManager.getTaoBaoGoodsTemp(Long.parseLong(id));
                if (goods == null)
                    try {
                        goods = TaoKeApiUtil.searchGoodsDetail(Long.parseLong(id));
                    } catch (NumberFormatException e) {
                        e.printStackTrace();
                    } catch (TaobaoGoodsDownException e) {
                        e.printStackTrace();
                    }
        } else {
            List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService
                    .getConfigByTypeCache(PidUser.TYPE_SHARE_GOODS);
            String pid = tbPidService.getSharePid().getPid();
            TaoKeAppInfo app = new TaoKeAppInfo();
            app.setAdzoneId(pid.split("_")[3]);
            app.setAppKey(configList.get(0).getAppKey());
            app.setAppSecret(configList.get(0).getAppSecret());
            app.setPid(pid);
            try {
                goods = TaoKeApiUtil.searchGoodsDetail(Long.parseLong(id), app);
            } catch (NumberFormatException e) {
                e.printStackTrace();
            } catch (TaobaoGoodsDownException e) {
                e.printStackTrace();
            }
            if (goods != null) {
                String url = goods.getAuctionUrl();
                if (!StringUtil.isNullOrEmpty(goods.getCouponLink())) {
                    url = goods.getCouponLink();
                }
                if (!url.contains("uland.taobao.com") && !url.contains("s.click.taobao.com")) {
                    TaoBaoGoodsBrief linkInfo = TaoKeApiUtil.specialConvertCoupon(Long.parseLong(id), app,null,null);
                    url = linkInfo.getCouponLink();
                    if (StringUtil.isNullOrEmpty(url))
                        url = linkInfo.getAuctionUrl();
                }
            } else {// 没有分享记录,需要直接分享
                LogHelper.test("没有分享记录:uid:" + uid + "  actionid:" + id);
                // 获取
                TaoKeAppInfo app = new TaoKeAppInfo();
                app.setPid(pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.share));
                app.setAdzoneId(app.getPid().split("_")[3]);
                app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY);
                app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
                token = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), url);
            }
        }
                try {
                    goods = TaoKeApiUtil.searchGoodsDetail(Long.parseLong(id), app);
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                } catch (TaobaoGoodsDownException e) {
                    e.printStackTrace();
                }
                if (goods != null) {
                    String url = goods.getAuctionUrl();
                    if (!StringUtil.isNullOrEmpty(goods.getCouponLink())) {
                        url = goods.getCouponLink();
                    }
                    String relationId = userExtraTaoBaoInfoService.getRelationIdByUid(Long.parseLong(uid));
                    if (!StringUtil.isNullOrEmpty(relationId))
                        url += "&relationId=" + relationId;
                    token = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), url);
                }
            }
        if (goods == null) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("商品信息获取失败")));
            return;
        }
        } else {
            List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService
                    .getConfigByTypeCache(PidUser.TYPE_SHARE_GOODS);
            String pid = tbPidService.getSharePid(acceptData.getSystem()).getPid();
            TaoKeAppInfo app = new TaoKeAppInfo();
            app.setAdzoneId(pid.split("_")[3]);
            app.setAppKey(configList.get(0).getAppKey());
            app.setAppSecret(configList.get(0).getAppSecret());
            app.setPid(pid);
            try {
                goods = TaoKeApiUtil.searchGoodsDetail(Long.parseLong(id), app);
            } catch (NumberFormatException e) {
                e.printStackTrace();
            } catch (TaobaoGoodsDownException e) {
                e.printStackTrace();
            }
            if (goods != null) {
                String url = goods.getAuctionUrl();
                if (!StringUtil.isNullOrEmpty(goods.getCouponLink())) {
                    url = goods.getCouponLink();
                }
                if (!url.contains("uland.taobao.com") && !url.contains("s.click.taobao.com")) {
                    TaoBaoGoodsBrief linkInfo = TaoKeApiUtil.specialConvertCoupon(Long.parseLong(id), app, null, null);
                    url = linkInfo.getCouponLink();
                    if (StringUtil.isNullOrEmpty(url))
                        url = linkInfo.getAuctionUrl();
                }
        if (StringUtil.isNullOrEmpty(token)) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("口令生成失败")));
            return;
        }
                token = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), url);
            }
        }
        // 券后价
        BigDecimal afterCouponPrice = TaoBaoUtil.getCouponPrice(goods);
        TaoBaoLink link = new TaoBaoLink();
        link.setTaoToken(token);
        if (goods == null) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("商品信息获取失败")));
            return;
        }
        JSONObject data = new JSONObject();
        data.put("title", goods.getTitle());
        if (goods.getImgList() == null)
            goods.setImgList(new ArrayList<>());
        goods.getImgList().add(0, TbImgUtil.getTBSizeImg(goods.getPictUrl(), 300));
        data.put("imgs", goods.getImgList());
        data.put("couponPrice", afterCouponPrice);
        // 老版本兼容
        data.put("quanPrice", afterCouponPrice);
        data.put("zkPrice", goods.getZkPrice());
        data.put("shareContent", "长按复制本段文字,打开【手机淘宝】即可领取【特别优惠券】购买下单,");
        data.put("token", TaoBaoUtil.filterTaoToken(link.getTaoToken()));
        data.put("reservePrice", goods.getReservePrice());
        data.put("shopType", goods.getUserType() == 1 ? 2 : 1);
        if (!StringUtil.isNullOrEmpty(goods.getCouponInfo()) && !"无".equalsIgnoreCase(goods.getCouponInfo())) {
            data.put("couponAmount", MoneyBigDecimalUtil.getWithNoZera(goods.getCouponAmount()));
            data.put("coupon", true);
            // 老版本兼容
            data.put("quan", true);
        } else {
            data.put("coupon", false);
            // 老版本兼容
            data.put("quan", true);
        }
        if (StringUtil.isNullOrEmpty(token)) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("口令生成失败")));
            return;
        }
        out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data)));
        // 券后价
        BigDecimal afterCouponPrice = TaoBaoUtil.getCouponPrice(goods);
        TaoBaoLink link = new TaoBaoLink();
        link.setTaoToken(token);
        final String tempUid = uid;
        ThreadUtil.run(new Runnable() {
        JSONObject data = new JSONObject();
        data.put("title", goods.getTitle());
        if (goods.getImgList() == null)
            goods.setImgList(new ArrayList<>());
        goods.getImgList().add(0, TbImgUtil.getTBSizeImg(goods.getPictUrl(), 300));
        data.put("imgs", goods.getImgList());
        data.put("couponPrice", afterCouponPrice);
        // 老版本兼容
        data.put("quanPrice", afterCouponPrice);
        data.put("zkPrice", goods.getZkPrice());
        data.put("shareContent", "长按复制本段文字,打开【手机淘宝】即可领取【特别优惠券】购买下单,");
        data.put("token", TaoBaoUtil.filterTaoToken(link.getTaoToken()));
        data.put("reservePrice", goods.getReservePrice());
        data.put("shopType", goods.getUserType() == 1 ? 2 : 1);
        if (!StringUtil.isNullOrEmpty(goods.getCouponInfo()) && !"无".equalsIgnoreCase(goods.getCouponInfo())) {
            data.put("couponAmount", MoneyBigDecimalUtil.getWithNoZera(goods.getCouponAmount()));
            data.put("coupon", true);
            // 老版本兼容
            data.put("quan", true);
        } else {
            data.put("coupon", false);
            // 老版本兼容
            data.put("quan", true);
        }
            @Override
            public void run() {
                try {
                    if (!StringUtil.isNullOrEmpty(tempUid))
                        userShareGoodsGroupService.updateBrowseRecord(Long.parseLong(tempUid), Long.parseLong(id), 1);
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                } catch (UserShareGoodsRecordException e) {
                    e.printStackTrace();
                }
            }
        });
        return;
    }
        out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data)));
    /**
     * 京东分享商品信息
     *
     * @param acceptData
     * @param id
     * @param uid
     * @param callback
     * @param out
     */
    @RequestMapping(value = "getJDGoodsDetail")
    public void getJDGoodsDetail(final AcceptData acceptData, final Long id, String uid, String callback,
            PrintWriter out) {
        if (id == null) {
            out.print(JsonUtil.loadFalseResult(1, "请上传id"));
            return;
        }
        final String tempUid = uid;
        ThreadUtil.run(new Runnable() {
        if (!StringUtil.isNullOrEmpty(uid)) {
            uid = AESUtil.decrypt(uid, Constant.UIDAESKEY);
        }
            @Override
            public void run() {
                try {
                    if (!StringUtil.isNullOrEmpty(tempUid))
                        userShareGoodsGroupService.updateBrowseRecord(Long.parseLong(tempUid), Long.parseLong(id), 1);
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                } catch (UserShareGoodsRecordException e) {
                    e.printStackTrace();
                }
            }
        });
        return;
    }
        JDGoods jdGoods = JDApiUtil.queryGoodsDetail(id);
        if (jdGoods == null) {
            jdGoods = JDApiUtil.getGoodsDetail(id);
        }
    /**
     * 京东分享商品信息
     *
     * @param acceptData
     * @param id
     * @param uid
     * @param callback
     * @param out
     */
    @RequestMapping(value = "getJDGoodsDetail")
    public void getJDGoodsDetail(final AcceptData acceptData, final Long id, String uid, String callback,
                                 PrintWriter out) {
        if (id == null) {
            out.print(JsonUtil.loadFalseResult(1, "请上传id"));
            return;
        }
        if (jdGoods == null) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("商品信息获取失败")));
            return;
        }
        if (!StringUtil.isNullOrEmpty(uid)) {
            uid = AESUtil.decrypt(uid, Constant.UIDAESKEY);
        }
        List<String> imageList = jdGoods.getImageList();
        if (imageList == null) {
            imageList = new ArrayList<>();
            imageList.add(jdGoods.getPicUrl());
        }
        JDGoods jdGoods = JDApiUtil.queryGoodsDetail(id);
        if (jdGoods == null) {
            jdGoods = JDApiUtil.getGoodsDetail(id);
        }
        boolean hasCoupon = false;
        String couponUrl = null;
        BigDecimal discount = new BigDecimal(0);
        JDCouponInfo couponInfo = JDUtil.getShowCouponInfo(jdGoods);
        if (couponInfo != null) {
            hasCoupon = true;
            discount = couponInfo.getDiscount();
            couponUrl = couponInfo.getLink();
        }
        if (jdGoods == null) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("商品信息获取失败")));
            return;
        }
        boolean jdzy = false;
        String owner = jdGoods.getOwner();
        if (!StringUtil.isNullOrEmpty(owner) && "g".equalsIgnoreCase(owner)) {
            jdzy = true;
        }
        List<String> imageList = jdGoods.getImageList();
        if (imageList == null) {
            imageList = new ArrayList<>();
            imageList.add(jdGoods.getPicUrl());
        }
        String materialId = "https://item.jd.com/" + id + ".html";
        String jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, null,JDApiUtil.POSITION_SHARE + "",
                uid);
        boolean hasCoupon = false;
        String couponUrl = null;
        BigDecimal discount = new BigDecimal(0);
        JDCouponInfo couponInfo = JDUtil.getShowCouponInfo(jdGoods);
        if (couponInfo != null) {
            hasCoupon = true;
            discount = couponInfo.getDiscount();
            couponUrl = couponInfo.getLink();
        }
        int priceType = 1;
        BigDecimal price = jdGoods.getPrice();
        ;
        JDPingouInfo pinGouInfo = jdGoods.getPinGouInfo();
        if (pinGouInfo != null) {
            priceType = 2; // 拼购价
            price = pinGouInfo.getPingouPrice();
        }
        boolean jdzy = false;
        String owner = jdGoods.getOwner();
        if (!StringUtil.isNullOrEmpty(owner) && "g".equalsIgnoreCase(owner)) {
            jdzy = true;
        }
        JSONObject data = new JSONObject();
        data.put("jdzy", jdzy);
        data.put("imgs", imageList);
        data.put("title", jdGoods.getSkuName());
        data.put("zkPrice", price);
        data.put("priceType", priceType);
        data.put("coupon", hasCoupon);
        data.put("couponAmount", discount);
        data.put("couponPrice", JDUtil.getCouponPrice(jdGoods));
        data.put("helpLink", configService.getValue("jd_share_h5_help_link",acceptData.getSystem()));
        data.put("jumpLink", jumpLink);
        JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
        String materialId = "https://item.jd.com/" + id + ".html";
        String jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, null, pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_JD, SystemPIDInfo.PidType.share),
                uid);
        final String tempUid = uid;
        ThreadUtil.run(new Runnable() {
            @Override
            public void run() {
                try {
                    if (!StringUtil.isNullOrEmpty(tempUid))
                        userShareGoodsGroupService.updateBrowseNum(Long.parseLong(tempUid), id,
                                Constant.SOURCE_TYPE_JD);
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                } catch (UserShareGoodsRecordException e) {
                    e.printStackTrace();
                }
            }
        });
        return;
    }
        int priceType = 1;
        BigDecimal price = jdGoods.getPrice();
        ;
        JDPingouInfo pinGouInfo = jdGoods.getPinGouInfo();
        if (pinGouInfo != null) {
            priceType = 2; // 拼购价
            price = pinGouInfo.getPingouPrice();
        }
    /**
     * 拼多多分享商品详情
     *
     * @param acceptData
     * @param id
     * @param uid
     * @param callback
     * @param out
     */
    @RequestMapping(value = "getPDDGoodsDetail")
    public void getPDDGoodsDetail(final AcceptData acceptData, final Long id, String uid, String callback,
            PrintWriter out) {
        if (id == null) {
            out.print(JsonUtil.loadFalseResult(1, "请上传id"));
            return;
        }
        JSONObject data = new JSONObject();
        data.put("jdzy", jdzy);
        data.put("imgs", imageList);
        data.put("title", jdGoods.getSkuName());
        data.put("zkPrice", price);
        data.put("priceType", priceType);
        data.put("coupon", hasCoupon);
        data.put("couponAmount", discount);
        data.put("couponPrice", JDUtil.getCouponPrice(jdGoods));
        data.put("helpLink", configService.getValue("jd_share_h5_help_link", acceptData.getSystem()));
        data.put("jumpLink", jumpLink);
        JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
        if (!StringUtil.isNullOrEmpty(uid)) {
            uid = AESUtil.decrypt(uid, Constant.UIDAESKEY);
        }
        final String tempUid = uid;
        ThreadUtil.run(new Runnable() {
            @Override
            public void run() {
                try {
                    if (!StringUtil.isNullOrEmpty(tempUid))
                        userShareGoodsGroupService.updateBrowseNum(Long.parseLong(tempUid), id,
                                Constant.SOURCE_TYPE_JD);
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                } catch (UserShareGoodsRecordException e) {
                    e.printStackTrace();
                }
            }
        });
        return;
    }
        PDDGoodsDetail pddGoods = PinDuoDuoApiUtil.getGoodsDetail(id);
        if (pddGoods == null) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("商品信息获取失败")));
            return;
        }
    /**
     * 拼多多分享商品详情
     *
     * @param acceptData
     * @param id
     * @param uid
     * @param callback
     * @param out
     */
    @RequestMapping(value = "getPDDGoodsDetail")
    public void getPDDGoodsDetail(final AcceptData acceptData, final Long id, String uid, String callback,
                                  PrintWriter out) {
        if (id == null) {
            out.print(JsonUtil.loadFalseResult(1, "请上传id"));
            return;
        }
        List<String> imageList = null;
        String[] goodsGalleryUrls = pddGoods.getGoodsGalleryUrls();
        if (goodsGalleryUrls != null) {
            imageList = Arrays.asList(goodsGalleryUrls);
        }
        if (imageList == null) {
            imageList = new ArrayList<>();
            String goodsImageUrl = pddGoods.getGoodsImageUrl();
            if (!StringUtil.isNullOrEmpty(goodsImageUrl)) {
                imageList.add(goodsImageUrl);
            }
        }
        if (!StringUtil.isNullOrEmpty(uid)) {
            uid = AESUtil.decrypt(uid, Constant.UIDAESKEY);
        }
        BigDecimal hundred = new BigDecimal(100);
        Boolean hasCoupon = pddGoods.getHasCoupon();
        BigDecimal amount = new BigDecimal(0);
        if (hasCoupon != null && hasCoupon) {
            amount = MoneyBigDecimalUtil.div(new BigDecimal(pddGoods.getCouponDiscount()), hundred).setScale(2);
        } else {
            hasCoupon = false;
        }
        PDDGoodsDetail pddGoods = PinDuoDuoApiUtil.getGoodsDetail(id);
        if (pddGoods == null) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("商品信息获取失败")));
            return;
        }
        String jumpLink = PinDuoDuoApiUtil.getPromotionUrl(pddGoods.getGoodsSign(), PinDuoDuoApiUtil.PID_SHARE + "", uid);
        List<String> imageList = null;
        String[] goodsGalleryUrls = pddGoods.getGoodsGalleryUrls();
        if (goodsGalleryUrls != null) {
            imageList = Arrays.asList(goodsGalleryUrls);
        }
        if (imageList == null) {
            imageList = new ArrayList<>();
            String goodsImageUrl = pddGoods.getGoodsImageUrl();
            if (!StringUtil.isNullOrEmpty(goodsImageUrl)) {
                imageList.add(goodsImageUrl);
            }
        }
        JSONObject data = new JSONObject();
        data.put("imgs", imageList);
        data.put("title", pddGoods.getGoodsName());
        data.put("zkPrice", MoneyBigDecimalUtil.div(new BigDecimal(pddGoods.getMinGroupPrice()), hundred).setScale(2));
        data.put("coupon", hasCoupon);
        data.put("couponAmount", amount);
        data.put("couponPrice", PinDuoDuoUtil.getCouponPrice(pddGoods));
        data.put("helpLink", configService.getValue("pdd_share_h5_help_link",acceptData.getSystem()));
        data.put("jumpLink", jumpLink);
        JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
        BigDecimal hundred = new BigDecimal(100);
        Boolean hasCoupon = pddGoods.getHasCoupon();
        BigDecimal amount = new BigDecimal(0);
        if (hasCoupon != null && hasCoupon) {
            amount = MoneyBigDecimalUtil.div(new BigDecimal(pddGoods.getCouponDiscount()), hundred).setScale(2);
        } else {
            hasCoupon = false;
        }
        final String tempUid = uid;
        ThreadUtil.run(new Runnable() {
            @Override
            public void run() {
                try {
                    if (!StringUtil.isNullOrEmpty(tempUid))
                        userShareGoodsGroupService.updateBrowseNum(Long.parseLong(tempUid), id,
                                Constant.SOURCE_TYPE_PDD);
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                } catch (UserShareGoodsRecordException e) {
                    e.printStackTrace();
                }
            }
        });
        return;
    }
        String jumpLink = PinDuoDuoApiUtil.getPromotionUrl(pddGoods.getGoodsSign(), pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_PDD, SystemPIDInfo.PidType.share), uid);
        JSONObject data = new JSONObject();
        data.put("imgs", imageList);
        data.put("title", pddGoods.getGoodsName());
        data.put("zkPrice", MoneyBigDecimalUtil.div(new BigDecimal(pddGoods.getMinGroupPrice()), hundred).setScale(2));
        data.put("coupon", hasCoupon);
        data.put("couponAmount", amount);
        data.put("couponPrice", PinDuoDuoUtil.getCouponPrice(pddGoods));
        data.put("helpLink", configService.getValue("pdd_share_h5_help_link", acceptData.getSystem()));
        data.put("jumpLink", jumpLink);
        JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
        final String tempUid = uid;
        ThreadUtil.run(new Runnable() {
            @Override
            public void run() {
                try {
                    if (!StringUtil.isNullOrEmpty(tempUid))
                        userShareGoodsGroupService.updateBrowseNum(Long.parseLong(tempUid), id,
                                Constant.SOURCE_TYPE_PDD);
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                } catch (UserShareGoodsRecordException e) {
                    e.printStackTrace();
                }
            }
        });
        return;
    }
}
fanli/src/main/java/com/yeshi/fanli/controller/wxmp/v1/DynamicController.java
@@ -6,6 +6,8 @@
import javax.annotation.Resource;
import com.yeshi.fanli.entity.SystemPIDInfo;
import com.yeshi.fanli.service.manger.PIDManager;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.yeshi.utils.JsonUtil;
@@ -40,6 +42,9 @@
    @Resource
    private SpecialService specialService;
    @Resource
    private PIDManager pidManager;
    /**
     * 首页专题
@@ -184,7 +189,7 @@
            JSONObject paramsJson = JSONObject.fromObject(params);
            // 京东转链
            String url = paramsJson.optString("url");
            String link = JDApiUtil.convertLinkWithSubUnionId(url, null, null,JDApiUtil.POSITION_FANLI + "", uid + "");
            String link = JDApiUtil.convertLinkWithSubUnionId(url, null, null,   pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_JD, SystemPIDInfo.PidType.fanli), uid + "");
            if (StringUtil.isNullOrEmpty(link)) {
                out.print(JsonUtil.loadFalseResult("转链失败"));
fanli/src/main/java/com/yeshi/fanli/controller/wxmp/v1/GoodsController.java
@@ -11,6 +11,8 @@
import javax.annotation.Resource;
import com.yeshi.fanli.entity.SystemEnum;
import com.yeshi.fanli.entity.SystemPIDInfo;
import com.yeshi.fanli.service.manger.PIDManager;
import com.yeshi.fanli.util.*;
import com.yeshi.fanli.vo.pdd.PDDConvertLinkResultVO;
import org.json.simple.JSONArray;
@@ -86,897 +88,893 @@
@RequestMapping("/wxmp/api/v1/goods")
public class GoodsController {
    @Resource
    private ConfigService configService;
    @Resource
    private ConfigService configService;
    @Resource
    private ShamUserService shamUserService;
    @Resource
    private ShamUserService shamUserService;
    @Resource
    private CollectionGoodsV2Service collectionGoodsV2Service;
    @Resource
    private CollectionGoodsV2Service collectionGoodsV2Service;
    @Resource
    private HongBaoManageService hongBaoManageService;
    @Resource
    private OrderHongBaoMoneyComputeService orderHongBaoMoneyComputeService;
    @Resource
    private HongBaoManageService hongBaoManageService;
    @Resource
    private UserInfoExtraService userInfoExtraService;
    @Resource
    private OrderHongBaoMoneyComputeService orderHongBaoMoneyComputeService;
    @Resource
    private ScanHistoryV2Service scanHistoryV2Service;
    @Resource
    private UserInfoExtraService userInfoExtraService;
    @Resource
    private UserInfoService userInfoService;
    @Resource
    private ScanHistoryV2Service scanHistoryV2Service;
    @Resource
    private JDGoodsCacheUtil jdGoodsCacheUtil;
    @Resource
    private UserInfoService userInfoService;
    @Resource
    private PinDuoDuoCacheUtil pinDuoDuoCacheUtil;
    @Resource
    private JDGoodsCacheUtil jdGoodsCacheUtil;
    @Resource
    private JumpDetailV2Service jumpDetailV2Service;
    @Resource
    private PinDuoDuoCacheUtil pinDuoDuoCacheUtil;
    @Resource
    private JDGoodsClassService jdGoodsClassService;
    @Resource
    private JumpDetailV2Service jumpDetailV2Service;
    @Resource
    private UserVIPInfoService userVIPInfoService;
    @Resource
    private JDGoodsClassService jdGoodsClassService;
    @Resource
    private QrCodeService qrCodeService;
    @Resource
    private UserVIPInfoService userVIPInfoService;
    @Resource
    private ShareGoodsService shareGoodsService;
    @Resource
    private QrCodeService qrCodeService;
    @Resource
    private UserShareGoodsRecordService userShareGoodsRecordService;
    @Resource
    private ShareGoodsService shareGoodsService;
    @Resource
    private SwiperPictureService swiperPictureService;
    @Resource
    private UserShareGoodsRecordService userShareGoodsRecordService;
    @Resource
    private HongBaoV2CountService hongBaoV2CountService;
    @Resource
    private SwiperPictureService swiperPictureService;
    /**
     * 一级分类
     *
     * @param acceptData
     * @param out
     */
    @RequestMapping(value = "getTopCategory", method = RequestMethod.POST)
    public void getTopCategory(WXMPAcceptData acceptData, Long uid, PrintWriter out) {
    @Resource
    private HongBaoV2CountService hongBaoV2CountService;
        SystemEnum system= SystemInfoUtil.getSystemByWXCXCAppId(acceptData.getAppId());
        JSONObject data = new JSONObject();
        data.put("list", configService.getValue(ConfigKeyEnum.jdWXMPClass.getKey(),system));
        String tips = null;
        if (uid == null || uid <= 0) {
            tips = configService.getValue(ConfigKeyEnum.tipGuideNewUser.getKey(),system);
        } else {
            long rebateOrder = hongBaoV2CountService.countRebateOrder(uid);
            long shareOrInviteOrder = hongBaoV2CountService.countShareOrInviteOrder(uid);
            if (rebateOrder + shareOrInviteOrder >= 3) {
                // 熟客版
            } else if (rebateOrder <= 0 && shareOrInviteOrder <= 0) {
                // 新人版
                tips = configService.getValue(ConfigKeyEnum.tipGuideNewUser.getKey(),system);
            } else if (rebateOrder > 0 && shareOrInviteOrder <= 0) {
                // 省钱版
                tips = configService.getValue(ConfigKeyEnum.tipGuideSaveMoney.getKey(),system);
            } else {
                // 赚钱版
                tips = configService.getValue(ConfigKeyEnum.tipGuideShareInvite.getKey(),system);
            }
        }
    @Resource
    private PIDManager pidManager;
        if (!StringUtil.isNullOrEmpty(tips)) {
            JSONObject tipData = JSONObject.fromObject(tips);
            data.put("tipData", tipData);
        }
    /**
     * 一级分类
     *
     * @param acceptData
     * @param out
     */
    @RequestMapping(value = "getTopCategory", method = RequestMethod.POST)
    public void getTopCategory(WXMPAcceptData acceptData, Long uid, PrintWriter out) {
        out.print(JsonUtil.loadTrueResult(data));
    }
        SystemEnum system = SystemInfoUtil.getSystemByWXCXCAppId(acceptData.getAppId());
        JSONObject data = new JSONObject();
        data.put("list", configService.getValue(ConfigKeyEnum.jdWXMPClass.getKey(), system));
    /**
     * 一级分类商品
     *
     * @param acceptData
     * @param out
     */
    @RequestMapping(value = "getCategoryRecommend", method = RequestMethod.POST)
    public void getCategoryRecommend(WXMPAcceptData acceptData, Long cid, Integer page, PrintWriter out) {
        if (cid == null) {
            out.print(JsonUtil.loadFalseResult("分类ID为空"));
            return;
        }
        String tips = null;
        if (uid == null || uid <= 0) {
            tips = configService.getValue(ConfigKeyEnum.tipGuideNewUser.getKey(), system);
        } else {
            long rebateOrder = hongBaoV2CountService.countRebateOrder(uid);
            long shareOrInviteOrder = hongBaoV2CountService.countShareOrInviteOrder(uid);
            if (rebateOrder + shareOrInviteOrder >= 3) {
                // 熟客版
            } else if (rebateOrder <= 0 && shareOrInviteOrder <= 0) {
                // 新人版
                tips = configService.getValue(ConfigKeyEnum.tipGuideNewUser.getKey(), system);
            } else if (rebateOrder > 0 && shareOrInviteOrder <= 0) {
                // 省钱版
                tips = configService.getValue(ConfigKeyEnum.tipGuideSaveMoney.getKey(), system);
            } else {
                // 赚钱版
                tips = configService.getValue(ConfigKeyEnum.tipGuideShareInvite.getKey(), system);
            }
        }
        JSONObject data = new JSONObject();
        if (page == 1) {
            // 轮播图
            String platform = acceptData.getPlatform();
            int version = Integer.parseInt(acceptData.getVersion());
            List<BannerVO> picList = swiperPictureService.getByBannerCardAndVersion("index_top", platform,
                    version,acceptData.getSystem());
            if (picList == null) {
                picList = new ArrayList<>();
            }
        if (!StringUtil.isNullOrEmpty(tips)) {
            JSONObject tipData = JSONObject.fromObject(tips);
            data.put("tipData", tipData);
        }
            for (BannerVO swiper : picList) {
                JSONObject params = null;
                if (StringUtil.isNullOrEmpty(swiper.getParams())) {
                    params = JSONObject.fromObject(swiper.getParams());
                }
                swiper.setJumpDetail(JumpDetailUtil.getWXMPJumDetail(swiper.getJumpDetail()));
            }
            data.put("bannerList", JsonUtil.getApiCommonGson().toJson(picList));
        }
        out.print(JsonUtil.loadTrueResult(data));
    }
        JDFilter filterAPI = new JDFilter();
        filterAPI.setPageIndex(page);
        filterAPI.setPageSize(Constant.PAGE_SIZE);
        filterAPI.setIsCoupon(1); // 有券
        filterAPI.setIsHot(1); // 爆款
        filterAPI.setCid1(cid);
        JDSearchResult result = JDApiUtil.queryByKey(filterAPI);
    /**
     * 一级分类商品
     *
     * @param acceptData
     * @param out
     */
    @RequestMapping(value = "getCategoryRecommend", method = RequestMethod.POST)
    public void getCategoryRecommend(WXMPAcceptData acceptData, Long cid, Integer page, PrintWriter out) {
        if (cid == null) {
            out.print(JsonUtil.loadFalseResult("分类ID为空"));
            return;
        }
        long count = 0;
        JSONArray array = new JSONArray();
        if (result != null) {
            PageEntity pageEntity = result.getPageEntity();
            if (pageEntity != null) {
                count = pageEntity.getTotalCount();
            }
        JSONObject data = new JSONObject();
        if (page == 1) {
            // 轮播图
            String platform = acceptData.getPlatform();
            int version = Integer.parseInt(acceptData.getVersion());
            List<BannerVO> picList = swiperPictureService.getByBannerCardAndVersion("index_top", platform,
                    version, acceptData.getSystem());
            if (picList == null) {
                picList = new ArrayList<>();
            }
            List<JDGoods> goodsList = result.getGoodsList();
            if (goodsList != null && goodsList.size() > 0) {
                Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
                        .excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
                GoodsMoneyConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
                        acceptData.getVersion(),acceptData.getSystem());
                for (JDGoods goods : goodsList) {
                    GoodsDetailVO goodsDetailVO = GoodsDetailVOFactory.convertJDGoods(goods, paramsDTO);
                    if (goodsDetailVO.isHasCoupon()) {
                        array.add(gson.toJson(goodsDetailVO));
                    }
                }
            }
        }
            for (BannerVO swiper : picList) {
                JSONObject params = null;
                if (StringUtil.isNullOrEmpty(swiper.getParams())) {
                    params = JSONObject.fromObject(swiper.getParams());
                }
                swiper.setJumpDetail(JumpDetailUtil.getWXMPJumDetail(swiper.getJumpDetail()));
            }
            data.put("bannerList", JsonUtil.getApiCommonGson().toJson(picList));
        }
        data.put("count", count);
        data.put("list", array);
        out.print(JsonUtil.loadTrueResult(data));
    }
        JDFilter filterAPI = new JDFilter();
        filterAPI.setPageIndex(page);
        filterAPI.setPageSize(Constant.PAGE_SIZE);
        filterAPI.setIsCoupon(1); // 有券
        filterAPI.setIsHot(1); // 爆款
        filterAPI.setCid1(cid);
        JDSearchResult result = JDApiUtil.queryByKey(filterAPI);
    /**
     * 获取商品详情
     *
     * @param acceptData
     * @param goodsId
     *            商品id
     * @param uid
     *            邀请码
     * @param goodsType
     *            商品类型
     * @param from
     *            页面来源
     * @param out
     */
    @RequestMapping(value = "getGoodsDetial")
    public void getGoodsDetial(WXMPAcceptData acceptData, Long goodsId, Integer goodsType, String from, Long uid,
            PrintWriter out) {
        if (goodsType == null || goodsType < 2 || goodsType > 3) {
            out.print(JsonUtil.loadFalseResult(1, "请传递正确平台参数"));
            return;
        }
        long count = 0;
        JSONArray array = new JSONArray();
        if (result != null) {
            PageEntity pageEntity = result.getPageEntity();
            if (pageEntity != null) {
                count = pageEntity.getTotalCount();
            }
        /*--------- 京东商品  -------*/
        if (goodsType.intValue() == Constant.SOURCE_TYPE_JD) {
            getDetialJD(acceptData, goodsId, uid, from, out);
            return;
        }
            List<JDGoods> goodsList = result.getGoodsList();
            if (goodsList != null && goodsList.size() > 0) {
                Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
                        .excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
                GoodsMoneyConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
                        acceptData.getVersion(), acceptData.getSystem());
                for (JDGoods goods : goodsList) {
                    GoodsDetailVO goodsDetailVO = GoodsDetailVOFactory.convertJDGoods(goods, paramsDTO);
                    if (goodsDetailVO.isHasCoupon()) {
                        array.add(gson.toJson(goodsDetailVO));
                    }
                }
            }
        }
        /*-------- 拼多多商品  -------*/
        if (goodsType.intValue() == Constant.SOURCE_TYPE_PDD) {
            getDetialPDD(acceptData, goodsId, uid, from, out);
            return;
        }
    }
        data.put("count", count);
        data.put("list", array);
        out.print(JsonUtil.loadTrueResult(data));
    }
    /**
     * 京东商品详情
     *
     * @param acceptData
     * @param id
     * @param uid
     * @param from
     * @param out
     */
    private void getDetialJD(WXMPAcceptData acceptData, Long id, Long uid, String from, PrintWriter out) {
        JDGoods jdGoods = JDApiUtil.queryGoodsDetail(id); // 高级接口
        if (jdGoods == null) {
            jdGoods = JDUtil.getGoodsDetail(id); // 爬取网页
            // jdGoods = JDApiUtil.getGoodsDetail(id); // 普通接口
        }
    /**
     * 获取商品详情
     *
     * @param acceptData
     * @param goodsId    商品id
     * @param uid        邀请码
     * @param goodsType  商品类型
     * @param from       页面来源
     * @param out
     */
    @RequestMapping(value = "getGoodsDetial")
    public void getGoodsDetial(WXMPAcceptData acceptData, Long goodsId, Integer goodsType, String from, Long uid,
                               PrintWriter out) {
        if (goodsType == null || goodsType < 2 || goodsType > 3) {
            out.print(JsonUtil.loadFalseResult(1, "请传递正确平台参数"));
            return;
        }
        if (jdGoods == null) {
            out.print(JsonUtil.loadFalseResult(2, "商品不存在"));
            return;
        }
        /*--------- 京东商品  -------*/
        if (goodsType.intValue() == Constant.SOURCE_TYPE_JD) {
            getDetialJD(acceptData, goodsId, uid, from, out);
            return;
        }
        List<String> imageList = jdGoods.getImageList();
        if (imageList == null) {
            imageList = new ArrayList<String>();
            imageList.add(jdGoods.getPicUrl());
        }
        /*-------- 拼多多商品  -------*/
        if (goodsType.intValue() == Constant.SOURCE_TYPE_PDD) {
            getDetialPDD(acceptData, goodsId, uid, from, out);
            return;
        }
    }
        // 保存缓存
        jdGoodsCacheUtil.saveGoodsInfo(jdGoods);
    /**
     * 京东商品详情
     *
     * @param acceptData
     * @param id
     * @param uid
     * @param from
     * @param out
     */
    private void getDetialJD(WXMPAcceptData acceptData, Long id, Long uid, String from, PrintWriter out) {
        JDGoods jdGoods = JDApiUtil.queryGoodsDetail(id); // 高级接口
        if (jdGoods == null) {
            jdGoods = JDUtil.getGoodsDetail(id); // 爬取网页
            // jdGoods = JDApiUtil.getGoodsDetail(id); // 普通接口
        }
        GoodsMoneyConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
                acceptData.getVersion(),acceptData.getSystem());
        paramsDTO.setMaxRewardRate(null);
        GoodsDetailVO goodsDetail = GoodsDetailVOFactory.convertJDGoods(jdGoods, paramsDTO);
        if (goodsDetail != null && goodsDetail.getMoneyInfo() != null && userVIPInfoService.isVIP(uid)) {
            goodsDetail.getMoneyInfo().setFanliMoney(goodsDetail.getMoneyInfo().getMaxMoney());
            goodsDetail.getMoneyInfo()
                    .setShareMoney("¥" + JDUtil.getGoodsFanLiMoney(jdGoods, hongBaoManageService.getShareRate(UserLevelEnum.superVIP,acceptData.getSystem())));
            goodsDetail.getMoneyInfo().setRateInfo(goodsDetail.getMoneyInfo().getMaxRateInfo());
            goodsDetail.getMoneyInfo().setCompositionInfo(goodsDetail.getMoneyInfo().getMaxCompositionInfo());
        }
        goodsDetail.getMoneyInfo()
                .setRateInfoHelpUrl(configService.getValue(ConfigKeyEnum.goodsDetailFanliRateHelpUrl.getKey(),acceptData.getSystem()));
        if (jdGoods == null) {
            out.print(JsonUtil.loadFalseResult(2, "商品不存在"));
            return;
        }
        // 附加信息
        OtherInfo otherInfo = new OtherInfo();
        List<String> imageList = jdGoods.getImageList();
        if (imageList == null) {
            imageList = new ArrayList<String>();
            imageList.add(jdGoods.getPicUrl());
        }
        // 京东plus返利
        String maxMoneyPlus = null;
        JDCategoryInfo categoryInfo = jdGoods.getCategoryInfo();
        if (categoryInfo != null && categoryInfo.getCid3() != null && jdGoods.getCommissionInfo() != null) {
            Long cid3 = categoryInfo.getCid3();
            JDGoodsClass threeClass = jdGoodsClassService.getThreeClassByCid(Integer.parseInt(cid3.toString()));
            if (threeClass != null && threeClass.getSelfComm() != null
                    && threeClass.getSelfComm().compareTo(new BigDecimal(0)) > 0) {
                BigDecimal commissionShare = jdGoods.getCommissionInfo().getCommissionShare();
                // plus比例 小于正常比例
                if (commissionShare != null && commissionShare.compareTo(threeClass.getSelfComm()) > 0) {
                    jdGoods.setCommissionPlus(threeClass.getSelfComm());
                    // plus返利
                    BigDecimal fanliMoneyPlus = JDUtil.getGoodsFanLiMoneyPlus(jdGoods,
                            hongBaoManageService.getFanLiRate(acceptData.getSystem()));
                    otherInfo.setFanliMoneyPlus("京东plus返¥" + fanliMoneyPlus);
                    // 使用奖励券最高返
        // 保存缓存
        jdGoodsCacheUtil.saveGoodsInfo(jdGoods);
                    maxMoneyPlus = "(京东plus返¥"
                            + JDUtil.getGoodsFanLiMoneyPlus(jdGoods, hongBaoManageService.getFanLiRate(UserLevelEnum.superVIP,acceptData.getSystem())) + ")";
        GoodsMoneyConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
                acceptData.getVersion(), acceptData.getSystem());
        paramsDTO.setMaxRewardRate(null);
        GoodsDetailVO goodsDetail = GoodsDetailVOFactory.convertJDGoods(jdGoods, paramsDTO);
        if (goodsDetail != null && goodsDetail.getMoneyInfo() != null && userVIPInfoService.isVIP(uid)) {
            goodsDetail.getMoneyInfo().setFanliMoney(goodsDetail.getMoneyInfo().getMaxMoney());
            goodsDetail.getMoneyInfo()
                    .setShareMoney("¥" + JDUtil.getGoodsFanLiMoney(jdGoods, hongBaoManageService.getShareRate(UserLevelEnum.superVIP, acceptData.getSystem())));
            goodsDetail.getMoneyInfo().setRateInfo(goodsDetail.getMoneyInfo().getMaxRateInfo());
            goodsDetail.getMoneyInfo().setCompositionInfo(goodsDetail.getMoneyInfo().getMaxCompositionInfo());
        }
                }
            }
        }
        goodsDetail.getMoneyInfo()
                .setRateInfoHelpUrl(configService.getValue(ConfigKeyEnum.goodsDetailFanliRateHelpUrl.getKey(), acceptData.getSystem()));
        // 奖励券返利
        RewardCouponVO rewardCoupon = new RewardCouponVO();
        rewardCoupon.setMaxMoneyPlus(maxMoneyPlus);
        // 附加信息
        OtherInfo otherInfo = new OtherInfo();
        rewardCoupon.setMaxMoney(goodsDetail.getMoneyInfo().getMaxMoney());
        rewardCoupon.setDesc("返");
        otherInfo.setRewardCoupon(rewardCoupon);
        goodsDetail.setOtherInfo(otherInfo);
        // 京东plus返利
        String maxMoneyPlus = null;
        JDCategoryInfo categoryInfo = jdGoods.getCategoryInfo();
        if (categoryInfo != null && categoryInfo.getCid3() != null && jdGoods.getCommissionInfo() != null) {
            Long cid3 = categoryInfo.getCid3();
            JDGoodsClass threeClass = jdGoodsClassService.getThreeClassByCid(Integer.parseInt(cid3.toString()));
            if (threeClass != null && threeClass.getSelfComm() != null
                    && threeClass.getSelfComm().compareTo(new BigDecimal(0)) > 0) {
                BigDecimal commissionShare = jdGoods.getCommissionInfo().getCommissionShare();
                // plus比例 小于正常比例
                if (commissionShare != null && commissionShare.compareTo(threeClass.getSelfComm()) > 0) {
                    jdGoods.setCommissionPlus(threeClass.getSelfComm());
                    // plus返利
                    BigDecimal fanliMoneyPlus = JDUtil.getGoodsFanLiMoneyPlus(jdGoods,
                            hongBaoManageService.getFanLiRate(acceptData.getSystem()));
                    otherInfo.setFanliMoneyPlus("京东plus返¥" + fanliMoneyPlus);
                    // 使用奖励券最高返
        CouponInfoVO couponInfo = goodsDetail.getCouponInfo();
        if (couponInfo != null) {
            // 券链接处理
            String materialId = "https://item.jd.com/" + id + ".html";
            String url = JDApiUtil.convertLinkWithSubUnionId(materialId, couponInfo.getLink(),
                    null,JDApiUtil.POSITION_COUPON + "", null);
            couponInfo.setLink(url);
        }
                    maxMoneyPlus = "(京东plus返¥"
                            + JDUtil.getGoodsFanLiMoneyPlus(jdGoods, hongBaoManageService.getFanLiRate(UserLevelEnum.superVIP, acceptData.getSystem())) + ")";
        ShopInfoVO shopInfo = goodsDetail.getShopInfo();
        if (shopInfo != null) {
            if (shopInfo.getId() == null || shopInfo.getScoreGoods() == null || shopInfo.getScoreLogistics() == null
                    || shopInfo.getScoreSeller() == null) {
                goodsDetail.setShopInfo(null);
            }
        }
                }
            }
        }
        GoodsDetailExtraVO extraVO = new GoodsDetailExtraVO();
        extraVO.setIsNative(false);
        // IOS是否正在上线
        if ("ios".equalsIgnoreCase(acceptData.getPlatform())) {
            String version = acceptData.getVersion();
            extraVO.setIosOnling(configService.iosOnLining(Integer.parseInt(version),acceptData.getSystem()));
        }
        // 奖励券返利
        RewardCouponVO rewardCoupon = new RewardCouponVO();
        rewardCoupon.setMaxMoneyPlus(maxMoneyPlus);
        Long inOrderCount30Days = jdGoods.getInOrderCount30Days();
        List<ShamUser> listShareUser = new ArrayList<ShamUser>();
        rewardCoupon.setMaxMoney(goodsDetail.getMoneyInfo().getMaxMoney());
        rewardCoupon.setDesc("返");
        otherInfo.setRewardCoupon(rewardCoupon);
        goodsDetail.setOtherInfo(otherInfo);
        // 京东开启分享
        String open = configService.getValue(ConfigKeyEnum.shareOpenJD.getKey(),acceptData.getSystem());
        if ("1".equals(open.trim())) {
            extraVO.setShareValid(true);
            MoneyInfoVO moneyInfo = goodsDetail.getMoneyInfo();
            if (moneyInfo != null) {
                String shareMoney = moneyInfo.getShareMoney().replaceAll("¥", "");
                if (Integer.parseInt(inOrderCount30Days.toString()) >= 1000) {
                    listShareUser.addAll(shamUserService.listRandShareUser(10, new BigDecimal(shareMoney), 1, 5));
                }
            }
        }
        CouponInfoVO couponInfo = goodsDetail.getCouponInfo();
        if (couponInfo != null) {
            // 券链接处理
            String materialId = "https://item.jd.com/" + id + ".html";
            String url = JDApiUtil.convertLinkWithSubUnionId(materialId, couponInfo.getLink(),
                    null, pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_JD, SystemPIDInfo.PidType.coupon), null);
            couponInfo.setLink(url);
        }
        extraVO.setListShareUser(listShareUser);
        ShopInfoVO shopInfo = goodsDetail.getShopInfo();
        if (shopInfo != null) {
            if (shopInfo.getId() == null || shopInfo.getScoreGoods() == null || shopInfo.getScoreLogistics() == null
                    || shopInfo.getScoreSeller() == null) {
                goodsDetail.setShopInfo(null);
            }
        }
        // 领券人列表
        List<ShamUser> listCouponUser = new ArrayList<ShamUser>();
        if (goodsDetail.isHasCoupon() && Integer.parseInt(inOrderCount30Days.toString()) >= 1000) {
            listCouponUser = shamUserService.listRandCouponUser(5, 1, 300);
        }
        extraVO.setListCouponUser(listCouponUser);
        GoodsDetailExtraVO extraVO = new GoodsDetailExtraVO();
        extraVO.setIsNative(false);
        // IOS是否正在上线
        if ("ios".equalsIgnoreCase(acceptData.getPlatform())) {
            String version = acceptData.getVersion();
            extraVO.setIosOnling(configService.iosOnLining(Integer.parseInt(version), acceptData.getSystem()));
        }
        if (uid != null) {
            // 是否加入收藏
            CollectionGoodsV2 collectionGoods = collectionGoodsV2Service.findByUidAndAuctionId(uid, id,
                    Constant.SOURCE_TYPE_JD);
            extraVO.setCollected(collectionGoods != null ? true : false);
        }
        Long inOrderCount30Days = jdGoods.getInOrderCount30Days();
        List<ShamUser> listShareUser = new ArrayList<ShamUser>();
        // 图文详情
        extraVO.setDetailUrl("https://in.m.jd.com/product/jieshao/video/" + id + ".html");
        // 京东开启分享
        String open = configService.getValue(ConfigKeyEnum.shareOpenJD.getKey(), acceptData.getSystem());
        if ("1".equals(open.trim())) {
            extraVO.setShareValid(true);
            MoneyInfoVO moneyInfo = goodsDetail.getMoneyInfo();
            if (moneyInfo != null) {
                String shareMoney = moneyInfo.getShareMoney().replaceAll("¥", "");
                if (Integer.parseInt(inOrderCount30Days.toString()) >= 1000) {
                    listShareUser.addAll(shamUserService.listRandShareUser(10, new BigDecimal(shareMoney), 1, 5));
                }
            }
        }
        // 商品链接
        String h5Url = String.format("http://%s%s?uid=%s&id=%s", configService.getH5Host(acceptData.getSystem()),
                Constant.systemCommonConfig.getShareGoodsPagePathJD(), "", id + "");
        try {
            extraVO.setH5Url(HttpUtil.getShortLink(h5Url));
        } catch (Exception e) {
            extraVO.setH5Url(h5Url);
        }
        extraVO.setListShareUser(listShareUser);
        String helpLink = null;
        extraVO.setFanliValid(true);
        // 领券人列表
        List<ShamUser> listCouponUser = new ArrayList<ShamUser>();
        if (goodsDetail.isHasCoupon() && Integer.parseInt(inOrderCount30Days.toString()) >= 1000) {
            listCouponUser = shamUserService.listRandCouponUser(5, 1, 300);
        }
        extraVO.setListCouponUser(listCouponUser);
        if (StringUtil.isNullOrEmpty(helpLink)) {
            helpLink = configService.getValue(ConfigKeyEnum.noRebateHelpLink.getKey(),acceptData.getSystem());
        }
        if (uid != null) {
            // 是否加入收藏
            CollectionGoodsV2 collectionGoods = collectionGoodsV2Service.findByUidAndAuctionId(uid, id,
                    Constant.SOURCE_TYPE_JD);
            extraVO.setCollected(collectionGoods != null ? true : false);
        }
        ShareVO shareInfoVO = new ShareVO();
        shareInfoVO.setHelpLink(helpLink);
        extraVO.setShare(shareInfoVO);
        // 图文详情
        extraVO.setDetailUrl("https://in.m.jd.com/product/jieshao/video/" + id + ".html");
        // 判断vip
        if (uid != null) {
            extraVO.setVip(userVIPInfoService.isVIP(uid));
        }
        JSONObject object = new JSONObject();
        object.put("extra", JsonUtil.getApiCommonGson().toJson(extraVO));
        object.put("goods", JsonUtil.getApiCommonGson().toJson(goodsDetail));
        out.print(JsonUtil.loadTrueResult(object.toString()));
        // 商品链接
        String h5Url = String.format("http://%s%s?uid=%s&id=%s", configService.getH5Host(acceptData.getSystem()),
                Constant.systemCommonConfig.getShareGoodsPagePathJD(), "", id + "");
        try {
            extraVO.setH5Url(HttpUtil.getShortLink(h5Url));
        } catch (Exception e) {
            extraVO.setH5Url(h5Url);
        }
        final JDGoods goods = jdGoods;
        ThreadUtil.run(new Runnable() {
            public void run() {
                // 添加浏览记录
                try {
                    scanHistoryV2Service.addJDScanHistory(uid, acceptData.getDevice(), goods);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
        String helpLink = null;
        extraVO.setFanliValid(true);
    /**
     * 拼多多商品详情
     *
     * @param acceptData
     * @param id
     * @param uid
     * @param from
     * @param out
     */
    private void getDetialPDD(WXMPAcceptData acceptData, Long id, Long uid, String from, PrintWriter out) {
        PDDGoodsDetail pddGoods =null; //PinDuoDuoApiUtil.getGoodsDetail(id);
        if (pddGoods == null) {
            out.print(JsonUtil.loadFalseResult(2, "商品不存在"));
            return;
        }
        if (StringUtil.isNullOrEmpty(helpLink)) {
            helpLink = configService.getValue(ConfigKeyEnum.noRebateHelpLink.getKey(), acceptData.getSystem());
        }
        GoodsMoneyConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
                acceptData.getVersion(),acceptData.getSystem());
        paramsDTO.setMaxRewardRate(null);
        GoodsDetailVO goodsDetail = GoodsDetailVOFactory.convertPDDGoods(pddGoods, paramsDTO);
        if (goodsDetail != null && goodsDetail.getMoneyInfo() != null && userVIPInfoService.isVIP(uid)) {
            goodsDetail.getMoneyInfo().setFanliMoney(goodsDetail.getMoneyInfo().getMaxMoney());
            goodsDetail.getMoneyInfo().setShareMoney(
                    "¥" + PinDuoDuoUtil.getGoodsFanLiMoney(pddGoods, hongBaoManageService.getShareRate(UserLevelEnum.superVIP,acceptData.getSystem())));
        }
        ShareVO shareInfoVO = new ShareVO();
        shareInfoVO.setHelpLink(helpLink);
        extraVO.setShare(shareInfoVO);
        if (goodsDetail.getCouponInfo() != null) {
            List<CouponInfoVO> list = new ArrayList<>();
            list.add(goodsDetail.getCouponInfo());
            goodsDetail.setCouponInfoList(list);
        }
        // 判断vip
        if (uid != null) {
            extraVO.setVip(userVIPInfoService.isVIP(uid));
        }
        JSONObject object = new JSONObject();
        object.put("extra", JsonUtil.getApiCommonGson().toJson(extraVO));
        object.put("goods", JsonUtil.getApiCommonGson().toJson(goodsDetail));
        out.print(JsonUtil.loadTrueResult(object.toString()));
        // 奖励券返利
        RewardCouponVO rewardCoupon = new RewardCouponVO();
        final JDGoods goods = jdGoods;
        ThreadUtil.run(new Runnable() {
            public void run() {
                // 添加浏览记录
                try {
                    scanHistoryV2Service.addJDScanHistory(uid, acceptData.getDevice(), goods);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
        rewardCoupon.setMaxMoney(goodsDetail.getMoneyInfo().getMaxMoney());
        rewardCoupon.setDesc("返");
    /**
     * 拼多多商品详情
     *
     * @param acceptData
     * @param id
     * @param uid
     * @param from
     * @param out
     */
    private void getDetialPDD(WXMPAcceptData acceptData, Long id, Long uid, String from, PrintWriter out) {
        PDDGoodsDetail pddGoods = null; //PinDuoDuoApiUtil.getGoodsDetail(id);
        if (pddGoods == null) {
            out.print(JsonUtil.loadFalseResult(2, "商品不存在"));
            return;
        }
        OtherInfo otherInfo = new OtherInfo();
        otherInfo.setRewardCoupon(rewardCoupon);
        goodsDetail.setOtherInfo(otherInfo);
        GoodsMoneyConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
                acceptData.getVersion(), acceptData.getSystem());
        paramsDTO.setMaxRewardRate(null);
        GoodsDetailVO goodsDetail = GoodsDetailVOFactory.convertPDDGoods(pddGoods, paramsDTO);
        if (goodsDetail != null && goodsDetail.getMoneyInfo() != null && userVIPInfoService.isVIP(uid)) {
            goodsDetail.getMoneyInfo().setFanliMoney(goodsDetail.getMoneyInfo().getMaxMoney());
            goodsDetail.getMoneyInfo().setShareMoney(
                    "¥" + PinDuoDuoUtil.getGoodsFanLiMoney(pddGoods, hongBaoManageService.getShareRate(UserLevelEnum.superVIP, acceptData.getSystem())));
        }
        CouponInfoVO couponInfo = goodsDetail.getCouponInfo();
        PDDConvertLinkResultVO convertUrl = null;
        if (couponInfo != null) {
            convertUrl = PinDuoDuoApiUtil.convert(pddGoods.getGoodsSign(), PinDuoDuoApiUtil.PID_COUPON + "", null,false);
            if (convertUrl != null)
                couponInfo.setLink(convertUrl.getUrl());
        }
        if (goodsDetail.getCouponInfo() != null) {
            List<CouponInfoVO> list = new ArrayList<>();
            list.add(goodsDetail.getCouponInfo());
            goodsDetail.setCouponInfoList(list);
        }
        ShopInfoVO shopInfo = goodsDetail.getShopInfo();
        if (shopInfo != null) {
            if (shopInfo.getId() == null || shopInfo.getScoreGoods() == null || shopInfo.getScoreLogistics() == null
                    || shopInfo.getScoreSeller() == null) {
                goodsDetail.setShopInfo(null);
            }
        }
        // 奖励券返利
        RewardCouponVO rewardCoupon = new RewardCouponVO();
        GoodsDetailExtraVO extraVO = new GoodsDetailExtraVO();
        extraVO.setDetailUrl("http://apph5.banliapp.com/apppage/goods_img_pdd.html?id=" + id);
        rewardCoupon.setMaxMoney(goodsDetail.getMoneyInfo().getMaxMoney());
        rewardCoupon.setDesc("返");
        String salesTip = pddGoods.getSalesTip();
        if (!StringUtil.isNullOrEmpty(salesTip)) {
            int indexOf = salesTip.indexOf("+");
            if (indexOf > 0) {
                salesTip = salesTip.substring(0, indexOf);
            }
        OtherInfo otherInfo = new OtherInfo();
        otherInfo.setRewardCoupon(rewardCoupon);
        goodsDetail.setOtherInfo(otherInfo);
            int totalSales = 0;
            if (salesTip.contains("万")) {
                salesTip = salesTip.substring(0, salesTip.indexOf("万"));
                totalSales = (int) (Float.parseFloat(salesTip) * 10000);
            } else {
                totalSales = Integer.parseInt(salesTip);
            }
        CouponInfoVO couponInfo = goodsDetail.getCouponInfo();
        PDDConvertLinkResultVO convertUrl = null;
        if (couponInfo != null) {
            convertUrl = PinDuoDuoApiUtil.convert(pddGoods.getGoodsSign(), pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_PDD, SystemPIDInfo.PidType.coupon), null, false);
            if (convertUrl != null)
                couponInfo.setLink(convertUrl.getUrl());
        }
        ShopInfoVO shopInfo = goodsDetail.getShopInfo();
        if (shopInfo != null) {
            if (shopInfo.getId() == null || shopInfo.getScoreGoods() == null || shopInfo.getScoreLogistics() == null
                    || shopInfo.getScoreSeller() == null) {
                goodsDetail.setShopInfo(null);
            }
        }
        GoodsDetailExtraVO extraVO = new GoodsDetailExtraVO();
        extraVO.setDetailUrl("http://apph5.banliapp.com/apppage/goods_img_pdd.html?id=" + id);
        String salesTip = pddGoods.getSalesTip();
        if (!StringUtil.isNullOrEmpty(salesTip)) {
            int indexOf = salesTip.indexOf("+");
            if (indexOf > 0) {
                salesTip = salesTip.substring(0, indexOf);
            }
            int totalSales = 0;
            if (salesTip.contains("万")) {
                salesTip = salesTip.substring(0, salesTip.indexOf("万"));
                totalSales = (int) (Float.parseFloat(salesTip) * 10000);
            } else {
                totalSales = Integer.parseInt(salesTip);
            }
            List<ShamUser> listShareUser = new ArrayList<ShamUser>();
            MoneyInfoVO moneyInfo = goodsDetail.getMoneyInfo();
            if (moneyInfo != null) {
                String shareMoney = moneyInfo.getShareMoney().replaceAll("¥", "");
                if (totalSales >= 50000) {
                    listShareUser = shamUserService.listRandShareUser(10, new BigDecimal(shareMoney), 1, 5);
                }
            }
            extraVO.setListShareUser(listShareUser);
            List<ShamUser> listShareUser = new ArrayList<ShamUser>();
            MoneyInfoVO moneyInfo = goodsDetail.getMoneyInfo();
            if (moneyInfo != null) {
                String shareMoney = moneyInfo.getShareMoney().replaceAll("¥", "");
                if (totalSales >= 50000) {
                    listShareUser = shamUserService.listRandShareUser(10, new BigDecimal(shareMoney), 1, 5);
                }
            }
            extraVO.setListShareUser(listShareUser);
            // 领券人列表
            List<ShamUser> listCouponUser = new ArrayList<ShamUser>();
            if (goodsDetail.isHasCoupon() && totalSales >= 50000) {
                listCouponUser = shamUserService.listRandCouponUser(5, 1, 300);
            }
            extraVO.setListCouponUser(listCouponUser);
        }
            // 领券人列表
            List<ShamUser> listCouponUser = new ArrayList<ShamUser>();
            if (goodsDetail.isHasCoupon() && totalSales >= 50000) {
                listCouponUser = shamUserService.listRandCouponUser(5, 1, 300);
            }
            extraVO.setListCouponUser(listCouponUser);
        }
        if (uid != null) {
            // 是否加入收藏
            CollectionGoodsV2 collectionGoods = collectionGoodsV2Service.findByUidAndAuctionId(uid, id,
                    Constant.SOURCE_TYPE_PDD);
            extraVO.setCollected(collectionGoods != null ? true : false);
        }
        if (uid != null) {
            // 是否加入收藏
            CollectionGoodsV2 collectionGoods = collectionGoodsV2Service.findByUidAndAuctionId(uid, id,
                    Constant.SOURCE_TYPE_PDD);
            extraVO.setCollected(collectionGoods != null ? true : false);
        }
        // 分享路径
        String h5Url = String.format("http://%s%s?uid=%s&id=%s", configService.getH5Host(acceptData.getSystem()),
                Constant.systemCommonConfig.getShareGoodsPagePathPDD(), "", id + "");
        try {
            extraVO.setH5Url(HttpUtil.getShortLink(h5Url));
        } catch (Exception e) {
            extraVO.setH5Url(h5Url);
        }
        // 分享路径
        String h5Url = String.format("http://%s%s?uid=%s&id=%s", configService.getH5Host(acceptData.getSystem()),
                Constant.systemCommonConfig.getShareGoodsPagePathPDD(), "", id + "");
        try {
            extraVO.setH5Url(HttpUtil.getShortLink(h5Url));
        } catch (Exception e) {
            extraVO.setH5Url(h5Url);
        }
        String helpLink = null;
        extraVO.setFanliValid(true);
        extraVO.setShareValid(true);
        String helpLink = null;
        extraVO.setFanliValid(true);
        extraVO.setShareValid(true);
        if (StringUtil.isNullOrEmpty(helpLink)) {
            helpLink = configService.getValue(ConfigKeyEnum.noRebateHelpLink.getKey(),acceptData.getSystem());
        }
        if (StringUtil.isNullOrEmpty(helpLink)) {
            helpLink = configService.getValue(ConfigKeyEnum.noRebateHelpLink.getKey(), acceptData.getSystem());
        }
        ShareVO shareInfoVO = new ShareVO();
        shareInfoVO.setHelpLink(helpLink);
        extraVO.setShare(shareInfoVO);
        ShareVO shareInfoVO = new ShareVO();
        shareInfoVO.setHelpLink(helpLink);
        extraVO.setShare(shareInfoVO);
        // 判断vip
        if (uid != null) {
            extraVO.setVip(userVIPInfoService.isVIP(uid));
        }
        // 判断vip
        if (uid != null) {
            extraVO.setVip(userVIPInfoService.isVIP(uid));
        }
        if (convertUrl != null) {
            extraVO.setCouponJumpLink(convertUrl.getUrl());
            extraVO.setNativeCouponJumpLink(PinDuoDuoUtil.getAndroidNativeURI(convertUrl.getUrl()));
        }
        if (convertUrl != null) {
            extraVO.setCouponJumpLink(convertUrl.getUrl());
            extraVO.setNativeCouponJumpLink(PinDuoDuoUtil.getAndroidNativeURI(convertUrl.getUrl()));
        }
        JSONObject object = new JSONObject();
        object.put("extra", JsonUtil.getApiCommonGson().toJson(extraVO));
        object.put("goods", JsonUtil.getApiCommonGson().toJson(goodsDetail));
        out.print(JsonUtil.loadTrueResult(object.toString()));
        JSONObject object = new JSONObject();
        object.put("extra", JsonUtil.getApiCommonGson().toJson(extraVO));
        object.put("goods", JsonUtil.getApiCommonGson().toJson(goodsDetail));
        out.print(JsonUtil.loadTrueResult(object.toString()));
        ThreadUtil.run(new Runnable() {
            public void run() {
                try {
                    scanHistoryV2Service.addPDDScanHistory(uid, acceptData.getDevice(), pddGoods);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
        ThreadUtil.run(new Runnable() {
            public void run() {
                try {
                    scanHistoryV2Service.addPDDScanHistory(uid, acceptData.getDevice(), pddGoods);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
    /**
     * 商品详情推荐(猜你喜欢 + 推荐)
     *
     * @param acceptData
     * @param id
     * @param out
     */
    @RequestMapping(value = "getRecommendGoods", method = RequestMethod.POST)
    public void getRecommendGoods(WXMPAcceptData acceptData, long id, Integer goodsType, PrintWriter out) {
        if (goodsType == null || goodsType < 2 || goodsType > 3) {
            out.print(JsonUtil.loadFalseResult(1, "请传递正确平台参数"));
            return;
        }
    /**
     * 商品详情推荐(猜你喜欢 + 推荐)
     *
     * @param acceptData
     * @param id
     * @param out
     */
    @RequestMapping(value = "getRecommendGoods", method = RequestMethod.POST)
    public void getRecommendGoods(WXMPAcceptData acceptData, long id, Integer goodsType, PrintWriter out) {
        if (goodsType == null || goodsType < 2 || goodsType > 3) {
            out.print(JsonUtil.loadFalseResult(1, "请传递正确平台参数"));
            return;
        }
        try {
            // 京东
            if (goodsType == Constant.SOURCE_TYPE_JD) {
                JSONObject data = new JSONObject();
                data.put("listGuess", JsonUtil.getApiCommonGson().toJson(new ArrayList<GoodsDetailVO>()));
        try {
            // 京东
            if (goodsType == Constant.SOURCE_TYPE_JD) {
                JSONObject data = new JSONObject();
                data.put("listGuess", JsonUtil.getApiCommonGson().toJson(new ArrayList<GoodsDetailVO>()));
                List<JDGoods> list = JDUtil.getRecommendGoodsById(id);
                if (list == null) {
                    list = new ArrayList<JDGoods>();
                } else if (list.size() > 10) {
                    list = list.subList(0, 10);
                }
                List<JDGoods> list = JDUtil.getRecommendGoodsById(id);
                if (list == null) {
                    list = new ArrayList<JDGoods>();
                } else if (list.size() > 10) {
                    list = list.subList(0, 10);
                }
                GoodsMoneyConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
                        acceptData.getVersion(),acceptData.getSystem());
                List<GoodsDetailVO> listDetailVO = new ArrayList<GoodsDetailVO>();
                GoodsMoneyConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
                        acceptData.getVersion(), acceptData.getSystem());
                List<GoodsDetailVO> listDetailVO = new ArrayList<GoodsDetailVO>();
                for (JDGoods goods : list) {
                    listDetailVO.add(GoodsDetailVOFactory.convertJDGoods(goods, paramsDTO));
                }
                for (JDGoods goods : list) {
                    listDetailVO.add(GoodsDetailVOFactory.convertJDGoods(goods, paramsDTO));
                }
                // 取偶数个数据
                if (listDetailVO.size() % 2 != 0) {
                    listDetailVO.remove(listDetailVO.size() - 1);
                }
                // 取偶数个数据
                if (listDetailVO.size() % 2 != 0) {
                    listDetailVO.remove(listDetailVO.size() - 1);
                }
                data.put("listQuality", JsonUtil.getApiCommonGson().toJson(listDetailVO));
                out.print(JsonUtil.loadTrueResult(data));
                return;
            }
                data.put("listQuality", JsonUtil.getApiCommonGson().toJson(listDetailVO));
                out.print(JsonUtil.loadTrueResult(data));
                return;
            }
            // 拼多多
            if (goodsType == Constant.SOURCE_TYPE_PDD) {
                JSONObject data = new JSONObject();
                data.put("listGuess", JsonUtil.getApiCommonGson().toJson(new ArrayList<GoodsDetailVO>()));
            // 拼多多
            if (goodsType == Constant.SOURCE_TYPE_PDD) {
                JSONObject data = new JSONObject();
                data.put("listGuess", JsonUtil.getApiCommonGson().toJson(new ArrayList<GoodsDetailVO>()));
                List<GoodsDetailVO> listDetailVO = new ArrayList<GoodsDetailVO>();
                List<GoodsDetailVO> listDetailVO = new ArrayList<GoodsDetailVO>();
                List<Long> goodsIdList = PinDuoDuoUtil.getRecommendGoodsId(id);
                if (goodsIdList != null && goodsIdList.size() > 0) {
                    PDDSearchFilter pddfilter = new PDDSearchFilter();
                    pddfilter.setPage(1);
                    pddfilter.setPageSize(Constant.PAGE_SIZE);
                    Long[] strings = new Long[goodsIdList.size()];
                    pddfilter.setGoodsIdList(goodsIdList.toArray(strings));
                List<Long> goodsIdList = PinDuoDuoUtil.getRecommendGoodsId(id);
                if (goodsIdList != null && goodsIdList.size() > 0) {
                    PDDSearchFilter pddfilter = new PDDSearchFilter();
                    pddfilter.setPage(1);
                    pddfilter.setPageSize(Constant.PAGE_SIZE);
                    Long[] strings = new Long[goodsIdList.size()];
                    pddfilter.setGoodsIdList(goodsIdList.toArray(strings));
                    PDDGoodsResult result = PinDuoDuoApiUtil.searchGoods(pddfilter,Constant.PDD_SEARCH_CUSTOMER_PARAMS);
                    if (result != null) {
                        List<PDDGoodsDetail> goodsList = result.getGoodsList();
                        if (goodsList != null && goodsList.size() > 0) {
                    PDDGoodsResult result = PinDuoDuoApiUtil.searchGoods(pddfilter, Constant.PDD_SEARCH_CUSTOMER_PARAMS);
                    if (result != null) {
                        List<PDDGoodsDetail> goodsList = result.getGoodsList();
                        if (goodsList != null && goodsList.size() > 0) {
                            if (goodsList.size() > 10) {
                                goodsList = goodsList.subList(0, 10);
                            }
                            if (goodsList.size() > 10) {
                                goodsList = goodsList.subList(0, 10);
                            }
                            GoodsMoneyConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService
                                    .getShowComputeRate(acceptData.getPlatform(), acceptData.getVersion(),acceptData.getSystem());
                            for (PDDGoodsDetail goods : goodsList) {
                                listDetailVO.add(GoodsDetailVOFactory.convertPDDGoods(goods, paramsDTO));
                            }
                        }
                    }
                }
                            GoodsMoneyConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService
                                    .getShowComputeRate(acceptData.getPlatform(), acceptData.getVersion(), acceptData.getSystem());
                            for (PDDGoodsDetail goods : goodsList) {
                                listDetailVO.add(GoodsDetailVOFactory.convertPDDGoods(goods, paramsDTO));
                            }
                        }
                    }
                }
                // 取偶数个数据
                if (listDetailVO.size() % 2 != 0) {
                    listDetailVO.remove(listDetailVO.size() - 1);
                }
                // 取偶数个数据
                if (listDetailVO.size() % 2 != 0) {
                    listDetailVO.remove(listDetailVO.size() - 1);
                }
                data.put("listQuality", JsonUtil.getApiCommonGson().toJson(listDetailVO));
                out.print(JsonUtil.loadTrueResult(data));
                return;
            }
        } catch (Exception e) {
            LogHelper.errorDetailInfo(e);
            JSONObject data = new JSONObject();
            data.put("listQuality", new JSONArray());
            data.put("listGuess", new JSONArray());
            out.print(JsonUtil.loadTrueResult(data));
        }
    }
                data.put("listQuality", JsonUtil.getApiCommonGson().toJson(listDetailVO));
                out.print(JsonUtil.loadTrueResult(data));
                return;
            }
        } catch (Exception e) {
            LogHelper.errorDetailInfo(e);
            JSONObject data = new JSONObject();
            data.put("listQuality", new JSONArray());
            data.put("listGuess", new JSONArray());
            out.print(JsonUtil.loadTrueResult(data));
        }
    }
    /**
     * 获取商品详情
     *
     * @param acceptData
     * @param goodsId
     *            商品id
     * @param uid
     *            邀请码
     * @param goodsType
     *            商品类型
     * @param from
     *            页面来源
     * @param out
     */
    @RequestMapping(value = "getBuyLink", method = RequestMethod.POST)
    public void getBuyLink(WXMPAcceptData acceptData, Long goodsId, Integer goodsType, String from, String couponUrl,
            Long uid, String inviteCode, PrintWriter out) {
        if (goodsId == null || goodsType == null) {
            out.print(JsonUtil.loadFalseResult(1, "商品信息传递错误"));
            return;
        }
    /**
     * 获取商品详情
     *
     * @param acceptData
     * @param goodsId    商品id
     * @param uid        邀请码
     * @param goodsType  商品类型
     * @param from       页面来源
     * @param out
     */
    @RequestMapping(value = "getBuyLink", method = RequestMethod.POST)
    public void getBuyLink(WXMPAcceptData acceptData, Long goodsId, Integer goodsType, String from, String couponUrl,
                           Long uid, String inviteCode, PrintWriter out) {
        if (goodsId == null || goodsType == null) {
            out.print(JsonUtil.loadFalseResult(1, "商品信息传递错误"));
            return;
        }
        // 判断是自购 还是根据邀请码
        boolean share = false;
        // 判断是自购 还是根据邀请码
        boolean share = false;
        String subUnionId = "";
        if (uid != null) {
            UserInfo user = userInfoService.getUserByIdWithMybatis(uid);
            if (user != null && user.getState() != UserInfo.STATE_NORMAL) {
                out.print(JsonUtil.loadFalseResult(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC));
                return;
            }
            subUnionId = uid.toString();
        } else if ((uid == null || uid < 1) && !StringUtil.isNullOrEmpty(inviteCode)) {
            try {
                UserInfo user = userInfoExtraService.getUserByInviteCode(inviteCode);
                if (user != null && user.getState() == UserInfo.STATE_NORMAL) {
                    share = true;
                    subUnionId = user.getId().toString();
                }
            } catch (UserInfoExtraException e) {
                e.printStackTrace();
            }
        }
        String subUnionId = "";
        if (uid != null) {
            UserInfo user = userInfoService.getUserByIdWithMybatis(uid);
            if (user != null && user.getState() != UserInfo.STATE_NORMAL) {
                out.print(JsonUtil.loadFalseResult(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC));
                return;
            }
            subUnionId = uid.toString();
        } else if ((uid == null || uid < 1) && !StringUtil.isNullOrEmpty(inviteCode)) {
            try {
                UserInfo user = userInfoExtraService.getUserByInviteCode(inviteCode);
                if (user != null && user.getState() == UserInfo.STATE_NORMAL) {
                    share = true;
                    subUnionId = user.getId().toString();
                }
            } catch (UserInfoExtraException e) {
                e.printStackTrace();
            }
        }
        String jumpLink = null;
        if (goodsType.intValue() == Constant.SOURCE_TYPE_JD) { // 京东
            JDGoods goods = jdGoodsCacheUtil.getGoodsInfo(goodsId);
            if (goods == null) {
                out.print(JsonUtil.loadFalseResult(2, "商品已下架"));
                return;
            }
        String jumpLink = null;
        if (goodsType.intValue() == Constant.SOURCE_TYPE_JD) { // 京东
            JDGoods goods = jdGoodsCacheUtil.getGoodsInfo(goodsId);
            if (goods == null) {
                out.print(JsonUtil.loadFalseResult(2, "商品已下架"));
                return;
            }
            String materialId = "https://item.jd.com/" + goodsId + ".html";
            if (StringUtil.isNullOrEmpty(couponUrl)) {
                JDCouponInfo couponInfo = JDUtil.getShowCouponInfo(goods.getCouponInfoList(), goods.getPrice());
                if (couponInfo != null) {
                    couponUrl = couponInfo.getLink();
                }
            }
            String materialId = "https://item.jd.com/" + goodsId + ".html";
            if (StringUtil.isNullOrEmpty(couponUrl)) {
                JDCouponInfo couponInfo = JDUtil.getShowCouponInfo(goods.getCouponInfoList(), goods.getPrice());
                if (couponInfo != null) {
                    couponUrl = couponInfo.getLink();
                }
            }
            long position = JDApiUtil.POSITION_FANLI;
            if (share) {
                position = JDApiUtil.POSITION_SHARE;
            }
            String jdLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, null,position + "", subUnionId);
            try {
                jumpLink = "/pages/union/proxy/proxy?spreadUrl=" + URLEncoder.encode(jdLink, "UTF-8");
            } catch (Exception e) {
                LogHelper.errorDetailInfo(e);
            }
        } else if (goodsType.intValue() == Constant.SOURCE_TYPE_PDD) { // 拼多多
            PDDGoodsDetail goods = pinDuoDuoCacheUtil.getGoodsInfo(goodsId);
            if (goods == null) {
                out.print(JsonUtil.loadFalseResult(2, "商品已下架"));
                return;
            }
            long position = Long.parseLong(pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_JD, SystemPIDInfo.PidType.fanli));
            if (share) {
                position = Long.parseLong(pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_JD, SystemPIDInfo.PidType.share));
            }
            String jdLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, null, position + "", subUnionId);
            try {
                jumpLink = "/pages/union/proxy/proxy?spreadUrl=" + URLEncoder.encode(jdLink, "UTF-8");
            } catch (Exception e) {
                LogHelper.errorDetailInfo(e);
            }
        } else if (goodsType.intValue() == Constant.SOURCE_TYPE_PDD) { // 拼多多
            PDDGoodsDetail goods = pinDuoDuoCacheUtil.getGoodsInfo(goodsId);
            if (goods == null) {
                out.print(JsonUtil.loadFalseResult(2, "商品已下架"));
                return;
            }
            String position = PinDuoDuoApiUtil.PID_FANLI;
            if (share) {
                position = PinDuoDuoApiUtil.PID_SHARE;
            }
            jumpLink = PinDuoDuoApiUtil.convertWXMP(goodsId, position, subUnionId);
        } else {
            out.print(JsonUtil.loadFalseResult(1, "参数传递错误"));
            return;
        }
            String position = pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_PDD, SystemPIDInfo.PidType.fanli);
            if (share) {
                position = pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_PDD, SystemPIDInfo.PidType.share);
            }
            jumpLink = PinDuoDuoApiUtil.convertWXMP(goodsId, position, subUnionId);
        } else {
            out.print(JsonUtil.loadFalseResult(1, "参数传递错误"));
            return;
        }
        if (StringUtil.isNullOrEmpty(jumpLink)) {
            out.print(JsonUtil.loadFalseResult(1, "创建购买信息失败"));
            return;
        }
        if (StringUtil.isNullOrEmpty(jumpLink)) {
            out.print(JsonUtil.loadFalseResult(1, "创建购买信息失败"));
            return;
        }
        JSONObject data = new JSONObject();
        data.put("goodsType", goodsType);
        data.put("jumpLink", jumpLink);
        out.print(JsonUtil.loadTrueResult(data));
    }
        JSONObject data = new JSONObject();
        data.put("goodsType", goodsType);
        data.put("jumpLink", jumpLink);
        out.print(JsonUtil.loadTrueResult(data));
    }
    /**
     * 分享商品海报
     *
     * @param acceptData
     * @param goodsId
     * @param goodsType
     * @param from
     * @param type
     * @param uid
     * @param out
     */
    @RequestMapping(value = "sharePoster", method = RequestMethod.POST)
    public void sharePoster(WXMPAcceptData acceptData, Long goodsId, Integer goodsType, String from, Integer type,
            Long uid, PrintWriter out) {
        if (uid == null || uid < 1) {
            out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
            return;
        }
    /**
     * 分享商品海报
     *
     * @param acceptData
     * @param goodsId
     * @param goodsType
     * @param from
     * @param type
     * @param uid
     * @param out
     */
    @RequestMapping(value = "sharePoster", method = RequestMethod.POST)
    public void sharePoster(WXMPAcceptData acceptData, Long goodsId, Integer goodsType, String from, Integer type,
                            Long uid, PrintWriter out) {
        if (uid == null || uid < 1) {
            out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
            return;
        }
        if (goodsId == null || goodsType == null) {
            out.print(JsonUtil.loadFalseResult(1, "商品信息传递错误"));
            return;
        }
        if (goodsId == null || goodsType == null) {
            out.print(JsonUtil.loadFalseResult(1, "商品信息传递错误"));
            return;
        }
        if (type == null || type < 1 || type > 2) {
            out.print(JsonUtil.loadFalseResult(1, "分享类型错误"));
            return;
        }
        if (type == null || type < 1 || type > 2) {
            out.print(JsonUtil.loadFalseResult(1, "分享类型错误"));
            return;
        }
        UserInfo user = userInfoService.getUserByIdWithMybatis(uid);
        if (user != null && user.getState() != UserInfo.STATE_NORMAL) {
            out.print(JsonUtil.loadFalseResult(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC));
            return;
        }
        UserInfo user = userInfoService.getUserByIdWithMybatis(uid);
        if (user != null && user.getState() != UserInfo.STATE_NORMAL) {
            out.print(JsonUtil.loadFalseResult(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC));
            return;
        }
        String inviteCode = userInfoExtraService.getInviteCodeByUid(uid);
        if (StringUtil.isNullOrEmpty(inviteCode)) {
            out.print(JsonUtil.loadFalseResult(1, "邀请码未激活"));
            return;
        }
        String inviteCode = userInfoExtraService.getInviteCodeByUid(uid);
        if (StringUtil.isNullOrEmpty(inviteCode)) {
            out.print(JsonUtil.loadFalseResult(1, "邀请码未激活"));
            return;
        }
        if (goodsType.intValue() == Constant.SOURCE_TYPE_JD) { // 京东
            createPosterJD(acceptData, goodsId, goodsType, from, type, user, inviteCode, out);
        } else if (goodsType.intValue() == Constant.SOURCE_TYPE_PDD) { // 拼多多
            createPosterPDD(acceptData, goodsId, goodsType, from, type, user, inviteCode, out);
        } else {
            out.print(JsonUtil.loadFalseResult(1, "参数传递错误"));
        }
    }
        if (goodsType.intValue() == Constant.SOURCE_TYPE_JD) { // 京东
            createPosterJD(acceptData, goodsId, goodsType, from, type, user, inviteCode, out);
        } else if (goodsType.intValue() == Constant.SOURCE_TYPE_PDD) { // 拼多多
            createPosterPDD(acceptData, goodsId, goodsType, from, type, user, inviteCode, out);
        } else {
            out.print(JsonUtil.loadFalseResult(1, "参数传递错误"));
        }
    }
    /**
     * 创建京东分享海报
     */
    private void createPosterJD(WXMPAcceptData acceptData, Long goodsId, Integer goodsType, String from, Integer type,
            UserInfo user, String inviteCode, PrintWriter out) {
        JDGoods jdGoods = jdGoodsCacheUtil.getGoodsInfo(goodsId);
        if (jdGoods == null) {
            out.print(JsonUtil.loadFalseResult(2, "商品已下架"));
            return;
        }
        GoodsMoneyConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
                acceptData.getVersion(),acceptData.getSystem());
        GoodsDetailVO goods = GoodsDetailVOFactory.convertJDGoods(jdGoods, paramsDTO);
    /**
     * 创建京东分享海报
     */
    private void createPosterJD(WXMPAcceptData acceptData, Long goodsId, Integer goodsType, String from, Integer type,
                                UserInfo user, String inviteCode, PrintWriter out) {
        JDGoods jdGoods = jdGoodsCacheUtil.getGoodsInfo(goodsId);
        if (jdGoods == null) {
            out.print(JsonUtil.loadFalseResult(2, "商品已下架"));
            return;
        }
        GoodsMoneyConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
                acceptData.getVersion(), acceptData.getSystem());
        GoodsDetailVO goods = GoodsDetailVOFactory.convertJDGoods(jdGoods, paramsDTO);
        String scene = goodsType + "#" + goodsId + "#" + inviteCode;
        FileUploadResult uploadResult = null;
        if (type == 1) {
            String erCodeUrl = "https://wxmp.banliapp.com/goods?i=" + scene;
            uploadResult = qrCodeService.drawGoodsPoster(erCodeUrl, user.getPortrait(), goods);
        } else {
            String acessToken = WXUtil.getAcessToken(Constant.WXMP_APP_INFO.getAppId(),
                    Constant.WXMP_APP_INFO.getAppSecret());
            InputStream xcxCode = WXXCXUtil.getXCXCode(acessToken, "/pages/goods/goods", scene);
            uploadResult = qrCodeService.drawGoodsPosterXCX(xcxCode, user, goods);
        }
        String scene = goodsType + "#" + goodsId + "#" + inviteCode;
        FileUploadResult uploadResult = null;
        if (type == 1) {
            String erCodeUrl = "https://wxmp.banliapp.com/goods?i=" + scene;
            uploadResult = qrCodeService.drawGoodsPoster(erCodeUrl, user.getPortrait(), goods);
        } else {
            String acessToken = WXUtil.getAcessToken(Constant.WXMP_APP_INFO.getAppId(),
                    Constant.WXMP_APP_INFO.getAppSecret());
            InputStream xcxCode = WXXCXUtil.getXCXCode(acessToken, "/pages/goods/goods", scene);
            uploadResult = qrCodeService.drawGoodsPosterXCX(xcxCode, user, goods);
        }
        try {
            userShareGoodsRecordService.saveShareRecord(user.getId(), CommonGoodsFactory.create(jdGoods));
        } catch (UserShareGoodsRecordException e) {
            e.printStackTrace();
        }
        String posterLink = uploadResult.getUrl();
        try {
            userShareGoodsRecordService.saveShareRecord(user.getId(), CommonGoodsFactory.create(jdGoods));
        } catch (UserShareGoodsRecordException e) {
            e.printStackTrace();
        }
        String posterLink = uploadResult.getUrl();
        JSONObject data = new JSONObject();
        data.put("posterLink", posterLink);
        out.print(JsonUtil.loadTrueResult(data));
        JSONObject data = new JSONObject();
        data.put("posterLink", posterLink);
        out.print(JsonUtil.loadTrueResult(data));
        com.yeshi.fanli.util.ThreadUtil.run(new Runnable() {
            @Override
            public void run() {
                // 异步操作 添加分享记录
                UserShareGoodsHistory history = new UserShareGoodsHistory();
                history.setUser(new UserInfo(user.getId()));
                history.setHongbao(new BigDecimal(goods.getMoneyInfo().getShareMoney().replace("¥", "")));
                history.setCreateTime(new Date());
                history.setGoodsType(Constant.SOURCE_TYPE_JD);
                history.setTkCode(null);
                history.setLink(null);
                history.setQuanLink(null);
                history.setGoodsId(goodsId);
                history.setPostPicture(goods.getPicUrl());
                history.setPictures(JsonUtil.getGson().toJson(goods.getImgList()));
                history.setShareImg(posterLink);
                shareGoodsService.addShareGoodsHistory(history);
            }
        });
    }
        com.yeshi.fanli.util.ThreadUtil.run(new Runnable() {
            @Override
            public void run() {
                // 异步操作 添加分享记录
                UserShareGoodsHistory history = new UserShareGoodsHistory();
                history.setUser(new UserInfo(user.getId()));
                history.setHongbao(new BigDecimal(goods.getMoneyInfo().getShareMoney().replace("¥", "")));
                history.setCreateTime(new Date());
                history.setGoodsType(Constant.SOURCE_TYPE_JD);
                history.setTkCode(null);
                history.setLink(null);
                history.setQuanLink(null);
                history.setGoodsId(goodsId);
                history.setPostPicture(goods.getPicUrl());
                history.setPictures(JsonUtil.getGson().toJson(goods.getImgList()));
                history.setShareImg(posterLink);
                shareGoodsService.addShareGoodsHistory(history);
            }
        });
    }
    /**
     * 创建拼多多分享海报
     */
    private void createPosterPDD(WXMPAcceptData acceptData, Long goodsId, Integer goodsType, String from, Integer type,
            UserInfo user, String inviteCode, PrintWriter out) {
        PDDGoodsDetail pddGoods = pinDuoDuoCacheUtil.getGoodsInfo(goodsId);
        if (pddGoods == null) {
            out.print(JsonUtil.loadFalseResult(2, "商品已下架"));
            return;
        }
        GoodsMoneyConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
                acceptData.getVersion(),acceptData.getSystem());
        GoodsDetailVO goods = GoodsDetailVOFactory.convertPDDGoods(pddGoods, paramsDTO);
    /**
     * 创建拼多多分享海报
     */
    private void createPosterPDD(WXMPAcceptData acceptData, Long goodsId, Integer goodsType, String from, Integer type,
                                 UserInfo user, String inviteCode, PrintWriter out) {
        PDDGoodsDetail pddGoods = pinDuoDuoCacheUtil.getGoodsInfo(goodsId);
        if (pddGoods == null) {
            out.print(JsonUtil.loadFalseResult(2, "商品已下架"));
            return;
        }
        GoodsMoneyConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
                acceptData.getVersion(), acceptData.getSystem());
        GoodsDetailVO goods = GoodsDetailVOFactory.convertPDDGoods(pddGoods, paramsDTO);
        String scene = goodsType + "#" + goodsId + "#" + inviteCode;
        FileUploadResult uploadResult = null;
        if (type == 1) {
            String erCodeUrl = "https://wxmp.banliapp.com/goods?info=" + scene;
            uploadResult = qrCodeService.drawGoodsPoster(erCodeUrl, user.getPortrait(), goods);
        } else {
            String acessToken = WXUtil.getAcessToken(Constant.WXMP_APP_INFO.getAppId(),
                    Constant.WXMP_APP_INFO.getAppSecret());
            InputStream xcxCode = WXXCXUtil.getXCXCode(acessToken, "/pages/goods/goods", scene);
            uploadResult = qrCodeService.drawGoodsPosterXCX(xcxCode, user, goods);
        }
        String scene = goodsType + "#" + goodsId + "#" + inviteCode;
        FileUploadResult uploadResult = null;
        if (type == 1) {
            String erCodeUrl = "https://wxmp.banliapp.com/goods?info=" + scene;
            uploadResult = qrCodeService.drawGoodsPoster(erCodeUrl, user.getPortrait(), goods);
        } else {
            String acessToken = WXUtil.getAcessToken(Constant.WXMP_APP_INFO.getAppId(),
                    Constant.WXMP_APP_INFO.getAppSecret());
            InputStream xcxCode = WXXCXUtil.getXCXCode(acessToken, "/pages/goods/goods", scene);
            uploadResult = qrCodeService.drawGoodsPosterXCX(xcxCode, user, goods);
        }
        try {
            userShareGoodsRecordService.saveShareRecord(user.getId(), CommonGoodsFactory.create(pddGoods));
        } catch (UserShareGoodsRecordException e) {
            e.printStackTrace();
        }
        String posterLink = uploadResult.getUrl();
        try {
            userShareGoodsRecordService.saveShareRecord(user.getId(), CommonGoodsFactory.create(pddGoods));
        } catch (UserShareGoodsRecordException e) {
            e.printStackTrace();
        }
        String posterLink = uploadResult.getUrl();
        JSONObject data = new JSONObject();
        data.put("posterLink", posterLink);
        out.print(JsonUtil.loadTrueResult(data));
        JSONObject data = new JSONObject();
        data.put("posterLink", posterLink);
        out.print(JsonUtil.loadTrueResult(data));
        // 异步操作
        com.yeshi.fanli.util.ThreadUtil.run(new Runnable() {
            @Override
            public void run() {
                // 异步操作 添加分享记录
                UserShareGoodsHistory history = new UserShareGoodsHistory();
                history.setUser(new UserInfo(user.getId()));
                history.setHongbao(new BigDecimal(goods.getMoneyInfo().getShareMoney().replace("¥", "")));
                history.setCreateTime(new Date());
                history.setGoodsType(Constant.SOURCE_TYPE_PDD);
                history.setTkCode(null);
                history.setLink(null);
                history.setQuanLink(null);
                history.setGoodsId(goodsId);
                history.setPostPicture(goods.getPicUrl());
                history.setPictures(JsonUtil.getGson().toJson(goods.getImgList()));
                history.setShareImg(posterLink);
                shareGoodsService.addShareGoodsHistory(history);
            }
        });
    }
        // 异步操作
        com.yeshi.fanli.util.ThreadUtil.run(new Runnable() {
            @Override
            public void run() {
                // 异步操作 添加分享记录
                UserShareGoodsHistory history = new UserShareGoodsHistory();
                history.setUser(new UserInfo(user.getId()));
                history.setHongbao(new BigDecimal(goods.getMoneyInfo().getShareMoney().replace("¥", "")));
                history.setCreateTime(new Date());
                history.setGoodsType(Constant.SOURCE_TYPE_PDD);
                history.setTkCode(null);
                history.setLink(null);
                history.setQuanLink(null);
                history.setGoodsId(goodsId);
                history.setPostPicture(goods.getPicUrl());
                history.setPictures(JsonUtil.getGson().toJson(goods.getImgList()));
                history.setShareImg(posterLink);
                shareGoodsService.addShareGoodsHistory(history);
            }
        });
    }
}
fanli/src/main/java/com/yeshi/fanli/dao/mongo/system/SystemPIDInfoDao.java
New file
@@ -0,0 +1,41 @@
package com.yeshi.fanli.dao.mongo.system;
import com.ks.lijin.query.BaseDaoQuery;
import com.yeshi.common.MongodbBaseDao;
import com.yeshi.fanli.entity.SystemPIDInfo;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;
import java.util.ArrayList;
import java.util.List;
@Repository
public class SystemPIDInfoDao extends MongodbBaseDao<SystemPIDInfo> {
    public List<SystemPIDInfo> list(DaoQuery daoQuery) {
        List<Criteria> andList = new ArrayList<>();
        if (daoQuery.pid != null) {
            andList.add(Criteria.where("pid").is(daoQuery.pid));
        }
        if (daoQuery.sourceType != null) {
            andList.add(Criteria.where("sourceType").is(daoQuery.sourceType));
        }
        Criteria[] ands = new Criteria[andList.size()];
        andList.toArray(ands);
        Query query = new Query();
        query.addCriteria(new Criteria().andOperator(ands));
        query.skip((int) daoQuery.start);
        query.limit(daoQuery.count);
        return findList(query);
    }
    public static class DaoQuery extends BaseDaoQuery {
        public String pid;
        public Integer sourceType;
    }
}
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/user/UserExtraTaoBaoInfoMapper.java
@@ -39,7 +39,7 @@
     * @param relationId
     * @return
     */
    UserExtraTaoBaoInfo selectByRelationIdWithUidNotNull(@Param("relationId") String relationId,@Param("system")  SystemEnum system);
    UserExtraTaoBaoInfo selectByRelationIdWithUidNotNull(@Param("relationId") String relationId,@Param("systemList")  List<SystemEnum> systemList);
    /**
     * 通过会员运营ID查询
@@ -47,7 +47,7 @@
     * @param specialId
     * @return
     */
    UserExtraTaoBaoInfo selectBySpecialIdWithUidNotNull(@Param("specialId") String specialId,@Param("system")  SystemEnum system);
    UserExtraTaoBaoInfo selectBySpecialIdWithUidNotNull(@Param("specialId") String specialId,@Param("systemList")  List<SystemEnum> systemList);
    
    /**
     * 统计正在使用的该淘宝的用户
fanli/src/main/java/com/yeshi/fanli/entity/SystemPIDInfo.java
New file
@@ -0,0 +1,105 @@
package com.yeshi.fanli.entity;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.Date;
/**
 * 系统推广位信息
 */
@Document(collection = "systemPIDInfo")
public class SystemPIDInfo {
    public enum PidType {
        fanli("返利"), fanliChannel("渠道返利"), coupon("领券"), share("分享");
        private PidType(String name) {
        }
    }
    @Id
    private String id;
    //推广位类型
    @Indexed
    private SystemEnum system;
    @Indexed
    private PidType pidType;
    private Integer sourceType;
    private String pid;
    private Date createTime;
    private Date updateTime;
    public SystemPIDInfo() {
    }
    public SystemPIDInfo(SystemEnum system, PidType pidType, Integer sourceType, String pid) {
        this.system = system;
        this.pidType = pidType;
        this.sourceType = sourceType;
        this.pid = pid;
    }
    public static String createId(SystemEnum system, Integer sourceType, PidType pidType) {
        return String.format("%s-%s-%s", system.name(), sourceType + "", pidType.name());
    }
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public SystemEnum getSystem() {
        return system;
    }
    public void setSystem(SystemEnum system) {
        this.system = system;
    }
    public PidType getPidType() {
        return pidType;
    }
    public void setPidType(PidType pidType) {
        this.pidType = pidType;
    }
    public String getPid() {
        return pid;
    }
    public void setPid(String pid) {
        this.pid = pid;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
    public Integer getSourceType() {
        return sourceType;
    }
    public void setSourceType(Integer sourceType) {
        this.sourceType = sourceType;
    }
}
fanli/src/main/java/com/yeshi/fanli/job/DynamicInfoJob.java
@@ -320,7 +320,7 @@
                desc = desc.replaceFirst("\\[链接\\]", link);
            }
            desc = convertLinkManager.convertJDLinkFromText(desc, 0L, true,false);
            desc = convertLinkManager.convertJDLinkFromText(SystemEnum.blks, desc, 0L, true, false);
            info.setContent(desc);
            List<JDGoods> goodsList = JDApiUtil.queryGoodsDetail(goods.getSkuList());
fanli/src/main/java/com/yeshi/fanli/service/impl/dynamic/GoodsEvaluateServiceImpl.java
@@ -18,7 +18,9 @@
import javax.imageio.ImageIO;
import com.yeshi.fanli.entity.SystemEnum;
import com.yeshi.fanli.entity.SystemPIDInfo;
import com.yeshi.fanli.exception.taobao.TaoBaoConvertLinkException;
import com.yeshi.fanli.service.manger.PIDManager;
import com.yeshi.fanli.service.manger.goods.TaoBaoLinkManager;
import org.apache.commons.beanutils.PropertyUtils;
import org.springframework.cache.annotation.CacheEvict;
@@ -125,6 +127,10 @@
    @Resource
    private DaTaoKeGoodsDetailV2Service daTaoKeGoodsDetailV2Service;
    @Resource
    private PIDManager pidManager;
    @Override
    public void switchState(String id) throws GoodsEvaluateException {
@@ -546,7 +552,7 @@
        String commentText = "";
        if (addComment) {
            if (goodsType == Constant.SOURCE_TYPE_TAOBAO) {
                TaoBaoLink taoBaoLink = taoBaoLinkManager.getTaoBaoLinkForShare(1L, Long.parseLong(goodsId), "0", null);
                TaoBaoLink taoBaoLink = taoBaoLinkManager.getTaoBaoLinkForShare(system, 1L, Long.parseLong(goodsId), "0", null);
                String template = configService.getValue(ConfigKeyEnum.quickShareTBCommentText.getKey(), system);
                commentText = template.replace("[淘口令]", TaoBaoUtil.filterTaoToken(taoBaoLink.getTaoToken()));
            } else if (goodsType == Constant.SOURCE_TYPE_JD) {
@@ -557,15 +563,16 @@
                }
                String materialId = "https://item.jd.com/" + goodsId + ".html";
                String jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, null,
                        JDApiUtil.POSITION_SHARE + "", "1");
                        pidManager.getPidCache(system, Constant.SOURCE_TYPE_JD, SystemPIDInfo.PidType.share), "1");
                String template = configService.getValue(ConfigKeyEnum.quickShareJDCommentText.getKey(), system);
                if (jumpLink == null) {
                    throw new GoodsEvaluateException(1, "该商品转链失败");
                }
                commentText = template.replace("[链接]", jumpLink);
            } else if (goodsType == Constant.SOURCE_TYPE_PDD) {
                PDDGoodsDetail goodsDetail = PinDuoDuoApiUtil.getGoodsDetail(Long.parseLong(goodsId), PinDuoDuoApiUtil.PID_SHARE + "", "1");
                String jumpLink = PinDuoDuoApiUtil.getPromotionUrl(goodsDetail.getGoodsSign(), PinDuoDuoApiUtil.PID_SHARE + "", "1");
                String sharePid = pidManager.getPidCache(system, Constant.SOURCE_TYPE_PDD, SystemPIDInfo.PidType.share);
                PDDGoodsDetail goodsDetail = PinDuoDuoApiUtil.getGoodsDetail(Long.parseLong(goodsId), sharePid, "1");
                String jumpLink = PinDuoDuoApiUtil.getPromotionUrl(goodsDetail.getGoodsSign(), sharePid, "1");
                if (jumpLink == null) {
                    throw new GoodsEvaluateException(1, "该商品转链失败");
                }
@@ -613,7 +620,7 @@
    private String createTokenAndLink(GoodsDetailVO goodsDetailVO, SystemEnum system) throws Exception {
        String commentText = "";
        if (goodsDetailVO.getGoodsType() == Constant.SOURCE_TYPE_TAOBAO) {
            TaoBaoLink taoBaoLink = taoBaoLinkManager.getTaoBaoLinkForShare(1L, Long.parseLong(goodsDetailVO.getGoodsId()), "0", null);
            TaoBaoLink taoBaoLink = taoBaoLinkManager.getTaoBaoLinkForShare(system, 1L, Long.parseLong(goodsDetailVO.getGoodsId()), "0", null);
            String template = configService.getValue(ConfigKeyEnum.quickShareTBCommentText.getKey(), system);
            commentText = template.replace("[淘口令]", TaoBaoUtil.filterTaoToken(taoBaoLink.getTaoToken()));
        } else if (goodsDetailVO.getGoodsType() == Constant.SOURCE_TYPE_JD) {
@@ -625,16 +632,19 @@
                couponUrl = couponInfo.getLink();
            }
            String materialId = "https://item.jd.com/" + goodsDetailVO.getGoodsId() + ".html";
            String jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, null, JDApiUtil.POSITION_SHARE + "",
            String jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, null, pidManager.getPidCache(system, Constant.SOURCE_TYPE_JD, SystemPIDInfo.PidType.share),
                    "1");
            String template = configService.getValue(ConfigKeyEnum.quickShareJDCommentText.getKey(), system);
            commentText = template.replace("[链接]", jumpLink);
        } else if (goodsDetailVO.getGoodsType() == Constant.SOURCE_TYPE_PDD) {
            String sharePid = pidManager.getPidCache(system, Constant.SOURCE_TYPE_PDD, SystemPIDInfo.PidType.share);
            PDDGoodsDetail goodsDetail = PinDuoDuoApiUtil.getGoodsDetail(Long.parseLong(goodsDetailVO.getGoodsId()),
                    PinDuoDuoApiUtil.PID_SHARE + "", "1");
                    sharePid, "1");
            String jumpLink = PinDuoDuoApiUtil.getPromotionUrl(goodsDetail.getGoodsSign(),
                    PinDuoDuoApiUtil.PID_SHARE + "", "1");
                    sharePid, "1");
            String template = configService.getValue(ConfigKeyEnum.quickSharePDDCommentText.getKey(), system);
            commentText = template.replace("[链接]", jumpLink);
        }
@@ -911,7 +921,7 @@
                }
            } else if (i == 0 && kind == 1) {
                try {
                    convertLinkManager.convertLinkFromText(content, Constant.LINK_TOKEN_VERIFY_UID, true, false);
                    convertLinkManager.convertLinkFromText(system, content, Constant.LINK_TOKEN_VERIFY_UID, true, false);
                } catch (Exception e) {
                    throw new GoodsEvaluateException(1, "不包含可转链的口令与链接");
                }
@@ -936,7 +946,7 @@
    }
    @Override
    public void saveCurrencyCoupon(String pid, int kind, CommentInfo commentInfo)
    public void saveCurrencyCoupon(SystemEnum system, String pid, int kind, CommentInfo commentInfo)
            throws GoodsEvaluateException, Exception {
        if (StringUtil.isNullOrEmpty(pid)) {
            throw new GoodsEvaluateException(1, "请保存第一部分信息");
@@ -981,7 +991,7 @@
        String content = commentInfo.getContent();
        if (!StringUtil.isNullOrEmpty(content) && commentInfo.getNeedSpin()) {
            try {
                convertLinkManager.convertLinkFromText(content, Constant.LINK_TOKEN_VERIFY_UID, true, false);
                convertLinkManager.convertLinkFromText(system, content, Constant.LINK_TOKEN_VERIFY_UID, true, false);
            } catch (ConvertLinkExceptionException e) {
                if (ConvertLinkExceptionException.CODE_NONE != e.getCode()) {
                    throw new GoodsEvaluateException(1, "包含不可转链的口令与链接");
@@ -2148,7 +2158,7 @@
        // 生成口令
        String token = null;
        try {
            TaoBaoLink taoBaoLink = taoBaoLinkManager.getTaoBaoLinkForShare(Constant.LINK_TOKEN_VERIFY_UID, goodsBrief.getAuctionId(), "1", null);
            TaoBaoLink taoBaoLink = taoBaoLinkManager.getTaoBaoLinkForShare(system, Constant.LINK_TOKEN_VERIFY_UID, goodsBrief.getAuctionId(), "1", null);
            token = taoBaoLink.getTaoToken();
        } catch (TaoBaoConvertLinkException e) {
            e.printStackTrace();
fanli/src/main/java/com/yeshi/fanli/service/impl/dynamic/WXMPDynamicInfoServiceImpl.java
@@ -6,6 +6,7 @@
import javax.annotation.Resource;
import com.yeshi.fanli.entity.SystemEnum;
import org.springframework.stereotype.Service;
import org.yeshi.utils.StringUtil;
@@ -65,7 +66,7 @@
        // 转链
        String convertContent = null;
        try {
            convertContent = convertLinkManager.convertLinkFromText(info.getContent(), uid, true,false);
            convertContent = convertLinkManager.convertLinkFromText(SystemEnum.blks, info.getContent(), uid, true,false);
        } catch (Exception e) {
            e.printStackTrace();
            LogHelper.errorDetailInfo(e);
fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/CommonShareInfoServiceImpl.java
@@ -2,6 +2,7 @@
import javax.annotation.Resource;
import com.yeshi.fanli.entity.SystemEnum;
import org.springframework.stereotype.Service;
import com.yeshi.fanli.dao.mybatis.homemodule.CommonShareInfoMapper;
@@ -33,7 +34,7 @@
            
            if (record.getNeedSpin()) {
                try {
                    convertLinkManager.convertLinkFromText(record.getComment(), Constant.LINK_TOKEN_VERIFY_UID, true,false);
                    convertLinkManager.convertLinkFromText(SystemEnum.blks, record.getComment(), Constant.LINK_TOKEN_VERIFY_UID, true,false);
                } catch (ConvertLinkExceptionException e) {
                    if (ConvertLinkExceptionException.CODE_NONE != e.getCode()) {
                        throw new SpecialException(1, "包含不可转链的口令与链接");
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderProcessServiceImpl.java
@@ -13,6 +13,9 @@
import javax.annotation.Resource;
import com.yeshi.fanli.entity.SystemEnum;
import com.yeshi.fanli.entity.SystemPIDInfo;
import com.yeshi.fanli.service.manger.PIDManager;
import com.yeshi.fanli.service.manger.order.TeamRewardManager;
import com.yeshi.fanli.util.pinduoduo.PinDuoDuoUtil;
import org.springframework.stereotype.Service;
@@ -167,18 +170,24 @@
    @Resource
    private TeamRewardManager teamRewardManager;
    @Resource
    private PIDManager pidManager;
    /**
     * 是否是分享订单
     *
     * @param order
     * @return
     */
    private boolean isShareOrder(TaoBaoOrder order) {
    private boolean isShareOrder(SystemEnum system, TaoBaoOrder order) {
        String specialRelationId = pidManager.getPidCache(system, Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.fanliChannel);
        List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID);
        String pid = String.format("mm_%s_%s_%s", configList.get(0).getAccountId(), order.getSourceMediaId(),
                order.getAdPositionId());
        if (!StringUtil.isNullOrEmpty(order.getSpecialId())
                || pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID)) {// 设置渠道ID当做会员运营ID的位置ID
                || pid.equalsIgnoreCase(specialRelationId)) {// 设置渠道ID当做会员运营ID的位置ID
            return false;
        } else if (!StringUtil.isNullOrEmpty(order.getRelationId())) {
            return true;
@@ -198,6 +207,44 @@
        }
    }
    //获取推广位类型
    private SystemPIDInfo.PidType getPidType(int sourceType, String pid) {
        List<SystemPIDInfo> pidInfoList = pidManager.listPidInfoByPidCache(pid, Constant.SOURCE_TYPE_TAOBAO);
        if (pidInfoList == null || pidInfoList.size() == 0) {
            pidInfoList = pidManager.listPidInfoByPidCache(pid, Constant.SOURCE_TYPE_ELME);
        }
        SystemPIDInfo.PidType pidType = null;
        if (pidInfoList != null && pidInfoList.size() > 0) {
            pidType = pidInfoList.get(0).getPidType();
        }
        return pidType;
    }
    //根据PID获取系统
    private List<SystemEnum> getPidSystems(String pid) {
        List<SystemEnum> systemList = new ArrayList<>();
        List<SystemPIDInfo> pidInfoList = pidManager.listPidInfoByPidCache(pid, null);
        if (pidInfoList != null) {
            for (SystemPIDInfo pidInfo : pidInfoList) {
                systemList.add(pidInfo.getSystem());
            }
        }
        return systemList;
    }
    private Set<Integer> getPidSourceTypes(String pid) {
        Set<Integer> sourceTypes = new HashSet<>();
        List<SystemPIDInfo> pidInfoList = pidManager.listPidInfoByPidCache(pid, null);
        if (pidInfoList != null) {
            for (SystemPIDInfo pidInfo : pidInfoList) {
                sourceTypes.add(pidInfo.getSourceType());
            }
        }
        return sourceTypes;
    }
    @Override
    public synchronized void processOrder(Map<String, List<TaoBaoOrder>> orders) {
        List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID);
@@ -214,37 +261,48 @@
                List<TaoBaoOrder> list = orders.get(orderId);
                String pid = String.format("mm_%s_%s_%s", configList.get(0).getAccountId(),
                        list.get(0).getSourceMediaId(), list.get(0).getAdPositionId());
                if ("饿了么".equalsIgnoreCase(list.get(0).getOrderType())
                        && !pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT)) {
                    // 饿了么订单开始归入到淘宝订单
                    if (TimeUtil.convertToTimeTemp(list.get(0).getCreateTime(),
                            "yyyy-MM-dd HH:mm:ss") >= Constant.NEW_ORDER_FANLI_RULE_TIME) {
                        fanliOrderMap.put(orderId, list);
                    } else {
                        elmeOrderMap.put(orderId, list);
                    }
                } else if ("口碑".equalsIgnoreCase(list.get(0).getOrderType())
                        && pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_KOUBEI_PID)) {// 口碑自购
                    fanliOrderMap.put(orderId, list);
                } else {
                    if (!StringUtil.isNullOrEmpty(list.get(0).getSpecialId())
                            || pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID)) {// 设置渠道ID当做会员运营ID的位置ID
                        fanliOrderMap.put(orderId, list);
                    } else if (!StringUtil.isNullOrEmpty(list.get(0).getRelationId())) {
                        shareOrderMap.put(orderId, list);
                    } else {
                        // 通过红包查询
                        CommonOrder commonOrder = commonOrderService
                                .selectBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO, list.get(0).getTradeId());
                        if (commonOrder != null) {
                            HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
                            if (hongBaoOrder != null && hongBaoOrder.getHongBaoV2() != null
                                    && hongBaoOrder.getHongBaoV2().getType() == HongBaoV2.TYPE_SHARE_GOODS) {
                                shareOrderMap.put(orderId, list);
                                continue;
                            }
                SystemPIDInfo.PidType pidType = getPidType(Constant.SOURCE_TYPE_TAOBAO, pid);
                //--------分离自购,分享,饿了么订单类型-------
                if (pidType != null) {
                    if ("饿了么".equalsIgnoreCase(list.get(0).getOrderType())
                            && pidType != SystemPIDInfo.PidType.share) {
                        // 饿了么订单开始归入到淘宝订单
                        if (TimeUtil.convertToTimeTemp(list.get(0).getCreateTime(),
                                "yyyy-MM-dd HH:mm:ss") >= Constant.NEW_ORDER_FANLI_RULE_TIME) {
                            fanliOrderMap.put(orderId, list);
                        } else {
                            elmeOrderMap.put(orderId, list);
                        }
                    } else {
                        if (!StringUtil.isNullOrEmpty(list.get(0).getSpecialId())
                                || pidType == SystemPIDInfo.PidType.fanliChannel) {// 设置渠道ID当做会员运营ID的位置ID
                            fanliOrderMap.put(orderId, list);
                        } else if (!StringUtil.isNullOrEmpty(list.get(0).getRelationId())) {
                            shareOrderMap.put(orderId, list);
                        } else {
                            // 通过红包查询
                            CommonOrder commonOrder = commonOrderService
                                    .selectBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO, list.get(0).getTradeId());
                            if (commonOrder != null) {
                                HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
                                if (hongBaoOrder != null && hongBaoOrder.getHongBaoV2() != null
                                        && hongBaoOrder.getHongBaoV2().getType() == HongBaoV2.TYPE_SHARE_GOODS) {
                                    shareOrderMap.put(orderId, list);
                                    continue;
                                }
                            }
                            fanliOrderMap.put(orderId, list);
                        }
                    }
                } else {
                    if ("口碑".equalsIgnoreCase(list.get(0).getOrderType())
                            && pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_KOUBEI_PID)) {// 口碑自购
                        fanliOrderMap.put(orderId, list);
                    } else {
                        fanliOrderMap.put(orderId, list);
                    }
                }
@@ -746,26 +804,30 @@
            String pid = String.format("mm_%s_%s_%s", configList.get(0).getAccountId(),
                    orderList.get(0).getSourceMediaId(), orderList.get(0).getAdPositionId());
            SystemPIDInfo.PidType pidType = getPidType(Constant.SOURCE_TYPE_TAOBAO, pid);
            List<SystemEnum> systemList = getPidSystems(pid);
            Set<Integer> sourceTypes = getPidSourceTypes(pid);
            Order oldOrder = orderMapper.selectOrderByOrderIdAndOrderType(orderId, Constant.SOURCE_TYPE_TAOBAO);
            // 原来不存在订单
            Long uid = null;
            if (oldOrder == null) {
                Long targetUid = null;
                if (pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID)
                if (pidType != null && pidType == SystemPIDInfo.PidType.fanliChannel
                        && !StringUtil.isNullOrEmpty(orderList.get(0).getRelationId())) {// 处理非返利商品库的商品
                    targetUid = taoBaoBuyRelationMapService.selectUidByRelationId(orderList.get(0).getRelationId());
                } else if ((pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_ELEME_PID)
                } else if ((sourceTypes.contains(Constant.SOURCE_TYPE_ELME)
                        || pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_KOUBEI_PID))
                        && !StringUtil.isNullOrEmpty(orderList.get(0).getRelationId())) {// 处理饿了么,口碑的订单
                    UserExtraTaoBaoInfo extraInfo = userExtraTaoBaoInfoService
                            .getByRelationId(orderList.get(0).getRelationId(), null);
                            .getByRelationId(orderList.get(0).getRelationId(), systemList);
                    if (extraInfo != null) {
                        targetUid = extraInfo.getUser().getId();
                    }
                } else if (!StringUtil.isNullOrEmpty(orderList.get(0).getSpecialId())) {
                    UserExtraTaoBaoInfo info = userExtraTaoBaoInfoService
                            .getBySpecialId(orderList.get(0).getSpecialId(), null);
                            .getBySpecialId(orderList.get(0).getSpecialId(), systemList);
                    if (info != null && info.getUser() != null)
                        targetUid = info.getUser().getId();
                }
@@ -903,7 +965,8 @@
        if (order == null || order.getOrderItemList() == null || order.getOrderItemList().size() == 0)
            return false;
        Long positionId = order.getOrderItemList().get(0).getPositionId();
        if (positionId == JDApiUtil.POSITION_SHARE) {// 分享订单
        SystemPIDInfo.PidType pidType = getPidType(Constant.SOURCE_TYPE_JD, positionId + "");
        if (pidType != null && pidType == SystemPIDInfo.PidType.share) {// 分享订单
            return true;
        }
        return false;
@@ -926,15 +989,21 @@
        if (!StringUtil.isNullOrEmpty(uidStr) && NumberUtil.isNumeric(uidStr))
            uid = Long.parseLong(uidStr);
        Long positionId = order.getOrderItemList().get(0).getPositionId();
        if (positionId == JDApiUtil.POSITION_FANLI)// 返利订单
        {
            processFanLiJDOrder(order, uid);
            lostOrderService.processSuceess(order.getOrderId() + "", Constant.SOURCE_TYPE_JD);
        } else if (positionId == JDApiUtil.POSITION_SHARE) {// 分享订单
            if (uid == null)// 分享订单不允许找回
                return;
            processShareJDOrder(order, uid);
        } else {// 处理是否有订单找回的状态
        SystemPIDInfo.PidType pidType = getPidType(Constant.SOURCE_TYPE_JD, positionId + "");
        if (pidType != null) {
            if (pidType == SystemPIDInfo.PidType.fanli)// 返利订单
            {
                processFanLiJDOrder(order, uid);
                lostOrderService.processSuceess(order.getOrderId() + "", Constant.SOURCE_TYPE_JD);
            } else if (pidType == SystemPIDInfo.PidType.share) {// 分享订单
                if (uid == null)// 分享订单不允许找回
                    return;
                processShareJDOrder(order, uid);
            } else {// 处理是否有订单找回的状态
                processFanLiJDOrder(order, null);
            }
        } else {
            processFanLiJDOrder(order, null);
        }
    }
@@ -1057,7 +1126,9 @@
     */
    private boolean isShareOrder(PDDOrder pddOrder) {
        String positionId = pddOrder.getpId();
        if (PinDuoDuoApiUtil.PID_SHARE.equalsIgnoreCase(positionId))
        SystemPIDInfo.PidType pidType = getPidType(Constant.SOURCE_TYPE_PDD, positionId);
        if (pidType != null && pidType == SystemPIDInfo.PidType.share)
            return true;
        else
            return false;
@@ -1075,15 +1146,20 @@
        if (!StringUtil.isNullOrEmpty(customParameters))
            uid = Long.parseLong(PinDuoDuoUtil.getUidFromCustomParams(customParameters));
        String positionId = pddOrder.getpId();
        if (PinDuoDuoApiUtil.PID_FANLI.equalsIgnoreCase(positionId))// 返利订单
        {
            processFanLiPDDOrder(pddOrder, uid);
            lostOrderService.processSuceess(pddOrder.getOrderSn(), Constant.SOURCE_TYPE_PDD);
        } else if (PinDuoDuoApiUtil.PID_SHARE.equalsIgnoreCase(positionId)) {// 分享订单
            if (uid == null)// 分享订单不允许找回
                return;
            processSharePDDOrder(pddOrder, uid);
        } else {// 处理是否有订单找回的状态
        SystemPIDInfo.PidType pidType = getPidType(Constant.SOURCE_TYPE_PDD, positionId);
        if (pidType != null) {
            if (pidType == SystemPIDInfo.PidType.fanli)// 返利订单
            {
                processFanLiPDDOrder(pddOrder, uid);
                lostOrderService.processSuceess(pddOrder.getOrderSn(), Constant.SOURCE_TYPE_PDD);
            } else if (pidType == SystemPIDInfo.PidType.share) {// 分享订单
                if (uid == null)// 分享订单不允许找回
                    return;
                processSharePDDOrder(pddOrder, uid);
            } else {// 处理是否有订单找回的状态
                processFanLiPDDOrder(pddOrder, null);
            }
        } else {
            processFanLiPDDOrder(pddOrder, null);
        }
    }
@@ -1341,15 +1417,22 @@
        if (!StringUtil.isNullOrEmpty(uidStr))
            uid = Long.parseLong(uidStr);
        String positionId = suningOrder.getPositionId();
        if (SuningApiUtil.PID_BUY.equalsIgnoreCase(positionId))// 返利订单
        {
            processFanLiSuningOrder(suningOrder, uid);
            lostOrderService.processSuceess(suningOrder.getOrderCode(), Constant.SOURCE_TYPE_SUNING);
        } else if (PinDuoDuoApiUtil.PID_SHARE.equalsIgnoreCase(positionId)) {// 分享订单
            if (uid == null)// 分享订单不允许找回
                return;
            processShareSuningOrder(suningOrder, uid);
        } else {// 处理是否有订单找回的状态
        SystemPIDInfo.PidType pidType = getPidType(Constant.SOURCE_TYPE_SUNING, positionId);
        if (pidType != null) {
            if (pidType == SystemPIDInfo.PidType.fanli)// 返利订单
            {
                processFanLiSuningOrder(suningOrder, uid);
                lostOrderService.processSuceess(suningOrder.getOrderCode(), Constant.SOURCE_TYPE_SUNING);
            } else if (pidType == SystemPIDInfo.PidType.share) {// 分享订单
                if (uid == null)// 分享订单不允许找回
                    return;
                processShareSuningOrder(suningOrder, uid);
            } else {// 处理是否有订单找回的状态
                processFanLiSuningOrder(suningOrder, null);
            }
        } else {
            processFanLiSuningOrder(suningOrder, null);
        }
    }
@@ -1485,9 +1568,12 @@
    @Override
    public boolean isShareOrder(CommonOrder commonOrder) {
        //获取系统
        UserInfo user = userInfoMapper.selectByPrimaryKey(commonOrder.getUserInfo().getId());
        SystemEnum system = user.getSystem();
        switch (commonOrder.getSourceType()) {
            case Constant.SOURCE_TYPE_TAOBAO:
                return isShareOrder(taoBaoOrderService.selectByTradeId(commonOrder.getTradeId()));
                return isShareOrder(system, taoBaoOrderService.selectByTradeId(commonOrder.getTradeId()));
            case Constant.SOURCE_TYPE_JD:
                return isShareOrder(jdOrderService.selectDetailByOrderId(Long.parseLong(commonOrder.getOrderNo())));
            case Constant.SOURCE_TYPE_PDD:
fanli/src/main/java/com/yeshi/fanli/service/impl/taobao/TaoBaoBuyRelationMapServiceImpl.java
@@ -5,6 +5,7 @@
import javax.annotation.Resource;
import com.yeshi.fanli.entity.SystemEnum;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
fanli/src/main/java/com/yeshi/fanli/service/impl/tlj/UserTaoLiJinNewbiesServiceImpl.java
@@ -8,6 +8,9 @@
import javax.annotation.Resource;
import com.yeshi.fanli.entity.SystemEnum;
import com.yeshi.fanli.entity.SystemPIDInfo;
import com.yeshi.fanli.service.manger.PIDManager;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -53,368 +56,373 @@
@Service
public class UserTaoLiJinNewbiesServiceImpl implements UserTaoLiJinNewbiesService {
    @Resource
    private UserTaoLiJinNewbiesMapper userTaoLiJinNewbiesMapper;
    @Resource
    private ConfigTaoLiJinService configTaoLiJinService;
    @Resource
    private UserInfoService userInfoService;
    @Resource
    private UserInfoExtraService userInfoExtraService;
    @Resource
    private UserMoneyMsgNotificationService userMoneyMsgNotificationService;
    @Resource
    private DeviceActiveService deviceActiveService;
    @Resource
    private JumpDetailV2Service jumpDetailV2Service;
    @Resource(name = "taskExecutor")
    private TaskExecutor executor;
    @Resource
    private TLJFreeBuyGoodsService tljFreeBuyGoodsService;
    @Resource
    private UserTaoLiJinDetailService userTaoLiJinDetailService;
    @Resource
    private TaoBaoBuyRelationMapService taoBaoBuyRelationMapService;
    @Override
    public boolean verifyHasReward(Long uid, String device) {
        try {
            if (StringUtil.isNullOrEmpty(device) && (uid == null || uid <= 0))
                return false;
            if (uid == null || uid <= 0) {
                DeviceActive deviceActive = deviceActiveService.getFirstActiveInfo(device);
                if (deviceActive == null)
                    return true; // 新设备弹出
                Date nowTime = new Date();
                Date createTime = deviceActive.getCreateTime();
                int days = DateUtil.daysBetween2(createTime, nowTime);
                if (days >= Constant.TLJ_NEW_USER_DAYS) {
                    return false; // 已经超出设置天数
                }
                return true; // 未超过时间
            }
            UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
            if (userInfoExtra == null || userInfoExtra.getFirstLoginTime() == null)
                return false;
            Date nowTime = new Date();
            Date firstLoginTime = userInfoExtra.getFirstLoginTime();
            int days = DateUtil.daysBetween2(firstLoginTime, nowTime);
            if (days >= Constant.TLJ_NEW_USER_DAYS)
                return false; // 已经超出设置天数
            UserTaoLiJinNewbies redPackWin = userTaoLiJinNewbiesMapper.selectByPrimaryKey(uid);
            if (redPackWin != null) {
                if (redPackWin.getMoney().compareTo(Constant.TLJ_NEW_USER_MONEY) >= 0)
                    return false; // 已领取完
                Date updateTime = redPackWin.getUpdateTime();
                int daysNum = DateUtil.daysBetween2(updateTime, nowTime);
                if (daysNum == 0)
                    return false; // 今日已领取
                Integer num = redPackWin.getNum();
                if (num >= Constant.TLJ_NEW_USER_DAYS)
                    return false; // 领取次数超限
            }
            return true;
        } catch (Exception e) {
            LogHelper.errorDetailInfo(e);
        }
        return false;
    }
    @RequestSerializableByKeyService(key = "#uid")
    @Transactional(rollbackFor = Exception.class)
    @Override
    public TaoLiJinWinDetailVO receiveReward(Long uid) throws Exception {
        if (uid == null || uid <= 0)
            return null; // 未登录弹出
        UserInfo userInfo = userInfoService.selectByPKey(uid);
        if (userInfo == null)
            return null;
        UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
        if (userInfoExtra == null || userInfoExtra.getFirstLoginTime() == null)
            return null;
        Date nowTime = new Date();
        Date firstLoginTime = userInfoExtra.getFirstLoginTime();
        int days = DateUtil.daysBetween2(firstLoginTime, nowTime);
        if (days >= Constant.TLJ_NEW_USER_DAYS)
            return null; // 已经超出设置天数
        UserTaoLiJinNewbies redPackWin = userTaoLiJinNewbiesMapper.selectForUpdate(uid);
        if (redPackWin != null) {
            if (redPackWin.getMoney().compareTo(Constant.TLJ_NEW_USER_MONEY) >= 0)
                return null; // 已领取完
            Date updateTime = redPackWin.getUpdateTime();
            int daysNum = DateUtil.daysBetween2(updateTime, nowTime);
            if (daysNum == 0)
                return null; // 今日已领取
            Integer num = redPackWin.getNum();
            if (num >= Constant.TLJ_NEW_USER_DAYS)
                return null; // 领取次数超限
        }
        BigDecimal money = null;
        if (redPackWin == null) { // 第一次
            if (days == Constant.TLJ_NEW_USER_DAYS - 1) {  // 最后一天
                money = Constant.TLJ_NEW_USER_MONEY;
            } else { // 计算随机奖励
                double randomNum = Constant.TLJ_NEW_USER_MIN +  Math.random() * (Constant.TLJ_NEW_USER_MAX - Constant.TLJ_NEW_USER_MIN);
                randomNum = randomNum/100;
                BigDecimal rate = new BigDecimal(randomNum).setScale(2, BigDecimal.ROUND_DOWN);
                money = MoneyBigDecimalUtil.mul(Constant.TLJ_NEW_USER_MONEY,rate);
            }
        } else if (days == Constant.TLJ_NEW_USER_DAYS - 1) { // 最后一天
            money = MoneyBigDecimalUtil.sub(Constant.TLJ_NEW_USER_MONEY, redPackWin.getMoney());
        } else { // 计算剩余随机奖励 10%-25%
            double randomNum = 10 +  Math.random() * (20 - 10);
            BigDecimal rate = new BigDecimal(randomNum/100).setScale(2, BigDecimal.ROUND_DOWN);
            money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.sub(Constant.TLJ_NEW_USER_MONEY,redPackWin.getMoney()),rate);
        }
        if (money.compareTo(new BigDecimal(0)) <= 0)
            return null;
        money = money.setScale(2);
        int num = 1;
        BigDecimal balance = null;
        if (redPackWin == null) {
            balance = money;
            // 注册开始 有效期
            Date endDate = DateUtil.plusDayDate(Constant.TLJ_NEW_USER_LIMIT, firstLoginTime);
            redPackWin = new UserTaoLiJinNewbies();
            redPackWin.setId(uid);
            redPackWin.setNum(1);
            redPackWin.setMoney(money);
            redPackWin.setEndTime(endDate);
            redPackWin.setCreateTime(nowTime);
            redPackWin.setUpdateTime(nowTime);
            userTaoLiJinNewbiesMapper.insertSelective(redPackWin);
        } else {
            userTaoLiJinNewbiesMapper.addMoney(uid, money);
            num = redPackWin.getNum() + 1;
            balance = MoneyBigDecimalUtil.add(money, redPackWin.getMoney());
        }
        // 明细
        UserTaoLiJinDetail detail = new UserTaoLiJinDetail();
        detail.setUid(uid);
        detail.setMoney(money);
        detail.setTitle(TaoLiJinDetailTypeEnum.add.getDesc());
        detail.setType(TaoLiJinDetailTypeEnum.add);
        detail.setCreateTime(new Date());
        detail.setRemark("新人红包");
        userTaoLiJinDetailService.insertSelective(detail);
        JSONObject json = new JSONObject();
        json.put("url", configTaoLiJinService.getValueByKey("new_user_free_buy_list"));
        TaoLiJinWinDetailVO winDetailVO = new TaoLiJinWinDetailVO();
        winDetailVO.setTitle("新人红包");
        winDetailVO.setBless("恭喜你!已领" + num + "/" + Constant.TLJ_NEW_USER_DAYS + "次");
        winDetailVO.setMoney(money.toString());
        winDetailVO.setDesc("已领取:" + balance + "元");
        winDetailVO.setTips(configTaoLiJinService.getValueByKey("new_user_win_tips"));
        winDetailVO.setParams(json.toString());
        winDetailVO.setJumpDetail(jumpDetailV2Service.getByTypeCache("web"));
        winDetailVO.setLogo(Constant.systemCommonConfig.getDefaultPortrait());
        winDetailVO.setLogoLight(userInfo.getPortrait());
        return winDetailVO;
    }
    @RequestSerializableByKeyService(key = "#uid")
    @Transactional(rollbackFor = Exception.class)
    @Override
    public String createTaoLiJinForBuy(TaoBaoGoodsBrief goods, Long uid) throws UserTaoLiJinNewbiesException {
        if (uid == null || uid <= 0 || goods == null)
            throw new UserTaoLiJinNewbiesException(1,"参数信息缺失");
        // 验证商品是否在免单商品库
        TLJFreeBuyGoods tljFreeBuyGoods = tljFreeBuyGoodsService.selectByAuctionIdAndDay(goods.getAuctionId(),
                TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd"));
        if (tljFreeBuyGoods == null)
            throw new UserTaoLiJinNewbiesException(1, "该商品非免单商品");
        // 验证是否有券
        if (goods == null || goods.getCouponAmount() == null ||
                goods.getCouponAmount().compareTo(new BigDecimal(0)) <= 0) {
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    tljFreeBuyGoodsService.deleteByGoodsId(goods.getAuctionId());
                }
            });
            throw new UserTaoLiJinNewbiesException(1, "该商品非免单商品");
        }
        // 验证券后价 是否在 1-2元
        BigDecimal money = TaoBaoUtil.getCouponPrice(goods);
        if (money.compareTo(new BigDecimal(1.0)) < 0 || money.compareTo(new BigDecimal(2.0)) > 0) {
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    tljFreeBuyGoodsService.deleteByGoodsId(goods.getAuctionId());
                }
            });
            throw new UserTaoLiJinNewbiesException(1, "该商品非免单商品");
        }
        // 验证用户信息
        UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
        if (userInfoExtra == null || userInfoExtra.getFirstLoginTime() == null)
            throw new UserTaoLiJinNewbiesException(1001, "你不是“新用户”无法使用新人红包0元购买。");
        // 验证是否激活
        if (StringUtil.isNullOrEmpty(userInfoExtra.getInviteCode()))
            throw new UserTaoLiJinNewbiesException(1002, "邀请码未激活,无法使用新人红包0元购买。");
        // 验证是否已超出新用户定义
        try {
            int days = DateUtil.daysBetween2(userInfoExtra.getFirstLoginTime(), new Date());
            if (days > Constant.TLJ_NEW_USER_DEFINE)
                throw new UserTaoLiJinNewbiesException(1001, "你不是“新用户”无法使用新人红包0元购买。");
        } catch (ParseException e1) {
            throw new UserTaoLiJinNewbiesException(1, "日期信息计算失败");
        }
        // 验证余额
        UserTaoLiJinNewbies taoLiJinNewbies = userTaoLiJinNewbiesMapper.selectForUpdate(uid);
        if (taoLiJinNewbies == null || taoLiJinNewbies.getMoney() == null ||
                taoLiJinNewbies.getMoney().compareTo(money)    < 0)
            throw new UserTaoLiJinNewbiesException(1001, "新人红包不足,请换个商品再试或继续领取到足额新人红包。");
        // 验证是否已过期
        if (taoLiJinNewbies.getEndTime() == null
                || taoLiJinNewbies.getEndTime().getTime() < java.lang.System.currentTimeMillis())
            throw new UserTaoLiJinNewbiesException(1, "新人红包已过期");
        // 红包减少
        userTaoLiJinNewbiesMapper.subMoney(uid, money);
        // 加入明细
        UserTaoLiJinDetail detail = new UserTaoLiJinDetail();
        detail.setUid(uid);
        detail.setMoney(new BigDecimal("-" + money));
        detail.setTitle(TaoLiJinDetailTypeEnum.reduce.getDesc());
        detail.setType(TaoLiJinDetailTypeEnum.reduce);
        detail.setCreateTime(new Date());
        detail.setRemark("新人免单使用红包");
        userTaoLiJinDetailService.insertSelective(detail);
        // 创建淘礼金链接
        if (TaoBaoUtil.isSpecialGoods(goods.getMaterialLibType())) {
            return createTaoLiJin(goods.getAuctionId(), money, 1, TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT);
        } else { // 非返利库商品
            String relationId = null;
            try {
                relationId = taoBaoBuyRelationMapService.getRelationId(uid);
            } catch (Exception e) {
                LogHelper.errorDetailInfo(e, "uid:" + uid, null);
            }
    @Resource
    private UserTaoLiJinNewbiesMapper userTaoLiJinNewbiesMapper;
            if (StringUtil.isNullOrEmpty(relationId))
                throw new UserTaoLiJinNewbiesException(1, "渠道未备案");
            return createTaoLiJin(goods.getAuctionId(), money, 1, TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID)
                    + "&relationId=" + relationId;
        }
    }
    @Transactional(rollbackFor=Exception.class)
    private String createTaoLiJin(Long auctionId, BigDecimal perface, int totalNum, String pid) throws UserTaoLiJinNewbiesException {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat formatStr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String name = "新人免单购";
        Date date = new Date();
        String date_str = format.format(date);
        String sendEndTime_str = date_str + " 22:00:00";
        String useEndTime_str = date_str + " 23:59:59";
        // 发放时间
        Date sendStartTime = date;
        Date sendEndTime = null;
        // 使用时间
        Date useStartTime = null;
        Date useEndTime = null;
        try {
            sendEndTime = formatStr.parse(sendEndTime_str);
            useEndTime = formatStr.parse(useEndTime_str);
        } catch (ParseException e2) {
            e2.printStackTrace();
        }
        // 创建淘礼金红包
        TaoLiJinDTO taoLiJinDTO = null;
        TaoKeAppInfo taoKeAppInfo = new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET, pid);
        try {
            taoLiJinDTO = TaoKeApiUtil.createTaoLiJin(auctionId, name, perface, totalNum, sendStartTime,
                    sendEndTime, useStartTime, useEndTime, taoKeAppInfo);
        } catch (TaoLiJinCreateException e) {
            LogHelper.errorDetailInfo(e);
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    if (e.getCode() == TaoLiJinCreateException.CODE_TLJ_FORBIDDEN) {
                        // 该商品不支持创建淘礼金红包
                        tljFreeBuyGoodsService.deleteByGoodsId(auctionId);
                    } else if (e.getCode() == TaoLiJinCreateException.CODE_TLJ_NO_MONEY) {
                        // 官方玩法钱包余额不足 TODO
                    }
                }
            });
        } catch (TaoKeApiException e) {
            LogHelper.errorDetailInfo(e);
        }
    @Resource
    private ConfigTaoLiJinService configTaoLiJinService;
        if (taoLiJinDTO == null || StringUtil.isNullOrEmpty(taoLiJinDTO.getSendUrl()))
            throw new UserTaoLiJinNewbiesException(1, "淘宝API红包创建失败");
        return taoLiJinDTO.getSendUrl();
    }
    @Resource
    private UserInfoService userInfoService;
    @Override
    public UserTaoLiJinNewbies selectByPrimaryKey(Long uid) {
        return userTaoLiJinNewbiesMapper.selectByPrimaryKey(uid);
    }
    @Resource
    private UserInfoExtraService userInfoExtraService;
    @Override
    public long count(String key) {
        return userTaoLiJinNewbiesMapper.count(key);
    }
    @Override
    public List<UserTaoLiJinNewbies> query(int page, int count, String key,Integer order) {
        return userTaoLiJinNewbiesMapper.query((page -1)* count, count, key, order);
    }
    @Resource
    private UserMoneyMsgNotificationService userMoneyMsgNotificationService;
    @Resource
    private DeviceActiveService deviceActiveService;
    @Resource
    private JumpDetailV2Service jumpDetailV2Service;
    @Resource(name = "taskExecutor")
    private TaskExecutor executor;
    @Resource
    private TLJFreeBuyGoodsService tljFreeBuyGoodsService;
    @Resource
    private UserTaoLiJinDetailService userTaoLiJinDetailService;
    @Resource
    private TaoBaoBuyRelationMapService taoBaoBuyRelationMapService;
    @Resource
    private PIDManager pidManager;
    @Override
    public boolean verifyHasReward(Long uid, String device) {
        try {
            if (StringUtil.isNullOrEmpty(device) && (uid == null || uid <= 0))
                return false;
            if (uid == null || uid <= 0) {
                DeviceActive deviceActive = deviceActiveService.getFirstActiveInfo(device);
                if (deviceActive == null)
                    return true; // 新设备弹出
                Date nowTime = new Date();
                Date createTime = deviceActive.getCreateTime();
                int days = DateUtil.daysBetween2(createTime, nowTime);
                if (days >= Constant.TLJ_NEW_USER_DAYS) {
                    return false; // 已经超出设置天数
                }
                return true; // 未超过时间
            }
            UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
            if (userInfoExtra == null || userInfoExtra.getFirstLoginTime() == null)
                return false;
            Date nowTime = new Date();
            Date firstLoginTime = userInfoExtra.getFirstLoginTime();
            int days = DateUtil.daysBetween2(firstLoginTime, nowTime);
            if (days >= Constant.TLJ_NEW_USER_DAYS)
                return false; // 已经超出设置天数
            UserTaoLiJinNewbies redPackWin = userTaoLiJinNewbiesMapper.selectByPrimaryKey(uid);
            if (redPackWin != null) {
                if (redPackWin.getMoney().compareTo(Constant.TLJ_NEW_USER_MONEY) >= 0)
                    return false; // 已领取完
                Date updateTime = redPackWin.getUpdateTime();
                int daysNum = DateUtil.daysBetween2(updateTime, nowTime);
                if (daysNum == 0)
                    return false; // 今日已领取
                Integer num = redPackWin.getNum();
                if (num >= Constant.TLJ_NEW_USER_DAYS)
                    return false; // 领取次数超限
            }
            return true;
        } catch (Exception e) {
            LogHelper.errorDetailInfo(e);
        }
        return false;
    }
    @RequestSerializableByKeyService(key = "#uid")
    @Transactional(rollbackFor = Exception.class)
    @Override
    public TaoLiJinWinDetailVO receiveReward(Long uid) throws Exception {
        if (uid == null || uid <= 0)
            return null; // 未登录弹出
        UserInfo userInfo = userInfoService.selectByPKey(uid);
        if (userInfo == null)
            return null;
        UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
        if (userInfoExtra == null || userInfoExtra.getFirstLoginTime() == null)
            return null;
        Date nowTime = new Date();
        Date firstLoginTime = userInfoExtra.getFirstLoginTime();
        int days = DateUtil.daysBetween2(firstLoginTime, nowTime);
        if (days >= Constant.TLJ_NEW_USER_DAYS)
            return null; // 已经超出设置天数
        UserTaoLiJinNewbies redPackWin = userTaoLiJinNewbiesMapper.selectForUpdate(uid);
        if (redPackWin != null) {
            if (redPackWin.getMoney().compareTo(Constant.TLJ_NEW_USER_MONEY) >= 0)
                return null; // 已领取完
            Date updateTime = redPackWin.getUpdateTime();
            int daysNum = DateUtil.daysBetween2(updateTime, nowTime);
            if (daysNum == 0)
                return null; // 今日已领取
            Integer num = redPackWin.getNum();
            if (num >= Constant.TLJ_NEW_USER_DAYS)
                return null; // 领取次数超限
        }
        BigDecimal money = null;
        if (redPackWin == null) { // 第一次
            if (days == Constant.TLJ_NEW_USER_DAYS - 1) {  // 最后一天
                money = Constant.TLJ_NEW_USER_MONEY;
            } else { // 计算随机奖励
                double randomNum = Constant.TLJ_NEW_USER_MIN + Math.random() * (Constant.TLJ_NEW_USER_MAX - Constant.TLJ_NEW_USER_MIN);
                randomNum = randomNum / 100;
                BigDecimal rate = new BigDecimal(randomNum).setScale(2, BigDecimal.ROUND_DOWN);
                money = MoneyBigDecimalUtil.mul(Constant.TLJ_NEW_USER_MONEY, rate);
            }
        } else if (days == Constant.TLJ_NEW_USER_DAYS - 1) { // 最后一天
            money = MoneyBigDecimalUtil.sub(Constant.TLJ_NEW_USER_MONEY, redPackWin.getMoney());
        } else { // 计算剩余随机奖励 10%-25%
            double randomNum = 10 + Math.random() * (20 - 10);
            BigDecimal rate = new BigDecimal(randomNum / 100).setScale(2, BigDecimal.ROUND_DOWN);
            money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.sub(Constant.TLJ_NEW_USER_MONEY, redPackWin.getMoney()), rate);
        }
        if (money.compareTo(new BigDecimal(0)) <= 0)
            return null;
        money = money.setScale(2);
        int num = 1;
        BigDecimal balance = null;
        if (redPackWin == null) {
            balance = money;
            // 注册开始 有效期
            Date endDate = DateUtil.plusDayDate(Constant.TLJ_NEW_USER_LIMIT, firstLoginTime);
            redPackWin = new UserTaoLiJinNewbies();
            redPackWin.setId(uid);
            redPackWin.setNum(1);
            redPackWin.setMoney(money);
            redPackWin.setEndTime(endDate);
            redPackWin.setCreateTime(nowTime);
            redPackWin.setUpdateTime(nowTime);
            userTaoLiJinNewbiesMapper.insertSelective(redPackWin);
        } else {
            userTaoLiJinNewbiesMapper.addMoney(uid, money);
            num = redPackWin.getNum() + 1;
            balance = MoneyBigDecimalUtil.add(money, redPackWin.getMoney());
        }
        // 明细
        UserTaoLiJinDetail detail = new UserTaoLiJinDetail();
        detail.setUid(uid);
        detail.setMoney(money);
        detail.setTitle(TaoLiJinDetailTypeEnum.add.getDesc());
        detail.setType(TaoLiJinDetailTypeEnum.add);
        detail.setCreateTime(new Date());
        detail.setRemark("新人红包");
        userTaoLiJinDetailService.insertSelective(detail);
        JSONObject json = new JSONObject();
        json.put("url", configTaoLiJinService.getValueByKey("new_user_free_buy_list"));
        TaoLiJinWinDetailVO winDetailVO = new TaoLiJinWinDetailVO();
        winDetailVO.setTitle("新人红包");
        winDetailVO.setBless("恭喜你!已领" + num + "/" + Constant.TLJ_NEW_USER_DAYS + "次");
        winDetailVO.setMoney(money.toString());
        winDetailVO.setDesc("已领取:" + balance + "元");
        winDetailVO.setTips(configTaoLiJinService.getValueByKey("new_user_win_tips"));
        winDetailVO.setParams(json.toString());
        winDetailVO.setJumpDetail(jumpDetailV2Service.getByTypeCache("web"));
        winDetailVO.setLogo(Constant.systemCommonConfig.getDefaultPortrait());
        winDetailVO.setLogoLight(userInfo.getPortrait());
        return winDetailVO;
    }
    @RequestSerializableByKeyService(key = "#uid")
    @Transactional(rollbackFor = Exception.class)
    @Override
    public String createTaoLiJinForBuy(TaoBaoGoodsBrief goods, Long uid) throws UserTaoLiJinNewbiesException {
        if (uid == null || uid <= 0 || goods == null)
            throw new UserTaoLiJinNewbiesException(1, "参数信息缺失");
        // 验证商品是否在免单商品库
        TLJFreeBuyGoods tljFreeBuyGoods = tljFreeBuyGoodsService.selectByAuctionIdAndDay(goods.getAuctionId(),
                TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd"));
        if (tljFreeBuyGoods == null)
            throw new UserTaoLiJinNewbiesException(1, "该商品非免单商品");
        // 验证是否有券
        if (goods == null || goods.getCouponAmount() == null ||
                goods.getCouponAmount().compareTo(new BigDecimal(0)) <= 0) {
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    tljFreeBuyGoodsService.deleteByGoodsId(goods.getAuctionId());
                }
            });
            throw new UserTaoLiJinNewbiesException(1, "该商品非免单商品");
        }
        // 验证券后价 是否在 1-2元
        BigDecimal money = TaoBaoUtil.getCouponPrice(goods);
        if (money.compareTo(new BigDecimal(1.0)) < 0 || money.compareTo(new BigDecimal(2.0)) > 0) {
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    tljFreeBuyGoodsService.deleteByGoodsId(goods.getAuctionId());
                }
            });
            throw new UserTaoLiJinNewbiesException(1, "该商品非免单商品");
        }
        // 验证用户信息
        UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
        if (userInfoExtra == null || userInfoExtra.getFirstLoginTime() == null)
            throw new UserTaoLiJinNewbiesException(1001, "你不是“新用户”无法使用新人红包0元购买。");
        // 验证是否激活
        if (StringUtil.isNullOrEmpty(userInfoExtra.getInviteCode()))
            throw new UserTaoLiJinNewbiesException(1002, "邀请码未激活,无法使用新人红包0元购买。");
        // 验证是否已超出新用户定义
        try {
            int days = DateUtil.daysBetween2(userInfoExtra.getFirstLoginTime(), new Date());
            if (days > Constant.TLJ_NEW_USER_DEFINE)
                throw new UserTaoLiJinNewbiesException(1001, "你不是“新用户”无法使用新人红包0元购买。");
        } catch (ParseException e1) {
            throw new UserTaoLiJinNewbiesException(1, "日期信息计算失败");
        }
        // 验证余额
        UserTaoLiJinNewbies taoLiJinNewbies = userTaoLiJinNewbiesMapper.selectForUpdate(uid);
        if (taoLiJinNewbies == null || taoLiJinNewbies.getMoney() == null ||
                taoLiJinNewbies.getMoney().compareTo(money) < 0)
            throw new UserTaoLiJinNewbiesException(1001, "新人红包不足,请换个商品再试或继续领取到足额新人红包。");
        // 验证是否已过期
        if (taoLiJinNewbies.getEndTime() == null
                || taoLiJinNewbies.getEndTime().getTime() < java.lang.System.currentTimeMillis())
            throw new UserTaoLiJinNewbiesException(1, "新人红包已过期");
        // 红包减少
        userTaoLiJinNewbiesMapper.subMoney(uid, money);
        // 加入明细
        UserTaoLiJinDetail detail = new UserTaoLiJinDetail();
        detail.setUid(uid);
        detail.setMoney(new BigDecimal("-" + money));
        detail.setTitle(TaoLiJinDetailTypeEnum.reduce.getDesc());
        detail.setType(TaoLiJinDetailTypeEnum.reduce);
        detail.setCreateTime(new Date());
        detail.setRemark("新人免单使用红包");
        userTaoLiJinDetailService.insertSelective(detail);
        String specialId = pidManager.getPid(SystemEnum.blks, Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.fanli);
        String specialRelationIdId = pidManager.getPid(SystemEnum.blks, Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.fanliChannel);
        // 创建淘礼金链接
        if (TaoBaoUtil.isSpecialGoods(goods.getMaterialLibType())) {
            return createTaoLiJin(goods.getAuctionId(), money, 1, specialId);
        } else { // 非返利库商品
            String relationId = null;
            try {
                relationId = taoBaoBuyRelationMapService.getRelationId(uid);
            } catch (Exception e) {
                LogHelper.errorDetailInfo(e, "uid:" + uid, null);
            }
            if (StringUtil.isNullOrEmpty(relationId))
                throw new UserTaoLiJinNewbiesException(1, "渠道未备案");
            return createTaoLiJin(goods.getAuctionId(), money, 1, specialRelationIdId)
                    + "&relationId=" + relationId;
        }
    }
    private String createTaoLiJin(Long auctionId, BigDecimal perface, int totalNum, String pid) throws UserTaoLiJinNewbiesException {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat formatStr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String name = "新人免单购";
        Date date = new Date();
        String date_str = format.format(date);
        String sendEndTime_str = date_str + " 22:00:00";
        String useEndTime_str = date_str + " 23:59:59";
        // 发放时间
        Date sendStartTime = date;
        Date sendEndTime = null;
        // 使用时间
        Date useStartTime = null;
        Date useEndTime = null;
        try {
            sendEndTime = formatStr.parse(sendEndTime_str);
            useEndTime = formatStr.parse(useEndTime_str);
        } catch (ParseException e2) {
            e2.printStackTrace();
        }
        // 创建淘礼金红包
        TaoLiJinDTO taoLiJinDTO = null;
        TaoKeAppInfo taoKeAppInfo = new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET, pid);
        try {
            taoLiJinDTO = TaoKeApiUtil.createTaoLiJin(auctionId, name, perface, totalNum, sendStartTime,
                    sendEndTime, useStartTime, useEndTime, taoKeAppInfo);
        } catch (TaoLiJinCreateException e) {
            LogHelper.errorDetailInfo(e);
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    if (e.getCode() == TaoLiJinCreateException.CODE_TLJ_FORBIDDEN) {
                        // 该商品不支持创建淘礼金红包
                        tljFreeBuyGoodsService.deleteByGoodsId(auctionId);
                    } else if (e.getCode() == TaoLiJinCreateException.CODE_TLJ_NO_MONEY) {
                        // 官方玩法钱包余额不足 TODO
                    }
                }
            });
        } catch (TaoKeApiException e) {
            LogHelper.errorDetailInfo(e);
        }
        if (taoLiJinDTO == null || StringUtil.isNullOrEmpty(taoLiJinDTO.getSendUrl()))
            throw new UserTaoLiJinNewbiesException(1, "淘宝API红包创建失败");
        return taoLiJinDTO.getSendUrl();
    }
    @Override
    public UserTaoLiJinNewbies selectByPrimaryKey(Long uid) {
        return userTaoLiJinNewbiesMapper.selectByPrimaryKey(uid);
    }
    @Override
    public long count(String key) {
        return userTaoLiJinNewbiesMapper.count(key);
    }
    @Override
    public List<UserTaoLiJinNewbies> query(int page, int count, String key, Integer order) {
        return userTaoLiJinNewbiesMapper.query((page - 1) * count, count, key, order);
    }
}
fanli/src/main/java/com/yeshi/fanli/service/impl/tlj/UserTaoLiJinRecordServiceImpl.java
@@ -10,7 +10,9 @@
import javax.annotation.Resource;
import com.yeshi.fanli.entity.SystemEnum;
import com.yeshi.fanli.entity.SystemPIDInfo;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.service.manger.PIDManager;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -131,6 +133,9 @@
        return userTaoLiJinRecordMapper.selectByPrimaryKey(id);
    }
    @Resource
    private PIDManager pidManager;
    @Transactional(rollbackFor = Exception.class)
    @Override
    public UserTaoLiJinRecord createSelfBuyTaoLiJin(Long uid, BigDecimal couplePrice, TaoBaoGoodsBrief goods)
@@ -168,7 +173,7 @@
                throw new UserTaoLiJinRecordException(101, "渠道未备案");
            }
            UserTaoLiJinRecord record = createUserTaoLiJin(1, uid, goods.getAuctionId(), couplePrice, 1, name,
                    sendStartTime, sendEndTime, null, useEndTime, TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID);
                    sendStartTime, sendEndTime, null, useEndTime, pidManager.getPidCache(SystemEnum.blks, Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.fanliChannel));
            record.setSendUrl(record.getSendUrl() + "&relationId=" + relationId);
            UserTaoLiJinRecord updateRecoed = new UserTaoLiJinRecord();
            updateRecoed.setId(record.getId());
@@ -177,7 +182,7 @@
            return record;
        } else {// 返利库商品
            return createUserTaoLiJin(1, uid, goods.getAuctionId(), couplePrice, 1, name, sendStartTime, sendEndTime, null,
                    useEndTime, TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT);
                    useEndTime,  pidManager.getPidCache(SystemEnum.blks, Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.fanli));
        }
    }
@@ -480,7 +485,7 @@
            BigDecimal shareMoney = new BigDecimal(0);
            BigDecimal commission = userTaoLiJinRecordVO.getCommission();
            if (commission != null && commission.compareTo(shareMoney) > 0) {
                BigDecimal shareRate = hongBaoManageService.getShareRate(UserLevelEnum.daRen,system);
                BigDecimal shareRate = hongBaoManageService.getShareRate(UserLevelEnum.daRen, system);
                shareMoney = MoneyBigDecimalUtil.mul(commission,
                        MoneyBigDecimalUtil.div(shareRate, new BigDecimal(100)));
                shareMoney = BigDecimalUtil.getWithNoZera(shareMoney);
fanli/src/main/java/com/yeshi/fanli/service/impl/user/TBPidServiceImpl.java
@@ -8,6 +8,10 @@
import javax.annotation.Resource;
import com.yeshi.fanli.entity.SystemEnum;
import com.yeshi.fanli.entity.SystemPIDInfo;
import com.yeshi.fanli.service.manger.PIDManager;
import com.yeshi.fanli.util.Constant;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
@@ -40,6 +44,9 @@
    @Resource
    private TaoBaoUnionConfigService taoBaoUnionConfigService;
    @Resource
    private PIDManager pidManager;
    private String getCookie() {
        String result = HttpUtil.get("http://193.112.35.168:8091/tb/cookie/getcookie?account=17784739772");
@@ -355,8 +362,8 @@
    }
    @Override
    public ClientTBPid getSharePid() {
        String pid = TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT;
    public ClientTBPid getSharePid(SystemEnum system) {
        String pid = pidManager.getPidCache(system, Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.share);
        ClientTBPid clientTBPid = new ClientTBPid(TaoBaoConstant.TAOBAO_AUTH_APPKEY, pid, pid.split("_")[2],
                pid.split("_")[3]);
        return clientTBPid;
fanli/src/main/java/com/yeshi/fanli/service/impl/user/cloud/UserCloudServiceImpl.java
@@ -9,7 +9,9 @@
import javax.annotation.Resource;
import com.yeshi.fanli.entity.SystemEnum;
import com.yeshi.fanli.entity.SystemPIDInfo;
import com.yeshi.fanli.exception.taobao.TaoBaoConvertLinkException;
import com.yeshi.fanli.service.manger.PIDManager;
import com.yeshi.fanli.service.manger.goods.TaoBaoLinkManager;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Service;
@@ -161,6 +163,10 @@
    @Resource
    private TaoBaoLinkManager taoBaoLinkManager;
    @Resource
    private PIDManager pidManager;
    @Override
    public UserCloud getValidByUid(Long uid) {
@@ -485,7 +491,7 @@
        for (CommentInfo commentInfo : comments) {
            String comment = null;
            try {
                comment = convertLinkManager.convertLinkFromText(commentInfo.getContent(), uid, true,false);
                comment = convertLinkManager.convertLinkFromText(user.getSystem(), commentInfo.getContent(), uid, true, false);
                hasToken = true;
            } catch (ConvertLinkExceptionException e) {
                if (e.getCode() != ConvertLinkExceptionException.CODE_NONE) {
@@ -865,7 +871,7 @@
                                 List<UserCloudGroup> listOpen, String pid) throws UserCloudException {
        TaoBaoLink taoBaoLink = null;
        try {
            taoBaoLink = taoBaoLinkManager.getTaoBaoLinkForShare(user.getId(), goodsId, relationId, null);
            taoBaoLink = taoBaoLinkManager.getTaoBaoLinkForShare(user.getSystem(), user.getId(), goodsId, relationId, null);
        } catch (TaoBaoConvertLinkException e) {
            LogHelper.errorDetailInfo(e);
            throw new UserCloudException(1, "该商品已下架");
@@ -930,7 +936,7 @@
            couponUrl = couponInfo.getLink();
        }
        String materialId = "https://item.jd.com/" + goodsId + ".html";
        String jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, null,JDApiUtil.POSITION_SHARE + "",
        String jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, null, pidManager.getPidCache(user.getSystem(), Constant.SOURCE_TYPE_JD, SystemPIDInfo.PidType.share),
                user.getId() + "");
        boolean coupon = false;
@@ -990,7 +996,7 @@
        if (goods == null)
            throw new UserCloudException(1, "该商品已下架");
        String jumpLink = PinDuoDuoApiUtil.getPromotionUrl(goods.getGoodsSign(), PinDuoDuoApiUtil.PID_SHARE + "", user.getId() + "");
        String jumpLink = PinDuoDuoApiUtil.getPromotionUrl(goods.getGoodsSign(), pidManager.getPidCache(user.getSystem(), Constant.SOURCE_TYPE_PDD, SystemPIDInfo.PidType.share), user.getId() + "");
        boolean coupon = true;
        if (goods.getHasCoupon() == null || !goods.getHasCoupon()) {
@@ -1102,7 +1108,7 @@
        String couponLink = goods.getCouponInfo().getCouponUrl();
        String jumpLink = SuningApiUtil.convertLink(SuningUtil.getProductUrl(sellerId + "", goodsId + ""),
                StringUtil.isNullOrEmpty(couponLink) ? null : couponLink, SuningApiUtil.PID_SHARE, user.getId() + "");
                StringUtil.isNullOrEmpty(couponLink) ? null : couponLink, pidManager.getPidCache(user.getSystem(), Constant.SOURCE_TYPE_SUNING, SystemPIDInfo.PidType.share), user.getId() + "");
        boolean coupon = false;
        String couponAmount = "";
fanli/src/main/java/com/yeshi/fanli/service/impl/user/tb/UserExtraTaoBaoInfoServiceImpl.java
@@ -298,17 +298,17 @@
    }
    @Override
    public UserExtraTaoBaoInfo getByRelationId(String relationId,SystemEnum system) {
    public UserExtraTaoBaoInfo getByRelationId(String relationId,List<SystemEnum> systemList) {
        if (StringUtil.isNullOrEmpty(relationId))
            return null;
        return userExtraTaoBaoInfoMapper.selectByRelationIdWithUidNotNull(relationId,system);
        return userExtraTaoBaoInfoMapper.selectByRelationIdWithUidNotNull(relationId,systemList);
    }
    @Override
    public UserExtraTaoBaoInfo getBySpecialId(String specialId,SystemEnum system) {
    public UserExtraTaoBaoInfo getBySpecialId(String specialId,List<SystemEnum> systemList) {
        if (StringUtil.isNullOrEmpty(specialId))
            return null;
        return userExtraTaoBaoInfoMapper.selectBySpecialIdWithUidNotNull(specialId,system);
        return userExtraTaoBaoInfoMapper.selectBySpecialIdWithUidNotNull(specialId,systemList);
    }
    @Override
fanli/src/main/java/com/yeshi/fanli/service/inter/dynamic/GoodsEvaluateService.java
@@ -94,7 +94,7 @@
     * @throws GoodsEvaluateException
     * @throws Exception
     */
    public void saveCurrencyCoupon(String pid, int kind, CommentInfo commentInfo) throws GoodsEvaluateException, Exception;
    public void saveCurrencyCoupon(SystemEnum system,String pid, int kind, CommentInfo commentInfo) throws GoodsEvaluateException, Exception;
    public void saveActivityPic(String pid, ImgInfo imgInfo, String picUrls, MultipartHttpServletRequest fileRequest)
fanli/src/main/java/com/yeshi/fanli/service/inter/user/TBPidService.java
@@ -1,5 +1,6 @@
package com.yeshi.fanli.service.inter.user;
import com.yeshi.fanli.entity.SystemEnum;
import com.yeshi.fanli.entity.taobao.ClientTBPid;
import com.yeshi.fanli.entity.taobao.TBPid;
@@ -40,6 +41,6 @@
     * 获取分享用的PID
     * @return
     */
    public ClientTBPid getSharePid();
    public ClientTBPid getSharePid(SystemEnum system);
}
fanli/src/main/java/com/yeshi/fanli/service/inter/user/tb/UserExtraTaoBaoInfoService.java
@@ -4,6 +4,8 @@
import com.yeshi.fanli.entity.bus.user.UserExtraTaoBaoInfo;
import com.yeshi.fanli.exception.user.UserExtraTaoBaoInfoException;
import java.util.List;
/**
 * 用户淘宝联盟服务
 * 
@@ -65,14 +67,14 @@
     * @param relationId
     * @return
     */
    public UserExtraTaoBaoInfo getByRelationId(String relationId, SystemEnum system);
    public UserExtraTaoBaoInfo getByRelationId(String relationId, List<SystemEnum> systemList);
    /**
     * 通过会员运营ID查询用户(用户信息不为空)
     * @param specialId
     * @return
     */
    public UserExtraTaoBaoInfo getBySpecialId(String specialId, SystemEnum system);
    public UserExtraTaoBaoInfo getBySpecialId(String specialId, List<SystemEnum> systemList);
    /**
fanli/src/main/java/com/yeshi/fanli/service/manger/PIDManager.java
New file
@@ -0,0 +1,95 @@
package com.yeshi.fanli.service.manger;
import com.yeshi.fanli.dao.mongo.system.SystemPIDInfoDao;
import com.yeshi.fanli.entity.SystemEnum;
import com.yeshi.fanli.entity.SystemPIDInfo;
import com.yeshi.fanli.exception.ParamsException;
import com.yeshi.fanli.util.StringUtil;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
/**
 * 推广位管理器
 */
@Component
public class PIDManager {
    @Resource
    private SystemPIDInfoDao systemPIDInfoDao;
    /**
     * 根据PID查询pid完整信息
     *
     * @param pid
     * @param sourceType
     * @return
     */
    public List<SystemPIDInfo> listPidInfoByPid(String pid, int sourceType) {
        SystemPIDInfoDao.DaoQuery daoQuery = new SystemPIDInfoDao.DaoQuery();
        daoQuery.sourceType = sourceType;
        daoQuery.pid = pid;
        daoQuery.count = 100;
        return systemPIDInfoDao.list(daoQuery);
    }
    @Cacheable(value = "configCache", key = "' listPidInfoByPid-'+#pid+'-'+#sourceType")
    public List<SystemPIDInfo> listPidInfoByPidCache(String pid, Integer sourceType) {
        return listPidInfoByPid(pid, sourceType);
    }
    /**
     * 获取PID
     *
     * @param systemEnum
     * @param sourceType
     * @param pidType
     * @return
     */
    public String getPid(SystemEnum systemEnum, Integer sourceType, SystemPIDInfo.PidType pidType) {
        String id = SystemPIDInfo.createId(systemEnum, sourceType, pidType);
        SystemPIDInfo info = systemPIDInfoDao.get(id);
        if (info != null)
            return info.getPid();
        return null;
    }
    /**
     * 获取PID缓存
     *
     * @param systemEnum
     * @param pidType
     * @return
     */
    @Cacheable(value = "configCache", key = "'getPid-'+#systemEnum+'-'+#sourceType+'-'+#pidType")
    public String getPidCache(SystemEnum systemEnum, Integer sourceType, SystemPIDInfo.PidType pidType) {
        return getPid(systemEnum, sourceType, pidType);
    }
    /**
     * 保存PIDInfo
     *
     * @param pidInfo
     * @throws ParamsException
     */
    public void savePidInfo(SystemPIDInfo pidInfo) throws ParamsException {
        if (StringUtil.isNullOrEmpty(pidInfo.getPid()) || pidInfo.getSourceType() == null || pidInfo.getSystem() == null || pidInfo.getPidType() == null) {
            throw new ParamsException(1, "参数不完整");
        }
        String id = SystemPIDInfo.createId(pidInfo.getSystem(), pidInfo.getSourceType(), pidInfo.getPidType());
        pidInfo.setId(id);
        if (pidInfo.getCreateTime() == null) {
            pidInfo.setCreateTime(new Date());
        }
        systemPIDInfoDao.save(pidInfo);
    }
}
fanli/src/main/java/com/yeshi/fanli/service/manger/goods/ConvertLinkManager.java
@@ -12,7 +12,11 @@
import javax.annotation.Resource;
import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
import com.yeshi.fanli.entity.SystemEnum;
import com.yeshi.fanli.entity.SystemPIDInfo;
import com.yeshi.fanli.service.inter.pdd.PDDAuthService;
import com.yeshi.fanli.service.manger.PIDManager;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.vo.pdd.PDDConvertLinkResultVO;
import org.springframework.stereotype.Component;
import org.yeshi.utils.StringUtil;
@@ -60,12 +64,15 @@
    @Resource
    private PDDAuthService pddAuthService;
    @Resource
    private PIDManager pidManager;
    /**
     * @Title: convertJDLinkFromText @Description:转链文本中的京东短链 @param text @param
     * uid @param share @return @throws Exception String 返回类型 @throws
     */
    public String convertJDLinkFromText(String text, Long uid, boolean share, boolean simpleTKToken) throws Exception {
    public String convertJDLinkFromText(SystemEnum system, String text, Long uid, boolean share, boolean simpleTKToken) throws Exception {
        StringBuilder builder = new StringBuilder(text);
        String newText = builder.toString();
@@ -79,10 +86,10 @@
            for (String shortLink : linkSet) {
                String link = null;
                if (share)
                    link = JDApiUtil.convertLinkWithSubUnionId(shortLink, null, null, JDApiUtil.POSITION_SHARE + "",
                    link = JDApiUtil.convertLinkWithSubUnionId(shortLink, null, null, pidManager.getPidCache(system, Constant.SOURCE_TYPE_JD, SystemPIDInfo.PidType.share),
                            uid + "");
                else
                    link = JDApiUtil.convertLinkWithSubUnionId(shortLink, null, null, JDApiUtil.POSITION_FANLI + "",
                    link = JDApiUtil.convertLinkWithSubUnionId(shortLink, null, null, pidManager.getPidCache(system, Constant.SOURCE_TYPE_JD, SystemPIDInfo.PidType.fanli),
                            uid + "");
                if (!StringUtil.isNullOrEmpty(link)) {
                    linkMap.put(shortLink, link);
@@ -99,7 +106,7 @@
        return newText;
    }
    public String convertPDDLinkFromText(String text, Long uid, boolean share) throws Exception {
    public String convertPDDLinkFromText(SystemEnum system, String text, Long uid, boolean share) throws Exception {
        StringBuilder builder = new StringBuilder(text);
        String newText = builder.toString();
@@ -118,7 +125,7 @@
                    if (goodsDetail == null)
                        throw new Exception("拼多多转链失败");
                    PDDConvertLinkResultVO pddUrl = PinDuoDuoApiUtil.convert(goodsDetail.getGoodsSign(),
                            share ? PinDuoDuoApiUtil.PID_SHARE : PinDuoDuoApiUtil.PID_FANLI, pddAuthService.getFanliCustomParams(uid), false);
                            share ? pidManager.getPidCache(system, Constant.SOURCE_TYPE_PDD, SystemPIDInfo.PidType.share) : pidManager.getPidCache(system, Constant.SOURCE_TYPE_PDD, SystemPIDInfo.PidType.fanli), pddAuthService.getFanliCustomParams(uid), false);
                    if (pddUrl != null) {
                        linkMap.put(shortLink, pddUrl.getShort_url());
                    }
@@ -165,7 +172,12 @@
     * @return
     * @throws Exception
     */
    private String convertTBLinkFromText(String text, Long uid, boolean share, boolean simpleToken) throws Exception {
    private String convertTBLinkFromText(SystemEnum system, String text, Long uid, boolean share, boolean simpleToken) throws Exception {
        String specialPid = pidManager.getPid(system, Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.fanli);
        String relationPid = pidManager.getPid(system, Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.share);
        String specialRelationPid = pidManager.getPid(system, Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.fanliChannel);
        StringBuilder builder = new StringBuilder(text);
        String newText = builder.toString();
@@ -194,7 +206,7 @@
                String link = null;
                if (share) {
                    //暂时调用好单库API
                    link = HaoDanKuApiUtil.getInstance().convertLink(auctionId, TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT, null, null, relationId);
                    link = HaoDanKuApiUtil.getInstance().convertLink(auctionId, relationPid, null, null, relationId);
//                    TaoBaoGoodsBrief goods =  TaoKeApiUtil.specialConvertCoupon(auctionId,
//                            new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET,
//                                    TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT));
@@ -216,7 +228,7 @@
                        TaoBaoGoodsBrief goods = TaoKeApiUtil.specialConvertCoupon(auctionId,
                                new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY,
                                        TaoBaoConstant.TAOBAO_AUTH_APPSECRET,
                                        TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT), specialId, null);
                                        specialPid), specialId, null);
                        if (goods == null)
                            throw new Exception("商品转链失败");
@@ -230,7 +242,7 @@
                        TaoBaoGoodsBrief goods = TaoKeApiUtil.specialConvertCoupon(auctionId,
                                new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY,
                                        TaoBaoConstant.TAOBAO_AUTH_APPSECRET,
                                        TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID), specialId, null);
                                        specialRelationPid), specialId, null);
                        if (goods == null)
                            throw new Exception("商品转链失败");
@@ -274,7 +286,7 @@
            for (String st : list) {
                String activityid = st.replace("{淘宝活动:", "").replace("}", "");
                if (!StringUtil.isNullOrEmpty(activityid)) {
                    String adzoneId = TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT.split("_")[3];
                    String adzoneId = relationPid.split("_")[3];
                    TaoKeOfficialActivityConvertResultDTO dto = TaoKeApiUtil.officialActivityConvert(adzoneId,
                            activityid, relationId);
                    String link = dto.getShort_click_url();
@@ -295,11 +307,11 @@
     * @Title: convertLinkFromText @Description: 从文本转链 @param text @return
     * String 返回类型 @throws
     */
    public String convertLinkFromText(String text, Long uid, boolean share, boolean simpleToken)
    public String convertLinkFromText(SystemEnum system, String text, Long uid, boolean share, boolean simpleToken)
            throws ConvertLinkExceptionException, Exception {
        String newText = convertJDLinkFromText(text, uid, share, simpleToken);
        newText = convertPDDLinkFromText(newText, uid, share);
        newText = convertTBLinkFromText(newText, uid, share, simpleToken);
        String newText = convertJDLinkFromText(system, text, uid, share, simpleToken);
        newText = convertPDDLinkFromText(system, newText, uid, share);
        newText = convertTBLinkFromText(system, newText, uid, share, simpleToken);
        List<String> urls = UrlUtils.parseUrlsFromText(text);
        if (urls != null)
fanli/src/main/java/com/yeshi/fanli/service/manger/goods/TaoBaoLinkManager.java
@@ -1,6 +1,8 @@
package com.yeshi.fanli.service.manger.goods;
import com.yeshi.common.entity.taobao.TaoKeAppInfo;
import com.yeshi.fanli.entity.SystemEnum;
import com.yeshi.fanli.entity.SystemPIDInfo;
import com.yeshi.fanli.entity.taobao.PidUser;
import com.yeshi.fanli.entity.taobao.TBPid;
import com.yeshi.fanli.entity.taobao.TaoBaoLink;
@@ -13,6 +15,7 @@
import com.yeshi.fanli.service.inter.redpack.UserTaoLiJinNewbiesService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
import com.yeshi.fanli.service.inter.user.TBPidService;
import com.yeshi.fanli.service.manger.PIDManager;
import com.yeshi.fanli.util.*;
import com.yeshi.fanli.util.cache.TaoBaoGoodsCacheUtil;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
@@ -58,6 +61,9 @@
    @Resource
    private TaoBaoCouponCacheService taoBaoCouponCacheService;
    @Resource
    private PIDManager pidManager;
    /**
     * 只领券
@@ -67,7 +73,7 @@
     * @param pid
     * @return
     */
    public TaoBaoLink getTaoBaoLinkForRecieveCoupon(Long auctionId, String specialId, String pid) throws TaoBaoConvertLinkException {
    public TaoBaoLink getTaoBaoLinkForRecieveCoupon(SystemEnum system, Long auctionId, String specialId, String pid) throws TaoBaoConvertLinkException {
        if (auctionId == null || auctionId <= 0) {
            throw new TaoBaoConvertLinkException(2, "商品ID不能为空");
        }
@@ -76,7 +82,7 @@
        app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY);
        app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
        if (pid == null)
            app.setPid(TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT);
            app.setPid(pidManager.getPidCache(system, Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.fanli));
        else
            app.setPid(pid);
@@ -136,11 +142,11 @@
     * @param pid
     * @return
     */
    public TaoBaoLink getTaoBaoLinkForBuy(Long uid, Long auctionId, String specialId, String pid) throws TaoBaoConvertLinkException {
    public TaoBaoLink getTaoBaoLinkForBuy(SystemEnum system, Long uid, Long auctionId, String specialId, String pid) throws TaoBaoConvertLinkException {
        if (uid == null || uid <= 0) {
            throw new TaoBaoConvertLinkException(1, "用户ID不能为空");
        }
        return getTaoBaoLinkForRecieveCoupon(auctionId, specialId, pid);
        return getTaoBaoLinkForRecieveCoupon(system, auctionId, specialId, pid);
    }
@@ -232,7 +238,7 @@
     * @param pid
     * @return
     */
    public TaoBaoLink getTaoBaoLinkForShare(Long uid, Long auctionId, String relationId, String pid) throws
    public TaoBaoLink getTaoBaoLinkForShare(SystemEnum system, Long uid, Long auctionId, String relationId, String pid) throws
            TaoBaoConvertLinkException {
        if (uid == null || uid <= 0) {
            throw new TaoBaoConvertLinkException(1, "用户ID不能为空");
@@ -246,7 +252,7 @@
        if (!StringUtil.isNullOrEmpty(relationId)) {
            if (StringUtil.isNullOrEmpty(pid))
                pid = TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT;
                pid = pidManager.getPidCache(system, Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.share);
            String appId = pid.split("_")[2];
            String adzoneId = pid.split("_")[3];
            TaoBaoUnionConfig taoBaoUnionConfig = taoBaoUnionConfigService.getConfigByAppIdCache(appId);
@@ -410,7 +416,7 @@
     * @param pid
     * @return
     */
    public TaoBaoLink getTaoLiJinLinkForShare(Long uid, Long auctionId, String relationId, String pid) throws
    public TaoBaoLink getTaoLiJinLinkForShare(SystemEnum system, Long uid, Long auctionId, String relationId, String pid) throws
            TaoBaoConvertLinkException {
        if (uid == null || uid <= 0) {
            throw new TaoBaoConvertLinkException(1, "用户ID不能为空");
@@ -424,7 +430,7 @@
        if (!StringUtil.isNullOrEmpty(relationId)) {
            if (StringUtil.isNullOrEmpty(pid))
                pid = TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT;
                pid = pidManager.getPidCache(system, Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.share);
            String appId = pid.split("_")[2];
            String adzoneId = pid.split("_")[3];
            TaoBaoUnionConfig taoBaoUnionConfig = taoBaoUnionConfigService.getConfigByAppIdCache(appId);
fanli/src/main/java/com/yeshi/fanli/util/TaoBaoConstant.java
@@ -8,23 +8,17 @@
    // 淘宝第三方授权
    public static final String TAOBAO_AUTH_APPKEY = "24980167";
    public static final String TAOBAO_AUTH_APPSECRET = "e0a2e05deabf5ce039b52e5b492d5382";
    public static final String TAOBAO_RELATION_PID_DEFAULT = "mm_124933865_56750082_87140050199";
    public static final String TAOBAO_SPECIAL_PID_DEFAULT = "mm_124933865_56750082_89555600043";
    public static final String TAOBAO_PID_DEFAULT="mm_124933865_56750082_89555600043";
    // 淘宝常用查询的媒体信息
    public static final String TAOBAO_COMMON_APPKEY = "24838852";
    public static final String TAOBAO_COMMON_APPSECRET = "bc8265e2bf8d8115329d652f9d3d4cd8";
    public static final String TAOBAO_COMMON_PID = "mm_124933865_43788020_437192946";
    // 淘宝将渠道ID处理成会员ID的pid
    public static final String TAOBAO_RELATION_AS_SPECIAL_PID = "mm_124933865_56750082_18689550042";
    // 淘礼金渠道ID
    public static final String TAOBAO_TLJ_RELATION_PID_DEFAULT = "mm_124933865_56750082_19507100253";
    // 淘礼金渠道会员
    public static final String TAOBAO_TLJ_RELATION_AS_SPECIAL_PID = "mm_124933865_56750082_19508150186";
    //饿了么PID
    public static final String TAOBAO_ELEME_PID = "mm_124933865_56750082_109491050276";
    
    //口碑PID
    public static final String TAOBAO_KOUBEI_PID = "mm_124933865_56750082_19511700026";
@@ -41,8 +35,8 @@
    public final static String SHARE_PRICE_TM="T猫价";
    public static TaoKeAppInfo getSpecialAuthAppInfo(){
        return new TaoKeAppInfo(TAOBAO_AUTH_APPKEY,TAOBAO_AUTH_APPSECRET,TAOBAO_SPECIAL_PID_DEFAULT);
    public static TaoKeAppInfo getSpecialAuthAppInfo(String pid){
        return new TaoKeAppInfo(TAOBAO_AUTH_APPKEY,TAOBAO_AUTH_APPSECRET,pid);
    }
}
fanli/src/main/java/com/yeshi/fanli/util/jd/JDApiUtil.java
@@ -46,9 +46,9 @@
    public static String SECRET_KEY = "e22367fc866746d98b50d47b4c521781";
    private static String SERVER_URL = "https://router.jd.com/api";
    public static long POSITION_FANLI = 1869704794L;
    public static long POSITION_SHARE = 1869542990L;
    public static long POSITION_COUPON = 1869704796L;
//    public static long POSITION_FANLI = 1869704794L;
//    public static long POSITION_SHARE = 1869542990L;
//    public static long POSITION_COUPON = 1869704796L;
    // 订单查询类型
    public static int ORDER_TYPE_CREATETIME = 1;// 下单时间
fanli/src/main/java/com/yeshi/fanli/util/pinduoduo/PinDuoDuoApiUtil.java
@@ -28,9 +28,11 @@
import net.sf.json.JSONObject;
public class PinDuoDuoApiUtil {
    public final static String PID_FANLI = "8590899_72067894";
    public final static String PID_SHARE = "8590899_72067895";
    public final static String PID_COUPON = "8590899_102657575";
//    public final static String PID_FANLI = "8590899_72067894";
//    public final static String PID_SHARE = "8590899_72067895";
//    public final static String PID_COUPON = "8590899_102657575";
    public final static String PID_DEFAULT = "8590899_72067894";
    private final static String CLIENT_ID = "9f6ee5ebd3b94c2080c4d51c2427e9fa";
    private final static String CLIENT_SECRET = "95e1f1904385664bf4b87d4b34de12f9f31c505d";
@@ -105,7 +107,7 @@
            map.put("range_list", gson.toJson(sf.getRangeList()).toString());
        }
        map.put("pid", PID_FANLI);
        map.put("pid", PID_DEFAULT);
        String result = baseRequest(map);
        System.out.println(result);
        JSONObject json = JSONObject.fromObject(result);
@@ -168,7 +170,7 @@
            map.put("activity_tags", JSONArray.fromObject(Arrays.asList(activityTags)).toString());
        }
        map.put("pid", PID_FANLI);
        map.put("pid", PID_DEFAULT);
        String result = baseRequest(map);
        JSONObject json = JSONObject.fromObject(result);
@@ -445,7 +447,7 @@
     */
    public static PDDGoodsDetail getGoodsDetail(Long goodsId) {
        try {
            return getGoodsDetail(goodsId, PID_FANLI, "437032");
            return getGoodsDetail(goodsId, PID_DEFAULT, "437032");
        } catch (PDDApiException e) {
            e.printStackTrace();
        }
@@ -513,7 +515,7 @@
        Map<String, String> map = new HashMap<>();
        map.put("type", "pdd.ddk.phrase.generate");
        map.put("goods_id_list", array.toString());
        map.put("p_id", PID_FANLI);
        map.put("p_id", PID_DEFAULT);
        String result = baseRequest(map);
        JSONObject resultJson = JSONObject.fromObject(result);
        JSONObject root = resultJson.optJSONObject("ddk_phrase_generate_response");
@@ -629,6 +631,6 @@
        PDDGoodsDetail goods = PinDuoDuoApiUtil.getGoodsDetail(227873724698L);
        PinDuoDuoApiUtil.convert(goods.getGoodsSign(), PID_FANLI + "","437032", false);
        PinDuoDuoApiUtil.convert(goods.getGoodsSign(), PID_DEFAULT + "","437032", false);
    }
}
fanli/src/main/java/com/yeshi/fanli/util/suning/SuningApiUtil.java
@@ -33,9 +33,11 @@
    public final static String APP_SECRET = "a217bc7018fd8ca112bb60f09057d996";
    public final static String APP_KEY = "6fca015e83eff7ef150bebcad418ea32";
    public final static String PID_SHARE = "666527";
    public final static String PID_BUY = "666526";
    public final static String PID_COUPON = "666528";
//    public final static String PID_SHARE = "666527";
//    public final static String PID_BUY = "666526";
//    public final static String PID_COUPON = "666528";
    public final static String PID_DEFAULT = "666526";
    private static String post(String url, String entity, Map<String, String> headers) {
        String charset = "utf-8";
fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoKeApiUtil.java
@@ -376,7 +376,7 @@
        // 从转链搜索
        TaoBaoGoodsBrief newGoods = specialConvertCoupon(goods.getAuctionId(),
                new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET,
                        TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT), specialId, relationId);
                        TaoBaoConstant.TAOBAO_PID_DEFAULT), specialId, relationId);
        if (newGoods != null) {
            goods.setTkRate(newGoods.getTkRate());
@@ -457,7 +457,7 @@
        // 从转链搜索
        TaoBaoGoodsBrief newGoods = specialConvertCoupon(goods.getAuctionId(),
                new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET,
                        TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT), null, null);
                        TaoBaoConstant.TAOBAO_PID_DEFAULT), null, null);
        if (newGoods != null) {
            goods.setTkRate(newGoods.getTkRate());
@@ -1540,32 +1540,6 @@
        return result;
    }
    /**
     * 从淘宝链接中解析商品ID(高级接口)
     *
     * @param link
     * @return
     */
    public static String parseAuctionIdFromLink(String link) {
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.item.click.extract");
        map.put("click_url", link + "");
        TaoKeAppInfo app = new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET,
                TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID);
        JSONObject resultJSON = null;
        try {
            resultJSON = TaoKeBaseUtil.baseRequest(map, app);
            System.out.println(resultJSON);
        } catch (TaoKeApiException e) {
            e.printStackTrace();
        }
        if (resultJSON == null)
            return null;
        return null;
    }
    public static String getAccessToken(String code, String appKey, String appSecret) {
        Map<String, String> map = new HashMap<>();
@@ -1803,64 +1777,6 @@
        return null;
    }
    public static void juHuaSuan() {
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.ju.items.search");
        map.put("current_page", 1 + "");
        map.put("page_size", 100 + "");
        map.put("pid", "mm_124933865_43788020_381938426");
        TaoKeAppInfo app = new TaoKeAppInfo();
        app.setAppKey("24838852");
        app.setAppSecret("bc8265e2bf8d8115329d652f9d3d4cd8");
        try {
            JSONObject json = TaoKeBaseUtil.baseRequest(map, app);
            System.out.println(json);
        } catch (TaoKeApiException e) {
            e.printStackTrace();
        }
    }
    public static void taoKeContent() {
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.content.get");
        map.put("adzone_id", TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT.split("_")[3]);
        map.put("type", "1");
        map.put("count", "100");
        TaoKeAppInfo app = new TaoKeAppInfo();
        app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY);
        app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
        try {
            JSONObject json = TaoKeBaseUtil.baseRequest(map, app);
            System.out.println(json);
        } catch (TaoKeApiException e) {
            e.printStackTrace();
        }
    }
    public static void taoKeContentSource(String contentId, String source) {
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.dg.optimus.material");
        map.put("adzone_id", TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT.split("_")[3]);
        map.put("page_size", "10");
        map.put("page_no", "1");
        map.put("content_id", contentId);
        map.put("content_source", source);
        map.put("material_id", "1");
        TaoKeAppInfo app = new TaoKeAppInfo();
        app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY);
        app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
        try {
            JSONObject json = TaoKeBaseUtil.baseRequest(map, app);
            System.out.println(json);
        } catch (TaoKeApiException e) {
            e.printStackTrace();
        }
    }
    // AA5ISJ
@@ -1973,44 +1889,6 @@
        }
    }
    public static void getTaoKeContentEffective() {
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.dg.optimus.material");
        map.put("adzone_id", TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID.split("_")[3]);
        map.put("page_no", "1");
        map.put("page_size", "20");
        map.put("content_id", "8872035");
        TaoKeAppInfo app = new TaoKeAppInfo();
        app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY);
        app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
        try {
            JSONObject json = TaoKeBaseUtil.baseRequest(map, app);
            System.out.println(json);
        } catch (TaoKeApiException e) {
            e.printStackTrace();
        }
    }
    public static void getTaoKeContent() {
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.content.get");
        map.put("adzone_id", TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID.split("_")[3]);
        map.put("type", "1");
        TaoKeAppInfo app = new TaoKeAppInfo();
        app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY);
        app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
        try {
            JSONObject json = TaoKeBaseUtil.baseRequest(map, app);
            System.out.println(json);
        } catch (TaoKeApiException e) {
            e.printStackTrace();
        }
    }
    /**
     * 淘口令转商品ID
     *
@@ -2021,7 +1899,7 @@
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.tpwd.convert");
        map.put("password_content", token);
        map.put("adzone_id", TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT.split("_")[3]);
        map.put("adzone_id", TaoBaoConstant.TAOBAO_PID_DEFAULT.split("_")[3]);
        TaoKeAppInfo app = new TaoKeAppInfo();
        app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY);
        app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
@@ -2165,7 +2043,7 @@
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.itemid.coupon.get");
        map.put("platform", 2 + "");
        map.put("pid", TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID);
        map.put("pid", TaoBaoConstant.TAOBAO_PID_DEFAULT);
        map.put("num_iids", auctionId + "");
        TaoKeAppInfo app = new TaoKeAppInfo();
        app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY);
@@ -2270,13 +2148,13 @@
        map.put("method", "taobao.tbk.itemid.coupon.get");
        map.put("platform", auctionId + "");
        map.put("num_iids", auctionId + "");
        map.put("pid", TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT);
        map.put("pid", TaoBaoConstant.TAOBAO_PID_DEFAULT);
        List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
        JSONObject resultJSON = null;
        try {
            resultJSON = TaoKeBaseUtil.baseRequest(map, new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY,
                    TaoBaoConstant.TAOBAO_AUTH_APPSECRET, TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT));
                    TaoBaoConstant.TAOBAO_AUTH_APPSECRET, TaoBaoConstant.TAOBAO_PID_DEFAULT));
            JSONObject response = resultJSON.optJSONObject("tbk_dg_optimus_material_response");
            if (response != null && response.optJSONObject("result_list") != null) {
fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoKeScApiUtil.java
@@ -260,7 +260,7 @@
    /**
     * 获取商品详情,简版
     *
     * @param id
     * @param ids
     * @return
     */
    public static List<TaoBaoGoodsBrief> getBatchGoodsInfos(String ids) throws TaobaoGoodsDownException {
@@ -324,7 +324,7 @@
        // 从转链搜索
        TaoBaoGoodsBrief newGoods = specialConvertCoupon(goods.getAuctionId(),
                new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET,
                        TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT));
                        TaoBaoConstant.TAOBAO_PID_DEFAULT));
        if (newGoods != null) {
            goods.setTkRate(newGoods.getTkRate());
@@ -401,7 +401,7 @@
        // 从转链搜索
        TaoBaoGoodsBrief newGoods = specialConvertCoupon(goods.getAuctionId(),
                new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET,
                        TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT));
                        TaoBaoConstant.TAOBAO_PID_DEFAULT));
        if (newGoods != null) {
            goods.setTkRate(newGoods.getTkRate());
@@ -1446,32 +1446,6 @@
        return result;
    }
    /**
     * 从淘宝链接中解析商品ID(高级接口)
     *
     * @param link
     * @return
     */
    public static String parseAuctionIdFromLink(String link) {
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.item.click.extract");
        map.put("click_url", link + "");
        TaoKeAppInfo app = new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET,
                TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID);
        JSONObject resultJSON = null;
        try {
            resultJSON = TaoKeBaseUtil.baseRequest(map, app);
            System.out.println(resultJSON);
        } catch (TaoKeApiException e) {
            e.printStackTrace();
        }
        if (resultJSON == null)
            return null;
        return null;
    }
    public static String getAccessToken(String code, String appKey, String appSecret) {
        Map<String, String> map = new HashMap<>();
@@ -1716,44 +1690,6 @@
    }
    public static void taoKeContent() {
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.content.get");
        map.put("adzone_id", TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT.split("_")[3]);
        map.put("type", "1");
        map.put("count", "100");
        TaoKeAppInfo app = new TaoKeAppInfo();
        app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY);
        app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
        try {
            JSONObject json = TaoKeBaseUtil.baseRequest(map, app);
            System.out.println(json);
        } catch (TaoKeApiException e) {
            e.printStackTrace();
        }
    }
    public static void taoKeContentSource(String contentId, String source) {
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.dg.optimus.material");
        map.put("adzone_id", TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT.split("_")[3]);
        map.put("page_size", "10");
        map.put("page_no", "1");
        map.put("content_id", contentId);
        map.put("content_source", source);
        map.put("material_id", "1");
        TaoKeAppInfo app = new TaoKeAppInfo();
        app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY);
        app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
        try {
            JSONObject json = TaoKeBaseUtil.baseRequest(map, app);
            System.out.println(json);
        } catch (TaoKeApiException e) {
            e.printStackTrace();
        }
    }
    // AA5ISJ
@@ -1866,44 +1802,6 @@
        }
    }
    public static void getTaoKeContentEffective() {
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.dg.optimus.material");
        map.put("adzone_id", TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID.split("_")[3]);
        map.put("page_no", "1");
        map.put("page_size", "20");
        map.put("content_id", "8872035");
        TaoKeAppInfo app = new TaoKeAppInfo();
        app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY);
        app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
        try {
            JSONObject json = TaoKeBaseUtil.baseRequest(map, app);
            System.out.println(json);
        } catch (TaoKeApiException e) {
            e.printStackTrace();
        }
    }
    public static void getTaoKeContent() {
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.content.get");
        map.put("adzone_id", TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID.split("_")[3]);
        map.put("type", "1");
        TaoKeAppInfo app = new TaoKeAppInfo();
        app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY);
        app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
        try {
            JSONObject json = TaoKeBaseUtil.baseRequest(map, app);
            System.out.println(json);
        } catch (TaoKeApiException e) {
            e.printStackTrace();
        }
    }
    /**
     * 淘口令转商品ID
     *
@@ -1914,7 +1812,7 @@
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.tpwd.convert");
        map.put("password_content", token);
        map.put("adzone_id", TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT.split("_")[3]);
        map.put("adzone_id", TaoBaoConstant.TAOBAO_PID_DEFAULT.split("_")[3]);
        TaoKeAppInfo app = new TaoKeAppInfo();
        app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY);
        app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
@@ -2054,7 +1952,7 @@
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.itemid.coupon.get");
        map.put("platform", 2 + "");
        map.put("pid", TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID);
        map.put("pid", TaoBaoConstant.TAOBAO_PID_DEFAULT);
        map.put("num_iids", auctionId + "");
        TaoKeAppInfo app = new TaoKeAppInfo();
        app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY);
@@ -2159,13 +2057,13 @@
        map.put("method", "taobao.tbk.itemid.coupon.get");
        map.put("platform", auctionId + "");
        map.put("num_iids", auctionId + "");
        map.put("pid", TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT);
        map.put("pid", TaoBaoConstant.TAOBAO_PID_DEFAULT);
        List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
        JSONObject resultJSON = null;
        try {
            resultJSON = TaoKeBaseUtil.baseRequest(map, new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY,
                    TaoBaoConstant.TAOBAO_AUTH_APPSECRET, TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT));
                    TaoBaoConstant.TAOBAO_AUTH_APPSECRET, TaoBaoConstant.TAOBAO_PID_DEFAULT));
            JSONObject response = resultJSON.optJSONObject("tbk_dg_optimus_material_response");
            if (response != null && response.optJSONObject("result_list") != null) {
fanli/src/main/resource/mapping/user/UserExtraTaoBaoInfoMapper.xml
@@ -65,7 +65,9 @@
    <select id="listByTaoBaoUid" resultMap="BaseResultMap"
            parameterType="java.lang.String">
        SELECT    <include refid="Base_Column_List"/>  FROM yeshi_ec_user_info_extra_taobao tb left join yeshi_ec_user on id=uiet_uid
        SELECT
        <include refid="Base_Column_List"/>
        FROM yeshi_ec_user_info_extra_taobao tb left join yeshi_ec_user on id=uiet_uid
        WHERE
        tb.`uiet_taobao_uid` = #{taoBaoUid}
        <if test="system!=null">
@@ -80,8 +82,10 @@
        <include refid="Base_Column_List"/>
        from yeshi_ec_user_info_extra_taobao left join yeshi_ec_user on id=uiet_uid where uiet_relation_id =
        #{relationId}
        <if test="system!=null">
            AND system=#{system}
        <if test="systemList!=null">
            <foreach collection="systemList" open=" and (" close=")" separator=" or " item="system">
                system=#{system}
            </foreach>
        </if>
        and
        uiet_uid is not null order by uiet_id desc limit 1
@@ -94,8 +98,10 @@
        <include refid="Base_Column_List"/>
        from yeshi_ec_user_info_extra_taobao left join yeshi_ec_user on id=uiet_uid where uiet_special_id =
        #{specialId}
        <if test="system!=null">
          AND system=#{system}
        <if test="systemList!=null">
            <foreach collection="systemList" open=" and (" close=")" separator=" or " item="system">
                system=#{system}
            </foreach>
        </if>
        and
        uiet_uid is not null order by uiet_id desc limit 1