/// <summary> /// 开户并绑定IC卡 /// </summary> /// <param name="merchant">商户信息</param> /// <returns></returns> public static bool CreateAccount(Merchant merchant, out string msg) { bool result = true; // 创建商户 JObject jServiceBody = new JObject(); jServiceBody.Add("name", merchant.Name); jServiceBody.Add("address", merchant.Address); jServiceBody.Add("phoneNumber", merchant.PhoneNo); jServiceBody.Add("personLiable", merchant.PersonInCharge); jServiceBody.Add("status", "N"); jServiceBody.Add("remark", merchant.Remarks); JObject json = new JObject(); json.Add("serviceMethod", "save"); json.Add("serviceName", "com.cygps.dubbo.wasteSorting.ICreditService"); json.Add("serviceBody", jServiceBody); string postData = "data=" + json.ToString(); string rt = PostData(Configs.Server, postData); json = JObject.Parse(rt); if (json.Count == 0) { result = false; msg = "内部错误"; } else if (json["code"].ToString() == "-1") { result = false; msg = json["message"].ToString(); } else if (json["code"].ToString() == "0") { msg = json["message"].ToString(); merchant.ID = json["id"].ToString(); // 绑定卡 //{"where":{"id":100000},"body":{"cardNo":"3546521554","status":"Y"}} JObject jWhere = new JObject(); jWhere.Add("id", merchant.ID); JObject jBody = new JObject(); jBody.Add("cardNo", merchant.ID); jBody.Add("status", "Y"); jServiceBody = new JObject(); jServiceBody.Add("body", jBody); jServiceBody.Add("where", jWhere); json = new JObject(); json.Add("serviceMethod", "update"); json.Add("serviceName", "com.cygps.dubbo.wasteSorting.ICreditService"); json.Add("serviceBody", jServiceBody); postData = "data=" + json.ToString(); rt = PostData(Configs.Server, postData); json = JObject.Parse(rt); if (json.Count == 0) { result = false; msg = "商户已添加,但绑定IC卡错误"; } if (json["code"].ToString() == "-1") { result = false; msg = "商户已添加,但绑定IC卡错误:" + msg; } else if (json["code"].ToString() == "0") { msg = "开卡成功"; } } else { result = false; msg = "未知的错误"; } return(result); }
/// <summary> /// 分页获取卡信息 /// </summary> /// <param name="cardInfo"></param> /// <param name="pagesize"></param> /// <param name="pageindex"></param> /// <returns></returns> public static DataTable GetMerchantList(Merchant cardInfo, int pagesize, int pageindex, out int total) { DataTable dt = GetMerchantTable(); // 发送 //string data={"serviceMethod":"selectByPage","serviceName":"com.cygps.dubbo.wasteSorting.ICreditService","serviceBody":{"name":"哈哈面","status":"Y","_pageSize":10,"_page":1,"_sortField":"credit","_number":-1}} JObject json = new JObject(); JObject jPamarm = new JObject(); if (!string.IsNullOrEmpty(cardInfo.Name)) { jPamarm.Add("*name", cardInfo.Name); } if (cardInfo.Status != CardBindingStatus.X) { jPamarm.Add("status", cardInfo.Status.ToString()); } if (!string.IsNullOrEmpty(cardInfo.PhoneNo)) { jPamarm.Add("*phoneNumber", cardInfo.PhoneNo); } jPamarm.Add("_pageSize", pagesize); // 必要 jPamarm.Add("_page", pageindex); // 必要 jPamarm.Add("_sortField", "credit"); // 排序字段 非必 jPamarm.Add("_number", -1); // 1正序 -1倒序 非必 JToken serviceMethod, serviceName, serviceBody; serviceMethod = "selectByPage"; serviceName = "com.cygps.dubbo.wasteSorting.ICreditService"; serviceBody = jPamarm; json.Add("serviceMethod", serviceMethod); json.Add("serviceName", serviceName); json.Add("serviceBody", serviceBody); string postData = "data=" + json.ToString(); string rt = PostData(Configs.Server, postData); // 接收 // 解析 json = JObject.Parse(rt); if (json.Count == 0 || (int)(json["code"]) == -1) { total = 0; return(dt); } JArray jlist = JArray.Parse(json["array"].ToString()); JObject tempo; JToken jRemark, jCardNo, jCredit; string ts;// 开卡时间戳13位处理成10位 string remark, cardNo; int credit; int j = pagesize * (pageindex - 1); for (int i = 0; i < jlist.Count; i++) { tempo = JObject.Parse(jlist[i].ToString()); if (!tempo.TryGetValue("cardNo", out jCardNo)) { cardNo = ""; } else { cardNo = jCardNo.ToString(); } if (!tempo.TryGetValue("remark", out jRemark)) { remark = string.Empty; } else { remark = jRemark.ToString(); } if (!tempo.TryGetValue("credit", out jCredit)) { credit = 0; } else { credit = int.Parse(jCredit.ToString()); } ts = tempo["_saveTime"].ToString();// 时间戳 ts = ts.Substring(0, ts.Length - 3); dt.Rows.Add(new object[12] { i + j + 1 , tempo["id"].ToString() , cardNo , tempo["name"].ToString() , tempo["status"].ToString() == "Y" ? "已绑定" : "未绑定" , tempo["address"].ToString() , tempo["personLiable"].ToString() , tempo["phoneNumber"].ToString() , GetTime(ts) , credit , "编辑" , remark }); } total = int.Parse(json["total"].ToString()); return(dt); }