| | |
| | | import com.yeshi.fanli.dao.mybatis.UserInfoMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.UserShareGoodsHistoryMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.share.PidUserMapper;
|
| | | import com.yeshi.fanli.dto.taobao.TaoLiJinDTO;
|
| | | import com.yeshi.fanli.entity.bus.share.UserShareGoodsHistory;
|
| | | import com.yeshi.fanli.entity.bus.tlj.UserTaoLiJinRecord;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.entity.bus.user.UserMoneyExtra;
|
| | | import com.yeshi.fanli.entity.taobao.PidUser;
|
| | | import com.yeshi.fanli.entity.taobao.TBPid;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoLink;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig;
|
| | | import com.yeshi.fanli.entity.taobao.TaoKeAppInfo;
|
| | | import com.yeshi.fanli.exception.ShareGoodsException;
|
| | | import com.yeshi.fanli.entity.taobao.UserTLJBuyHistory;
|
| | | import com.yeshi.fanli.exception.share.ShareGoodsException;
|
| | | import com.yeshi.fanli.exception.taobao.TaoKeApiException;
|
| | | import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
|
| | | import com.yeshi.fanli.exception.tlj.TaoLiJinCreateException;
|
| | | import com.yeshi.fanli.exception.tlj.UserTaoLiJinRecordException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.config.ConfigService;
|
| | | import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
|
| | | import com.yeshi.fanli.service.inter.goods.ShareGoodsService;
|
| | | import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
|
| | | import com.yeshi.fanli.service.inter.money.UserMoneyExtraService;
|
| | | import com.yeshi.fanli.service.inter.monitor.BusinessEmergent110Service;
|
| | | import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
|
| | | import com.yeshi.fanli.service.inter.taobao.TLJBuyGoodsService;
|
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
|
| | | import com.yeshi.fanli.service.inter.taobao.UserTLJBuyHistoryService;
|
| | | import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinRecordService;
|
| | | import com.yeshi.fanli.service.inter.user.TBPidService;
|
| | | import com.yeshi.fanli.service.inter.user.UserAccountService;
|
| | | import com.yeshi.fanli.service.inter.user.UserShareGoodsRecordService;
|
| | |
| | | import com.yeshi.fanli.util.ImageUtil;
|
| | | import com.yeshi.fanli.util.RedisManager;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.TaoBaoConstant;
|
| | | import com.yeshi.fanli.util.TimeUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoBaoUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
|
| | |
|
| | |
| | | @Resource
|
| | | private CommonGoodsService commonGoodsService;
|
| | |
|
| | | @Resource
|
| | | private UserMoneyExtraService userMoneyExtraService;
|
| | |
|
| | | @Resource
|
| | | private UserTaoLiJinRecordService userTaoLiJinRecordService;
|
| | |
|
| | | @Resource
|
| | | private UserTLJBuyHistoryService userTLJBuyHistoryService;
|
| | |
|
| | | @Resource
|
| | | private TLJBuyGoodsService tljBuyGoodsService;
|
| | |
|
| | | @Resource
|
| | | private BusinessEmergent110Service businessEmergent110Service;
|
| | |
|
| | | @Override
|
| | | public void addShareGoodsHistory(UserShareGoodsHistory history) {
|
| | | UserShareGoodsHistory userShareGoodsHistory = userShareGoodsHistoryMapper
|
| | |
| | | UserShareGoodsHistory update = new UserShareGoodsHistory();
|
| | | update.setId(userShareGoodsHistory.getId());
|
| | | userShareGoodsHistory.setTkCode(history.getTkCode());
|
| | | userShareGoodsHistory.setCreateTime(new Date());
|
| | | userShareGoodsHistoryMapper.updateByPrimaryKeySelective(userShareGoodsHistory);
|
| | | } else
|
| | | userShareGoodsHistoryMapper.insertSelective(history);
|
| | |
|
| | | }
|
| | |
|
| | | @Override
|
| | |
| | |
|
| | | // 没有获取到转过链的商品详情
|
| | | if (StringUtil.isNullOrEmpty(goods.getCouponLink()) && !goods.getAuctionUrl().contains("s.click.taobao.com")) {
|
| | | TaoBaoLink taoBaoLink = TaoBaoUtil.getTbLinkForShare(auctionId, tbPid.getPid(), taoBaoUnionConfig);
|
| | | TaoBaoGoodsBrief taoBaoLink = TaoKeApiUtil.specialConvertCoupon(auctionId, info); // TaoBaoUtil.getTbLinkForShare(auctionId,
|
| | | // tbPid.getPid(),
|
| | | // taoBaoUnionConfig);
|
| | | if (taoBaoLink == null) {
|
| | | throw new ShareGoodsException(201, "转链失败");
|
| | | }
|
| | | goods.setCouponLink(taoBaoLink.getCouponLink());
|
| | | goods.setAuctionUrl(taoBaoLink.getClickUrl());
|
| | | goods.setAuctionUrl(taoBaoLink.getAuctionUrl());
|
| | | }
|
| | | return addShareGoodsHistory(uid, goods);
|
| | | }
|
| | |
| | | }
|
| | |
|
| | | UserShareGoodsHistory history = new UserShareGoodsHistory();
|
| | | history.setTkCode(tbLink.getTaoToken());
|
| | | history.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken()));
|
| | | history.setLink(tbLink.getClickUrl());
|
| | | history.setQuanLink(tbLink.getCouponLink());
|
| | | history.setTkCode(tbLink.getTaoToken());
|
| | | history.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken()));
|
| | |
|
| | | history.setCreateTime(new Date());
|
| | | history.setGoodsId(goods.getAuctionId());
|
| | |
| | | // throw new ShareGoodsException(4, "生成二维码失败");
|
| | | // }
|
| | | // 获取到用户的头像
|
| | | UserInfo user = userinfoMapper.selectByPrimaryKey(uid);
|
| | | UserInfo user = userinfoMapper.selectAvailableByPrimaryKey(uid);
|
| | | InputStream portrait = null;
|
| | | if (!StringUtil.isNullOrEmpty(user.getPortrait())) {
|
| | | try {
|
| | |
| | |
|
| | | UserShareGoodsHistory history = new UserShareGoodsHistory();
|
| | | history.setId(userShareGoodsHistory.getId());
|
| | | history.setTkCode(tbLink.getTaoToken());
|
| | | history.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken()));
|
| | | history.setLink(tbLink.getClickUrl());
|
| | | history.setQuanLink(tbLink.getCouponLink());
|
| | | history.setTkCode(tbLink.getTaoToken());
|
| | | history.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken()));
|
| | | userShareGoodsHistoryMapper.updateByPrimaryKeySelective(history);
|
| | |
|
| | | userShareGoodsHistory.setTkCode(tbLink.getTaoToken());
|
| | | userShareGoodsHistory.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken()));
|
| | | userShareGoodsHistory.setLink(tbLink.getClickUrl());
|
| | | userShareGoodsHistory.setQuanLink(tbLink.getCouponLink());
|
| | | userShareGoodsHistory.setTkCode(tbLink.getTaoToken());
|
| | | userShareGoodsHistory.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken()));
|
| | | }
|
| | |
|
| | | return userShareGoodsHistory;
|
| | |
| | | TaoKeAppInfo info = new TaoKeAppInfo();
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(relationId)) {
|
| | | String pid = Constant.TAOBAO_RELATION_PID_DEFAULT;
|
| | | String pid = TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT;
|
| | | String appId = pid.split("_")[2];
|
| | | String adzoneId = pid.split("_")[3];
|
| | | TaoBaoUnionConfig taoBaoUnionConfig = taoBaoUnionConfigService.getConfigByAppIdCache(appId);
|
| | |
| | | }
|
| | | TaoBaoGoodsBrief goods = null;
|
| | | try {
|
| | | // 测试
|
| | | // info.setAdzoneId("123");
|
| | | goods = TaoKeApiUtil.searchGoodsDetail(auctionId, info);
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | throw new ShareGoodsException(4, "商品已下架");
|
| | |
| | | if (StringUtil.isNullOrEmpty(goods.getCouponLink()) && !goods.getAuctionUrl().contains("s.click.taobao.com")) {
|
| | | TaoBaoUnionConfig taoBaoUnionConfig = taoBaoUnionConfigService
|
| | | .getConfigByAppIdCache(info.getPid().split("_")[2]);
|
| | | TaoBaoLink taoBaoLink = TaoBaoUtil.getTbLinkForShare(auctionId, info.getPid(), taoBaoUnionConfig);
|
| | | TaoBaoGoodsBrief taoBaoLink = TaoKeApiUtil.specialConvertCoupon(auctionId, info);
|
| | | if (taoBaoLink == null) {
|
| | | throw new ShareGoodsException(201, "商品转链失败");
|
| | | }
|
| | | goods.setCouponLink(taoBaoLink.getCouponLink());
|
| | | goods.setAuctionUrl(taoBaoLink.getClickUrl());
|
| | | goods.setAuctionUrl(taoBaoLink.getAuctionUrl());
|
| | | }
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(relationId)) {
|
| | |
| | | return getTaoBaoLink(uid, auctionId, tbPid.getPid());
|
| | | }
|
| | |
|
| | | @Override
|
| | | public TaoBaoLink getTaoBaoLink(Long uid, Long auctionId, String pid) throws ShareGoodsException {
|
| | |
|
| | | if (uid == null || uid <= 0) {
|
| | |
| | | }
|
| | |
|
| | | if (StringUtil.isNullOrEmpty(goods.getCouponLink()) && !goods.getAuctionUrl().contains("s.click.taobao.com")) {
|
| | | TaoBaoLink taoBaoLink = TaoBaoUtil.getTbLinkForShare(auctionId, pid, taoBaoUnionConfig);
|
| | | TaoBaoGoodsBrief taoBaoLink = TaoKeApiUtil.specialConvertCoupon(auctionId, info);
|
| | | if (taoBaoLink == null) {
|
| | | throw new ShareGoodsException(201, "商品转链失败");
|
| | | }
|
| | | goods.setCouponLink(taoBaoLink.getCouponLink());
|
| | | goods.setAuctionUrl(taoBaoLink.getClickUrl());
|
| | | goods.setAuctionUrl(taoBaoLink.getAuctionUrl());
|
| | | }
|
| | |
|
| | | // 创建淘口令
|
| | |
| | | }
|
| | |
|
| | | TaoKeAppInfo app = new TaoKeAppInfo();
|
| | | app.setAppKey(Constant.TAOBAO_AUTH_APPKEY);
|
| | | app.setAppSecret(Constant.TAOBAO_AUTH_APPSECRET);
|
| | | app.setPid(Constant.TAOBAO_SPECIAL_PID_DEFAULT);
|
| | | app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY);
|
| | | app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
|
| | | app.setPid(TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT);
|
| | | TaoBaoGoodsBrief goods = TaoKeApiUtil.specialConvertCoupon(auctionId, app);
|
| | | if (goods == null) {
|
| | | throw new ShareGoodsException(1, "");
|
| | |
| | | taoBaoLink.setAuctionId(auctionId);
|
| | | taoBaoLink.setClickUrl(goods.getAuctionUrl());
|
| | | taoBaoLink.setCouponLink(goods.getCouponLink());
|
| | | if (!StringUtil.isNullOrEmpty(goods.getYsylClickUrl()))
|
| | | taoBaoLink.setCouponLink(goods.getYsylClickUrl());
|
| | | taoBaoLink.setGoods(goods);
|
| | | return taoBaoLink;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public UserShareGoodsHistory getShareGoodsHistory(Long uid, Long auctionId) {
|
| | | return userShareGoodsHistoryMapper.selectByUidAndAuctionId(uid, auctionId);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public TaoBaoLink getTaoBaoLinkForShare(Long uid, Long auctionId, String relationId, String pid)
|
| | | throws ShareGoodsException {
|
| | | if (uid == null || uid <= 0) {
|
| | | throw new ShareGoodsException(1, "用户ID不能为空");
|
| | | }
|
| | |
|
| | | if (auctionId == null || auctionId <= 0) {
|
| | | throw new ShareGoodsException(2, "商品ID不能为空");
|
| | | }
|
| | |
|
| | | TaoKeAppInfo info = new TaoKeAppInfo();
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(relationId)) {
|
| | | String appId = pid.split("_")[2];
|
| | | String adzoneId = pid.split("_")[3];
|
| | | TaoBaoUnionConfig taoBaoUnionConfig = taoBaoUnionConfigService.getConfigByAppIdCache(appId);
|
| | | info.setAdzoneId(adzoneId);
|
| | | info.setAppKey(taoBaoUnionConfig.getAppKey());
|
| | | info.setAppSecret(taoBaoUnionConfig.getAppSecret());
|
| | | info.setPid(pid);
|
| | | } else {
|
| | | TBPid tbPid = tbPidService.getTBPid(uid, PidUser.TYPE_SHARE_GOODS);
|
| | | if (tbPid == null) {
|
| | | throw new ShareGoodsException(3, "获取推广位失败");
|
| | | }
|
| | | String appId = tbPid.getPid().split("_")[2];
|
| | | TaoBaoUnionConfig taoBaoUnionConfig = taoBaoUnionConfigService.getConfigByAppIdCache(appId);
|
| | | String adzoneId = tbPid.getPid().split("_")[3];
|
| | | info.setAdzoneId(adzoneId);
|
| | | info.setAppKey(taoBaoUnionConfig.getAppKey());
|
| | | info.setAppSecret(taoBaoUnionConfig.getAppSecret());
|
| | | info.setPid(tbPid.getPid());
|
| | | }
|
| | | TaoBaoGoodsBrief goods = null;
|
| | | try {
|
| | | goods = TaoKeApiUtil.searchGoodsDetail(auctionId, info);
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | throw new ShareGoodsException(4, "商品已下架");
|
| | | } finally {
|
| | | }
|
| | | if (goods == null) {
|
| | | throw new ShareGoodsException(5, "获取商品详情失败");
|
| | | }
|
| | |
|
| | | if (StringUtil.isNullOrEmpty(goods.getCouponLink()) && !goods.getAuctionUrl().contains("s.click.taobao.com")) {
|
| | | TaoBaoGoodsBrief taoBaoLink = TaoKeApiUtil.specialConvertCoupon(auctionId, info);
|
| | | if (taoBaoLink == null) {
|
| | | throw new ShareGoodsException(201, "商品转链失败");
|
| | | }
|
| | | goods.setCouponLink(taoBaoLink.getCouponLink());
|
| | | goods.setAuctionUrl(taoBaoLink.getAuctionUrl());
|
| | | }
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(relationId)) {
|
| | | if (!StringUtil.isNullOrEmpty(goods.getAuctionUrl()))
|
| | | goods.setAuctionUrl(goods.getAuctionUrl() + "&relationId=" + relationId);
|
| | | if (!StringUtil.isNullOrEmpty(goods.getCouponLink()))
|
| | | goods.setCouponLink(goods.getCouponLink() + "&relationId=" + relationId);
|
| | | }
|
| | |
|
| | | // 保存商品详情
|
| | |
|
| | | // 创建淘口令
|
| | | TaoBaoLink tbLink = new TaoBaoLink();
|
| | | tbLink.setAuctionId(goods.getAuctionId());
|
| | | tbLink.setClickUrl(goods.getAuctionUrl());
|
| | | tbLink.setCouponLink(goods.getCouponLink());
|
| | | if (!StringUtil.isNullOrEmpty(goods.getYsylClickUrl()))
|
| | | tbLink.setCouponLink(goods.getYsylClickUrl());
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(tbLink.getCouponLink())) {// 通过立即推广方式获取淘口令成功
|
| | | String quanToken = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), tbLink.getCouponLink());
|
| | | if (!StringUtil.isNullOrEmpty(quanToken)) {
|
| | | tbLink.setTaoToken(quanToken);
|
| | | }
|
| | | } else if (!StringUtil.isNullOrEmpty(tbLink.getClickUrl())) {
|
| | | String quanToken = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), tbLink.getClickUrl());
|
| | | if (!StringUtil.isNullOrEmpty(quanToken)) {
|
| | | tbLink.setTaoToken(quanToken);
|
| | | }
|
| | | }
|
| | |
|
| | | tbLink.setGoods(goods);
|
| | |
|
| | | // 存储分享商品的信息,用于加快分享网页接口请求速度
|
| | | if (Constant.IS_OUTNET)
|
| | | redisManager.saveTaoBaoGoodsBriefTemp(goods);
|
| | |
|
| | | return tbLink;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public TaoBaoLink getTaoLiJinLinkForBuy(Long uid, String specialId, Long auctionId, String pid)
|
| | | throws ShareGoodsException {
|
| | | if (uid == null || uid <= 0) {
|
| | | throw new ShareGoodsException(1, "用户ID不能为空");
|
| | | }
|
| | |
|
| | | if (auctionId == null || auctionId <= 0) {
|
| | | throw new ShareGoodsException(2, "商品ID不能为空");
|
| | | }
|
| | |
|
| | | // 用户剩余可以淘礼金验证
|
| | | UserMoneyExtra userMoneyExtra = userMoneyExtraService.selectByPrimaryKey(uid);
|
| | | if (userMoneyExtra == null || userMoneyExtra.getTlj() == null) {
|
| | | throw new ShareGoodsException(101, "红包余额不足");
|
| | | }
|
| | |
|
| | | TaoKeAppInfo app = new TaoKeAppInfo();
|
| | | app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY);
|
| | | app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
|
| | | if (pid == null)
|
| | | app.setPid(TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT);
|
| | | else
|
| | | app.setPid(pid);
|
| | | TaoBaoGoodsBrief goods = TaoKeApiUtil.specialConvertCoupon(auctionId, app);
|
| | | if (goods == null) {
|
| | | throw new ShareGoodsException(1, "");
|
| | | }
|
| | |
|
| | | String taoLiJinLink = null;
|
| | | try {
|
| | | goods.setAuctionId(auctionId);
|
| | | UserTaoLiJinRecord createUserTaoLiJin = userTaoLiJinRecordService.createSelfBuyTaoLiJin(uid, 1, goods);
|
| | | taoLiJinLink = createUserTaoLiJin.getSendUrl();
|
| | | } catch (UserTaoLiJinRecordException e) {
|
| | | throw new ShareGoodsException(e.getCode(), e.getMsg());
|
| | | }
|
| | |
|
| | | TaoBaoLink taoBaoLink = new TaoBaoLink();
|
| | | taoBaoLink.setAuctionId(auctionId);
|
| | | taoBaoLink.setClickUrl(goods.getAuctionUrl());
|
| | | taoBaoLink.setCouponLink(taoLiJinLink);
|
| | | taoBaoLink.setGoods(goods);
|
| | |
|
| | | return taoBaoLink;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public TaoBaoLink getTaoLiJinLinkForShare(Long uid, Long auctionId, String relationId) throws ShareGoodsException {
|
| | |
|
| | | if (uid == null || uid <= 0) {
|
| | | throw new ShareGoodsException(1, "用户ID不能为空");
|
| | | }
|
| | |
|
| | | if (auctionId == null || auctionId <= 0) {
|
| | | throw new ShareGoodsException(2, "商品ID不能为空");
|
| | | }
|
| | |
|
| | | TaoKeAppInfo info = new TaoKeAppInfo();
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(relationId)) {
|
| | | String pid = TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT;
|
| | | String appId = pid.split("_")[2];
|
| | | String adzoneId = pid.split("_")[3];
|
| | | TaoBaoUnionConfig taoBaoUnionConfig = taoBaoUnionConfigService.getConfigByAppIdCache(appId);
|
| | | info.setAdzoneId(adzoneId);
|
| | | info.setAppKey(taoBaoUnionConfig.getAppKey());
|
| | | info.setAppSecret(taoBaoUnionConfig.getAppSecret());
|
| | | info.setPid(pid);
|
| | | } else {
|
| | | TBPid tbPid = tbPidService.getTBPid(uid, PidUser.TYPE_SHARE_GOODS);
|
| | | if (tbPid == null) {
|
| | | throw new ShareGoodsException(3, "获取推广位失败");
|
| | | }
|
| | | String appId = tbPid.getPid().split("_")[2];
|
| | | TaoBaoUnionConfig taoBaoUnionConfig = taoBaoUnionConfigService.getConfigByAppIdCache(appId);
|
| | | String adzoneId = tbPid.getPid().split("_")[3];
|
| | | info.setAdzoneId(adzoneId);
|
| | | info.setAppKey(taoBaoUnionConfig.getAppKey());
|
| | | info.setAppSecret(taoBaoUnionConfig.getAppSecret());
|
| | | info.setPid(tbPid.getPid());
|
| | | }
|
| | | TaoBaoGoodsBrief goods = null;
|
| | | try {
|
| | | goods = TaoKeApiUtil.searchGoodsDetail(auctionId, info);
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | throw new ShareGoodsException(4, "商品已下架");
|
| | | } finally {
|
| | | }
|
| | | if (goods == null) {
|
| | | throw new ShareGoodsException(5, "获取商品详情失败");
|
| | | }
|
| | |
|
| | | if (StringUtil.isNullOrEmpty(goods.getCouponLink()) && !goods.getAuctionUrl().contains("s.click.taobao.com")) {
|
| | | TaoBaoUnionConfig taoBaoUnionConfig = taoBaoUnionConfigService
|
| | | .getConfigByAppIdCache(info.getPid().split("_")[2]);
|
| | | TaoBaoGoodsBrief taoBaoLink = TaoKeApiUtil.specialConvertCoupon(auctionId, info);
|
| | | if (taoBaoLink == null) {
|
| | | throw new ShareGoodsException(201, "商品转链失败");
|
| | | }
|
| | | goods.setCouponLink(taoBaoLink.getCouponLink());
|
| | | goods.setAuctionUrl(taoBaoLink.getAuctionUrl());
|
| | | }
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(relationId)) {
|
| | | if (!StringUtil.isNullOrEmpty(goods.getAuctionUrl()))
|
| | | goods.setAuctionUrl(goods.getAuctionUrl() + "&relationId=" + relationId);
|
| | | if (!StringUtil.isNullOrEmpty(goods.getCouponLink()))
|
| | | goods.setCouponLink(goods.getCouponLink() + "&relationId=" + relationId);
|
| | | }
|
| | |
|
| | | // 创建淘口令
|
| | | TaoBaoLink tbLink = new TaoBaoLink();
|
| | | tbLink.setAuctionId(goods.getAuctionId());
|
| | | tbLink.setClickUrl(goods.getAuctionUrl());
|
| | | tbLink.setCouponLink(goods.getCouponLink());
|
| | | tbLink.setGoods(goods);
|
| | |
|
| | | // 存储分享商品的信息,用于加快分享网页接口请求速度
|
| | | if (Constant.IS_OUTNET)
|
| | | redisManager.saveTaoBaoGoodsBriefTemp(goods);
|
| | |
|
| | | return tbLink;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public TaoBaoLink getTaoLiJinLinkForBuyWithOutFanLi(Long uid, Long auctionId, TaoKeAppInfo app)
|
| | | throws ShareGoodsException, TaoLiJinCreateException {
|
| | | if (uid == null || uid <= 0) {
|
| | | throw new ShareGoodsException(1, "用户ID不能为空");
|
| | | }
|
| | |
|
| | | if (auctionId == null || auctionId <= 0) {
|
| | | throw new ShareGoodsException(2, "商品ID不能为空");
|
| | | }
|
| | |
|
| | | boolean canBuy = userTLJBuyHistoryService.canBuy(uid, auctionId);
|
| | | if (!canBuy) {
|
| | | throw new ShareGoodsException(3, "立减红包已抢光,请稍后再试");
|
| | | }
|
| | |
|
| | | long currentTime = System.currentTimeMillis();
|
| | | Date sendEndTime = new Date(TimeUtil.convertToTimeTemp(
|
| | | TimeUtil.getGernalTime(currentTime + 1000 * 60 * 60 * 24L, "yyyy-MM-dd"), "yyyy-MM-dd"));
|
| | | TaoBaoGoodsBrief goods = null;
|
| | | try {
|
| | | goods = TaoKeApiUtil.searchGoodsDetail(auctionId);
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | throw new ShareGoodsException(4, "商品已下架");
|
| | | }
|
| | |
|
| | | BigDecimal perface = TaoBaoUtil.getGoodsHongBaoMoney(goods, new BigDecimal(70));
|
| | | TaoLiJinDTO taoLiJinDTO = null;
|
| | | try {
|
| | | taoLiJinDTO = TaoKeApiUtil.createTaoLiJin(auctionId, "自购立减", perface, 1,
|
| | | new Date(currentTime - 1000 * 60 * 10L), sendEndTime, new Date(currentTime - 1000 * 60 * 10L),
|
| | | sendEndTime, app);
|
| | | } catch (TaoLiJinCreateException e1) {
|
| | | if (e1.getCode() == TaoLiJinCreateException.CODE_TLJ_NO_MONEY) {// 资金不足
|
| | | TaoBaoUnionConfig config = taoBaoUnionConfigService.getConfigByAppKeyCache(app.getAppKey());
|
| | | businessEmergent110Service.tljNoMoney(config.getAccount());
|
| | | } else if (e1.getCode() == TaoLiJinCreateException.CODE_TLJ_FORBIDDEN) {// 商品不允许创建淘礼金
|
| | | tljBuyGoodsService.removeGoods(auctionId);
|
| | | }
|
| | | LogHelper.errorDetailInfo(e1, e1.getMessage(), null);
|
| | | } catch (TaoKeApiException e) {
|
| | | LogHelper.errorDetailInfo(e, e.getMessage(), null);
|
| | | throw new ShareGoodsException(5, "生成推广链接失败");
|
| | | }
|
| | |
|
| | | if (taoLiJinDTO == null)
|
| | | throw new ShareGoodsException(5, "生成推广链接失败");
|
| | |
|
| | | // 减去剩余个数(随机减去8到10个)
|
| | | tljBuyGoodsService.subHongBaoLeftCount(auctionId, TimeUtil.getGernalTime(currentTime, "yyyy-MM-dd"),
|
| | | 8 + (int) (3 * Math.random()));
|
| | |
|
| | | // 插入记录
|
| | | try {
|
| | | userTLJBuyHistoryService.addHistory(new UserTLJBuyHistory(null, uid, auctionId,
|
| | | TimeUtil.getGernalTime(currentTime, "yyyy-MM-dd"), taoLiJinDTO.getRightsId(), new Date()));
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | |
|
| | | TaoBaoLink taoBaoLink = new TaoBaoLink();
|
| | | taoBaoLink.setAuctionId(auctionId);
|
| | | taoBaoLink.setClickUrl(goods.getAuctionUrl());
|
| | | taoBaoLink.setCouponLink(taoLiJinDTO.getSendUrl());
|
| | | taoBaoLink.setGoods(goods);
|
| | | return taoBaoLink;
|
| | | }
|
| | | }
|