袁野 2 months ago
parent d4cde237c5
commit f7fbeebafb
  1. 7
      cweb/pom.xml
  2. 25
      cweb/src/main/java/com/hfkj/controller/GoodsController.java
  3. 5
      service/src/main/java/com/hfkj/model/GoodsInfoModel.java
  4. 6
      service/src/main/java/com/hfkj/model/GoodsModel.java
  5. 4
      service/src/main/java/com/hfkj/model/PricePromotionInfoModel.java
  6. 8
      service/src/main/java/com/hfkj/service/goods/GoodsDataService.java
  7. 88
      service/src/main/java/com/hfkj/service/goods/impl/GoodsDataServiceImpl.java
  8. 32
      service/src/main/java/com/hfkj/service/pdd/PddService.java

@ -40,6 +40,13 @@
<directory>src/main/resources/${env}</directory> <directory>src/main/resources/${env}</directory>
<filtering>false</filtering> <filtering>false</filtering>
</resource> </resource>
<resource>
<directory>${basedir}/lib</directory>
<targetPath>BOOT-INF/lib/</targetPath>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
</resources> </resources>
<plugins> <plugins>
<plugin> <plugin>

@ -43,7 +43,7 @@ public class GoodsController {
) { ) {
try { try {
List<GoodsModel> goodsList = new ArrayList<>(); List<GoodsModel> goodsList;
// 1:淘宝 2:拼多多 // 1:淘宝 2:拼多多
if (type == 1) { if (type == 1) {
@ -55,11 +55,24 @@ public class GoodsController {
goodsList = goodsDataService.goodsModelTaoBaoList(jsonObject); goodsList = goodsDataService.goodsModelTaoBaoList(jsonObject);
} else if (type == 2) { } else if (type == 2) {
if (pageSize < 10) { JSONObject object = PddService.authority();
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR , "pageSize的取值范围是10-100!"); boolean generateAuthorityUrl = object.getJSONObject("authorityQueryResponse").getInteger("bind") == 0;
if (!generateAuthorityUrl && title != null) {
goodsList = new ArrayList<>();
JSONObject jsonObject = PddService.promotion();
JSONObject promotion = jsonObject.getJSONObject("rpPromotionUrlGenerateResponse").getJSONArray("urlList").getJSONObject(0);
GoodsModel goodsModel = new GoodsModel();
goodsModel.setPddUrl(promotion);
goodsList.add(goodsModel);
} else {
if (pageSize < 10) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR , "pageSize的取值范围是10-100!");
}
JSONObject jsonObject = PddService.syncInvoke(title , pageNo , pageSize);
goodsList = goodsDataService.goodsModelPddList(jsonObject);
} }
JSONObject jsonObject = PddService.syncInvoke(title , pageNo , pageSize);
return ResponseMsgUtil.success(jsonObject);
} else { } else {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR , "未知类型!"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR , "未知类型!");
} }
@ -105,7 +118,7 @@ public class GoodsController {
boolean generateAuthorityUrl = object.getJSONObject("authorityQueryResponse").getInteger("bind") == 0; boolean generateAuthorityUrl = object.getJSONObject("authorityQueryResponse").getInteger("bind") == 0;
JSONObject jsonObject = PddService.promotion(searchId , goodsSign , generateAuthorityUrl); JSONObject jsonObject = PddService.promotion(searchId , goodsSign , generateAuthorityUrl);
return ResponseMsgUtil.success(jsonObject); return ResponseMsgUtil.success(jsonObject.getJSONObject("goodsPromotionUrlGenerateResponse").getJSONArray("goodsPromotionUrlList").getJSONObject(0));
} catch (Exception e) { } catch (Exception e) {
log.error("error!",e); log.error("error!",e);

@ -36,4 +36,9 @@ public class GoodsInfoModel {
* 元宝数量 * 元宝数量
*/ */
BigDecimal ingot; BigDecimal ingot;
/**
* 库存
*/
String annualVol;
} }

