chore 优化代码

This commit is contained in:
2025-10-16 10:30:51 +08:00
parent f1c609b4be
commit 1f5bc3e971
367 changed files with 2705 additions and 3083 deletions

View File

@ -1,60 +1,58 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Entities;
using System.Collections.Generic;
using Volo.Abp.Domain.Values;
namespace KonSoft.Admin.Entities
namespace KonSoft.Admin.Entities;
/// <summary>
/// 地址
/// </summary>
public class AddressInfo : ValueObject
{
/// <summary>
/// 地址
/// </summary>
public class AddressInfo : ValueObject
public AddressInfo()
{
/// <summary>
/// 联系人
/// </summary>
public string ContactName { get; private set; }
/// <summary>
/// 手机号
/// </summary>
public string ContactPhone { get; private set; }
/// <summary>
/// 详细地址
/// </summary>
public string DetailAddress { get; private set; }
/// <summary>
/// 城市
/// </summary>
public string City { get; private set; }
/// <summary>
/// 区域
/// </summary>
public string District { get; private set; }
public AddressInfo() { }
public AddressInfo(string contactName, string contactPhone, string detailAddress, string city, string district)
{
ContactName = contactName;
ContactPhone = contactPhone;
DetailAddress = detailAddress;
City = city;
District = district;
}
protected override IEnumerable<object> GetAtomicValues()
{
yield return ContactName;
yield return ContactPhone;
yield return DetailAddress;
yield return City;
yield return District;
}
}
}
public AddressInfo(string contactName, string contactPhone, string detailAddress, string city, string district)
{
ContactName = contactName;
ContactPhone = contactPhone;
DetailAddress = detailAddress;
City = city;
District = district;
}
/// <summary>
/// 联系人
/// </summary>
public string ContactName { get; }
/// <summary>
/// 手机号
/// </summary>
public string ContactPhone { get; }
/// <summary>
/// 详细地址
/// </summary>
public string DetailAddress { get; }
/// <summary>
/// 城市
/// </summary>
public string City { get; }
/// <summary>
/// 区域
/// </summary>
public string District { get; }
protected override IEnumerable<object> GetAtomicValues()
{
yield return ContactName;
yield return ContactPhone;
yield return DetailAddress;
yield return City;
yield return District;
}
}

View File

@ -0,0 +1,24 @@
using Volo.Abp.Identity;
namespace KonSoft.Admin.Entities;
/// <summary>
/// 家政服务工人实体
/// </summary>
public class HouseholdWorker : IdentityUser
{
/// <summary>
/// 接单数
/// </summary>
public int OrderCount { get; set; }
/// <summary>
/// 职业
/// </summary>
public required string Profession { get; set; }
/// <summary>
/// 能力范围
/// </summary>
public required string ScopeOfCompetence { get; set; }
}

View File

