領域驅動設計DDD實戰進階第一波(八):開發通常業務的大健康行業直銷系統(實現經銷商上下文領域層之POCO模型)

從這篇文章開始,咱們開始介紹大健康行業直銷系統領域層的實現。微信

先簡單講下業務方面的需求:直銷系統會有一個頂級的經銷商,經銷商的基本信息中包括經銷商的名字、聯繫人(由於在平臺購買產品後,會寄送給聯繫人)、總的電子幣(電子幣是由經銷商支付產生,購買產品後會扣減電子幣)、總的獎金幣(系統週期性根據經銷商購買的東西來肯定獎金幣,獎金幣能夠購買東西,也能夠提現)、總PV(經銷商購買時,會根據購買產品的PV進行累加)、卡的類型(根據經銷商初次的電子幣肯定卡的類型)、子經銷商個數(子經銷商的註冊由父經銷商進行,父經銷商的直接子經銷商不超過2個)、級別(根據週期消費總額肯定經銷商級別);另外經銷商有個層級結構,最後系統固然還要對應經銷商的登陸信息,默認系統會有個登錄密碼;經銷商在註冊子經銷商時,會從本身扣除一部分電子幣附加到子經銷商上。ui

從整個需求的理解並經過對DDD理解來看,咱們會有兩個聚合,分別是經銷商聚合(包括經銷商、聯繫人、層級)和登錄聚合。spa

1.經銷商聚合根:

public partial class Dealers:IAggregationRoot
{
    public Dealers() { }

    public string Code { get; set; }
    [Key]
    public Guid Id { get; set; }
    public string Name { get; set; }
    public string Tel { get; set; }
    public decimal TotalEleMoney { get; set; }
    public decimal JiangJInMoney { get; set; }
    public decimal TotalPV { get; set; }
    public CardType CardType { get; set; }
    public Level Level { get; set; }
    public int SubCount { get; set; }
    public List<Contact> Contacts { get; set; }
    public DealerTree DealerTree { get; set; }
}

public enum CardType : int
{
    普通會員=1,
    銀卡會員=2,
    金卡會員=3
}
public enum Level : int
{
    片區經理=1,
    省區經理=2,
    大區經理=3,
    董事=4
}
複製代碼

2.聯繫人值對象:

public partial class Contact : IValueObject
{
    public Contact() { }
    public Guid Id { get; set; }
    public string ContactName { get; set; }
    public string ContactTel { get; set; }
    public string Province { get; set; }
    public string City { get; set; }
    public string Zero { get; set; }
    public string Street { get; set; }
    public IsDefaultContact IsDefault { get; set; }
}
public enum IsDefaultContact : int
{
    默認=1,
    非默認=2
}
複製代碼

3.層次結構值對象:

public partial class DealerTree : IValueObject
{
    public DealerTree() { }
    public Guid Id { get; set; }
    public Guid DealerId { get; set; }
    public Guid? ParentDealerId { get; set; }
    public int Layer { get; set; }
}
複製代碼

從經銷商聚合你們能夠看到,在建立一個經銷商時,除了有經銷商的基本信息外,還必須同時建立聯繫人與層次結構,這樣一個經銷商纔是完整的,並且經銷商也引用到了聯繫人與層次結構。code

4.登陸聚合根:

public partial class Login : IAggregationRoot
{
    public Login() { }
    //表明登陸的電話號碼
    public string Code { get; set; }
    public string Password { get; set; }
    public Guid DealerId { get; set; }
    [Key]
    public Guid Id { get ; set ; }
}
複製代碼

5.處理經銷商界限上下文與數據訪問上下文的映射

關於如何講經銷商界限上下文映射到數據訪問上下文,請參考產品上下文的相關實現,這裏就再也不累述了。cdn

下一篇文章開始講經銷商上下文倉儲的實現,由於在註冊子經銷商的領域邏輯中,會經過倉儲去判斷當前經銷商是否子經銷商個數超過2個。視頻

DDD實戰進階視頻請關注微信公衆號:對象

相關文章
相關標籤/搜索