2025-06-17 09:31:12 +08:00
|
|
|
|
using System.Collections.Generic;
|
2025-07-10 23:16:27 +08:00
|
|
|
|
using HK;
|
2025-06-17 09:31:12 +08:00
|
|
|
|
|
2025-07-10 23:16:27 +08:00
|
|
|
|
namespace Runtime
|
2025-06-17 09:31:12 +08:00
|
|
|
|
{
|
|
|
|
|
public class ShoppingCart
|
|
|
|
|
{
|
2025-07-13 15:53:13 +08:00
|
|
|
|
private string _userName = string.Empty;
|
|
|
|
|
private string _userModie = string.Empty;
|
|
|
|
|
private string _userEmail = string.Empty;
|
|
|
|
|
private string _orderID = string.Empty;
|
|
|
|
|
private bool _isAgreeSubscribe = false;
|
|
|
|
|
private List<ShoppingCartData> _datas = new List<ShoppingCartData>();
|
|
|
|
|
private string _totalQuantity = "0";
|
|
|
|
|
private string _itemsSubTotal = "0";
|
|
|
|
|
private string _discount = "0";
|
|
|
|
|
private string _totalAmount = "0";
|
|
|
|
|
private string _monetary = "RMB";
|
|
|
|
|
|
|
|
|
|
public string userName
|
|
|
|
|
{
|
|
|
|
|
get => _userName;
|
|
|
|
|
set => _userName = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string userModie
|
|
|
|
|
{
|
|
|
|
|
get => _userModie;
|
|
|
|
|
set => _userModie = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string userEmail
|
|
|
|
|
{
|
|
|
|
|
get => _userEmail;
|
|
|
|
|
set => _userEmail = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string orderID
|
|
|
|
|
{
|
|
|
|
|
get => _orderID;
|
|
|
|
|
set => _orderID = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool isAgreeSubscribe
|
|
|
|
|
{
|
|
|
|
|
get => _isAgreeSubscribe;
|
|
|
|
|
set => _isAgreeSubscribe = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<ShoppingCartData> datas => _datas;
|
|
|
|
|
|
|
|
|
|
public string totalQuantity => _totalQuantity;
|
|
|
|
|
public string itemsSubTotal => _itemsSubTotal;
|
|
|
|
|
public string discount => _discount;
|
|
|
|
|
public string totalAmount => _totalAmount;
|
|
|
|
|
|
|
|
|
|
public string monetary
|
|
|
|
|
{
|
|
|
|
|
get => _monetary;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_monetary = value;
|
|
|
|
|
UpdateDatas();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ShoppingCart()
|
|
|
|
|
{
|
|
|
|
|
var value = PlayerPersistent.GetString("monetary");
|
|
|
|
|
if (!string.IsNullOrEmpty(value))
|
|
|
|
|
{
|
|
|
|
|
_monetary = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UpdateDatas();
|
|
|
|
|
}
|
2025-06-17 09:31:12 +08:00
|
|
|
|
|
2025-07-02 10:24:01 +08:00
|
|
|
|
public void AddData(ShoppingCartData data)
|
|
|
|
|
{
|
|
|
|
|
datas.Add(data);
|
|
|
|
|
UpdateDatas();
|
|
|
|
|
}
|
2025-06-17 09:31:12 +08:00
|
|
|
|
|
2025-07-10 23:16:27 +08:00
|
|
|
|
public void RemoveData(ShoppingCartData data)
|
|
|
|
|
{
|
|
|
|
|
datas.Remove(data);
|
|
|
|
|
UpdateDatas();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Reset()
|
|
|
|
|
{
|
|
|
|
|
datas.Clear();
|
|
|
|
|
UpdateDatas();
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-02 10:24:01 +08:00
|
|
|
|
public void UpdateDatas()
|
|
|
|
|
{
|
2025-07-13 15:53:13 +08:00
|
|
|
|
_totalQuantity = string.Empty;
|
|
|
|
|
_itemsSubTotal = string.Empty;
|
|
|
|
|
_discount = string.Empty;
|
|
|
|
|
_totalAmount = string.Empty;
|
2025-07-02 10:24:01 +08:00
|
|
|
|
|
2025-07-11 22:35:50 +08:00
|
|
|
|
int i = 0, d = 0, t = 0, q = 0;
|
2025-07-02 10:24:01 +08:00
|
|
|
|
foreach (var shoppingCartData in datas)
|
|
|
|
|
{
|
2025-07-11 22:35:50 +08:00
|
|
|
|
q += shoppingCartData.count;
|
2025-07-02 10:24:01 +08:00
|
|
|
|
i += shoppingCartData.bookAmount * shoppingCartData.count;
|
|
|
|
|
d += shoppingCartData.bookDiscount * shoppingCartData.count;
|
|
|
|
|
t += shoppingCartData.bookAmount * shoppingCartData.count;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-13 15:53:13 +08:00
|
|
|
|
_totalQuantity = $"{q}";
|
|
|
|
|
_itemsSubTotal = $"{monetary} {i:F}";
|
|
|
|
|
_discount = $"{monetary} {d:F}";
|
|
|
|
|
_totalAmount = $"{monetary} {t:F}";
|
2025-07-02 10:24:01 +08:00
|
|
|
|
}
|
2025-06-17 09:31:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-07-02 10:24:01 +08:00
|
|
|
|
public class ShoppingCartData
|
2025-06-17 09:31:12 +08:00
|
|
|
|
{
|
2025-07-10 23:16:27 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// name
|
|
|
|
|
/// </summary>
|
2025-07-02 10:24:01 +08:00
|
|
|
|
public string bookName;
|
2025-07-11 22:35:50 +08:00
|
|
|
|
|
2025-07-10 23:16:27 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 价格
|
|
|
|
|
/// </summary>
|
2025-07-02 10:24:01 +08:00
|
|
|
|
public int bookAmount;
|
2025-07-11 22:35:50 +08:00
|
|
|
|
|
2025-07-10 23:16:27 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 优惠
|
|
|
|
|
/// </summary>
|
2025-07-02 10:24:01 +08:00
|
|
|
|
public int bookDiscount;
|
2025-07-11 22:35:50 +08:00
|
|
|
|
|
2025-07-10 23:16:27 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 数量
|
|
|
|
|
/// </summary>
|
2025-07-02 10:24:01 +08:00
|
|
|
|
public int count;
|
2025-07-11 22:35:50 +08:00
|
|
|
|
|
2025-07-14 19:29:10 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 预览图
|
|
|
|
|
/// </summary>
|
2025-07-02 10:24:01 +08:00
|
|
|
|
public byte[] previewImage;
|
2025-07-14 19:29:10 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 设计图
|
|
|
|
|
/// </summary>
|
|
|
|
|
public byte[] designImage;
|
2025-06-17 09:31:12 +08:00
|
|
|
|
}
|
2025-07-10 23:16:27 +08:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-11 22:35:50 +08:00
|
|
|
|
public void RefreshCart()
|
|
|
|
|
{
|
|
|
|
|
shoppingCart.UpdateDatas();
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-10 23:16:27 +08:00
|
|
|
|
public void ResetCart()
|
|
|
|
|
{
|
|
|
|
|
shoppingCart.Reset();
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-06-17 09:31:12 +08:00
|
|
|
|
}
|