@ -1,5 +1,6 @@
package com.hfkj.model; package com.hfkj.model;
import com.alibaba.fastjson.JSONObject;
import lombok.Data; import lombok.Data;
@ -18,4 +19,9 @@ public class GoodsModel {
*/ */
GoodsInfoModel goodsInfo; GoodsInfoModel goodsInfo;
/**
* 拼多多授权地址
*/
JSONObject pddUrl;
} }

@ -18,6 +18,10 @@ public class PricePromotionInfoModel {
* 预估到手价()若属于预售商品付定金时间内预估到手价价=定金+尾款的预估到手价 * 预估到手价()若属于预售商品付定金时间内预估到手价价=定金+尾款的预估到手价
*/ */
BigDecimal finalPromotionPrice; BigDecimal finalPromotionPrice;
/**
* 优惠券金额
*/
BigDecimal couponPrice;
/** /**
* 销售价格无促销时等于一口价有促销时为促销价若属于预售商品付定金时间内在线售卖价=预售价 * 销售价格无促销时等于一口价有促销时为促销价若属于预售商品付定金时间内在线售卖价=预售价
*/ */

@ -23,5 +23,13 @@ public interface GoodsDataService {
*/ */
List<GoodsModel> goodsModelTaoBaoList(JSONObject jsonObject); List<GoodsModel> goodsModelTaoBaoList(JSONObject jsonObject);
/**
* @MethodName goodsModelPddList
* @Description: 拼多多数据整理
* @param jsonObject
* @return: java.util.List<com.hfkj.model.GoodsModel>
* @Author: Sum1Dream
* @Date: 2024/9/20 下午2:21
*/
List<GoodsModel> goodsModelPddList(JSONObject jsonObject); List<GoodsModel> goodsModelPddList(JSONObject jsonObject);
} }

