|
|
@ -1,15 +1,16 @@ |
|
|
|
package com.hai.order.service.impl; |
|
|
|
package com.hai.order.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.hai.common.exception.ErrorCode; |
|
|
|
import com.hai.common.exception.ErrorCode; |
|
|
|
import com.hai.common.exception.ErrorHelp; |
|
|
|
import com.hai.common.exception.ErrorHelp; |
|
|
|
import com.hai.common.exception.SysCode; |
|
|
|
import com.hai.common.exception.SysCode; |
|
|
|
import com.hai.common.security.AESEncodeUtil; |
|
|
|
import com.hai.common.security.AESEncodeUtil; |
|
|
|
import com.hai.common.security.UserCenter; |
|
|
|
import com.hai.common.security.UserCenter; |
|
|
|
|
|
|
|
import com.hai.common.utils.DateUtil; |
|
|
|
import com.hai.common.utils.IDGenerator; |
|
|
|
import com.hai.common.utils.IDGenerator; |
|
|
|
import com.hai.config.HuiLianTongConfig; |
|
|
|
import com.hai.config.*; |
|
|
|
import com.hai.config.HuiLianTongUnionCardConfig; |
|
|
|
|
|
|
|
import com.hai.config.JinZhuJiaYouService; |
|
|
|
|
|
|
|
import com.hai.entity.*; |
|
|
|
import com.hai.entity.*; |
|
|
|
import com.hai.enum_type.GasClassGroupTaskStatus; |
|
|
|
import com.hai.enum_type.GasClassGroupTaskStatus; |
|
|
|
import com.hai.enum_type.JinZhuJiaYouOilNo; |
|
|
|
import com.hai.enum_type.JinZhuJiaYouOilNo; |
|
|
@ -35,6 +36,7 @@ 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.net.URLDecoder; |
|
|
|
import java.net.URLDecoder; |
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Collectors; |
|
|
@ -101,6 +103,15 @@ public class OrderCreateHandleServiceImpl implements OrderCreateHandleService { |
|
|
|
@Resource |
|
|
|
@Resource |
|
|
|
private JinZhuJiaYouService gasJinZhuJiaYouService; |
|
|
|
private JinZhuJiaYouService gasJinZhuJiaYouService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
|
|
|
private ThirdProductConfig thirdProductConfig; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
|
|
|
private HighUserService highUserService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
|
|
|
private ApiMemberProductService apiMemberProductService; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public List<HighChildOrder> couponHandle(HighDiscountUserRel discountUserRel, CreateOrderChildModel createOrderChild) throws Exception { |
|
|
|
public List<HighChildOrder> couponHandle(HighDiscountUserRel discountUserRel, CreateOrderChildModel createOrderChild) throws Exception { |
|
|
|
if (createOrderChild.getSaleCount() != 1) { |
|
|
|
if (createOrderChild.getSaleCount() != 1) { |
|
|
@ -488,4 +499,226 @@ public class OrderCreateHandleServiceImpl implements OrderCreateHandleService { |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public List<HighChildOrder> thirdPartyOrder(JSONObject object) throws Exception { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<HighChildOrder> childOrderList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 查询用户
|
|
|
|
|
|
|
|
HighUser user = highUserService.findByUserId(object.getLong("userId")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 实际支付金额
|
|
|
|
|
|
|
|
BigDecimal orderPayPrice = new BigDecimal(0); |
|
|
|
|
|
|
|
// 市场金额
|
|
|
|
|
|
|
|
BigDecimal marketPrice = new BigDecimal(0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 查询详单订单的实际
|
|
|
|
|
|
|
|
JSONObject productDetail = thirdProductConfig.getThirdPartyByDetail(object.getInteger("platformId"), object.getInteger("productType"), object.getLong("companyId") , object.getLong("productId")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取token 千猪请求接口token
|
|
|
|
|
|
|
|
JSONObject userToken = QianZhuConfig.getTokenV2(user.getId().toString(), user.getName(), user.getPhone()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!userToken.getBoolean("success")) { |
|
|
|
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, userToken.getString("message")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 1 星巴克 2 肯德基 3 会员充值
|
|
|
|
|
|
|
|
if (object.getInteger("productType") == 1) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<String> List = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONArray array = object.getJSONArray("orderItems"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (Object o : array) { |
|
|
|
|
|
|
|
JSONObject object1 = (JSONObject) o; |
|
|
|
|
|
|
|
Map<String, Object> contentMap = new LinkedHashMap<>(); |
|
|
|
|
|
|
|
if (!object1.getString("productId").equals("")) { |
|
|
|
|
|
|
|
contentMap.put("productId", object1.getString("productId")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!object1.getString("cupSize").equals("")) { |
|
|
|
|
|
|
|
contentMap.put("cupSize", object1.getString("cupSize")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!object1.getString("temperature").equals("")) { |
|
|
|
|
|
|
|
contentMap.put("temperature", object1.getString("temperature")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!object1.getString("cream").equals("")) { |
|
|
|
|
|
|
|
contentMap.put("cream", object1.getString("cream")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!object1.getString("espresso").equals("")) { |
|
|
|
|
|
|
|
contentMap.put("espresso", object1.getString("espresso")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!object1.getString("milk").equals("")) { |
|
|
|
|
|
|
|
contentMap.put("milk", object1.getString("milk")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!object1.getString("milkBubble").equals("")) { |
|
|
|
|
|
|
|
contentMap.put("milkBubble", object1.getString("milkBubble")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!"".equals(object1.getString("num"))) { |
|
|
|
|
|
|
|
contentMap.put("num", object1.getString("num")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
List.add(JSON.toJSONString(contentMap)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 下单
|
|
|
|
|
|
|
|
jsonObject = QianZhuConfig.starbucksOrders(user.getId().toString(), object.getString("storeCode"), List.toString().replace(" ", ""), object.getString("customerMobile")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 判断下单是否成功
|
|
|
|
|
|
|
|
if (!Objects.equals(jsonObject.getString("code"), "200")) { |
|
|
|
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, jsonObject.getString("message")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!jsonObject.getBoolean("success")) { |
|
|
|
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, jsonObject.getString("message")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 根据订单号查询订单详情
|
|
|
|
|
|
|
|
JSONObject orderObject = QianZhuConfig.starbucksOrderByOrderNo(jsonObject.getJSONObject("data").getString("orderNo")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 判断是否成功
|
|
|
|
|
|
|
|
if (!orderObject.getBoolean("success")) { |
|
|
|
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, jsonObject.getString("message")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取星巴克订单内容
|
|
|
|
|
|
|
|
JSONArray starbucksOrder = orderObject.getJSONObject("data").getJSONArray("orderItems"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (Object starbucksObject : starbucksOrder) { |
|
|
|
|
|
|
|
JSONObject childObject = (JSONObject) starbucksObject; |
|
|
|
|
|
|
|
HighChildOrder childOrder = new HighChildOrder(); |
|
|
|
|
|
|
|
childOrder.setChildOrderStatus(1); |
|
|
|
|
|
|
|
childOrder.setGoodsType(9); |
|
|
|
|
|
|
|
childOrder.setStoreId(object.getLong("storeCode")); |
|
|
|
|
|
|
|
childOrder.setChannelOrderNo(jsonObject.getJSONObject("data").getString("orderNo")); |
|
|
|
|
|
|
|
childOrder.setGoodsId(object.getLong("productId")); |
|
|
|
|
|
|
|
childOrder.setStoreAddress(childObject.getString("storeAddress")); |
|
|
|
|
|
|
|
childOrder.setStoreName(childObject.getString("storeName")); |
|
|
|
|
|
|
|
childOrder.setGoodsName(childObject.getString("productName")); |
|
|
|
|
|
|
|
childOrder.setGoodsImg(childObject.getString("imgUrl")); |
|
|
|
|
|
|
|
childOrder.setSaleCount(childObject.getInteger("quantity")); |
|
|
|
|
|
|
|
childOrder.setGoodsPrice(childObject.getBigDecimal("marketPrice")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 计算利润
|
|
|
|
|
|
|
|
BigDecimal profitPrice = childObject.getBigDecimal("marketPrice").multiply(productDetail.getBigDecimal("priceDiscount").divide(new BigDecimal(100))); |
|
|
|
|
|
|
|
// 计算子订单支付金额
|
|
|
|
|
|
|
|
BigDecimal childPrice = childObject.getBigDecimal("unitPrice").add(profitPrice).setScale(2 , RoundingMode.HALF_UP); |
|
|
|
|
|
|
|
if (childPrice.compareTo(childObject.getBigDecimal("marketPrice")) > 0) { |
|
|
|
|
|
|
|
childPrice = childObject.getBigDecimal("marketPrice"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (object.getLong("memDiscountId") != null) { |
|
|
|
|
|
|
|
childOrder.setGoodsActualPrice(childObject.getBigDecimal("marketPrice")); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
childOrder.setGoodsActualPrice(childPrice); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
childPrice = childPrice.multiply(childObject.getBigDecimal("quantity")); |
|
|
|
|
|
|
|
// 计算总订单实际支付金额
|
|
|
|
|
|
|
|
orderPayPrice = orderPayPrice.add(childPrice); |
|
|
|
|
|
|
|
// 计算市场价金额
|
|
|
|
|
|
|
|
marketPrice = marketPrice.add(childObject.getBigDecimal("marketPrice").multiply(childObject.getBigDecimal("quantity"))); |
|
|
|
|
|
|
|
childOrder.setTotalPrice(childPrice); |
|
|
|
|
|
|
|
childOrderList.add(childOrder); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} 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")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 判断下单是否成功
|
|
|
|
|
|
|
|
if (!Objects.equals(jsonObject.getString("code"), "10000")) { |
|
|
|
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, jsonObject.getString("message")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 根据订单号查询订单详情
|
|
|
|
|
|
|
|
JSONObject orderObject = QianZhuConfig.getKfcOrderByOrderNo(jsonObject.getJSONObject("data").getString("orderNo")); |
|
|
|
|
|
|
|
// 判断下单是否成功
|
|
|
|
|
|
|
|
if (!orderObject.getBoolean("success")) { |
|
|
|
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, jsonObject.getString("message")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取肯德基订单内容
|
|
|
|
|
|
|
|
JSONArray kfcOrder = orderObject.getJSONObject("data").getJSONObject("kfcPlaceOrder").getJSONArray("items"); |
|
|
|
|
|
|
|
for (Object kfcObject : kfcOrder) { |
|
|
|
|
|
|
|
JSONObject childObject = (JSONObject) kfcObject; |
|
|
|
|
|
|
|
HighChildOrder childOrder = new HighChildOrder(); |
|
|
|
|
|
|
|
childOrder.setChildOrderStatus(1); |
|
|
|
|
|
|
|
childOrder.setGoodsType(4); |
|
|
|
|
|
|
|
childOrder.setGoodsId(object.getLong("productId")); |
|
|
|
|
|
|
|
childOrder.setChannelOrderNo(jsonObject.getJSONObject("data").getString("orderNo")); |
|
|
|
|
|
|
|
childOrder.setStoreAddress(orderObject.getJSONObject("data").getJSONObject("kfcPlaceOrder").getString("storeAddress")); |
|
|
|
|
|
|
|
childOrder.setStoreName(orderObject.getJSONObject("data").getJSONObject("kfcPlaceOrder").getString("storeName")); |
|
|
|
|
|
|
|
childOrder.setGoodsName(childObject.getString("productName")); |
|
|
|
|
|
|
|
childOrder.setGoodsImg(childObject.getString("imageUrl")); |
|
|
|
|
|
|
|
childOrder.setSaleCount(childObject.getInteger("quantity")); |
|
|
|
|
|
|
|
childOrder.setGoodsPrice(childObject.getBigDecimal("originPrice")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 计算利润
|
|
|
|
|
|
|
|
BigDecimal profitPrice = childObject.getBigDecimal("originPrice").multiply(productDetail.getBigDecimal("priceDiscount").divide(new BigDecimal(100))); |
|
|
|
|
|
|
|
// 计算子订单支付金额
|
|
|
|
|
|
|
|
BigDecimal childPrice = childObject.getBigDecimal("price").add(profitPrice).setScale(2 , RoundingMode.HALF_UP); |
|
|
|
|
|
|
|
if (childPrice.compareTo(childObject.getBigDecimal("originPrice")) > 0) { |
|
|
|
|
|
|
|
childPrice = childObject.getBigDecimal("originPrice"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (object.getLong("memDiscountId") != null) { |
|
|
|
|
|
|
|
childOrder.setGoodsActualPrice(childObject.getBigDecimal("originPrice")); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
childOrder.setGoodsActualPrice(childPrice); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
childPrice = childPrice.multiply(childObject.getBigDecimal("quantity")); |
|
|
|
|
|
|
|
// 计算总订单实际支付金额
|
|
|
|
|
|
|
|
orderPayPrice = orderPayPrice.add(childPrice); |
|
|
|
|
|
|
|
// 计算市场价金额
|
|
|
|
|
|
|
|
marketPrice = marketPrice.add(childObject.getBigDecimal("originPrice").multiply(childObject.getBigDecimal("quantity"))); |
|
|
|
|
|
|
|
childOrder.setTotalPrice(childPrice); |
|
|
|
|
|
|
|
childOrderList.add(childOrder); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if (object.getInteger("productType") == 3) { |
|
|
|
|
|
|
|
ApiMemberProduct memberProduct = apiMemberProductService.findById(object.getLong("goodsId")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (memberProduct == null) { |
|
|
|
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "当前产品不可购买"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
object.put("productId", memberProduct.getProductId()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 计算实际支付金额
|
|
|
|
|
|
|
|
orderPayPrice = memberProduct.getCostPrice().add(memberProduct.getPrice().multiply(productDetail.getBigDecimal("priceDiscount").divide(new BigDecimal(100)))).setScale(2, RoundingMode.HALF_UP); |
|
|
|
|
|
|
|
if (orderPayPrice.compareTo(memberProduct.getPrice()) > 0) { |
|
|
|
|
|
|
|
orderPayPrice = memberProduct.getPrice(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 计算市场价金额
|
|
|
|
|
|
|
|
marketPrice = memberProduct.getPrice(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HighChildOrder childOrder = new HighChildOrder(); |
|
|
|
|
|
|
|
childOrder.setChildOrderStatus(1); |
|
|
|
|
|
|
|
childOrder.setGoodsType(10); |
|
|
|
|
|
|
|
childOrder.setStoreId(object.getLong("storeCode")); |
|
|
|
|
|
|
|
childOrder.setGoodsId(memberProduct.getId()); |
|
|
|
|
|
|
|
childOrder.setGoodsName(memberProduct.getName()); |
|
|
|
|
|
|
|
childOrder.setSaleCount(1); |
|
|
|
|
|
|
|
childOrder.setGoodsPrice(marketPrice); |
|
|
|
|
|
|
|
if (object.getLong("memDiscountId") != null) { |
|
|
|
|
|
|
|
childOrder.setGoodsActualPrice(marketPrice); |
|
|
|
|
|
|
|
childOrder.setTotalPrice(marketPrice); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
childOrder.setGoodsActualPrice(orderPayPrice); |
|
|
|
|
|
|
|
childOrder.setTotalPrice(orderPayPrice); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
childOrderList.add(childOrder); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return childOrderList; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|