@Override protected void getData() { Request<JSONObject> request = new NyppJsonRequest(ServerConfig.QUERY_DEFAULT_ADDRESS); Map<String, String> postData = new HashMap<String, String>(); postData.put("sign", TApplication.getInstance().getUserSign()); postData.put("memberNo", TApplication.getInstance().getMemberId()); request.setRequestBody(new Gson().toJson(postData)); CallServer.getRequestInstance() .add( context, 0, request, new HttpListener<JSONObject>() { @Override public void onSucceed(int what, Response<JSONObject> response) { JSONObject result = response.get(); if ("200".equals(result.optString("status"))) { CommonResult<AddressBean> addressBean = CommonResult.fromJson(result.toString(), AddressBean.class); addrData = addressBean.getData(); if (addrData != null) { setAddr(); } } } @Override public void onFailed( int what, String url, Object tag, Exception exception, int responseCode, long networkMillis) {} }, false, true); }
private void submitOrders() { if (addrData == null) { ToastUtil.show("请您去选择收货地址"); return; } Request<JSONObject> request = new NyppJsonRequest(ServerConfig.SUBMIT_ORDERS); JSONObject postJson = null; try { postJson = new JSONObject(); postJson.put("sign", TApplication.getInstance().getUserSign()); postJson.put("memberId", TApplication.getInstance().getMemberId()); postJson.put("contactName", addrData.name); // 姓名 postJson.put("contactPhone", addrData.mobile); postJson.put("province", addrData.provinceId); postJson.put("city", addrData.cityId); postJson.put("district", addrData.districtId); postJson.put("address", addrData.address); postJson.put("message", msgEt.getText().toString()); postJson.put("orderAmount", allMoney); postJson.put("logisticsFees", logistics); postJson.put("discountAmount", 0); // 优惠金额 JSONArray array = new JSONArray(); for (GoodsCartBean cartBean : cartList) { JSONObject object = new JSONObject(); object.put("cartId", ""); object.put("productId", cartBean.pid); JSONArray sukArray = new JSONArray(); for (GoodsCartSukBean sukBean : cartBean.sukList) { JSONObject sukobject = new JSONObject(); sukobject.put("sukId", sukBean.sukId); sukobject.put("number", sukBean.quantity); sukobject.put("cartDetailId", sukBean.detailId); sukArray.put(sukobject); } object.put("sukList", sukArray); array.put(object); } postJson.put("productIds", array); } catch (Exception e) { return; } request.setRequestBody(postJson.toString()); CallServer.getRequestInstance() .add( context, 0, request, new HttpListener<JSONObject>() { @Override public void onSucceed(int what, Response<JSONObject> response) { JSONObject result = response.get(); // 响应结果 if ("200".equals(result.optString("status"))) { Intent intent = new Intent(context, PayModeActivity.class); intent.putExtra("orderId", result.optString("data")); // 订单编号 intent.putExtra("orderMoney", allMoney); // 订单价格 startActivityForResult(intent, SELECT_ADDR); EventBus.getDefault().post("getOrderData"); } else { String resultStr = result.optString("declare", "定单提交失败"); ToastUtil.show(resultStr); } } @Override public void onFailed( int what, String url, Object tag, Exception exception, int responseCode, long networkMillis) {} }, false, true); }