using MyCode.Project.Domain.Message.Act.BaoDian; using MyCode.Project.Infrastructure.Exceptions; using MyCode.Project.Domain.Model; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using SqlSugar; using MyCode.Project.Domain.Repositories; namespace MyCode.Project.Services.BLL { public class BaoDianBLL { #region 初始化 private readonly IRepository _repository; public BaoDianBLL(IRepository repository) { _repository = repository; } #endregion #region CheckSaveProductSalesSchedules 判断产品销售计划的保存 /// /// 判断产品销售计划的保存 /// /// public void CheckSaveProductSalesSchedules(ProductSalesScheduleAct act) { if (string.IsNullOrWhiteSpace(act.PackageName)) { throw new BaseException("套餐名称不能为空"); } if (act.EffectType == 0) { throw new BaseException("请选择功效"); } if (act.PackageType == 0) { throw new BaseException("请选择所属类型"); } if ((act.SkuList == null || act.SkuList.Count == 0) && (act.ServiceList == null || act.ServiceList.Count == 0)) { throw new BaseException("至少选择一个商品或服务"); } act.SkuList.ForEach(x => { if (x.Qty <= 0) { throw new BaseException($"{x.Name}的数量不能少于等于0"); } }); } #endregion #region CheckSaveNewMemberSalesSchedule 判断新客销售计划的保存 /// /// 判断新客销售计划的保存 /// /// public void CheckSaveNewMemberSalesSchedule(NewMemberSalesScheduleAct act) { if (string.IsNullOrWhiteSpace(act.PackageName)) { throw new BaseException("套餐名称不能为空"); } if ((act.SkuList == null || act.SkuList.Count == 0)&&(act.ServiceList==null||act.ServiceList.Count==0)) { throw new BaseException("至少选择一个商品或服务"); } } #endregion #region GetProductCode 获取产品计划套餐编码 /// /// 获取产品计划套餐编码 /// /// public string GetProductCode() { var code = _repository.Queryable().OrderBy(p => p.CreateTime, OrderByType.Desc).Select(p => p.Code).First(); //新店铺编码+1 if (!string.IsNullOrWhiteSpace(code)) { int codeNum = Convert.ToInt32(code.Replace('C', ' ').Replace('P', ' ')); code = $"CP{codeNum + 1}"; } if (string.IsNullOrWhiteSpace(code)) { code = $"CP10001"; } return code; } #endregion #region GetNewMemberCode 获取新客计划套餐编码 /// /// 获取新客计划套餐编码 /// /// public string GetNewMemberCode() { var code = _repository.Queryable().OrderBy(p => p.CreateTime, OrderByType.Desc).Select(p => p.Code).First(); //新店铺编码+1 if (!string.IsNullOrWhiteSpace(code)) { int codeNum = Convert.ToInt32(code.Replace('X', ' ').Replace('K', ' ')); code = $"XK{codeNum + 1}"; } if (string.IsNullOrWhiteSpace(code)) { code = $"XK10001"; } return code; } #endregion } }