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


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

先簡單講下業務方面的需求:直銷系統會有一個頂級的經銷商,經銷商的基本信息中包括經銷商的名字、聯系人(因為在平台購買產品后,會寄送給聯系人)、總的電子幣(電子幣是由經銷商支付產生,

購買產品后會扣減電子幣)、總的獎金幣(系統周期性根據經銷商購買的東西來確定獎金幣,獎金幣可以購買東西,也可以提現)、總PV(經銷商購買時,會根據購買產品的PV進行累加)、卡的類型(根據經銷商初次的電子幣確定卡的類型)、子經銷商個數(子經銷商的注冊由父經銷商進行,父經銷商的直接子經銷商不超過2個)、級別(根據周期消費總額確定經銷商級別);另外經銷商有個層級結構,

最后系統當然還要對應經銷商的登錄信息,默認系統會有個登陸密碼;經銷商在注冊子經銷商時,會從自己扣除一部分電子幣附加到子經銷商上。

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

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; }
    }

從經銷商聚合大家可以看到,在創建一個經銷商時,除了有經銷商的基本信息外,還必須同時創建聯系人與層次結構,這樣一個經銷商才是完整的,而且經銷商也引用到了聯系人與層次結構。

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 ; }
    }

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

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

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

QQ討論群:309287205

DDD實戰進階視頻請關注微信公眾號:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM