using System; using System.Collections.Generic; using System.Linq; using System.Text; using DevComponents.DotNetBar.SuperGrid; using Newtonsoft.Json; using NPoco; using POSV.Entity; namespace POSV.ShoppingCart { [Serializable] [JsonObject(MemberSerialization.OptIn)] [TableName("pos_order_item")] [PrimaryKey(new string[] { "id" }, AutoIncrement = false)] public class OrderItem : BaseEntity, IEqualityComparer { public OrderItem() { } [Ignore] public string clientId { get; set; } /// /// 租户ID /// [JsonProperty(PropertyName = "tenantId")] [Column("tenantId")] public string TenantId { get; set; } /// /// 订单ID /// [JsonProperty(PropertyName = "orderId")] [Column("orderId")] public string OrderId { get; set; } /// /// 订单号 /// [JsonProperty(PropertyName = "tradeNo")] [Column("tradeNo")] public string TradeNo { get; set; } /// /// 明细ID /// [JsonProperty(PropertyName = "orgItemId")] [Column("orgItemId")] public string OrgItemId { get; set; } [NonSerialized] private GridRow _gridRow; /// /// Grid的唯一行索引,这个对象无法序列化 /// [JsonIgnore] [Ignore] public GridRow GridRow { get { return _gridRow; } set { _gridRow = value; } } /// /// 购物车-序号 /// [JsonProperty(PropertyName = "orderNo")] [Column("orderNo")] public int OrderNo { get; set; } /// /// 购物车-名称 /// [JsonProperty(PropertyName = "productName")] [Column("productName")] public string Name { get; set; } /// /// 简称 /// [JsonProperty(PropertyName = "shortName")] [Column("shortName")] public string ShortName { get; set; } /// /// 规格名称 /// [JsonProperty(PropertyName = "specName")] [Column("specName")] public string SpecName { get; set; } private string _displayName = string.Empty; /// /// 界面品名显示 /// [JsonProperty(PropertyName = "displayName")] [Column("displayName")] public string DisplayName { get { //判断参数配置中是否定义显示简称 bool showShortName = Global.Instance.GlobalConfigBoolValue(ConfigConstant.CASHIER_SHOW_SHORTNAME, false); //销售界面名称的显示 string showName = (showShortName && !string.IsNullOrEmpty(this.ShortName)) ? this.ShortName : this.Name; //判断参数配置中是否定义显示规格 bool showSpecName = Global.Instance.GlobalConfigBoolValue(ConfigConstant.CASHIER_SHOW_SPECNAME, true); //销售界面规格的显示 string specName = showSpecName ? (string.IsNullOrEmpty(this.SpecName) ? "" : Global.Instance.Additional.Item1 + this.SpecName + Global.Instance.Additional.Item2) : ""; //附加规格到名称中 string result = showName + specName; if (this.RowState == OrderRowState.普通 || this.RowState == OrderRowState.套餐主) { if (this.Promotions != null) { //禁止收银前台赠送 bool notAllowShowGive = Global.Instance.GlobalConfigBoolValue(ConfigConstant.CASHIER_NOT_ALLOW_SHOW_GIVE, true); if (!notAllowShowGive && this.Promotions.Exists(x => x.PromotionType == PromotionType.赠送)) { result = Global.Instance.Additional.Item1 + "赠" + Global.Instance.Additional.Item2 + result; } //禁止收银前台折扣 bool notAllowShowDiscount = Global.Instance.GlobalConfigBoolValue(ConfigConstant.CASHIER_NOT_ALLOW_SHOW_DISCOUNT, true); if (!notAllowShowDiscount && this.Promotions.Exists(x => x.PromotionType == PromotionType.折扣 || x.PromotionType == PromotionType.整单折扣)) { result = Global.Instance.Additional.Item1 + "折" + Global.Instance.Additional.Item2 + result; } //禁止收银前台议价 bool notAllowShowBargain = Global.Instance.GlobalConfigBoolValue(ConfigConstant.CASHIER_NOT_ALLOW_SHOW_BARGAIN, true); if (!notAllowShowBargain && this.Promotions.Exists(x => x.PromotionType == PromotionType.议价 || x.PromotionType == PromotionType.整单议价)) { result = Global.Instance.Additional.Item1 + "议" + Global.Instance.Additional.Item2 + result; } //双数特价 if (this.Promotions.Exists(x => x.PromotionType == PromotionType.双数特价优惠 || x.PromotionType == PromotionType.双数特价赠送)) { result = Global.Instance.Additional.Item1 + "双" + Global.Instance.Additional.Item2 + result; } } } if (this.RowState == OrderRowState.套餐明) { result = Global.Instance.Additional.Item1 + "套" + Global.Instance.Additional.Item2 + result; } this._displayName = result; return _displayName; } set { this._displayName = value; } } private decimal _quantity; /// /// 购物车-数量 /// [JsonProperty(PropertyName = "quantity")] [Column("quantity")] public decimal Quantity { get { return this._quantity; } set { this._quantity = value; //调整做法计价 if (this.Flavors != null) { this.Flavors.ForEach(x => x.OrderItemQuantity = this._quantity); } } } private decimal _refundQuantity = 0; /// /// 购物车-退数量 /// [JsonProperty(PropertyName = "rquantity")] [Column("rquantity")] public decimal RefundQuantity { get { return this._refundQuantity; } set { this._refundQuantity = value; } } /// /// 购物车-中途退数量 /// [JsonProperty(PropertyName = "middleRefundQuantity")] [Column("middleRefundQuantity")] public decimal MiddleRefundQuantity { get; set; } private decimal _usableRefundQuantity = decimal.Zero; /// /// 可退数量,显示用 /// [JsonProperty(PropertyName = "usableRefundQuantity")] [Ignore] public decimal UsableRefundQuantity { get { if (this._usableRefundQuantity != decimal.Zero) { return this._usableRefundQuantity; } else { return this.Quantity - this.MiddleRefundQuantity; } } set { _usableRefundQuantity = value; } } /// /// 售价 /// [JsonProperty(PropertyName = "salePrice")] [Column("salePrice")] public decimal SalePrice { get; set; } /// /// 会员售价 /// [Ignore] public decimal MemberSalePrice { get; set; } /// /// 成本价 /// [JsonProperty(PropertyName = "costPrice")] [Column("costPrice")] public decimal CostPrice { get; set; } /// /// 购物车-零售价 /// [JsonProperty(PropertyName = "price")] [Column("price")] public decimal Price { get; set; } /// /// 折后单价 /// [JsonProperty(PropertyName = "discountPrice")] [Column("discountPrice")] public decimal DiscountPrice { get; set; } /// /// 最低售价 /// [JsonProperty(PropertyName = "minPrice")] [Column("minPrice")] public decimal MinPrice { get; set; } /// /// 会员价 /// [JsonProperty(PropertyName = "memberPrice")] [Column("memberPrice")] public decimal MemberPrice { get; set; } /// /// 第三方价 /// [JsonProperty(PropertyName = "otherPrice")] [Column("otherPrice")] public decimal OtherPrice { get; set; } /// /// 批发价 /// [JsonProperty(PropertyName = "dispatchPrice")] [Column("dispatchPrice")] public decimal DispatchPrice { get; set; } private decimal _amount = 0; /// /// 购物车金额小计 = 数量 * 销售单价 /// [JsonProperty(PropertyName = "amount")] [Column("amount")] public decimal Amount { get { this._amount = OrderUtils.ToRound((this.Quantity - this.RefundQuantity) * this.Price); return this._amount; } set { this._amount = value; } } /// /// 购物车显示-优惠 /// [JsonProperty(PropertyName = "discount")] [Column("discount")] public decimal Discount { get; set; } = 0; /// /// 单品优惠率,不包含做法 /// [JsonProperty(PropertyName = "discountRate")] [Column("discountRate")] public decimal DiscountRate { get { if (this.Amount == 0) { return 0; } return OrderUtils.ToRound(this.DiscountAmount / this.Amount); } } /// /// 购物车-行下划线 /// [JsonProperty(PropertyName = "underline")] [Column("underline")] public int Underline { get; set; } /// /// 购物车-是否包含做法 /// [JsonProperty(PropertyName = "flavor")] [Column("flavor")] public int Flavor { get; set; } /// /// 购物车-组标识 /// [JsonProperty(PropertyName = "group")] [Column("group")] public string Group { get; set; } /// /// 购物车-父行 /// [JsonProperty(PropertyName = "parentId")] [Column("parentId")] public string ParentId { get; set; } /// /// 购物车-加料方案 /// [JsonProperty(PropertyName = "scheme")] [Column("scheme")] public string Scheme { get; set; } /// /// 行状态 /// [JsonProperty(PropertyName = "rowState")] [Column("isSuit")] public OrderRowState RowState { get; set; } /// ///道菜ID /// [JsonProperty(PropertyName = "suitId")] [Column("suitId")] public string SuitId { get; set; } /// /// 道菜基准数量 /// [JsonProperty(PropertyName = "suitQuantity")] [Column("suitQuantity")] public decimal SuitQuantity { get; set; } /// /// 道菜基准加价 /// [JsonProperty(PropertyName = "suitAddPrice")] [Column("suitAddPrice")] public decimal SuitAddPrice { get; set; } /// /// 道菜基准加价后的金额 /// [JsonProperty(PropertyName = "suitAmount")] [Column("suitAmount")] public decimal SuitAmount { get; set; } /// /// 操作行为 /// [JsonProperty(PropertyName = "action")] [Column("action")] public string Action { get; set; } = string.Empty; /// /// 行备注 /// [JsonProperty(PropertyName = "remark")] [Column("remark")] public string Remark { get; set; } = string.Empty; /// /// 商品对应的详细信息,包含规格、价格信息 /// [JsonProperty(PropertyName = "product")] [Ignore] public ProductExt ProductExt { get; set; } /// /// 单品享受的优惠列表 /// [JsonProperty(PropertyName = "promotions")] [Ignore] public List Promotions { get; set; } /// /// 支付方式分摊明细 /// [JsonProperty(PropertyName = "itemPayList")] [Ignore] public List ItemPayList { get; set; } /// /// 做法/要求明细 /// [JsonProperty(PropertyName = "flavors")] [Ignore] public List Flavors { get; set; } = new List(); private int _flavorCount = 0; /// /// 单品做法总数量 /// [JsonProperty(PropertyName = "flavorCount")] [Column("flavorCount")] public int FlavorCount { get { if (this.RowState == OrderRowState.套餐主) { return this._flavorCount; } else { this._flavorCount = (int)(this.Flavors == null ? 0 : Flavors.Sum(x => x.Quantity)); return this._flavorCount; } } set { this._flavorCount = value; } } private decimal _flavorAmount = 0; /// /// 做法/要求加价合计金额 /// [JsonProperty(PropertyName = "flavorAmount")] [Column("flavorAmount")] public decimal FlavorAmount { get { if (this.RowState == OrderRowState.套餐主) { return this._flavorAmount; } else { this._flavorAmount = (this.Flavors == null ? 0 : this.Flavors.Sum(x => x.Amount)); return this._flavorAmount; } } set { this._flavorAmount = value; } } private decimal _flavorDiscountAmount = 0; /// /// 做法/要求加价优惠金额 /// [JsonProperty(PropertyName = "flavorDiscountAmount")] [Column("flavorDiscountAmount")] public decimal FlavorDiscountAmount { get { if (this.RowState == OrderRowState.套餐主) { return this._flavorDiscountAmount; } else { this._flavorDiscountAmount = (this.Flavors == null ? 0 : this.Flavors.Sum(x => x.DiscountAmount)); return this._flavorDiscountAmount; } } set { this._flavorDiscountAmount = value; } } private decimal _flavorReceivableAmount = 0; /// /// 做法/要求加价应收金额 /// [JsonProperty(PropertyName = "flavorReceivableAmount")] [Column("flavorReceivableAmount")] public decimal FlavorReceivableAmount { get { if (this.RowState == OrderRowState.套餐主) { return this._flavorReceivableAmount; } else { this._flavorReceivableAmount = (this.Flavors == null ? 0 : this.Flavors.Sum(x => x.ReceivableAmount)); return this._flavorReceivableAmount; } } set { this._flavorReceivableAmount = value; } } /// /// 做法/要求描述 /// [JsonProperty(PropertyName = "flavorNames")] [Column("flavorNames")] public string FlavorNames { get { if (this.Flavors == null || this.Flavors.Count == 0) { return ""; } return string.Join(",", this.Flavors.ConvertAll(m => m.ToString()).ToArray()); } } /// /// 标签打印名称 /// [JsonIgnore] [Ignore] public string LabelFlavorNames { get { if (this.Flavors == null || this.Flavors.Count == 0) { return ""; } return string.Join(",", this.Flavors.ConvertAll(m => m.ToLabelString()).ToArray()); } } private decimal _totalAmount = 0; /// /// 总金额 = 商品小计+做法小计 /// [JsonProperty(PropertyName = "totalAmount")] [Column("totalAmount")] public decimal TotalAmonut { get { this._totalAmount = this.Amount + this.FlavorAmount; return this._totalAmount; } set { this._totalAmount = value; } } /// /// 优惠金额 /// [JsonProperty(PropertyName = "discountAmount")] [Column("discountAmount")] public decimal DiscountAmount { get { decimal sum = 0; if (this.Promotions != null && this.Promotions.Count > 0) { List tempPromotion = this.Promotions.FindAll(x => x.PromotionType != PromotionType.做法折扣); sum = tempPromotion.Sum(m => m.DiscountAmount); } return OrderUtils.ToRound(sum); } } /// /// 应收金额 = 小计 - 优惠 /// [JsonProperty(PropertyName = "receivableAmount")] [Column("receivableAmount")] public decimal ReceivableAmount { get { return this.Amount - this.DiscountAmount; } } /// /// 总优惠金额 = 商品优惠小计+做法优惠小计 /// [JsonProperty(PropertyName = "totalDiscountAmount")] [Column("totalDiscountAmount")] public decimal TotalDiscountAmount => this.DiscountAmount + this.FlavorDiscountAmount; /// /// 行记录的创建时间 /// [JsonProperty(PropertyName = "saleDate")] [Column("saleDate")] public string SaleDate { get; set; } = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); /// /// 总应收金额 = 商品应收小计+做法应收小计 /// [JsonProperty(PropertyName = "totalReceivableAmount")] [Column("totalReceivableAmount")] public decimal TotalReceivableAmount => this.ReceivableAmount + this.FlavorReceivableAmount ; private decimal _usableRefundAmount = decimal.Zero; /// /// 可退金额,显示用 /// [JsonProperty(PropertyName = "usableRefundAmount")] [Ignore] public decimal UsableRefundAmount { get { if (this._usableRefundAmount != decimal.Zero) { return this._usableRefundAmount; } else { return this.TotalReceivableAmount; } } set { this._usableRefundAmount = value; } } /// /// 菜品ID /// [JsonProperty(PropertyName = "productId")] [Column("productId")] public string ProductId { get; set; } /// /// 菜品编号 /// [JsonProperty(PropertyName = "productNo")] [Column("productNo")] public string ProductNo { get; set; } /// /// 菜品单位ID /// [JsonProperty(PropertyName = "productUnitId")] [Column("productUnitId")] public string ProductUnitId { get; set; } /// /// 菜品单位名称 /// [JsonProperty(PropertyName = "productUnitName")] [Column("productUnitName")] public string ProductUnitName { get; set; } /// /// 品类ID /// [JsonProperty(PropertyName = "typeId")] [Column("typeId")] public string TypeId { get; set; } /// /// 品类名称 /// [JsonProperty(PropertyName = "typeName")] [Column("typeName")] public string TypeName { get; set; } /// /// 规格ID /// [JsonProperty(PropertyName = "specId")] [Column("specId")] public string SpecId { get; set; } /// /// 厨打方案 /// [JsonProperty(PropertyName = "chuda")] [Column("chuda")] public string Chuda { get; set; } /// /// 厨打标识 /// [JsonProperty(PropertyName = "chudaFlag")] [Column("chudaFlag")] public string ChudaFlag { get; set; } /// /// 已厨打数量 /// [JsonProperty(PropertyName = "chudaQty")] [Column("chudaQty")] public decimal ChudaQty { get; set; } /// /// 出品方案 /// [JsonProperty(PropertyName = "chupin")] [Column("chupin")] public string Chupin { get; set; } /// /// 出品标识 /// [JsonProperty(PropertyName = "chupinFlag")] [Column("chupinFlag")] public string ChupinFlag { get; set; } /// /// 已出品数量 /// [JsonProperty(PropertyName = "chupinQty")] [Column("chupinQty")] public decimal ChupinQty { get; set; } /// /// 厨打标签标识 /// [JsonProperty(PropertyName = "chuDaLabelFlag")] [Column("chuDaLabelFlag")] public string ChuDaLabelFlag { get; set; } /// /// 厨打标签方案 /// [JsonProperty(PropertyName = "chuDaLabel")] [Column("chuDaLabel")] public string ChuDaLabel { get; set; } /// /// 已厨打标签数量 /// [JsonProperty(PropertyName = "chuDaLabelQty")] [Column("chuDaLabelQty")] public decimal ChuDaLabelQty { get; set; } /// /// 厨显方案 /// [JsonProperty(PropertyName = "chuxian")] [Column("chuxian")] public string Chuxian { get; set; } /// /// 厨显标识 /// [JsonProperty(PropertyName = "chuxianFlag")] [Column("chuxianFlag")] public string ChuxianFlag { get; set; } /// /// 已厨显数量 /// [JsonProperty(PropertyName = "chuxianQty")] [Column("chuxianQty")] public decimal ChuxianQty { get; set; } /// /// 厨显超时(分钟) /// [JsonProperty(PropertyName = "chuxianTime")] [Column("chuxianTime")] public int ChuxianTime { get; set; } /// /// KDS出品方案 /// [JsonProperty(PropertyName = "kdsChupin")] [Column("kdsChupin")] public string KdsChupin { get; set; } /// /// KDS出品标识 /// [JsonProperty(PropertyName = "kdsChupinFlag")] [Column("kdsChupinFlag")] public string KdsChupinFlag { get; set; } /// /// KDS已出品数量 /// [JsonProperty(PropertyName = "kdsChupinQty")] [Column("kdsChupinQty")] public decimal KdsChupinQty { get; set; } /// /// KDS出品超时(分钟) /// [JsonProperty(PropertyName = "kdsChupinTime")] [Column("kdsChupinTime")] public int KdsChupinTime { get; set; } /// /// 可折扣(0否-1是) /// [JsonProperty(PropertyName = "discountFlag")] [Column("discountFlag")] public int DiscountFlag { get; set; } /// /// 是否主食(0否-1是) /// [JsonProperty(PropertyName = "tapleFlag")] [Column("tapleFlag")] public int TapleFlag { get; set; } /// /// 是否需要称重(0否-1是) /// [JsonProperty(PropertyName = "weighFlag")] [Column("weighFlag")] public int WeighFlag { get; set; } /// /// 是否可议价(0否-1是) /// [JsonProperty(PropertyName = "currentFlag")] [Column("currentFlag")] public int CurrentFlag { get; set; } /// /// 会员折上折(0不允许-1允许) /// [JsonProperty(PropertyName = "mebDiscountFlag")] [Column("mebDiscountFlag")] public int MebDiscountFlag { get; set; } /// /// 允许赠送(0不允许-1允许) /// [JsonProperty(PropertyName = "giveFlag")] [Column("giveFlag")] public int GiveFlag { get; set; } /// /// 打印标签(0否-1是) /// [JsonProperty(PropertyName = "labelPrintFlag")] [Column("labelPrintFlag")] public int LabelPrintFlag { get; set; } /// /// 已打印标签数量 /// [JsonProperty(PropertyName = "labelQty")] [Column("labelQty")] public decimal LabelQty { get; set; } /// /// 允许促销(0不允许-1允许) /// [JsonProperty(PropertyName = "promotionFlag")] [Column("promotionFlag")] public int PromotionFlag { get; set; } /// /// 管理库存(0否-1是) /// [JsonProperty(PropertyName = "stockFlag")] [Column("stockFlag")] public int StockFlag { get; set; } /// /// 订单完成时间(格式: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"); private decimal _estimatedCost = 0; /// /// 预估成本 /// [JsonProperty(PropertyName = "estimatedCost")] [Column("estimatedCost")] public decimal EstimatedCost { get { this._estimatedCost = OrderUtils.ToRound(this.CostPrice * (this.Quantity - this.RefundQuantity)); return this._estimatedCost; } set { this._estimatedCost = value; } } private decimal _estimatedProfitAmount = 0; /// /// 预估毛利金额 /// [JsonProperty(PropertyName = "estimatedProfitAmount")] [Column("estimatedProfitAmount")] public decimal EstimatedProfitAmount { get { this._estimatedProfitAmount = this.ReceivableAmount - this.EstimatedCost; return this._estimatedProfitAmount; } set { this._estimatedProfitAmount = value; } } private decimal _estimatedProfitMargin = 0; /// /// 预估毛利率 /// [JsonProperty(PropertyName = "estimatedProfitMargin")] [Column("estimatedProfitMargin")] public decimal EstimatedProfitMargin { get { 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; private decimal _saleTax = 0M; [Ignore] public decimal SaleTaxMoney { get { if (this.ProductExt == null) return 0; //zhangy 2020-04-15 Add 添加门店销项税率 if(Global.Instance.Worker != null && Global.Instance.Worker.StoreInfo != null && Global.Instance.Worker.StoreInfo.StoreTaxRateFlag == 1) { var saleTax = Global.Instance.Worker.StoreInfo.SaleTax; if(saleTax == 0) { return 0; } else { return (this.ReceivableAmount + this.FlavorReceivableAmount) / (1 + saleTax) * saleTax; } } else { return (this.ReceivableAmount + this.FlavorReceivableAmount) / (1 + (this.ProductExt.SaleTax / 100.00M)) * ((this.ProductExt.SaleTax / 100.00M)); } } } [Ignore] public decimal SaleTax { get { if (this.ProductExt == null) { return 0; } else { return this.ProductExt.SaleTax; } } } public bool Equals(OrderItem x, OrderItem y) { return x.Id.Equals(y.Id); } public int GetHashCode(OrderItem obj) { return obj.GetHashCode(); } [Ignore] public string OtherWaimaiPrintName { get; set; } [Ignore] public string OtherWaimaiPrintMake { get; set; } } public enum OrderRowState { None = 0, 普通 = 1, 套餐主 = 2, 套餐明 = 3, 自选快餐 = 4 } }