| | |
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.fanli.facade.goods.dto.taoke.TaoKeAppInfo;
|
| | | import org.fanli.facade.goods.entity.taobao.TBPid;
|
| | | import org.fanli.facade.goods.entity.taobao.TaoBaoLink;
|
| | | import org.fanli.facade.goods.entity.taobao.TaoBaoUnionConfig;
|
| | |
| | | import org.fanli.facade.goods.service.usergoods.UserShareGoodsRecordService;
|
| | | import org.fanli.facade.goods.utils.ImageUtil;
|
| | | import org.fanli.facade.goods.utils.RedisGoodsManager;
|
| | | import org.fanli.facade.goods.utils.dataoke.TaoKeApiUtil;
|
| | | import org.fanli.facade.goods.utils.taobao.TaoBaoUtil;
|
| | | import org.fanli.facade.order.service.hongbao.HongBaoManageService;
|
| | | import org.fanli.facade.goods.utils.taobao.TaoKeGoodsApiUtil;
|
| | | import org.fanli.facade.system.dto.taobao.TaoKeAppInfo;
|
| | | import org.fanli.facade.system.service.common.ConfigService;
|
| | | import org.fanli.facade.system.service.hongbao.HongBaoManageService;
|
| | | import org.fanli.facade.user.service.UserAccountService;
|
| | | import org.fanli.facade.user.service.UserInfoService;
|
| | |
|
| | | import com.alibaba.dubbo.config.annotation.Service;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.yeshi.utils.FileUtil;
|
| | | import org.yeshi.utils.HttpUtil;
|
| | | import org.yeshi.utils.JsonUtil;
|
| | |
| | | import com.yeshi.fanli.goods.dao.usergoods.PidUserMapper;
|
| | | import com.yeshi.fanli.goods.dao.usergoods.UserShareGoodsHistoryMapper;
|
| | |
|
| | | @Service(version = "1.0.0")
|
| | | @Service
|
| | | public class ShareGoodsServiceImpl implements ShareGoodsService {
|
| | |
|
| | | @Resource
|
| | |
| | |
|
| | | @Resource
|
| | | private UserShareGoodsHistoryMapper userShareGoodsHistoryMapper;
|
| | |
|
| | | @Resource
|
| | | private HongBaoManageMapper hongBaoManageMapper;
|
| | |
|
| | | @Resource
|
| | | private UserInfoService userInfoService;
|
| | |
|
| | | @Resource
|
| | | private RedisGoodsManager redisManager;
|
| | |
| | | }
|
| | |
|
| | | @Override
|
| | | public UserShareGoodsHistory addShareGoodsHistory(Long uid, Long auctionId) throws ShareGoodsException {
|
| | | TBPid tbPid = tbPidService.getTBPid(uid, PidUser.TYPE_SHARE_GOODS);
|
| | | public UserShareGoodsHistory addShareGoodsHistory(UserInfo user, Long auctionId) throws ShareGoodsException {
|
| | | TBPid tbPid = tbPidService.getTBPid(user.getId(), PidUser.TYPE_SHARE_GOODS);
|
| | | if (tbPid == null) {
|
| | | throw new ShareGoodsException(1, "获取PID失败");
|
| | | }
|
| | |
| | | TaoBaoGoodsBrief goods = null;
|
| | | long startTime = System.currentTimeMillis();
|
| | | try {
|
| | | goods = TaoKeApiUtil.searchGoodsDetail(auctionId, info);
|
| | | goods = TaoKeGoodsApiUtil.searchGoodsDetail(auctionId, info);
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | throw new ShareGoodsException(3, "商品已下架");
|
| | | } finally {
|
| | |
| | | goods.setCouponLink(taoBaoLink.getCouponLink());
|
| | | goods.setAuctionUrl(taoBaoLink.getClickUrl());
|
| | | }
|
| | | return addShareGoodsHistory(uid, goods);
|
| | | return addShareGoodsHistory(user, goods);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public UserShareGoodsHistory addShareGoodsHistory(Long uid, TaoBaoGoodsBrief goods) throws ShareGoodsException {
|
| | | public UserShareGoodsHistory addShareGoodsHistory(UserInfo user, TaoBaoGoodsBrief goods) throws ShareGoodsException {
|
| | | if (StringUtil.isNullOrEmpty(goods.getCouponLink()) && StringUtil.isNullOrEmpty(goods.getAuctionUrl())) {
|
| | | throw new ShareGoodsException(10, "转链失败");
|
| | | }
|
| | |
| | | tbLink.setCouponLink(goods.getCouponLink());
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(tbLink.getCouponLink())) {// 通过立即推广方式获取淘口令成功
|
| | | String quanToken = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), tbLink.getCouponLink());
|
| | | String quanToken = TaoKeGoodsApiUtil.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());
|
| | | String quanToken = TaoKeGoodsApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), tbLink.getClickUrl());
|
| | | if (!StringUtil.isNullOrEmpty(quanToken)) {
|
| | | tbLink.setTaoToken(quanToken);
|
| | | }
|
| | |
| | | imgList = new ArrayList<>();
|
| | | }
|
| | | history.setPictures(JsonUtil.getGson().toJson(imgList));
|
| | | history.setUser(new UserInfo(uid));
|
| | | history.setUser(user);
|
| | | history.setPostPicture(goods.getPictUrl());
|
| | | // 生成二维码信息
|
| | | // 包含用户ID与商品ID
|
| | | // 新版商品分享
|
| | | String url = String.format("http://%s%s?uid=%s&id=%s", configService.getH5Host(),
|
| | | Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY),
|
| | | Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(user.getId() + "", Constant.UIDAESKEY),
|
| | | goods.getAuctionId() + "");
|
| | |
|
| | | String shortLink = HttpUtil.getShortLink(url);
|
| | | if (!StringUtil.isNullOrEmpty(shortLink)) {
|
| | | url = shortLink;
|
| | | }
|
| | | String destPath = FileUtil.getCacheDir() + "/ercode_" + uid + "_" + goods.getAuctionId() + ".jpg";
|
| | | String shareImgPath = FileUtil.getCacheDir() + "/share_" + uid + "_" + goods.getAuctionId() + ".png";
|
| | | String destPath = FileUtil.getCacheDir() + "/ercode_" + user.getId() + "_" + goods.getAuctionId() + ".jpg";
|
| | | String shareImgPath = FileUtil.getCacheDir() + "/share_" + user.getId() + "_" + goods.getAuctionId() + ".png";
|
| | | InputStream erCodeInputStream = null;
|
| | |
|
| | | try {
|
| | |
| | | // throw new ShareGoodsException(4, "生成二维码失败");
|
| | | // }
|
| | | // 获取到用户的头像
|
| | | UserInfo user = userInfoService.selectByPKey(uid);
|
| | | InputStream portrait = null;
|
| | | if (!StringUtil.isNullOrEmpty(user.getPortrait())) {
|
| | | try {
|
| | | portrait = HttpUtil.downLoadImg(user.getPortrait());
|
| | | } catch (HttpException e) {
|
| | | String portraitUrl = userAccountService.repairPortrait(uid);
|
| | | String portraitUrl = userAccountService.repairPortrait(user.getId());
|
| | | if (StringUtil.isNullOrEmpty(portraitUrl))
|
| | | throw new ShareGoodsException(11, "获取头像出错");
|
| | | else {
|
| | |
| | | }
|
| | |
|
| | | FileUploadResult shareImgResult = COSManager.getInstance().uploadInputStream(shareImgInputStream,
|
| | | "sharegoods/share_" + uid + "_" + goods.getAuctionId() + "_" + System.currentTimeMillis() + ".png");
|
| | | "sharegoods/share_" + user.getId() + "_" + goods.getAuctionId() + "_" + System.currentTimeMillis() + ".png");
|
| | |
|
| | | if (shareImgResult == null || StringUtil.isNullOrEmpty(shareImgResult.getUrl())) {
|
| | | throw new ShareGoodsException(6, "分享图片保存失败");
|
| | |
| | |
|
| | | // 查询之前是否存在,存在就替换掉
|
| | |
|
| | | UserShareGoodsHistory old = userShareGoodsHistoryMapper.selectByUidAndAuctionId(uid, history.getGoodsId());
|
| | | UserShareGoodsHistory old = userShareGoodsHistoryMapper.selectByUidAndAuctionId(user.getId(), history.getGoodsId());
|
| | | if (old != null) {
|
| | | history.setId(old.getId());
|
| | | userShareGoodsHistoryMapper.updateByPrimaryKeySelective(history);
|
| | |
| | | }
|
| | |
|
| | | @Override
|
| | | public UserShareGoodsHistory getShareGoodsHistoryDetail(Long uid, Long auctionId) throws ShareGoodsException {
|
| | | UserShareGoodsHistory userShareGoodsHistory = userShareGoodsHistoryMapper.selectByUidAndAuctionId(uid,
|
| | | public UserShareGoodsHistory getShareGoodsHistoryDetail(UserInfo user, Long auctionId) throws ShareGoodsException {
|
| | | UserShareGoodsHistory userShareGoodsHistory = userShareGoodsHistoryMapper.selectByUidAndAuctionId(user.getId(),
|
| | | auctionId);
|
| | | if (userShareGoodsHistory == null)
|
| | | throw new ShareGoodsException(10, "分享不存在");
|
| | |
|
| | | // 淘口令不存在
|
| | | if (StringUtil.isNullOrEmpty(userShareGoodsHistory.getTkCode())) {
|
| | | TBPid tbPid = tbPidService.getTBPid(uid, PidUser.TYPE_SHARE_GOODS);
|
| | | TBPid tbPid = tbPidService.getTBPid(user.getId(), PidUser.TYPE_SHARE_GOODS);
|
| | | if (tbPid == null)
|
| | | throw new ShareGoodsException(1, "获取PID失败");
|
| | |
|
| | |
| | | if (tbLink == null) {
|
| | | TaoBaoGoodsBrief goods = null;
|
| | | try {
|
| | | goods = TaoKeApiUtil.searchGoodsDetail(auctionId);
|
| | | goods = TaoKeGoodsApiUtil.searchGoodsDetail(auctionId);
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | throw new ShareGoodsException(4, "商品已下架");
|
| | | }
|
| | |
| | | }
|
| | | TaoBaoGoodsBrief goods = null;
|
| | | try {
|
| | | goods = TaoKeApiUtil.searchGoodsDetail(auctionId, info);
|
| | | goods = TaoKeGoodsApiUtil.searchGoodsDetail(auctionId, info);
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | throw new ShareGoodsException(4, "商品已下架");
|
| | | } finally {
|
| | |
| | | tbLink.setCouponLink(goods.getCouponLink());
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(tbLink.getCouponLink())) {// 通过立即推广方式获取淘口令成功
|
| | | String quanToken = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), tbLink.getCouponLink());
|
| | | String quanToken = TaoKeGoodsApiUtil.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());
|
| | | String quanToken = TaoKeGoodsApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), tbLink.getClickUrl());
|
| | | if (!StringUtil.isNullOrEmpty(quanToken)) {
|
| | | tbLink.setTaoToken(quanToken);
|
| | | }
|
| | |
| | | return getTaoBaoLink(uid, auctionId, tbPid.getPid());
|
| | | }
|
| | |
|
| | | @Override
|
| | | public TaoBaoLink getTaoBaoLink(Long uid, Long auctionId, String pid) throws ShareGoodsException {
|
| | |
|
| | | if (uid == null || uid <= 0) {
|
| | |
| | | info.setPid(pid);
|
| | | TaoBaoGoodsBrief goods = null;
|
| | | try {
|
| | | goods = TaoKeApiUtil.searchGoodsDetailForConvert(auctionId, info);
|
| | | goods = TaoKeGoodsApiUtil.searchGoodsDetailForConvert(auctionId, info);
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | throw new ShareGoodsException(4, "商品已下架");
|
| | | } finally {
|
| | |
|
| | | }
|
| | | if (goods == null) {
|
| | | throw new ShareGoodsException(5, "获取商品详情失败");
|
| | |
| | | throw new ShareGoodsException(2, "商品ID不能为空");
|
| | | }
|
| | |
|
| | | return getTaoBaoLink(uid, auctionId, Constant.TAOBAO_SPECIAL_PID_DEFAULT);
|
| | | TaoKeAppInfo app = new TaoKeAppInfo();
|
| | | app.setAppKey(Constant.TAOBAO_AUTH_APPKEY);
|
| | | app.setAppSecret(Constant.TAOBAO_AUTH_APPSECRET);
|
| | | app.setPid(Constant.TAOBAO_SPECIAL_PID_DEFAULT);
|
| | | TaoBaoGoodsBrief goods = TaoKeGoodsApiUtil.specialConvertCoupon(auctionId, app);
|
| | | if (goods == null) {
|
| | | throw new ShareGoodsException(1, "");
|
| | | }
|
| | |
|
| | | TaoBaoLink taoBaoLink = new TaoBaoLink();
|
| | | taoBaoLink.setAuctionId(auctionId);
|
| | | taoBaoLink.setClickUrl(goods.getAuctionUrl());
|
| | | taoBaoLink.setCouponLink(goods.getCouponLink());
|
| | | taoBaoLink.setGoods(goods);
|
| | |
|
| | | return taoBaoLink;
|
| | | }
|
| | |
|
| | | }
|