private void confirmOrder() { if (totalMoney <= 0) { Notify.show("商品信息有误"); } else if (addressFragment.getAddress() == null) { Notify.show("收货人地址有误"); } else { addLocalGoodsOrder(); } }
/** * 添加本地产品订单 * * @author Tiger @Result {"message":"ok","state":"SUCCESS","cacheKey":null,"dataList":[{ * "servicetelephone" :"028-12345678","deliveryType":"送货上门","paymentType" :"1","orderDate" * :"2015-10-16","servicename":"易田测试加盟店四","productInfo": * "[{\"spname\":\"产品组-测试产品\",\"price\":\"33.0\",\"Amount\":\"66.0\",\"num\":\"2\"}]" * ,"ordernumber":"YT5966059962","postagePrice":"满50.0包邮", "orderPrice" * :"66.0","servicePhone":"13228116626"}],"totalCount":1, "dataMap":{},"object":null} */ private void addLocalGoodsOrder() { Request request = new Request(); request.setUrl(API.API_LOCAL_BUSINESS_GOODS_ORDER_ADD); request.addRequestParam("serviceProvidID", Store.getStore().getStoreId()); request.addRequestParam("memberAccount", User.getUser().getUseraccount()); request.addRequestParam("customerName", addressFragment.getAddress().getPersonName()); request.addRequestParam("customerPhone", addressFragment.getAddress().getPhone()); request.addRequestParam("retailOrderPrice", totalMoney + ""); JSONArray data = new JSONArray(); JSONArray deliveryInfo = new JSONArray(); try { for (int i = 0; i < localCars.size(); i++) { JSONObject deliveryInfoObject = new JSONObject(); deliveryInfoObject.put("supplyId", localCars.get(i).getStore().getId()); deliveryInfoObject.put("deliveryType", localCars.get(i).getDiliver().getName()); switch (localCars.get(i).getDiliver().getType()) { case ModelDiliver.TYPE_HOME: deliveryInfoObject.put( "address", addressFragment.getAddress().getAreaAddress() + addressFragment.getAddress().getDetailedAddress()); break; case ModelDiliver.TYPE_SELF: deliveryInfoObject.put("address", localCars.get(i).getStore().getServiceaddress()); break; default: break; } deliveryInfoObject.put("paymentType", localCars.get(i).getPayment().getType()); deliveryInfo.put(deliveryInfoObject); for (int j = 0; j < localCars.get(i).getCarGoods().size(); j++) { JSONObject dataObject = new JSONObject(); ModelLocalCarGoods dataGoods = localCars.get(i).getCarGoods().get(j); dataObject.put("retailProductManagerID", dataGoods.getGoods().getId()); dataObject.put("orderType", "0"); dataObject.put("shopNum", dataGoods.getGoodsCount()); dataObject.put("productPrice", dataGoods.getGoods().getRetailPrice()); data.put(dataObject); } } } catch (JSONException e) { e.printStackTrace(); } request.addRequestParam("data", data.toString()); request.addRequestParam("deliveryInfo", deliveryInfo.toString()); MissionController.startRequestMission( getActivity(), request, new RequestListener() { @Override protected void onStart() { showLoading("下单中,请稍候..."); } @Override protected void onFail(MissionMessage missionMessage) { Notify.show("下单失败," + missionMessage.getMessage()); } @Override protected void onSuccess(RequestMessage requestMessage) { if (!TextUtils.isEmpty(requestMessage.getResult())) { JSONObject object; try { object = new JSONObject(requestMessage.getResult()); if (object.optString("state").equalsIgnoreCase("SUCCESS")) { LocalCarController.deleteSelectedGoods(); Notify.show("下单成功"); JSONArray orderArray = object.optJSONArray("dataList"); if (orderArray != null) { double payPrice = 0; ArrayList<String> orderNumbers = new ArrayList<String>(); for (int i = 0; i < orderArray.length(); i++) { ModelLocalGoodsOrderResult orderResult = new ModelLocalGoodsOrderResult(orderArray.optJSONObject(i)); if (orderResult.getPaymentType() == ModelPayment.TYPE_ONLINE) { orderNumbers.add(orderResult.getOrdernumber()); payPrice += orderResult.getOrderPrice(); } } if (orderNumbers.size() > 0) { if (payPrice > 0) { payMoney(orderNumbers, payPrice, PayFragment.ORDER_TYPE_LP); getActivity().finish(); return; } } } showOrder(PayFragment.ORDER_TYPE_LP); getActivity().finish(); return; } else { hideLoading(); Notify.show(object.optString("message")); return; } } catch (JSONException e) { hideLoading(); Notify.show("下单失败"); e.printStackTrace(); return; } } else { hideLoading(); Notify.show("下单失败"); } } @Override protected void onFinish() { hideLoading(); } }); }