@ -1,157 +1,171 @@
using KonSoft.Admin.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System;
using KonSoft.Admin.Enums;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.Identity;
namespace KonSoft.Admin.Entities
namespace KonSoft.Admin.Entities;
public class Order : FullAuditedAggregateRoot<Guid>
{
public class Order : FullAuditedAggregateRoot<Guid>
protected Order()
{
/// <summary>
/// 订单编号
/// </summary>
public string OrderSN { get; private set; }
/// <summary>
/// 用户ID
/// </summary>
public Guid CustomerId { get; private set; }
/// <summary>
/// 家政人员ID
/// </summary>
public Guid? WorkerId { get; private set; }
///// <summary>
///// 用户ID
///// </summary>
//public virtual IdentityUser Customer { get; private set; }
///// <summary>
///// 家政人员ID
///// </summary>
//public virtual IdentityUser? Worker { get; private set; }
/// <summary>
/// 服务项目ID
/// </summary>
public Guid ServiceCategoryId { get; private set; }
public virtual ServiceCategory ServiceCategory { get; private set; }
/// <summary>
/// 服务预约时间
/// </summary>
public DateTime ServiceTime { get; private set; }
public OrderStatus Status { get; private set; }
/// <summary>
/// 应付金额
/// </summary>
public decimal Amount { get; private set; }
/// <summary>
/// 实付金额
/// </summary>
public decimal PaidAmount { get; private set; }
/// <summary>
/// 支付方式
/// </summary>
public string PaymentMethod { get; private set; }
/// <summary>
/// 地址
/// </summary>
public AddressInfo Address { get; private set; }
/// <summary>
/// 备注
/// </summary>
public string? Remark { get; private set; }
/// <summary>
/// 取消原因
/// </summary>
public string? CancelReason { get; private set; }
protected Order() { }
public Order(Guid id, string orderSN, Guid customerId, Guid serviceCategoryId, DateTime serviceTime, decimal amount, AddressInfo address, string remark = null)
: base(id)
{
OrderSN = orderSN;
CustomerId = customerId;
ServiceCategoryId = serviceCategoryId;
ServiceTime = serviceTime;
Amount = amount;
Address = address;
Remark = remark;
Status = OrderStatus.PendingPayment;
}
public void MarkPaid(decimal paidAmount, string method)
{
if (Status != OrderStatus.PendingPayment)
throw new InvalidOperationException("订单不在待付款状态");
PaidAmount = paidAmount;
PaymentMethod = method;
Status = OrderStatus.PaidWaitingAssign;
}
public void AssignWorker(Guid workerId)
{
if (Status != OrderStatus.PaidWaitingAssign)
throw new InvalidOperationException("订单无法分配师傅");
WorkerId = workerId;
Status = OrderStatus.AssignedWaitingService;
}
public void StartService()
{
if (Status != OrderStatus.AssignedWaitingService)
throw new InvalidOperationException("订单无法开始");
Status = OrderStatus.InService;
}
public void CompleteService()
{
if (Status != OrderStatus.InService)
throw new InvalidOperationException("订单未开始服务,无法完成");
Status = OrderStatus.WaitingConfirm;
}
public void ConfirmCompletion()
{
if (Status != OrderStatus.WaitingConfirm)
throw new InvalidOperationException("订单无法确认");
Status = OrderStatus.Completed;
}
public void Cancel(string reason)
{
// 若已完成或退款中则不可取消
if (Status == OrderStatus.Completed || Status == OrderStatus.Refunding || Status == OrderStatus.Refunded)
throw new InvalidOperationException("订单无法被取消");
CancelReason = reason;
Status = OrderStatus.Canceled;
}
}
}
public Order(Guid id, string orderSN, Guid customerId, Guid serviceCategoryId, DateTime serviceTime, decimal amount,
AddressInfo address, string remark = null)
: base(id)
{
OrderSN = orderSN;
CustomerId = customerId;
ServiceCategoryId = serviceCategoryId;
ServiceTime = serviceTime;
Amount = amount;
Address = address;
Remark = remark;
Status = OrderStatus.PendingPayment;
}
/// <summary>
/// 订单编号
/// </summary>
public string OrderSN { get; private set; }
/// <summary>
/// 用户ID
/// </summary>
public Guid CustomerId { get; private set; }
/// <summary>
/// 家政人员ID
/// </summary>
public Guid? WorkerId { get; private set; }
///// <summary>
///// 用户ID
///// </summary>
//public virtual IdentityUser Customer { get; private set; }
///// <summary>
///// 家政人员ID
///// </summary>
//public virtual IdentityUser? Worker { get; private set; }
/// <summary>
/// 服务项目ID
/// </summary>
public Guid ServiceCategoryId { get; private set; }
public virtual ServiceCategory ServiceCategory { get; private set; }
/// <summary>
/// 服务预约时间
/// </summary>
public DateTime ServiceTime { get; private set; }
public OrderStatus Status { get; private set; }
/// <summary>
/// 应付金额
/// </summary>
public decimal Amount { get; private set; }
/// <summary>
/// 实付金额
/// </summary>
public decimal PaidAmount { get; private set; }
/// <summary>
/// 支付方式
/// </summary>
public string PaymentMethod { get; private set; }
/// <summary>
/// 地址
/// </summary>
public AddressInfo Address { get; private set; }
/// <summary>
/// 备注
/// </summary>
public string? Remark { get; private set; }
/// <summary>
/// 取消原因
/// </summary>
public string? CancelReason { get; private set; }
public void MarkPaid(decimal paidAmount, string method)
{
if (Status != OrderStatus.PendingPayment)
{
throw new InvalidOperationException("订单不在待付款状态");
}
PaidAmount = paidAmount;
PaymentMethod = method;
Status = OrderStatus.PaidWaitingAssign;
}
public void AssignWorker(Guid workerId)
{
if (Status != OrderStatus.PaidWaitingAssign)
{
throw new InvalidOperationException("订单无法分配师傅");
}
WorkerId = workerId;
Status = OrderStatus.AssignedWaitingService;
}
public void StartService()
{
if (Status != OrderStatus.AssignedWaitingService)
{
throw new InvalidOperationException("订单无法开始");
}
Status = OrderStatus.InService;
}
public void CompleteService()
{
if (Status != OrderStatus.InService)
{
throw new InvalidOperationException("订单未开始服务,无法完成");
}
Status = OrderStatus.WaitingConfirm;
}
public void ConfirmCompletion()
{
if (Status != OrderStatus.WaitingConfirm)
{
throw new InvalidOperationException("订单无法确认");
}
Status = OrderStatus.Completed;
}
public void Cancel(string reason)
{
// 若已完成或退款中则不可取消
if (Status == OrderStatus.Completed || Status == OrderStatus.Refunding || Status == OrderStatus.Refunded)
{
throw new InvalidOperationException("订单无法被取消");
}
CancelReason = reason;
Status = OrderStatus.Canceled;
}
}

