Beispiel #1
0
  private void AddOrUpdateProduct(
      String qrCode, Map<String, Object> params, final ManagerCallBack<String> callBack) {
    if (qrCode != null && params != null) {
      StringBuilder fields = new StringBuilder();
      for (String key : params.keySet()) {
        fields.append(key).append(",");
      }
      fields.delete(fields.length() - 1, fields.length());
      params.put("fields", fields.toString());
    }
    String url;
    if (qrCode == null) {
      url =
          HttpApi.PRODUCT_ADD_PRODUCT.replaceFirst(
              ":sid", String.valueOf(MyApplication.getStoreid()));
    } else {
      url =
          HttpApi.PRODUCT_UPDATE_INFO
              .replaceFirst(":sid", String.valueOf(MyApplication.getStoreid()))
              .replaceFirst(":qr", String.valueOf(qrCode));
      MyLog.e(qrCode, qrCode);
    }
    HttpUtils.getInstance()
        .sendPostRequest(
            url,
            1,
            params,
            new HttpClientUtilCallBack<String>() {
              @Override
              public void onSuccess(String url, long flag, String returnContent) {
                super.onSuccess(url, flag, returnContent);
                addProductParams = null;
                JSONObject jsonObject;
                try {
                  jsonObject = new JSONObject(returnContent);
                  int code = jsonObject.getJSONObject(Config.STATUS).getInt(Config.CODE);
                  if (code == HttpCode.SUCCESS) {
                    if (null != callBack) {
                      callBack.onSuccess(null);
                    }
                  } else {
                    if (null != callBack) {
                      callBack.onFailure(
                          code, jsonObject.getJSONObject(Config.STATUS).getString(Config.MSG));
                    }
                  }
                } catch (JSONException e) {
                  e.printStackTrace();
                }
              }

              @Override
              public void onFailure(String url, long flag, ErrorCode errorCode) {
                super.onFailure(url, flag, errorCode);
                addProductParams = null;
                if (null != callBack) {
                  callBack.onFailure(errorCode.code(), errorCode.msg());
                }
              }
            });
  }
Beispiel #2
0
  /**
   * 添加商品或修改商品信息
   *
   * @param isAdd 新增商品时,为true
   * @param selectedImageList 修改商品照片时,选择的本地照片列表
   * @param productPic 商品原有照片列表
   * @param product_name 商品名称,必填
   * @param product_brand 商品品牌,必填
   * @param product_bar 条形码,选填
   * @param product_desc 商品描述,可选
   * @param product_retail_price 商品价格,单位:分,必填
   * @param product_retail_apr 商品折扣
   * @param product_original_price 商品原价
   * @param product_unit 商品单位,必填
   * @param stock_cnt 库存剩余量,选填
   * @param is_recommend 是否是店长推荐的商品,选填
   * @param status 是否启用商品
   * @param product_tag 商品标签,选填
   * @param callBack
   */
  public void updateOrAdd(
      final boolean isAdd,
      ArrayList<GalleryPicEntity> selectedImageList,
      final ArrayList<String> productPic,
      String product_name,
      String product_brand,
      final String product_qr,
      String product_bar,
      String product_desc,
      long product_retail_price,
      String product_retail_apr,
      int product_category_id,
      long product_original_price,
      int product_type,
      String product_unit,
      double stock_cnt,
      boolean is_recommend,
      boolean status,
      String product_tag,
      final ManagerCallBack<String> callBack) {
    addProductParams = new HashMap<String, Object>();
    if (product_name == null || product_name.isEmpty()) {
      return;
    }
    addProductParams.put("product_name", product_name);
    if (product_brand != null && !product_brand.isEmpty()) {
      addProductParams.put("product_brand", product_brand);
    }
    if (product_bar != null && !product_bar.isEmpty()) {
      addProductParams.put("product_bar", product_bar);
    }
    if (product_desc != null && !product_desc.isEmpty()) {
      addProductParams.put("product_desc", product_desc);
    }
    addProductParams.put("product_category", product_category_id);
    addProductParams.put("product_retail_price", product_retail_price);
    addProductParams.put("product_original_price", product_original_price);
    addProductParams.put("product_retail_apr", product_retail_apr);
    addProductParams.put("product_type", product_type);
    if (product_unit == null || product_unit.isEmpty()) {
      return;
    }
    addProductParams.put("product_unit", product_unit);
    if (stock_cnt != 0) {
      addProductParams.put("stock_cnt", stock_cnt);
    }
    // 1,推荐,2不推荐
    addProductParams.put("is_recommend", is_recommend ? 1 : 2);
    // 1,推荐,2不推荐
    addProductParams.put("status", status ? 1 : 2);
    if (product_tag != null && !product_tag.isEmpty()) {
      addProductParams.put("product_tag", product_tag);
    }
    if (selectedImageList != null && selectedImageList.size() > 1) {
      MyLog.e("imagelist", selectedImageList.toString());
      String[] path = new String[selectedImageList.size() - 1];
      for (int i = 0; i < selectedImageList.size() - 1; i++) {
        path[i] = selectedImageList.get(i).imagePath;
      }
      new ImageUpLoadManager()
          .upLoadImage(
              path,
              new ManagerCallBack<List<String>>() {
                @Override
                public void onSuccess(List<String> returnContent) {
                  super.onSuccess(returnContent);
                  StringBuilder qiniuRequest = new StringBuilder();
                  for (int i = 0; i < returnContent.size(); i++) {
                    qiniuRequest.append(returnContent.get(i));
                    qiniuRequest.append(",");
                  }
                  if (productPic != null) {
                    for (int i = 0; i < productPic.size(); i++) {
                      qiniuRequest.append(productPic.get(i));
                      qiniuRequest.append(",");
                    }
                  }
                  qiniuRequest.delete(qiniuRequest.length() - 1, qiniuRequest.length());

                  addProductParams.put("product_avatar", qiniuRequest.toString());
                  AddOrUpdateProduct(isAdd ? null : product_qr, addProductParams, callBack);
                }

                @Override
                public void onFailure(int code, String msg) {
                  if (null != callBack) {
                    callBack.onFailure(code, msg);
                  }
                };
              });
    } else {
      if (productPic != null) {
        StringBuilder qiniuRequest = new StringBuilder();
        for (int i = 0; i < productPic.size(); i++) {
          qiniuRequest.append(productPic.get(i));
          qiniuRequest.append(",");
        }
        qiniuRequest.delete(qiniuRequest.length() - 1, qiniuRequest.length());

        addProductParams.put("product_avatar", qiniuRequest.toString());
      } else {
        addProductParams.put("product_avatar", "");
      }
      AddOrUpdateProduct(isAdd ? null : product_qr, addProductParams, callBack);
    }
  }