/// <summary> /// 把购物车添加到订单 /// </summary> void setAddOrder() { string uname = string.Empty; string uphone = string.Empty; string address = string.Empty; string payway = string.Empty; string carryway = string.Empty; string countcost = string.Empty; string leavemsg = string.Empty; string zipcode = string.Empty; string num = string.Empty; #region --------------获取请求信息--------------- if (Request["num"] != null && Request["num"] != "") { num = Request["num"]; } if (Request["uname"] != null && Request["uname"] != "") { uname = Common.Common.NoHtml(Request["uname"]); } if (Request["uphone"] != null && Request["uphone"] != "") { uphone = Common.Common.NoHtml(Request["uphone"]); } if (Request["address"] != null && Request["address"] != "") { address = Request["address"]; } if (Request["payway"] != null && Request["payway"] != "") { payway = Common.Common.NoHtml(Request["payway"]); } if (Request["carryway"] != null && Request["carryway"] != "") { carryway = Common.Common.NoHtml(Request["carryway"]); } if (Request["countcost"] != null && Request["countcost"] != "") { countcost = Common.Common.NoHtml(Request["countcost"]); } if (Request["leavemsg"] != null && Request["leavemsg"] != "") { leavemsg = Common.Common.NoHtml(Request["leavemsg"]); } if (Request["zipcode"] != null && Request["zipcode"] != "") { zipcode = Common.Common.NoHtml(Request["zipcode"]); } #endregion if (customid.Trim() != null && customid.Trim() != "") { MSShoppingCartDAL cartDal = new MSShoppingCartDAL(); MSProductOrderDAL OrderDal = new MSProductOrderDAL(); if (OrderDal.ExistOrderByUID(customid, strpid)) { Response.Write("{\"error\":true,\"exist\":true}"); } else { try { string strOrdernum = cartDal.SubOrder(customid, uname, uphone, leavemsg, address, zipcode, strpid, countcost, num, mid); if (strOrdernum != null && strOrdernum != "") { strSiteCode = "VYIGO"; MSOrderLogDAL.AddMSOrderLog("客户【" + customid + "】下单成功,订单号为【" + strOrdernum + "】"); MSProductDAL productDal = new MSProductDAL(); string pnam = string.Empty; if (strpid != null && strpid != "") { pnam = productDal.GetMSProductVaueByID("Ptitle", strpid).ToString(); } #region -发消息到店铺注册用户 string p_uid = string.Empty; string p_openid = string.Empty; if (strpid != null && strpid != "") { try { p_uid = productDal.GetMSProductVaueByID("CustomerID", strpid).ToString(); } catch (Exception) { } } if (p_uid != null && p_uid != "") { MSCustomersDAL P_UDal = new MSCustomersDAL(); try { p_openid = P_UDal.GetCustomerValueByID("OpenID", p_uid).ToString(); } catch (Exception) { } } if (p_openid != null && p_openid != "" && strSiteCode != null && strSiteCode != "") { JQDialog.SendWeiXinMsg(strSiteCode, p_openid, "亲爱的店长大人,您的宝贝【" + pnam + "】已于" + DateTime.Now.ToString("yyyy年MM月dd日 HH:mm:ss") + "被" + uname + "成功买下,单号【" + strOrdernum + "】赶紧去小店看看吧!"); } MSOrderLogDAL.AddMSOrderLog("下单成功,通知到OpenID为【" + p_openid + "】的店长"); #endregion #region -产品属性 MSProductParaDAL paraDal = new MSProductParaDAL(); int stock = 0; if (paraDal.ExistMSPPara("", strpid) && mid != null && mid != "") { try { stock = int.Parse(paraDal.GetMSPParaValueByID("Stock", mid).ToString()); } catch (Exception) { } if (stock > 0) { int buynum = 0; try { buynum = Convert.ToInt32(quantity); } catch (Exception) { } if (buynum != 0 && buynum < stock) { stock = stock - buynum; paraDal.UpdateStock(stock, mid); } } } #endregion DataSet orderds = cartDal.GetMyOrderDetail(strOrdernum); string payinfo = string.Empty; string productname = string.Empty; //用户购买的商品名称 string ordernum = string.Empty; //订单号 if (orderds != null && orderds.Tables.Count > 0 && orderds.Tables[0].Rows.Count > 0) { productname = orderds.Tables[0].Rows[0]["Ptitle"].ToString(); ordernum = orderds.Tables[0].Rows[0]["ID"].ToString(); //payinfo= WapPayHelper.BuildRequest(productname, ordernum, countcost, customid); } if (productname.Trim() != null && productname.Trim() != "" && ordernum != null && ordernum != "") { //Response.Write("{\"success\":true,\"payinfo\":\"" + payinfo + "\"}"); Response.Write("{\"success\":true,\"pname\":\"" + productname + "\",\"ordernum\":\"" + ordernum + "\",\"countcost\":\"" + countcost + "\",\"customid\":\"" + customid + "\",\"openid\":\"" + openid + "\"}"); } } else { Response.Write("{\"error\":true,\"msg\":\"操作失败,重新操作\"}"); } } catch (Exception) { Response.Write("{\"error\":true,\"msg\":\"操作失败,重新操作\"}"); } } } else { setCookies(); Response.Write("{\"error\":true,\"msg\":\"操作失败,请登录后再操作\",\"loginurl\":\"UserLogin.aspx\"}"); } Response.End(); }
/// <summary> /// 删除订单 /// </summary> void DelOrder() { string oid = string.Empty; string uid = string.Empty; if (Request["oid"] != null && Request["oid"] != "") { oid = Common.Common.NoHtml(Request["oid"]); } if (Request["uid"] != null && Request["uid"] != "") { uid = Common.Common.NoHtml(Request["uid"]); } if (oid != null && oid != "" && uid != null && uid != "") { MSProductOrderDAL OrderDal = new MSProductOrderDAL(); if (OrderDal.UpdateOrderStateByUID(uid, oid)) { int orderquantity = 0; string mid = string.Empty; int quantity = 0; #region -更新库存 MSProductParaDAL paraDal = new MSProductParaDAL(); try { orderquantity = Convert.ToInt32(OrderDal.GetOrderDetailValueByOID("Quantity", oid).ToString()); } catch (Exception) { } if (orderquantity != null && orderquantity > 0) { try { mid = OrderDal.GetOrderDetailValueByOID("MID", oid).ToString(); } catch (Exception) { } } if (mid != null && mid != "") { try { quantity = Convert.ToInt32(paraDal.GetMSPParaValueByID("Stock", mid).ToString()); } catch (Exception) { } } #endregion if (quantity >= 0 && orderquantity > 0) { quantity = quantity + orderquantity; try { paraDal.UpdateStock(quantity, mid); } catch (Exception) { } } MSOrderLogDAL.AddMSOrderLog("订单【" + oid + "】已被客户【" + uid + "】OpenID-【" + strOpenID + "】取消,库存更新"); Response.Write("{\"success\":true}"); } else { Response.Write("{\"error\":true,\"msg\":\"操作失败,请稍后再操作\"}"); } } else { Response.Write("{\"error\":true,\"msg\":\"操作失败,请核对后再操作\"}"); } Response.End(); }