111 lines
2.8 KiB
C#
111 lines
2.8 KiB
C#
using System.Collections.Generic;
|
|
using HK;
|
|
|
|
namespace Runtime
|
|
{
|
|
public class ShoppingCart
|
|
{
|
|
public string userName = string.Empty;
|
|
public string userModie = string.Empty;
|
|
public string userEmail = string.Empty;
|
|
public string orderID = string.Empty;
|
|
public bool isAgreeSubscribe = false;
|
|
public List<ShoppingCartData> datas = new List<ShoppingCartData>();
|
|
public string totalQuantity = "0";
|
|
public string itemsSubTotal = "0";
|
|
public string discount = "0";
|
|
public string totalAmount = "0";
|
|
|
|
public void AddData(ShoppingCartData data)
|
|
{
|
|
datas.Add(data);
|
|
UpdateDatas();
|
|
}
|
|
|
|
public void RemoveData(ShoppingCartData data)
|
|
{
|
|
datas.Remove(data);
|
|
UpdateDatas();
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
datas.Clear();
|
|
UpdateDatas();
|
|
}
|
|
|
|
public void UpdateDatas()
|
|
{
|
|
totalQuantity = string.Empty;
|
|
itemsSubTotal = string.Empty;
|
|
discount = string.Empty;
|
|
totalAmount = string.Empty;
|
|
|
|
int i = 0, d = 0, t = 0, q = 0;
|
|
foreach (var shoppingCartData in datas)
|
|
{
|
|
q += shoppingCartData.count;
|
|
i += shoppingCartData.bookAmount * shoppingCartData.count;
|
|
d += shoppingCartData.bookDiscount * shoppingCartData.count;
|
|
t += shoppingCartData.bookAmount * shoppingCartData.count;
|
|
}
|
|
|
|
totalQuantity = q.ToString();
|
|
itemsSubTotal = i.ToString("F");
|
|
discount = d.ToString("F");
|
|
totalAmount = t.ToString("F");
|
|
}
|
|
}
|
|
|
|
public class ShoppingCartData
|
|
{
|
|
/// <summary>
|
|
/// name
|
|
/// </summary>
|
|
public string bookName;
|
|
|
|
/// <summary>
|
|
/// 价格
|
|
/// </summary>
|
|
public int bookAmount;
|
|
|
|
/// <summary>
|
|
/// 优惠
|
|
/// </summary>
|
|
public int bookDiscount;
|
|
|
|
/// <summary>
|
|
/// 数量
|
|
/// </summary>
|
|
public int count;
|
|
|
|
public byte[] previewImage;
|
|
public byte[] tifImage;
|
|
}
|
|
|
|
public class ShoppingCartManager : ManagerBase<ShoppingCartManager>
|
|
{
|
|
private ShoppingCart shoppingCart = new();
|
|
public ShoppingCart ShoppingCart => shoppingCart;
|
|
|
|
public void AddToCart(ShoppingCartData data)
|
|
{
|
|
shoppingCart.AddData(data);
|
|
}
|
|
|
|
public void RemoveFromCart(ShoppingCartData data)
|
|
{
|
|
shoppingCart.RemoveData(data);
|
|
}
|
|
|
|
public void RefreshCart()
|
|
{
|
|
shoppingCart.UpdateDatas();
|
|
}
|
|
|
|
public void ResetCart()
|
|
{
|
|
shoppingCart.Reset();
|
|
}
|
|
}
|
|
} |