@ -10,9 +10,12 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
@Service("goodsDataService") @Service("goodsDataService")
public class GoodsDataServiceImpl implements GoodsDataService { public class GoodsDataServiceImpl implements GoodsDataService {
@ -38,7 +41,7 @@ public class GoodsDataServiceImpl implements GoodsDataService {
MorePromotionModel morePromotionModel; MorePromotionModel morePromotionModel;
List<MorePromotionModel> morePromotionModels; List<MorePromotionModel> morePromotionModels;
// 获取元宝的汇率 // 获取元宝的汇率
SecDictionary dictionary = secDictionaryService.findDictionary("GRADE_EXCHANGE_RATE"); SecDictionary dictionary = secDictionaryService.findDictionary("GOLD_COIN_EXCHANGE_RATE");
JSONArray data = jsonObject.getJSONArray("result_list"); JSONArray data = jsonObject.getJSONArray("result_list");
@ -49,7 +52,6 @@ public class GoodsDataServiceImpl implements GoodsDataService {
JSONObject price_promotion_info = object.getJSONObject("price_promotion_info"); JSONObject price_promotion_info = object.getJSONObject("price_promotion_info");
JSONObject item_basic_info = object.getJSONObject("item_basic_info"); JSONObject item_basic_info = object.getJSONObject("item_basic_info");
JSONObject income_info = publish_info.getJSONObject("income_info"); JSONObject income_info = publish_info.getJSONObject("income_info");
JSONArray more_promotion_list = price_promotion_info.getJSONArray("more_promotion_list");
JSONArray final_promotion_path_list = price_promotion_info.getJSONArray("final_promotion_path_list"); JSONArray final_promotion_path_list = price_promotion_info.getJSONArray("final_promotion_path_list");
// 淘客推广信息 // 淘客推广信息
@ -66,15 +68,25 @@ public class GoodsDataServiceImpl implements GoodsDataService {
publishInfoModel.setIncomeInfo(incomeInfoModel); publishInfoModel.setIncomeInfo(incomeInfoModel);
// 插入淘客推广信息 // 插入淘客推广信息
goodsModel.setPublishInfo(publishInfoModel); goodsModel.setPublishInfo(publishInfoModel);
String small_images;
// 商品基础信息 // 商品基础信息
goodsInfoModel = new GoodsInfoModel(); goodsInfoModel = new GoodsInfoModel();
goodsInfoModel.setIngot(incomeInfoModel.getCommissionAmount().multiply(new BigDecimal(dictionary.getCodeValue()))); goodsInfoModel.setIngot(incomeInfoModel.getCommissionAmount().multiply(new BigDecimal(dictionary.getCodeValue())));
goodsInfoModel.setProvCity(item_basic_info.getString("prov_city")); goodsInfoModel.setProvCity(item_basic_info.getString("prov_city"));
goodsInfoModel.setTitle(item_basic_info.getString("title")); goodsInfoModel.setTitle(item_basic_info.getString("title"));
goodsInfoModel.setAnnualVol(item_basic_info.getString("annual_vol"));
goodsInfoModel.setPictUrl(item_basic_info.getString("pict_url")); goodsInfoModel.setPictUrl(item_basic_info.getString("pict_url"));
goodsInfoModel.setShortTitle(item_basic_info.getString("short_title")); goodsInfoModel.setShortTitle(item_basic_info.getString("short_title"));
String small_images = item_basic_info.getJSONArray("small_images").toString(); if (item_basic_info.getJSONArray("small_images") == null) {
goodsInfoModel.setSmallImages(JSONObject.parseArray(small_images,String.class)); List<String> arrayList = new ArrayList<>();
arrayList.add(item_basic_info.getString("pict_url"));
goodsInfoModel.setSmallImages(arrayList);
} else {
small_images = item_basic_info.getJSONArray("small_images").toString();
goodsInfoModel.setSmallImages(JSONObject.parseArray(small_images,String.class));
}
goodsInfoModel.setShopTitle(item_basic_info.getString("shop_title")); goodsInfoModel.setShopTitle(item_basic_info.getString("shop_title"));
// 插入商品基础信息 // 插入商品基础信息
goodsModel.setGoodsInfo(goodsInfoModel); goodsModel.setGoodsInfo(goodsInfoModel);
@ -83,20 +95,10 @@ public class GoodsDataServiceImpl implements GoodsDataService {
pricePromotionInfoModel.setReservePrice(price_promotion_info.getBigDecimal("reserve_price")); pricePromotionInfoModel.setReservePrice(price_promotion_info.getBigDecimal("reserve_price"));
pricePromotionInfoModel.setZkFinalPrice(price_promotion_info.getBigDecimal("zk_final_price")); pricePromotionInfoModel.setZkFinalPrice(price_promotion_info.getBigDecimal("zk_final_price"));
pricePromotionInfoModel.setFinalPromotionPrice(price_promotion_info.getBigDecimal("final_promotion_price")); pricePromotionInfoModel.setFinalPromotionPrice(price_promotion_info.getBigDecimal("final_promotion_price"));
pricePromotionInfoModel.setCouponPrice(pricePromotionInfoModel.getZkFinalPrice().subtract(pricePromotionInfoModel.getFinalPromotionPrice()));
// 更多活动优惠 // 更多活动优惠
morePromotionModels = new ArrayList<>(); morePromotionModels = new ArrayList<>();
if (more_promotion_list != null && !more_promotion_list.isEmpty()) {
for (Object more_promotion : more_promotion_list) {
JSONObject morePromotion = (JSONObject) more_promotion;
morePromotionModel = new MorePromotionModel();
morePromotionModel.setPromotionDesc(morePromotion.getString("promotion_desc"));
morePromotionModel.setPromotionTitle(morePromotion.getString("promotion_title"));
morePromotionModel.setPromotionStartTime(morePromotion.getString("promotion_start_time"));
morePromotionModel.setPromotionEndTime(morePromotion.getString("promotion_end_time"));
morePromotionModel.setPromotionId(morePromotion.getString("promotion_id"));
morePromotionModels.add(morePromotionModel);
}
}
if (final_promotion_path_list != null && !final_promotion_path_list.isEmpty()) { if (final_promotion_path_list != null && !final_promotion_path_list.isEmpty()) {
for (Object final_promotion : final_promotion_path_list) { for (Object final_promotion : final_promotion_path_list) {
JSONObject morePromotion = (JSONObject) final_promotion; JSONObject morePromotion = (JSONObject) final_promotion;
@ -111,10 +113,15 @@ public class GoodsDataServiceImpl implements GoodsDataService {
} }
} }
morePromotionModels = morePromotionModels.stream().sorted(Comparator.comparing(MorePromotionModel:: getPromotionFee).reversed()).collect(Collectors.toList());
// 插入更多活动优惠 // 插入更多活动优惠
pricePromotionInfoModel.setMorePromotionList(morePromotionModels); pricePromotionInfoModel.setMorePromotionList(morePromotionModels);
goodsModel.setPricePromotionInfo(pricePromotionInfoModel); goodsModel.setPricePromotionInfo(pricePromotionInfoModel);
goodsModelList.add(goodsModel); if (!morePromotionModels.isEmpty()) {
goodsModelList.add(goodsModel);
}
} }
return goodsModelList; return goodsModelList;
@ -131,25 +138,60 @@ public class GoodsDataServiceImpl implements GoodsDataService {
PricePromotionInfoModel pricePromotionInfoModel; PricePromotionInfoModel pricePromotionInfoModel;
// 基础信息 // 基础信息
GoodsInfoModel goodsInfoModel; GoodsInfoModel goodsInfoModel;
// 商品佣金信息
IncomeInfoModel incomeInfoModel;
// 更多活动优惠 // 更多活动优惠
MorePromotionModel morePromotionModel; MorePromotionModel morePromotionModel;
List<MorePromotionModel> morePromotionModels; List<MorePromotionModel> morePromotionModels;
// 获取元宝的汇率
SecDictionary dictionary = secDictionaryService.findDictionary("GOLD_COIN_EXCHANGE_RATE");
JSONArray array = jsonObject.getJSONObject("goodsSearchResponse").getJSONArray("goodsSearchResponse"); JSONArray array = jsonObject.getJSONObject("goodsSearchResponse").getJSONArray("goodsList");
for (Object object : array) { for (Object object : array) {
JSONObject goods = (JSONObject) object; JSONObject goods = (JSONObject) object;
goodsModel = new GoodsModel(); goodsModel = new GoodsModel();
// 商品基础信息
goodsInfoModel = new GoodsInfoModel();
goodsInfoModel.setTitle(goods.getString("goodsName"));
goodsInfoModel.setAnnualVol(goods.getString("salesTip"));
goodsInfoModel.setPictUrl(goods.getString("goodsImageUrl"));
goodsInfoModel.setShopTitle(goods.getString("mallName"));
goodsInfoModel.setIngot(
goods.getBigDecimal("minNormalPrice").
multiply(goods.getBigDecimal("promotionRate").
multiply(new BigDecimal(dictionary.getCodeValue()))).
divide(new BigDecimal(100*1000) , 6 , RoundingMode.DOWN)
);
// 插入商品基础信息
goodsModel.setGoodsInfo(goodsInfoModel);
// 淘客推广信息 // 淘客推广信息
// 商品佣金信息
incomeInfoModel = new IncomeInfoModel();
publishInfoModel = new PublishInfoModel(); publishInfoModel = new PublishInfoModel();
publishInfoModel.setGoodsSign(goods.getString("goodsSign"));
publishInfoModel.setSearchId(goods.getString("searchId"));
// 插入淘客推广信息
goodsModel.setPublishInfo(publishInfoModel);
// 更多活动优惠
morePromotionModels = new ArrayList<>();
morePromotionModel = new MorePromotionModel();
morePromotionModel.setPromotionFee(goods.getBigDecimal("couponDiscount").divide(new BigDecimal(100) , 2 , RoundingMode.DOWN));
morePromotionModel.setPromotionStartTime(goods.getString("couponStartTime"));
morePromotionModel.setPromotionEndTime(goods.getString("couponEndTime"));
morePromotionModels.add(morePromotionModel);
// 价格促销信息
pricePromotionInfoModel = new PricePromotionInfoModel();
pricePromotionInfoModel.setReservePrice(goods.getBigDecimal("minNormalPrice").divide(new BigDecimal(100) , 2 , RoundingMode.DOWN));
pricePromotionInfoModel.setZkFinalPrice(goods.getBigDecimal("minGroupPrice").divide(new BigDecimal(100) , 2 , RoundingMode.DOWN));
pricePromotionInfoModel.setFinalPromotionPrice(pricePromotionInfoModel.getZkFinalPrice());
// 插入更多活动优惠
pricePromotionInfoModel.setMorePromotionList(morePromotionModels);
goodsModel.setPricePromotionInfo(pricePromotionInfoModel);
goodsModelList.add(goodsModel);
} }
return Collections.emptyList(); return goodsModelList;
} }
} }

@ -8,10 +8,12 @@ import com.pdd.pop.sdk.http.PopHttpClient;
import com.pdd.pop.sdk.http.api.pop.request.PddDdkGoodsPromotionUrlGenerateRequest; import com.pdd.pop.sdk.http.api.pop.request.PddDdkGoodsPromotionUrlGenerateRequest;
import com.pdd.pop.sdk.http.api.pop.request.PddDdkGoodsSearchRequest; import com.pdd.pop.sdk.http.api.pop.request.PddDdkGoodsSearchRequest;
import com.pdd.pop.sdk.http.api.pop.request.PddDdkMemberAuthorityQueryRequest; import com.pdd.pop.sdk.http.api.pop.request.PddDdkMemberAuthorityQueryRequest;
import com.pdd.pop.sdk.http.api.pop.request.PddDdkRpPromUrlGenerateRequest;
import com.pdd.pop.sdk.http.api.pop.response.PddDdkGoodsPromotionUrlGenerateResponse; import com.pdd.pop.sdk.http.api.pop.response.PddDdkGoodsPromotionUrlGenerateResponse;
import com.pdd.pop.sdk.http.api.pop.response.PddDdkGoodsSearchResponse; import com.pdd.pop.sdk.http.api.pop.response.PddDdkGoodsSearchResponse;
import com.pdd.pop.sdk.http.api.pop.response.PddDdkMemberAuthorityQueryResponse; import com.pdd.pop.sdk.http.api.pop.response.PddDdkMemberAuthorityQueryResponse;
import com.pdd.pop.sdk.http.api.pop.response.PddDdkRpPromUrlGenerateResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -81,6 +83,36 @@ public class PddService {
} }
/**
* @MethodName promotion
* @Description: 生成授权地址
* @param
* @return: com.alibaba.fastjson.JSONObject
* @Author: Sum1Dream
* @Date: 2024/9/20 下午3:57
*/
public static JSONObject promotion() throws Exception {
log.info("============ 拼多多请求-START =============");
String clientId = "71a050c5d93d4169a237539af44c7c33";
String clientSecret = "b96def667dd28660d09f19ba2e9e9f23d810d563";
PopClient client = new PopHttpClient(clientId, clientSecret);
PddDdkRpPromUrlGenerateRequest request = new PddDdkRpPromUrlGenerateRequest();
List<String> pIdList = new ArrayList<>();
pIdList.add("41483885_294044603");
request.setPIdList(pIdList);
request.setChannelType(10);
PddDdkRpPromUrlGenerateResponse response = client.syncInvoke(request);
log.info("请求接口:" + "promotion");
log.info("请求参数:" + JSONObject.toJSONString(request));
log.info("响应参数:" + JsonUtil.transferToJson(response));
log.info("============ 拼多多请求-END ==============");
return JSONObject.parseObject(JSON.toJSONString(response));
}
/** /**
* @MethodName authority * @MethodName authority
* @Description: 查询是否绑定备案 * @Description: 查询是否绑定备案

Loading…
Cancel
Save