|
|
@ -284,6 +284,264 @@ public class ApiOpenServiceImpl implements ApiOpenService { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
@Transactional(rollbackFor=Exception.class,isolation = Isolation.SERIALIZABLE,propagation= Propagation.REQUIRES_NEW) |
|
|
|
|
|
|
|
public void createOrder(JSONObject object , ApiMerchants apiMerchants) throws Exception { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // 定义订单
|
|
|
|
|
|
|
|
// HighOrder highOrder = new HighOrder();
|
|
|
|
|
|
|
|
// highOrder.setMerchId(apiMerchants.getMchId());
|
|
|
|
|
|
|
|
// highOrder.setWhetherRebate(false);
|
|
|
|
|
|
|
|
// highOrder.setMemPhone(apiMerchants.getPhone());
|
|
|
|
|
|
|
|
// highOrder.setMemName(apiMerchants.getMerchantName());
|
|
|
|
|
|
|
|
// highOrder.setMemId(apiMerchants.getId());
|
|
|
|
|
|
|
|
// highOrder.setCreateTime(new Date());
|
|
|
|
|
|
|
|
// highOrder.setOrderStatus(1);
|
|
|
|
|
|
|
|
// highOrder.setProductType(object.getInteger("productType"));
|
|
|
|
|
|
|
|
// highOrder.setPayType(OrderPayTypeEnum.type8.getType());
|
|
|
|
|
|
|
|
// highOrder.setOrderNo("HF" + DateUtil.date2String(new Date(),"yyyyMMddHHmmss") + IDGenerator.nextId(5));
|
|
|
|
|
|
|
|
// highOrderMapper.insert(highOrder);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // 订单总金额
|
|
|
|
|
|
|
|
// BigDecimal marketPriceTotal = new BigDecimal(0);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // 定义下单json对象
|
|
|
|
|
|
|
|
// JSONObject jsonObject;
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // 获取token
|
|
|
|
|
|
|
|
// JSONObject userToken = QianZhuConfig.getTokenV2(apiMerchants.getId().toString(), apiMerchants.getMerchantName(), apiMerchants.getPhone());
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if (!userToken.getBoolean("success")) {
|
|
|
|
|
|
|
|
// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, userToken.getString("message"));
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // 1 星巴克 2 肯德基 3 会员充值
|
|
|
|
|
|
|
|
// if (object.getInteger("productType") == 1) {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // 判断当前商户是否有权限下单
|
|
|
|
|
|
|
|
// if (!secConfigService.isConfig("STARBUCKS_CONFIG" , object.getString("merchId"))) {
|
|
|
|
|
|
|
|
// throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "当前帐户无权限查询!");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
// List.add(JSON.toJSONString(contentMap));
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // 下单
|
|
|
|
|
|
|
|
// jsonObject = QianZhuConfig.starbucksOrders(apiMerchants.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.setOrderId(highOrder.getId());
|
|
|
|
|
|
|
|
// childOrder.setChildOrdeStatus(1);
|
|
|
|
|
|
|
|
// childOrder.setMemId(highOrder.getMemId());
|
|
|
|
|
|
|
|
// childOrder.setGoodsType(9);
|
|
|
|
|
|
|
|
// childOrder.setStoreId(object.getLong("storeCode"));
|
|
|
|
|
|
|
|
// childOrder.setGoodsId(childObject.getLong("id"));
|
|
|
|
|
|
|
|
// 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 childPrice = childObject.getBigDecimal("marketPrice");
|
|
|
|
|
|
|
|
// childOrder.setGoodsActualPrice(childPrice);
|
|
|
|
|
|
|
|
// // 计算市场价金额
|
|
|
|
|
|
|
|
// childOrder.setTotalPrice(childPrice.multiply(childObject.getBigDecimal("quantity")));
|
|
|
|
|
|
|
|
// marketPriceTotal = marketPriceTotal.add(childOrder.getTotalPrice());
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// highChildOrderMapper.insert(childOrder);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// // 拼接json对象
|
|
|
|
|
|
|
|
// object.put("sourceType" , 5);
|
|
|
|
|
|
|
|
// object.put("content" , apiMerchants.getMerchantName() + "|" + "星巴克下单" + "|扣款" + marketPriceTotal);
|
|
|
|
|
|
|
|
// }else if (object.getInteger("productType") == 2) {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // 判断当前商户是否有肯德基下单权限
|
|
|
|
|
|
|
|
// if (!secConfigService.isConfig("KFC_CONFIG" , object.getString("merchId"))) {
|
|
|
|
|
|
|
|
// throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "当前帐户无权限查询!");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// // 判断就餐方式
|
|
|
|
|
|
|
|
// 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"), apiMerchants.getId().toString());
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // 判断下单是否成功
|
|
|
|
|
|
|
|
// 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.setOrderId(highOrder.getId());
|
|
|
|
|
|
|
|
// childOrder.setChildOrdeStatus(1);
|
|
|
|
|
|
|
|
// childOrder.setGoodsType(4);
|
|
|
|
|
|
|
|
// childOrder.setMemId(highOrder.getMemId());
|
|
|
|
|
|
|
|
// childOrder.setExt6(object.getString("storeCode"));
|
|
|
|
|
|
|
|
// childOrder.setGoodsId(childObject.getLong("productId"));
|
|
|
|
|
|
|
|
// 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 childPrice = childObject.getBigDecimal("originPrice");
|
|
|
|
|
|
|
|
// childOrder.setGoodsActualPrice(childPrice);
|
|
|
|
|
|
|
|
// // 计算市场价金额
|
|
|
|
|
|
|
|
// childOrder.setTotalPrice(childPrice.multiply(childObject.getBigDecimal("quantity")));
|
|
|
|
|
|
|
|
// marketPriceTotal = marketPriceTotal.add(childOrder.getTotalPrice());
|
|
|
|
|
|
|
|
// highChildOrderMapper.insert(childOrder);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// // 拼接json对象
|
|
|
|
|
|
|
|
// object.put("sourceType" , 4);
|
|
|
|
|
|
|
|
// object.put("content" , apiMerchants.getMerchantName() + "|" + "肯德基下单" + "|扣款" + marketPriceTotal);
|
|
|
|
|
|
|
|
// } else if (object.getInteger("productType") == 3) {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // 判断是否有会员充值下单权限
|
|
|
|
|
|
|
|
// if (!secConfigService.isConfig("MEMBER_RECHARGE_CONFIG" , object.getString("merchId"))) {
|
|
|
|
|
|
|
|
// throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOT_AUTHORIZED, "当前帐户无权限查询!");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // 获取会员充值
|
|
|
|
|
|
|
|
// ApiMemberProduct memberProduct = apiMemberProductService.findById(object.getLong("goodsId"));
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if (memberProduct == null) {
|
|
|
|
|
|
|
|
// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "当前产品不可购买");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// object.put("productId", memberProduct.getProductId());
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// HighChildOrder childOrder = new HighChildOrder();
|
|
|
|
|
|
|
|
// childOrder.setOrderId(highOrder.getId());
|
|
|
|
|
|
|
|
// childOrder.setChildOrdeStatus(1);
|
|
|
|
|
|
|
|
// childOrder.setGoodsType(10);
|
|
|
|
|
|
|
|
// childOrder.setStoreId(object.getLong("storeCode"));
|
|
|
|
|
|
|
|
// childOrder.setGoodsId(memberProduct.getId());
|
|
|
|
|
|
|
|
// childOrder.setGoodsName(memberProduct.getName());
|
|
|
|
|
|
|
|
// childOrder.setSaleCount(1);
|
|
|
|
|
|
|
|
// childOrder.setMemId(highOrder.getMemId());
|
|
|
|
|
|
|
|
// childOrder.setGoodsPrice(memberProduct.getPrice());
|
|
|
|
|
|
|
|
// childOrder.setGoodsActualPrice(memberProduct.getPrice());
|
|
|
|
|
|
|
|
// // 计算市场价金额
|
|
|
|
|
|
|
|
// childOrder.setTotalPrice(memberProduct.getPrice());
|
|
|
|
|
|
|
|
// marketPriceTotal = marketPriceTotal.add(childOrder.getTotalPrice());
|
|
|
|
|
|
|
|
// highChildOrderMapper.insert(childOrder);
|
|
|
|
|
|
|
|
// object.put("sourceType" , 6);
|
|
|
|
|
|
|
|
// object.put("content" , apiMerchants.getMerchantName() + "|" + "第三方会员充值下单" + "|扣款" + marketPriceTotal);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// // 当前账号余额是否可以充值当前金额
|
|
|
|
|
|
|
|
// if (apiMerchants.getAmounts().compareTo(marketPriceTotal) < 0) {
|
|
|
|
|
|
|
|
// throw ErrorHelp.genException(SysCode.System, ErrorCode.INSUFFICIENT_BALANCE);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// highOrder.setTotalPrice(marketPriceTotal);
|
|
|
|
|
|
|
|
// highOrder.setPayPrice(marketPriceTotal);
|
|
|
|
|
|
|
|
// highOrder.setPayRealPrice(marketPriceTotal);
|
|
|
|
|
|
|
|
// highOrder.setPayablePrice(marketPriceTotal);
|
|
|
|
|
|
|
|
// ApiAmountRecord apiAmountRecord = apiMerchantAmount(highOrder , apiMerchants , object);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// highOrder.setOrderStatus(2);
|
|
|
|
|
|
|
|
// highOrder.setPayTime(new Date());
|
|
|
|
|
|
|
|
// highOrder.setPaySerialNo("22" + DateUtil.date2String(new Date(), "yyyyMMddHHmmss") + IDGenerator.nextId(5));
|
|
|
|
|
|
|
|
// highOrderMapper.updateByPrimaryKey(highOrder);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // 更新子订单状态
|
|
|
|
|
|
|
|
// List<HighChildOrder> childOrderList = highOrderService.getChildOrderByOrder(highOrder.getId());
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// for (HighChildOrder highChildOrder : childOrderList) {
|
|
|
|
|
|
|
|
// highChildOrder.setChildOrdeStatus(2);
|
|
|
|
|
|
|
|
// highChildOrderMapper.updateByPrimaryKey(highChildOrder);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // 插入订单记录
|
|
|
|
|
|
|
|
// ApiOrderRecord apiOrderRecordPost = new ApiOrderRecord();
|
|
|
|
|
|
|
|
// apiOrderRecordPost.setStatus(103);
|
|
|
|
|
|
|
|
// apiOrderRecordPost.setOrderNo(highOrder.getOrderNo());
|
|
|
|
|
|
|
|
// apiOrderRecordPost.setSourceOrderNo(apiAmountRecord.getSourceOrderNo());
|
|
|
|
|
|
|
|
// apiOrderRecordPost.setCreateTime(new Date());
|
|
|
|
|
|
|
|
// apiOrderRecordPost.setMchId(apiMerchants.getMchId());
|
|
|
|
|
|
|
|
// apiOrderRecordPost.setOrderId(highOrder.getId());
|
|
|
|
|
|
|
|
// apiOrderRecordPost.setGoodsId(apiMerchants.getMchId());
|
|
|
|
|
|
|
|
// apiOrderRecordPost.setNotifyUrl(object.getString("notifyUrl"));
|
|
|
|
|
|
|
|
// apiOrderRecordPost.setUpdateTime(new Date());
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// apiOrderRecordService.insertOrderRecord(apiOrderRecordPost);
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private ApiAmountRecord apiMerchantAmount(HighOrder highOrder , ApiMerchants apiMerchants , JSONObject object) throws Exception { |
|
|
|
private ApiAmountRecord apiMerchantAmount(HighOrder highOrder , ApiMerchants apiMerchants , JSONObject object) throws Exception { |
|
|
|
// 插入金额记录
|
|
|
|
// 插入金额记录
|
|
|
|
// 变更前金额
|
|
|
|
// 变更前金额
|
|
|
|