123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- package com.cdf.controller.api;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.cdf.common.ResultCode;
- import com.cdf.common.ResultData;
- import com.cdf.entity.ProductSource;
- import com.cdf.exception.BusinessException;
- import com.cdf.httpClient.client.CdfClient;
- import com.cdf.httpClient.client.CdfHKClient;
- import com.cdf.httpClient.request.CdfInCatRequest;
- import com.cdf.httpClient.response.cdf.CdfProductVo;
- import com.cdf.response.SkuListVo;
- import com.cdf.service.IProductSourceService;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.RestController;
- import javax.annotation.Resource;
- import java.util.List;
- @RestController
- @RequestMapping("/api")
- public class CdfHkProductApiController {
- @Resource
- private CdfHKClient cdfHKClient;
- @Autowired
- private IProductSourceService productSourceService;
- @GetMapping("/getCatNum")
- public ResultData getCatNum(@RequestParam(required = false) String AccessToken,
- @RequestParam(required = false,defaultValue = "1")Integer productSourceId){
- ProductSource productSource = productSourceService.getById(productSourceId);
- if(productSource == null|| productSource.getMchType() == 1){
- throw new BusinessException(ResultCode.PARAM_MISS);
- }
- JSONObject catNum = cdfHKClient.getCatNum(productSource.getCdfHost(),productSource.getCdfMchId(),AccessToken);
- return ResultData.ok(catNum);
- }
- @GetMapping("/inCat")
- public ResultData inCat(@RequestParam(required = false) String AccessToken,
- @RequestParam(required = false) String skuId,
- @RequestParam(required = false) Integer num,
- @RequestParam(required = false,defaultValue = "1")Integer productSourceId){
- ProductSource productSource = productSourceService.getById(productSourceId);
- if(productSource == null|| productSource.getMchType() == 1){
- throw new BusinessException(ResultCode.PARAM_MISS);
- }
- JSONObject jsonObject = cdfHKClient.inCat(productSource.getCdfHost(),productSource.getCdfMchId(),AccessToken, new CdfInCatRequest(skuId, num));
- if(jsonObject.get("success")!=null && !jsonObject.getBoolean("success")){
- return ResultData.error(jsonObject.getString("msg"));
- }
- if(jsonObject.get("status")!=null ){
- return ResultData.error(401,jsonObject.getString("msg"));
- }
- return ResultData.ok(jsonObject);
- }
- @GetMapping("/getProductInfo")
- public ResultData getProductInfo(@RequestParam(required = false) String productId,
- @RequestParam(required = false,defaultValue = "1")Integer productSourceId){
- if(StringUtils.isBlank(productId)){
- return ResultData.ok();
- }
- ProductSource productSource = productSourceService.getById(productSourceId);
- if(productSource == null || productSource.getMchType() == 1){
- throw new BusinessException(ResultCode.PARAM_MISS);
- }
- CdfProductVo productById = cdfHKClient.getProductById(productSource.getCdfHost(),productSource.getCdfMchId(),productId);
- /**
- * 澳门店:1
- * 东涌店:2
- * 柬中免店:3
- * 会员购店:12
- * https://ar.cdfmembers.com/spu?showType=makeup&spuId=p15685542&storeId=1&userId=601131887&AccessToken=05508E6249DF10D42876C63E6823E98AAFCA8B1CD592F0D5B5A112BF3B51BB01BD5C8661A63D9D16039DA34FD0352B184F892FAB146A3531&cookieId=24fb1f47-cf3f-4a3d-c0fe-62be0c99a400
- */
- List<SkuListVo> skuList = cdfHKClient.getSkuList(productId, productSourceId);
- for (SkuListVo o : skuList) {
- o.setUrl(o.getUrl() + "&spuId=" + productId +"&storeId="+productSourceId);
- }
- productById.setSkuList(skuList);
- return ResultData.ok(productById);
- }
- }
|