View File

@ -1,99 +1,105 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using Volo.Abp.Domain.Entities.Auditing;
namespace KonSoft.Admin.Entities
namespace KonSoft.Admin.Entities;
public class Product(
Guid id,
string name,
string code,
decimal price,
string description,
string type,
Guid? parentId,
string status = "在售",
int order = 0) : FullAuditedAggregateRoot<Guid>(id)
{
public class Product(Guid id, string name, string code, decimal price, string description, string type, Guid? parentId, string status = "在售", int order = 0) : FullAuditedAggregateRoot<Guid>(id)
/// <summary>
/// 分类名称
/// </summary>
public string Name { get; private set; } = name;
/// <summary>
/// 商品编码
/// </summary>
public string Code { get; private set; } = code;
/// <summary>
/// 商品价格
/// </summary>
public decimal Price { get; private set; } = price;
/// <summary>
/// 商品描述
/// </summary>
public string Description { get; private set; } = description;
/// <summary>
/// 分类类型(大类或小类)
/// </summary>
public string Type { get; private set; } = type;
/// <summary>
/// 父分类ID
/// </summary>
public Guid? ParentId { get; private set; } = parentId;
/// <summary>
/// 商品状态(在售/下架等)
/// </summary>
public string Status { get; private set; } = status;
/// <summary>
/// 排序字段
/// </summary>
public int Order { get; private set; } = order;
[NotMapped] public List<Product> Children { get; set; } = new();
/// <summary>
/// 修改商品信息
/// </summary>
public void Update(string name, string code, decimal price, string description, int order)
{
/// <summary>
/// 分类名称
/// </summary>
public string Name { get; private set; } = name;
Name = name;
Code = code;
Price = price;
Description = description;
Order = order;
}
/// <summary>
/// 商品编码
/// </summary>
public string Code { get; private set; } = code;
/// <summary>
/// 修改商品分类
/// </summary>
public void ChangeCategory(string type, Guid? parentId)
{
Type = type;
ParentId = parentId;
}
/// <summary>
/// 商品价格
/// </summary>
public decimal Price { get; private set; } = price;
/// <summary>
/// 上架商品
/// </summary>
public void PutOnSale()
{
Status = "在售";
}
/// <summary>
/// 商品描述
/// </summary>
public string Description { get; private set; } = description;
/// <summary>
/// 下架商品
/// </summary>
public void TakeOffSale()
{
Status = "下架";
}
/// <summary>
/// 分类类型(大类或小类)
/// </summary>
public string Type { get; private set; } = type;
/// <summary>
/// 父分类ID
/// </summary>
public Guid? ParentId { get; private set; } = parentId;
/// <summary>
/// 商品状态(在售/下架等)
/// </summary>
public string Status { get; private set; } = status;
/// <summary>
/// 排序字段
/// </summary>
public int Order { get; private set; } = order;
[NotMapped]
public List<Product> Children { get; set; } = new();
/// <summary>
/// 修改商品信息
/// </summary>
public void Update(string name, string code, decimal price, string description, int order)
{
Name = name;
Code = code;
Price = price;
Description = description;
Order = order;
}
/// <summary>
/// 修改商品分类
/// </summary>
public void ChangeCategory(string type, Guid? parentId)
{
Type = type;
ParentId = parentId;
}
/// <summary>
/// 上架商品
/// </summary>
public void PutOnSale()
{
Status = "在售";
}
/// <summary>
/// 下架商品
/// </summary>
public void TakeOffSale()
{
Status = "下架";
}
/// <summary>
/// 修改价格
/// </summary>
public void ChangePrice(decimal newPrice)
{
Price = newPrice;
}
/// <summary>
/// 修改价格
/// </summary>
public void ChangePrice(decimal newPrice)
{
Price = newPrice;
}
}

