From 06e2a1402e04c971c8fc1285e83887b0210b18b9 Mon Sep 17 00:00:00 2001 From: Sum1Dream <418471657@qq.com> Date: Wed, 6 Jul 2022 09:50:05 +0800 Subject: [PATCH] =?UTF-8?q?api=E9=9C=80=E6=B1=82=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/HighThirdPartyController.java | 218 ++++++++++-------- .../java/com/hai/config/QianZhuConfig.java | 37 ++- .../com/hai/config/ThirdProductConfig.java | 80 +++++++ .../main/java/com/hai/entity/HighOrder.java | 33 ++- .../com/hai/service/HighOrderService.java | 2 +- .../service/impl/HighOrderServiceImpl.java | 52 ++++- 6 files changed, 313 insertions(+), 109 deletions(-) create mode 100644 hai-service/src/main/java/com/hai/config/ThirdProductConfig.java diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighThirdPartyController.java b/hai-cweb/src/main/java/com/cweb/controller/HighThirdPartyController.java index 2a5be215..6c92d719 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighThirdPartyController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighThirdPartyController.java @@ -13,15 +13,14 @@ import com.hai.common.utils.CoordCommonUtil; import com.hai.common.utils.ResponseMsgUtil; import com.hai.config.CommonSysConst; import com.hai.config.QianZhuConfig; +import com.hai.config.ThirdProductConfig; import com.hai.entity.*; import com.hai.enum_type.ProductImgEnum; import com.hai.model.ApiStarbucksProductsModel; import com.hai.model.BsProductConfigModel; import com.hai.model.HighUserModel; import com.hai.model.ResponseData; -import com.hai.service.ApiProductService; -import com.hai.service.BsConfigService; -import com.hai.service.HighOrderService; +import com.hai.service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.collections4.MapUtils; @@ -37,6 +36,7 @@ import org.w3c.dom.ls.LSException; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.*; import java.util.stream.Collectors; @@ -52,14 +52,23 @@ public class HighThirdPartyController { private ApiProductService apiProductService; @Resource - private BsConfigService bsConfigService; + private ThirdProductConfig thirdProductConfig; @Resource private HighOrderService highOrderService; + @Resource + private BsCompanyService bsCompanyService; + + @Resource + private CommonService commonService; + @Autowired private UserCenter userCenter; + @Resource + private BsConfigService bsConfigService; + @RequestMapping(value = "/getAllCity", method = RequestMethod.GET) @ResponseBody @@ -77,9 +86,22 @@ public class HighThirdPartyController { @RequestMapping(value = "/getStarbucksProducts", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询星巴克商品") - public ResponseData getStarbucksProducts(@RequestParam(name = "name", required = false) String name) { + public ResponseData getStarbucksProducts(@RequestParam(name = "name", required = false) String name, + @RequestParam(value = "regionId", required = true) String regionId) { try { + SecRegion region = commonService.getParentByRegion(Long.valueOf(regionId)); + BigDecimal productDiscount = null; + if (region != null) { + BsCompany bsCompany = bsCompanyService.selectCompanyByRegion(region.getRegionId().toString()); + productDiscount = thirdProductConfig.getProductConfigNum(1, bsCompany.getId()); + } + + if (productDiscount == null) { + log.error("getRechargeProduct error!", "查询失败!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "当前地区未配置产品"); + } + List CategoryNameList = apiProductService.getCategoryName(); List starbucksProductsList = new ArrayList<>(); @@ -88,11 +110,14 @@ public class HighThirdPartyController { i++; ApiStarbucksProducts starbucksProducts = new ApiStarbucksProducts(); Map map = new HashMap<>(); - map.put("name" , name); - map.put("categoryName" , s); + map.put("name", name); + map.put("categoryName", s); List list = apiProductService.getStarbucksProducts(map); for (ApiStarbucksProducts apiStarbucksProducts : list) { apiStarbucksProducts.setExt1(String.valueOf(i)); + apiStarbucksProducts.setSalesVentiPrice(apiStarbucksProducts.getSalesVentiPrice().add(apiStarbucksProducts.getSalesVentiPrice().multiply(productDiscount.divide(new BigDecimal(100)))).setScale(2, RoundingMode.HALF_UP)); + apiStarbucksProducts.setSalesTallPrice(apiStarbucksProducts.getSalesTallPrice().add(apiStarbucksProducts.getSalesTallPrice().multiply(productDiscount.divide(new BigDecimal(100)))).setScale(2, RoundingMode.HALF_UP)); + apiStarbucksProducts.setSalesGrandePrice(apiStarbucksProducts.getSalesGrandePrice().add(apiStarbucksProducts.getSalesGrandePrice().multiply(productDiscount.divide(new BigDecimal(100)))).setScale(2, RoundingMode.HALF_UP)); starbucksProductsList.add(apiStarbucksProducts); } starbucksProducts.setName(s); @@ -115,12 +140,12 @@ public class HighThirdPartyController { public ResponseData getStarbucksStore(@RequestParam(name = "lat", required = true) String lat, @RequestParam(name = "lon", required = true) String lon) { try { - JSONObject jsonObject = QianZhuConfig.getStarbucksStore(lat , lon); + JSONObject jsonObject = QianZhuConfig.getStarbucksStore(lat, lon); if (jsonObject.getBoolean("success")) { return ResponseMsgUtil.success(jsonObject.getJSONArray("data")); } else { log.error("getRechargeProduct error!", "查询失败!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR , jsonObject.getString("message")); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, jsonObject.getString("message")); } } catch (Exception e) { @@ -129,77 +154,6 @@ public class HighThirdPartyController { } } - @RequestMapping(value = "/findStarbucksProducts", method = RequestMethod.GET) - @ResponseBody - @ApiOperation(value = "根据id查询详情产品详情") - public ResponseData findStarbucksProducts(@RequestParam(value = "id", required = true) Long id) { - try { - - BsProductConfig bsProductConfig = apiProductService.findProductConfigByGoodsId(id); - - if (bsProductConfig == null) { - log.error("findStarbucksProducts error!", "查询失败!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR , "未查询到当前商品"); - } - - ApiStarbucksProducts apiStarbucksProducts = apiProductService.findStarbucksProducts(bsProductConfig.getProductId()); - apiStarbucksProducts.setSalesVentiPrice(apiStarbucksProducts.getMarketVentiPrice().multiply(bsProductConfig.getDiscount()).divide(new BigDecimal(100))); - apiStarbucksProducts.setSalesTallPrice(apiStarbucksProducts.getMarketTallPrice().multiply(bsProductConfig.getDiscount()).divide(new BigDecimal(100))); - apiStarbucksProducts.setSalesGrandePrice(apiStarbucksProducts.getMarketGrandePrice().multiply(bsProductConfig.getDiscount()).divide(new BigDecimal(100))); - - ApiStarbucksProductsModel starbucksProductsModel = new ApiStarbucksProductsModel(); - BeanUtils.copyProperties(apiStarbucksProducts, starbucksProductsModel); - - Map listMap = new HashMap<>(); - listMap.put("productType", "5"); - listMap.put("returnType", 1); - listMap.put("sourceId", bsProductConfig.getId()); - listMap.put("platformId", null); - - starbucksProductsModel.setIntegralDiscount(bsConfigService.getProductDiscountByMap(listMap).getDiscount()); - starbucksProductsModel.setProductPayTypeString(bsConfigService.getProductPayTypeByMap(listMap)); - starbucksProductsModel.setProductPlatformString(bsConfigService.getProductPlatformByMap(listMap)); - - return ResponseMsgUtil.success(starbucksProductsModel); - - - } catch (Exception e) { - log.error("OutRechargePriceController --> findById() error!", e); - return ResponseMsgUtil.exception(e); - } - } - - @RequestMapping(value = "/addOrder", method = RequestMethod.POST) - @ResponseBody - @ApiOperation(value = "增加订单") - public ResponseData addOrder(@RequestBody JSONObject object, HttpServletRequest request) { - try { - - // 用户 - SessionObject sessionObject = userCenter.getSessionObject(request); - HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); - - - if (StringUtils.isBlank(object.getString("customerMobile")) || - StringUtils.isBlank(object.getString("regionId")) || - StringUtils.isBlank(object.getString("productType")) || - object.getJSONArray("orderItems") == null - ) { - log.error("addOrder error!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); - } - - object.put("userId", userInfoModel.getHighUser().getId()); - - highOrderService.insertThirdProduct(object); - - return ResponseMsgUtil.success("下单成功"); - - } catch (Exception e) { - log.error("HighOrderController -> addOrder() error!", e); - return ResponseMsgUtil.exception(e); - } - } @RequestMapping(value = "/getKfcStoresList", method = RequestMethod.GET) @ResponseBody @@ -207,19 +161,19 @@ public class HighThirdPartyController { public ResponseData getKfcStoresList(@RequestParam(name = "storeName", required = false) String storeName, @RequestParam(name = "cityCode", required = true) String cityCode, @RequestParam(name = "lat", required = true) String lat, - @RequestParam(name = "lon", required = true) String lon) { + @RequestParam(name = "lon", required = true) String lon) { try { Map map = new HashMap<>(); - map.put("storeName" , storeName); - map.put("cityCode" , cityCode); + map.put("storeName", storeName); + map.put("cityCode", cityCode); List list = apiProductService.getKfcStoresList(map); - if (StringUtils.isNotBlank(lat)){ + if (StringUtils.isNotBlank(lat)) { for (ApiKfcStores stores : list) { double distance = CoordCommonUtil.getDistance(Double.valueOf(stores.getLat()), Double.valueOf(stores.getLon()), Double.valueOf(lat), Double.valueOf(lon)); - stores.setDistance(String.valueOf(Math.round(distance/100d)/10d)); + stores.setDistance(String.valueOf(Math.round(distance / 100d) / 10d)); } } @@ -234,32 +188,46 @@ public class HighThirdPartyController { @RequestMapping(value = "/listByStoreCode", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询肯德基门店菜单") - public ResponseData listByStoreCode(@RequestParam(name = "storeCode", required = false) String storeCode) { + public ResponseData listByStoreCode(@RequestParam(name = "storeCode", required = false) String storeCode, @RequestParam(value = "regionId", required = true) String regionId) { try { JSONObject jsonObject = QianZhuConfig.listByStoreCode(storeCode); JSONArray array = jsonObject.getJSONArray("data"); - Map listMap = new HashMap<>(); - listMap.put("productType", "2"); - listMap.put("companyId", 2); + if (array == null) { + log.error("addOrder error!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未查询到任何门店"); + } + + BigDecimal productDiscount = null; + SecRegion region = commonService.getParentByRegion(Long.valueOf(regionId)); + if (region != null) { + BsCompany bsCompany = bsCompanyService.selectCompanyByRegion(region.getRegionId().toString()); + productDiscount = thirdProductConfig.getProductConfigNum(1, bsCompany.getId()); + } - List productConfigs = apiProductService.getProductConfig(listMap); + if (productDiscount == null) { + log.error("getRechargeProduct error!", "查询失败!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "当前地区未配置产品"); + } + int i = 0; for (Object data : array) { JSONObject dataObject = (JSONObject) data; + i++; + dataObject.put("kfcId", i); if (dataObject.getJSONArray("products") != null) { for (Object products : dataObject.getJSONArray("products")) { JSONObject productsObject = (JSONObject) products; BigDecimal productsPrice = productsObject.getBigDecimal("price"); - productsObject.put("salePrice" , productsPrice.add(productsPrice.multiply(productConfigs.get(0).getDiscount()).divide(new BigDecimal(100)))); + productsObject.put("salePrice", productsPrice.add(productsPrice.multiply(productDiscount).divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_UP)); if (productsObject.getJSONArray("specGroups") != null) { for (Object specGroups : productsObject.getJSONArray("specGroups")) { JSONObject specGroupsObject = (JSONObject) specGroups; BigDecimal specGroupsPrice = specGroupsObject.getBigDecimal("price"); - specGroupsObject.put("salePrice" , specGroupsPrice.add(specGroupsPrice.multiply(productConfigs.get(0).getDiscount()).divide(new BigDecimal(100)))); + specGroupsObject.put("salePrice", specGroupsPrice.add(specGroupsPrice.multiply(productDiscount).divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_UP)); } } } @@ -270,12 +238,76 @@ public class HighThirdPartyController { return ResponseMsgUtil.success(array); } else { log.error("getRechargeProduct error!", "查询失败!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR , jsonObject.getString("message")); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, jsonObject.getString("message")); + } + + } catch (Exception e) { + log.error("HighUserCardController --> oilCardRefund() error!", e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value = "/getThirdPartyByDetail", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "查询第三方产品详情") + public ResponseData getThirdPartyByDetail(@RequestParam(name = "platformId", required = true) Integer platformId, + @RequestParam(name = "productType", required = true) Integer productType, + @RequestParam(name = "regionId", required = true) String regionId) { + try { + + SecRegion region = commonService.getParentByRegion(Long.valueOf(regionId)); + + if (region == null) { + log.error("getRechargeProduct error!", "查询失败!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, regionId + "当前地区未配置产品"); } + BsCompany bsCompany = bsCompanyService.selectCompanyByRegion(region.getRegionId().toString()); + + return ResponseMsgUtil.success(thirdProductConfig.getThirdPartyByDetail(platformId , productType , bsCompany.getId())); + } catch (Exception e) { log.error("HighUserCardController --> oilCardRefund() error!", e); return ResponseMsgUtil.exception(e); } } + + + @RequestMapping(value = "/addOrder", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "增加订单") + public ResponseData addOrder(@RequestBody JSONObject object, HttpServletRequest request) { + try { + + // 用户 + SessionObject sessionObject = userCenter.getSessionObject(request); + HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); + + + if (StringUtils.isBlank(object.getString("customerMobile")) || + StringUtils.isBlank(object.getString("regionId")) || + StringUtils.isBlank(object.getString("storeCode")) || + object.getInteger("productType") == null || + object.getInteger("platformId") == null || + object.getJSONArray("orderItems") == null + ) { + log.error("addOrder error!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + SecRegion region = commonService.getParentByRegion(object.getLong("regionId")); + if (region != null) { + BsCompany bsCompany = bsCompanyService.selectCompanyByRegion(region.getRegionId().toString()); + object.put("companyId", String.valueOf(bsCompany.getId())); + } + + object.put("userId", userInfoModel.getHighUser().getId()); + + return ResponseMsgUtil.success(highOrderService.insertThirdProduct(object)); + + } catch (Exception e) { + log.error("HighOrderController -> addOrder() error!", e); + return ResponseMsgUtil.exception(e); + } + } } diff --git a/hai-service/src/main/java/com/hai/config/QianZhuConfig.java b/hai-service/src/main/java/com/hai/config/QianZhuConfig.java index f5d02eeb..d642c350 100644 --- a/hai-service/src/main/java/com/hai/config/QianZhuConfig.java +++ b/hai-service/src/main/java/com/hai/config/QianZhuConfig.java @@ -309,7 +309,7 @@ public class QianZhuConfig { * @Param [java.lang.String, java.lang.String, java.lang.String, java.lang.String] * @return com.alibaba.fastjson.JSONObject */ - public static JSONObject starbucksOrders( String platformUniqueId ,String storeCode , String orderItems , String customerMobile) throws Exception { + public static JSONObject starbucksOrders( Long platformUniqueId ,String storeCode , String orderItems , String customerMobile) throws Exception { Map contentMap = new LinkedHashMap<>(); contentMap.put("storeCode", storeCode); @@ -338,7 +338,7 @@ public class QianZhuConfig { Map contentMap = new LinkedHashMap<>(); contentMap.put("orderNo", orderNo); Map map = new HashMap<>(); - map.put("platformId", "10458"); + map.put("platformId", CommonSysConst.getSysConfig().getQinzhuPlatformId()); map.put("action", "starbucksOrders.pay"); map.put("version", "1.0"); map.put("content", JSON.toJSONString(contentMap)); @@ -369,4 +369,37 @@ public class QianZhuConfig { map.put("sign", MD5Util.encode(QianZhuConfig.generateSignature(map,CommonSysConst.getSysConfig().getQinzhuSecret()).getBytes()).toLowerCase()); return HttpsUtils.doPost(CommonSysConst.getSysConfig().getQinzhuUrl()+"/openApi/v4/orders/createKfcOrder", JSONObject.toJSONString(map)); } + + /** + * @Author Sum1Dream + * @name starbucksOrderByOrderNo.java + * @Description // 根据订单号查询星巴克订单详情 + * @Date 16:38 2022/7/5 + * @Param [java.lang.String] + * @return com.alibaba.fastjson.JSONObject + */ + public static JSONObject starbucksOrderByOrderNo(String orderNo) throws Exception { + Map contentMap = new LinkedHashMap<>(); + contentMap.put("orderNo", orderNo); + Map map = new HashMap<>(); + map.put("platformId", CommonSysConst.getSysConfig().getQinzhuPlatformId()); + map.put("action", "starbucksOrders.getByOrderNo"); + map.put("version", "1.0"); + map.put("content", JSON.toJSONString(contentMap)); + map.put("traceId", WxUtils.makeNonStr()); + map.put("timestamp", new Date().getTime()); + map.put("sign", MD5Util.encode(generateSignature(map,"nnl3gg4ss0pka11t").getBytes()).toLowerCase()); + return HttpsUtils.doPost(CommonSysConst.getSysConfig().getQianzhuH5url(), JSON.toJSONString(map)); + } + + public static JSONObject getKfcOrderByOrderNo(Integer eatType , String storeCode , String mobile , String items , String platformUniqueId , String userRemark) throws Exception { + Map map = new HashMap<>(); + map.put("platformId", CommonSysConst.getSysConfig().getQinzhuPlatformId()); + map.put("items", items); + map.put("timestamp", new Date().getTime()); + map.put("sign", MD5Util.encode(QianZhuConfig.generateSignature(map,CommonSysConst.getSysConfig().getQinzhuSecret()).getBytes()).toLowerCase()); + return HttpsUtils.doPost(CommonSysConst.getSysConfig().getQinzhuUrl()+"/openApi/v4/orders/createKfcOrder", JSONObject.toJSONString(map)); + } + + } diff --git a/hai-service/src/main/java/com/hai/config/ThirdProductConfig.java b/hai-service/src/main/java/com/hai/config/ThirdProductConfig.java new file mode 100644 index 00000000..d80dd470 --- /dev/null +++ b/hai-service/src/main/java/com/hai/config/ThirdProductConfig.java @@ -0,0 +1,80 @@ +package com.hai.config; + +import com.alibaba.fastjson.JSONObject; +import com.hai.entity.BsProductConfig; +import com.hai.entity.BsProductDiscount; +import com.hai.service.ApiProductService; +import com.hai.service.BsConfigService; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author hurui + * @version 1.0 + * @ClassName ThirdProductConfig + * @description: 第三方接口配置文件 + * @date 2021/7/5 14:18 + */ +@Component +public class ThirdProductConfig { + + @Resource + private BsConfigService bsConfigService; + + @Resource + private ApiProductService apiProductService; + + // 产品折扣比例 + public BigDecimal getProductConfigNum(Integer productType , Long companyId) { + + Map listMap = new HashMap<>(); + listMap.put("productType", productType); + listMap.put("companyId", companyId); + + List productConfigs = apiProductService.getProductConfig(listMap); + + if (productConfigs.size() > 0 ) { + return productConfigs.get(0).getDiscount(); + } + return null; + } + + // 产品折扣比例 + public BsProductConfig getProductConfig(Integer productType , Long companyId) { + + Map listMap = new HashMap<>(); + listMap.put("productType", productType); + listMap.put("companyId", companyId); + + List productConfigs = apiProductService.getProductConfig(listMap); + + if (productConfigs.size() > 0 ) { + return productConfigs.get(0); + } + return null; + } + + public JSONObject getThirdPartyByDetail(Integer platformId , Integer productType , Long companyId) { + BsProductConfig productConfig = getProductConfig(productType, companyId); + + JSONObject object = new JSONObject(); + + Map listMap = new HashMap<>(); + listMap.put("productType", "5"); + listMap.put("returnType", 1); + listMap.put("sourceId", productConfig.getId()); + listMap.put("platformId", platformId); + + object.put("integralDiscount" , bsConfigService.getProductDiscountByMap(listMap).getDiscount()); + object.put("productPayType" , bsConfigService.getProductPayTypeByMap(listMap)); + object.put("productPlatform" , bsConfigService.getProductPlatformByMap(listMap)); + + return object; + } + +} diff --git a/hai-service/src/main/java/com/hai/entity/HighOrder.java b/hai-service/src/main/java/com/hai/entity/HighOrder.java index a41be3cf..f29c94b1 100644 --- a/hai-service/src/main/java/com/hai/entity/HighOrder.java +++ b/hai-service/src/main/java/com/hai/entity/HighOrder.java @@ -3,6 +3,7 @@ package com.hai.entity; import java.io.Serializable; import java.math.BigDecimal; import java.util.Date; +import java.util.List; /** * high_order @@ -200,6 +201,36 @@ public class HighOrder implements Serializable { private String ext3; + private List highChildOrderList; + + private HighDiscount highDiscount; + + private Boolean isTyAgent; + + public List getHighChildOrderList() { + return highChildOrderList; + } + + public void setHighChildOrderList(List highChildOrderList) { + this.highChildOrderList = highChildOrderList; + } + + public HighDiscount getHighDiscount() { + return highDiscount; + } + + public void setHighDiscount(HighDiscount highDiscount) { + this.highDiscount = highDiscount; + } + + public Boolean getIsTyAgent() { + return isTyAgent; + } + + public void setIsTyAgent(Boolean tyAgent) { + isTyAgent = tyAgent; + } + private static final long serialVersionUID = 1L; public Long getId() { @@ -662,4 +693,4 @@ public class HighOrder implements Serializable { sb.append("]"); return sb.toString(); } -} \ No newline at end of file +} diff --git a/hai-service/src/main/java/com/hai/service/HighOrderService.java b/hai-service/src/main/java/com/hai/service/HighOrderService.java index 0adca0de..a44fbb6f 100644 --- a/hai-service/src/main/java/com/hai/service/HighOrderService.java +++ b/hai-service/src/main/java/com/hai/service/HighOrderService.java @@ -443,5 +443,5 @@ public interface HighOrderService { * @Param [com.alibaba.fastjson.JSONObject] * @return void */ - void insertThirdProduct(JSONObject object); + JSONObject insertThirdProduct(JSONObject object) throws Exception; } diff --git a/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java index 5bae2102..27a704cf 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java @@ -8,6 +8,7 @@ import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; import com.hai.common.utils.DateUtil; import com.hai.common.utils.HttpsUtils; +import com.hai.common.utils.ResponseMsgUtil; import com.hai.config.*; import com.hai.dao.*; import com.hai.entity.*; @@ -15,6 +16,7 @@ import com.hai.enum_type.*; import com.hai.model.*; import com.hai.msg.entity.MsgTopic; import com.hai.service.*; +import io.netty.handler.ipfilter.UniqueIpFilter; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.eclipse.paho.client.mqttv3.MqttClient; @@ -43,6 +45,9 @@ public class HighOrderServiceImpl implements HighOrderService { @Resource private HighDeviceService deviceService; + @Resource + private ThirdProductConfig thirdProductConfig; + @Resource private HighOrderMapperExt highOrderMapperExt; @@ -55,6 +60,10 @@ public class HighOrderServiceImpl implements HighOrderService { @Resource private HighCouponCodeService highCouponCodeService; + @Resource + private ApiProductService apiProductService; + + @Resource private HighCouponService highCouponService; @@ -1763,21 +1772,40 @@ public class HighOrderServiceImpl implements HighOrderService { } } - @Override - @Transactional( - isolation = Isolation.SERIALIZABLE, - propagation = Propagation.REQUIRES_NEW) - public void insertThirdProduct(JSONObject object) { + public JSONObject insertThirdProduct(JSONObject object) throws Exception { + + HighOrder highOrder = new HighOrder(); HighUser user = highUserService.findByUserId(object.getLong("userId")); - // 查询积分抵扣比例 - Map listMap = new HashMap<>(); - listMap.put("productType", "5"); - listMap.put("returnType", 1); - listMap.put("sourceId", 100001); + JSONObject jsonObject = null; + // 1 星巴克 2 肯德基 + if (object.getInteger("productType") == 1) { + jsonObject = QianZhuConfig.starbucksOrders(object.getLong("userId") , object.getString("storeCode") , object.getString("orderItems") , object.getString("customerMobile")); + } else if (object.getInteger("productType") == 2) { + if (object.getInteger("eatType") == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请选择就餐方式!"); + } + jsonObject = QianZhuConfig.createKfcOrder(object.getInteger("eatType") , object.getString("storeCode") , object.getString("customerMobile") , object.getString("orderItems") , object.getString("userId"), object.getString("userRemark")); + } + + if (jsonObject != null && jsonObject.getBoolean("success")) { + + highOrder.setOrderNo(jsonObject.getJSONObject("data").getString("orderNo")); + highOrder.setRegionId(object.getString("regionId")); + highOrder.setCreateTime(new Date()); + highOrder.setMemId(user.getId()); + highOrder.setMemName(user.getName()); + highOrder.setMemPhone(user.getPhone()); + highOrder.setOrderStatus(1); + highOrder.setRemarks(object.getString("userRemark")); - // 查询产品积分抵扣比例 - BsProductDiscount bsProductDiscount = bsConfigService.getProductDiscountByMap(listMap); + highOrderMapper.insert(highOrder); + + return jsonObject.getJSONObject("data"); + } else { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR , jsonObject.getString("message")); + } } + }