private void loginUser() { Request request = new Request(); request.setUrl(API.API_USER_LOGIN); request.addRequestParam("phone", nameEdit.getText().toString()); request.addRequestParam("password", getEncodedPassWord(passwordEdit.getText().toString())); request.setSaveCookie(true); MissionController.startRequestMission( getActivity(), request, new RequestListener() { @Override protected void onStart() { showLoading("正在登录..."); } @Override protected void onFail(MissionMessage missionMessage) {} @Override protected void onSuccess(RequestMessage requestMessage) { if (!TextUtils.isEmpty(requestMessage.getResult())) { try { JSONObject object = new JSONObject(requestMessage.getResult()); if (object.optString("state").equalsIgnoreCase("SUCCESS")) { Notify.show("登录成功"); Content.saveStringContent( Parameters.CACHE_KEY_MONEY_SN, object.optString("cacheKey")); JSONObject userObject = object.optJSONObject("object"); if (userObject != null) { Content.saveStringContent( Parameters.CACHE_KEY_USER_JSON, userObject.toString()); Content.saveStringContent( Parameters.CACHE_KEY_USER_PASSWORD, getEncodedPassWord(passwordEdit.getText().toString().trim())); User.init(getActivity()); initSignature(); } getActivity().finish(); return; } Notify.show(object.optString("message")); return; } catch (JSONException e) { e.printStackTrace(); } } Notify.show("登录失败"); } @Override protected void onFinish() { hideLoading(); } }); }
private void getFreight() { ControllableMission controllableMission = new ControllableMission() { @Override protected void doing() { for (int i = 0; i < localCars.size(); i++) { Request request = new Request(); request.setUrl(API.API_STORE_SEND_FEE); request.addRequestParam("no", localCars.get(i).getStore().getNo()); String result = MissionController.request(request); if (!TextUtils.isEmpty(result)) { try { JSONObject object = new JSONObject(result); if (object.optString("state").equalsIgnoreCase("SUCCESS")) { ModelStorePostInfo storePostInfo = new ModelStorePostInfo(object.optJSONObject("dataMap")); localCars.get(i).setStorePostInfo(storePostInfo); } } catch (JSONException e) { e.printStackTrace(); } } } LocalCarController.save(localCars); } }; controllableMission.setControllableListener( new ControllableListener() { @Override protected void onStart() { showLoading(); } @Override protected void onFinish() { hideLoading(); refresh(); } }); MissionController.startControllableMission(getActivity(), controllableMission); }
private void getArea() { Request request = new Request(); request.setUrl(API.API_STORE_AREA); if (!TextUtils.isEmpty(currentArea.getId())) { request.addRequestParam("aid", currentArea.getId()); } MissionController.startRequestMission( getActivity(), request, new RequestListener() { @Override protected void onStart() { showLoading(); areas.clear(); areaListAdapter.notifyDataSetChanged(); } @Override protected void onFail(MissionMessage missionMessage) {} @Override protected void onSuccess(RequestMessage requestMessage) { if (!TextUtils.isEmpty(requestMessage.getResult())) { try { JSONObject object = new JSONObject(requestMessage.getResult()); if (object.optString("state").equalsIgnoreCase("SUCCESS")) { JSONArray array = object.optJSONArray("dataList"); if (array != null) { for (int i = 0; i < array.length(); i++) { ModelArea area = new ModelArea(array.getJSONObject(i)); areas.add( new ModelStoreArea( area.getId(), area.getValuename(), area.getAreaType().getId())); } if (!areas.isEmpty()) { areaListAdapter.notifyDataSetChanged(); if (areas.size() == 1) { if (areas.get(0).getId().equals("3253")) { selectArea(areas.get(0)); } } return; } } Intent intent = new Intent(); intent.putExtra("id", currentArea.getId()); intent.putExtra("name", getSelectedAreaName()); getActivity().setResult(23, intent); getActivity().finish(); } } catch (JSONException e) { e.printStackTrace(); } } } @Override protected void onFinish() { hideLoading(); } }); }
/** * 添加本地产品订单 * * @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(); } }); }