View File

@ -1,46 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Entities.Auditing;
namespace KonSoft.Admin.Entities
namespace KonSoft.Admin.Entities;
public class ServiceCategory : FullAuditedAggregateRoot<Guid>
{
public class ServiceCategory : FullAuditedAggregateRoot<Guid>
protected ServiceCategory()
{
public string Name { get; private set; }
public Guid? ParentId { get; private set; }
public string Path { get; private set; }
public int Level { get; private set; }
protected ServiceCategory() { }
public ServiceCategory(Guid id, string name)
: base(id)
{
Name = name;
}
public ServiceCategory(Guid id, string name, Guid? parentId = null, string path = null, int level = 0) : base(id)
{
Name = name;
ParentId = parentId;
Path = path ?? id.ToString();
Level = level;
}
public void UpdateName(string name) => Name = name;
public void SetParent(ServiceCategory parent)
{
ParentId = parent?.Id;
Level = (parent?.Level ?? 0) + 1;
Path = parent != null ? $"{parent.Path}/{Id}" : Id.ToString();
}
}
}
public ServiceCategory(Guid id, string name)
: base(id)
{
Name = name;
}
public ServiceCategory(Guid id, string name, Guid? parentId = null, string path = null, int level = 0) : base(id)
{
Name = name;
ParentId = parentId;
Path = path ?? id.ToString();
Level = level;
}
public string Name { get; private set; }
public Guid? ParentId { get; private set; }
public string Path { get; private set; }
public int Level { get; private set; }
public void UpdateName(string name)
{
Name = name;
}
public void SetParent(ServiceCategory parent)
{
ParentId = parent?.Id;
Level = (parent?.Level ?? 0) + 1;
Path = parent != null ? $"{parent.Path}/{Id}" : Id.ToString();
}
}

View File

@ -1,34 +0,0 @@
using KonSoft.Admin.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Entities.Auditing;
namespace KonSoft.Admin.Entities
{
/// <summary>
/// 家政人员
/// </summary>
public class Worker : FullAuditedAggregateRoot<Guid>
{
public string Name { get; private set; }
public string Phone { get; private set; }
public decimal Rating { get; private set; } // 评分
public List<Guid> SkillCategoryIds { get; private set; } = new List<Guid>();
public Worker() { }
public void UpdateRating(decimal newRating)
{
Rating = newRating;
}
public bool CanPerform(Guid serviceCategoryId)
{
return SkillCategoryIds.Contains(serviceCategoryId);
}
}
}