The first wave of advanced DDD actual combat (8): Develop a direct sales system for the general business of the big health industry (implement the POCO model of the dealer context field layer)

Starting from this article, we start to introduce the implementation of the domain layer of the direct selling system in the big health industry.

Let’s briefly talk about business requirements: there will be a top-level distributor in the direct selling system, and the basic information of the distributor includes the distributor’s name, contact person (because after purchasing the product on the platform, it will be sent to the contact person), general manager The electronic currency (electronic currency is generated by the dealer's payment,

After purchasing the product, the electronic currency will be deducted), the total bonus coins (the system periodically determines the bonus coins according to the things purchased by the dealer, and the bonus coins can be purchased or withdrawn), the total PV (when the dealer buys, it will be determined according to the The PV of the purchased product is accumulated), the type of card (the type of card is determined according to the initial electronic currency of the dealer), the number of sub-dealers (the registration of sub-dealers is carried out by the parent dealer, and the direct sub-dealer of the parent dealer No more than 2), level (dealer level is determined according to the total period of consumption); in addition, the dealer has a hierarchical structure,

Finally, of course, the system also needs to correspond to the login information of the dealer. By default, the system will have a login password; when the dealer registers a sub-dealer, it will deduct a part of the electronic currency from itself and attach it to the sub-dealer.

From the understanding of the entire demand and through the understanding of DDD, we will have two aggregations, namely the distributor aggregation (including distributors, contacts, levels) and the login aggregation.

1. Dealer Aggregate Root:

 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
    {
        Ordinary Member = 1 ,
        Silver Member = 2 ,
        Gold Member = 3
    }
    public enum Level : int
    {
        area manager = 1 ,
        Provincial Manager = 2 ,
        Region Manager = 3 ,
        directors = 4 
    }

2. Contact value object:

 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
    {
        default = 1 ,
        non-default = 2 
    }

3. Hierarchical Value Objects:

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

As you can see from the dealer aggregation, when creating a dealer, in addition to the basic information of the dealer, it is also necessary to create a contact and a hierarchy at the same time, so that a dealer is complete, and the dealer is also quoted Contacts and Hierarchy.

4. Log in to the aggregate root:

 public partial class Login : IAggregationRoot
    {
        public Login() { }
         // represents the login phone number 
        public  string Code { get ; set ; }
         public  string Password { get ; set ; }
         public Guid DealerId { get ; set ; }
        [Key]
        public Guid Id { get ; set ; }
    }

4. Handle the mapping between dealer bound context and data access context

For how to map the dealer boundary context to the data access context, please refer to the relevant implementation of the product context, which will not be repeated here.

The next article will talk about the implementation of dealer context warehousing, because in the domain logic of registering sub-dealers, it will be judged whether the current dealer has more than 2 sub-dealers through warehousing.

QQ discussion group: 309287205

Please pay attention to the WeChat public account for the advanced video of DDD actual combat:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325122442&siteId=291194637