fanli/src/main/java/com/yeshi/fanli/controller/apph5/AppH5ShareController.java
@@ -22,11 +22,16 @@ import com.yeshi.fanli.entity.bus.share.UserShareGoodsRecord; import com.yeshi.fanli.entity.goods.CommonGoods; import com.yeshi.fanli.entity.jd.JDGoods; import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief; import com.yeshi.fanli.exception.taobao.TaoKeApiException; import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException; import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService; import com.yeshi.fanli.service.inter.user.UserShareGoodsRecordService; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory; import com.yeshi.fanli.util.jd.JDApiUtil; import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil; import com.yeshi.fanli.util.taobao.TaoKeApiUtil; import com.yeshi.fanli.vo.goods.GoodsDetailVO; import net.sf.json.JSONArray; @@ -71,15 +76,15 @@ } /** * 分享商品详情 * 分享商品列表 * * @param callback * @param shareId 分享id * @param source 来源 * @param out */ @RequestMapping(value = "getListJD") public void getListJD(String callback, Long shareId, PrintWriter out) { @RequestMapping(value = "getList") public void getList(String callback, Long shareId, PrintWriter out) { try { if (shareId == null) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("传递参数不正确")); @@ -90,30 +95,77 @@ List<UserShareGoodsGroup> list = userShareGoodsRecordService.listByRecordId(shareId); if (list != null && list.size() > 0) { List<Long> listGid = new ArrayList<Long>(); List<Long> listIdTB = new ArrayList<Long>(); List<Long> listIdJD = new ArrayList<Long>(); List<Long> listIdPDD = new ArrayList<Long>(); for (int i = 0; i < list.size(); i++) { CommonGoods commonGoods = list.get(i).getCommonGoods(); if (commonGoods == null) { continue; } listGid.add(commonGoods.getGoodsId()); } // API网络接口验证是否在售 List<JDGoods> listGoods = null; try { JDFilter filter = new JDFilter(); filter.setListId(listGid); filter.setPageIndex(1); filter.setPageSize(100); JDSearchResult result = JDApiUtil.queryByKey(filter); if (result != null) { listGoods = result.getGoodsList(); Integer goodsType = commonGoods.getGoodsType(); if (goodsType == null) { continue; } } catch (Exception e) { e.printStackTrace(); if (Constant.SOURCE_TYPE_TAOBAO == goodsType) { listIdTB.add(commonGoods.getGoodsId()); } else if (Constant.SOURCE_TYPE_JD == goodsType) { listIdJD.add(commonGoods.getGoodsId()); } else if (Constant.SOURCE_TYPE_PDD == goodsType) { listIdPDD.add(commonGoods.getGoodsId()); } } // 淘宝验证是否在售 List<TaoBaoGoodsBrief> listTB = null; if (listIdTB.size() > 0) { try { listTB = TaoKeApiUtil.getBatchGoodsInfo(listIdTB); } catch (Exception e) { e.printStackTrace(); } } // 京东验证是否在售 List<JDGoods> listJD = null; if (listIdJD.size() > 0) { try { JDFilter filter = new JDFilter(); filter.setListId(listIdJD); filter.setPageIndex(1); filter.setPageSize(100); JDSearchResult result = JDApiUtil.queryByKey(filter); if (result != null) { listJD = result.getGoodsList(); } } catch (Exception e) { e.printStackTrace(); } } // 拼多多验证是否在售 List<PDDGoodsDetail> listPDD = null; if (listIdPDD.size() > 0) { try { Long[] ids = new Long[list.size()]; PDDSearchFilter sf = new PDDSearchFilter(); sf.setPage(1); sf.setPageSize(100); sf.setGoodsIdList(listIdPDD.toArray(ids)); PDDGoodsResult result = PinDuoDuoApiUtil.searchGoods(sf); if (result != null) { listPDD = result.getGoodsList(); } } catch (Exception e) { e.printStackTrace(); } } Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()) .excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create(); BigDecimal fanLiRate = hongBaoManageService.getFanLiRate(); @@ -124,11 +176,27 @@ if (commonGoods == null) { continue; } if (listGoods != null && listGoods.size() > 0) { Integer goodsType = commonGoods.getGoodsType(); if (goodsType == null) { goodsType = Constant.SOURCE_TYPE_TAOBAO; } Long commonGid = commonGoods.getGoodsId(); if (goodsType == Constant.SOURCE_TYPE_TAOBAO && listTB != null && listTB.size() > 0) { int state = 1; // 默认停售 Long commonGid = commonGoods.getGoodsId(); for (JDGoods goodsDetail : listGoods) { for (TaoBaoGoodsBrief goodsDetail : listTB) { Long goodsId =goodsDetail.getAuctionId(); if (goodsId == commonGid || goodsId.equals(commonGid)) { state = 0; // 在售 break; } } commonGoods.setState(state); } if (goodsType == Constant.SOURCE_TYPE_JD && listJD != null && listJD.size() > 0) { int state = 1; // 默认停售 for (JDGoods goodsDetail : listJD) { Long goodsId =goodsDetail.getSkuId(); if (goodsId == commonGid || goodsId.equals(commonGid)) { state = 0; // 在售 @@ -138,91 +206,10 @@ commonGoods.setState(state); } GoodsDetailVO detailVO = GoodsDetailVOFactory.convertCommonGoods(commonGoods, null, fanLiRate, shareRate); if (!detailVO.isHasCoupon()) { detailVO.setState(1);; // 已抢光 } array.add(gson.toJson(detailVO)); } } String title = ""; UserShareGoodsRecord userShareGoodsRecord = userShareGoodsRecordService.selectByPrimaryKey(shareId); if (userShareGoodsRecord != null) { title = userShareGoodsRecord.getTitle(); } JSONObject data = new JSONObject(); data.put("title", title); data.put("count", list.size()); data.put("result_list", array); JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); } catch (Exception e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("获取失败")); e.printStackTrace(); } } /** * 分享商品详情 * * @param callback * @param shareId 分享id * @param source 来源 * @param out */ @RequestMapping(value = "getListPDD") public void getListPDD(String callback, Long shareId, PrintWriter out) { try { if (shareId == null) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("传递参数不正确")); return; } JSONArray array = new JSONArray(); List<UserShareGoodsGroup> list = userShareGoodsRecordService.listByRecordId(shareId); if (list != null && list.size() > 0) { Long[] listGid = new Long[list.size()]; for (int i = 0; i < list.size(); i++) { CommonGoods commonGoods = list.get(i).getCommonGoods(); if (commonGoods == null) { continue; } listGid[i] = commonGoods.getGoodsId(); } // API网络接口验证是否在售 List<PDDGoodsDetail> listGoods = null; try { PDDSearchFilter sf = new PDDSearchFilter(); sf.setPage(1); sf.setPageSize(100); sf.setGoodsIdList(listGid); PDDGoodsResult result = PinDuoDuoApiUtil.searchGoods(sf); if (result != null) { listGoods = result.getGoodsList(); } } catch (Exception e) { e.printStackTrace(); } Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()) .excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create(); BigDecimal fanLiRate = hongBaoManageService.getFanLiRate(); BigDecimal shareRate = hongBaoManageService.getShareRate(); for (UserShareGoodsGroup goodsGroup : list) { CommonGoods commonGoods = goodsGroup.getCommonGoods(); if (commonGoods == null) { continue; } if (listGoods != null && listGoods.size() > 0) { if (goodsType == Constant.SOURCE_TYPE_PDD && listPDD != null && listPDD.size() > 0) { int state = 1; // 默认停售 Long commonGid = commonGoods.getGoodsId(); for (PDDGoodsDetail goodsDetail : listGoods) { for (PDDGoodsDetail goodsDetail : listPDD) { Long goodsId =goodsDetail.getGoodsId(); if (goodsId == commonGid || goodsId.equals(commonGid)) { state = 0; // 在售 fanli/src/main/java/com/yeshi/fanli/controller/client/v1/UserGoodsStorageController.java
@@ -214,7 +214,7 @@ * @param out */ @RequestMapping(value = "sharegoods", method = RequestMethod.POST) public void shareGoods(AcceptData acceptData, Long uid, String storageIds, Integer goodsType, PrintWriter out) { public void shareGoods(AcceptData acceptData, Long uid, String storageIds, PrintWriter out) { if (StringUtil.isNullOrEmpty(storageIds)) { out.print(JsonUtil.loadFalseResult("分享商品不能为空")); @@ -238,12 +238,8 @@ out.print(JsonUtil.loadFalseResult("分享商品数量只能是9个")); return; } if (goodsType == null) { goodsType = Constant.SOURCE_TYPE_TAOBAO; } JSONObject data = userGoodsStorageService.shareGoods(uid, listStorageID, goodsType); JSONObject data = userGoodsStorageService.shareGoods(uid, listStorageID); out.print(JsonUtil.loadTrueResult(data)); } catch (UserGoodsStorageException e) { fanli/src/main/java/com/yeshi/fanli/controller/client/v2/ShareControllerV2.java
@@ -544,11 +544,10 @@ return; } // TODO ShareInfoVO shareInfo = new ShareInfoVO(); String url = String.format("http://%s%s?uid=%s&id=%s&appType=flq&goodsType=%s", configService.getH5Host(), Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY), goodsId + "", Constant.SOURCE_TYPE_JD); String url = String.format("http://%s%s?uid=%s&id=%s", configService.getH5Host(), Constant.systemCommonConfig.getShareGoodsPagePathJD(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY), goodsId + ""); // 券短连接 String shortLink = HttpUtil.getShortLink(url); @@ -666,10 +665,9 @@ ShareInfoVO shareInfo = new ShareInfoVO(); // TODO String url = String.format("http://%s%s?uid=%s&id=%s&appType=flq&goodsType=%s", configService.getH5Host(), Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY), goodsId + "", Constant.SOURCE_TYPE_PDD); String url = String.format("http://%s%s?uid=%s&id=%s", configService.getH5Host(), Constant.systemCommonConfig.getShareGoodsPagePathPDD(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY), goodsId + ""); String shortLink = HttpUtil.getShortLink(url); if (!StringUtil.isNullOrEmpty(shortLink)) { fanli/src/main/java/com/yeshi/fanli/controller/client/v2/ShareStorageControllerV2.java
@@ -21,6 +21,7 @@ import com.yeshi.fanli.entity.bus.user.UserGoodsStorage; import com.yeshi.fanli.entity.goods.CommonGoods; import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief; import com.yeshi.fanli.exception.share.UserShareGoodsRecordException; import com.yeshi.fanli.exception.taobao.TaoKeApiException; import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException; import com.yeshi.fanli.exception.user.UserGoodsStorageException; @@ -28,6 +29,7 @@ import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService; import com.yeshi.fanli.service.inter.user.UserGoodsStorageService; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory; import com.yeshi.fanli.util.taobao.TaoKeApiUtil; import com.yeshi.fanli.vo.goods.GoodsDetailVO; @@ -203,4 +205,52 @@ out.print(JsonUtil.loadTrueResult(data)); } /** * 分享商品返回二维码图片 * * @param callback * @param storageIds * id数组 * @param out */ @RequestMapping(value = "createShare", method = RequestMethod.POST) public void createShare(AcceptData acceptData, Long uid, String storageIds, PrintWriter out) { if (StringUtil.isNullOrEmpty(storageIds)) { out.print(JsonUtil.loadFalseResult("分享商品不能为空")); return; } if (uid == null) { out.print(JsonUtil.loadFalseResult("用户未登录")); return; } try { Gson gson = new Gson(); List<Long> listStorageID = gson.fromJson(storageIds, new TypeToken<ArrayList<Long>>() {}.getType()); if (listStorageID == null || listStorageID.size() < 9) { out.print(JsonUtil.loadFalseResult("分享商品数量不足")); return; } if (listStorageID.size() != 9) { out.print(JsonUtil.loadFalseResult("分享商品数量只能是9个")); return; } JSONObject data = userGoodsStorageService.createShareV2(uid, listStorageID); out.print(JsonUtil.loadTrueResult(data)); } catch (UserGoodsStorageException e) { out.print(JsonUtil.loadFalseResult("分享失败")); e.printStackTrace(); } catch (UserShareGoodsRecordException e) { out.print(JsonUtil.loadFalseResult("分享失败")); e.printStackTrace(); } catch (Exception e) { out.print(JsonUtil.loadFalseResult("分享失败")); e.printStackTrace(); } } } fanli/src/main/java/com/yeshi/fanli/entity/config/SystemCommonConfig.java
@@ -52,6 +52,12 @@ @Map("share_goods_page_path") private String shareGoodsPagePath; @Map("share_goods_page_path_jd") private String shareGoodsPagePathJD; @Map("share_goods_page_path_pdd") private String shareGoodsPagePathPDD; @Map("app_shareinfo_url") private String appShareInfoUrl; @@ -224,4 +230,21 @@ public void setDefaultPortrait(String defaultPortrait) { this.defaultPortrait = defaultPortrait; } public String getShareGoodsPagePathJD() { return shareGoodsPagePathJD; } public void setShareGoodsPagePathJD(String shareGoodsPagePathJD) { this.shareGoodsPagePathJD = shareGoodsPagePathJD; } public String getShareGoodsPagePathPDD() { return shareGoodsPagePathPDD; } public void setShareGoodsPagePathPDD(String shareGoodsPagePathPDD) { this.shareGoodsPagePathPDD = shareGoodsPagePathPDD; } } fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserGoodsStorageServiceImpl.java
@@ -350,13 +350,12 @@ } @Override public JSONObject shareGoods(Long uid, List<Long> listStorageID, Integer goodsType) public JSONObject shareGoods(Long uid, List<Long> listStorageID) throws UserGoodsStorageException, UserShareGoodsRecordException { List<UserGoodsStorage> listStorage = userGoodsStorageMapper.listQueryByIds(listStorageID); if (listStorage == null || listStorage.size() == 0) { throw new UserGoodsStorageException(1, "选品库商品不存在"); } List<UserGoodsStorage> listResult = new ArrayList<UserGoodsStorage>(); // 还原顺序 用于制图 @@ -391,22 +390,70 @@ data.put("revenue", listGoodsBrief.size() + "个商品预估分享奖金:¥"+totalMoney); data.put("shareId", shareRecord.getRedisKey()); data.put("shareImg", uploadResult); if (goodsType == null) { goodsType = Constant.SOURCE_TYPE_TAOBAO; data.put("notifyDesc", configService.get("goods_share_multiple_notify")); return data; } @Override public JSONObject createShareV2(Long uid, List<Long> listStorageID) throws UserGoodsStorageException, UserShareGoodsRecordException { List<UserGoodsStorage> listStorage = userGoodsStorageMapper.listQueryByIds(listStorageID); if (listStorage == null || listStorage.size() == 0) { throw new UserGoodsStorageException(1, "选品库商品不存在"); } List<UserGoodsStorage> listResult = new ArrayList<UserGoodsStorage>(); // 还原顺序 用于制图 for (Long sid: listStorageID) { for (UserGoodsStorage torage: listStorage) { Long id = torage.getId(); if (sid == id || sid.equals(id)) { listResult.add(torage); break; } } } BigDecimal totalMoney = new BigDecimal(0.00); List<TaoBaoGoodsBrief> listGoodsBrief = new ArrayList<TaoBaoGoodsBrief>(); Integer goodsType = null; BigDecimal rate = hongBaoManageService.getShareRate(); for (UserGoodsStorage userGoodsStorage: listResult) { CommonGoods commonGoods = userGoodsStorage.getCommonGoods(); if (goodsType == null) { goodsType = commonGoods.getGoodsType(); } TaoBaoGoodsBrief goodsBrief = TaoBaoUtil.convert(commonGoods); listGoodsBrief.add(goodsBrief); BigDecimal money = TaoBaoUtil.getGoodsHongBaoMoney(goodsBrief, rate); totalMoney = MoneyBigDecimalUtil.add(totalMoney, money); } ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsStorageV2(uid, listGoodsBrief, listStorageID); FileUploadResult uploadResult = new FileUploadResult(); uploadResult.setUrl(shareRecord.getSharePictureUrl()); JSONObject data = new JSONObject(); data.put("revenue", listGoodsBrief.size() + "个商品预估分享奖金:¥"+totalMoney); data.put("shareId", shareRecord.getRedisKey()); data.put("shareImg", uploadResult); // 提示语不同 if (goodsType == Constant.SOURCE_TYPE_JD) { // 京东 TODO data.put("notifyDesc", configService.get("goods_share_multiple_notify")); // 京东 data.put("notifyDesc", configService.get("goods_share_notify_jd")); } else if (goodsType == Constant.SOURCE_TYPE_PDD) { // 拼多多 TODO data.put("notifyDesc", configService.get("goods_share_multiple_notify")); // 拼多多 data.put("notifyDesc", configService.get("goods_share_notify_pdd")); } else { data.put("notifyDesc", configService.get("goods_share_multiple_notify")); } return data; } fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserShareGoodsRecordServiceImpl.java
@@ -713,6 +713,45 @@ return recordDTO; } @Override public ShareGoodsRecordDTO addRecordGoodsStorageV2(Long uid, List<TaoBaoGoodsBrief> listGoodsBrief, List<Long> listStorageID) throws UserShareGoodsRecordException { if (uid == null || uid <= 0 || listGoodsBrief == null || listGoodsBrief.size() == 0) { throw new UserShareGoodsRecordException(1, "传递参数不正确"); } // 插入记录 UserShareGoodsRecord record = new UserShareGoodsRecord(); record.setUid(uid); record.setShareState(0); // 初始未分享 record.setSource(ShareSourceTypeEnum.storage); record.setPicture(listGoodsBrief.get(0).getPictUrl()); // 取一个商品图片作为主图 record.setCreateTime(new Date()); userShareGoodsRecordMapper.insertSelective(record); Long id = record.getId(); // 分享链接 String shareUrl = getShareUrlV2(record); // 分享二维码链接 FileUploadResult uploadResult = drawingSharePicture(uid, id, shareUrl, listGoodsBrief); ShareGoodsRecordDTO recordDTO = new ShareGoodsRecordDTO(); recordDTO.setUid(uid); recordDTO.setShareId(id); recordDTO.setShareUrl(shareUrl); recordDTO.setListId(listStorageID); recordDTO.setListGoodsBrief(listGoodsBrief); recordDTO.setSharePictureUrl(uploadResult.getUrl()); recordDTO.setSource(ShareSourceTypeEnum.storage); // 缓存分享商品信息 String key = StringUtil.Md5(uid + "#GoodsStorage#" + id); recordDTO.setRedisKey(key); redisManager.cacheCommonString(key, JsonUtil.getSimpleGson().toJson(recordDTO), 60 * 20); return recordDTO; } @Override public ShareGoodsRecordDTO addRecordActivity(Long uid, List<TaoBaoGoodsBrief> listGoodsBrief) @@ -867,6 +906,27 @@ } return url; } /** * 分享链接 * * @param shareRecord * @return */ public String getShareUrlV2(UserShareGoodsRecord shareRecord) { Long uid = shareRecord.getUid(); Long shareId = shareRecord.getId(); String url = String.format("http://%s/share_mushGoods_1.6.0.html?uid=%s&shareId=%s", configService.getH5Host(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY), shareId + ""); String shortLink = HttpUtil.getShortLink(url); if (!StringUtil.isNullOrEmpty(shortLink)) { url = shortLink; } return url; } /** * 生成分享图 fanli/src/main/java/com/yeshi/fanli/service/inter/user/UserGoodsStorageService.java
@@ -91,7 +91,7 @@ * @throws UserGoodsStorageException * @throws UserShareGoodsRecordException */ public JSONObject shareGoods(Long uid, List<Long> listStorageID, Integer goodsType) throws UserGoodsStorageException, UserShareGoodsRecordException; public JSONObject shareGoods(Long uid, List<Long> listStorageID) throws UserGoodsStorageException, UserShareGoodsRecordException; /** * 添加简版商品到选品库 @@ -101,4 +101,15 @@ */ public void addCommonGoods(Long uid, Set<Long> ids) throws UserGoodsStorageException; /** * 创建分享 * @param uid * @param listStorageID * @return * @throws UserGoodsStorageException * @throws UserShareGoodsRecordException */ public JSONObject createShareV2(Long uid, List<Long> listStorageID) throws UserGoodsStorageException, UserShareGoodsRecordException; } fanli/src/main/java/com/yeshi/fanli/service/inter/user/UserShareGoodsRecordService.java
@@ -142,5 +142,8 @@ throws UserShareGoodsRecordException; public List<UserShareGoodsGroup> listByRecordId(Long shareId); public ShareGoodsRecordDTO addRecordGoodsStorageV2(Long uid, List<TaoBaoGoodsBrief> listGoodsBrief, List<Long> listStorageID) throws UserShareGoodsRecordException; } fanli/src/main/java/com/yeshi/fanli/util/factory/CommonGoodsFactory.java
@@ -147,7 +147,7 @@ cg.setGoodsType(CommonGoods.GOODS_TYPE_PDD); cg.setPicture(goods.getGoodsThumbnailUrl()); cg.setPictureWhite(null); cg.setPrice(MoneyBigDecimalUtil.div(new BigDecimal(goods.getMinNormalPrice()), new BigDecimal(100))); cg.setPrice(MoneyBigDecimalUtil.div(new BigDecimal(goods.getMinGroupPrice()), new BigDecimal(100))); String salesTip = goods.getSalesTip(); if (StringUtil.isNullOrEmpty(salesTip)) {