瀏覽代碼

点餐调整

gongfuzhu 9 月之前
父節點
當前提交
c3db9866ff

+ 8 - 0
SpringBatchServiceClient/src/main/java/com/zswl/cloud/springBatch/client/model/ypp/kfc/request/CreateOrdereRquest.java

@@ -15,6 +15,14 @@ import java.util.List;
 @AllArgsConstructor
 @NoArgsConstructor
 public class CreateOrdereRquest {
+
+    private Channel channel;
+
+    private String shopName;
+
+    private String goodsName;
+
+    private String imageCnUrl;
     /**
      * appid
      */

+ 27 - 21
SpringBatchServiceServer/src/main/java/com/zswl/cloud/springBtach/server/core/api/ypp/KfcApi.java

@@ -1,28 +1,25 @@
 package com.zswl.cloud.springBtach.server.core.api.ypp;
 
 import cn.hutool.core.util.ObjectUtil;
-import cn.hutool.http.HttpRequest;
-import cn.hutool.http.HttpResponse;
-import cn.hutool.http.HttpUtil;
 import cn.hutool.json.JSONConfig;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
 import com.github.microservice.auth.security.helper.AuthHelper;
 import com.github.microservice.auth.security.model.AuthDetails;
-import com.zswl.cloud.springBatch.client.model.ypp.kfc.request.OrderListRequest;
 import com.zswl.cloud.springBatch.client.model.ypp.kfc.request.CreateOrdereRquest;
+import com.zswl.cloud.springBatch.client.model.ypp.kfc.request.OrderListRequest;
 import com.zswl.cloud.springBatch.client.model.ypp.kfc.response.*;
+import com.zswl.cloud.springBtach.server.core.api.ypp.request.KfcGoodsDetailRequest;
+import com.zswl.cloud.springBtach.server.core.api.ypp.request.KfcShopDetailRequest;
+import com.zswl.cloud.springBtach.server.core.api.ypp.request.KfcShopsRequest;
 import com.zswl.cloud.springBtach.server.core.dao.ApiLogDao;
-import com.zswl.cloud.springBtach.server.core.domain.ApiLog;
 import com.zswl.cloud.springBtach.server.core.helper.RedisHelper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
-import org.springframework.util.Assert;
+import org.springframework.util.MultiValueMap;
 import org.springframework.web.util.UriComponentsBuilder;
 
-import java.util.HashMap;
-
 //接口地址 https://apifox.com/apidoc/shared-48c64918-c4ce-49f4-b846-d23855299d7a/doc-2590155
 @Component
 public class KfcApi {
@@ -142,14 +139,18 @@ public class KfcApi {
      * @param lon
      * @return
      */
-    public ShopsResponse shops(String ot, String cityId, String lat, String lon) {
+    public ShopsResponse shops(KfcShopsRequest kfcShopsRequest) {
         String baseUrl = "https://channel.youpiaopiao.cn/api/kfc/shops";
-
         UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseUrl);
-        builder.queryParam("ot", ot);
-        builder.queryParam("cityId", cityId);
-        builder.queryParam("lat", lat);
-        builder.queryParam("lon", lon);
+        builder.queryParam("ot", kfcShopsRequest.getOt());
+        builder.queryParam("cityId", kfcShopsRequest.getCityId());
+
+        if (ObjectUtil.isNotEmpty(kfcShopsRequest.getLat())) {
+            builder.queryParam("lat", kfcShopsRequest.getLat());
+        }
+        if (ObjectUtil.isNotEmpty(kfcShopsRequest.getLon())) {
+            builder.queryParam("lon", kfcShopsRequest.getLon());
+        }
         String entries = tokenApi.httpGet(builder.build().toUriString());
         return JSONUtil.toBean(entries, ShopsResponse.class);
 
@@ -163,13 +164,18 @@ public class KfcApi {
      * @param lon
      * @return
      */
-    public ShopResponse shop(String id, String lat, String lon) {
+    public ShopResponse shop(KfcShopDetailRequest kfcShopDetailRequest) {
         String baseUrl = "https://channel.youpiaopiao.cn/api/kfc/shop";
 
         UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseUrl);
-        builder.queryParam("id", id);
-        builder.queryParam("lat", lat);
-        builder.queryParam("lon", lon);
+        builder.queryParam("id", kfcShopDetailRequest.getId());
+
+        if (ObjectUtil.isNotEmpty(kfcShopDetailRequest.getLat())) {
+            builder.queryParam("lat", kfcShopDetailRequest.getLat());
+        }
+        if (ObjectUtil.isNotEmpty(kfcShopDetailRequest.getLon())) {
+            builder.queryParam("lon", kfcShopDetailRequest.getLon());
+        }
         String entries = tokenApi.httpGet(builder.build().toUriString());
         return JSONUtil.toBean(entries, ShopResponse.class);
 
@@ -200,12 +206,12 @@ public class KfcApi {
      * @param productId
      * @return
      */
-    public JSONObject goods_detail(String shopId, String productId) {
+    public JSONObject goods_detail(KfcGoodsDetailRequest kfcGoodsDetailRequest) {
         String baseUrl = "https://channel.youpiaopiao.cn/api/kfc/goods_detail";
 
         UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseUrl);
-        builder.queryParam("shopId", shopId);
-        builder.queryParam("productId", productId);
+        builder.queryParam("shopId", kfcGoodsDetailRequest.getShopId());
+        builder.queryParam("productId", kfcGoodsDetailRequest.getProductId());
         String entries = tokenApi.httpGet(builder.build().toUriString());
         JSONConfig jsonConfig = new JSONConfig();
         jsonConfig.setIgnoreError(true);

+ 6 - 2
SpringBatchServiceServer/src/main/java/com/zswl/cloud/springBtach/server/core/api/ypp/YppApi.java

@@ -224,8 +224,12 @@ public class YppApi {
         builder.queryParam("districtId", districtId);
         builder.queryParam("brandId", brandId);
         builder.queryParam("cityId", cityId);
-        builder.queryParam("lat", lat);
-        builder.queryParam("lng", lng);
+        if (ObjectUtil.isNotEmpty(lat)) {
+            builder.queryParam("lat", lat);
+        }
+        if (ObjectUtil.isNotEmpty(lng)) {
+            builder.queryParam("lng", lng);
+        }
         String entries = tokenApi.httpGet(builder.build().toUriString());
         JSONConfig jsonConfig = JSONConfig.create();
         jsonConfig.setIgnoreError(true);

+ 14 - 0
SpringBatchServiceServer/src/main/java/com/zswl/cloud/springBtach/server/core/api/ypp/request/KfcGoodsDetailRequest.java

@@ -0,0 +1,14 @@
+package com.zswl.cloud.springBtach.server.core.api.ypp.request;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class KfcGoodsDetailRequest {
+
+    private String shopId;
+    private String productId;
+}

+ 15 - 0
SpringBatchServiceServer/src/main/java/com/zswl/cloud/springBtach/server/core/api/ypp/request/KfcShopDetailRequest.java

@@ -0,0 +1,15 @@
+package com.zswl.cloud.springBtach.server.core.api.ypp.request;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class KfcShopDetailRequest {
+
+    private String id;
+    private String lat;
+    private String lon;
+}

+ 16 - 0
SpringBatchServiceServer/src/main/java/com/zswl/cloud/springBtach/server/core/api/ypp/request/KfcShopsRequest.java

@@ -0,0 +1,16 @@
+package com.zswl.cloud.springBtach.server.core.api.ypp.request;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class KfcShopsRequest {
+
+    private String ot;
+    private String cityId;
+    private String lat;
+    private String lon;
+}

+ 77 - 0
SpringBatchServiceServer/src/main/java/com/zswl/cloud/springBtach/server/core/controller/KfcController.java

@@ -0,0 +1,77 @@
+package com.zswl.cloud.springBtach.server.core.controller;
+
+import cn.hutool.json.JSONObject;
+import com.github.microservice.auth.client.content.ResultContent;
+import com.github.microservice.auth.security.annotations.ResourceAuth;
+import com.github.microservice.auth.security.type.AuthType;
+import com.zhongshu.payment.client.model.order.v2.CreatOrderResultModel;
+import com.zswl.cloud.springBatch.client.model.ypp.kfc.request.CreateOrdereRquest;
+import com.zswl.cloud.springBatch.client.model.ypp.kfc.response.CityListResponse;
+import com.zswl.cloud.springBatch.client.model.ypp.kfc.response.CreateOrdereResponse;
+import com.zswl.cloud.springBatch.client.model.ypp.kfc.response.ShopResponse;
+import com.zswl.cloud.springBatch.client.model.ypp.kfc.response.ShopsResponse;
+import com.zswl.cloud.springBtach.server.core.api.ypp.request.KfcGoodsDetailRequest;
+import com.zswl.cloud.springBtach.server.core.api.ypp.request.KfcShopDetailRequest;
+import com.zswl.cloud.springBtach.server.core.api.ypp.request.KfcShopsRequest;
+import com.zswl.cloud.springBtach.server.core.service.impl.KfcServiceImpl;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.log4j.Log4j2;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.websocket.server.PathParam;
+
+@Log4j2
+@RestController
+@RequestMapping("ypp/kfc")
+public class KfcController {
+
+    @Autowired
+    private KfcServiceImpl kfcService;
+
+    @ApiOperation("城市列表")
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @RequestMapping(value = "cityList", method = RequestMethod.GET)
+    public ResultContent<CityListResponse> cityList() {
+
+        return kfcService.cityList();
+    }
+
+    @ApiOperation("平台店铺列表")
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @RequestMapping(value = "shops", method = RequestMethod.POST)
+    public ResultContent<ShopsResponse> shops(@RequestBody KfcShopsRequest kfcShopsRequest) {
+        return kfcService.shops(kfcShopsRequest);
+    }
+
+    @ApiOperation("店铺详情")
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @RequestMapping(value = "shop", method = RequestMethod.POST)
+    public ResultContent<ShopResponse> shop(@RequestBody KfcShopDetailRequest kfcShopsRequest) {
+        return kfcService.shop(kfcShopsRequest);
+    }
+
+    @ApiOperation("店铺详情")
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @RequestMapping(value = "menus/{shopId}", method = RequestMethod.GET)
+    public ResultContent<JSONObject> menus(@PathParam("shopId") String shopId) {
+        return kfcService.menus(shopId);
+    }
+
+    @ApiOperation("商品详情(不同平台返回的商品详情会有所不同)")
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @RequestMapping(value = "goodsDetail", method = RequestMethod.POST)
+    public ResultContent<JSONObject> goodsDetail(@RequestBody KfcGoodsDetailRequest kfcGoodsDetailRequest) {
+        return kfcService.goodsDetail(kfcGoodsDetailRequest);
+    }
+
+    @ApiOperation("下单(自己做产品展示,才需要下单接口)")
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @RequestMapping(value = "createOrder", method = RequestMethod.POST)
+    public ResultContent<CreatOrderResultModel> createOrder(@RequestBody CreateOrdereRquest createOrdereRquest) {
+        return kfcService.createOrder(createOrdereRquest);
+    }
+}

+ 155 - 0
SpringBatchServiceServer/src/main/java/com/zswl/cloud/springBtach/server/core/service/impl/KfcServiceImpl.java

@@ -0,0 +1,155 @@
+package com.zswl.cloud.springBtach.server.core.service.impl;
+
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import com.github.microservice.auth.client.content.ResultContent;
+import com.github.microservice.auth.client.content.ResultState;
+import com.github.microservice.auth.security.helper.AuthHelper;
+import com.zhongshu.payment.client.model.order.v2.CreatOrderResultModel;
+import com.zhongshu.payment.client.model.order.v2.CreateOrder2Model;
+import com.zhongshu.payment.client.service.v2.OrderService2;
+import com.zhongshu.payment.client.type.JobFlowMap;
+import com.zhongshu.payment.client.type.TransferOwner;
+import com.zhongshu.payment.client.type.TransferType;
+import com.zswl.cloud.shop.client.service.ShopService;
+import com.zswl.cloud.shop.client.vo.life.AccountDetailVo;
+import com.zswl.cloud.shop.client.vo.life.SharePlatformVo;
+import com.zswl.cloud.springBatch.client.model.ypp.kfc.request.CreateOrdereRquest;
+import com.zswl.cloud.springBatch.client.model.ypp.kfc.response.CityListResponse;
+import com.zswl.cloud.springBatch.client.model.ypp.kfc.response.CreateOrdereResponse;
+import com.zswl.cloud.springBatch.client.model.ypp.kfc.response.ShopResponse;
+import com.zswl.cloud.springBatch.client.model.ypp.kfc.response.ShopsResponse;
+import com.zswl.cloud.springBatch.client.model.ypp.movie.response.CreateOrder2Response;
+import com.zswl.cloud.springBatch.client.model.ypp.movie.response.OrderDetailResponse;
+import com.zswl.cloud.springBtach.server.core.api.ypp.KfcApi;
+import com.zswl.cloud.springBtach.server.core.api.ypp.request.KfcGoodsDetailRequest;
+import com.zswl.cloud.springBtach.server.core.api.ypp.request.KfcShopDetailRequest;
+import com.zswl.cloud.springBtach.server.core.api.ypp.request.KfcShopsRequest;
+import lombok.extern.log4j.Log4j2;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+
+@Service
+@Log4j2
+public class KfcServiceImpl {
+
+    @Autowired
+    OrderService2 orderService2;
+
+    @Autowired
+    ShopService shopService;
+
+    @Autowired
+    AuthHelper authHelper;
+
+
+    @Autowired
+    private KfcApi kfcApi;
+
+
+    public ResultContent<CityListResponse> cityList() {
+
+        CityListResponse cityListResponse = kfcApi.cityList();
+        return ResultContent.buildContent(cityListResponse);
+    }
+
+    public ResultContent<ShopsResponse> shops(KfcShopsRequest kfcShopsRequest) {
+
+        ShopsResponse shops = kfcApi.shops(kfcShopsRequest);
+        return ResultContent.buildContent(shops);
+    }
+
+    public ResultContent<ShopResponse> shop(KfcShopDetailRequest kfcShopDetailRequest) {
+
+        ShopResponse shop = kfcApi.shop(kfcShopDetailRequest);
+        return ResultContent.buildContent(shop);
+    }
+
+    public ResultContent<JSONObject> menus(String shopId) {
+
+        JSONObject menus = kfcApi.menus(shopId);
+        return ResultContent.buildContent(menus);
+    }
+
+    public ResultContent<JSONObject> goodsDetail(KfcGoodsDetailRequest kfcGoodsDetailRequest) {
+
+        JSONObject menus = kfcApi.goods_detail(kfcGoodsDetailRequest);
+        return ResultContent.buildContent(menus);
+    }
+
+    public ResultContent<CreatOrderResultModel> createOrder(CreateOrdereRquest kfcGoodsDetailRequest) {
+
+
+
+        com.zswl.cloud.shop.client.ret.ResultContent<AccountDetailVo> shopSetting = shopService.shopSetting("有票票");
+        if (!shopSetting.getState().equals(com.zswl.cloud.shop.client.ret.ResultState.Success)) {
+            return ResultContent.build(ResultState.Fail, "有票票信息未配置");
+        }
+        AccountDetailVo accountDetailVo = shopSetting.getContent();
+
+        String shopId = accountDetailVo.getAccountId();
+        String authAccount = accountDetailVo.getAuthAccount();
+        SharePlatformVo sharePlatformVo = accountDetailVo.getSharePlatformVo();
+
+        kfcGoodsDetailRequest.setPhone(authHelper.getCurrentUser().getPhone());
+        CreateOrdereResponse createOrdereResponse = kfcApi.create_order(kfcGoodsDetailRequest);
+        BigDecimal bigDecimal = BigDecimal.valueOf(createOrdereResponse.getData().getPayAmount());
+
+
+        CreateOrder2Model createOrder2Model = new CreateOrder2Model();
+        createOrder2Model.setUserId(authHelper.getCurrentUser().getUserId());
+        createOrder2Model.setShopId(shopId);
+        JSONObject shopInfo = new JSONObject();
+        shopInfo.set("shopName", kfcGoodsDetailRequest.getShopName());
+        createOrder2Model.setShopInfo(shopInfo);
+        createOrder2Model.setTotalAmount(bigDecimal);
+        createOrder2Model.setDiscountAmount(BigDecimal.ZERO);
+        createOrder2Model.setPayAmount(bigDecimal);
+        createOrder2Model.setAccesserUserId(authAccount);
+        createOrder2Model.setChannel(kfcGoodsDetailRequest.getChannel());
+
+
+        JSONObject goodsInfo = JSONUtil.parseObj(kfcGoodsDetailRequest);
+        goodsInfo.set("goodsName", kfcGoodsDetailRequest.getGoodsName());
+        goodsInfo.set("goodsPath", kfcGoodsDetailRequest.getImageCnUrl());
+        goodsInfo.set("channelOrderId", createOrdereResponse.getData().getOrderId());
+
+
+        CreateOrder2Model.Goods goods = new CreateOrder2Model.Goods();
+        goods.setGoodsId(kfcGoodsDetailRequest.getProducts().get(0).getProductId());
+        goods.setJobFlowMap(JobFlowMap.YPP);
+        goods.setGoodsInfo(goodsInfo);
+        goods.setPayAmount(bigDecimal);
+        goods.setValidDay(90);
+        goods.setTransferType(sharePlatformVo.getShareType().equals(1) ? TransferType.RATIO : TransferType.FIXED);
+
+        List<CreateOrder2Model.Owner> ownerList = new ArrayList<>();
+
+        CreateOrder2Model.Owner platfor = new CreateOrder2Model.Owner();
+        platfor.setOwner(TransferOwner.PLATFORM);
+        platfor.setValue(sharePlatformVo.getPlatformRate());
+
+        CreateOrder2Model.Owner buy = new CreateOrder2Model.Owner();
+        buy.setOwner(TransferOwner.BUY_SHOP);
+        buy.setValue(sharePlatformVo.getBuyShopRate());
+        buy.setShopId(shopId);
+
+        CreateOrder2Model.Owner use = new CreateOrder2Model.Owner();
+        use.setOwner(TransferOwner.USE_SHOP);
+        use.setValue(sharePlatformVo.getCheckShopRate());
+
+        ownerList.add(platfor);
+        ownerList.add(buy);
+        ownerList.add(use);
+        goods.setTransferRrule(ownerList);
+        goods.setExtend(JSONUtil.parseObj(createOrdereResponse));
+        createOrder2Model.setGoodsList(List.of(goods));
+
+        return orderService2.creat(createOrder2Model);
+//        return ResultContent.buildContent(order);
+    }
+}