购物车代码
public ActionResult Ordershopcart()
{
{
//获取会员信息
Member member = CookieUtil.GetLoginCookie();
//获取购物车对象
Mola.Model.ShoppingCartInfo shoppingCart = Common.GetShoppingCartInfo(member, Common.GetComBinFlag(), null);
if (shoppingCart == null || shoppingCart.CartItems == null)
{
return Redirect("/");
}
if (!string.IsNullOrEmpty(shoppingCart.ModOrderCode))
{
return Redirect("/Cart/ModOrdershopcart.aspx");
}
Member member = CookieUtil.GetLoginCookie();
//获取购物车对象
Mola.Model.ShoppingCartInfo shoppingCart = Common.GetShoppingCartInfo(member, Common.GetComBinFlag(), null);
if (shoppingCart == null || shoppingCart.CartItems == null)
{
return Redirect("/");
}
if (!string.IsNullOrEmpty(shoppingCart.ModOrderCode))
{
return Redirect("/Cart/ModOrdershopcart.aspx");
}
//保存购物车对象
Common.SaveShoppingCartInfo(shoppingCart, shoppingCart.SerializationCart, false, 0, false);
ViewBag.ShoppingCart = shoppingCart;
ViewBag.DiscountCode = Common.GetShoppingDiscountData() == null ? "" : Common.GetShoppingDiscountData();
return View();
}
Common.SaveShoppingCartInfo(shoppingCart, shoppingCart.SerializationCart, false, 0, false);
ViewBag.ShoppingCart = shoppingCart;
ViewBag.DiscountCode = Common.GetShoppingDiscountData() == null ? "" : Common.GetShoppingDiscountData();
return View();
}
/// <summary>
/// 更新购物车数量
/// </summary>
/// <returns></returns>
public ActionResult UpdateCarItemQty()
{
//获取序列化购物车
SerializationCartInfo sCart = Common.GetSerializationCart();
if (sCart == null)
{
return Redirect("/Cart/shopping_index.aspx");
}
string wareCode = QueryString.safeq("WareCode");
decimal qty = QueryString.intsafeq("Qty");
bool isCombin = Common.GetComBinFlag();
int webSite = QueryString.intsafeq("WebSiteId");
int kitOrder = QueryString.intsafeq("KitOrder");
//转化成购物车对象
Member member = Mola.Core.CookieUtil.GetLoginCookie();
/// 更新购物车数量
/// </summary>
/// <returns></returns>
public ActionResult UpdateCarItemQty()
{
//获取序列化购物车
SerializationCartInfo sCart = Common.GetSerializationCart();
if (sCart == null)
{
return Redirect("/Cart/shopping_index.aspx");
}
string wareCode = QueryString.safeq("WareCode");
decimal qty = QueryString.intsafeq("Qty");
bool isCombin = Common.GetComBinFlag();
int webSite = QueryString.intsafeq("WebSiteId");
int kitOrder = QueryString.intsafeq("KitOrder");
//转化成购物车对象
Member member = Mola.Core.CookieUtil.GetLoginCookie();
//更新购物车信息
string strMsg = new CartClient().UpdateCartItemQty(wareCode, kitOrder, qty, webSite, isCombin, member, ref sCart);
if (string.IsNullOrEmpty(strMsg))
{
return Content(StringUtils.ToJson(sCart));
}
else
{
string jsonCart = StringUtils.ToJson(sCart);
if (strMsg != "Y")
{
return Content("{MSG:'" + NoticeHelper.GetNotice(strMsg) + "',ShoppingCart:" + jsonCart + "}");
}
else
{
Common.SetComBinFlag(0);
Common.SaveShoppingCartInfo(sCart, false, 1, true);
ShoppingCartInfo cartInfo = Common.GetShoppingCartInfo(member, isCombin, sCart);
// cartInfo.CartItems[0].KitDetail[0].KitOrder
return Content(StringUtils.ToJson(cartInfo));
}
}
}
string strMsg = new CartClient().UpdateCartItemQty(wareCode, kitOrder, qty, webSite, isCombin, member, ref sCart);
if (string.IsNullOrEmpty(strMsg))
{
return Content(StringUtils.ToJson(sCart));
}
else
{
string jsonCart = StringUtils.ToJson(sCart);
if (strMsg != "Y")
{
return Content("{MSG:'" + NoticeHelper.GetNotice(strMsg) + "',ShoppingCart:" + jsonCart + "}");
}
else
{
Common.SetComBinFlag(0);
Common.SaveShoppingCartInfo(sCart, false, 1, true);
ShoppingCartInfo cartInfo = Common.GetShoppingCartInfo(member, isCombin, sCart);
// cartInfo.CartItems[0].KitDetail[0].KitOrder
return Content(StringUtils.ToJson(cartInfo));
}
}
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public ActionResult RemoveCartItem()
{
#region 购物车
SerializationCartInfo sCart = Common.GetSerializationCart();
Mola.Model.Member member = Mola.Core.CookieUtil.GetLoginCookie();
#endregion
string wareCode = QueryString.safeq("WareCode");
bool isCombin = Common.GetComBinFlag();
int webSiteId = QueryString.intsafeq("WebSiteId");
int kitOrder = QueryString.intsafeq("KitOrder");
ShoppingCartInfo cartInfo = new ShoppingCartInfo();
//转化成购物车对象
string strMsg = new CartClient().RemoveCartItem(wareCode, kitOrder, webSiteId, isCombin, member, ref sCart);
if (strMsg == "Y")
{
Common.SetComBinFlag(0);
Common.RemoveShppingcartItem(wareCode, kitOrder);
Common.SaveShoppingCartInfo(sCart, false, 1, true);
cartInfo = Common.GetShoppingCartInfo(member, isCombin, sCart);
}
return Content(StringUtils.ToJson(cartInfo));
}
///
/// </summary>
/// <returns></returns>
public ActionResult RemoveCartItem()
{
#region 购物车
SerializationCartInfo sCart = Common.GetSerializationCart();
Mola.Model.Member member = Mola.Core.CookieUtil.GetLoginCookie();
#endregion
string wareCode = QueryString.safeq("WareCode");
bool isCombin = Common.GetComBinFlag();
int webSiteId = QueryString.intsafeq("WebSiteId");
int kitOrder = QueryString.intsafeq("KitOrder");
ShoppingCartInfo cartInfo = new ShoppingCartInfo();
//转化成购物车对象
string strMsg = new CartClient().RemoveCartItem(wareCode, kitOrder, webSiteId, isCombin, member, ref sCart);
if (strMsg == "Y")
{
Common.SetComBinFlag(0);
Common.RemoveShppingcartItem(wareCode, kitOrder);
Common.SaveShoppingCartInfo(sCart, false, 1, true);
cartInfo = Common.GetShoppingCartInfo(member, isCombin, sCart);
}
return Content(StringUtils.ToJson(cartInfo));
}
/// <summary>
/// 修改购物车
/// </summary>
/// <returns></returns>
public ActionResult ModOrdershopcart()
{
//获取购物车
Mola.Model.ShoppingCartInfo shoppingCart = Common.GetShoppingCartInfo(CookieUtil.GetLoginCookie(), Common.GetComBinFlag(), null);
#region 数据检查
if (shoppingCart == null || shoppingCart.CartItems == null || shoppingCart.CartItems.Count <= 0)
{
return Redirect("/Cart/shopping_index.aspx");
}
if (string.IsNullOrEmpty(shoppingCart.ModOrderCode))
{
return Redirect("/Cart/Ordershopcart.aspx");
}
#endregion
ViewBag.ShoppingCart = shoppingCart;
ViewBag.DiscountCode = Common.GetShoppingDiscountData() == null ? "" : Common.GetShoppingDiscountData();
return View();
}
#region 取消修改订单
public ActionResult OrderCancelMod()
{
Model.Member member = CookieUtil.GetLoginCookie();
ShoppingCartInfo shoppingCart = Common.GetShoppingCartInfo(member);
if (member == null)
{
Common.ClearShoppingCart(member);
return Redirect("/cart/Ordershopcart.aspx");
}
if (shoppingCart != null)
{
string ordercode = shoppingCart.ModOrderCode;
Common.ClearShoppingCart(member);
return Redirect("/Order/OrderDetail.aspx?ordercode=" + ordercode);
}
else
{
Common.ClearShoppingCart(member);
return Redirect("/Member/default.aspx");
}
}
#endregion
#region 新加 验证打折
public bool ActiveCode()
{
bool result = true;
string disCode = FormString.safeq("Active_Code"); ;
string orgDisCode = disCode;
if (disCode == "")
{
return false;
}
Model.Member member = CookieUtil.GetLoginCookie();
ShoppingCartInfo shoppingCart = Common.GetShoppingCartInfo(member);
//验证折扣
result = new CartClient().ExistsDiscount(ref disCode, shoppingCart.TotalAmount);
if (!result)
{
return result;
}
//添加折扣
shoppingCart.DiscountList = new CartClient().AddDiscount(disCode);
Common.SaveShoppingCartInfo(shoppingCart, shoppingCart.SerializationCart, false, 0, true);
if (orgDisCode.Length == 16)
{
Common.SaveShoppingDiscountData(orgDisCode);
}
else
{
Common.SaveShoppingDiscountData(disCode);
}
return result;
}
/// 修改购物车
/// </summary>
/// <returns></returns>
public ActionResult ModOrdershopcart()
{
//获取购物车
Mola.Model.ShoppingCartInfo shoppingCart = Common.GetShoppingCartInfo(CookieUtil.GetLoginCookie(), Common.GetComBinFlag(), null);
#region 数据检查
if (shoppingCart == null || shoppingCart.CartItems == null || shoppingCart.CartItems.Count <= 0)
{
return Redirect("/Cart/shopping_index.aspx");
}
if (string.IsNullOrEmpty(shoppingCart.ModOrderCode))
{
return Redirect("/Cart/Ordershopcart.aspx");
}
#endregion
ViewBag.ShoppingCart = shoppingCart;
ViewBag.DiscountCode = Common.GetShoppingDiscountData() == null ? "" : Common.GetShoppingDiscountData();
return View();
}
#region 取消修改订单
public ActionResult OrderCancelMod()
{
Model.Member member = CookieUtil.GetLoginCookie();
ShoppingCartInfo shoppingCart = Common.GetShoppingCartInfo(member);
if (member == null)
{
Common.ClearShoppingCart(member);
return Redirect("/cart/Ordershopcart.aspx");
}
if (shoppingCart != null)
{
string ordercode = shoppingCart.ModOrderCode;
Common.ClearShoppingCart(member);
return Redirect("/Order/OrderDetail.aspx?ordercode=" + ordercode);
}
else
{
Common.ClearShoppingCart(member);
return Redirect("/Member/default.aspx");
}
}
#endregion
#region 新加 验证打折
public bool ActiveCode()
{
bool result = true;
string disCode = FormString.safeq("Active_Code"); ;
string orgDisCode = disCode;
if (disCode == "")
{
return false;
}
Model.Member member = CookieUtil.GetLoginCookie();
ShoppingCartInfo shoppingCart = Common.GetShoppingCartInfo(member);
//验证折扣
result = new CartClient().ExistsDiscount(ref disCode, shoppingCart.TotalAmount);
if (!result)
{
return result;
}
//添加折扣
shoppingCart.DiscountList = new CartClient().AddDiscount(disCode);
Common.SaveShoppingCartInfo(shoppingCart, shoppingCart.SerializationCart, false, 0, true);
if (orgDisCode.Length == 16)
{
Common.SaveShoppingDiscountData(orgDisCode);
}
else
{
Common.SaveShoppingDiscountData(disCode);
}
return result;
}