


superdesk-app-services-flashdeliver/src/main/java/cn/superdesk/app/flashdeliver/service/WxOrderService.java

```java
/**
     * 获取订单号
     *
     * @param saleParam
     * @param headerParam
     * @param param
     * @param timestamp
     * @param nonceStr
     * @param amount
     * @return
     */
    private String getOrdrIdAndSendMsg(SaleParam saleParam, HeaderParam headerParam, OrderParam param, Long timestamp
            , String nonceStr, BigDecimal amount) throws Exception {


        JSONArray jsonGoods = new JSONArray();
        JSONObject jsonGood = null;


        List<ProductVO> lstProduct = Lists.newArrayList();

        for (ProductParam productParam : saleParam.getProductList()) {
            jsonGood = new JSONObject();
            ProductEntity productEntity = productEntityMapper.selectByPrimaryKey(productParam.getProductId());
            //amount.add(productEntity.getPrice());//要算折后价
            jsonGood.put("productId",productEntity.getId());
            jsonGood.put("goods_name", String.format("%s_%d", productEntity.getProductName(), productEntity.getId()));
            jsonGood.put("quantity", productParam.getQuantity());
            jsonGood.put("price", productEntity.getPrice());
            jsonGood.put("unit", productEntity.getUnit());
            //jsonGood.put("cost_price", new BigDecimal("0"));
            jsonGood.put("cost_price", productEntity.getCostPrice()==null?BigDecimal.ZERO:productEntity.getCostPrice());//增加同步成本价 by qzy
            jsonGood.put("goods_params", "");
            jsonGoods.add(jsonGood);


            //add by qzy
            ProductVO productVO = new ProductVO();
            BeanUtils.copyProperties(productEntity,productVO);
            productVO.setOriginPrice(productVO.getPrice());
            lstProduct.add(productVO);

        }

        //楼闪送需要传套价 by qzy
        this.setPriceOrderDetail(param, jsonGoods, lstProduct);

        //套价基础上算总价
        BigDecimal totalAmount = BigDecimal.ZERO;
        //amount=jsonGoods.stream().map(obj->((JSONObject)obj).getBigDecimal("price")).reduce(BigDecimal.ZERO, BigDecimal::add);
        for(int k=0;k<jsonGoods.size();k++){
            JSONObject obj = (JSONObject)jsonGoods.get(k);
            totalAmount = totalAmount.add(obj.getBigDecimal("price").multiply(obj.getBigDecimal("quantity")).setScale(2,BigDecimal.ROUND_HALF_UP));
        }
        totalAmount = totalAmount.add(param.getDeliveryAmount());//在加配送费

        //套价基础上算成本价
        BigDecimal totalCostAmount = BigDecimal.ZERO;
        for(int c=0;c<jsonGoods.size();c++){
            JSONObject obj = (JSONObject)jsonGoods.get(c);
            //totalCostAmount = totalCostAmount.add(obj.getBigDecimal("cost_price").multiply(obj.getBigDecimal("getQuantity")).setScale(2,BigDecimal.ROUND_HALF_UP));

            BigDecimal costPrice=obj.getBigDecimal("cost_price");
            Integer quantity=obj.getInteger("quantity");
            if(null!=costPrice && costPrice.compareTo(BigDecimal.ZERO) >= 0){//不为空 且大于等于0

                BigDecimal tempCostPrice=costPrice.multiply(BigDecimal.valueOf(quantity));
                totalCostAmount=totalCostAmount.add(tempCostPrice.setScale(2,BigDecimal.ROUND_HALF_UP));
            }else{
                totalCostAmount=null;//有一个没有配置成本价 整体成本价为空
                break;
            }

        }


        JSONObject jsonParam = new JSONObject();
        jsonParam.put("version", "1.0");
        jsonParam.put("timestamp", String.valueOf(timestamp));
        jsonParam.put("charset", "utf-8");
        jsonParam.put("nonce_str", nonceStr);



        String sign = SignUtil.makeSign(SignUtil.buildParam(jsonParam));

        jsonParam.put("order_type", "闪送订单");
        jsonParam.put("service_no", "LNSS");
        if (StringUtils.isNotBlank(param.getEnterprise()) && param.getEnterpriseId() != null) {
            jsonParam.put("purchase_virt", String.format("%s_%d", param.getEnterprise(), param.getEnterpriseId()));
        } else {
            jsonParam.put("purchase_virt", "");
        }

        jsonParam.put("purchase_user", String.format("%s_%d", headerParam.getUserName(), headerParam.getUserId()));
        jsonParam.put("settlement_type", "");
        jsonParam.put("sale", String.format("%s_%d", saleParam.getSaleName(), saleParam.getSaleId()));
        jsonParam.put("amount", totalAmount);
        jsonParam.put("cost_amount",totalCostAmount);
        jsonParam.put("transport_amount", param.getDeliveryAmount());//配送费
        jsonParam.put("payment_type", param.getPaymentType() + 1);
        jsonParam.put("pay_state", PayStatusEnum.NO_SALE.getKey());
        if (param.getPaymentType().equals(PayTypeEnum.NOW_SALE.getKey())) {
            jsonParam.put("order_state", OrderStatusEnum.NO_SALE.getKey());
            jsonParam.put("order_state_name", OrderStatusEnum.NO_SALE.getDesc());
        } else {
            jsonParam.put("order_state", OrderStatusEnum.SALE.getKey());
            jsonParam.put("order_state_name", OrderStatusEnum.SALE.getDesc());
        }
        jsonParam.put("appraise_state", 2);
        jsonParam.put("source_channel", 1);
        jsonParam.put("project_id", param.getProjectId());
        jsonParam.put("user_name", headerParam.getUserName());
        jsonParam.put("user_id", headerParam.getUserId());
        jsonParam.put("user_type", 1);
        jsonParam.put("out_sn", "");
        jsonParam.put("other_params", "");
        jsonParam.put("goods", jsonGoods);
        jsonParam.put("sign", sign);

        logger.info(String.format("sendOrderBody[调用统一订单请求参数]:%s", jsonParam.toJSONString()));

        JSONObject jsonResult = HttpClientUtils.httpPost(config.getOrder(), jsonParam);

        if (jsonResult.getString("code").equals("200")) {
            return jsonResult.getString("data");
        }

        logger.info(String.format("sendOrder[调用统一订单返回结果]:%s", jsonResult.toJSONString()));
        return null;
    }
```