最近在做一個多租戶的雲SAAS軟件自助服務平台,途中遇到很多問題,我會將一些心得、體會逐漸分享出來,和大家一起探討。這是本系列的第一篇文章。
大家知道,要做一個全自助服務的SAAS雲平台是比較復雜的,稍微有些漏洞,就會被不法分子鑽漏洞,牽涉到一些金錢上的糾紛。因此,一開始的設計就比較重要了。說到雲自助服務平台,可能和網上購物、在線商城有些類似,但里面提供的是相關服務,還是有些區別的,我在這里先講幾個概念:
- 產品:產品即服務,即是提供給用戶的服務。產品有單價,有些產品是基礎產品,用戶購買正式產品必須免費提供的,產品可以提供給用戶進行試用。
- 模塊:產品包括很多模塊,有些模塊是必然會提供給用戶的,比如 操作人員管理、操作日志 等,還有些模塊是可選的,用戶針對自己的情況進行購買,類似增值服務,比如移動端、企業主頁等。另外還有些一次性的服務,比如系統數據對接,硬件設備購買等;
- 服務:用戶所能享受到的服務,有一定的使用期限;
- 訂單:用戶根據所擁有的 服務 所下的訂單(而不是產品哦,為什么?);
- 購物車:在用戶訂單生成前先把產品放在購物車里,購物車有很多類別,有的購物車是對目前服務進行的延期,有些是把試用的產品轉為正式,有些是對現有服務模塊的增刪,牽涉到追加購買等。購物車操作頻繁、需要做非常多的校驗,要和已經購買的服務做無縫的對接,這也是雲SAAS產品和普通電商很大不同的地方。到了訂單階段,就相對比較簡單了,生成訂單后將購物車清空、可以生成多張訂單,支付的時候再做一遍校驗。
總體的概念流程是 服務->產品->購物車->訂單->服務
上一張購物車驗證規則的流程圖
一些類(還沒有全部完成):
對實體類的操作大都采用工廠方式:
購物車類代碼:

1 public class UserCart 2 { 3 public string UserId { get; set; } 4 /// <summary> 5 /// 設置域名 6 /// </summary> 7 public string ServiceIndentify { get; set; } 8 public OrderType OrderType { get; set; } 9 public IList<UserCartProduct> UserCartProducts { get; set; } 10 public float TotalPrice 11 { 12 get 13 { 14 if (OrderType == OrderType.Experience) 15 { 16 return 0; 17 } 18 else 19 { 20 return UserCartProducts.Sum(p => p.Price); 21 } 22 } 23 } 24 public virtual IList<UserCartProduct> UserCartProduct { get; set; } 25 } 26 27 public class UserCartProduct 28 { 29 public string ProductId { get; set; } 30 public int ProductBasePrice { get; set; } 31 public Period Period { get; set; } 32 public DateTime StartDate { get; set; } 33 public DateTime EndDate { get; set; } 34 public IList<string> UserCartProductBasicModules { get; set; } 35 public IList<UserCartAddtionalModule> UserCartProductAddtionalModules { get; set; } 36 public IList<UserCartAddtionalService> UserCartAddtionalServices { get; set; } 37 public IList<UserCartOption> UserCartOptions { get; set; } 38 public float Price 39 { 40 get 41 { 42 return ProductBasePrice 43 + UserCartProductAddtionalModules.Sum(m => m.UintPrice.GetPriceByPeriod(Period)) 44 + UserCartAddtionalServices.Sum(m => m.UintPrice.GetPriceByPeriod(new Period(PeriodType.Times, m.Quantity))) 45 + UserCartOptions.Sum(m => m.UintPrice.GetPriceByPeriod(Period)); 46 } 47 } 48 public virtual UserCart UserCart { get; set; } 49 } 50 51 public class ModuleBase 52 { 53 public string ModuleId { get; set; } 54 55 public PeriodPrice UintPrice { get; set; } 56 57 } 58 59 public class UserCartAddtionalModule: ModuleBase 60 { 61 } 62 63 public class UserCartAddtionalService : ModuleBase 64 { 65 public int Quantity { get; set; } 66 } 67 68 public class UserCartOption: ModuleBase 69 { 70 public string CheckId { get; set; } 71 public string OriginCheckedId { get; set; } 72 public PeriodPrice OriginPeriodPrice { get; set; } 73 }
其他類類似。
大家對這塊有什么好的意見和建議,希望能夠提出來。
SAAS雲平台搭建札記系列文章:
SAAS雲平台搭建札記: (一)淺論SAAS多租戶自助雲服務平台的產品、服務和訂單
SAAS雲平台搭建札記: (二)Linux Ubutu下.Net Core整套運行環境的搭建