|
|
|
@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.hai.common.exception.ErrorCode; |
|
|
|
|
import com.hai.common.exception.ErrorHelp; |
|
|
|
|
import com.hai.common.exception.SysCode; |
|
|
|
|
import com.hai.config.DataUtilConfig; |
|
|
|
|
import com.hai.config.QianZhuConfig; |
|
|
|
|
import com.hai.entity.*; |
|
|
|
|
import com.hai.openApi.config.PriceComputeConfig; |
|
|
|
@ -17,9 +18,7 @@ import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
|
|
@Service("apiOrderCreateHandleService") |
|
|
|
|
public class ApiOrderCreateHandleServiceImpl implements ApiOrderCreateHandleService { |
|
|
|
@ -45,6 +44,9 @@ public class ApiOrderCreateHandleServiceImpl implements ApiOrderCreateHandleServ |
|
|
|
|
@Resource |
|
|
|
|
private OutRechargePriceService rechargePriceService; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private ApiProductService apiProductService; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public ApiOrder oilHandle(JSONObject object) throws Exception { |
|
|
|
|
|
|
|
|
@ -218,16 +220,11 @@ public class ApiOrderCreateHandleServiceImpl implements ApiOrderCreateHandleServ |
|
|
|
|
// 获取下单内容
|
|
|
|
|
JSONObject dataObject = JSONObject.parseObject(object.getString("content")); |
|
|
|
|
|
|
|
|
|
JSONArray dataArray = dataObject.getJSONArray("data"); |
|
|
|
|
|
|
|
|
|
// 查询api商户
|
|
|
|
|
ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 查询折扣比例
|
|
|
|
|
Map<String , Object> mchProductMap = new HashMap<>(); |
|
|
|
|
mchProductMap.put("productType" , object.getString("productType")); |
|
|
|
|
mchProductMap.put("mchId" , object.getString("merchId")); |
|
|
|
|
ApiMchProduct mchProduct = apiMchProductService.findByMap(mchProductMap); |
|
|
|
|
|
|
|
|
|
// 查询肯德基门店菜单
|
|
|
|
|
JSONObject jsonObject = QianZhuConfig.listByStoreCode(dataObject.getString("storeCode")); |
|
|
|
|
JSONArray array = jsonObject.getJSONArray("data"); |
|
|
|
@ -235,36 +232,109 @@ public class ApiOrderCreateHandleServiceImpl implements ApiOrderCreateHandleServ |
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "门店编码错误"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 查询折扣比例
|
|
|
|
|
Map<String, Object> mapProduct = new HashMap<>(); |
|
|
|
|
mapProduct.put("mchId" , object.getString("merchId")); |
|
|
|
|
mapProduct.put("productType" , OrderProductType.PRODUCT_TYPE2.getNumber()); |
|
|
|
|
|
|
|
|
|
ApiMchProduct apiMchProducts = apiMchProductService.findByMap(mapProduct); |
|
|
|
|
|
|
|
|
|
StringBuffer orderItems = new StringBuffer(); |
|
|
|
|
|
|
|
|
|
BigDecimal priceTotal = new BigDecimal(0); |
|
|
|
|
BigDecimal facePrice = new BigDecimal(0); |
|
|
|
|
|
|
|
|
|
Map<String , String> map = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
for (Object o : dataArray) { |
|
|
|
|
JSONObject itemData = (JSONObject) o; |
|
|
|
|
|
|
|
|
|
orderItems.append(itemData.getString("productId")).append("|").append(itemData.getInteger("num")).append(","); |
|
|
|
|
for (Object data : array) { |
|
|
|
|
JSONObject kfcObject = (JSONObject) data; |
|
|
|
|
if (kfcObject.getJSONArray("products") != null) { |
|
|
|
|
for (Object products : kfcObject.getJSONArray("products")) { |
|
|
|
|
JSONObject productsObject = (JSONObject) products; |
|
|
|
|
productsObject.put("taxOriginalPrice" , null); |
|
|
|
|
productsObject.put("taxOriginalTotalPrice" , null); |
|
|
|
|
productsObject.put("price" , priceComputeConfig.computationPriceCost(apiMchProducts.getDiscount() , productsObject.getBigDecimal("originalPrice") , productsObject.getBigDecimal("price"))); |
|
|
|
|
productsObject.put("taxPrice" , null); |
|
|
|
|
|
|
|
|
|
if (productsObject.getJSONArray("specGroups") != null) { |
|
|
|
|
for (Object specGroups : productsObject.getJSONArray("specGroups")) { |
|
|
|
|
JSONObject specGroupsObject = (JSONObject) specGroups; |
|
|
|
|
specGroupsObject.put("taxOriginalPrice" , null); |
|
|
|
|
specGroupsObject.put("taxOriginalTotalPrice" , null); |
|
|
|
|
specGroupsObject.put("price" , priceComputeConfig.computationPriceCost(apiMchProducts.getDiscount() , specGroupsObject.getBigDecimal("originalPrice") , specGroupsObject.getBigDecimal("price"))); |
|
|
|
|
specGroupsObject.put("taxPrice" , null); |
|
|
|
|
JSONObject kfcData = DataUtilConfig.dataFindByKfc(kfcObject , itemData.getString("productId")); |
|
|
|
|
if (kfcData != null) { |
|
|
|
|
if (map.containsKey(itemData.getString("productId"))) { |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
map.put(itemData.getString("productId") , itemData.getString("productId")); |
|
|
|
|
priceTotal = priceTotal.add(priceComputeConfig.computationPriceCost(apiMchProducts.getDiscount() , kfcData.getBigDecimal("originalPrice") , kfcData.getBigDecimal("price")).multiply(itemData.getBigDecimal("num"))); |
|
|
|
|
facePrice = facePrice.add(kfcData.getBigDecimal("originalPrice").multiply(itemData.getBigDecimal("num"))); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
dataObject.put("orderItems" , orderItems); |
|
|
|
|
|
|
|
|
|
// 组装api订单
|
|
|
|
|
ApiOrder apiOrder = new ApiOrder(); |
|
|
|
|
apiOrder.setCreateTime(new Date()); |
|
|
|
|
apiOrder.setTitle(apiMerchants.getMerchantName() + "|" + OrderProductType.PRODUCT_TYPE2.getName() + "|扣款" + priceTotal); |
|
|
|
|
apiOrder.setFacePrice(facePrice); |
|
|
|
|
apiOrder.setCostPrice(priceTotal); |
|
|
|
|
apiOrder.setMchId(object.getString("merchId")); |
|
|
|
|
apiOrder.setMchName(apiMerchants.getMerchantName()); |
|
|
|
|
apiOrder.setUpdateTime(new Date()); |
|
|
|
|
apiOrder.setProductType(object.getInteger("productType")); |
|
|
|
|
apiOrder.setMchOrderNo(object.getString("orderNo")); |
|
|
|
|
apiOrder.setOrderPrice(facePrice); |
|
|
|
|
apiOrder.setNotifyUrl(object.getString("notifyUrl")); |
|
|
|
|
apiOrder.setContent(dataObject.toJSONString()); |
|
|
|
|
return apiOrder; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|
@Override |
|
|
|
|
public ApiOrder starbucksHandle(JSONObject object) throws Exception { |
|
|
|
|
|
|
|
|
|
// 获取下单内容
|
|
|
|
|
JSONObject dataObject = JSONObject.parseObject(object.getString("content")); |
|
|
|
|
|
|
|
|
|
JSONArray dataArray = dataObject.getJSONArray("data"); |
|
|
|
|
|
|
|
|
|
// 查询api商户
|
|
|
|
|
ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); |
|
|
|
|
|
|
|
|
|
// 查询折扣比例
|
|
|
|
|
Map<String, Object> mapProduct = new HashMap<>(); |
|
|
|
|
mapProduct.put("mchId" , object.getString("merchId")); |
|
|
|
|
mapProduct.put("productType" , OrderProductType.PRODUCT_TYPE2.getNumber()); |
|
|
|
|
|
|
|
|
|
ApiMchProduct apiMchProducts = apiMchProductService.findByMap(mapProduct); |
|
|
|
|
|
|
|
|
|
BigDecimal priceTotal = new BigDecimal(0); |
|
|
|
|
BigDecimal facePrice = new BigDecimal(0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (Object starbucksObject : dataArray) { |
|
|
|
|
|
|
|
|
|
JSONObject starbucksData = (JSONObject) starbucksObject; |
|
|
|
|
ApiStarbucksProducts starbucksProducts = apiProductService.findStarbucksProductsByGoodsId(starbucksData.getLong("productId")); |
|
|
|
|
|
|
|
|
|
BigDecimal marketPrice = priceComputeConfig.getStarbucksCpuSizePriceMarket(starbucksProducts , starbucksData.getString("cupSize")); |
|
|
|
|
BigDecimal salesPrice = priceComputeConfig.getStarbucksCpuSizePriceSales(starbucksProducts , starbucksData.getString("cupSize")); |
|
|
|
|
|
|
|
|
|
priceTotal = priceTotal.add(priceComputeConfig.computationPriceCost(apiMchProducts.getDiscount() , marketPrice , salesPrice).multiply(starbucksData.getBigDecimal("num"))); |
|
|
|
|
facePrice = facePrice.add(marketPrice.multiply(starbucksData.getBigDecimal("num"))); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 组装api订单
|
|
|
|
|
ApiOrder apiOrder = new ApiOrder(); |
|
|
|
|
apiOrder.setCreateTime(new Date()); |
|
|
|
|
apiOrder.setTitle(apiMerchants.getMerchantName() + "|" + OrderProductType.PRODUCT_TYPE1.getName() + "|扣款" + priceTotal); |
|
|
|
|
apiOrder.setFacePrice(facePrice); |
|
|
|
|
apiOrder.setCostPrice(priceTotal); |
|
|
|
|
apiOrder.setMchId(object.getString("merchId")); |
|
|
|
|
apiOrder.setMchName(apiMerchants.getMerchantName()); |
|
|
|
|
apiOrder.setUpdateTime(new Date()); |
|
|
|
|
apiOrder.setProductType(object.getInteger("productType")); |
|
|
|
|
apiOrder.setMchOrderNo(object.getString("orderNo")); |
|
|
|
|
apiOrder.setOrderPrice(facePrice); |
|
|
|
|
apiOrder.setNotifyUrl(object.getString("notifyUrl")); |
|
|
|
|
apiOrder.setContent(dataObject.toJSONString()); |
|
|
|
|
return apiOrder; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|