袁野 2 years ago
commit 59fc152281
  1. 198
      hai-cweb/src/main/java/com/cweb/controller/HighThirdPartyController.java
  2. 37
      hai-service/src/main/java/com/hai/config/QianZhuConfig.java
  3. 80
      hai-service/src/main/java/com/hai/config/ThirdProductConfig.java
  4. 31
      hai-service/src/main/java/com/hai/entity/HighOrder.java
  5. 2
      hai-service/src/main/java/com/hai/service/HighOrderService.java
  6. 52
      hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.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<String> CategoryNameList = apiProductService.getCategoryName();
List<ApiStarbucksProducts> starbucksProductsList = new ArrayList<>();
@ -93,6 +115,9 @@ public class HighThirdPartyController {
List<ApiStarbucksProducts> 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);
@ -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<String, Object> 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
@ -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<String, Object> 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, "未查询到任何门店");
}
List<BsProductConfig> productConfigs = apiProductService.getProductConfig(listMap);
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());
}
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));
}
}
}
@ -278,4 +246,68 @@ public class HighThirdPartyController {
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);
}
}
}

@ -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<String,Object> contentMap = new LinkedHashMap<>();
contentMap.put("storeCode", storeCode);
@ -338,7 +338,7 @@ public class QianZhuConfig {
Map<String,Object> contentMap = new LinkedHashMap<>();
contentMap.put("orderNo", orderNo);
Map<String,Object> 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<String,Object> contentMap = new LinkedHashMap<>();
contentMap.put("orderNo", orderNo);
Map<String,Object> 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<String,Object> 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));
}
}

@ -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<String, Object> listMap = new HashMap<>();
listMap.put("productType", productType);
listMap.put("companyId", companyId);
List<BsProductConfig> productConfigs = apiProductService.getProductConfig(listMap);
if (productConfigs.size() > 0 ) {
return productConfigs.get(0).getDiscount();
}
return null;
}
// 产品折扣比例
public BsProductConfig getProductConfig(Integer productType , Long companyId) {
Map<String, Object> listMap = new HashMap<>();
listMap.put("productType", productType);
listMap.put("companyId", companyId);
List<BsProductConfig> 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<String, Object> 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;
}
}

@ -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
@ -207,6 +208,36 @@ public class HighOrder implements Serializable {
private String ext3;
private List<HighChildOrder> highChildOrderList;
private HighDiscount highDiscount;
private Boolean isTyAgent;
public List<HighChildOrder> getHighChildOrderList() {
return highChildOrderList;
}
public void setHighChildOrderList(List<HighChildOrder> 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() {

@ -443,5 +443,5 @@ public interface HighOrderService {
* @Param [com.alibaba.fastjson.JSONObject]
* @return void
*/
void insertThirdProduct(JSONObject object);
JSONObject insertThirdProduct(JSONObject object) throws Exception;
}

@ -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<String, Object> 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")) {
// 查询产品积分抵扣比例
BsProductDiscount bsProductDiscount = bsConfigService.getProductDiscountByMap(listMap);
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"));
highOrderMapper.insert(highOrder);
return jsonObject.getJSONObject("data");
} else {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR , jsonObject.getString("message"));
}
}
}

Loading…
Cancel
Save