using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using POSV.Utils;
using NPoco;
using POSV.Entity;
using Newtonsoft.Json.Converters;
using POSV.Card;
using System.Collections.ObjectModel;
namespace POSV.ShoppingCart
{
///
/// 订单对象,包含整个订单的全部信息
///
[Serializable]
[JsonObject(MemberSerialization.OptIn)]
[TableName("pos_order")]
[PrimaryKey(new string[] { "id" }, AutoIncrement = false)]
public class OrderObject : BaseEntity
{
public OrderObject()
{
this.ErrorMessage = "";
}
[Ignore]
public bool isUpLoadTicket { get; set; } = false;
///
/// 租户ID
///
[JsonProperty(PropertyName = "tenantId")]
[Column("tenantId")]
public string TenantId { get; set; }
///
/// 订单内部标识
///
[JsonProperty(PropertyName = "objectId")]
[Column("objectId")]
public string ObjectId { get; set; }
///
/// 单据编号
///
[JsonProperty(PropertyName = "no")]
[Column("tradeNo")]
public string TradeNo { get; set; } = string.Empty;
///
/// 订单序号
///
[JsonProperty(PropertyName = "orderNo")]
[Column("orderNo")]
public string OrderNo { get; set; }
///
/// 门店ID
///
[JsonProperty(PropertyName = "storeId")]
[Column("storeId")]
public string StoreId { get; set; }
///
/// 门店编号
///
[JsonProperty(PropertyName = "storeNo")]
[Column("storeNo")]
public string StoreNo { get; set; }
///
/// 门店名称
///
[JsonProperty(PropertyName = "storeName")]
[Column("storeName")]
public string StoreName { get; set; }
///
/// 操作员工号
///
[JsonProperty(PropertyName = "workNo")]
[Column("workerNo")]
public string WorkerNo { get; set; }
///
/// 操作员名称
///
[JsonProperty(PropertyName = "workName")]
[Column("workerName")]
public string WorkerName { get; set; }
///
/// POS
///
[JsonProperty(PropertyName = "posNo")]
[Column("posNo")]
public string PosNo { get; set; }
///
/// 收银设备名称
///
[JsonProperty(PropertyName = "deviceName")]
[Column("deviceName")]
public string DeviceName { get; set; }
///
/// 收银设备Mac地址
///
[JsonProperty(PropertyName = "deviceMac")]
[Column("macAddress")]
public string MacAddress { get; set; }
///
/// 收银设备IP地址
///
[JsonProperty(PropertyName = "deviceIp")]
[Column("ipAddress")]
public string IpAddress { get; set; }
///
/// 营业员编码
///
[JsonProperty(PropertyName = "salesCode")]
[Column("salesCode")]
public string SalesCode { get; set; } = string.Empty;
///
/// 营业员名称
///
[JsonProperty(PropertyName = "salesName")]
[Column("salesName")]
public string SalesName { get; set; } = string.Empty;
///
/// 餐桌号
///
[JsonProperty(PropertyName = "tableNo")]
[Column("tableNo")]
public string TableNo { get; set; } = string.Empty;
///
/// 餐桌名称
///
[JsonProperty(PropertyName = "tableName")]
[Column("tableName")]
public string TableName { get; set; } = string.Empty;
///
/// 人数
///
[JsonProperty(PropertyName = "people")]
[Column("people")]
public int People { get; set; } = 1;
///
/// 班次
///
[JsonProperty(PropertyName = "shiftNo")]
[Column("shiftNo")]
public string ShiftNo { get; set; }
///
/// 班次名称
///
[JsonProperty(PropertyName = "shiftName")]
[Column("shiftName")]
public string ShiftName { get; set; }
///
/// 销售订单创建时间
///
[JsonProperty(PropertyName = "saleDate")]
[Column("saleDate")]
public string SaleDate { get; set; } = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
///
/// 订单完成时间(格式:yyyy-MM-dd HH:mm:ss)
///
[JsonProperty(PropertyName = "finishDate")]
[Column("finishDate")]
public string FinishDate { get; set; } = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
/////
///// 商品Map明细
/////
//[JsonProperty(PropertyName = "maps")]
//[Ignore]
//public ObservableDictionary Maps { get; set; }
[JsonProperty(PropertyName = "maps")]
[Ignore]
public ObservableCollection Maps { get; set; }
private int _orderCount = 0;
///
/// 购物车中总行数
///
[JsonProperty(PropertyName = "orderCount")]
[Column("orderCount")]
public int OrderCount
{
get
{
this._orderCount = (this.Maps == null ? 0 : this.Maps.Count);
return _orderCount;
}
set
{
this._orderCount = value;
}
}
private List _items;
///
/// 商品List集合
///
[JsonProperty(PropertyName = "items")]
[Ignore]
public List Items
{
get
{
this._items = (this.Maps == null ? this._items : this.Maps.ToList());
return this._items;
}
set
{
this._items = value;
}
}
[Ignore]
public decimal ItemsSaleTax
{
get
{
this._items = (this.Maps == null ? this._items : this.Maps.ToList());
return _items.Sum(f=>f.SaleTaxMoney);
//_items.ForEach(f =>
//{
// _tax += f.Amount * (f.ProductExt.SaleTax / 100);
//});
//return _tax;
}
}
///
/// 支付明细
///
[JsonProperty(PropertyName = "pays")]
[Ignore]
public List Pays { get; set; }
private int _payCount = 0;
///
/// 购物车中总行数
///
[JsonProperty(PropertyName = "payCount")]
[Column("payCount")]
public int PayCount
{
get
{
this._payCount = (this.Pays == null ? 0 : Pays.Count);
return this._payCount;
}
set
{
this._payCount = value;
}
}
///
/// 整单享受的优惠列表
///
[JsonProperty(PropertyName = "promotions")]
[Ignore]
public List Promotions { get; set; }
private int _promotionCount = 0;
///
/// 整单享受的数量
///
[JsonProperty(PropertyName = "promotionCount")]
[Column("promotionCount")]
public int PromotionCount
{
get
{
this._promotionCount = (this.Promotions == null ? 0 : Promotions.Count);
return this._promotionCount;
}
set
{
this._promotionCount = value;
}
}
private decimal _totalQuantity = 0;
///
/// 整单的数量合计
///
[JsonProperty(PropertyName = "totalQuantity")]
[Column("totalQuantity")]
public decimal TotalQuantity
{
get
{
this._totalQuantity = (this.Items == null ? 0 : this.Items.FindAll(x => x.RowState != OrderRowState.套餐明).Sum(m => m.Quantity));
return this._totalQuantity;
}
set
{
this._totalQuantity = value;
}
}
private decimal _amount = 0;
///
/// 消费金额,不包含套餐明细
///
[JsonProperty(PropertyName = "amount")]
[Column("amount")]
public decimal Amount
{
get
{
//金额合计不包含套餐明细
if (this.Items == null)
{
this._amount = 0;
}
else
{
//不包含套餐明细的金额
var _total = this.Items.FindAll(x => x.RowState != OrderRowState.套餐明).Sum(m => m.TotalAmonut);
this._amount = _total;
}
return OrderUtils.ToRound(this._amount);
}
set
{
this._amount = value;
}
}
private decimal _productAmount = 0;
///
/// 消费金额,不包含套餐明细
///
[Ignore]
public decimal ProductAmount
{
get
{
//金额合计不包含套餐明细
if (this.Items == null)
{
this._productAmount = 0;
}
else
{
//不包含套餐明细的金额
var _total = this.Items.FindAll(x => x.RowState != OrderRowState.套餐明).Sum(m => m.Amount);
this._productAmount = _total;
}
return OrderUtils.ToRound(this._productAmount);
}
set
{
this._productAmount = value;
}
}
private decimal _discountAmount = 0;
///
/// 优惠金额,不包含套餐明细
///
[JsonProperty(PropertyName = "discountAmount")]
[Column("discountAmount")]
public decimal DiscountAmount
{
get
{
decimal mainDiscount = (this.Items == null ? 0 : this.Items.FindAll(x => x.RowState != OrderRowState.套餐明).Sum(m => m.TotalDiscountAmount));
//decimal detailFlavorDiscount = this._discountAmount = (this.Items == null ? 0 : this.Items.FindAll(x => x.RowState == OrderRowState.套餐明).Sum(m => m.FlavorDiscountAmount));
//this._discountAmount = mainDiscount + detailFlavorDiscount;
//return OrderUtils.ToRound(this._discountAmount);
this._discountAmount = mainDiscount;
return OrderUtils.ToRound(this._discountAmount);
}
set
{
this._discountAmount = value;
}
}
private decimal _productDiscountAmount = 0;
///
/// 产品优惠金额,不包含套餐明细
///
[Ignore]
public decimal ProductDiscountAmount
{
get
{
decimal mainDiscount = (this.Items == null ? 0 : this.Items.FindAll(x => x.RowState != OrderRowState.套餐明).Sum(m => m.DiscountAmount));
this._productDiscountAmount = mainDiscount;
return OrderUtils.ToRound(this._productDiscountAmount);
}
set
{
this._productDiscountAmount = value;
}
}
///
/// 总优惠率,包含商品+加价
///
[JsonProperty(PropertyName = "discountRate")]
[Column("discountRate")]
public decimal DiscountRate
{
get
{
if (this.Amount == 0)
{
return 0;
}
return OrderUtils.ToRound(this.DiscountAmount / this.Amount);
}
}
private decimal _receivableAmount = 0;
///
/// 应收金额 = 消费金额 - 优惠金额
///
[JsonProperty(PropertyName = "receivable")]
[Column("receivableAmount")]
public decimal ReceivableAmount
{
get
{
this._receivableAmount = this.Amount - this.DiscountAmount;
return this._receivableAmount;
}
set
{
this._receivableAmount = value;
}
}
private decimal _productReceivableAmount = 0;
///
/// 应收金额 = 消费金额 - 优惠金额
///
[Ignore]
public decimal ProductReceivableAmount
{
get
{
this._productReceivableAmount = this.ProductAmount - this.ProductDiscountAmount;
return this._productReceivableAmount;
}
set
{
this._productReceivableAmount = value;
}
}
private decimal _paidAmount = 0;
///
/// 实收金额 = 应收金额 - 抹零金额
///
[JsonProperty(PropertyName = "paid")]
[Column("paidAmount")]
public decimal PaidAmount
{
get
{
//this._paidAmount = (this.Pays == null ? 0 : this.Pays.Sum(m => m.PaidAmount));
this._paidAmount = this._receivableAmount - this.MalingAmount ;
return this._paidAmount;
}
set
{
this._paidAmount = value;
}
}
private decimal _receivedAmount = 0;
///
/// 已收金额,各种支付明细的实收金额合计
///
[JsonProperty(PropertyName = "received")]
[Column("receivedAmount")]
public decimal ReceivedAmount
{
get
{
this._receivedAmount = (this.Pays == null ? 0 : this.Pays.Sum(m => m.PaidAmount));
//this._receivedAmount = this._receivableAmount - this.MalingAmount;
return this._receivedAmount;
}
set
{
this._receivedAmount = value;
}
}
///
/// 抹零金额
///
[JsonProperty(PropertyName = "maling")]
[Column("malingAmount")]
public decimal MalingAmount { get; set; }
///
/// 找零金额
///
[JsonProperty(PropertyName = "change")]
[Column("changeAmount")]
public decimal ChangeAmount { get; set; }
///
/// 溢收金额
///
[Ignore]
public decimal OverAmount { get; set; }
///
/// 开票金额
///
[JsonProperty(PropertyName = "invoiced")]
[Column("invoicedAmount")]
public decimal InvoicedAmount { get; set; }
///
/// 订单同步状态 0-新增,1-已同步,2-问题单
///
[JsonProperty(PropertyName = "sync")]
[Column("syncStatus")]
public int SyncStatus { get; set; } = 0;
///
/// 上传错误次数,错误次数越多,优先级越低
///
[JsonProperty(PropertyName = "uploadErrors")]
[Column("uploadErrors")]
public int UploadErrors { get; set; }
///
/// 订单状态
///
[JsonProperty(PropertyName = "status")]
[Column("orderStatus")]
public OrderStatus OrderStatus { get; set; }
///
/// 订单类型
///
[JsonProperty(PropertyName = "type")]
[Column("orderType")]
public OrderType OrderType { get; set; } = OrderType.堂食;
///
/// 支付状态
///
[JsonProperty(PropertyName = "paymentStatus")]
[Column("paymentStatus")]
public OrderPaymentStatus PaymentStatus { get; set; }
///
/// 打印状态
///
[JsonProperty(PropertyName = "printStatus")]
[Column("printStatus")]
public OrderPrintStatus PrintStatus { get; set; }
///
/// 打印次数
///
[JsonProperty(PropertyName = "printTimes")]
[Column("printTimes")]
public int PrintTimes { get; set; }
///
/// 原单号
///
[JsonProperty(PropertyName = "noOrg")]
[Column("orgTradeNo")]
public string OrgTradeNo { get; set; } = string.Empty;
///
/// 退单原因
///
[JsonProperty(PropertyName = "backCause")]
[Column("refundCause")]
public string RefundCause { get; set; }
private int _isMember = 0;
///
/// 是否使用会员卡(0否1是)
///
[JsonProperty(PropertyName = "isMember")]
[Column("isMember")]
public int IsMember
{
get
{
if (isUpLoadTicket)
{
return this._isMember;
}
else
{
return this.Member == null ? 0 : 1;
}
}
set
{
this._isMember = value;
}
}
private string _memberNo = string.Empty;
///
/// 会员卡号
///
[JsonProperty(PropertyName = "memberNo")]
[Column("memberNo")]
public string MemberNo
{
get
{
if (!string.IsNullOrEmpty(_memberNo))
{
return _memberNo;
}
else
{
return (this.Member != null && this.Member.CurrentCard != null) ? this.Member.CurrentCard.CardNo : string.Empty;
}
}
set
{
_memberNo = value;
}
}
private string _memberMobileNo = string.Empty;
///
/// 会员手机号
///
[JsonProperty(PropertyName = "memberMobileNo")]
[Column("memberMobileNo")]
public string MemberMobileNo
{
get
{
if (!string.IsNullOrEmpty(_memberMobileNo))
{
return _memberMobileNo;
}
else
{
return (this.Member != null) ? this.Member.Mobile : string.Empty;
}
}
set
{
this._memberMobileNo = value;
}
}
private string _cardFaceNo = string.Empty;
///
/// 会员卡面号
///
[JsonProperty(PropertyName = "cardFaceNo")]
[Column("cardFaceNo")]
public string CardFaceNo
{
get
{
if (!string.IsNullOrEmpty(_cardFaceNo))
{
return _cardFaceNo;
}
else
{
return (this.Member != null && this.Member.CurrentCard != null) ? this.Member.CurrentCard.FaceNo : string.Empty;
}
}
set
{
this._cardFaceNo = value;
}
}
///
/// 消费前积分
///
[JsonProperty(PropertyName = "memberPreJifen")]
[Column("prePoint")]
public decimal PrePoint { get; set; }
///
/// 本单积分
///
[JsonProperty(PropertyName = "memberJifen")]
[Column("addPoint")]
public decimal AddPoint { get; set; }
///
/// 消费后积分
///
[JsonProperty(PropertyName = "memberAftJifen")]
[Column("aftPoint")]
public decimal AftPoint { get; set; } = 0.00M;
///
/// 已退积分,原单使用
///
[JsonProperty(PropertyName = "refundPoint")]
[Column("refundPoint")]
public decimal RefundPoint { get; set; }
///
/// 可退积分,计算过程使用
///
[JsonProperty(PropertyName = "usableRefundPoint")]
[Ignore]
public decimal UsableRefundPoint
{
get
{
return this.AddPoint - this.RefundPoint;
}
}
private decimal _estimatedCost = 0;
///
/// 预估成本
///
[JsonProperty(PropertyName = "estimatedCost")]
[Column("estimatedCost")]
public decimal EstimatedCost
{
get
{
this._estimatedCost = 0.00M;
if (Items != null && Items.Count > 0)
{
foreach (OrderItem item in Items)
{
if (item.RowState == OrderRowState.套餐明)
{
this._estimatedCost += 0;
}
else
{
this._estimatedCost += OrderUtils.ToRound(item.EstimatedCost);
}
}
}
return this._estimatedCost;
}
set
{
this._estimatedCost = value;
}
}
private decimal _estimatedProfitAmount = 0;
///
/// 预估毛利金额
///
[JsonProperty(PropertyName = "estimatedProfitAmount")]
[Column("estimatedProfitAmount")]
public decimal EstimatedProfitAmount
{
get
{
this._estimatedProfitAmount = 0.00M;
if (Items != null && Items.Count > 0)
{
foreach (OrderItem item in Items)
{
if (item.RowState == OrderRowState.套餐明)
{
this._estimatedProfitAmount += 0;
}
else
{
this._estimatedProfitAmount += OrderUtils.ToRound(item.EstimatedProfitAmount);
}
}
}
return this._estimatedProfitAmount;
}
set
{
this._estimatedProfitAmount = value;
}
}
private decimal _estimatedProfitMargin = 0;
///
/// 预估毛利率
///
[JsonProperty(PropertyName = "estimatedProfitMargin")]
[Column("estimatedProfitMargin")]
public decimal EstimatedProfitMargin
{
get
{
this._estimatedProfitMargin = 0.00M;
if (this.ReceivableAmount != 0)
{
this._estimatedProfitMargin = this.EstimatedProfitAmount / this.ReceivableAmount;
}
else
{
this._estimatedProfitMargin = 0;
}
return this._estimatedProfitMargin;
}
set
{
this._estimatedProfitMargin = value;
}
}
///
/// 实际成本
///
[JsonProperty(PropertyName = "totalCost")]
[Column("totalCost")]
public decimal TotalCost { get; set; } = 0.00M;
///
/// 实际毛利金额
///
[JsonProperty(PropertyName = "profitAmount")]
[Column("profitAmount")]
public decimal ProfitAmount { get; set; } = 0.00M;
///
/// 实际毛利率
///
[JsonProperty(PropertyName = "profitMargin")]
[Column("profitMargin")]
public decimal ProfitMargin { get; set; } = 0.00M;
///
/// 会员信息
///
[JsonProperty(PropertyName = "member")]
[Ignore]
public MemberInfoQueryResponse Member { get; set; } = null;
///
/// 享迷卡会员信息
///
[Ignore]
public MemberInfoQueryResponse XmkMember { get; set; } = null;
///
/// 会员卡支付清单
///
[JsonProperty(PropertyName = "mpay")]
[Ignore]
public CardTradePayResponse CardPayResult { get; set; }
///
/// 数据上传状态
///
[JsonProperty(PropertyName = "uploadStatus")]
[Column("uploadStatus")]
public int UploadStatus { get; set; } = -1;
///
/// 数据上传消息说明
///
[JsonProperty(PropertyName = "uploadMessage")]
[Column("uploadMessage")]
public string UploadMessage { get; set; } = string.Empty;
///
/// 数据上传错误码
///
[JsonProperty(PropertyName = "uploadErrCode")]
[Column("uploadErrCode")]
public string UploadErrCode { get; set; } = string.Empty;
///
/// 数据上传错误说明
///
[JsonProperty(PropertyName = "uploadErrMessage")]
[Column("uploadErrMessage")]
public string UploadErrMessage { get; set; } = string.Empty;
///
/// 数据上传服务端ID
///
[JsonProperty(PropertyName = "ticketId")]
[Column("ticketId")]
public string TicketId { get; set; } = string.Empty;
///
/// 数据上传成功的时间
///
[JsonProperty(PropertyName = "uploadTime")]
[Column("uploadTime")]
public string UploadTime { get; set; } = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
///
/// 星期
///
[JsonProperty(PropertyName = "weeker")]
[Column("weeker")]
public string Weeker
{
get; set;
}
///
/// 天气
///
[JsonProperty(PropertyName = "weather")]
[Column("weather")]
public string Weather
{
get; set;
}
///
/// 订单备注
///
[JsonProperty(PropertyName = "ext1")]
[Column("ext1")]
public string Ext1 { get; set; }
///
/// POS机名
///
[JsonProperty(PropertyName = "ext2")]
[Column("ext2")]
public string Ext2 { get; set; }
///
/// 厨打方案名称
///
[JsonProperty(PropertyName = "ext3")]
[Column("ext3")]
public string Ext3 { get; set; }
#region 异步支付通知信息
///
/// 异步通知状态
///
[JsonProperty(PropertyName = "PayState")]
[Ignore]
public string PayState { get; set; }
///
/// 支付查询剩余次数
///
[JsonProperty(PropertyName = "PayQueryQuantity")]
[Ignore]
public int PayQueryQuantity { get; set; }
///
/// 支付错误信息
///
[JsonProperty(PropertyName = "ErrorMessage")]
[Ignore]
public string ErrorMessage { get; set; }
#endregion
///
/// 单据类型;0结账单1退单
///
[Ignore]
public int PrintType
{
get; set;
}
///
/// 重打标识
///
[Ignore]
public bool RPrint
{
get; set;
}
///
/// 外送单
///
[JsonProperty(PropertyName = "delivery")]
[Ignore]
public OrderDelivery Delivery { get; set; } = null;
[Ignore]
public bool IsUserMemberPrice { get; set; } = false;
[Ignore]
public DateTime PayCountDown { get; set; }
[Ignore]
public string ReserveTime { get; set; }
///
/// erp上传标识
///
[Ignore]
[Column("IsUploadERP")]
public int IsUploadERP
{
get; set;
}
#region 小程序点餐辅助字段
[Ignore]
///
/// 餐盒费
///
public decimal BoxFee { get; set; }
[Ignore]
///
/// 配送费
///
public decimal DeliverFee { get; set; }
///
/// 就餐模式
///
[Ignore]
public string BusMode
{
get;
set;
}
///
/// 外送地址
///
[Ignore]
public string Address
{
get;
set;
}
///
/// 收货人
///
[Ignore]
public string Recipients
{
get;
set;
}
///
/// 联系电话
///
[Ignore]
public string Phone
{
get;
set;
}
#region subin 20230916 新增,用于本地小程序订单退款。
///
/// 小程序付款的PayuserId
///
[Ignore]
public string OpenId { get; set; }
#endregion
#endregion
[Ignore]
public string wishtime { get; set; }
///
/// 本单扣款结算汇总金额,考虑到数据库增加字段的风险,没有存储到数据库,上传数据时候汇总。
/// zhangy 2020-02-18 Add
///
[JsonProperty(PropertyName = "orderChargeBack")]
[Ignore]
public decimal OrderChargeBack { get; set; } = 0.00M;
#region subin 2023-10-25 add 分账标识,用于区别是否已分账
///
/// 是否已分账
///
[JsonProperty(PropertyName = "isSplited")]
[Column("isSplited")]
public int IsSplited { get; set; } = 0;
#endregion
}
}